2024-11-12 13:08:43 +03:00
< ? php
class attendancelog {
private string $name ;
private $DB ;
public function __construct ( $DB , $name ){
$this -> DB = $DB ;
$this -> name = $name ;
}
function getAllGrupps () {
2024-11-14 17:00:33 +03:00
$sql_search = 'SELECT id, sokr, fo, kurs FROM acs_grupp WHERE fo="ОФО" ORDER BY `sokr` DESC' ;
2024-11-12 13:08:43 +03:00
$rez = $this -> DB -> QUR_SEL ( $sql_search );
return $rez ;
}
function getStudentsByGroup ( $groupName , $educationForm )
{
$educationForm = urlencode ( $educationForm );
$groupName = urlencode ( $groupName );
$url = 'https://eios.mkgtu.ru/api.php?des=studentsByGrupp¶m1=' . $groupName . '¶m2=' . $educationForm ;
return json_decode ( file_get_contents ( $url ), 1 );
}
2024-11-13 16:26:13 +03:00
function getClassesByGroup ( $groupName , $educationForm )
{
$tmp = explode ( '-' , $groupName );
$groupName = trim ( $tmp [ 0 ]);
$groupNumber = substr ( $tmp [ 1 ], 0 , 2 );
$educationForm = urlencode ( $educationForm );
$groupName = urlencode ( $groupName );
$groupNumber = urlencode ( $groupNumber );
$url = 'https://local.mkgtu.ru/raspisnew/api.php?des=raspis_grupp&name=' . $groupName . '&number=' . $groupNumber . '&fo=' . $educationForm ;
return json_decode ( file_get_contents ( $url ), 1 );
//return $url;
}
2024-11-14 17:00:33 +03:00
function currentTime () { //возвращает информацию о текущем моменте для пользователя
$rez = array ();
$moment = getdate ();
$curr_minutes = $moment [ 'hours' ] * 60 + $moment [ 'seconds' ];
$minutes = 480 ;
for ( $i = 1 ; $i < 8 ; $i ++ ) { //возвращает текущую пару в университете
if ( $curr_minutes >= $minutes - 10 AND $curr_minutes <= $minutes + 90 ){
$rez [ 'time1' ] = $i ;
}
if ( $i == 4 ){
$minutes = $minutes + 110 ;
} else {
$minutes = $minutes + 100 ;
}
}
$week = json_decode ( file_get_contents ( 'https://local.mkgtu.ru/raspisnew/api.php?des=raspis_week_cur' ), 1 );
$rez [ 'day1' ] = $moment [ 'wday' ];
$rez [ 'mday' ] = $moment [ 'mday' ];
$rez [ 'mon' ] = $moment [ 'mon' ];
$rez [ '0' ] = $moment [ '0' ];
$rez [ 'year' ] = $moment [ 'year' ];
$rez [ 'date' ] = date ( " Y-m-d " );
$rez [ 'week1' ] = $week [ 'week_cur' ];
return $rez ;
}
2024-11-13 16:26:13 +03:00
2024-11-12 14:57:17 +03:00
function getGroupNameByID ( $id ) {
$sql_search = 'SELECT sokr, fo FROM acs_grupp WHERE id=' . $id . ' ' ;
return $this -> DB -> QUR_SEL ( $sql_search );
}
2024-11-25 14:26:19 +03:00
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' ];
}
2024-12-02 15:00:31 +03:00
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 ;
}
}
2024-11-12 13:08:43 +03:00
function mainPageAction ()
{
$des = '' ; if ( isset ( $_GET [ 'des' ])) $des = $_GET [ 'des' ];
if ( $des == 'show' ){
2024-11-12 14:57:17 +03:00
$current_group = $this -> getGroupNamebyID ( $_GET [ 'id' ]);
2024-11-13 16:26:13 +03:00
$current_group_classes = $this -> getClassesByGroup ( $current_group [ 1 ][ 'sokr' ], $current_group [ 1 ][ 'fo' ]);
2024-11-14 17:00:33 +03:00
$currentTime = $this -> currentTime ();
2024-11-13 16:26:13 +03:00
$out = array ();
2024-12-02 15:00:31 +03:00
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' ];
}
2024-11-13 16:26:13 +03:00
foreach ( $current_group_classes [ 'raspis' ] as $class ) {
2024-11-25 14:26:19 +03:00
if ( $class [ 'week1' ] == $week_compare ) {
if ( $class [ 'day1' ] == $day_compare ){
$out [ 'day_name' ] = $class [ 'day_name' ];
$out [ 'day_info' ][ $class [ 'time1' ]] = $class ;
2024-12-02 15:00:31 +03:00
$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 ;
}
}
2024-11-25 14:26:19 +03:00
}
2024-11-14 17:00:33 +03:00
}
2024-11-13 16:26:13 +03:00
}
return $out ;
2024-11-12 13:08:43 +03:00
}
}
function HTML ()
{
$html = '' ;
$groups = $this -> getAllGrupps ();
2024-11-14 17:00:33 +03:00
$currentTime = $this -> currentTime ();
2024-12-02 15:00:31 +03:00
$AttendanceAddEdit = $this -> AttendanceAddEdit ();
$actionResult = $this -> mainPageAction ();
2024-11-12 13:08:43 +03:00
//$html .= '<pre>'. print_r($groups,1) . '</pre>';
2024-11-25 14:26:19 +03:00
//$html .= '<pre>'. print_r($actionResult,1) . '</pre>';
//$html .= '<pre>'. print_r($currentTime,1) . '</pre>';
2024-12-02 15:00:31 +03:00
//$html .= '<pre>'. print_r($AttendanceAddEdit,1) . '</pre>';
2024-11-13 16:26:13 +03:00
//$html .= '<pre>'. print_r($_GET,1) . '</pre>';
2024-11-14 17:00:33 +03:00
//$html .= '<pre>'. print_r($_POST,1) . '</pre>';
2024-12-02 15:00:31 +03:00
$html .= '<pre>' . print_r ( $_SESSION , 1 ) . '</pre>' ;
2024-11-12 13:08:43 +03:00
GLOBAL $smarty ;
$page = '' ; if ( isset ( $_GET [ 'page' ])) $page = $_GET [ 'page' ];
$des = '' ; if ( isset ( $_GET [ 'des' ])) $des = $_GET [ 'des' ];
$smarty -> assign ( 'des' , $des );
$smarty -> assign ( 'name' , $this -> name );
2024-11-14 17:00:33 +03:00
$smarty -> assign ( 'currentTime' , $currentTime );
2024-11-12 13:08:43 +03:00
if ( $page == 'headman' ) {
$smarty -> clearCache ( 'moduls/attendancelog/tpl/headman.html' );
$html .= $smarty -> fetch ( 'moduls/attendancelog/tpl/headman.html' );
}
if ( $page == '' ){
$smarty -> assign ( 'groups' , $groups );
$smarty -> clearCache ( 'moduls/attendancelog/tpl/main_page.html' );
$html .= $smarty -> fetch ( 'moduls/attendancelog/tpl/main_page.html' );
}
if ( $page == 'main' ){
2024-11-12 14:57:17 +03:00
if ( $des == 'show' ){
$smarty -> assign ( 'actionResult' , $actionResult );
$groupName = $this -> getGroupNameByID ( $_GET [ 'id' ]);
$groupName = $groupName [ 1 ][ 'sokr' ];
$smarty -> assign ( 'groupName' , $groupName );
}
2024-11-12 13:08:43 +03:00
$smarty -> assign ( 'groups' , $groups );
$smarty -> clearCache ( 'moduls/attendancelog/tpl/main_page.html' );
$html .= $smarty -> fetch ( 'moduls/attendancelog/tpl/main_page.html' );
}
return $html ;
}
}