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

		$objUploadMgmt = new cms_uploadMgmt();
		$objUploadMgmt->upload_id		= $_REQUEST['upload_id'];
		$objUploadMgmt->branch_id		= $_REQUEST['branch_hidden'];
		$objUploadMgmt->year_id	= $_REQUEST['year_hidden'];
		$objUploadMgmt->branchyear_id	= $_REQUEST['branchyear_hidden'];
		$objUploadMgmt->semester_id	= $_REQUEST['semester_hidden'];
		$objUploadMgmt->subject_id 	= $_REQUEST['subject_hidden'];
		$objUploadMgmt->title 	= $_REQUEST['title'];
		$objUploadMgmt->description 	= $_REQUEST['description'];
		$objUploadMgmt->assignment_date=$_REQUEST['assignment_date'];
		$objUploadMgmt->submission_date=$_REQUEST['submission_date'];
		$objUploadMgmt->college_id = $_SESSION["VedantnrCollegeId"] ;
		$objUploadMgmt->active 	= ($_REQUEST['active']=='on'?1:0);
	
		if($objUploadMgmt->upload_id == 0){
			$objUploadMgmt->add();
		}
		else{			
			if($_REQUEST['act'] == "del"){
				$old_upload_file=$CollegeImagePath . $_REQUEST['old_upload_file'];	
				if (file_exists($old_upload_file)) {
                    unlink($old_upload_file);
                }
				$objUploadMgmt->delete();
			}else{
				$objUploadMgmt->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 	  = $objUploadMgmt->upload_id;
				$Ext = substr($FileName, strrpos($FileName, ".")+1);
				$Ext = strtolower($Ext);
				$thumbimg = "upload_" . $ID . "." . $Ext;
				$thumbimg_path = $CollegeImagePath  . $thumbimg;		
				$old_upload_file= $CollegeImagePath . $_REQUEST['old_upload_file'];	
				
				if (file_exists($old_upload_file)) {
                    unlink($old_upload_file);
                }
				if (file_exists($thumbimg_path)) {
                    unlink($thumbimg_path);
                }
                if (!is_dir($CollegeImagePath)) {
                    mkdir($CollegeImagePath, 0755);
                    chmod($CollegeImagePath, 0755);
                }
                copy($_FILES['file_name']['tmp_name'], $thumbimg_path);
                $file_path=realpath($thumbimg_path);
                chmod($file_path,0644);
				$objUploadMgmt->file_name = $thumbimg;
				$objUploadMgmt->updatefile();
            }          
        }
	
		echo '{"success":"true"}';
	}
	else
	{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>