Добавление отдельной таблицы для предметов

This commit is contained in:
RomanGolienko 2024-12-09 11:38:53 +03:00
parent 6a646633e9
commit b9336d3ff1
2 changed files with 30 additions and 5 deletions

View File

@ -118,17 +118,36 @@ class attendancelog {
$awn = json_decode(file_get_contents($url),1); $awn = json_decode(file_get_contents($url),1);
return $awn['week_cur']; 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() public function AttendanceAddEdit()
{ {
if(isset($_POST['attendance_add_edit'])){ if(isset($_POST['attendance_add_edit'])){
foreach ($_POST['attendance_add_edit']['attendance'] as $user_id => $student_att){ 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); $search = $this->DB->QUR_SEL($sql_search);
if (isset($search[1])){ if (isset($search[1])){
$sql_update = 'UPDATE acs_attendancelog_students_attendance SET att=' . $student_att . ' WHERE id='. $search[1]['id'] .' '; $sql_update = 'UPDATE acs_attendancelog_students_attendance SET att=' . $student_att . ' WHERE id='. $search[1]['id'] .' ';
$rez = $this->DB->QUR($sql_update); $rez = $this->DB->QUR($sql_update);
}else { }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); $rez = $this->DB->QUR($sql_insert);
} }
@ -163,15 +182,18 @@ class attendancelog {
if($class['day1'] == $day_compare){ if($class['day1'] == $day_compare){
$out['day_name'] = $class['day_name']; $out['day_name'] = $class['day_name'];
$out['day_info'][$class['time1']] = $class; $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){ foreach ($out['students_all'] as $student_id => $student_name){
$out['day_info'][$class['time1']]['students'][$student_id] = '0'; $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); $search = $this->DB->QUR_SEL($sql_search);
if(isset($search[1])){ if(isset($search[1])){
$out['day_info'][$class['time1']]['students'][$student_id] = $search[1]['att']; $out['day_info'][$class['time1']]['students'][$student_id] = $search[1]['att'];
} }
} }
} }
} }
} }
@ -186,16 +208,18 @@ class attendancelog {
$currentTime = $this->currentTime(); $currentTime = $this->currentTime();
$AttendanceAddEdit = $this->AttendanceAddEdit();// должен вызываться перед mainPageAction $AttendanceAddEdit = $this->AttendanceAddEdit();// должен вызываться перед mainPageAction
$actionResult = $this->mainPageAction(); $actionResult = $this->mainPageAction();
$predmetsAddEdit = $this->predmetsAddEdit('Исследование операций и методы оптимизации');
//$html .= '<pre>'. print_r($groups,1) . '</pre>'; //$html .= '<pre>'. print_r($groups,1) . '</pre>';
//$html .= '<pre>'. print_r($currentUserInfo,1) . '</pre>'; //$html .= '<pre>'. print_r($currentUserInfo,1) . '</pre>';
//$html .= '<pre>'. print_r($actionResult,1) . '</pre>'; $html .= '<pre>'. print_r($actionResult,1) . '</pre>';
$html .= '<pre>'. print_r($predmetsAddEdit,1) . '</pre>';
//$html .= '<pre>'. print_r($currentTime,1) . '</pre>'; //$html .= '<pre>'. print_r($currentTime,1) . '</pre>';
//$html .= '<pre>'. print_r($_SESSION,1) . '</pre>'; //$html .= '<pre>'. print_r($_SESSION,1) . '</pre>';
//$html .= '<pre>'. print_r($AttendanceAddEdit,1) . '</pre>'; //$html .= '<pre>'. print_r($AttendanceAddEdit,1) . '</pre>';
//$html .= '<pre>'. print_r($_GET,1) . '</pre>'; //$html .= '<pre>'. print_r($_GET,1) . '</pre>';
//$html .= '<pre>'. print_r($_POST,1) . '</pre>'; $html .= '<pre>'. print_r($_POST,1) . '</pre>';
//$html .= '<pre>'. print_r($_SESSION,1) . '</pre>'; //$html .= '<pre>'. print_r($_SESSION,1) . '</pre>';
$page = ''; if(isset($_GET['page'])) $page = $_GET['page']; $page = ''; if(isset($_GET['page'])) $page = $_GET['page'];

View File

@ -6,6 +6,7 @@ if (isset($_SESSION['user']['fio'])){
// $class = new attendancelog($DB, $_SESSION['user']['fio']); // $class = new attendancelog($DB, $_SESSION['user']['fio']);
$class = new attendancelog($DB, $_SESSION['user']['fio']); $class = new attendancelog($DB, $_SESSION['user']['fio']);
$OUT = $class->HTML(); $OUT = $class->HTML();
} else { } else {
} }