diff --git a/inc/attendancelog.php b/inc/attendancelog.php index cf89625..7764eaf 100644 --- a/inc/attendancelog.php +++ b/inc/attendancelog.php @@ -118,17 +118,36 @@ class attendancelog { $awn = json_decode(file_get_contents($url),1); return $awn['week_cur']; } + + public function predmetsAddEdit($predmet_name){ + //принимает имя предмета. Делает запись в таблицу предметов, если такой нет. В любом случае возвращает айди предмета + $sql_search = 'SELECT id, name FROM acs_attendancelog_predmets WHERE name="'. $predmet_name .'"'; + $search = $this->DB->QUR_SEL($sql_search); + if(isset($search[1])){ + $search = $search[1]; + } + if(count($search) == 0){ + $sql_insert = 'INSERT INTO acs_attendancelog_predmets (id, name) VALUES (0,"'. $predmet_name .'")'; + $rez = $this->DB->QUR($sql_insert); + $sql_search = 'SELECT id, name FROM acs_attendancelog_predmets WHERE name="'. $predmet_name .'"'; + $search = $this->DB->QUR_SEL($sql_search); + if(isset($search[1])){ + $search = $search[1]; + } + } + return $search['id']; + } public function AttendanceAddEdit() { if(isset($_POST['attendance_add_edit'])){ foreach ($_POST['attendance_add_edit']['attendance'] as $user_id => $student_att){ - $sql_search = 'SELECT id FROM acs_attendancelog_students_attendance WHERE user_id="'. $user_id .'" 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']) .'" '; + $sql_search = 'SELECT id FROM acs_attendancelog_students_attendance WHERE user_id="'. $user_id .'" 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_id="'. $this->DB->rescape($_POST['attendance_add_edit']['info']['predmet_id']) .'" '; $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, user_id, gruppa, date1, att, time1, predmet) VALUES (0,"'.$user_id.'", "'. $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']) . '")'; + $sql_insert = 'INSERT INTO acs_attendancelog_students_attendance (id, user_id, gruppa, date1, att, time1, predmet_id) VALUES (0,"'.$user_id.'", "'. $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_id']) . '")'; $rez = $this->DB->QUR($sql_insert); } @@ -163,15 +182,18 @@ class attendancelog { if($class['day1'] == $day_compare){ $out['day_name'] = $class['day_name']; $out['day_info'][$class['time1']] = $class; + $out['day_info'][$class['time1']]['predmet_id'] = $this->predmetsAddEdit($class['predmet']); foreach ($out['students_all'] as $student_id => $student_name){ $out['day_info'][$class['time1']]['students'][$student_id] = '0'; - $sql_search = 'SELECT user_id, att FROM acs_attendancelog_students_attendance WHERE user_id="'. $student_id .'" AND gruppa="'. $current_group[1]['sokr'] .'" AND date1="'. $db_date .'" AND time1='. $class['time1'] .' AND predmet="'. $class['predmet'] .'" '; + $sql_search = 'SELECT user_id, att FROM acs_attendancelog_students_attendance WHERE user_id="'. $student_id .'" AND gruppa="'. $current_group[1]['sokr'] .'" AND date1="'. $db_date .'" AND time1='. $class['time1'] .' AND predmet_id='. $out['day_info'][$class['time1']]['predmet_id']; + //$out['day_info'][$class['time1']]['search'] = $sql_search; $search = $this->DB->QUR_SEL($sql_search); if(isset($search[1])){ $out['day_info'][$class['time1']]['students'][$student_id] = $search[1]['att']; } } + } } } @@ -186,16 +208,18 @@ class attendancelog { $currentTime = $this->currentTime(); $AttendanceAddEdit = $this->AttendanceAddEdit();// должен вызываться перед mainPageAction $actionResult = $this->mainPageAction(); + $predmetsAddEdit = $this->predmetsAddEdit('Исследование операций и методы оптимизации'); //$html .= '
'. print_r($groups,1) . ''; //$html .= '
'. print_r($currentUserInfo,1) . ''; - //$html .= '
'. print_r($actionResult,1) . ''; + $html .= '
'. print_r($actionResult,1) . ''; + $html .= '
'. print_r($predmetsAddEdit,1) . ''; //$html .= '
'. print_r($currentTime,1) . ''; //$html .= '
'. print_r($_SESSION,1) . ''; //$html .= '
'. print_r($AttendanceAddEdit,1) . ''; //$html .= '
'. print_r($_GET,1) . ''; - //$html .= '
'. print_r($_POST,1) . ''; + $html .= '
'. print_r($_POST,1) . ''; //$html .= '
'. print_r($_SESSION,1) . ''; $page = ''; if(isset($_GET['page'])) $page = $_GET['page']; diff --git a/out.php b/out.php index 00e2db6..1e32576 100644 --- a/out.php +++ b/out.php @@ -6,6 +6,7 @@ if (isset($_SESSION['user']['fio'])){ // $class = new attendancelog($DB, $_SESSION['user']['fio']); $class = new attendancelog($DB, $_SESSION['user']['fio']); $OUT = $class->HTML(); + } else { }