parent
a369d05e19
commit
9042166d38
@ -0,0 +1,51 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* View (MVC patter) for adding a attendance |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
// protect a course script |
||||
api_protect_course_script(true); |
||||
|
||||
// error messages |
||||
if (isset($error) && intval($error) == 1) { |
||||
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false); |
||||
} |
||||
|
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
|
||||
$token = Security::get_token(); |
||||
// display form |
||||
$form = new FormValidator('attendance_add','POST','index.php?action=attendance_add&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"'); |
||||
$form->addElement('header', '', get_lang('CreateANewAttendance')); |
||||
$form->addElement('hidden', 'sec_token',$token); |
||||
|
||||
$form->add_textfield('title', get_lang('Title'), true, array('size'=>'50')); |
||||
$form->applyFilter('title','html_filter'); |
||||
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200')); |
||||
|
||||
// Adavanced Parameters |
||||
$form->addElement('html', '<div class="row"><div class="label">'); |
||||
$form->addElement('html', '<div class="formw"><a href="javascript://" class = "advanced_parameters" ><span id="img_plus_and_minus"> '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a></div></div></div>'); |
||||
$form->addElement('html','<div id="id_qualify" style="display:none">'); |
||||
|
||||
// Qualify Attendance for gradebook option |
||||
$form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),'onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'); |
||||
$form -> addElement('html','<div id="options_field" style="display:none">'); |
||||
$form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook')); |
||||
$form->applyFilter('attendance_qualify_title', 'html_filter'); |
||||
$form->addElement('text', 'attendance_weight', get_lang('QualifyWeight'),'value="0.00" Style="width:40px" onfocus="this.select();"'); |
||||
$form->applyFilter('attendance_weight', 'html_filter'); |
||||
$form->addElement('html','</div>'); |
||||
|
||||
$form->addElement('html','</div>'); |
||||
$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>'); |
||||
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); |
||||
$form->display(); |
||||
?> |
@ -0,0 +1,76 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* View (MVC patter) for attendance calendar (list, edit, add) |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
echo '<div class="actions" style="margin-bottom:30px">'; |
||||
echo '<a href="index?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('check.gif',get_lang('AttendanceSheet')).' '.get_lang('AttendanceSheet').'</a>'; |
||||
if ($action == 'calendar_add') { |
||||
echo '<a href="index?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('calendar_up.gif',get_lang('AttendanceCalendarList')).' '.get_lang('GoToAttendanceCalendarList').'</a>'; |
||||
} else { |
||||
echo '<a href="index?'.api_get_cidreq().'&action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('calendar_add.png',get_lang('AddDateAndTime')).' '.get_lang('AddDateAndTime').'</a>'; |
||||
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDeleteAllDates').'\')) return false;" href="index?'.api_get_cidreq().'&action=calendar_all_delete&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('calendar_delete.png',get_lang('CleanCalendar')).' '.get_lang('CleanCalendar').'</a>'; |
||||
} |
||||
echo '</div>'; |
||||
|
||||
$message_information = get_lang('informationAttendanceCalendar'); |
||||
|
||||
if (!empty($message_information)) { |
||||
$message = '<strong>'.get_lang('Information').'</strong><br />'; |
||||
$message .= $message_information; |
||||
Display::display_normal_message($message, false); |
||||
} |
||||
|
||||
if (isset($action) && $action == 'calendar_add') { |
||||
// calendar add form |
||||
echo '<div class="attendance-calendar-add">'; |
||||
echo '<h4>'.get_lang('AddADateTime').'</h4>'; |
||||
$form = new FormValidator('attendance_calendar_add','POST','index.php?action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'&'.api_get_cidreq(),''); |
||||
$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_add')); |
||||
$defaults['date_time'] = date('Y-m-d 12:00:00'); |
||||
$form->addElement('html','<div class="clear"></div>'); |
||||
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); |
||||
$form->setDefaults($defaults); |
||||
$form->display(); |
||||
echo '</div>'; |
||||
} else { |
||||
// calendar list |
||||
echo '<div class="attendance-calendar-list">'; |
||||
echo '<h4>'.get_lang('CalendarList').'</h4>'; |
||||
if (!empty($attendance_calendar)) { |
||||
foreach ($attendance_calendar as $calendar) { |
||||
echo '<div class="attendance-calendar-row">'; |
||||
if ((isset($action) && $action == 'calendar_edit') && (isset($calendar_id) && $calendar_id == $calendar['id'])) { |
||||
// calendar edit form |
||||
echo '<div class="attendance-calendar-edit">'; |
||||
$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,''); |
||||
$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_edit')); |
||||
$defaults['date_time'] = $calendar['date_time']; |
||||
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); |
||||
$form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"'); |
||||
$form->setDefaults($defaults); |
||||
$form->display(); |
||||
echo '</div>'; |
||||
} else { |
||||
echo Display::return_icon('lp_calendar_event.png',get_lang('DateTime')).' '.$calendar['date_time'].' '; |
||||
echo '<span style="margin-left:20px;">'; |
||||
echo '<a href="index?'.api_get_cidreq().'&action=calendar_edit&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style'=>'vertical-align:middle')).'</a> '; |
||||
echo '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index?'.api_get_cidreq().$param_gradebook.'&action=calendar_delete&calendar_id='.intval($calendar['id']).'&attendance_id='.$attendance_id.'">'.Display::return_icon('delete.gif', get_lang('Delete'), array('style'=>'vertical-align:middle')).'</a>'; |
||||
echo '</span>'; |
||||
} |
||||
echo '</div>'; |
||||
} |
||||
} else { |
||||
echo '<div style="padding:5px;">'.get_lang('ThereAreNoRegisteredDatetimeYet').'</div>'; |
||||
} |
||||
echo '</div>'; |
||||
} |
||||
?> |
@ -0,0 +1,270 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This file contains class used like controller, it should be included inside a dispatcher file (e.g: index.php) |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
/** |
||||
* Controller script. Prepares the common background variables to give to the scripts corresponding to |
||||
* the requested action |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
class AttendanceController |
||||
{ |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public function __construct() { |
||||
$this->toolname = 'attendance'; |
||||
$this->view = new View($this->toolname); |
||||
} |
||||
|
||||
/** |
||||
* It's used for listing attendace, |
||||
* render to attendance_list view |
||||
* @param boolean true for listing history (optional) |
||||
* @param array message for showing by action['edit','add','delete'] (optional) |
||||
*/ |
||||
public function attendance_list($history=false,$messages=array()) { |
||||
|
||||
$attendance = new Attendance(); |
||||
$data = array(); |
||||
|
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_list'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
/** |
||||
* It's used for adding attendace, |
||||
* render to attendance_add or attendance_list view |
||||
*/ |
||||
public function attendance_add() { |
||||
|
||||
$attendance = new Attendance(); |
||||
$data = array(); |
||||
|
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
|
||||
$check = Security::check_token(); |
||||
if ($check) { |
||||
$attendance->set_name($_POST['title']); |
||||
$attendance->set_description($_POST['title']); |
||||
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']); |
||||
$attendance->set_attendance_weight($_POST['attendance_weight']); |
||||
$link_to_gradebook = false; |
||||
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) { |
||||
$link_to_gradebook = true; |
||||
} |
||||
$last_id = $attendance->attendance_add($link_to_gradebook); |
||||
Security::clear_token(); |
||||
} |
||||
|
||||
if ($last_id) { |
||||
$this->attendance_sheet('calendar_list',$last_id); |
||||
} else { |
||||
$data['error_attendance_add'] = true; |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_add'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
} else { |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_add'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* It's used for editing attendace, |
||||
* render to attendance_edit or attendance_list view |
||||
* @param int attendance id |
||||
*/ |
||||
public function attendance_edit($attendance_id) { |
||||
$attendance = new Attendance(); |
||||
$data = array(); |
||||
$attendance_id = intval($attendance_id); |
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
$check = Security::check_token(); |
||||
if ($check) { |
||||
$attendance->set_name($_POST['title']); |
||||
$attendance->set_description($_POST['description']); |
||||
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']); |
||||
$attendance->set_attendance_weight($_POST['attendance_weight']); |
||||
|
||||
$link_to_gradebook = false; |
||||
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) { |
||||
$link_to_gradebook = true; |
||||
} |
||||
$affected_rows = $attendance->attendance_edit($attendance_id,$link_to_gradebook); |
||||
Security::clear_token(); |
||||
} |
||||
|
||||
|
||||
|
||||
if ($affected_rows) { |
||||
$data['message_edit'] = true; |
||||
} |
||||
$this->attendance_list(); |
||||
} else { |
||||
// default values |
||||
$attendance_data = $attendance->get_attendance_by_id($attendance_id); |
||||
$data['attendance_id'] = $attendance_data['id']; |
||||
$data['title'] = $attendance_data['name']; |
||||
$data['description'] = $attendance_data['description']; |
||||
$data['attendance_qualify_title'] = $attendance_data['attendance_qualify_title']; |
||||
$data['attendance_weight'] = $attendance_data['attendance_weight']; |
||||
|
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_edit'); |
||||
$this->view->render(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* It's used for delete attendace, |
||||
* render to attendance_list view |
||||
* @param int attendance id |
||||
*/ |
||||
public function attendance_delete($attendance_id) { |
||||
$attendance = new Attendance(); |
||||
//$attendance_id = intval($attendance_id); |
||||
if (!empty($attendance_id)) { |
||||
$affected_rows = $attendance->attendance_delete($attendance_id); |
||||
} |
||||
if ($affected_rows) { |
||||
$message['message_attendance_delete'] = true; |
||||
} |
||||
$this->attendance_list(); |
||||
} |
||||
|
||||
/** |
||||
* It's used for controlling attendace sheet (list, add), |
||||
* render to attendance_sheet view |
||||
* @param string action |
||||
* @param int attendance id |
||||
*/ |
||||
public function attendance_sheet($action,$attendance_id) { |
||||
$attendance = new Attendance(); |
||||
$data = array(); |
||||
$data['attendance_id'] = $attendance_id; |
||||
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id); |
||||
$data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id); |
||||
|
||||
if (api_is_allowed_to_edit(null, true)) { |
||||
$data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); |
||||
} else { |
||||
$data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, api_get_user_id()); |
||||
$data['faults'] = $attendance->get_faults_of_user(api_get_user_id(), $attendance_id); |
||||
} |
||||
|
||||
$data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); |
||||
|
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
$presences = array(); |
||||
$check_values = array(); |
||||
if (isset($_POST['check_presence'])) { |
||||
$presences = $_POST['check_presence']; |
||||
$calendar_tmp = array(); |
||||
foreach ($presences as $presence) { |
||||
$presence_split = explode('_',$presence); |
||||
$calendar_id = $presence_split[1]; |
||||
$user_id = $presence_split[3]; |
||||
$calendar_tmp[] = $calendar_id; |
||||
if (in_array($calendar_id, $calendar_tmp)) { |
||||
$check_values[$calendar_id][] = $user_id; |
||||
} |
||||
} |
||||
} |
||||
foreach ($check_values as $cal_id => $value) { |
||||
$users_present = $value; |
||||
$affected_rows = $attendance->attendance_sheet_add($cal_id,$users_present,$attendance_id); |
||||
} |
||||
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id); |
||||
$data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id); |
||||
$data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); |
||||
$data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); |
||||
} |
||||
|
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_sheet'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
/** |
||||
* It's used for controlling attendace calendar (list, add, edit, delete), |
||||
* render to attendance_calendar view |
||||
* @param string action (optional, by default 'calendar_list') |
||||
* @param int attendance id (optional) |
||||
* @param int calendar id (optional) |
||||
*/ |
||||
public function attendance_calendar($action = 'calendar_list',$attendance_id = 0, $calendar_id = 0) { |
||||
|
||||
$attendance = new Attendance(); |
||||
$calendar_id = intval($calendar_id); |
||||
$data = array(); |
||||
$data['attendance_id'] = $attendance_id; |
||||
$attendance_id = intval($attendance_id); |
||||
|
||||
if ($action == 'calendar_add') { |
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
if (!isset($_POST['cancel'])) { |
||||
$datetime = $attendance->build_datetime_from_array($_POST['date_time']); |
||||
if (!empty($datetime)) { |
||||
$attendance->set_date_time($datetime); |
||||
$affected_rows = $attendance->attendant_calendar_add($attendance_id); |
||||
} else { |
||||
$data['error_date'] = true; |
||||
} |
||||
$action = 'calendar_list'; |
||||
} else { |
||||
$action = 'calendar_list'; |
||||
} |
||||
} |
||||
} else if ($action == 'calendar_edit') { |
||||
$data['calendar_id'] = $calendar_id; |
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
if (!isset($_POST['cancel'])) { |
||||
$datetime = $attendance->build_datetime_from_array($_POST['date_time']); |
||||
$attendance->set_date_time($datetime); |
||||
$affected_rows = $attendance->attendant_calendar_edit($calendar_id, $attendance_id); |
||||
$data['calendar_id'] = 0; |
||||
$action = 'calendar_list'; |
||||
} else { |
||||
$action = 'calendar_list'; |
||||
} |
||||
} |
||||
} else if ($action == 'calendar_delete') { |
||||
$affected_rows = $attendance->attendance_calendar_delete($calendar_id, $attendance_id); |
||||
$action = 'calendar_list'; |
||||
} else if ($action == 'calendar_all_delete') { |
||||
$affected_rows = $attendance->attendance_calendar_delete(0, $attendance_id, true); |
||||
$action = 'calendar_list'; |
||||
} |
||||
|
||||
$data['action'] = $action; |
||||
$data['attendance_calendar'] = $attendance->get_attendance_calendar($attendance_id); |
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('attendance_calendar'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
?> |
@ -0,0 +1,65 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* View (MVC patter) for editing an attendance |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
|
||||
// protect a course script |
||||
api_protect_course_script(true); |
||||
|
||||
// error messages |
||||
if (isset($error) && intval($error) == 1) { |
||||
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false); |
||||
} |
||||
|
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
$token = Security::get_token(); |
||||
$attendance_weight = floatval($attendance_weight); |
||||
|
||||
// display form |
||||
$form = new FormValidator('attendance_edit','POST','index.php?action=attendance_edit&'.api_get_cidreq().'&attendance_id='.$attendance_id.$param_gradebook,'','style="width: 100%;"'); |
||||
$form->addElement('header', '', get_lang('EditAnAttendance')); |
||||
$form->addElement('hidden', 'sec_token',$token); |
||||
|
||||
$form->add_textfield('title', get_lang('Title'), true, array('size'=>'50')); |
||||
$form->applyFilter('title','html_filter'); |
||||
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200')); |
||||
|
||||
// Adavanced Parameters |
||||
$form->addElement('html', '<div class="row"><div class="label">'); |
||||
if (!empty($attendance_qualify_title) || !empty($attendance_weight)) { |
||||
$form->addElement('html', '<div class="formw"><a href="javascript://" class="advanced_parameters"><span id="img_plus_and_minus"> '.Display::return_icon('div_hide.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a></div></div></div>'); |
||||
$form->addElement('html','<div id="id_qualify" style="display:block">'); |
||||
$form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),array('checked'=>'true','onclick'=>'javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}')); |
||||
$form -> addElement('html','<div id="options_field" style="display:block">'); |
||||
} else { |
||||
$form->addElement('html', '<div class="formw"><a href="javascript://" class="advanced_parameters"><span id="img_plus_and_minus"> '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a></div></div></div>'); |
||||
$form->addElement('html','<div id="id_qualify" style="display:none">'); |
||||
$form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'),'onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'); |
||||
$form -> addElement('html','<div id="options_field" style="display:none">'); |
||||
} |
||||
$form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook')); |
||||
$form->applyFilter('attendance_qualify_title', 'html_filter'); |
||||
$form->addElement('text', 'attendance_weight', get_lang('QualifyWeight'),'value="0.00" Style="width:40px" onfocus="this.select();"'); |
||||
$form->applyFilter('attendance_weight', 'html_filter'); |
||||
$form->addElement('html','</div>'); |
||||
|
||||
$form->addElement('html','</div>'); |
||||
$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>'); |
||||
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); |
||||
|
||||
// set default values |
||||
$default['title'] = Security::remove_XSS($title); |
||||
$default['description'] = Security::remove_XSS($description,STUDENT); |
||||
$default['attendance_qualify_title'] = $attendance_qualify_title; |
||||
$default['attendance_weight'] = $attendance_weight; |
||||
$form->setDefaults($default); |
||||
$form->display(); |
||||
?> |
@ -0,0 +1,34 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* View (MVC patter) for listing attendances |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
if (api_is_allowed_to_edit(null, true)) { |
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
echo '<div class="actions" style="margin-bottom:30px">'; |
||||
echo '<a href="index?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.Display::return_icon('adherir.png',get_lang('CreateANewAttendance')).' '.get_lang('CreateANewAttendance').'</a>'; |
||||
echo '</div>'; |
||||
} |
||||
$table = new SortableTable('attendance_list', array('Attendance', 'get_number_of_attendances'), array('Attendance', 'get_attendance_data'), $default_column); |
||||
$table->set_additional_parameters($parameters); |
||||
$table->set_header(0, '', false, array('style'=>'width:20px;')); |
||||
$table->set_header(1, get_lang('Name'), true ); |
||||
$table->set_header(2, get_lang('Description'), true); |
||||
$table->set_header(3, get_lang('CountDoneAttendance'), true, array('style'=>'width:50px;')); |
||||
|
||||
if (api_is_allowed_to_edit(null, true)) { |
||||
$table->set_header(4, get_lang('Action'), false,array('style'=>'text-align:center')); |
||||
$table->set_form_actions(array ('attendance_delete_select' => get_lang('DeleteAllAttendances'))); |
||||
} |
||||
|
||||
$table->display(); |
||||
|
||||
|
||||
?> |
@ -0,0 +1,175 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* View (MVC patter) for attendance sheet (list, edit, add) |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
if (api_is_allowed_to_edit(null, true)) { |
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
echo '<div class="actions" style="margin-bottom:30px">'; |
||||
echo '<a href="index?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.Display::return_icon('calendar_up.gif',get_lang('AttendanceCalendar')).' '.get_lang('AttendanceCalendar').'</a>'; |
||||
echo '</div>'; |
||||
|
||||
$message_information = get_lang('informationAttendanceSheet'); |
||||
if (!empty($message_information)) { |
||||
$message = '<strong>'.get_lang('Information').'</strong><br />'; |
||||
$message .= $message_information; |
||||
Display::display_normal_message($message, false); |
||||
} |
||||
?> |
||||
<?php
|
||||
|
||||
if (count($users_in_course) > 0) { |
||||
?> |
||||
<form method="post" action="index?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_gradebook ?>&attendance_id=<?php echo $attendance_id?>" >
|
||||
<div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;border:1px solid gray;margin-top:20px;"> |
||||
|
||||
<div class="attendance-users-table" style="width:450px;float:left;"> |
||||
|
||||
<table class="data_table" width="100%"> |
||||
<tr class="row_odd" > |
||||
<th height="60px" width="35px" ><?php echo get_lang('Order')?></th>
|
||||
<th width="45px" ><?php echo get_lang('Photo')?></th>
|
||||
<th><?php echo get_lang('LastName')?></th>
|
||||
<th><?php echo get_lang('FirstName')?></th>
|
||||
<th width="90px"><?php echo get_lang('faults')?></th>
|
||||
</tr> |
||||
|
||||
<?php
|
||||
$i = 1; |
||||
$class = ''; |
||||
foreach ($users_in_course as $data) { |
||||
$faults = 0; |
||||
if ($i%2 == 0) {$class='row_odd';} |
||||
else {$class='row_even';} |
||||
?> |
||||
<tr class="<?php echo $class ?>">
|
||||
<td height="50px"><center><?php echo $i ?></center></td>
|
||||
<td><?php echo $data['photo'] ?></td>
|
||||
<td><?php echo $data['lastname'] ?></td>
|
||||
<td><?php echo $data['firstname'] ?></td>
|
||||
<td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($data['result_color_bar'])?$data['result_color_bar']:'none') ?>"><?php echo $data['attendance_result'] ?></div></center></td>
|
||||
</tr> |
||||
<?php
|
||||
$i++; |
||||
} |
||||
?> |
||||
</table> |
||||
|
||||
</div> |
||||
|
||||
<div class="attendance-calendar-table" style="overflow:auto;overflow-y:hidden;"> |
||||
<table class="data_table" width="100%"> |
||||
<tr class="row_odd"> |
||||
<?php
|
||||
if (count($attendant_calendar) > 0 ) { |
||||
foreach ($attendant_calendar as $calendar) { |
||||
//$datetime = explode(' ',$calendar['date_time']); |
||||
$date = $calendar['date']; |
||||
$time = $calendar['time']; |
||||
$datetime = $date.'<br />'.$time; |
||||
$checked_date = ''; |
||||
if (!empty($calendar['done_attendance'])){ |
||||
$datetime = '<font color="blue">'.$date.'<br />'.$time.'</font>'; |
||||
} |
||||
if ($next_attendance_calendar_id == $calendar['id']) { |
||||
$checked_date = 'checked'; |
||||
} |
||||
?> |
||||
<th height="60px" style="padding:5px;"><?php echo '<span style="font-size:10px;">'.$datetime.'<br /><input type="checkbox" id="datetime_column_'.$calendar['id'].'" '.$checked_date.'/></span>' ?></th>
|
||||
<?php }
|
||||
} else { ?> |
||||
<th height="60px" style="padding:5px;"><span><a href="index?<?php echo api_get_cidreq() ?>&action=calendar_list&attendance_id=<?php echo $attendance_id.$param_gradebook ?>">
|
||||
<?php echo Display::return_icon('calendar_up.gif',get_lang('AttendanceCalendar')).' '.get_lang('GoToAttendanceCalendar') ?></a></span></th>
|
||||
<?php } ?> |
||||
</tr> |
||||
<?php
|
||||
$i = 0; |
||||
foreach ($users_in_course as $user) { |
||||
$class = ''; |
||||
if ($i%2==0) {$class = 'row_even';} |
||||
else {$class = 'row_odd';} |
||||
?> |
||||
<tr class="<?php echo $class ?>">
|
||||
<?php
|
||||
if (count($attendant_calendar) > 0 ) { |
||||
foreach ($attendant_calendar as $calendar) { |
||||
$checked = 'checked'; |
||||
if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) { |
||||
$presence = $users_presence[$user['user_id']][$calendar['id']]['presence']; |
||||
if (intval($presence) == 1) { |
||||
$checked = 'checked'; |
||||
} else { |
||||
$checked = ''; |
||||
} |
||||
} |
||||
$disabled = 'disabled'; |
||||
$style_td = ''; |
||||
if ($next_attendance_calendar_id == $calendar['id']) { |
||||
$style_td = 'background-color:#e1e1e1'; |
||||
$disabled = ''; |
||||
} |
||||
?> |
||||
<td height="50px" style="<?php echo $style_td ?>" class="checkboxes_col_<?php echo $calendar['id'] ?>"><center><input type="checkbox" name="check_presence[]" value="cal_<?php echo $calendar['id'] ?>_user_<?php echo $user['user_id'] ?>" <?php echo $disabled.' '.$checked ?> /><span class="<?php echo 'anchor_'.$calendar['id'] ?>"></span></center></td>
|
||||
|
||||
<?php }
|
||||
} else { ?> |
||||
<td height="50px" class="checkboxes_col_<?php echo $calendar['id'] ?>"><center> </center></td>
|
||||
<?php } ?> |
||||
</tr> |
||||
<?php $i++ ;
|
||||
} |
||||
?> |
||||
|
||||
</table> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="clear"></div> |
||||
<div style="margin-top:20px;"><button type="submit" class="save"><?php echo get_lang('SaveAttendanceSheet') ?></button></div>
|
||||
</form> |
||||
|
||||
<?php } else {
|
||||
echo '<div><a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a></div>'; |
||||
} |
||||
|
||||
} else { |
||||
// View for students |
||||
$user_id = api_get_user_id(); |
||||
?> |
||||
<h3><?php echo get_lang('AttendanceSheetReport') ?></h3>
|
||||
<div> |
||||
<table width="200px;"> |
||||
<tr> |
||||
<td><?php echo get_lang('Faults').': ' ?></td><td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar'])?$faults['color_bar']:'none') ?>"><?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center></td>
|
||||
</tr> |
||||
</table> |
||||
</div> |
||||
<div> |
||||
<br /> |
||||
<center> |
||||
<table class="data_table"> |
||||
<tr class="row_odd" > |
||||
<th><?php echo get_lang('Calendar')?></th>
|
||||
<th><?php echo get_lang('Attendance')?></th>
|
||||
</tr> |
||||
<?php
|
||||
$i = 0; |
||||
foreach($users_presence[$user_id] as $presence) { |
||||
$class = ''; |
||||
if ($i%2==0) {$class = 'row_even';} |
||||
else {$class = 'row_odd';} |
||||
?> |
||||
<tr class="<?php echo $class ?>"><td><?php echo Display::return_icon('lp_calendar_event.png',get_lang('DateTime')).' '.$presence['date_time'] ?></td><td><center><?php echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence')) ?></center></td></tr>
|
||||
|
||||
<?php } ?> |
||||
</table> |
||||
</center> |
||||
</div> |
||||
<?php } ?> |
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Layout (principal view) used for structuring other views |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendace |
||||
*/ |
||||
|
||||
// protect a course script |
||||
api_protect_course_script(true); |
||||
|
||||
|
||||
// Header |
||||
$tool = TOOL_ATTENDANCE; |
||||
Display :: display_header(''); |
||||
|
||||
// Introduction section |
||||
Display::display_introduction_section($tool); |
||||
|
||||
// Tracking |
||||
event_access_tool($tool); |
||||
|
||||
// Display |
||||
echo $content; |
||||
|
||||
// Footer |
||||
Display :: display_footer(); |
||||
|
||||
?> |
@ -0,0 +1,737 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This file contains class used like library provides functions for attendance tool. It's also used like model to attendance_controller (MVC pattern) |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
/** |
||||
* Attendance can be used to instanciate objects or as a library to manage attendances |
||||
* @package chamilo.attendance |
||||
*/ |
||||
|
||||
class Attendance |
||||
{ |
||||
private $session_id; |
||||
private $course_id; |
||||
private $date_time; |
||||
private $name; |
||||
private $description; |
||||
private $attendance_qualify_title; |
||||
private $attendance_weight; |
||||
|
||||
|
||||
public function __construct() {} |
||||
|
||||
/** |
||||
* Get the total number of attendance inside current course and current session |
||||
* @see SortableTable#get_total_number_of_items() |
||||
*/ |
||||
function get_number_of_attendances() { |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$session_id = api_get_session_id(); |
||||
$sql = "SELECT COUNT(att.id) AS total_number_of_items FROM $tbl_attendance att WHERE att.active = 1 = att.session_id = '$session_id' "; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
$obj = Database::fetch_object($res); |
||||
return $obj->total_number_of_items; |
||||
} |
||||
|
||||
/** |
||||
* Get the attendaces to display on the current page (fill the sortable-table) |
||||
* @param int offset of first user to recover |
||||
* @param int Number of users to get |
||||
* @param int Column to sort on |
||||
* @param string Order (ASC,DESC) |
||||
* @see SortableTable#get_table_data($from) |
||||
*/ |
||||
function get_attendance_data($from, $number_of_items, $column, $direction) { |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$session_id = api_get_session_id(); |
||||
$column = intval($column); |
||||
$from = intval($from); |
||||
$number_of_items = intval($number_of_items); |
||||
if (!in_array($direction, array('ASC','DESC'))) { |
||||
$direction = 'ASC'; |
||||
} |
||||
$sql = "SELECT |
||||
att.id AS col0, |
||||
att.name AS col1, |
||||
att.description AS col2, |
||||
att.attendance_qualify_max AS col3 |
||||
FROM $tbl_attendance att |
||||
WHERE att.session_id = '$session_id' AND att.active = 1 |
||||
ORDER BY col$column $direction LIMIT $from,$number_of_items "; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
$attendances = array (); |
||||
|
||||
$param_gradebook = ''; |
||||
if (isset($_SESSION['gradebook'])) { |
||||
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; |
||||
} |
||||
|
||||
while ($attendance = Database::fetch_row($res)) { |
||||
$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$param_gradebook.'">'.$attendance[1].'</a>'; |
||||
$attendance[3] = '<center>'.$attendance[3].'</center>'; |
||||
if (api_is_allowed_to_edit(null, true)) { |
||||
$actions = ''; |
||||
$actions .= '<center><a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a> '; |
||||
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a></center>'; |
||||
$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions); |
||||
} else { |
||||
$attendance[0] = ' '; |
||||
$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]); |
||||
} |
||||
} |
||||
return $attendances; |
||||
} |
||||
|
||||
/** |
||||
* Get the attendaces by id to display on the current page |
||||
* @param int attendance id |
||||
* @return array attendance data |
||||
*/ |
||||
public function get_attendance_by_id($attendance_id) { |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$sesion_id = api_get_session_id(); |
||||
$attendance_id = intval($attendance_id); |
||||
$attendance_data = array(); |
||||
$sql = "SELECT * FROM $tbl_attendance WHERE id = '$attendance_id'"; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($res) > 0) { |
||||
while ($row = Database::fetch_array($res)) { |
||||
$attendance_data = $row; |
||||
} |
||||
} |
||||
return $attendance_data; |
||||
} |
||||
|
||||
/** |
||||
* add attendaces inside table |
||||
* @param bool true for adding link in gradebook or false otherwise (optional) |
||||
* @return int last attendance id |
||||
*/ |
||||
public function attendance_add($link_to_gradebook = false) { |
||||
global $_course; |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||||
$session_id = api_get_session_id(); |
||||
$user_id = api_get_user_id(); |
||||
$course_code = api_get_course_id(); |
||||
$title_gradebook= Database::escape_string($this->attendance_qualify_title); |
||||
$value_calification = 0; |
||||
$weight_calification = floatval($this->attendance_weight); |
||||
$sql = "INSERT INTO $tbl_attendance |
||||
SET name ='".Database::escape_string($this->name)."', |
||||
description = '".Database::escape_string($this->description)."', |
||||
attendance_qualify_title = '$title_gradebook', |
||||
attendance_weight = '$weight_calification', |
||||
session_id = '$session_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
$last_id = 0; |
||||
if (!empty($affected_rows)) { |
||||
// save inside item property table |
||||
$last_id = Database::insert_id(); |
||||
api_item_property_update($_course, TOOL_ATTENDANCE, $last_id,"AttendanceAdded", $user_id); |
||||
} |
||||
// add link to gradebook |
||||
if ($link_to_gradebook) { |
||||
$description = ''; |
||||
$link_id=is_resource_in_course_gradebook($course_code,7,$last_id,$session_id); |
||||
if ($link_id==false) { |
||||
add_resource_to_course_gradebook($course_code, 7, $last_id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,$session_id); |
||||
} else { |
||||
Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.''); |
||||
} |
||||
} |
||||
return $last_id; |
||||
} |
||||
|
||||
/** |
||||
* edit attendaces inside table |
||||
* @param int attendance id |
||||
* @param bool true for adding link in gradebook or false otherwise (optional) |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendance_edit($attendance_id, $link_to_gradebook = false) { |
||||
global $_course; |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||||
$session_id = api_get_session_id(); |
||||
$user_id = api_get_user_id(); |
||||
$attendance_id = intval($attendance_id); |
||||
$course_code = api_get_course_id(); |
||||
$title_gradebook = Database::escape_string($this->attendance_qualify_title); |
||||
$value_calification = 0; |
||||
$weight_calification = floatval($this->attendance_weight); |
||||
|
||||
|
||||
$sql = "UPDATE $tbl_attendance |
||||
SET name ='".Database::escape_string($this->name)."', |
||||
description = '".Database::escape_string($this->description)."', |
||||
attendance_qualify_title = '".$title_gradebook."', |
||||
attendance_weight = '".$weight_calification."' |
||||
WHERE id = '$attendance_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
if (!empty($affected_rows)) { |
||||
// update row item property table |
||||
$last_id = Database::insert_id(); |
||||
api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id,"AttendanceUpdated", $user_id); |
||||
} |
||||
|
||||
// add link to gradebook |
||||
if ($link_to_gradebook) { |
||||
$description = ''; |
||||
$link_id=is_resource_in_course_gradebook($course_code,7,$attendance_id,$session_id); |
||||
if ($link_id==false) { |
||||
add_resource_to_course_gradebook($course_code, 7, $attendance_id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,$session_id); |
||||
} else { |
||||
Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.''); |
||||
} |
||||
} |
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* delete attendaces |
||||
* @param int attendance id |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendance_delete($attendance_id) { |
||||
global $_course; |
||||
$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
||||
$user_id = api_get_user_id(); |
||||
if (is_array($attendance_id)) { |
||||
foreach ($attendance_id as $id) { |
||||
$id = intval($id); |
||||
$sql = "UPDATE $tbl_attendance SET active = 0 WHERE id = '$id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
if (!empty($affected_rows)) { |
||||
// update row item property table |
||||
api_item_property_update($_course, TOOL_ATTENDANCE, $id,"delete", $user_id); |
||||
} |
||||
} |
||||
} else { |
||||
$attendance_id = intval($attendance_id); |
||||
$sql = "UPDATE $tbl_attendance SET active = 0 WHERE id = '$attendance_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
if (!empty($affected_rows)) { |
||||
// update row item property table |
||||
api_item_property_update($_course, TOOL_ATTENDANCE, $attendance_id,"delete", $user_id); |
||||
} |
||||
} |
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* get registered users inside current course |
||||
* @param int attendance id for showing attendance result field (optional) |
||||
* @return array users data |
||||
*/ |
||||
public function get_users_rel_course($attendance_id = 0) { |
||||
$current_session_id = api_get_session_id(); |
||||
$current_course_id = api_get_course_id(); |
||||
if (!empty($current_session_id)) { |
||||
$a_course_users = CourseManager :: get_user_list_from_course_code($current_course_id, true, $current_session_id,'','lastname'); |
||||
} else { |
||||
$a_course_users = CourseManager :: get_user_list_from_course_code($current_course_id, false, 0, '','lastname'); |
||||
} |
||||
// get registered users inside current course |
||||
$a_users = array(); |
||||
|
||||
foreach ($a_course_users as $key => $value) { |
||||
$uid = intval($value['user_id']); |
||||
if ($uid <= 1) continue; |
||||
if (!empty($attendance_id)) { |
||||
$attendance_id = intval($attendance_id); |
||||
$user_faults = $this->get_faults_of_user($uid, $attendance_id); |
||||
$value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)'; |
||||
$value['result_color_bar'] = $user_faults['color_bar']; |
||||
} |
||||
|
||||
// user's picture |
||||
$image_path = UserManager::get_user_picture_path_by_id($uid, 'web', false); |
||||
$user_profile = UserManager::get_picture_user($uid, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" '); |
||||
if (!api_is_anonymous()) { |
||||
if (!empty($image_path['file'])) { |
||||
$photo = '<center><a class="thickbox" href="'.$image_path['dir'].$image_path['file'].'" ><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($value['firstname'], $value['lastname']).'" title="'.api_get_person_name($value['firstname'], $value['lastname']).'" /></a></center>'; |
||||
} else { |
||||
$photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($value['firstname'], $value['lastname']).'" title="'.api_get_person_name($value['firstname'], $value['lastname']).'" /></center>'; |
||||
} |
||||
} else { |
||||
$photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($value['firstname'], $value['lastname']).'" title="'.api_get_person_name($value['firstname'], $value['lastname']).'" /></center>'; |
||||
} |
||||
$value['photo'] = $photo; |
||||
$a_users[$key] = $value; |
||||
} |
||||
return $a_users; |
||||
} |
||||
|
||||
/** |
||||
* add attendaces sheet inside table |
||||
* @param int attendance calendar id |
||||
* @param array present users during current class |
||||
* @param int attendance id |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendance_sheet_add($calendar_id,$users_present,$attendance_id) { |
||||
$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
||||
$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
||||
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
||||
|
||||
$calendar_id = intval($calendar_id); |
||||
$attendance_id = intval($attendance_id); |
||||
$users = $this->get_users_rel_course(); |
||||
$user_ids = array_keys($users); |
||||
$users_absent = array_diff($user_ids,$users_present); |
||||
$affected_rows = 0; |
||||
|
||||
// save users present in class |
||||
foreach ($users_present as $user_present) { |
||||
$uid = intval($user_present); |
||||
// check if user already was registered with the $calendar_id |
||||
$sql = "SELECT user_id FROM $tbl_attendance_sheet WHERE user_id='$uid' AND attendance_calendar_id = '$calendar_id'"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($rs) == 0) { |
||||
$sql = "INSERT INTO $tbl_attendance_sheet SET user_id ='$uid', attendance_calendar_id = '$calendar_id', presence = 1"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} else { |
||||
$sql = "UPDATE $tbl_attendance_sheet SET presence = 1 WHERE user_id ='$uid' AND attendance_calendar_id = '$calendar_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} |
||||
} |
||||
|
||||
// save users absent in class |
||||
foreach ($users_absent as $user_absent) { |
||||
$uid = intval($user_absent); |
||||
// check if user already was registered with the $calendar_id |
||||
$sql = "SELECT user_id FROM $tbl_attendance_sheet WHERE user_id='$uid' AND attendance_calendar_id = '$calendar_id'"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($rs) == 0) { |
||||
$sql = "INSERT INTO $tbl_attendance_sheet SET user_id ='$uid', attendance_calendar_id = '$calendar_id', presence = 0"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} else { |
||||
$sql = "UPDATE $tbl_attendance_sheet SET presence = 0 WHERE user_id ='$uid' AND attendance_calendar_id = '$calendar_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} |
||||
} |
||||
|
||||
// update done_attendance inside attendance calendar table |
||||
$sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1 WHERE id = '$calendar_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
|
||||
// save users' results |
||||
$this->update_users_results($user_ids, $attendance_id); |
||||
|
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* update users' attendance results |
||||
* @param array registered users inside current course |
||||
* @param int attendance id |
||||
* @return void |
||||
*/ |
||||
public function update_users_results($user_ids, $attendance_id) { |
||||
$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
||||
$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
||||
$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); |
||||
$attendance_id = intval($attendance_id); |
||||
// fill results about presence of students |
||||
$attendance_calendar = $this->get_attendance_calendar($attendance_id); |
||||
$calendar_ids = array(); |
||||
// get all dates from calendar by current attendance |
||||
foreach ($attendance_calendar as $cal) { |
||||
$calendar_ids[] = $cal['id']; |
||||
} |
||||
// get count of presences by users inside current attendance and save like results |
||||
$count_presences = 0; |
||||
if (count($user_ids) > 0) { |
||||
foreach ($user_ids as $uid) { |
||||
$count_presences = 0; |
||||
if (count($calendar_ids) > 0) { |
||||
$sql = "SELECT count(presence) as count_presences FROM $tbl_attendance_sheet WHERE user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") AND presence = 1"; |
||||
$rs_count = Database::query($sql, __FILE__, __LINE__); |
||||
$row_count = Database::fetch_array($rs_count); |
||||
$count_presences = $row_count['count_presences']; |
||||
} |
||||
// save results |
||||
$sql = "SELECT id FROM $tbl_attendance_result WHERE user_id='$uid' AND attendance_id='$attendance_id'"; |
||||
$rs_check_result = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($rs_check_result) > 0) { |
||||
// update result |
||||
$sql = "UPDATE $tbl_attendance_result SET score='$count_presences' WHERE user_id='$uid' AND attendance_id='$attendance_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
} else { |
||||
// insert new result |
||||
$sql = "INSERT INTO $tbl_attendance_result SET user_id='$uid', attendance_id = '$attendance_id', score='$count_presences'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
} |
||||
} |
||||
} |
||||
// update attendance qualify max |
||||
$count_done_calendar = $this->get_done_attendance_calendar($attendance_id); |
||||
$sql = "UPDATE $tbl_attendance SET attendance_qualify_max='$count_done_calendar' WHERE id = '$attendance_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
/** |
||||
* Get number of done attendances inside current sheet |
||||
* @param int attendance id |
||||
* @return int number of done attendances |
||||
*/ |
||||
public function get_done_attendance_calendar($attendance_id) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$attendance_id = intval($attendance_id); |
||||
$sql = "SELECT count(done_attendance) as count FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id' AND done_attendance=1"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
$row = Database::fetch_array($rs); |
||||
$count = $row['count']; |
||||
return $count; |
||||
} |
||||
|
||||
/** |
||||
* Get results of faults (absents) by user |
||||
* @param int user id |
||||
* @param int attendance id |
||||
* @return array results containing number of faults, total done attendance, porcent of faults and color depend on result (red, orange) |
||||
*/ |
||||
public function get_faults_of_user($user_id, $attendance_id) { |
||||
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
||||
$user_id = intval($user_id); |
||||
$attendance_id = intval($attendance_id); |
||||
$results = array(); |
||||
$attendance_data = $this->get_attendance_by_id($attendance_id); |
||||
$total_done_attendance = $attendance_data['attendance_qualify_max']; |
||||
$attendance_user_score = $this->get_user_score($user_id, $attendance_id); |
||||
// calculate results |
||||
$faults = $total_done_attendance-$attendance_user_score; |
||||
$faults = $faults > 0 ? $faults:0; |
||||
$faults_porcent = $total_done_attendance > 0 ?round(($faults*100)/$total_done_attendance,0):0; |
||||
$results['faults'] = $faults; |
||||
$results['total'] = $total_done_attendance; |
||||
$results['faults_porcent'] = $faults_porcent; |
||||
$color_bar = ''; |
||||
if ($faults_porcent > 25 ) { |
||||
$color_bar = '#F11'; |
||||
} else if ($faults_porcent > 10) { |
||||
$color_bar = '#F90'; |
||||
} |
||||
$results['color_bar'] = $color_bar; |
||||
return $results; |
||||
} |
||||
|
||||
/** |
||||
* Get registered users' attendance sheet inside current course |
||||
* @param int attendance id |
||||
* @param int user id for showing data for only one user (optional) |
||||
* @return array users attendance sheet data |
||||
*/ |
||||
public function get_users_attendance_sheet($attendance_id, $user_id = 0) { |
||||
global $dateTimeFormatLong; |
||||
$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
||||
$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$attendance_id = intval($attendance_id); |
||||
|
||||
$attendance_calendar = $this->get_attendance_calendar($attendance_id); |
||||
$calendar_ids = array(); |
||||
// get all dates from calendar by current attendance |
||||
foreach ($attendance_calendar as $cal) { |
||||
$calendar_ids[] = $cal['id']; |
||||
} |
||||
|
||||
$data = array(); |
||||
if (empty($user_id)) { |
||||
// get all registered users inside current course |
||||
$users = $this->get_users_rel_course(); |
||||
$user_ids = array_keys($users); |
||||
if (count($calendar_ids) > 0 && count($user_ids) > 0) { |
||||
foreach ($user_ids as $uid) { |
||||
$sql = "SELECT * FROM $tbl_attendance_sheet WHERE user_id = '$uid' AND attendance_calendar_id IN(".implode(',',$calendar_ids).") "; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($res) > 0) { |
||||
while ($row = Database::fetch_array($res)) { |
||||
$data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence']; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
// get attendance for current user |
||||
$user_id = intval($user_id); |
||||
if (count($calendar_ids) > 0) { |
||||
$sql = "SELECT cal.date_time, att.presence FROM $tbl_attendance_sheet att INNER JOIN $tbl_attendance_calendar cal ON cal.id = att.attendance_calendar_id WHERE att.user_id = '$user_id' AND att.attendance_calendar_id IN(".implode(',',$calendar_ids).") "; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($res) > 0) { |
||||
while ($row = Database::fetch_array($res)) { |
||||
$row['date_time'] = api_format_date($dateTimeFormatLong, strtotime($row['date_time'])); |
||||
$data[$user_id][] = $row; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
/** |
||||
* Get next attendance calendar without presences (done attendances) |
||||
* @param int attendance id |
||||
* @return int attendance calendar id |
||||
*/ |
||||
public function get_next_attendance_calendar_id($attendance_id) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$attendance_id = intval($attendance_id); |
||||
$sql = "SELECT id FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id' AND done_attendance = 0 ORDER BY date_time limit 1"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
$next_calendar_id = 0; |
||||
if (Database::num_rows($rs) > 0) { |
||||
$row = Database::fetch_array($rs); |
||||
$next_calendar_id = $row['id']; |
||||
} |
||||
return $next_calendar_id; |
||||
} |
||||
|
||||
/** |
||||
* Get user' score from current attendance |
||||
* @param int user id |
||||
* @param int attendance id |
||||
* @return int score |
||||
*/ |
||||
public function get_user_score($user_id, $attendance_id) { |
||||
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
||||
$user_id = intval($user_id); |
||||
$attendance_id = intval($attendance_id); |
||||
$sql = "SELECT score FROM $tbl_attendance_result WHERE user_id='$user_id' AND attendance_id='$attendance_id'"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
$score = 0; |
||||
if (Database::num_rows($rs) > 0) { |
||||
$row = Database::fetch_array($rs); |
||||
$score = $row['score']; |
||||
} |
||||
return $score; |
||||
} |
||||
|
||||
/** |
||||
* Get attendance calendar data by id |
||||
* @param int attendance calendar id |
||||
* @return array attendance calendar data |
||||
*/ |
||||
public function get_attendance_calendar_by_id($calendar_id) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$calendar_id = intval($calendar_id); |
||||
$sql = "SELECT * FROM $tbl_attendance_calendar WHERE id = '$calendar_id' "; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
$data = array(); |
||||
if (Database::num_rows($rs) > 0) { |
||||
while ($row = Database::fetch_array($rs)) { |
||||
$data = $row; |
||||
} |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
/** |
||||
* Get all attendance calendar data inside current attendance |
||||
* @param int attendance id |
||||
* @return array attendance calendar data |
||||
*/ |
||||
public function get_attendance_calendar($attendance_id) { |
||||
global $dateFormatShort, $timeNoSecFormat; |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$attendance_id = intval($attendance_id); |
||||
$sql = "SELECT * FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id' ORDER BY date_time "; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
$data = array(); |
||||
if (Database::num_rows($rs) > 0) { |
||||
while ($row = Database::fetch_array($rs)) { |
||||
$row['date'] = api_format_date($dateFormatShort, strtotime($row['date_time'])); |
||||
$row['time'] = api_format_date($timeNoSecFormat, strtotime($row['date_time'])); |
||||
$data[] = $row; |
||||
} |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
/** |
||||
* Add new datetime inside attendance calendar table |
||||
* @param int attendance id |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendant_calendar_add($attendance_id) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$affected_rows = 0; |
||||
$attendance_id = intval($attendance_id); |
||||
// check if datetime already exists inside the table |
||||
$sql = "SELECT id FROM $tbl_attendance_calendar WHERE date_time='".Database::escape_string($this->date_time)."' AND attendance_id = '$attendance_id'"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($rs) == 0) { |
||||
$sql = "INSERT INTO $tbl_attendance_calendar SET date_time='".Database::escape_string($this->date_time)."', attendance_id = '$attendance_id'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} |
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* edit a datetime inside attendance calendar table |
||||
* @param int attendance calendar id |
||||
* @param int attendance id |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendant_calendar_edit($calendar_id, $attendance_id) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$affected_rows = 0; |
||||
$attendance_id = intval($attendance_id); |
||||
// check if datetime already exists inside the table |
||||
$sql = "SELECT id FROM $tbl_attendance_calendar WHERE date_time = '".Database::escape_string($this->date_time)."' AND attendance_id = '$attendance_id'"; |
||||
$rs = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($rs) == 0) { |
||||
$sql = "UPDATE $tbl_attendance_calendar SET date_time='".Database::escape_string($this->date_time)."' WHERE id = '".intval($calendar_id)."'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
$affected_rows = Database::affected_rows(); |
||||
} |
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* delete a datetime from attendance calendar table |
||||
* @param int attendance calendar id |
||||
* @param int attendance id |
||||
* @param bool true for removing all calendar inside current attendance, false for removing by calendar id |
||||
* @return int affected rows |
||||
*/ |
||||
public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false) { |
||||
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
||||
$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET); |
||||
$session_id = api_get_session_id(); |
||||
$attendance_id = intval($attendance_id); |
||||
// get all registered users inside current course |
||||
$users = $this->get_users_rel_course(); |
||||
$user_ids = array_keys($users); |
||||
|
||||
if ($all_delete) { |
||||
$attendance_calendar = $this->get_attendance_calendar($attendance_id); |
||||
$calendar_ids = array(); |
||||
// get all dates from calendar by current attendance |
||||
if (!empty($attendance_calendar)) { |
||||
foreach ($attendance_calendar as $cal) { |
||||
// delete all data from attendance sheet |
||||
$sql = "DELETE FROM $tbl_attendance_sheet WHERE attendance_calendar_id = '".intval($cal['id'])."'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
// delete data from attendance calendar |
||||
$sql = "DELETE FROM $tbl_attendance_calendar WHERE id = '".intval($cal['id'])."'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
} |
||||
} |
||||
} else { |
||||
// delete just one row from attendance sheet by the calendar id |
||||
$sql = "DELETE FROM $tbl_attendance_sheet WHERE attendance_calendar_id = '".intval($calendar_id)."'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
// delete data from attendance calendar |
||||
$sql = "DELETE FROM $tbl_attendance_calendar WHERE id = '".intval($calendar_id)."'"; |
||||
Database::query($sql, __FILE__, __LINE__); |
||||
} |
||||
|
||||
$affected_rows = Database::affected_rows(); |
||||
// update users' results |
||||
$this->update_users_results($user_ids, $attendance_id); |
||||
return $affected_rows; |
||||
} |
||||
|
||||
/** |
||||
* buid a string datetime from array |
||||
* @param array array containing data e.g: e.g: $array('Y'=>'2010', 'F' => '02', 'd' => '10', 'H' => '12', 'i' => '30') |
||||
* @return string date and time e.g: '2010-02-10 12:30:00' |
||||
*/ |
||||
public function build_datetime_from_array($array) { |
||||
$year = '0000'; |
||||
$month = $day = $hours = $minutes = $seconds = '00'; |
||||
if (isset($array['Y']) && isset($array['F']) && isset($array['d']) && isset($array['H']) && isset($array['i'])) { |
||||
$year = $array['Y']; |
||||
$month = $array['F']; |
||||
if (intval($month) < 10 ) $month = '0'.$month; |
||||
$day = $array['d']; |
||||
if (intval($day) < 10 ) $day = '0'.$day; |
||||
$hours = $array['H']; |
||||
if (intval($hours) < 10 ) $hours = '0'.$hours; |
||||
$minutes = $array['i']; |
||||
if (intval($minutes) < 10 ) $minutes = '0'.$minutes; |
||||
} |
||||
if (checkdate($month,$day,$year)) { |
||||
$datetime = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.':'.$seconds; |
||||
} |
||||
return $datetime; |
||||
} |
||||
|
||||
/** Setters for fields of attendances tables **/ |
||||
public function set_session_id($session_id) { |
||||
$this->session_id = $session_id; |
||||
} |
||||
|
||||
public function set_course_id($course_id) { |
||||
$this->course_id = $course_id; |
||||
} |
||||
|
||||
public function set_date_time($datetime) { |
||||
$this->date_time = $datetime; |
||||
} |
||||
|
||||
public function set_name($name) { |
||||
$this->name = $name; |
||||
} |
||||
|
||||
public function set_description($description) { |
||||
$this->description = $description; |
||||
} |
||||
|
||||
public function set_attendance_qualify_title($attendance_qualify_title) { |
||||
$this->attendance_qualify_title = $attendance_qualify_title; |
||||
} |
||||
|
||||
public function set_attendance_weight($attendance_weight) { |
||||
$this->attendance_weight = $attendance_weight; |
||||
} |
||||
|
||||
/** Getters for fields of attendances tables **/ |
||||
public function get_session_id() { |
||||
return $this->session_id; |
||||
} |
||||
|
||||
public function get_course_id() { |
||||
return $this->course_id; |
||||
} |
||||
|
||||
public function get_date_time() { |
||||
return $this->date_time; |
||||
} |
||||
|
||||
public function get_name($name) { |
||||
return $this->name; |
||||
} |
||||
|
||||
public function get_description($description) { |
||||
return $this->description; |
||||
} |
||||
|
||||
public function get_attendance_qualify_title($attendance_qualify_title) { |
||||
return $this->attendance_qualify_title; |
||||
} |
||||
|
||||
public function get_attendance_weight($attendance_weight) { |
||||
return $this->attendance_weight; |
||||
} |
||||
|
||||
} |
||||
?> |
Loading…
Reference in new issue