<?php 
require "commonincludefiles.php";
//-------------------------

$objcms_circularmasterMgmt= new cms_circularmasterMgmt();


$objcms_circularmasterMgmt->circular_id=$_POST['circular_id'];
$objcms_circularmasterMgmt->branch_id=$_POST['branch_hidden'];
$objcms_circularmasterMgmt->year_id=$_POST['year_hidden'];
$objcms_circularmasterMgmt->branchyear_id=$_POST['branchyear_hidden'];
$objcms_circularmasterMgmt->semester_id=$_POST['semester_hidden'];
//$objcms_circularmasterMgmt->student_id=$_POST['student_id'];
//$objcms_circularmasterMgmt->employee_id=$_POST['employee_id'];

if($_POST['all_student_id']=='on')
{
	$objcms_circularmasterMgmt->all_student_id= 1;
}

if($_POST['all_employee_id']=='on')
{
	$objcms_circularmasterMgmt->all_employee_id= 1;
}

if($_POST['circular_active']=='on')
{
	$objcms_circularmasterMgmt->circular_active= 1;
}
$objcms_circularmasterMgmt->circular_type=$_POST['circulartype_hidden'];
$objcms_circularmasterMgmt->circular_title=$_POST['circular_title'];
$objcms_circularmasterMgmt->circular_subject=$_POST['circular_subject'];
$objcms_circularmasterMgmt->circular_file=$_POST['circular_file'];

$objcms_circularmasterMgmt->circular_start_date=$_POST['circular_start_date'];
$objcms_circularmasterMgmt->circular_end_date=$_POST['circular_end_date'];

/*if($objcms_circularmasterMgmt->circular_id == "0" ||  $objcms_circularmasterMgmt->circular_id== ""){ 
	$objcms_circularmasterMgmt->add(); 
} 
else{
	if($_REQUEST[act] == "del")
	 {$objcms_circularmasterMgmt->delete();
	 }else
	 {$objcms_circularmasterMgmt->edit();
	}
	echo'{"success":"true"}'; 
 }
*/


	if($_REQUEST['act'] != "del"){
		if($_REQUEST['circular_id'] > 0){
			$objcms_circularmasterMgmt->edit();
		} else if($_REQUEST['circular_id'] == 0 || $_REQUEST["circular_id"] ==""){
			$objcms_circularmasterMgmt->add();
		} 
	} else if($_REQUEST['act'] == "del"){
		$objcms_circularmasterMgmt->delete();
	}
	
	
	if (isset($_FILES['newPic']['name']) && !empty($_FILES['newPic']['name'])) {
            if (strlen($_FILES['newPic']['name']) > 0) {
                $FileName = $_FILES['newPic']['name'];
                $Ext = substr($FileName, strrpos($FileName, ".")+1);
                $Ext = strtolower($Ext);
				$CircularImagePath="circular/";
			    $circular_id = $objcms_circularmasterMgmt->circular_id;
                $thumbimg = "circular_" . $circular_id . "." . $Ext;
                $thumbimg_path = $CircularImagePath . $thumbimg;

                if (file_exists($thumbimg_path)) {
                    unlink($thumbimg_path);
                }

                if (!is_dir($CircularImagePath)) {
                    mkdir($CircularImagePath, 0755);
                    chmod($CircularImagePath, 0755);
                }
                copy($_FILES['newPic']['tmp_name'], $thumbimg_path);

                $file_path=realpath($thumbimg_path);
                chmod($file_path, 0644);
				
				/* start resizing */
                   if (preg_match("/(jpg|gif|png|jpeg)/",$Ext))	{												
						$objResizeImage = new ResizeImageMgmt();
						$objResizeImage->resize($thumbimg_path,100,100,true,true);//name,w,h, blnfixheight
				 	}
				/* end resizing */	
						
				$objcms_circularmasterMgmt->circular_id=$circular_id;
				$objcms_circularmasterMgmt->circular_file = $thumbimg;
				$objcms_circularmasterMgmt->updatePhoto();
				
            } else {
                $thumbimg = "default.gif";
            }            
        }	
	
	echo '{"success":"true"}';  
?>
