<?php
session_start();
        // where is your config file stored?
	include ("config.php");
	$uid = htmlspecialchars(trim($_POST['uid']));
	$pass = htmlspecialchars(trim($_POST['pass']));
	$ans='select password from tbl_user where user_name="'.$_POST['uid'].'"';
	$res = mysql_query($ans);
	$inf = mysql_fetch_array($res);
	//print_r($inf);
	//print_r($_POST);
    if($inf[0]==$_POST['pass'])
    {
	  if($_POST['upgrdtype']=="Sem")//Semester Upgrade
	  {
	   
	    //Upgrade B-Tech
	   $passbtech='UPDATE student SET Semester = "pout", Status="0" WHERE (Semester ="S8" AND Batch="B-Tech") OR (Semester ="S4" AND Batch="M-Tech)"';//Passout S8
	   mysql_query($passbtech);
	   for($i=3;$i<8;$i++)//Sn to Sn+1
	   {
	      $j=$i+1;
	     $sem_upgrade_btech='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="B-Tech" AND Update_status="0"';
		 //echo $sem_upgrade_btech;
		 mysql_query($sem_upgrade_btech);
	   }
	   for($i=1;$i<4;$i++)//Sn to Sn+1 M-Tech
	   {
	      $j=$i+1;
	     $sem_upgrade_btech='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="M-Tech" AND Update_status="0"';
		 //echo $sem_upgrade_btech;
		 mysql_query($sem_upgrade_btech);
	   }
	   //Upgrade MCA
	   $passmca='UPDATE student SET Semester = "pout", Status="0" WHERE Semester ="S6" AND Batch="MCA"';//Passout S8
	   mysql_query($passmca);
	   for($i=1;$i<6;$i++)//Sn to Sn+1
	   {
	       $j=$i+1;
	     $sem_upgrade_mca='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="MCA" AND Update_status="0"';
		 mysql_query($sem_upgrade_mca);
	   }   
	   //Reset Update Status
	   $changeus='UPDATE student SET Update_status="0" WHERE Status="1"';
	   mysql_query($changeus);
	   
	   }
	   else if($_POST['upgrdtype']=="Year")//Year Upgrade involving S1S2
	   {
	      //Semester Upgrade For S1S2
		  $s1s2upgrade='UPDATE student SET Semester = "S3",Update_status=1 WHERE Semester ="S1S2" AND Batch="B-Tech" AND Update_status="0"';
		  mysql_query($s1s2upgrade);
		  
		  //Upgrade B-Tech
	 $passbtech='UPDATE student SET Semester = "pout", Status="0" WHERE Semester ="S8" AND Batch="B-Tech"';//Passout S8
	   mysql_query($passbtech);
	   for($i=3;$i<8;$i++)//Sn to Sn+1
	   {
	      $j=$i+1;
	     $sem_upgrade_btech='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="B-Tech" AND Update_status="0"';
		// echo $sem_upgrade_btech;
		 mysql_query($sem_upgrade_btech);
	   }
		
 	   for($i=1;$i<4;$i++)//Sn to Sn+1 M-Tech
	   {
	      $j=$i+1;
	     $sem_upgrade_btech='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="M-Tech" AND Update_status="0"';
		 //echo $sem_upgrade_btech;
		 mysql_query($sem_upgrade_btech);
	   }
	   
	   //Upgrade MCA
	   $passmca='UPDATE student SET Semester = "pout", Status="0" WHERE Semester ="S6" AND Batch="MCA"';//Passout S8
	   mysql_query($passmca);
	   for($i=1;$i<6;$i++)//Sn to Sn+1
	   {
	       $j=$i+1;
	     $sem_upgrade_mca='UPDATE student SET Semester = "S'.$j.'",Update_status=1 WHERE Semester ="S'.$i.'" AND Batch="MCA" AND Update_status="0"';
		// echo $sem_upgrade_mca;
		 mysql_query($sem_upgrade_mca);
	   }   
	   //Reset Update Status
	   $changeus='UPDATE student SET Update_status="0" WHERE Status="1"';
	   mysql_query($changeus);
	  
	   }
	  echo "yes";
	}
	else
	{
		   echo "no";
	}
?>
