JezK
Edit File: ajaxconditions.php
<?php if(session_id() == "") { session_start(); } include_once("school_admin_access.php"); include_once("school_admin_student.php"); include_once("student_access.php"); include 'android_push.php'; $student_new=new student_access(); $admin=new adminaccess(); $student=new studentacess(); // print_r($_SESSION); $school_id = $_SESSION['child']['log_school_id']; $user_id = $_SESSION['child']['auth_id']; $acadamic_id = $_SESSION['child']['current_academic_id']; $choosen_acc_id = $_SESSION['child']['choosen_academic_id']; if($acadamic_id != $choosen_acc_id){ $a_id = $choosen_acc_id; }else{ $a_id = $acadamic_id; } if($_POST['action'] == "add_student"){ $school_licene_count =$admin->check_license_count($school_id); //$students_count = $student_new->check_student_count_add($school_id,$acadamic_id,$choosen_acc_id); $students_count = $student_new->check_student_count_add_data($school_id,$a_id); $licencecount = ''; foreach($school_licene_count as $key=>$val) { $licencecount = $licencecount + $key; } if($students_count['cnt'] < $licencecount) { echo "sucess"; exit; }else{ echo "exeedcount"; exit; } } //echo("<script>alert('123');</script>"); if($_POST['action'] == "generate_license"){ // echo 'hllooo';exit; // print_r($_POST);exit; $remain_count = $_POST['remain']; $acadamic_id = $_POST['acadamic_id']; $ids= ltrim ($_POST['data'], ','); $ids= rtrim ($_POST['data'], ','); $check_data =$student->check_student_licensestatus($ids); if($check_data){ foreach($check_data as $key=>$val){ if($key == '1'){ $active_data['active'] = $val; }else if($key == '0'){ $active_data['inactive'] = $val; } } } // $student_ids = explode(",",$_POST['data']); $student_ids = explode(",",$ids); $z=0; $check_license_sets = $admin->check_license_sets_count($school_id); $licencecount = 0; foreach($check_license_sets as $key=>$val){ $licence_ids[] = $val['school_license_id']; $licencecount = $licencecount + $val['license_count']; //$check_license_new = $admin->check_license_count_new($key); } if($licence_ids){ $licenceids = implode(",",$licence_ids); } //$dist_licene_count =$admin->distributelicense_count_new($licenceids); // $check_license = $admin->check_license_count($school_id); //if($active_data['inactive'] && $active_data['active']){ if($active_data['inactive'] || $active_data['active']){ echo $result = "check"; exit; }else if($remain_count < count($student_ids)){ echo $result = "exceedlimit"; exit; }else{ // foreach($licence_ids as $key=>$val){ for($i=0; $i < count($licence_ids); $i++){ $result=""; $val = $licence_ids[$i]; $dist_licene_count =$admin->distributelicense_count($val,$acadamic_id); $check_licene_setcount =$admin->check_licene_setcount($val); $remaining = $check_licene_setcount['license_count'] - $dist_licene_count['distributedcount']; $studentcount = count($student_ids); //~ echo "$studentcount"; //~ exit; //if($dist_licene_count['distributedcount'] < $check_licene_setcount['license_count']){ if($remaining > 0){ $licence_id = $val; //~ echo($licence_id); //~ exit; //else{ //echo $i; for($j=0; $j < $remaining; $j++ ){ // foreach($student_ids as $key=>$val){ if($studentcount > 0 ){ if($student_ids[$z] != ''){ $Length = 6; $characters = "0123456789"; $license = substr(str_shuffle($characters.time()), 0, $Length); $licence_key =$student->check_licencekey($license); if($licence_key == 0){ $license_new = $license; }else{ $license_new = substr(str_shuffle($characters.time()), 0, $Length); } $result_data =$student->insert_student_licences($student_ids[$z],$license_new,$user_id,$licence_id,$acadamic_id); // $result .= $student_ids[$z]."+++".$licence_id."-----".$i."-----".$j."-----".$z."<br>"; $z++; $studentcount--; } } // } } echo "sucess"; } } } } //return $result; if($_POST['action'] == "deactive_license"){ $ids= ltrim ($_POST['data'], ','); $check_data =$student->check_student_licensestatus($ids); if($check_data){ foreach($check_data as $key=>$val){ if($key == '1'){ $active_data['active'] = $val; }else if($key == '0'){ $active_data['deactive'] = $val; } } }else { $active_data['inactive'] = 'inactive'; } if(($active_data['deactive'] && $active_data['active']) || $active_data['deactive'] ){ echo $result = "check"; exit; }else if($active_data['inactive']){ echo $result = "inactive"; exit; }else { $result_data =$student->update_student_licensestatus($ids); if($result_data){ $msg['type'] = "lic_status"; $check_parents_data = $student->check_parent_data_licence($_POST['data']); if($check_parents_data){ foreach($check_parents_data as $key=>$val){ $registatoin_ids[] = $val['device_id']; $msg['student_id'] = $val['student_id']; } $student_name = $admin->student_name($msg['student_id']); $msg['message'] = $student_name." has been deactivated. Please contact School Admin"; $msg['result'] = $message; $resultss = send_notification($registatoin_ids, $msg); } echo $result = "success"; } } //return $result; } if($_POST['action'] == "change_status"){ if($_POST['status'] == 1){ $licencecount = $student->check_schoollicence_count($_POST['stuid']); $avalable_count = $student->check_license_count($licencecount['school_license_id']); if($licencecount['license_count'] > $avalable_count['cnt'] && $licencecount){ $result_data =$student->update_license_status($_POST); if($result_data){ $check_parents_data = $student->check_parent_data_licence($_POST['stuid']); if($check_parents_data){ $msg['type'] = "lic_status"; foreach($check_parents_data as $key=>$val){ $registatoin_ids[] = $val['device_id']; $msg['student_id'] = $val['student_id']; } $student_name = $admin->student_name($msg['student_id']); if($_POST['status'] == 1){ $msg['message'] = ''; } else { $msg['message'] = $student_name.' has been deactivated. Please contact School Admin'; } $msg['result'] = $message; $resultss = send_notification($registatoin_ids, $msg); } echo $result = "success"; } }else{ $check_license_sets = $admin->check_license_sets_count($school_id); $licencecount = 0; foreach($check_license_sets as $key=>$val){ $licence_ids[] = $val['school_license_id']; $licencecount = $licencecount + $val['license_count']; //$check_license_new = $admin->check_license_count_new($key); } if($licence_ids){ $licenceids = implode(",",$licence_ids); } for($i=0; $i < count($licence_ids); $i++){ $result=""; $val = $licence_ids[$i]; $dist_licene_count =$admin->distributelicense_count($val,$acadamic_id); $check_licene_setcount =$admin->check_licene_setcount($val); $remaining = $check_licene_setcount['license_count'] - $dist_licene_count['distributedcount']; if($remaining > 0){ $licence_id = $val; $result_data =$student->update_license_set($_POST,$licence_id); } echo $result = "success"; } } }else { $result_data =$student->update_license_status($_POST); if($result_data){ $check_parents_data = $student->check_parent_data_licence($_POST['stuid']); if($check_parents_data){ $msg['type'] = "lic_status"; foreach($check_parents_data as $key=>$val){ $registatoin_ids[] = $val['device_id']; $msg['student_id'] = $val['student_id']; } $student_name = $admin->student_name($msg['student_id']); if($_POST['status'] == 1){ $msg['message'] = ''; } else { $msg['message'] = $student_name.' has been deactivated. Please contact School Admin'; } $msg['result'] = $message; $resultss = send_notification($registatoin_ids, $msg); } echo $result = "success"; } } } if($_POST['action'] == "send_mails_license"){ //$student_ids = explode(",",$_POST['data']); $ids= ltrim ($_POST['data'], ','); $ids= rtrim ($_POST['data'], ','); $result_data = $student->send_licences_mail($ids); $result_license_keys = $student->get_licences_key($ids); if($result_data){ $result = $student->send_LicenceKey_student($result_data,$result_license_keys ,$_SESSION); if($result == 1){ echo $result= "success"; } } } ?>