<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{

		$objcms_upload_filesMgmt= new UploadfilesMgmt();
		$objcms_upload_filesMgmt->upload_file_id=$_POST['upload_file_id'];
		$objcms_upload_filesMgmt->upload_id=$_POST['upload_hidden'];
		$objcms_upload_filesMgmt->title=$_POST['title'];
		$objcms_upload_filesMgmt->active=($_POST['active']=='on'?1:0);
		$objcms_upload_filesMgmt->assignment_date=$_POST['assignment_date'];
		$objcms_upload_filesMgmt->submission_date=$_POST['submission_date'];
		
		if($objcms_upload_filesMgmt->upload_file_id == "0" ||  $objcms_upload_filesMgmt->upload_file_id== ""){ 
		$objcms_upload_filesMgmt->add(); 
		} 
		else{
		if($_REQUEST['act'] == "del")
		 {	$objcms_upload_filesMgmt->delete();
		 }
		 else{
			 $objcms_upload_filesMgmt->edit();
			}
			
		 }
		 
		 if (isset($_FILES['file_name']['name']) && !empty($_FILES['file_name']['name'])) {
            if (strlen($_FILES['file_name']['name']) > 0) {
               
			    $FileName = $_FILES['file_name']['name'];
				$ID 	  = $objcms_upload_filesMgmt->upload_file_id;

                $thumbimg = $ID.'_'.$FileName;
                $thumbimg_path = $StudentImagePath."/".$thumbimg;

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

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

                $file_path=realpath($thumbimg_path);
                chmod($file_path, 0644);
								
				$objcms_upload_filesMgmt->file_name = $thumbimg;
				$objcms_upload_filesMgmt->updatefile();
				
            } else {
                $thumbimg = "";
            }            
        }	
		echo'{"success":"true"}'; 
	}
	else
	{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>