0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.216.126.33


Current Path : /var/www/oasis/src_old/
Upload File :
Current File : /var/www/oasis/src_old/upload_studentPhoto.php

<?php
// DateTime.Now.Second.ToString()
session_start();
require_once(__DIR__."/../../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

function replaceChars($name)
{
	$spl_char = array("*","/","~","!","@","#","$","%","^","&",":",";","?","/","\\","_","-","'"," ","");
	$link_name = strtolower(str_replace($spl_char,"_",$name));
	return str_ireplace("__","_",$link_name);
}

function viewStudInfoToupload($aobj_context)
{	
	session_start();
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);  
	
	$college_code = $_SESSION['collcode']; 
	$degree_code = $aobj_context->mobj_data['degreeCode']; 
	$_SESSION['degree_codeImgUp']=$degree_code;
	$RegNo_start = substr("00000000".$aobj_context->mobj_data["regStart"],-8); 
	$RegNo_end = substr("ZZZZZZZZ".$aobj_context->mobj_data["regEnd"],-8); 
	
	
	$get_studentInfo = "select * from student where fcollcode = '{$college_code}' and fdegree ='{$degree_code}' and fregno between '{$RegNo_start}' and '{$RegNo_end}' order by fregno";
	$lobj_get_studentInfo = $aobj_context->mobj_db->getAll($get_studentInfo);
	
	$get_currentDate = "select CONCAT(DATE_FORMAT(NOW(),'%Y'),DATE_FORMAT(NOW(),'%m'),DATE_FORMAT(NOW(),'%d'),DATE_FORMAT(CURTIME(),'%r')) as currentDate";
	$lobj_get_currentDate=$aobj_context->mobj_db->getRow($get_currentDate);
	
	$currentDate = $lobj_get_currentDate[currentDate];
	 
	if($lobj_get_studentInfo)
	{
		$e_data.="<table  align = 'center' width='100%' cellspacing='0' cellpadding='1' border='0' >";
		$e_data.="<th align='left' colspan='6' class='ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper' style='font-size:12px; padding-left:6px; height:24px;'>Photo Upload List</th>";
		$e_data.="<tr class='ui-state-default ui-jqgrid-hdiv'>";
		$e_data.="<td align='center' style='width:55px; font-size:12px;  border-left:1px solid #C5DBEC;border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>Sl.No.</td>";
		$e_data.="<td align='center' style='width:105px; font-size:12px;  border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>Register No.</td>";
		$e_data.="<td align='center' style='width:205px; font-size:12px;   border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>Name</td>";
		$e_data.="<td align='center' style='width:105px; font-size:12px;  border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>Degree Code</td>";
		$e_data.="<td align='center' style='width:155px; font-size:12px;  border-right:1px solid #C5DBEC; border-bottom:1px solid #C5DBEC;'>Photo</td>";

		$e_data.="</tr>";							

		$k=0;
		$id=1;
		$m=0;
		//var_dump($lobj_get_moudle_names); die();
		$counter_degree = 1;
		foreach($lobj_get_studentInfo as $key=>$value)
		{
		if($k%2==0)
		{
		$class='tbl_row';
		$inp_class='tbl_row_input';
		}
		else
		{
		$input_class='tbl_row1'; 
		$inp_class='tbl_row1_input';
		}  
		$image_src='';
		$photo_path=$value['FPHOTOPATH'];
		$f_regno = $value['FREGNO'];
		$imagePath = "https://university-student-photos.s3.ap-south-1.amazonaws.com/".$_SESSION['FUNIVCODE']. "/". $photo_path;
		// var_dump($imagePath);
		// die();

		if(!empty($photo_path) && file_exists($photo_path)) 
		{			
			$image_src = $photo_path.'?'.$currentDate;

			$upload = "<div style = 'display:;'><span >
		<input type='hidden' id='hd_regno_{$id}' value='{$f_regno}'>
		<input type='file'  id='student_entry_upload_{$id}' name='student_entry_upload_{$id}' 
		onchange='UserSelectedPhotoDisplay({$id},\"{$value[FREGNO]}\");' style='width:75px'></span>
		<span style='padding:5px 5px;'><input type='submit' style = 'display:;' value='Upload' onclick='UserSelectedPhotoUpload({$id})'></span></div>";
		}
		else
		{
			$image_src = "images/default_photo.jpg";															
			$upload = "<div><span ><input type='hidden' id='hd_regno_{$id}' value='{$f_regno}'>
		<input type='file'  id='student_entry_upload_{$id}' name='student_entry_upload_{$id}' onchange='UserSelectedPhotoUpload({$id},\"{$value[FREGNO]}\");' style='width:75px'></span>
		<span style='padding:5px 5px;'><input type='submit' value='Upload' onclick='UserSelectedPhotoUpload({$id},\"{$value[FREGNO]}\")'></span></div>";
		}
				
		$e_data.="<tr class='ui-widget-content jqgrow'>";	
		$e_data.="<td class='tbl_row_new' style='border-left:1px solid #C5DBEC; border-right:1px solid #C5DBEC; padding:2px; font-size:12px;text-align:center; ' id='it_cnt_{$id}' >{$counter_degree}</td>";				
		$e_data.="<td class='tbl_row_new' style='border-right:1px solid #C5DBEC; padding:2px; font-size:12px;text-align:center; ' id='it_mname_{$id}' >{$value[FREGNO]}</td>";
		$e_data.="<td class='tbl_row_new' style=' border-right:1px solid #C5DBEC; padding:2px; font-size:12px; '  id='it_dname_{$id}' >{$value[FNAME]}</td>";
		$e_data.="<td class='tbl_row_new' style='border-right:1px solid #C5DBEC; padding:2px; font-size:12px; text-align:center;' id='it_mname_{$id}' >{$value[FDEGREE]}</td>";
		$e_data.="<td class='tbl_row_new' style='border-right:1px solid #C5DBEC; padding:2px; font-size:12px;height:120px;width:200px;' id='it_mname_{$id}' ><span style='margin-left:20px;background:#EEEEE;'>
		<img src='{$imagePath}' id='student_entry_photo_{$id}' width='100px' height='70px'/></span>{$upload}</td>";//src='{$image_src}
		$e_data.="</tr>";
		$k++;
		$id++;
		$m++;
		$counter_degree++;
		}
		$e_data.="</table>";
		$arr['total_count']= $m;						
		$arr['html']=$e_data;
		$arr['error']=0;
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
	}
	else
	{
		$error_data = 'No Records Found.. ';
		echo $aobj_context->mobj_output->ToJSONEnvelope($error_data,-1,"failure"); 
		return;
	}
}


function saveUserSelectedPhotoUpload($aobj_context)
{
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	session_start();
	$degree_code = $_SESSION['degree_codeImgUp'];
	$college_code = $_SESSION['collcode']; 
	$user_id = $_SESSION['user_id']; 
	$FUNIVCODE = $_SESSION['FUNIVCODE'];
	$img_index = $aobj_context->mobj_data['index'];
	$regno_index = $aobj_context->mobj_data['regno'];
	
	$college_path=$aobj_context->main_src."/student_photos/{$college_code}";
	$folder_path=$aobj_context->main_src."/student_photos/{$college_code}/".replaceChars(strtolower($degree_code));
	$file_name=basename($_FILES['student_entry_upload_'.$img_index]['name']);
	// $file_name=replaceChars(basename($_FILES['student_entry_upload_'.$img_index]['name']));
	$path_arr=pathinfo($_FILES['student_entry_upload_'.$img_index]['name']);
	$file_ext=$path_arr['extension'];
	$ext = pathinfo($file_name, PATHINFO_EXTENSION);
	$full_file_path= $folder_path.'/'.$regno_index.".".$ext;
	$image_path="student_photos/{$college_code}/".replaceChars(strtolower($degree_code)).'/'.$regno_index.".".$ext;
	$photo_path="";
	$filePath = realpath($_FILES['student_entry_upload_'.$img_index]['tmp_name']);
	$S3filePath = $_SESSION['FUNIVCODE']."/student_photos/{$college_code}/".replaceChars(strtolower($degree_code))."/{$regno_index}.".$ext;

	$s3 = S3Client::factory(
		array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		)
	);
	
		if(isset($_FILES['student_entry_upload_'.$img_index]['name']) && $_FILES['student_entry_upload_'.$img_index]['name'] != '')         
		{ 
			$size=($_FILES['student_entry_upload_'.$img_index]['size']/1024);
			if($size>1024)
			{
			$data="Please Upload the Photo of size less than 1 MB";
				echo $aobj_context->mobj_output->ToJSONEnvelope($data,-2,"success"); 
				return;
			}

			// $result =  move_uploaded_file($_FILES['student_entry_upload_'.$img_index]['tmp_name'],$full_file_path)

			$result = $s3->putObject(['Bucket' => 'university-student-photos', 'Key' => $S3filePath, 'SourceFile' => $filePath]);
	
			if($result)
			{
				$photo_path=$image_path;
			}
		}
			
			$update_qry = "update student set FPHOTOPATH='{$photo_path}' where FREGNO='{$regno_index}' 
			and FDEGREE='{$degree_code}' and FCOLLCODE='{$college_code}'";

			$lobj_rs = $aobj_context->mobj_db->Execute($update_qry);
			if($lobj_rs)
			{	
				$arr='Photo Uploaded Successfully';
		
				echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
			}
			else
			{
				$arr='Photo Uploaded Failed';
				echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
			}
}

 function UserSelectedPhotoDisplay($aobj_context)
 {
	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	session_start();
	$degree_code = $_SESSION['degree_codeImgUp'];
	$college_code = $_SESSION['collcode']; 
	$user_id = $_SESSION['user_id']; 
	$FUNIVCODE = $_SESSION['FUNIVCODE'];
	$img_index = $aobj_context->mobj_data['index'];
	$regno_index = $aobj_context->mobj_data['regno'];
	
	$college_path=$aobj_context->main_src."/student_photos/{$college_code}";
	$folder_path=$aobj_context->main_src."/student_photos/{$college_code}/".replaceChars(strtolower($degree_code));
	$file_name=basename($_FILES['student_entry_upload_'.$img_index]['name']);
	// $file_name=replaceChars(basename($_FILES['student_entry_upload_'.$img_index]['name']));
	$path_arr=pathinfo($_FILES['student_entry_upload_'.$img_index]['name']);
	$file_ext=$path_arr['extension'];
	$ext = pathinfo($file_name, PATHINFO_EXTENSION);
	$full_file_path= $folder_path.'/'.$regno_index.".".$ext;
	$image_path="student_photos/{$college_code}/".replaceChars(strtolower($degree_code)).'/'.$regno_index.".".$ext;
	$photo_path="";
	$filePath = realpath($_FILES['student_entry_upload_'.$img_index]['tmp_name']);
	$S3filePath = $_SESSION['FUNIVCODE']."/student_photos/{$college_code}/".replaceChars(strtolower($degree_code))."/{$regno_index}.".$ext;

	$s3 = S3Client::factory(
		array(
			'credentials' => array(
				'key' => IAM_KEY,
				'secret' => IAM_SECRET
			),
			'version' => "latest",
			'region'  => 'ap-south-1'
		)
	);
	
		if(isset($_FILES['student_entry_upload_'.$img_index]['name']) && $_FILES['student_entry_upload_'.$img_index]['name'] != '')         
		{ 
			$size=($_FILES['student_entry_upload_'.$img_index]['size']/1024);
			if($size>1024)
			{
			$data="Please Upload the Photo of size less than 1 MB";
				echo $aobj_context->mobj_output->ToJSONEnvelope($data,-2,"success"); 
				return;
			}

			// $result =  move_uploaded_file($_FILES['student_entry_upload_'.$img_index]['tmp_name'],$full_file_path)

			$result = $s3->putObject(['Bucket' => 'university-student-photos', 'Key' => $S3filePath, 'SourceFile' => $filePath]);
	
			if($result)
			{
				$photo_path=$image_path;
			}
		}
			
			$update_qry = "update student set FPHOTOPATH='{$photo_path}' where FREGNO='{$regno_index}' 
			and FDEGREE='{$degree_code}' and FCOLLCODE='{$college_code}'";

			$lobj_rs = $aobj_context->mobj_db->Execute($update_qry);
			if($lobj_rs)
			{	
				$arr='Photo Uploaded Successfully';
		
				echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success"); 
			}
			else
			{
				$arr='Photo Uploaded Failed';
				echo $aobj_context->mobj_output->ToJSONEnvelope($arr,-1,"failure");
			}
}
?>