protected function validate() { $required = array("section" => "Section", "date" => "Date", "students" => "Students"); global $user; global $objPDO; $student = new Student($objPDO, $user->getuserId()); if ($user->checkAdmin() == true || $student->checkTeacher()) { if (isset($_POST)) { foreach ($required as $key => $value) { if (!isset($_POST[$key]) || $_POST[$key] == '' || $_POST[$key] == 'select') { echo $value . ' is Required<br/>'; return; } } echo 'Saving...'; require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/attendence_class.php'; $arr = $_POST['students']; $attRel = new Attendence($objPDO); $attRel->deleteBySectionDate($_POST['section'], $_POST['date']); for ($i = 0; $i < count($arr); $i++) { $attRel = new Attendence($objPDO); $attRel->setSectionId(intval($_POST['section'])); $attRel->setDate($_POST['date']); $attRel->setStudentId(intval($arr[$i])); if (isset($_POST[$arr[$i]])) { $attRel->setPresence(1); } else { $attRel->setPresence(0); } $attRel->save(); } echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/attendance/create"/>'; } } else { header('Location:http://localhost/cloud'); } }
public function actionSearchstudid1() { $model = new Attendence(); $tran = new StudentTransaction(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Attendence']['st_id'])) { $row1 = Yii::app()->user->getState('stud_array'); $all_array = Yii::app()->user->getState('all_array'); $model->attributes = $_POST['Attendence']; $checkboxvalue = $_POST['Attendence']['st_id']; $count = count($row1); $final = array(); $i = 0; foreach ($row1 as $r1) { $final[$i] = $r1['student_transaction_student_id']; // we have insert student info table in attendence table..... $i++; } $result = array_diff($final, $checkboxvalue); foreach ($checkboxvalue as $present_list) { $model->setIsNewRecord(true); $model->branch_id = $all_array['branch_id']; $model->shift_id = $all_array['shift_id']; $model->div_id = $all_array['div_id']; $model->batch_id = $all_array['batch_id']; $model->sub_id = $all_array['sub_id']; $model->sem_id = $all_array['sem_id']; $model->sem_name_id = $all_array['sem_name']; $model->attendence_date = $all_array['date']; $model->id = null; $model->st_id = $present_list; $model->attendence = 'P'; $model->attendence_organization_id = Yii::app()->user->getState('org_id'); $model->save(); } foreach ($result as $absent_list) { $model->branch_id = $all_array['branch_id']; $model->shift_id = $all_array['shift_id']; $model->div_id = $all_array['div_id']; $model->batch_id = $all_array['batch_id']; $model->sub_id = $all_array['sub_id']; $model->sem_id = $all_array['sem_id']; $model->setIsNewRecord(true); $model->id = null; $model->st_id = $absent_list; $model->attendence = 'A'; $model->attendence_organization_id = Yii::app()->user->getState('org_id'); $model->attendence_date = $all_array['date']; $model->save(); } $this->redirect(array('admin')); } }