<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');
@extract($_REQUEST);

if (empty($catID)) {
	$heading="Add New Career";
}
else {
	$heading="Edit Career";
}

$record_type="career";
$script_name="addeditcareer.php";
$redirect_script_name="manage_career.php";
$table_name="career_tbl";
#################### Add Record ##################
if($id=='remove_image'){
	mysqli_query("UPDATE $table_name SET $field='' where catID = '$catID'");
	$_SESSION[session_message]=$record_type.' has been updated successfully';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
	exit;
}
if($_REQUEST[action]=="add_record" && $catName!="") {
	
	$numCnt=getCount($table_name," where catName='$catName' and parentID='$parentID' and catID!='$catID' ");
	if($numCnt>0) {
		$_SESSION[session_message]=$record_type.' already exist';
	}
	else{
		if($_FILES[image][name]!=""){
			$file_extension=strtolower(getExtension($_FILES[image][name]));
			if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png"){
				$_SESSION[session_message]='Please upload image (.jpg,.gif,.png Format Only)';
				header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
				exit;
			}
			if($_FILES[image][name]!=""){
				$cat=str_replace(" ", "-", $catName);
				$img_name=$cat.date("s");
				$img=upload_file($img_name,"image","uploaded-files/blog/images");	
			}
		}		
		if($_FILES[image1][name]!=""){
			$cat=str_replace(" ", "-", $catName);
			$img_name1="b1".date("s");				
			$img1=upload_file($img_name1,"image1","uploaded-files/blog/banners");	
		}
		if($_FILES[image2][name]!=""){
			$cat=str_replace(" ", "-", $catName);
			$img_name2="b2".date("s");
			$img2=upload_file($img_name1,"image2","uploaded-files/blog/banners");	
		}
		
		$maxRes=db_fetch_array(db_query("select max(catOrder) from $table_name where parentID='$parentID'"));
		$catOrder=$maxRes[0]+1;
		if($blogDname == ''){
			$blogDname = $catName;
		}
		$sql=db_query("insert into $table_name set parentID='$parentID', catName='$catName', catDesc='$catDesc', catDesc1='$catDesc1', catDesc2='$catDesc2', catDesc3='$catDesc3',  catOrder='$catOrder',experience='$experience	',salary='$salary', location='$location',   blogDate='$blog_date'");
		$_SESSION[session_message]=$record_type.' has been added successfully';
		header("Location: ".SITE_ADMIN_URL."/".$redirect_script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
		exit;
	}
}

################ Update Record ##################

if($_REQUEST[action]=="update_record" && $catName!="" ) {
	
	$numCnt=getCount($table_name," where catName='$catName' and parentID='$parentID' and catID!='$catID'");
	if($numCnt>0) {
		$_SESSION[session_message]=$record_type.' already exist';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
		exit;
	}
	
	if($_FILES[image][name]!=""){
		$file_extension=strtolower(getExtension($_FILES[image][name]));
		if($file_extension!="jpg" && $file_extension!="gif" && $file_extension!="jpeg" && $file_extension!="png"){
			$_SESSION[session_message]='Please upload image (.jpg,.gif,.png Format Only)';
			header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
			exit;
		}
		if($_FILES[image][name]!=""){
			$categoryRes=getResult($table_name," where catID='$catID'","catImage");
			$filename=$categoryRes['catImage'];
			if($filename!="") {
				$file=SITE_DIR_PATH."/uploaded-files/blog/images/".$filename;
				if(file_exists($file)) {
					unlink($file);
				}
			}
			$cat=str_replace(" ", "-", $catName);
			$img_name=$cat.date("s");
			$img=upload_file($img_name,"image","uploaded-files/blog/images");
			updateTable($table_name," catImage='$img' where catID='$catID'");
		}
	}
	if($_FILES[image1][name]!=""){
			$categoryRes=getResult($table_name," where catID='$catID'","banner1");
			$filename=$categoryRes['banner1'];
			if($filename!="") {
				$file=SITE_DIR_PATH."/uploaded-files/blog/banners/".$filename;
				if(file_exists($file)) {
					unlink($file);
				}
			}
			$cat=str_replace(" ", "-", $catName);
			$img_name1="b1".date("s");
			$img1=upload_file($img_name1,"image1","uploaded-files/blog/banners");
			updateTable($table_name," banner1='$img1' where catID='$catID'");
		}

if($_FILES[image2][name]!=""){
			$categoryRes=getResult($table_name," where catID='$catID'","banner2");
			$filename=$categoryRes['banner2'];
			if($filename!="") {
				$file=SITE_DIR_PATH."/uploaded-files/blog/banners/".$filename;
				if(file_exists($file)) {
					unlink($file);
				}
			}
			$cat=str_replace(" ", "-", $catName);
			$img_name2="b2".date("s");
			$img2=upload_file($img_name2,"image2","uploaded-files/blog/banners");
			updateTable($table_name," banner2='$img2' where catID='$catID'");
		}
		if($blogDname == ''){
			$blogDname = $catName;
		}
	updateTable($table_name," catName='$catName',  catDesc='$catDesc', catDesc1='$catDesc1', catDesc2='$catDesc2', catDesc3='$catDesc3',  experience='$experience	',salary='$salary', location='$location',  blogDate='$blog_date' where catID='$catID'");
  $_SESSION[session_message]=$record_type.' has been updated successfully';
	header("Location: ".SITE_ADMIN_URL."/".$redirect_script_name."?start=".$start."&parentID=".$parentID."&catID=".$catID."&pagesize=".$pagesize);
	exit;
}
########################################################
admin_header();
?>

<div align="left" class="myTitle"><?=$heading;?></div>
<hr size="2" width="100%" color="#92B2D6">
<?php
print_message();
$res=getResult($table_name," where catID='$catID'");

	$catName=$res[catName];
	$catDesc=$res[catDesc];
	$catDesc1=$res[catDesc1];
$catDesc2=$res[catDesc2];
$catDesc3=$res[catDesc3];
    $experience=$res[experience];
    $blog_date=$res[blogDate];
 $salary=$res[salary];

	$location=$res[location];



?>

<table width="100%"  border="0" cellpadding="0" cellspacing="2">
 <tr>
  <td align="right"><input type="button" class="button" value="Go Back To Manage <?=$record_type;?>" onclick="window.location.href='<?=SITE_ADMIN_URL?>/<?=$redirect_script_name;?>?parentID=<?=$parentID;?>&catID=<?=$catID;?>&start=<?=$start;?>&pagesize=<?=$pagesize;?>';"></td>
 </tr>
</table><br />

<form name="formn" method="post" action="" enctype="multipart/form-data" onsubmit="return validate(this);">
<?=$msg;?>
<table width="100%"  border="0" cellpadding="0" cellspacing="2" class="lightBorder">
 <tr>
  <td class="brdrbtm" width="125"><b>Job Title</b>*</td>
<td class="brdrbtm">
    <div class="form-group">
   <input name="catName" class="txtfieldadmin" size="70" value="<?=$catName?>" id="NOBLANK~Please enter category name~DM~">
    </div>
  </td>
 </tr>
 <tr>
  <td class="brdrbtm" width="125"><b>Experience</b>*</td>
<td class="brdrbtm">
    <div class="form-group">
   <input name="experience" class="txtfieldadmin" size="70" value="<?=$experience?>" id="NOBLANK~Please enter category name~DM~">
    </div>
  </td>
 </tr>
    <tr>
  <td class="brdrbtm" width="125"><b>Location</b>*</td>
<td class="brdrbtm">
    <div class="form-group">
   <input name="location" class="txtfieldadmin" size="70" value="<?=$location?>" id="NOBLANK~Please enter category name~DM~">
    </div>
  </td>
 </tr>
	<tr>
  <td class="brdrbtm" width="125"><b>Salary Expected</b>*</td>
<td class="brdrbtm">
    <div class="form-group">
   <input name="salary" class="txtfieldadmin" size="70" value="<?=$salary?>" id="NOBLANK~Please enter Blog Written by name~DM~">
    </div>
  </td>
 </tr>
 <tr>
  <td class="brdrbtm" width="125"><b>Post Date</b>*</td>
<td class="brdrbtm">
    <div class="form-group">
   <input name="blog_date" type="date" size="70" value="<?=$blog_date?>" id="NOBLANK~Please enter Blog Written by name~DM~">
    </div>
  </td>
 </tr>
 
<script type="text/javascript" src="tinymce1/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
    selector: "textarea"
 });
</script>
 <tr>
  <tr>
  <td class="brdrbtm"><b>Job Description</b></td>
      <td class="brdrbtm">  <div class="form-group"><textarea name="catDesc3" id="catDesc3" rows="5" cols="30" class="txtfieldadmin" ><?=$catDesc3?></textarea></div></td>

 </tr>
    <tr>
  <td class="brdrbtm"><b>Qualification</b></td>
    <td class="brdrbtm">  <div class="form-group"><textarea name="catDesc" id="catDesc" rows="5" cols="30" class="txtfieldadmin" ><?=$catDesc?></textarea></div></td>

 </tr>
  <tr>
  <td class="brdrbtm"><b> Responsibilities</b></td>
      <td class="brdrbtm">  <div class="form-group"><textarea name="catDesc1" id="catDesc1" rows="10" cols="70" class="txtfieldadmin" ><?=$catDesc1?></textarea></div></td>
 </tr>
    <tr>
  <td class="brdrbtm"><b> Key Skills</b></td>
      <td class="brdrbtm">  <div class="form-group"><textarea name="catDesc2" id="catDesc2" rows="10" cols="70" class="txtfieldadmin" ><?=$catDesc2?></textarea></div></td>
 </tr>
<script type="text/javascript">
	var oFCKeditor=new FCKeditor('catDesc1');
	oFCKeditor.BasePath="fckeditor/";
	oFCKeditor.Width="600px";
	oFCKeditor.Height="400px";
	oFCKeditor.ReplaceTextarea();
	</script>
 
 <tr>
  <td></td>
  <td class="brdrbtm">
        <div class="form-group">
   <?php
   if($res[catID]=="") {
	   ?>
	   <input type="submit" name="add_record" class="button" value="Add <?=$record_type;?>"><input type="hidden" name="action" value="add_record">
	   <?php	   
   }
   else{
	   ?>
	   <input type="submit" name="update_record" class="button" value="Update <?=$record_type;?>"><input type="hidden" name="action" value="update_record">
	   <?php	   
   }
   ?>
   &nbsp;&nbsp;<input type="button" name="cancel" class="button" value="Cancel" onclick="javascript: window.location.href='<?=SITE_ADMIN_URL;?>/<?=$redirect_script_name;?>?parentID=<?=$parentID;?>&catID=<?=$catID;?>&start=<?=$start;?>&pagesize=<?=$pagesize;?>'">  
      </div>
  </td>
 </tr>
</table>
</form>

<?php
admin_footer();
exit;
?>