diff --git a/encoder/app.php b/encoder/app.php index 9795d66..4c3e787 100644 --- a/encoder/app.php +++ b/encoder/app.php @@ -13,101 +13,22 @@ $error_message = ''; // --- 1. Handle Form Submission BEFORE any HTML is rendered --- if (isset($_POST['submit'])) { - $upload_paths = [ - 'app_ad' => '/var/www/html/app_ad.png', - 'app_logo' => '/var/www/html/app_logo.png' - ]; - $secondary_dir = '/var/www/encoder/'; - $errors = []; - // Handle File Deletions - $to_delete = $_POST['remove_files'] ?? []; - foreach ($to_delete as $file_key => $should_delete) { - if ($should_delete === '1' && isset($upload_paths[$file_key])) { - $path = $upload_paths[$file_key]; - if (file_exists($path)) { - unlink($path); - // Also remove from encoder directory - $secondary_path = $secondary_dir . basename($path); - if (file_exists($secondary_path)) { - unlink($secondary_path); - } - } - } - } - - foreach ($upload_paths as $input_name => $destination) { - if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) { - $tmp_path = $_FILES[$input_name]['tmp_name']; - - // 1. Verify it is actually a PNG using GD/getimagesize - $image_info = @getimagesize($tmp_path); - if (!$image_info || $image_info[2] !== IMAGETYPE_PNG) { - $errors[] = "File for $input_name must be a valid PNG image."; - continue; - } - - - $target_width = ($input_name === 'app_logo') ? 128 : 256; - $target_height = ($input_name === 'app_logo') ? 128 : 256; - - // 3. Load the source image - $src_img = @imagecreatefrompng($tmp_path); - if (!$src_img) { - $errors[] = "Failed to process $input_name (Invalid PNG data)."; - continue; - } - - // 4. Create a blank truecolor canvas - $dst_img = imagecreatetruecolor($target_width, $target_height); - - // 5. Preserve transparency for PNG - imagealphablending($dst_img, false); - imagesavealpha($dst_img, true); - $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); - imagefill($dst_img, 0, 0, $transparent); - - // 6. Resize (Resample) - imagecopyresampled( - $dst_img, - $src_img, - 0, - 0, - 0, - 0, - $target_width, - $target_height, - imagesx($src_img), - imagesy($src_img) - ); - - // 7. Save to primary destination with compression (level 7) - if (imagepng($dst_img, $destination, 7)) { - $filename = basename($destination); - $secondary_destination = $secondary_dir . $filename; - - if (!copy($destination, $secondary_destination)) { - $errors[] = "Failed to create secondary copy for $input_name."; - } - } else { - $errors[] = "Failed to save processed $input_name."; - } - - imagedestroy($src_img); - imagedestroy($dst_img); - } - } - // Handle Text Fields $text_fields = [ 'channel_name', 'office_address', 'office_address_1', 'office_address_2', - 'contact_details', + 'contact_name_1', + 'contact_number_1', + 'contact_name_2', + 'contact_number_2', + 'contact_name_3', + 'contact_number_3', 'enforcement_officer', - 'eo_contact_details', + 'enforcement_officer_contact', 'company_name', 'cin_number', 'gstin_number', @@ -116,9 +37,12 @@ if (isset($_POST['submit'])) { 'content_language' ]; + // Dynamically build the list based on what is actually posted to handle the 3 contacts $data_to_save = []; - foreach ($text_fields as $field) { - $data_to_save[$field] = $_POST[$field] ?? ''; + foreach ($_POST as $key => $value) { + if ($key !== 'submit') { + $data_to_save[$key] = $value; + } } // Save if no errors occurred @@ -134,6 +58,7 @@ if (isset($_POST['submit'])) { // --- 2. Load Data for Display --- $saved_data = []; if (file_exists($json_file)) { + $json_content = file_get_contents($json_file); // Note: fixed typo from your snippet if it was file_get_contents $json_content = file_get_contents($json_file); $saved_data = json_decode($json_content, true) ?? []; } @@ -146,30 +71,8 @@ function getValue($data, $key) include 'header.php'; ?> - - -
+
- - -

Broadcasting Information

@@ -181,14 +84,14 @@ include 'header.php';
-

General Details

+

General Details

-
+
@@ -200,16 +103,43 @@ include 'header.php';
+ +
- - + +
+
+ + +
+ + +
+ + +
+
+ + +
+ + +
+ + +
+
+ + +
+
- +
@@ -229,19 +159,19 @@ include 'header.php';
-

Content Details

+

Content Details

@@ -250,13 +180,13 @@ include 'header.php'; Content Type
@@ -267,38 +197,6 @@ include 'header.php';
- - -
-

Upload Ad (PNG)

-
- - -
New file selected
- -
- - -
- -
-
- - -
-

Upload Logo (PNG)

-
- - -
New file selected
- -
- - -
- -
-