<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>

<?php

if(($_REQUEST['action']=='software'))

{
  $branchID=$_SESSION['branch'];
 $sql = "SELECT * FROM  dummy_data_insert WHERE branch_id='$branchID'";
 // print_r($sql);
 $WorkAssignListings = $m->query($sql); 


      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
       

      	$m->where("Class_Name", $WorkAssignListVal['class']);
        $m->where("branch_id", $_SESSION['branch']);
        $class=$m->get("edu_class_config");

        //echo $class[0]['class_id'];

        $m->where("class_id", $class[0]['class_id']);
        $m->where("section_name", $WorkAssignListVal['section']);
        $m->where("branch_id", $_SESSION['branch']);
        $section=$m->get("edu_adm_section_detail");
        //echo $section[0]['section_id'];



      $m->where("session_id", $_SESSION['current_session']);

      $ss11=$m->get("edu_session_config");

      $session=$ss11[0]['session_year']-2000;

  // coding to generate auto roll number

        $ss="-".$session."-";

    $sql = "SELECT MAX(CAST(SUBSTR(candidate_roll_no,4,LENGTH(candidate_roll_no)) AS UNSIGNED)) AS prev_roll

    FROM edu_student_details as std WHERE std.branch_id =  '$branch' AND std.status='0'

    ";  

    //  print_r($sql);

      $numb;

      

      $evt =$m->query($sql);
      

      $prev= $evt[0]['prev_roll'];

        if($prev!=NULL){    

            $numb=$prev+1;        
//echo $numb;
        } else{$numb+=1;}

        $roll=str_pad($numb,3,'0',STR_PAD_LEFT);

    
        $newRoll=$session."-".$roll;



        if ($newRoll!=NULL){    

          $roll= $newRoll;

        }

        else{

          

          $roll= "--";

          

          } // closing code for generating roll number



        $data = array(
		
		'branch_id' => $_SESSION['branch'],
    'session_id' => $_SESSION['current_session'],
    'first_name' => $WorkAssignListVal['StudentName'],
    'last_name' => $WorkAssignListVal['FatherName'],
    'class_id' => $class[0]['class_id'],
    'section_id' => $section[0]['section_id'],   
    'candidate_roll_no' => $roll,    
    'status' => 0,   
    'cell_no' => "0".$WorkAssignListVal['ContactNoFather']
	);
	
 //echo "<pre>"; print_r($data); echo "</pre>";
 $result =  $m->insert('edu_student_details', $data);

  $m->where("branch_id", $_SESSION['branch']); 
  $m->delete("dummy_data_insert"); 


	
      } 

header("location:../students_reports.php?".session_id().session_id().session_id().session_id().session_id());

}


      ?>
 
        

       



