Добавлена возможность отмечать посещение, отображение адаптируется к данным (чекбоксы)

This commit is contained in:
RomanGolienko 2024-12-02 15:00:31 +03:00
parent 10d53cb144
commit fbb88422d0
2 changed files with 71 additions and 22 deletions

View File

@ -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();
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']));
$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 ($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 .= '<pre>'. print_r($groups,1) . '</pre>';
//$html .= '<pre>'. print_r($actionResult,1) . '</pre>';
//$html .= '<pre>'. print_r($currentTime,1) . '</pre>';
//$html .= '<pre>'. print_r($AttendanceAddEdit,1) . '</pre>';
//$html .= '<pre>'. print_r($_GET,1) . '</pre>';
//$html .= '<pre>'. print_r($_POST,1) . '</pre>';
//$html .= '<pre>'. print_r($_SESSION,1) . '</pre>';
$html .= '<pre>'. print_r($_SESSION,1) . '</pre>';
GLOBAL $smarty;
$page = ''; if(isset($_GET['page'])) $page = $_GET['page'];
$des = ''; if(isset($_GET['des'])) $des = $_GET['des'];

View File

@ -1,4 +1,4 @@
<div class="row-fluid">
<div class="row-fluid">
<div class="span">
<h3 class="page-title"> Посещаемость </h3>
<ul class="breadcrumb">
@ -36,6 +36,9 @@
<span class="tools"><a href="javascript:;" class="icon-chevron-down"></a></span>
</div>
<div class="widget-body">
{if $actionResult|count < 1}
<h3> У группы нет пар в этот день!</h3>
{else}
<div class="accordion" id="accordion{$key}">
<h3 style="width: 100%; text-align: center">
({$actionResult.day_name})
@ -65,27 +68,28 @@
<table class="table table-striped">
<thead>
<tr>
<th>No</th>
<th>ФИО</th>
<th>Присутствие</th>
<th>Примечание</th>
</tr>
</thead>
<tbody>
{foreach from=$actionResult.students.students key=key item=student}
{foreach from=$class.students key=student item=att}
<tr>
<td>{$key}</td>
<td>{$student}</td>
<td>
<input type="hidden" name="attendance_add_edit[attendance][{$student}]" value="off">
<input type="hidden" name="attendance_add_edit[info]['week1']" value="{$class.week1}">
<input type="hidden" name="attendance_add_edit[info]['day1']" value="{$class.day1}">
<input type="hidden" name="attendance_add_edit[info]['time1']" value="{$class.time1}">
<input type="hidden" name="attendance_add_edit[info]['predmet']" value="{$class.predmet}">
<input type="hidden" name="attendance_add_edit[info]['gruppa']" value="{$groupName}">
<input type="checkbox" name="attendance_add_edit[attendance][{$student}]" id="{$key}">
<input type="hidden" name="attendance_add_edit[info][time1]" value="{$class.time1}">
<input type="hidden" name="attendance_add_edit[info][predmet]" value="{$class.predmet}">
<input type="hidden" name="attendance_add_edit[info][gruppa]" value="{$groupName}">
{if isset($smarty.post.date_request)}
<input type="hidden" name="attendance_add_edit[info][date]" value="{$smarty.post.date_request}">
{else}
<input type="hidden" name="attendance_add_edit[info][date]" value="{$currentTime.date}">
{/if}
<label for="{$student|replace:' ':''}{$key}"></label>
<input class="custom-checkbox" type="checkbox" name="attendance_add_edit[attendance][{$student}]" id="{$student|replace:' ':''}{$key}" {if $att == 'on'} checked {/if}>
</td>
<td><input type="text" name="" id="" value=""></td>
</tr>
{/foreach}
</tbody>
@ -103,6 +107,7 @@
{/if}
{/foreach}
</div>
{/if}
</div>
</div>
</div>