public function saveAttendance() { if ($this->data['users']->role != "admin") { exit; } $attendanceList = array(); $attendanceArray = attendance::where('date', Input::get('attendanceDay'))->get(); foreach ($attendanceArray as $stAttendance) { $attendanceList[$stAttendance->studentId] = $stAttendance->status; } $vacationArray = array(); $vacationList = vacation::where('vacDate', Input::get('attendanceDay'))->where('acYear', $this->panelInit->selectAcYear)->where('role', 'teacher')->get(); foreach ($vacationList as $vacation) { $vacationArray[$vacation->userid] = $vacation->id; } $stAttendance = Input::get('stAttendance'); while (list($key, $value) = each($stAttendance)) { if (isset($vacationArray[$key])) { $vacationEdit = vacation::where('id', $vacationArray[$key])->first(); $vacationEdit->acceptedVacation = $value['vacationStat']; $vacationEdit->save(); if ($value['vacationStat'] == 1) { $value['attendance'] = "9"; } } if (isset($value['attendance']) and strlen($value['attendance']) > 0) { if (!isset($attendanceList[$key])) { $attendanceN = new attendance(); $attendanceN->classId = 0; $attendanceN->date = Input::get('attendanceDay'); $attendanceN->studentId = $key; $attendanceN->status = $value['attendance']; $attendanceN->save(); } else { if ($attendanceList[$key] != $value['attendance']) { $attendanceN = attendance::where('studentId', $key)->where('date', Input::get('attendanceDay'))->first(); $attendanceN->status = $value['attendance']; if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") { $attendanceN->subjectId = Input::get('subject'); } $attendanceN->save(); } } } } return $this->panelInit->apiOutput(true, "Attendance", $this->panelInit->language['attendanceSaved']); }
public function saveAttendance() { if ($this->data['users']->role != "admin" and $this->data['users']->role != "teacher") { exit; } $attendanceList = array(); if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") { $attendanceArray = attendance::where('classId', Input::get('classId'))->where('subjectId', Input::get('subject'))->where('date', Input::get('attendanceDay'))->get(); } else { $attendanceArray = attendance::where('classId', Input::get('classId'))->where('date', Input::get('attendanceDay'))->get(); } foreach ($attendanceArray as $stAttendance) { $attendanceList[$stAttendance->studentId] = $stAttendance->status; } $vacationArray = array(); $vacationList = vacation::where('vacDate', Input::get('attendanceDay'))->where('acYear', $this->panelInit->selectAcYear)->where('role', 'student')->get(); foreach ($vacationList as $vacation) { $vacationArray[$vacation->userid] = $vacation->id; } if ($this->panelInit->settingsArray['absentNotif'] == "mail" || $this->panelInit->settingsArray['absentNotif'] == "mailsms") { $mail = true; } if ($this->panelInit->settingsArray['absentNotif'] == "sms" || $this->panelInit->settingsArray['absentNotif'] == "mailsms") { $sms = true; } if (isset($mail) || isset($sms)) { $mailTemplate = mailsmsTemplates::where('templateTitle', 'Student Absent')->first(); } $stAttendance = Input::get('stAttendance'); while (list($key, $value) = each($stAttendance)) { if (isset($vacationArray[$key])) { $vacationEdit = vacation::where('id', $vacationArray[$key])->first(); $vacationEdit->acceptedVacation = $value['vacationStat']; $vacationEdit->save(); if ($value['vacationStat'] == 1) { $value['attendance'] = "9"; } } if (isset($value['attendance']) and strlen($value['attendance']) > 0) { if (!isset($attendanceList[$key])) { $attendanceN = new attendance(); $attendanceN->classId = Input::get('classId'); $attendanceN->date = Input::get('attendanceDay'); $attendanceN->studentId = $key; $attendanceN->status = $value['attendance']; if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") { $attendanceN->subjectId = Input::get('subject'); } $attendanceN->save(); if ($value['attendance'] != "1" and $this->panelInit->settingsArray['absentNotif'] != "0") { $parents = User::where('parentOf', 'like', '%"' . $key . '"%')->get(); $student = User::where('id', $key)->first(); $absentStatus = ""; switch ($value['attendance']) { case '0': $absentStatus = $this->panelInit->language['Absent']; break; case '2': $absentStatus = $this->panelInit->language['Late']; break; case '3': $absentStatus = $this->panelInit->language['LateExecuse']; break; case '4': $absentStatus = $this->panelInit->language['earlyDismissal']; break; case '9': $absentStatus = $this->panelInit->language['acceptedVacation']; break; } $MailSmsHandler = new MailSmsHandler(); foreach ($parents as $parent) { if (isset($mail)) { $studentTemplate = $mailTemplate->templateMail; $examGradesTable = ""; $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{parentName}", "{parentEmail}", "{absentDate}", "{absentStatus}", "{schoolTitle}"); $replaceArray = array($student->fullName, $student->studentRollId, $student->email, $student->username, $parent->fullName, $parent->email, Input::get('attendanceDay'), $absentStatus, $this->panelInit->settingsArray['siteTitle']); $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate); $MailSmsHandler->mail($parent->email, $this->panelInit->language['absentReport'], $studentTemplate); } if (isset($sms) and $parent->mobileNo != "") { $studentTemplate = $mailTemplate->templateSMS; $examGradesTable = ""; $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{parentName}", "{parentEmail}", "{absentDate}", "{absentStatus}", "{schoolTitle}"); $replaceArray = array($student->fullName, $student->studentRollId, $student->email, $student->username, $parent->fullName, $parent->email, Input::get('attendanceDay'), $absentStatus, $this->panelInit->settingsArray['siteTitle']); $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate); $MailSmsHandler->sms($parent->mobileNo, $studentTemplate); } } } } else { if ($attendanceList[$key] != $value['attendance']) { $attendanceN = attendance::where('studentId', $key)->where('date', Input::get('attendanceDay'))->where('classId', Input::get('classId'))->first(); $attendanceN->status = $value['attendance']; if ($this->data['panelInit']->settingsArray['attendanceModel'] == "subject") { $attendanceN->subjectId = Input::get('subject'); } $attendanceN->save(); if ($value['attendance'] != "1" and $this->panelInit->settingsArray['absentNotif'] != "0") { $parents = User::where('parentOf', 'like', '%"' . $key . '"%')->get(); $student = User::where('id', $key)->first(); $absentStatus = ""; switch ($value['attendance']) { case '0': $absentStatus = $this->panelInit->language['Absent']; break; case '2': $absentStatus = $this->panelInit->language['Late']; break; case '3': $absentStatus = $this->panelInit->language['LateExecuse']; break; case '4': $absentStatus = $this->panelInit->language['earlyDismissal']; break; case '9': $absentStatus = $this->panelInit->language['acceptedVacation']; break; } $MailSmsHandler = new MailSmsHandler(); foreach ($parents as $parent) { if (isset($mail)) { $studentTemplate = $mailTemplate->templateMail; $examGradesTable = ""; $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{parentName}", "{parentEmail}", "{absentDate}", "{absentStatus}", "{schoolTitle}"); $replaceArray = array($student->fullName, $student->studentRollId, $student->email, $student->username, $parent->fullName, $parent->email, Input::get('attendanceDay'), $absentStatus, $this->panelInit->settingsArray['siteTitle']); $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate); $MailSmsHandler->mail($parent->email, $this->panelInit->language['absentReport'], $studentTemplate); } if (isset($sms) and $parent->mobileNo != "") { $studentTemplate = $mailTemplate->templateSMS; $examGradesTable = ""; $searchArray = array("{studentName}", "{studentRoll}", "{studentEmail}", "{studentUsername}", "{parentName}", "{parentEmail}", "{absentDate}", "{absentStatus}", "{schoolTitle}"); $replaceArray = array($student->fullName, $student->studentRollId, $student->email, $student->username, $parent->fullName, $parent->email, Input::get('attendanceDay'), $absentStatus, $this->panelInit->settingsArray['siteTitle']); $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate); $MailSmsHandler->sms($parent->mobileNo, $studentTemplate); } } } } } } } return $this->panelInit->apiOutput(true, "Attendance", $this->panelInit->language['attendanceSaved']); }