<? 
ob_start(); // Start output buffering
session_start();
include_once("../includes/main.inc.php");
$headerTitleName = "Add New Material";

$page_id = $_REQUEST['page_id'];
$industry_name = isset($industry_name) ? addslashes($industry_name) : '';
$parent_childs = isset($parent_childs) ? addslashes($parent_childs) : '';
$title = isset($title) ? addslashes($title) : '';
$description = isset($description) ? addslashes($description) : '';
$keyword = isset($keyword) ? addslashes($keyword) : '';
$country_title = isset($country_title) ? addslashes($country_title) : '';
$country_descriptions = isset($country_descriptions)? addslashes($country_descriptions): '';
$country_descriptions1 = isset($country_descriptions1)? addslashes($country_descriptions1): '';
$country_descriptions2 = isset($country_descriptions2)? addslashes($country_descriptions2): '';
$country_descriptions3 = isset($country_descriptions3)? addslashes($country_descriptions3): '';
$country_descriptions4 = isset($country_descriptions4)? addslashes($country_descriptions4): '';
$country_descriptions5 = isset($country_descriptions5)? addslashes($country_descriptions5): '';
$country_descriptions6 = isset($country_descriptions6)? addslashes($country_descriptions6): '';
$country_descriptions7 = isset($country_descriptions7)? addslashes($country_descriptions7): '';
$country_descriptions8 = isset($country_descriptions8)? addslashes($country_descriptions8): '';
$conclusion = isset($conclusion)? addslashes($conclusion): '';
$country_url = isset($country_url)? addslashes($country_url): '';

	
if(is_post_back()) {

	if($page_id!='') {
	   // print_r($_POST);exit();
$industry_name = $_POST['industry_name'] ?? '';
$parent_childs = isset($_POST['parent_childs']) ? intval($_POST['parent_childs']) : 0;
if($parent_childs=='0'){
    $country_url=' ';
}
$country_status = $_POST['country_status'] ?? '0'; // Default to '0' (Inactive)
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$keyword = $_POST['keyword'] ?? '';
$country_title =$_POST['country_title'] ?? '';
$country_url =$_POST['country_url'] ?? '';
$country_descriptions = isset($_POST['country_descriptions']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions']))
    ) 
    : '';
$country_descriptions1 = isset($_POST['country_descriptions1']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions1']))
    ) 
    : '';
    $country_descriptions2 = isset($_POST['country_descriptions2']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions2']))
    ) 
    : '';
    $country_descriptions3 = isset($_POST['country_descriptions3']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions3']))
    ) 
    : '';
    $country_descriptions4 = isset($_POST['country_descriptions4']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions4']))
    ) 
    : '';
    $country_descriptions5 = isset($_POST['country_descriptions5']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions5']))
    ) 
    : '';
    $country_descriptions6= isset($_POST['country_descriptions6']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions6']))
    ) 
    : '';
    $country_descriptions7 = isset($_POST['country_descriptions7']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions7']))
    ) 
    : '';
    $country_descriptions8 = isset($_POST['country_descriptions8']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions8']))
    ) 
    : '';
    $conclusion = isset($_POST['conclusion']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['conclusion']))
    ) 
    : '';
    $sv_image_1 = $sv_image_1 ?? ''; 

		$sql = "update `tbl_material_used` set industry_name='$industry_name', parent_childs='$parent_childs', country_status='$country_status', title='$title', description='$description', keyword='$keyword', country_title='$country_title', country_descriptions='$country_descriptions',country_descriptions1='$country_descriptions1',country_descriptions2='$country_descriptions2',country_descriptions3='$country_descriptions3',country_descriptions4='$country_descriptions4',country_descriptions5='$country_descriptions5',country_descriptions6='$country_descriptions6',country_descriptions7='$country_descriptions7',country_descriptions8='$country_descriptions8',conclusion='$conclusion' where country_id = $page_id ";
//	print_r($sql);exit();
	
		db_query($sql);
		
		########### Uploading Image ################
		if($_FILES['sv_image']['name']!='')
		{
			if(strlen($sv_image) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image);
			}
			$sv_image_1 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES[sv_image]['name']);
				copy($_FILES['sv_image']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_1) or die("Image is not uploaded");
				copy($_FILES['sv_image']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_1) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_1;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_1; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES[sv_image][type] =="image/pjpeg" OR $_FILES[sv_image][type]=="image/jpeg" OR $_FILES[sv_image][type]=="image/png")){echo "Your uploaded file must be of JPG or GIF or PNG. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES[sv_image][type]=="image/pjpeg" OR $_FILES[sv_image][type]=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
			else{
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
			
			db_query("update tbl_material_used set country_banner='".$sv_image_1."' where country_id = $page_id ");
		}
			if($_FILES['industry_image1']['name']!='')
		{
		    $sv_image9=$sv_image9 ?? '';
			if(strlen($sv_image9) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image9)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image9);
			}
			$sv_image_9 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES['industry_image1']['name']);
			$sv_image_9=$sv_image_9 ?? '';
				copy($_FILES['industry_image1']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_9) or die("Image is not uploaded");
				copy($_FILES['industry_image1']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_9) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_9;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_9; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES['industry_image1']['type'] =="image/pjpeg" OR $_FILES['industry_image1']['type']=="image/jpeg" OR $_FILES['industry_image1']['type']=="image/png" OR
			$_FILES['industry_image1']['type']=="image/webp")){echo "Your uploaded file must be of JPG or GIF or PNG or Webp. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES['industry_image1']['type']=="image/pjpeg" OR $_FILES['industry_image1']['type']=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
		elseif($_FILES['industry_image1']['type']=="image/png"){ 
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
				elseif($_FILES['industry_image1']['type'] == "image/webp") {
                 $im = imagecreatefromwebp($add); // Create image from WebP
                 $width = imagesx($im); // Original picture width is stored
                 $height = imagesy($im); // Original picture height is stored
                 $newimage = imagecreatetruecolor($n_width, $n_height);
                 imagecopyresized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                 imagewebp($newimage, $tsrc); // Save thumbnail as WebP
                 chmod("$tsrc", 0777);
             }
             				db_query("update tbl_material_used set industry_image1='".$sv_image_9."' where country_id = $page_id ");

			
		}
			if($_FILES['industry_image2']['name']!='')
		{
		    $sv_image10=$sv_image10 ?? '';
			if(strlen($sv_image10) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image10)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image10);
			}
			$sv_image_10 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES['industry_image2']['name']);
			$sv_image_10=$sv_image_10 ?? '';
				copy($_FILES['industry_image2']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_10) or die("Image is not uploaded");
				copy($_FILES['industry_image2']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_10) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_10;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_10; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES['industry_image2']['type'] =="image/pjpeg" OR $_FILES['industry_image2']['type']=="image/jpeg" OR $_FILES['industry_image2']['type']=="image/png" OR
			$_FILES['industry_image2']['type']=="image/webp")){echo "Your uploaded file must be of JPG or GIF or PNG or Webp. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES['industry_image2']['type']=="image/pjpeg" OR $_FILES['industry_image2']['type']=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
		elseif($_FILES['industry_image2']['type']=="image/png"){ 
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
				elseif($_FILES['industry_image2']['type'] == "image/webp") {
                 $im = imagecreatefromwebp($add); // Create image from WebP
                 $width = imagesx($im); // Original picture width is stored
                 $height = imagesy($im); // Original picture height is stored
                 $newimage = imagecreatetruecolor($n_width, $n_height);
                 imagecopyresized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                 imagewebp($newimage, $tsrc); // Save thumbnail as WebP
                 chmod("$tsrc", 0777);
             }
			
				db_query("update tbl_material_used set industry_image2='".$sv_image_10."' where country_id = $page_id ");
		}
		set_session_msg("Material Used updated successfully.");	
	
	} else{	
	
	     ########### Uploading Image ################
		if($_FILES['sv_image']['name']!='')
		{
		    $sv_image=$sv_image ?? '';
			if(strlen($sv_image) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image);
			}
			$sv_image_1 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES['sv_image']['name']);
				copy($_FILES['sv_image']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_1) or die("Image is not uploaded");
				copy($_FILES['sv_image']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_1) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_1;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_1; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES['sv_image']['type'] =="image/pjpeg" OR $_FILES['sv_image']['type']=="image/jpeg" OR $_FILES['sv_image']['type']=="image/png" OR $_FILES['sv_image']['type']=="image/webp")){echo "Your uploaded file must be of JPG or GIF or PNG. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES['sv_image']['type']=="image/pjpeg" OR $_FILES['sv_image']['type']=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
			if($_FILES['sv_image']['type']=="image/png"){
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
			if ($_FILES['sv_image']['type'] == "image/webp") {
                 $im = imagecreatefromwebp($add); // Create image from WebP
                 $width = imagesx($im); // Original picture width is stored
                 $height = imagesy($im); // Original picture height is stored
                 $newimage = imagecreatetruecolor($n_width, $n_height);
                 imagecopyresized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                 imagewebp($newimage, $tsrc); // Save thumbnail as WebP
                 chmod("$tsrc", 0777);
             }
			
		}
			if($_FILES['industry_image1']['name']!='')
		{
		    $sv_image9=$sv_image9 ?? '';
			if(strlen($sv_image9) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image9)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image9);
			}
			$sv_image_9 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES['industry_image1']['name']);
			$sv_image_9=$sv_image_9 ?? '';
				copy($_FILES['industry_image1']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_9) or die("Image is not uploaded");
				copy($_FILES['industry_image1']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_9) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_9;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_9; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES['industry_image1']['type'] =="image/pjpeg" OR $_FILES['industry_image1']['type']=="image/jpeg" OR $_FILES['industry_image1']['type']=="image/png" OR
			$_FILES['industry_image1']['type']=="image/webp")){echo "Your uploaded file must be of JPG or GIF or PNG or Webp. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES['industry_image1']['type']=="image/pjpeg" OR $_FILES['industry_image1']['type']=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
		elseif($_FILES['industry_image1']['type']=="image/png"){ 
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
				elseif($_FILES['industry_image1']['type'] == "image/webp") {
                 $im = imagecreatefromwebp($add); // Create image from WebP
                 $width = imagesx($im); // Original picture width is stored
                 $height = imagesy($im); // Original picture height is stored
                 $newimage = imagecreatetruecolor($n_width, $n_height);
                 imagecopyresized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                 imagewebp($newimage, $tsrc); // Save thumbnail as WebP
                 chmod("$tsrc", 0777);
             }
			
		}	if($_FILES['industry_image2']['name']!='')
		{
		    $sv_image10=$sv_image10  ?? '';
			if(strlen($sv_image10) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image10)){
				@unlink(UP_FILES_FS_PATH."/banner/thumb/".$sv_image10);
			}
			$sv_image_10 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES['industry_image2']['name']);
			$sv_image_10=$sv_image_10 ?? '';
				copy($_FILES['industry_image2']['tmp_name'], UP_FILES_FS_PATH."/banner/thumb/".$sv_image_10) or die("Image is not uploaded");
				copy($_FILES['industry_image2']['tmp_name'], UP_FILES_FS_PATH."/banner/original/".$sv_image_10) or die("Image is not uploaded");
			$n_width=120; // Fix the width of the thumb nail images
			$n_height=90; // Fix the height of the thumb nail imaage
			
			$tsrc=UP_FILES_FS_PATH."/banner/thumb/".$sv_image_10;
			$add=UP_FILES_FS_PATH."/banner/original/".$sv_image_10; // Path where thumb nail image will be stored
			
			//echo $tsrc;
			if (!($_FILES['industry_image2']['type'] =="image/pjpeg" OR $_FILES['industry_image2']['type']=="image/jpeg" OR $_FILES['industry_image2']['type']=="image/png" OR
			$_FILES['industry_image2']['type']=="image/webp")){echo "Your uploaded file must be of JPG or GIF or PNG or Webp. Other file types are not allowed<BR>";
			exit;}
				///////// starting of JPG thumb nail creation//////////
			if($_FILES['industry_image2']['type']=="image/pjpeg" OR $_FILES['industry_image2']['type']=="image/jpeg")
			{
				$im=ImageCreateFromJPEG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
		elseif($_FILES['industry_image2']['type']=="image/png"){ 
				$im=ImageCreateFromPNG($add);
				$width=ImageSx($im); // Original picture width is stored
				$height=ImageSy($im); // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImagePng($newimage,$tsrc);
				chmod("$tsrc",0777);
			}
				elseif($_FILES['industry_image2']['type'] == "image/webp") {
                 $im = imagecreatefromwebp($add); // Create image from WebP
                 $width = imagesx($im); // Original picture width is stored
                 $height = imagesy($im); // Original picture height is stored
                 $newimage = imagecreatetruecolor($n_width, $n_height);
                 imagecopyresized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                 imagewebp($newimage, $tsrc); // Save thumbnail as WebP
                 chmod("$tsrc", 0777);
             }
			
		}
$industry_name = $_POST['industry_name'] ?? '';
$parent_childs = isset($_POST['parent_childs']) ? intval($_POST['parent_childs']) : 0;
if($parent_childs=='0'){
    $country_url=' ';
}
$country_status = $_POST['country_status'] ?? '0'; // Default to '0' (Inactive)
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$keyword = $_POST['keyword'] ?? '';
$country_title =$_POST['country_title'] ?? '';
$country_url =$_POST['country_url'] ?? '';
$country_descriptions = isset($_POST['country_descriptions']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions']))
    ) 
    : '';
$country_descriptions1 = isset($_POST['country_descriptions1']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions1']))
    ) 
    : '';
$country_descriptions2 = isset($_POST['country_descriptions2']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions2']))
    ) 
    : '';
 $country_descriptions3 = isset($_POST['country_descriptions3']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions3']))
    ) 
    : '';
    $country_descriptions4 = isset($_POST['country_descriptions4']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions4']))
    ) 
    : '';
    $country_descriptions5 = isset($_POST['country_descriptions5']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions5']))
    ) 
    : '';
    $country_descriptions6= isset($_POST['country_descriptions6']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions6']))
    ) 
    : '';
    $country_descriptions7 = isset($_POST['country_descriptions7']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions7']))
    ) 
    : '';
    $country_descriptions8 = isset($_POST['country_descriptions8']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['country_descriptions8']))
    ) 
    : '';
$conclusion = isset($_POST['conclusion']) 
    ? mysqli_real_escape_string(
        $GLOBALS['dbcon'],
        str_replace(["\r", "\n"], ' ', stripslashes($_POST['conclusion']))
    ) 
    : '';
$sv_image_1 = $sv_image_1 ?? ''; 
		 $sql = "insert into `tbl_material_used` set industry_name='$industry_name',  parent_childs='$parent_childs',country_status='$country_status', title='$title', description='$description', keyword='$keyword', country_title='$country_title', country_descriptions='$country_descriptions',country_descriptions1='$country_descriptions1',country_descriptions2='$country_descriptions2',country_descriptions3='$country_descriptions3',country_descriptions4='$country_descriptions4',country_descriptions5='$country_descriptions5',country_descriptions6='$country_descriptions6',country_descriptions7='$country_descriptions7',country_descriptions8='$country_descriptions8',conclusion='$conclusion', country_banner='$sv_image_1',industry_image1='$sv_image_9',industry_image2='$sv_image_10'";
	//	 print_r($sql);exit();
		db_query($sql);
		set_session_msg("New Material added successfully.");
	}
	header("Location: material_used_list.php?start=$start");
	exit;
}

$page_id = $_REQUEST['page_id'];
if($page_id!='') {
	$sql = "select * from `tbl_material_used` where country_id = '$page_id'";
	$result = db_query($sql);
	if ($line_raw = mysqli_fetch_array($result)) {
		//$line_raw = ms_form_value($line_raw);
		@extract($line_raw);
	}
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">

<? include("top.inc.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="pageHead"><div id="txtPageHead">
       Add/Edit Industry</div></td>
  </tr>
</table>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<table width="80%" align="left">
		  	<tr><td>
		  	<form method="post" action="" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return validate(this);">
        <table width="80%" align="center" border=0 cellpadding="0"  cellspacing="0" class="text">
    	<tr>
<?php
$start = isset($_GET['start']) ? intval($_GET['start']) : 0; // Ensure `$start` is defined
?>
<td colspan="2" height="30" align="right">
    <a href="material_used_list.php?start=<?=$start?>" class="redcolor">
        <strong>Back To Material Used List</strong>
    </a>
</td>		</tr>    
        <tr><td height="15"><div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br /></td></tr>  
		

        <tr><td>&nbsp;</td></tr>
        
        
        <tr>
		  <td class="lables"><b>Material Name</b></td>
          <td class="feildstxt"><input type="text" style="width:300px;" value="<?=stripslashes($industry_name)?>" name="industry_name" id="industry_name"  /></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <?php  $pcqry = db_query("select country_id,industry_name from `tbl_material_used` where parent_childs='0' ");	?>
        <tr>
		  <td class="lables"><b>Parent</b></td>
          <td class="feildstxt"><select name="parent_childs" id="parent_childs">
          <option value="0" <?php if($parent_childs=='0'){ echo 'selected="selected"'; } ?>>None</option>
          <?php while($parentData = mysqli_fetch_assoc($pcqry)){ ?>  
          <option value="<?php echo $parentData['country_id']; ?>" <?php if($parentData['country_id']==$parent_childs){ echo 'selected="selected"'; } ?>><?php echo $parentData['industry_name']; ?></option>      
          <?php } ?>    
          </select></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
      

		<tr>
		  <td class="lables"><b>Status</b></td>
		  <?php $country_status = $country_status ?? ''; // Ensure variable exists
 ?>
          <td class="feildstxt"><select name="country_status" id="country_status">
          <option value="1" <?php if($country_status=='1'){ echo 'selected="selected"'; } ?>>Active</option>
          <option value="0" <?php if($country_status=='0'){ echo 'selected="selected"'; } ?>>InActive</option>          
          </select></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables" colspan="2"><hr/></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables"><b>Title </b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="title" id="title"  ><?=stripslashes($title)?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables"><b>Description </b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="description" id="description"  ><?=stripslashes($description)?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables"><b>Keyword</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="keyword" id="keyword"  ><?=stripslashes($keyword)?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables" colspan="2"><hr/></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables"><b>Banner Image</b></td>
          <td class="feildstxt"><input type="file" name="sv_image" id="sv_image"  /></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Current Banner Image</b></td>
          <td class="feildstxt"><?php if (!empty($sv_image) && file_exists(UP_FILES_FS_PATH."/banner/original/".$sv_image)) {
    $imgPath = UP_FILES_FS_PATH."/banner/original/".$sv_image;
    $imgsrcBig = UP_FILES_WS_PATH."/banner/original/".$sv_image;
    $size = getimagesize($imgPath);
    
    if ($size !== false) {
        $mime = $size['mime'];

        switch ($mime) {
            case 'image/jpeg':
                $img = imagecreatefromjpeg($imgPath);
                break;
            case 'image/png':
                $img = imagecreatefrompng($imgPath);
                break;
            case 'image/gif':
                $img = imagecreatefromgif($imgPath);
                break;
            default:
                $img = false;
                echo 'Unsupported image type.';
                break;
        }

        if ($img !== false) {
            $width = imagesx($img);
            $height = imagesy($img);
            // Show image preview if you want
            echo '<img src="'.$imgsrcBig.'" width="'.$width.'" height="'.$height.'" alt="Preview">';
        } else {
            echo 'Could not load image.';
        }
    } else {
        echo 'Invalid image file.';
    }
}
?></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Title</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_title" id="country_title"  ><?=stripslashes($country_title)?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Url</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_url" id="country_url"  ><?=stripslashes($country_url)?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
        <tr>
		  <td class="lables"><b>Material Descriptions1</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions" id="country_descriptions"  ><?=stripslashes($country_descriptions ?? '')?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        
          <tr>
		  <td class="lables"><b>Material Descriptions2</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions1" id="country_descriptions1"  ><?=stripslashes($country_descriptions1 ?? '')?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions3</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions2" id="country_descriptions2"  ><?=stripslashes($country_descriptions2 ?? '')?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions4</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions3" id="country_descriptions3"  ><?=stripslashes($country_descriptions3 ?? '')?></textarea></td>
        </tr>
         <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions5</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions4" id="country_descriptions4"  ><?=stripslashes($country_descriptions4 ?? '')?></textarea></td>
        </tr>
         <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions6</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions5" id="country_descriptions5"  ><?=stripslashes($country_descriptions5 ?? '')?></textarea></td>
        </tr>
         <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions7</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions6" id="country_descriptions6"  ><?=stripslashes($country_descriptions6 ?? '')?></textarea></td>
        </tr>
         <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions8</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions7" id="country_descriptions7"  ><?=stripslashes($country_descriptions7 ?? '')?></textarea></td>
        </tr>
         <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Material Descriptions9</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="country_descriptions8" id="country_descriptions8"  ><?=stripslashes($country_descriptions8 ?? '')?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Conclusion</b></td>
          <td class="feildstxt"><textarea style="width:300px;" name="conclusion" id="conclusion"  ><?=stripslashes($conclusion ?? '')?></textarea></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr><td>&nbsp;</td></tr>
            <tr>
		  <td class="lables"><b>Material Used Image1</b></td>
          <td class="feildstxt"><input type="file" name="industry_image1" id="industry_image1"  /></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Current Material Used Image1</b></td>
          <td class="feildstxt"><?php
if ($page_id != '') {
    $sv_image9 = $industry_image1;

    // Show thumbnail
    if (strlen($sv_image9) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image9)) {
        $imgsrc = UP_FILES_WS_PATH."/banner/thumb/".$sv_image9;
        echo '<img src="'.$imgsrc.'" alt="No Image" />';
    } else {
        echo 'NO Images';
    }

    // Work with original
    if (strlen($sv_image9) && file_exists(UP_FILES_FS_PATH."/banner/original/".$sv_image9)) {
        $imgsrcBig = UP_FILES_FS_PATH."/banner/original/".$sv_image9;

        // detect image type
        $info = getimagesize($imgsrcBig);
        $mime = $info['mime'];

        switch ($mime) {
            case 'image/jpeg':
                $img = imagecreatefromjpeg($imgsrcBig);
                break;
            case 'image/png':
                $img = imagecreatefrompng($imgsrcBig);
                break;
            case 'image/gif':
                $img = imagecreatefromgif($imgsrcBig);
                break;
            default:
                $img = false;
                break;
        }

        if ($img) {
            $width  = imagesx($img);
            $height = imagesy($img);
        } else {
            echo "Unsupported image type: $mime";
        }
    }
}
?></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
             <tr>
		  <td class="lables"><b>Material Used Image2</b></td>
          <td class="feildstxt"><input type="file" name="industry_image2" id="industry_image2"  /></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
		  <td class="lables"><b>Current Material Used Image2</b></td>
          <td class="feildstxt"><?php
if ($page_id != '') {
    $sv_image10 = $industry_image2;

    // Show thumbnail
    if (strlen($sv_image10) && file_exists(UP_FILES_FS_PATH."/banner/thumb/".$sv_image10)) {
        $imgsrc = UP_FILES_WS_PATH."/banner/thumb/".$sv_image10;
        echo '<img src="'.$imgsrc.'" alt="No Image" />';
    } else {
        echo 'NO Images';
    }

    // Work with original
    if (strlen($sv_image10) && file_exists(UP_FILES_FS_PATH."/banner/original/".$sv_image10)) {
        $imgsrcBig = UP_FILES_FS_PATH."/banner/original/".$sv_image10;

        // detect image type
        $info = getimagesize($imgsrcBig);
        $mime = $info['mime'];

        switch ($mime) {
            case 'image/jpeg':
                $img = imagecreatefromjpeg($imgsrcBig);
                break;
            case 'image/png':
                $img = imagecreatefrompng($imgsrcBig);
                break;
            case 'image/gif':
                $img = imagecreatefromgif($imgsrcBig);
                break;
            default:
                $img = false;
                break;
        }

        if ($img) {
            $width  = imagesx($img);  // Original picture width
            $height = imagesy($img);  // Original picture height
        } else {
            echo "Unsupported image type: $mime";
        }
    }
}?></td>
        </tr>
        <tr><td>&nbsp;</td></tr>
     
        <tr>
        <td align="left" class="lables">&nbsp;</td>
        <td align="left" class="feildstxt"><input class="button" type="submit" name="submit" value="Save"></td>
        </tr>
        <tr><td height="25">&nbsp;</td></tr>
   </table>
    </form>
    </td></tr></table> 
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions1','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions2','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions3','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions4','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions5','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions6','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions7','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
     <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_descriptions8','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('conclusion','650','300')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    
   <!-- <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_ad1','650','200')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_ad2','650','200')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   
    <script type="text/javascript">
		 var oFCKeditor=new FCKeditor('country_ad3','650','200')	;
		 oFCKeditor.BasePath="fckeditor/";	
		 oFCKeditor.ReplaceTextarea();
    </script>   -->
  <? include("bottom.inc.php");?>