From b3ceee15152a3d696571825912e045a3263a7551 Mon Sep 17 00:00:00 2001 From: RomanGolienko Date: Fri, 13 Dec 2024 17:11:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=80=D0=BE=D1=81=D1=82=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B5=20=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=BF=D0=BF.=20=D0=9F=D1=80=D0=BE=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=80=D0=BE=D1=81=D1=82=D1=8B=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B7=D0=B0=D1=85=D0=BE=D0=B4=D0=B5=20=D1=81=D1=82?= =?UTF-8?q?=D1=83=D0=B4=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/attendancelog.php | 69 +++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/inc/attendancelog.php b/inc/attendancelog.php index a11b51f..9d28a26 100644 --- a/inc/attendancelog.php +++ b/inc/attendancelog.php @@ -6,11 +6,9 @@ class attendancelog { $this->DB = $DB; $this->name = $name; } - public function currentUserInfo() - { + public function currentUserInfo(){ $currentUserInfo = array(); - if(isset($_SESSION['user']['teacher'])) - { + if(isset($_SESSION['user']['teacher'])) { $currentUserInfo['role'] = 'teacher'; $currentUserInfo['user_id'] = $_SESSION['user']['id']; $currentUserInfo['teacher_id'] = $_SESSION['user']['teacher']['id']; @@ -29,10 +27,14 @@ class attendancelog { } return $currentUserInfo; - }else if(isset($_SESSION['user']['student'])) - { + }else if(isset($_SESSION['user']['student'])) { $currentUserInfo['role'] = 'student'; $currentUserInfo['user_id'] = $_SESSION['user']['id']; + $sql_search = 'SELECT * FROM acs_attendancelog_headmen WHERE user_id='. $currentUserInfo['user_id'] .' '; + $rez = $this->DB->QUR_SEL($sql_search); + if(!isset($rez[1])){ + return 0; + } $currentUserInfo['student_id'] = $_SESSION['user']['student']['id']; $currentUserInfo['grupp_id'] = $_SESSION['user']['student']['grupp']['id']; if(isset($_SESSION['user']['student']['grupp'])){ @@ -108,18 +110,13 @@ class attendancelog { function getGroupNameByID($id) { $sql_search = 'SELECT sokr, fo FROM acs_grupp WHERE id='. $id .' '; - return $this->DB->QUR_SEL($sql_search); - //$tmp = $this->DB->QUR_SEL($sql_search); - // unset($tmp[0]); - // return $tmp; + $tmp = $this->DB->QUR_SEL($sql_search); + return $tmp[1]; } public function getWeekByDate($ts=0) { $url = 'https://local.mkgtu.ru/raspisnew/api.php?des=raspis_week_cur&ts=' . $ts; $awn = json_decode(file_get_contents($url),1); return $awn['week_cur']; - } - public function headmanAddEdit(){ - } public function predmetsAddEdit($predmet_name){ //принимает имя предмета. Делает запись в таблицу предметов, если такой нет. В любом случае возвращает айди предмета @@ -159,16 +156,35 @@ class attendancelog { return $rez; } } + public function headmanAddDelete(){ + if(isset($_POST['headman_request'])){ + $currentUserInfo = $this->currentUserInfo(); + $current_time = $this->currentTime(); + $current_group = $this->getGroupNamebyID((int)$_GET['id']); + $students = $this->getStudentsByGroup($current_group['sokr'], $current_group['fo']); + $sql_search = 'SELECT * FROM acs_attendancelog_headmen WHERE gruppa="'. $current_group['sokr'] .'" '; + $rez = $this->DB->QUR_SEL($sql_search); + if(isset($rez[1])){ + $rez = $rez[1]; + $sql_delete = 'DELETE FROM acs_attendancelog_headmen WHERE gruppa="'. $current_group['sokr'] .'" '; + $rez = $this->DB->QUR($sql_delete); + } + $sql_insert = 'INSERT INTO acs_attendancelog_headmen (id, user_id, gruppa, date_add, added_by) VALUES (0, '. $this->DB->rescape($_POST['headman_request']) .', "'. $current_group['sokr'] .'", "'. $current_time['date'] .'", '. $currentUserInfo['user_id'] .' )'; + $rez = $this->DB->QUR($sql_insert); + return $rez; + + } + } function mainPageAction() { $currentUserInfo = $this->currentUserInfo(); $des = ''; if(isset($_GET['des'])) $des = $_GET['des']; if ($des == 'show'){ $current_group = $this->getGroupNamebyID((int)$_GET['id']); - $current_group_classes = $this->getClassesByGroup($current_group[1]['sokr'], $current_group[1]['fo']); + $current_group_classes = $this->getClassesByGroup($current_group['sokr'], $current_group['fo']); $currentTime = $this->currentTime(); $out = array(); - $tmp = $this->getStudentsByGroup($current_group[1]['sokr'], $current_group[1]['fo']); + $tmp = $this->getStudentsByGroup($current_group['sokr'], $current_group['fo']); $out['students_all'] = $tmp['students']; if(isset($_POST['date_request'])) { $week_compare = $this->getWeekByDate(strtotime($_POST['date_request'])); @@ -205,6 +221,25 @@ class attendancelog { function headmanPageAction(){ $des = ''; if(isset($_GET['des'])) $des = $_GET['des']; if($des == 'add_edit'){ + $out = array(); + $current_group = $this->getGroupNamebyID((int)$_GET['id']); + $students = $this->getStudentsByGroup($current_group['sokr'], $current_group['fo']); + $out['current_group'] = $current_group; + $sql_search = 'SELECT * FROM acs_attendancelog_headmen WHERE gruppa="'. $current_group['sokr'] .'" '; + $rez = $this->DB->QUR_SEL($sql_search); + if (isset($rez[1])){ + $rez = $rez[1]; + } + foreach ($students['students'] as $user_id => $student_name){ + $out['students'][$user_id]['student_name'] = $student_name; + if($rez['user_id'] == $user_id){ + $out['students'][$user_id]['headman'] = 1; + $out['headman'] = $student_name; + }else{ + $out['students'][$user_id]['headman'] = 0; + } + } + return $out; } } function HTML() @@ -214,15 +249,17 @@ class attendancelog { $currentUserInfo = $this->currentUserInfo(); $currentTime = $this->currentTime(); $AttendanceAddEdit = $this->AttendanceAddEdit();// должен вызываться перед mainPageAction + $headmanAddDelete = $this->headmanAddDelete(); $mainPageActionResult = $this->mainPageAction(); $headmanPageActionResult = $this->headmanPageAction(); $predmetsAddEdit = $this->predmetsAddEdit('Исследование операций и методы оптимизации'); - //$html .= '
'. print_r($groups,1) . '
'; //$html .= '
'. print_r($currentUserInfo,1) . '
'; //$html .= '
'. print_r($mainPageActionResult,1) . '
'; + //$html .= '
'. print_r($headmanPageActionResult,1) . '
'; //$html .= '
'. print_r($predmetsAddEdit,1) . '
'; + //$html .= '
'. print_r($headmanAddDelete,1) . '
'; //$html .= '
'. print_r($currentTime,1) . '
'; //$html .= '
'. print_r($_SESSION,1) . '
'; //$html .= '
'. print_r($AttendanceAddEdit,1) . '
';