0
I can’t seem to solve this problem! When I attend on a particular day, the ***status** of this day is repeated throughout the month**. In the example below, I did the day 1, then I did the day 2 of one student, and look what happened.
I checked the page that performs the frequency and everything is ok, recording only the day informed, as well as in the database. The problem is in the code below, I can’t find where the script copies the day in the following days.
Code used:
<hr />
<?php echo form_open(site_url('admin/attendance_report_selector')); ?>
<div class="row">
<?php
function isWeekend($date) {
return (date('N', strtotime($date)) >= 7);
}
$query = $this->db->get('class');
if ($query->num_rows() > 0) :
$class = $query->result_array();
?>
<div class="col-md-3">
<div class="form-group">
<label class="control-label" style="margin-bottom: 5px;">Ano escolar</label>
<select class="form-control selectboxit" name="class_id" onchange="select_section(this.value)">
<option value="">Selecione</option>
<?php foreach ($class as $row) : ?>
<option value="<?php echo $row['class_id']; ?>" <?php if ($class_id == $row['class_id']) echo 'selected'; ?>><?php echo $row['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php endif; ?>
<?php
$query = $this->db->get_where('section', array('class_id' => $class_id));
if ($query->num_rows() > 0) :
$sections = $query->result_array();
?>
<div id="section_holder">
<div class="col-md-3">
<div class="form-group">
<label class="control-label" style="margin-bottom: 5px;">Turma</label>
<select class="form-control selectboxit" name="section_id">
<?php foreach ($sections as $row) : ?>
<option value="<?php echo $row['section_id']; ?>" <?php if ($section_id == $row['section_id']) echo 'selected'; ?>><?php echo $row['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<?php endif; ?>
<div class="col-md-2">
<div class="form-group">
<label class="control-label" style="margin-bottom: 5px;">Mês</label>
<select name="month" class="form-control selectboxit" id="month">
<?php
for ($i = 1; $i <= 12; $i++) :
if ($i == 1) $m = 'Janeiro';
else if ($i == 2) $m = 'Fevereiro';
else if ($i == 3) $m = 'Março';
else if ($i == 4) $m = 'Abril';
else if ($i == 5) $m = 'Maio';
else if ($i == 6) $m = 'Junho';
else if ($i == 7) $m = 'Julho';
else if ($i == 8) $m = 'Agosto';
else if ($i == 9) $m = 'Setembro';
else if ($i == 10) $m = 'Outubro';
else if ($i == 11) $m = 'Novembro';
else if ($i == 12) $m = 'Dezembro';
?>
<option value="<?php echo $i; ?>" <?php if ($month == $i) echo 'selected'; ?>>
<?php echo get_phrase($m); ?>
</option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label class="control-label" style="margin-bottom: 5px;">Ano letivo</label>
<select class="form-control selectboxit" name="sessional_year">
<?php $sessional_year_options = explode('-', $running_year); ?>
<option value="<?php echo $sessional_year_options[0]; ?>" <?php if ($sessional_year == $sessional_year_options[0]) echo 'selected'; ?>>
<?php echo $sessional_year_options[0]; ?></option>
<option value="<?php echo $sessional_year_options[1]; ?>" <?php if ($sessional_year == $sessional_year_options[1]) echo 'selected'; ?>>
<?php echo $sessional_year_options[1]; ?></option>
</select>
</div>
</div>
<input type="hidden" name="year" value="<?php echo $running_year; ?>">
<div class="col-md-2" style="margin-top: 20px;">
<button type="submit" class="btn btn-info">Gerar relatório</button>
</div>
</div>
<?php echo form_close(); ?>
<?php if ($class_id != '' && $section_id != '' && $month != '' && $sessional_year != '') : ?>
<br>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4" style="text-align: center;">
<div class="tile-stats tile-gray">
<div class="icon"><i class="entypo-docs"></i></div>
<h3 style="color: #696969;">
<?php
$section_name = $this->db->get_where('section', array('section_id' => $section_id))->row()->name;
$section_teacher = $this->db->get_where('section', array('section_id' => $section_id))->row()->teacher_id;
$class_name = $this->db->get_where('class', array('class_id' => $class_id))->row()->name;
if ($month == 1) $m = 'Janeiro';
else if ($month == 2) $m = 'Fevereiro';
else if ($month == 3) $m = 'Março';
else if ($month == 4) $m = 'Abril';
else if ($month == 5) $m = 'Maio';
else if ($month == 6) $m = 'Junho';
else if ($month == 7) $m = 'Julho';
else if ($month == 8) $m = 'Agosto';
else if ($month == 9) $m = 'Setembro';
else if ($month == 10) $m = 'Outubro';
else if ($month == 11) $m = 'Novembro';
else if ($month == 12) $m = 'Dezembro';
echo get_phrase('Relatório de frequência');
?>
</h3>
<h4 style="color: #696969;">
<?php echo get_phrase('') . ' ' . $class_name; ?> : Turma <?php echo $section_name; ?><br>
<?php echo $m . ' de ' . $sessional_year; ?> <br>
<?php echo 'Professor(a) ' . $this->db->get_where('teacher', array('teacher_id' => $section_teacher))->row()->name; ?>
</h4>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col-md-12">
<table class="table table-bordered">
<thead>
<tr>
<td>#</td>
<td style="text-align: center;">
Alunos <i class="entypo-down-thin"></i> | Dias letivos do mês <i class="entypo-right-thin"></i>
</td>
<?php
$year = explode('-', $running_year);
$days = cal_days_in_month(CAL_GREGORIAN, $month, $sessional_year);
// Código que busca o dias letivos no banco de dados
for ($i = 1; $i <= $days; $i++) {
$diasValidos = $this->db->get_where('school_days', array('day' => $i,'month' => $month))->row();
if (isWeekend($sessional_year . '-' . $month . '-' . $i))
continue;
if($diasValidos->day != NULL){
?>
<td style="text-align: center;"><?php echo $i; ?></td>
<?php } ?>
<?php } ?>
<td style="text-align: center;">Faltas</td>
<td style="text-align: center;">F. Acumuladas</td>
</tr>
</thead>
<tbody>
<?php
$data = array();
$enrolls = $this->db->get_where('enroll', array('class_id' => $class_id, 'year' => $running_year, 'section_id' => $section_id))->result_array();
$index = 0;
$students = [];
foreach ($enrolls as $enroll) {
array_push($students, $this->db->get_where('student', array('student_id' => $enroll['student_id']))->row());
}
$remStudents = $this->db->get_where('remanejamentos', array(
'old_class' => $class_id,
'old_section' => $section_id,
'year' => $sessional_year,
))->result_array();
foreach ($remStudents as $rem) {
if (in_array($rem['student_id'], array_column($students, 'student_id')))
continue;
array_push($students, $this->db->get_where('student', array('student_id' => $rem['student_id']))->row());
}
function orderByName($a, $b) {
return strcmp($a->name, $b->name);
}
usort($students, 'orderByName');
foreach ($students as $row) :
$showBlank = false;
$matriculaData = date('m-Y', strtotime(str_replace('/', '-', $row->matricula)));
$currentData = date('m-Y', strtotime('01' . '-' . $month . '-' . $sessional_year));
if ($matriculaData > $currentData && explode('-', $matriculaData)[1] == explode('-', $currentData)[1])
continue;
if($matriculaData == $currentData)
$showBlank = true;
$remanejado = false;
$rem = $this->db->get_where('remanejamentos', array(
'student_id' => $row->student_id,
'old_class' => $class_id,
'old_section' => $section_id,
))->result_array();
$newStudent = $this->db->get_where('remanejamentos', array(
'student_id' => $row->student_id,
'new_class' => $class_id,
'new_section' => $section_id,
))->result_array();
$dataRem = null;
$dataRem2 = null;
$fullDataRem = null;
if (sizeof($rem) > 0) {
$remanejado = true;
$dataRem = date('m-Y', strtotime(str_replace('/', '-', $rem[0]['data_remanejado'])));
$fullDataRem = date('d-m-Y', strtotime(str_replace('/', '-', $rem[0]['data_remanejado'])));
$sectionName = $this->db->get_where('section', array('section_id' => $rem[0]['new_section']))->row()->name;
if($currentData >= explode('/', $dataRem)[0]){
$remName = $row->name . ' - ' .'Rem. p/ Turma ' . $sectionName . ', ' . $rem[0]['data_remanejado'];
}else{
$remName = $row->name;
}
}
if (sizeof($newStudent) > 0) {
$remanejado = true;
$sectionName = $this->db->get_where('section', array('section_id' => $newStudent[0]['old_section']))->row()->name;
$dataRem2 = date('m-Y', strtotime(str_replace('/', '-', $newStudent[0]['data_remanejado'])));
$fullDataRem = date('d-m-Y', strtotime(str_replace('/', '-', $newStudent[0]['data_remanejado'])));
$remName = $row->name . ' - ' .'Rem. Turma ' . $sectionName . ', ' . $newStudent[0]['data_remanejado'];
}
$curData = date('m-Y', strtotime($sessional_year . '-' . $month));
if(($curData < $dataRem && $sessional_year != explode('-', $dataRem)[1]) || ($curData < $dataRem2 && $sessional_year == explode('-', $dataRem2)[1]))
continue;
$index++;
?>
<tr>
<td><?= $index ?></td>
<td style="text-align: left;">
<?php
$transferido = (strlen($row->transferencia) > 1 ? true : false);
if ($transferido) {
$dataTranferido = $row->transferencia;
if(explode('-', $currentData)[0] >= explode('/', $dataTranferido)[1]){
$remName = $row->name . ' - ' .'<b> Transferido(a): </b>'.$dataTranferido;
}else{
$remName = $row->name;
}
}
if ($remanejado || $transferido)
echo $remName;
else
echo $row->name;
?>
</td>
<?php
$diasValidos = $this->db->get_where('school_days', array('month' => $month))->result_array();
$status = 0;
for ($i = 1; $i <= $days; $i++) {
if(in_array($i, array_column($diasValidos, 'day'))){
if (isWeekend($sessional_year . '-' . $month . '-' . $i))
break;
$curDay = $i;
if($i < 10)
$curDay = '0' . $i;
$matriculaData = date('d-m-Y', strtotime(str_replace('/', '-', $row->matricula)));
$currentData = date('d-m-Y', strtotime($curDay . '-' . $month . '-' . $sessional_year));
$timestamp != null;
$timestamp = strtotime($i . '-' . $month . '-' . $sessional_year);
if($timestamp != null) {
$attendance = $this->db->get_where('attendance', array(
'section_id' => $section_id,
'class_id' => $class_id,
'year' => $running_year,
'timestamp' => $timestamp,
'student_id' => $row->student_id
))->result_array();
}
foreach ($attendance as $row1) :
$month_dummy = date('d', $row1['timestamp']);
if ($i == $month_dummy){
$status = $row1['status'];
}
endforeach;
?>
<td style="text-align: center; color: white; background:
<?php if ($status == 1) {
echo "#00a651";
}
if ($status == 2) {
echo '#ee4749';
}
?>;">
<?php
if($status == 1){
echo '<i class="fa fa-check"></i>';
}
if($status == 2){
echo '<i class="fa fa-times"></i>';
}
?>
</td>
<?php }}
$attendance = $this->db->get_where('attendance', array(
'section_id' => $section_id,
'class_id' => $class_id,
'year' => $running_year,
'student_id' => $row->student_id
))->result_array();
?>
<td style="text-align: center;">
<?php
$ano = explode('-',$running_year)[0];
$delimiter = '';
if($month < 10){
$delimiter = 0;
}
$timestamp = strtotime($currentData);
$inicio = strtotime($ano.'-'.$delimiter.$month.'-01T00:00:00.000');
$aux = 0;
for($i = 0; $i <= count($attendance); $i++){
if($attendance[$i]['status'] == 2 && $attendance[$i]['timestamp'] >= $inicio && $attendance[$i]['timestamp'] <= $timestamp){
$aux++;
}
}
echo $aux;
?>
</td>
<td style="text-align: center;">
<?php
$timestamp = strtotime($currentData);
$aux = 0;
for($i = 0; $i <= count($attendance); $i++){
if($attendance[$i]['status'] == 2 && $attendance[$i]['timestamp'] <= $timestamp){
$aux++;
}
}
echo $aux;
?>
</td>
<?php endforeach; ?>
</tr>
<?php ?>
</tbody>
</table>
<!-- Tabela Carga Horária -->
<?php
$hasData = sizeof($this->db->get_where('workload', array('year' => $sessional_year))->result_array()) > 0 ? true : false;
?>
<div class="col-md-12" style="padding-left: 0px; padding-right: 0px;">
<div class="col-md-6" style="padding-left: 0px; padding-right: 5px;">
<table class="table">
<thead>
<tr>
<th class="text-center">Controle de Carga Horária</th>
<th class="text-center">Neste Mês</th>
<th class="text-center">Meses Anteriores</th>
<th class="text-center">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p style="font-weight: 700; text-align: center;">Dias de aulas previstas</p>
</td>
<td class="text-center">
<?php
if ($hasData) {
$previstasNesteMes = $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => ($month - 1),
))->row()->aulas_previstas;
echo $previstasNesteMes;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
$previstasMesesAnteriores = 0;
for ($i = 0; $i < ($month - 1); $i++) {
$previstasMesesAnteriores += $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => $i,
))->row()->aulas_previstas;
}
echo $previstasMesesAnteriores;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
echo $previstasMesesAnteriores + $previstasNesteMes;
}
?>
</td>
</tr> <!-- ./dias-de-aulas-previstas -->
<tr>
<td>
<p style="font-weight: 700; text-align: center;">Dias de aulas dadas</p>
</td>
<td class="text-center">
<?php
if ($hasData) {
$dadasNesteMes = $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => ($month - 1),
))->row()->aulas_dadas;
echo $dadasNesteMes;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
$dadasMesesAnteriores = 0;
for ($i = 0; $i < ($month - 1); $i++) {
$dadasMesesAnteriores += $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => $i,
))->row()->aulas_dadas;
}
echo $dadasMesesAnteriores;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
echo $dadasMesesAnteriores + $dadasNesteMes;
}
?>
</td>
</tr> <!-- ./dias-de-aulas-dadas -->
<tr>
<td>
<p style="font-weight: 700; text-align: center;">Dias de aulas a repor</p>
</td>
<td class="text-center">
<?php
if ($hasData) {
$reportNesteMes = $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => ($month - 1),
))->row()->aulas_report;
echo $reportNesteMes;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
$reportMesesAnteriores = 0;
for ($i = 0; $i < ($month - 1); $i++) {
$reportMesesAnteriores += $this->db->get_where('workload', array(
'year' => $sessional_year,
'mes_id' => $i,
))->row()->aulas_report;
}
echo $reportMesesAnteriores;
}
?>
</td>
<td class="text-center">
<?php
if ($hasData) {
echo $reportMesesAnteriores + $reportNesteMes;
}
?>
</td>
</tr> <!-- ./dias-de-aulas-a-report -->
</tbody>
</table>
</div>
<div class="col-md-6" style="padding-left: 0px; padding-right: 0px; margin-top: 10px;">
<div class="form-group">
<label>Observações</label>
<textarea rows="6" class="form-control" disabled style="resize: none">
<?php
if ($hasData) {
echo $this->db->get_where('workload_observations', array('year' => $sessional_year, 'mes_id' => ($month - 1),
'turno' => $this->db->get_where('section', array( 'section_id' => $section_id,))->row()->nick_name))->row()->content;
}
?>
</textarea>
</div>
</div>
</div>
<div class="col-md-12 text-center">
<a href="<?php echo site_url('admin/attendance_report_print_view/' . $class_id . '/' . $section_id . '/' . $month . '/' . $sessional_year); ?>" class="btn btn-primary" target="_blank">
Imprimir relatório
</a>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/javascript">
// ajax form plugin calls at each modal loading,
$(document).ready(function() {
// SelectBoxIt Dropdown replacement
if ($.isFunction($.fn.selectBoxIt)) {
$("select.selectboxit").each(function(i, el) {
var $this = $(el),
opts = {
showFirstOption: attrDefault($this, 'first-option', true),
'native': attrDefault($this, 'native', false),
defaultText: attrDefault($this, 'text', ''),
};
$this.addClass('visible');
$this.selectBoxIt(opts);
});
}
});
</script>
<script type="text/javascript">
function select_section(class_id) {
$.ajax({
url: '<?php echo site_url('admin/get_section/'); ?>' + class_id,
success: function(response) {
jQuery('#section_holder').html(response);
}
});
}
</script>