From faf421cb7d4d70b0144f0c06342fd7efd9154cec Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 7 Oct 2010 15:36:04 +0200 Subject: [PATCH] Adding sticky header in attendance sheet see BT#1653 --- main/attendance/attendance_controller.php | 92 ++-- main/attendance/attendance_sheet.php | 467 +++++++++++-------- main/course_progress/thematic_controller.php | 2 +- main/css/chamilo/default.css | 5 +- main/css/chamilo_electric_blue/default.css | 6 +- main/css/chamilo_green/default.css | 7 +- main/css/chamilo_orange/default.css | 7 +- main/css/chamilo_red/default.css | 7 +- main/inc/lib/attendance.lib.php | 118 +++-- 9 files changed, 437 insertions(+), 274 deletions(-) diff --git a/main/attendance/attendance_controller.php b/main/attendance/attendance_controller.php index 21b993cf54..e0fe328a90 100755 --- a/main/attendance/attendance_controller.php +++ b/main/attendance/attendance_controller.php @@ -185,7 +185,10 @@ $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); + $filter_type = 'today'; + if (!empty($_REQUEST['filter'])) { + $filter_type = $_REQUEST['filter']; + } if (api_is_allowed_to_edit(null, true)) { $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); @@ -216,10 +219,12 @@ } $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id); - $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id); + $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type); $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id); + } else { + $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id,$filter_type); } $this->view->set_data($data); @@ -243,50 +248,49 @@ $data['attendance_id'] = $attendance_id; $attendance_id = intval($attendance_id); - if ($action == 'calendar_add') { + if ($action == 'calendar_add') { if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { - if (!isset($_POST['cancel'])) { - - if (isset($_POST['repeat'])) { - $start_datetime = api_strtotime($attendance->build_datetime_from_array($_POST['date_time'])); - - - $_POST['end_date_time']['H'] = $_POST['date_time']['H']; - $_POST['end_date_time']['i'] = $_POST['date_time']['i']; - - $end_datetime = api_strtotime($attendance->build_datetime_from_array($_POST['end_date_time'])); - $checkdate = checkdate($_POST['end_date_time']['F'], $_POST['end_date_time']['d'], $_POST['end_date_time']['Y']); - - $repeat_type = $_POST['repeat_type']; - if (($end_datetime > $start_datetime) && $checkdate) { - $affected_rows = $attendance->attendance_repeat_calendar_add($attendance_id, $start_datetime, $end_datetime, $repeat_type); - $action = 'calendar_list'; - - } else { - - if (!$checkdate) { - $data['error_checkdate'] = true; - } else { - $data['error_repeat_date'] = true; - } - - $data['repeat'] = true; - $action = 'calendar_add'; - } - } else { - $datetime = $attendance->build_datetime_from_array($_POST['date_time']); - $datetimezone = api_get_utc_datetime($datetime); - if (!empty($datetime)) { - $attendance->set_date_time($datetimezone); - $affected_rows = $attendance->attendance_calendar_add($attendance_id); - $action = 'calendar_list'; - } else { - $data['error_date'] = true; - $action = 'calendar_add'; - } - - } + if (!isset($_POST['cancel'])) { + if (isset($_POST['repeat'])) { + error_log($attendance->build_datetime_from_array($_POST['date_time'])); + //$start_datetime = api_strtotime($attendance->build_datetime_from_array($_POST['date_time'])); + + $start_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['date_time'])),'UTC'); + error_log('$start_datetime '.$start_datetime); + + $_POST['end_date_time']['H'] = $_POST['date_time']['H']; + $_POST['end_date_time']['i'] = $_POST['date_time']['i']; + error_log($attendance->build_datetime_from_array($_POST['end_date_time'])); + + $end_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['end_date_time'])),'UTC'); + error_log('$end_datetime '.$end_datetime); + $checkdate = checkdate($_POST['end_date_time']['F'], $_POST['end_date_time']['d'], $_POST['end_date_time']['Y']); + $repeat_type = $_POST['repeat_type']; + if (($end_datetime > $start_datetime) && $checkdate) { + $affected_rows = $attendance->attendance_repeat_calendar_add($attendance_id, $start_datetime, $end_datetime, $repeat_type); + $action = 'calendar_list'; + } else { + if (!$checkdate) { + $data['error_checkdate'] = true; + } else { + $data['error_repeat_date'] = true; + } + $data['repeat'] = true; + $action = 'calendar_add'; + } + } else { + $datetime = $attendance->build_datetime_from_array($_POST['date_time']); + $datetimezone = api_get_utc_datetime($datetime); + if (!empty($datetime)) { + $attendance->set_date_time($datetimezone); + $affected_rows = $attendance->attendance_calendar_add($attendance_id); + $action = 'calendar_list'; + } else { + $data['error_date'] = true; + $action = 'calendar_add'; + } + } } else { $action = 'calendar_list'; } diff --git a/main/attendance/attendance_sheet.php b/main/attendance/attendance_sheet.php index 8fe2101a6b..ad10795cdf 100755 --- a/main/attendance/attendance_sheet.php +++ b/main/attendance/attendance_sheet.php @@ -2,8 +2,9 @@ /* For licensing terms, see /license.txt */ /** -* View (MVC patter) for attendance sheet (list, edit, add) +* View (MVC patter) for attendance sheet (list, edit, add) * @author Christian Fasanando +* @author Julio Montoya reworked 2010 * @package chamilo.attendance */ @@ -11,198 +12,300 @@ api_protect_course_script(true); if (api_is_allowed_to_edit(null, true)) { - $param_gradebook = ''; - if (isset($_SESSION['gradebook'])) { - $param_gradebook = '&gradebook='.$_SESSION['gradebook']; - } - echo ''; + $param_gradebook = ''; + if (isset($_SESSION['gradebook'])) { + $param_gradebook = '&gradebook='.$_SESSION['gradebook']; + } + if (!$is_locked_attendance || api_is_platform_admin()) { + echo ''; + } + $message_information = get_lang('AttendanceSheetDescription'); + if (!empty($message_information)) { + $message = ''.get_lang('Information').'
'; + $message .= $message_information; + Display::display_normal_message($message, false); + } - $message_information = get_lang('AttendanceSheetDescription'); - if (!empty($message_information)) { - $message = ''.get_lang('Information').'
'; - $message .= $message_information; - Display::display_normal_message($message, false); - } -?> - 0) { - ?> -
+ if ($is_locked_attendance) { + Display::display_warning_message(get_lang('TheAttendanceSheetIsLocked'), false); + } + + $form = new FormValidator('filter', 'post', 'index.php?action=attendance_sheet_add&'.api_get_cidreq().$param_gradebook.'&attendance_id='.$attendance_id); + + $values = array('all'=>get_lang('All'), 'today'=>get_lang('Today'),'all_done'=>get_lang('AllDone'), 'all_not_done'=>get_lang('AllNotDone')); + $form->addElement('select', 'filter', 'Filter', $values); + $form->addElement('style_submit_button', null, get_lang('Filter'), 'class="filter"'); + + if (isset($_REQUEST['filter'])) { + + if (in_array($_REQUEST['filter'],array_keys($values))) { + $default_filter = $_REQUEST['filter']; + } + } else { + $default_filter = 'today'; + } + $form->setDefaults(array('filter'=>$default_filter)); + $param_filter = '&filter='.Security::remove_XSS($default_filter); -
+ if (count($users_in_course) > 0) { + $form->display(); + ?> + -
-
-
-
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
- '.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'
'; - } +
+ + + 0 ) { + foreach ($attendant_calendar as $calendar) { + $date = $calendar['date']; + $time = $calendar['time']; + $datetime = $date.'
'.$time; + + $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id'])); + if (!empty($calendar['done_attendance'])){ + $datetime = ''.$date.'
'.$time.'
'; + } + $disabled_check = 'disabled'; + $input_hidden = ''; + if ($next_attendance_calendar_id == $calendar['id']) { + $input_hidden = ''; + $disabled_check = ''; + $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id'])); + } + + $result .= ''; + } + } else { + $result = ''; + } + ?> + + + + + + + + + + + + + + 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 = ''; + } + } else { + //if the user wasn't registered at that time, consider unchecked + if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) { + $checked = ''; + } + } + $disabled = 'disabled'; + $style_td = ''; + if ($next_attendance_calendar_id == $calendar['id']) { + $style_td = 'background-color:#e1e1e1'; + $disabled = ''; + } + ?> + + + + + + + + +
'; + $result .= '
'.$datetime.' '; + $result .= ''.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').''; + $result .= '
'.$input_hidden.'
'; + $result .=Display::return_icon('calendar_up.gif',get_lang('AttendanceCalendar')).' '.get_lang('GoToAttendanceCalendar').'
+
+
+ + /> + +
+
+
+
+
 
+
+
+
+ +
+
+
+ '.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').''; + } } else { - // View for students -?> -

- -
- - - - - -
-
- -
-
-
- - - - - - - - - - -
-
-
+ // View for students +?> +

+ +
+ + + + + +
+
+ +
+
+
+ + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/main/course_progress/thematic_controller.php b/main/course_progress/thematic_controller.php index d1218ef819..87b6a772ef 100755 --- a/main/course_progress/thematic_controller.php +++ b/main/course_progress/thematic_controller.php @@ -33,7 +33,7 @@ class ThematicController * render to thematic.php */ public function thematic($action) { - + var_dump($action); $thematic= new Thematic(); $data = array(); $error = false; diff --git a/main/css/chamilo/default.css b/main/css/chamilo/default.css index 14b9db846e..d14ac3d395 100755 --- a/main/css/chamilo/default.css +++ b/main/css/chamilo/default.css @@ -4137,7 +4137,6 @@ div.attendance-calendar-add div.row div.formw,div.attendance-calendar-edit div.r padding:2px; font-size:120%; font-weight: bold; - margin:5px; padding:5px; } @@ -4328,11 +4327,11 @@ span.form_required { .attendance-users-table td { - height:66px; + /* height:66px;*/ } .attendance-calendar-table td { - height:66px; + /*height:66px;*/ } #contact_registration .label{ diff --git a/main/css/chamilo_electric_blue/default.css b/main/css/chamilo_electric_blue/default.css index 00eea8622d..12a7a04b38 100644 --- a/main/css/chamilo_electric_blue/default.css +++ b/main/css/chamilo_electric_blue/default.css @@ -4041,7 +4041,7 @@ div.attendance-calendar-add div.row div.formw,div.attendance-calendar-edit div.r padding:2px; font-size:120%; font-weight: bold; - margin:5px; + /* margin:5px; */ padding:5px; } @@ -4301,9 +4301,9 @@ span.form_required { } .attendance-users-table td { - height:66px; + /* height:66px; */ } .attendance-calendar-table td { - height:66px; + /* height:66px; */ } diff --git a/main/css/chamilo_green/default.css b/main/css/chamilo_green/default.css index dc958ce796..b2b0a19010 100644 --- a/main/css/chamilo_green/default.css +++ b/main/css/chamilo_green/default.css @@ -4056,8 +4056,7 @@ div.attendance-calendar-add div.row div.formw,div.attendance-calendar-edit div.r background-color:none; padding:2px; font-size:120%; - font-weight: bold; - margin:5px; + font-weight: bold; padding:5px; } @@ -4317,9 +4316,9 @@ span.form_required { } .attendance-users-table td { - height:66px; + /* height:66px; */ } .attendance-calendar-table td { - height:66px; +/* height:66px; */ } diff --git a/main/css/chamilo_orange/default.css b/main/css/chamilo_orange/default.css index 50f9aed304..a9b5152017 100644 --- a/main/css/chamilo_orange/default.css +++ b/main/css/chamilo_orange/default.css @@ -4034,8 +4034,7 @@ div.attendance-calendar-add div.row div.formw,div.attendance-calendar-edit div.r background-color:none; padding:2px; font-size:120%; - font-weight: bold; - margin:5px; + font-weight: bold; padding:5px; } @@ -4295,9 +4294,9 @@ span.form_required { } .attendance-users-table td { - height:66px; + /* height:66px; */ } .attendance-calendar-table td { - height:66px; + /*height:66px; */ } diff --git a/main/css/chamilo_red/default.css b/main/css/chamilo_red/default.css index f5ed7b03dc..0cc14dff24 100644 --- a/main/css/chamilo_red/default.css +++ b/main/css/chamilo_red/default.css @@ -4044,8 +4044,7 @@ div.attendance-calendar-add div.row div.formw,div.attendance-calendar-edit div.r background-color:none; padding:2px; font-size:120%; - font-weight: bold; - margin:5px; + font-weight: bold; padding:5px; } @@ -4305,9 +4304,9 @@ span.form_required { } .attendance-users-table td { - height:66px; + /* height:66px; */ } .attendance-calendar-table td { - height:66px; + /*height:66px;*/ } diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index b169c90628..587111d152 100755 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -695,26 +695,53 @@ class Attendance } } 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) { + public function get_attendance_calendar($attendance_id, $type = 'all') { 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 "; + $attendance_id = intval($attendance_id); + $sql = "SELECT * FROM $tbl_attendance_calendar WHERE attendance_id = '$attendance_id' "; + $filter_where = ''; + if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done'))) { + $type = 'all'; + } + switch ($type ) { + case 'today': + //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )'; + break; + case 'all_done': + $sql .= " AND done_attendance = 1 "; + break; + case 'all_not_done': + $sql .= " AND done_attendance = 0 "; + break; + case 'all': + default: + break; + } + $sql .= " ORDER BY date_time "; + $rs = Database::query($sql); $data = array(); if (Database::num_rows($rs) > 0) { - while ($row = Database::fetch_array($rs)) { - $row['date_time'] = api_get_local_time($row['date_time']); - $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); - $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT); - $data[] = $row; + while ($row = Database::fetch_array($rs,'ASSOC')) { + $row['db_date_time'] = $row['date_time']; + $row['date_time'] = api_get_local_time($row['date_time']); + $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); + $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT); + if ($type == 'today') { + if (date('d-m-Y', api_strtotime($row['date_time'])) == api_strtotime(api_get_local_time())) { + $data[] = $row; + } + } else { + $data[] = $row; + } } } return $data; @@ -742,48 +769,73 @@ class Attendance /** * save repeated date inside attendance calendar table + * @param int attendance id + * @param int start date in tms + * @param int end date in tms + * @param string repeat type daily, weekly, monthlyByDate + */ public function attendance_repeat_calendar_add($attendance_id, $start_date, $end_date, $repeat_type) { - $attendance_id = intval($attendance_id); - // save start date - $datetime = date('Y-m-d H:i:s', $start_date); - $datetimezone = api_get_utc_datetime($datetime); + $datetimezone = api_get_utc_datetime($start_date); $this->set_date_time($datetimezone); $res = $this->attendance_calendar_add($attendance_id); - - // save repeated dates + + //86400 = 24 hours in seconds + //604800 = 1 week in seconds + // Saves repeated dates switch($repeat_type) { case 'daily': + $j = 1; for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { - $datetime = date('Y-m-d H:i:s', $i); - $datetimezone = api_get_utc_datetime($datetime); + //$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 0, $j); //to support europe timezones + $datetimezone = api_get_utc_datetime($i); $this->set_date_time($datetimezone); $res = $this->attendance_calendar_add($attendance_id); + $j++; } break; exit; case 'weekly': - for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { - $datetime = date('Y-m-d H:i:s', $i); - $datetimezone = api_get_utc_datetime($datetime); + $j = 1; + for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { + $datetimezone = api_get_utc_datetime($i); + //$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 0, $j*7); //to support europe timezones $this->set_date_time($datetimezone); $res = $this->attendance_calendar_add($attendance_id); + $j++; } break; case 'monthlyByDate': - $next_start = $this->add_month($start_date); - while($next_start <= $end_date) { - $datetime = date('Y-m-d H:i:s', $next_start); - $datetimezone = api_get_utc_datetime($datetime); + $j = 1; + //@todo fix bug with february + for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { + $datetimezone = api_get_utc_datetime($i); + //$datetimezone = api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , $j); //to support europe timezones $this->set_date_time($datetimezone); $res = $this->attendance_calendar_add($attendance_id); - $next_start = $this->add_month($next_start); + $j++; } + + //$next_start = $this->add_month($start_date); + /* + $next_start = api_strtotime(api_get_utc_date_add(api_get_utc_datetime($start_date), 0 , 1),'UTC'); + error_log('22-->$start_date '.$start_date); + error_log('$next_start '.$next_start); + error_log('$end_date '.$end_date); + while($next_start <= $end_date) { + //$datetime = date('Y-m-d H:i:s', $next_start); + $datetimezone = api_get_utc_datetime($next_start); + error_log('$datetimezone n loop '.$datetimezone); + $this->set_date_time($datetimezone); + $res = $this->attendance_calendar_add($attendance_id); + //$next_start = $this->add_month($next_start); + $next_start = api_strtotime(api_get_utc_date_add(api_get_utc_datetime($next_start), 0 , 1),'UTC'); + error_log('$next_start in loop '.$next_start); + }*/ break; } - } /** @@ -793,14 +845,22 @@ class Attendance * @return int The new timestamp */ private function add_month($timestamp, $num=1) { - list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp)); + $values = api_get_utc_datetime($timestamp); + $values = str_replace(array(':','-',' '), '/', $values); + list($y, $m, $d, $h, $n, $s) = split('/',$values); if($m+$num>12) { $y += floor($num/12); $m += $num%12; } else { $m += $num; } - return mktime($h, $n, $s, $m, $d, $y); + //date_default_timezone_set('UTC'); + // return mktime($h, $n, $s, $m, $d, $y); + $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC'); + if (!empty($result)) { + return $result; + } + return false; } /**