diff --git a/inc/attendancelog.php b/inc/attendancelog.php index 2d8176c..70171b6 100644 --- a/inc/attendancelog.php +++ b/inc/attendancelog.php @@ -65,6 +65,32 @@ class attendancelog { $awn = json_decode(file_get_contents($url),1); return $awn['week_cur']; } + + public function AttendanceAddEdit() + { + if(isset($_POST['attendance_add_edit'])){ + + foreach ($_POST['attendance_add_edit']['attendance'] as $student_name => $student_att){ + if ($student_att == 'on'){ + $student_att = 1; + }else{ + $student_att = 0; + } + $sql_search = 'SELECT id FROM acs_attendancelog_students_attendance WHERE name="'. $student_name .'" AND gruppa="'. $this->DB->rescape($_POST['attendance_add_edit']['info']['gruppa']) .'" AND date1="'. $this->DB->rescape($_POST['attendance_add_edit']['info']['date']) .'" AND time1='. $this->DB->rescape($_POST['attendance_add_edit']['info']['time1']) .' AND predmet="'. $this->DB->rescape($_POST['attendance_add_edit']['info']['predmet']) .'" '; + $search = $this->DB->QUR_SEL($sql_search); + if (isset($search[1])){ + $sql_update = 'UPDATE acs_attendancelog_students_attendance SET att=' . $student_att . ' WHERE id='. $search[1]['id'] .' '; + $rez = $this->DB->QUR($sql_update); + }else { + $sql_insert = 'INSERT INTO acs_attendancelog_students_attendance (id, name, gruppa, date1, att, time1, predmet) VALUES (0,"'.$student_name.'", "'. $this->DB->rescape($_POST['attendance_add_edit']['info']['gruppa']) .'", "'. $this->DB->rescape($_POST['attendance_add_edit']['info']['date']) .'", '. $student_att .', '. $this->DB->rescape($_POST['attendance_add_edit']['info']['time1']) .',"'. $this->DB->rescape($_POST['attendance_add_edit']['info']['predmet']) . '")'; + $rez = $this->DB->QUR($sql_insert); + } + + + } + return $rez; + } + } function mainPageAction() { $des = ''; if(isset($_GET['des'])) $des = $_GET['des']; @@ -73,19 +99,35 @@ class attendancelog { $current_group_classes = $this->getClassesByGroup($current_group[1]['sokr'], $current_group[1]['fo']); $currentTime = $this->currentTime(); $out = array(); + if(isset($_POST['date_request'])) { + $week_compare = $this->getWeekByDate(strtotime($_POST['date_request'])); + $day_compare = date('w', strtotime($_POST['date_request'])); + $db_date = $this->DB->rescape($_POST['date_request']); + }else { + $week_compare = $currentTime['week1']; + $day_compare = $currentTime['day1']; + $db_date = $currentTime['date']; + } foreach ($current_group_classes['raspis'] as $class) { - if(isset($_POST['date_request'])) { - $week_compare = $this->getWeekByDate(strtotime($_POST['date_request'])); - $day_compare = date('w', strtotime($_POST['date_request'])); - }else { - $week_compare = $currentTime['week1']; - $day_compare = $currentTime['day1']; - } if ($class['week1'] == $week_compare) { if($class['day1'] == $day_compare){ $out['day_name'] = $class['day_name']; $out['day_info'][$class['time1']] = $class; - $out['students'] = $this->getStudentsByGroup($current_group[1]['sokr'], $current_group[1]['fo']); + $students = $this->getStudentsByGroup($current_group[1]['sokr'], $current_group[1]['fo']); + foreach ($students['students'] as $student_name){ + $out['day_info'][$class['time1']]['students'][$student_name] = 'off'; + $sql_search = 'SELECT name, att FROM acs_attendancelog_students_attendance WHERE name="'. $student_name .'" AND gruppa="'. $current_group[1]['sokr'] .'" AND date1="'. $db_date .'" AND time1='. $class['time1'] .' AND predmet="'. $class['predmet'] .'" '; + $search = $this->DB->QUR_SEL($sql_search); + if(isset($search[1])){ + if($search[1]['att'] == 1){ + $db_att = 'on'; + }else{ + $db_att = 'off'; + } + $out['day_info'][$class['time1']]['students'][$student_name] = $db_att; + } + + } } } } @@ -96,14 +138,16 @@ class attendancelog { { $html = ''; $groups = $this->getAllGrupps(); - $actionResult = $this->mainPageAction(); $currentTime = $this->currentTime(); + $AttendanceAddEdit = $this->AttendanceAddEdit(); + $actionResult = $this->mainPageAction(); //$html .= '
'. print_r($groups,1) . ''; //$html .= '
'. print_r($actionResult,1) . ''; //$html .= '
'. print_r($currentTime,1) . ''; + //$html .= '
'. print_r($AttendanceAddEdit,1) . ''; //$html .= '
'. print_r($_GET,1) . ''; //$html .= '
'. print_r($_POST,1) . ''; - //$html .= '
'. print_r($_SESSION,1) . ''; + $html .= '
'. print_r($_SESSION,1) . ''; GLOBAL $smarty; $page = ''; if(isset($_GET['page'])) $page = $_GET['page']; $des = ''; if(isset($_GET['des'])) $des = $_GET['des']; diff --git a/tpl/main_page.html b/tpl/main_page.html index 10ab9ba..a561005 100644 --- a/tpl/main_page.html +++ b/tpl/main_page.html @@ -1,4 +1,4 @@ -