<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class_for_web.php");
$obj=new my_class();
// ============
extract($_POST);


$branch_id = $_SESSION['LOGIN_BRANCH'];
$column = 'current_session';
$where_cond= "branch_id =".$branch_id;
$info=$obj->View_column_details_By_Cond("_students_admission_mark_settings",$column,$where_cond);
$current_session = $info['current_session'] ;

// for deactivation Approve all, 
$form_data=array(
				'_candidate_status'=>'N'
		);
$where_cond=" _session='".$current_session."' AND branch_id=".$branch_id." AND _class='".$class."'   "; 		
$up=$obj->Update_Data('_students_admission_form',$form_data,$where_cond) ;


$num = '01';
if($class=='one') $num = '01';
if($class=='two') $num = '02';
if($class=='three') $num = '03';
if($class=='four') $num = '04';
if($class=='five') $num = '05';
if($class=='six') $num = '06';
if($class=='seven') $num = '07';
if($class=='eight') $num = '08';
if($class=='nine') $num = '09';
if($class=='eleven') $num = '11';


$where_cond=" _session='".$current_session."' AND branch_id=".$branch_id." AND _class='".$class."' AND (_approve_status='A' OR _approve_status='S')  ";
$columns ='admission_id';
$can_list=$obj->View_all_data_row_column_By_Cond('_students_admission_form',$columns,$where_cond);
//echo 'SELECT * FROM _students_admission_form WHERE'.$where_cond;



$result = array();
$i =0;
if(count($can_list)>0){
	foreach ($can_list AS $index => $value) {
		$result[$i]['admission_id'] = $value['admission_id'];
		$i++;
	}
}
$total = count($result);

function array_random($arr, $num = 1) {
    shuffle($arr);
   
    $r = array();
    for ($i = 0; $i < $num; $i++) {
        $r[] = $arr[$i];
    }
    return $num == 1 ? $r[0] : $r;
}
$new = array();
$j = 1;
$i = 0;
$pre_st = $num;
print_r($result);
$rand_form = array_random($result, $total); 

foreach($rand_form as $index=>$val){
	 $roll = '';
	 $roll =  $pre_st.str_pad($j, 4, "0", STR_PAD_LEFT);
	 $new[$i]['admission_id'] = $val['admission_id'];
	 $new[$i]['roll'] = $roll ;
	 $i++;
	 $j++;
	 
	 $form_data=array(
				'admission_exam_roll'=>$roll
		);
	 $up=$obj->Update_Data('_students_admission_form',$form_data,' admission_id='.$val['admission_id']) ;
	 
}

?>