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.117.91.116


Current Path : /var/www/html/studentportal_wait/cronjobs/
Upload File :
Current File : /var/www/html/studentportal_wait/cronjobs/smspush_30022018.php

<?php

	//include 'database.php';
	$servername = "97.74.228.93";
	$username   = "logisys3_logu";
	$password  = "Logisys@2106";
	
	include("sendGridMail.php");

	/*$servername = "server";
	$username   = 'root';
	$password  = "";*/

	$conn = new  mysqli($servername,$username,$password);
	if(!$conn) 
	{
        die("Connection failed: " . mysqli_connect_error());
	}

	$commondb = "logisys3_comexam";
	ini_set('max_execution_time', 300);
	$sql = "select fdbname, funivcode from {$commondb}.dbname where ifnull(fdeleted,'') <> 'T'"; 
	$result = mysqli_query($conn,$sql);

	$result1 = 0;
	if($result)
	{		
		while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$db = $row['fdbname'];
			$univcode = $row['funivcode'];

			//IA marks insert
			$enttype = 'IA';
			
			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
			select distinct '{$univcode}', x.fregno, '{$enttype}', '{$enttype}', 
			'Dear Student, IA marks is available in Student Portal http://studentportal.universitysolutions.in', 'F', 'F', x.fyear, x.fexamtype, now(),d.fexamdate
			from {$db}.marks x inner join {$db}.collexam y
			on x.fdegree = y.fdegree and x.fexamno = y.fexamno and x.fcollcode = y.fcollcode
			inner join {$db}.degree d on x.fdegree = d.fdegree and x.fexamno = d.fexamno 
			where ifnull(x.fmarks,-1) <> -1
			and date_format(now(),'%Y-%m-%d') between y.fiato and 
			DATE_ADD(y.fiato,INTERVAL 30 DAY) 
			and ifnull(y.fiapush,'F') <> 'T'
			and x.fyear = '2018' and x.fexamtype = '1'";
			//var_dump($sql1);

			$result1 = mysqli_query($conn, $sql1);	

			//echo "Insert {$univcode} {$enttype} {$result1}";
			if($result1)
			{	
			
				$sql1 = "update {$db}.marks x,{$db}.collexam y set fiapush = 'T' 
				where x.fdegree = y.fdegree and x.fexamno = y.fexamno 
				and x.fcollcode = y.fcollcode and ifnull(x.fmarks,-1) <> -1 
				and date_format(now(),'%Y-%m-%d') between y.fiato 
				and DATE_ADD(y.fiato,INTERVAL 30 DAY)";
				
				$result1 = mysqli_query($conn, $sql1);
				//explode(" ",{$db});
			//	$message = "IA Marks of ".;
			}
			
			//echo "Update {$univcode} {$enttype} {$result1}";
			//Hall Ticket
			
			$enttype = 'HT';
			
			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
			select distinct '{$univcode}', x.fregno, '{$enttype}', '{$enttype}', 
			concat('Dear Student, Hall Ticket of ',w.fexamdate,' exam is available for download at http://studentportal.universitysolutions.in/') as fmessage, 'F', 'F', x.fyear, x.fexamtype, now(),w.fexamdate
			from {$db}.candsum x inner join {$db}.collexam y
			on x.fdegree = y.fdegree and x.fcollcode = y.fcollcode
			inner join {$db}.student z 
			on x.fdegree = z.fdegree and x.fregno = z.fregno 
			inner join {$db}.degree w on x.fdegree = w.fdegree and x.fexamno = w.fexamno 
			where ifnull(x.frecptdate,'') <> '' 
			and date_format(now(),'%Y-%m-%d') between y.fhtfrom and y.fhtto
			and x.fyear = '2018' and x.fexamtype = '1' and ifnull(z.fexamappblk,'') <> 'T' 
			and ifnull(y.fhtpush,'F') <> 'T'
			and ifnull(z.fmp,'') <> 'T'";
			//var_dump($sql1);
			//break;
			$result1 = mysqli_query($conn, $sql1);		
			
			
			if($result1)
			{	
				$sql1 = "update {$db}.candsum x,{$db}.collexam y set fhtpush = 'T' 
				where x.fdegree = y.fdegree and x.fcollcode = y.fcollcode 
				and ifnull(x.frecptdate,'') <> '' 
				and date_format(now(),'%Y-%m-%d') between y.fhtfrom and y.fhtto";

				$result1 = mysqli_query($conn, $sql1);
			}

			//Attendance
			
			$enttype = 'AT';
			
			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
			select distinct '{$univcode}', x.fregno, '{$enttype}', '{$enttype}',
			'Dear Student, Attendance details is available in Student Portal http://studentportal.universitysolutions.in/', 'F', 'F', x.fyear, x.fexamtype, now(),d.fexamdate
			from {$db}.attend x inner join {$db}.collexam y
			on x.fdegree = y.fdegree and x.fexamno = y.fexamno and x.fcollcode = y.fcollcode
			inner join {$db}.degree d on x.fdegree = d.fdegree and x.fexamno = d.fexamno
			where ifnull(x.fper,-1) <> -1
			and ifnull(y.fattpush,'F') <> 'T'
			and date_format(now(),'%Y-%m-%d') between y.fattto and DATE_ADD(y.fattto,INTERVAL 10 DAY)
			and x.fyear = '2018' and x.fexamtype = '1'";
			
			$result1 = mysqli_query($conn, $sql1);	
			
			//echo "Insert {$univcode} {$enttype} {$result1}";
			if($result1)
			{
				$sql1 = "update {$db}.attend x,{$db}.collexam y, set fattpush = 'T' 
				where x.fdegree = y.fdegree and x.fexamno = y.fexamno 
				and x.fcollcode = y.fcollcode 
				and ifnull(x.fper,-1) <> -1 
				and date_format(now(),'%Y-%m-%d') between y.fattto 
				and DATE_ADD(y.fattto,INTERVAL 10 DAY)";

				$result1 = mysqli_query($conn, $sql1);
			}
			//echo "Update {$univcode} {$enttype} {$result1}";
			
			//Absent 
			
			$enttype = 'AB';

			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
			select distinct '{$univcode}', x.fregno, 'AB', y.fqpcode,
			concat('Dear Student, you are absent for the QP Code ', concat(x.fqpcode, ' - ',y.fsubname),' examination held on ',date_format(x.fdoe,'%d/%m/%Y')) as fmessage,
			'F', 'F', x.fyear, x.fexamtype, now(),d.fexamdate
			from {$db}.absent x inner join {$db}.subject y
			on x.fqpcode = y.fqpcode and x.fdoe = y.fdoe 
			inner join {$db}.degree d on y.fdegree = d.fdegree and y.fexamno = d.fexamno
			where ifnull(x.fabstype,-1) = 'QpA' and ifnull(x.fabsms,'F') <> 'T'
			and x.fyear = '2018' and x.fexamtype = '1'";
			
			$result1 = mysqli_query($conn, $sql1);	
			
			//echo "Insert {$univcode} {$enttype} {$result1}";
			if($result1)
			{
				$query = "update {$db}.absent x, {$db}.subject y set x.fabsms = 'T' 
							where x.fyear = '2018' and x.fexamtype = '1' 
							and  x.fqpcode = y.fqpcode and x.fdoe = y.fdoe 
							and ifnull(x.fabstype,-1) = 'QpA'";
				$result1 = mysqli_query($conn, $query);
			}
			//echo "Update {$univcode} {$enttype} {$result1}";
			
			//Malpractice 
			
			$enttype = 'MP';

			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype,fupdate,fexamdate)
			select distinct '{$univcode}', x.fregno, 'MP', y.fqpcode , 
			concat('Dear Student, you have been registered under malpratice for the QP Code ', concat(x.fqpcode, ' - ',y.fsubname),' examination held on ',date_format(x.fdoe,'%d/%m/%Y')) as fmessage,
			'F', 'F', x.fyear, x.fexamtype, now(),d.fexamdate
			from {$db}.absent x inner join {$db}.subject y
			on x.fqpcode = y.fqpcode and x.fdoe = y.fdoe 
			inner join {$db}.degree d on y.fdegree = d.fdegree and y.fexamno = d.fexamno
			where ifnull(x.fabstype,-1) = 'QpM' and ifnull(x.fabsms,'F') <> 'T'
			and x.fyear = '2018' and x.fexamtype = '1'";
			
			$result1 = mysqli_query($conn, $sql1);
			
			//echo "Insert {$univcode} {$enttype} {$result1}";
			if($result1)
			{
				$query = "update {$db}.absent x, {$db}.subject y set x.fabsms = 'T' 
							where x.fyear = '2018' and x.fexamtype = '1' 
							and  x.fqpcode = y.fqpcode and x.fdoe = y.fdoe 
							and ifnull(x.fabstype,-1) = 'QpM'";
				$result1 = mysqli_query($conn, $query);
			}
			//echo "Update {$univcode} {$enttype} {$result1}";
			
			//Room Allotment

			$enttype = 'RA';

			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
				select distinct '{$univcode}', x.fregno, 'RA', y.fqpcode ,  
				concat('Dear Student, you have been alloted to room no. : ',
				if(ifnull(z.froomname,'') = '',
				ifnull(x.FHALLNO,''),ifnull(z.froomname,'')), ' for the QP Code ',
				concat(y.fqpcode,' - ',y.fsubname),' on ',
				date_format(y.fdoe,'%d/%m/%Y'),' (',w.FDESCPN,').',' All the best.') as fmessage,
				'F', 'F', x.fyear, x.fexamtype,now(),d.fexamdate
				from {$db}.canddet x inner join {$db}.subject y
				on  x.fdegree = y.fdegree and x.fexamno = y.fexamno and x.fsubcode = y.fsubcode 
				inner join {$db}.degree d on x.fdegree = d.fdegree and x.fexamno = d.fexamno
				left join {$db}.masroom z on x.fcollcode = z.fcollcode and x.FHALLNO = z.froomno
				left join {$db}.reason w on y.FSESSION = w.FREASONCD
				where ifnull(x.fpresent,'') = 'p' and ifnull(x.fpassmth,'') = ''
				and x.fyear = '2018' and x.fexamtype = '1' 
				and date_format(now(),'%Y-%m-%d') = date_format(y.fdoe,'%Y-%m-%d')
				and ifnull(y.FSESSION,'') like 'M%' and ifnull(x.fhallno,'') <> ''";
				
			$result1 = mysqli_query($conn, $sql1);
			
			//echo "Insert {$univcode} {$enttype} {$result1}";

			$enttype = 'PR';

			$sql1 = "insert ignore into {$commondb}.sendsms(funivcode, fregno, fenttype, fsubcode, fmessage, fstatus, fdeleted, fyear, fexamtype, fupdate,fexamdate)
			select distinct '{$univcode}', cd.fregno, 'PR', cd.fexamno, 
			concat('Dear ', st.fname,', Practical time table of ',de.fexamdate, ' exam is available in Student Portal http://studentportal.universitysolutions.in') as fmessage, 'F', 'F', cd.fyear, cd.fexamtype, now(),de.fexamdate
			from {$db}.canddet cd inner join {$db}.subject su
			on cd.fdegree = su.fdegree
			and cd.fexamno = su.fexamno
			and cd.fsubcode = su.fsubcode
			inner join {$db}.degree de
			on cd.fdegree = de.fdegree
			and cd.fexamno = de.fexamno
			inner join {$db}.marks_pr mp on
			cd.fdegree = mp.fdegree
			and cd.fexamno = mp.fexamno
			and cd.fcollcode = mp.fcollcode
			and cd.fregno = mp.fregno
			and su.fcsubcode = mp.fsubcode
			inner join {$db}.practical_entry_freeze pr
			on mp.fdegree = pr.fdegree
			and mp.fexamno = pr.fexam
			and mp.fcollcode = pr.fcollcode
			and mp.fsubcode = pr.fcsubcode 
			and mp.fbatch = pr.fbatch
			inner join {$db}.student st on cd.fregno = st.fregno
			where su.fcsubcode = pr.fcsubcode
			and ifnull(cd.fpassmth,'') = ''
			and ifnull(cd.fpresent,'') = 'P'
			and pr.FEXAMDATE > now()
			and ifnull(mp.fprpush,'') <> 'T'
			and su.ftheory <> 'T'";

			$result1 = mysqli_query($conn, $sql1);
			//echo "Insert {$univcode} {$enttype} {$result1}";

			if($result1)
			{
				$query = "update {$db}.marks_pr mp, 
				{$db}.canddet cd set mp.fprpush = 'T'
				where mp.FREGNO = cd.FREGNO and mp.FCOLLCODE = cd.FCOLLCODE and mp.FDEGREE = cd.FDEGREE and mp.FEXAMNO = cd.FEXAMNO
				and cd.FPRESENT = 'P' and ifnull(fpassmth,'') = ''";
				
				$result1 = mysqli_query($conn, $query);
			}
			//echo "Update {$univcode} {$enttype} {$result1}";	
		}
		
		$sql1 = "update {$commondb}.sendsms x, {$commondb}.masuser y set x.fmobileno = y.fmobileno
		where x.funivcode = y.funivcode and x.fregno = y.fregno and ifnull(x.fmobileno,'') = ''";
		
		$result1 = mysqli_query($conn, $sql1);		

		//Email statistics - Push Data
		if($result1)
		{
			
			$query = "select s.funivcode, d.funivname, s.fenttype,count(fmobileno) as pushcount,date_format(left(fupdate,10),'%d.%m.%Y') as pushdate
			from {$commondb}.sendsms s
			inner  join {$commondb}.dbname d
			on s.funivcode = d.funivcode
			where ifnull(fmobileno,'') <> ''
			and ifnull(fstatus,'') = 'F'
			and left(fupdate,10) = date_format(now(),'%Y-%m-%d')
			group by s.funivcode,s.fenttype";
			
			$result = mysqli_query($conn, $query);
			$count = mysqli_num_rows($result);
			if($count > 0)
			{	
				$table = '<table cellspacing="1" cellpadding="2" border="0" align="center" bgcolor="#505151">
						<thead> 
						<tr bgcolor="#e1eaea">
						 <th>Sl.<br> No.</th>
						 <th>University <br>Code</th>
						 <th>University Name</th>
						 <th>Event <br> Type</th>
						 <th>Count</th>
						 <th>Date</th>
						 </tr>
						 </thead>';	
				$i = 1;
				while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
				{
						//var_dump($row);
					
					$table .= "<tr bgcolor='#ffffff' >";
					$table .= "<td><center>".$i."</center></td>";
					$table .= "<td><center>".$row['funivcode']."</center></td>";
					$table .= "<td>".$row['funivname']."</td>";
					$table .= "<td><center>".$row['fenttype']."</center></td>";
					$table .= "<td align='right'>".$row['pushcount']."</td>";
					$table .= "<td><center>".$row['pushdate']."</center></td>";
					$table .= "</tr>";
					//$sum +=$row['pushcount'];
					$i++;
				}

				$table.="</table>";
				
				$emails = ['prashanth.k@logisys.org','arun.v@logisys.org', 'mohan.s@logisys.org'];

				$subject = "OASIS DAILY SMS DATA UPLOAD STATISTICS( ".$_SERVER['REMOTE_ADDR'].")";
				for($i=0;$i< count($emails); $i++)
				{
					
					$emailid = $emails[$i];
					$resp = sendGridMail($emailid,$subject,$table);
					//$resp = 0;
					echo $resp; 
				}
			}		

				
			$arr = "Updated Successfully";
			echo $table;	
		
		}else
		{	
			$arr = "Updation Failed";
			//echo json_encode($arr);
		}
		
	}
		
?>