Minor fixes coming from 1.10

skala
Julio Montoya 13 years ago
parent 7e25e09c61
commit e1a0ef63b7
  1. 14
      main/exercice/exercise_show.php
  2. 9
      main/exercice/exercise_submit.php
  3. 9
      main/exercice/question.class.php
  4. 5
      main/exercice/question_pool.php
  5. 258
      main/inc/ajax/model.ajax.php
  6. 164
      main/inc/lib/course.lib.php
  7. 12
      main/inc/lib/internationalization.lib.php
  8. 154
      main/inc/lib/sortable_table.class.php

@ -61,7 +61,13 @@ if ( empty ( $action ) ) { $action = $_REQUEST['action']; }
$id = intval($_REQUEST['id']); //exe id
if (empty($id)) {
api_not_allowed();
api_not_allowed(true);
}
if (api_is_course_session_coach(api_get_user_id(), api_get_course_id(), api_get_session_id())) {
if (!api_coach_can_edit_view_results(api_get_course_id(), api_get_session_id())) {
api_not_allowed(true);
}
}
$is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
@ -71,7 +77,7 @@ $track_exercise_info = get_exercise_track_exercise_info($id);
//No track info
if (empty($track_exercise_info)) {
api_not_allowed();
api_not_allowed(true);
}
$exercise_id = $track_exercise_info['id'];
@ -100,7 +106,7 @@ if (isset($session_control_key) && !exercise_time_control_is_valid($exercise_id,
//Only users can see their own results
if (!$is_allowedToEdit) {
if ($student_id != $current_user_id) {
api_not_allowed();
api_not_allowed(true);
}
}
@ -701,7 +707,7 @@ if ($origin != 'learnpath') {
echo '<script type="text/javascript">'.$href.'</script>';
//Record the results in the learning path, using the SCORM interface (API)
echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting'); </script>";
echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
echo '</body></html>';
} else {
Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));

@ -457,7 +457,7 @@ if ($formSent && isset($_POST)) {
}
}
}
header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
} else {
//Time control is only enabled for ONE PER PAGE
@ -479,13 +479,12 @@ if ($formSent && isset($_POST)) {
Database::query($update_query);*/
}
if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
//header("Location: exercise_show.php?id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit;
}
} else {
if ($debug) { error_log('10. Redirecting to exercise_submit.php'); }
header("Location: exercise_submit.php?exerciseId=$exerciseId&origin=$origin");
header("Location: exercise_submit.php?".api_get_cidreq()."&exerciseId=$exerciseId&origin=$origin");
exit;
}
}
@ -835,6 +834,7 @@ if (!empty($error)) {
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'");
$.ajax({
type:"post",
async: false,
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
success: function(return_value) {
@ -899,6 +899,7 @@ if (!empty($error)) {
$.ajax({
type:"post",
async: false,
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,
success: function(return_value) {

@ -28,6 +28,7 @@ define('MULTIPLE_ANSWER_TRUE_FALSE', 11);
define('MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE', 12);
define('ORAL_EXPRESSION', 13);
define('GLOBAL_MULTIPLE_ANSWER', 14);
define('MEDIA_QUESTION', 15);
//Some alias used in the QTI exports
define('MCUA', 1);
@ -55,6 +56,8 @@ abstract class Question
public $level;
public $picture;
public $exerciseList; // array with the list of exercises which this question is in
public $category_list;
public $parent_id;
public $category;
private $isContent;
public $course;
@ -75,7 +78,7 @@ abstract class Question
MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'),
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array('multiple_answer_combination_true_false.class.php', 'MultipleAnswerCombinationTrueFalse'),
GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php' , 'GlobalMultipleAnswer'),
//MEDIA_QUESTION => array('media_question.class.php' , 'MediaQuestion')
);
/**
@ -95,6 +98,8 @@ abstract class Question
$this->extra=''; // This variable is used when loading an exercise like an scenario with an special hotspot: final_overlap, final_missing, final_excess
$this->exerciseList=array();
$this->course = api_get_course_info();
$this->category_list = array();
$this->parent_id = 0;
}
public function getIsContent() {
@ -971,7 +976,7 @@ abstract class Question
}
}
}
$sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql);

@ -247,8 +247,7 @@ $htmlHeadXtra[] = "
function confirm_your_choice() {
return confirm('$confirmYourChoice');
}
</script>
";
</script>";
Display::display_header($nameTools,'Exercise');
@ -285,7 +284,7 @@ if (isset($type)) {
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
// Session list, if sessions are used.
$session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
$session_list = SessionManager::get_sessions_by_general_coach(api_get_user_id());
$tabAttrParam = array('class'=>'chzn-select', 'onchange'=>'submit_form(this)'); // when sessions are used
$labelFormRow = get_lang('Session');
$session_select_list = array();

@ -10,22 +10,28 @@ require_once '../global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
// 1. Setting variables needed by jqgrid
$action = $_GET['a'];
$page = intval($_REQUEST['page']); //page
$limit = intval($_REQUEST['rows']); //quantity of rows
$sidx = $_REQUEST['sidx']; //index (field) to filter
$sidx = $_REQUEST['sidx']; //index (field) to filter
$sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, array('asc','desc'))) {
$sord = 'desc';
if (strpos(strtolower($sidx), 'asc') !== false) {
$sidx = str_replace(array('asc', ','), '', $sidx);
$sord = 'asc';
}
if (strpos(strtolower($sidx), 'desc') !== false) {
$sidx = str_replace(array('desc', ','), '', $sidx);
$sord = 'desc';
}
if (!in_array($action, array(
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_user_skill_ranking',
'get_usergroups_teacher'))
) {
@ -57,7 +63,7 @@ function get_where_clause($col, $oper, $val) {
global $ops;
if (empty($col)){
return '';
}
}
if($oper == 'bw' || $oper == 'bn') $val .= '%';
if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
@ -74,32 +80,32 @@ $search_string = isset($_REQUEST['searchString']) ? $_REQUEST['searchString']
if ($_REQUEST['_search'] == 'true') {
$where_condition = ' 1 = 1 ';
$where_condition_in_form = get_where_clause($search_field, $search_oper, $search_string);
if (!empty($where_condition_in_form)) {
$where_condition .= ' AND '.$where_condition_in_form;
}
$filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
if (!empty($filters)) {
$where_condition .= ' AND ( ';
$counter = 0;
foreach ($filters->rules as $key=>$rule) {
$where_condition .= get_where_clause($rule->field,$rule->op, $rule->data);
if ($counter < count($filters->rules) -1) {
if ($counter < count($filters->rules) -1) {
$where_condition .= $filters->groupOp;
}
$counter++;
}
$where_condition .= ' ) ';
}
}
}
//var_dump($where_condition);
// get index row - i.e. user click to sort $sord = $_GET['sord'];
// get the direction
// get index row - i.e. user click to sort $sord = $_GET['sord'];
// get the direction
if (!$sidx) $sidx = 1;
//2. Selecting the count FIRST
//@todo rework this
@ -111,28 +117,28 @@ switch ($action) {
case 'get_work_user_list':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$work_id = $_REQUEST['work_id'];
$count = get_count_work($work_id);
$count = get_count_work($work_id);
break;
case 'get_exercise_results':
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
$exercise_id = $_REQUEST['exerciseId'];
if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
$filter_user = intval($_GET['filter_by_user']);
if ($where_condition == "") {
$where_condition .= " te.exe_user_id = '$filter_user'" ;
} else {
$where_condition .= " AND te.exe_user_id = '$filter_user'";
}
}
$count = get_count_exam_results($exercise_id, $where_condition);
}
$count = get_count_exam_results($exercise_id, $where_condition);
break;
case 'get_hotpotatoes_exercise_results':
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
$hotpot_path = $_REQUEST['path'];
$count = get_count_exam_hotpotatoes_results($hotpot_path);
$count = get_count_exam_hotpotatoes_results($hotpot_path);
break;
case 'get_sessions':
case 'get_sessions':
$count = SessionManager::get_count_admin();
break;
case 'get_timelines':
@ -147,15 +153,15 @@ switch ($action) {
break;
case 'get_event_email_template':
$obj = new EventEmailTemplate();
$count = $obj->get_count();
$count = $obj->get_count();
break;
case 'get_careers':
$obj = new Career();
$count = $obj->get_count();
break;
case 'get_promotions':
case 'get_promotions':
$obj = new Promotion();
$count = $obj->get_count();
$count = $obj->get_count();
break;
case 'get_grade_models':
$obj = new GradeModel();
@ -169,34 +175,34 @@ switch ($action) {
$obj = new UserGroup();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$course_id = api_get_course_int_id();
if ($type == 'registered') {
if ($type == 'registered') {
$count = $obj->get_usergroup_by_course_with_data_count($course_id);
} else {
$count = $obj->get_count();
$count = $obj->get_count();
}
break;
default:
exit;
exit;
}
//3. Calculating first, end, etc
//3. Calculating first, end, etc
$total_pages = 0;
if ($count > 0) {
if ($count > 0) {
if (!empty($limit)) {
$total_pages = ceil($count/$limit);
}
}
if ($page > $total_pages) {
if ($page > $total_pages) {
$page = $total_pages;
}
}
$start = $limit * $page - $limit;
if ($start < 0 ) {
$start = 0;
}
}
//4. Deleting an element if the user wants to
if ($_REQUEST['oper'] == 'del') {
if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') {
$obj->delete($_REQUEST['id']);
}
@ -205,13 +211,13 @@ $is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(
//5. Querying the DB for the elements
$columns = array();
switch ($action) {
case 'get_user_skill_ranking':
switch ($action) {
case 'get_user_skill_ranking':
$columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
$result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
$result = msort($result, 'skills_acquired', 'asc');
$skills_in_course = array();
$skills_in_course = array();
if (!empty($result)) {
//$counter = 1;
foreach ($result as &$item) {
@ -219,52 +225,52 @@ switch ($action) {
$personal_course_list = UserManager::get_personal_session_course_list($item['user_id']);
$count_skill_by_course = array();
foreach ($personal_course_list as $course_item) {
if (!isset($skills_in_course[$course_item['code']])) {
if (!isset($skills_in_course[$course_item['code']])) {
$count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
$skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
$skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
} else {
$count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
}
}
}
$item['photo'] = Display::img($user_info['avatar_small']);
$item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
$item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
}
}
break;
case 'get_work_user_list':
case 'get_work_user_list':
if (isset($_GET['type']) && $_GET['type'] == 'simple') {
$columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
} else {
$columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions');
$columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions');
}
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
break;
case 'get_exercise_results':
$course = api_get_course_info();
$course = api_get_course_info();
//used inside get_exam_results_data()
$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
if ($is_allowedToEdit) {
$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
} else {
//$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
}
$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
}
$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
break;
case 'get_hotpotatoes_exercise_results':
$course = api_get_course_info();
$course = api_get_course_info();
//used inside get_exam_results_data()
$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
break;
case 'get_sessions':
$columns = array('name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility');
$result = SessionManager::get_sessions_admin(array('where'=> $where_condition, 'order'=>"$sidx $sord", 'limit'=> "$start , $limit"));
break;
case 'get_timelines':
$columns = array('headline', 'actions');
$columns = array('name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility');
$result = SessionManager::get_sessions_admin(array('where'=> $where_condition, 'order'=>"$sidx $sord", 'limit'=> "$start , $limit"));
break;
case 'get_timelines':
$columns = array('headline', 'actions');
//$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id');
if(!in_array($sidx, $columns)) {
$sidx = 'headline';
}
@ -273,19 +279,19 @@ switch ($action) {
$new_result = array();
foreach ($result as $item) {
if (!$item['status']) {
$item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
$item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
}
$item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH).'timeline/view.php?id='.$item['id']);
$item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH).'timeline/?action=add_item&parent_id='.$item['id']);
$item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'timeline/?action=edit&id='.$item['id']);
$item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'timeline/?action=delete&id='.$item['id']);
$new_result[] = $item;
}
$result = $new_result;
}
$result = $new_result;
break;
case 'get_gradebooks':
$columns = array('name', 'certificates','skills', 'actions', 'has_certificates');
case 'get_gradebooks':
$columns = array('name', 'certificates','skills', 'actions', 'has_certificates');
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}
@ -296,54 +302,54 @@ switch ($action) {
continue;
}
$skills = $obj->get_skills_by_gradebook($item['id']);
//Fixes bug when gradebook doesn't have names
if (empty($item['name'])) {
$item['name'] = $item['course_code'];
$item['name'] = $item['course_code'];
} else {
//$item['name'] = $item['name'].' ['.$item['course_code'].']';
}
$item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH).'gradebook/index.php?id_session=0&cidReq='.$item['course_code']);
if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
$item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
$item['has_certificates'] = '1';
$item['has_certificates'] = '1';
} else {
$item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
$item['has_certificates'] = '0';
}
}
if (!empty($skills)) {
foreach($skills as $skill) {
$item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
$item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
}
}
$new_result[] = $item;
}
}
$result = $new_result;
break;
case 'get_event_email_template':
$columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
case 'get_event_email_template':
$columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
if(!in_array($sidx, $columns)) {
$sidx = 'subject';
}
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
foreach ($result as $item) {
$language_info = api_get_language_info($item['language_id']);
$item['language_id'] = $language_info['english_name'];
$item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'admin/event_type.php?action=edit&event_type_name='.$item['event_type_name']);
$item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'admin/event_controller.php?action=delete&id='.$item['id']);
/*if (!$item['status']) {
$item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>';
}*/
$new_result[] = $item;
}
$result = $new_result;
break;
case 'get_careers':
$columns = array('name', 'description', 'actions');
}
$result = $new_result;
break;
case 'get_careers':
$columns = array('name', 'description', 'actions');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
@ -354,14 +360,14 @@ switch ($action) {
$item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
}
$new_result[] = $item;
}
$result = $new_result;
}
$result = $new_result;
break;
case 'get_promotions':
case 'get_promotions':
$columns = array('name', 'career', 'description', 'actions');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
}
$result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "$obj->table p LEFT JOIN ".Database::get_main_table(TABLE_CAREER)." c ON c.id = p.career_id ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
foreach($result as $item) {
@ -369,7 +375,7 @@ switch ($action) {
$item['name'] = '<font style="color:#AAA">'.$item['name'].'</font>';
}
$new_result[] = $item;
}
}
$result = $new_result;
break;
case 'get_grade_models':
@ -389,26 +395,26 @@ switch ($action) {
$result = Database::select('*', $obj->table, array('order'=>"name $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
if (!empty($result)) {
foreach ($result as $group) {
foreach ($result as $group) {
$group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
$group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$new_result[] = $group;
}
$result = $new_result;
}
$columns = array('name', 'users', 'courses','sessions');
}
$columns = array('name', 'users', 'courses','sessions');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}
//Multidimensional sort
msort($result, $sidx);
break;
break;
case 'get_usergroups_teacher':
$columns = array('name', 'users', 'actions');
$options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
$columns = array('name', 'users', 'actions');
$options = array('order'=>"name $sord", 'LIMIT'=> "$start , $limit");
switch ($type) {
case 'not_registered':
case 'not_registered':
$options['course_id'] = $course_id;
$result = $obj->get_usergroup_not_in_course($options);
break;
@ -416,55 +422,55 @@ switch ($action) {
$options['where'] = array(" usergroup.course_id = ? " => $course_id);
$result = $obj->get_usergroup_in_course($options);
break;
}
$new_result = array();
}
$new_result = array();
if (!empty($result)) {
foreach ($result as $group) {
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
$url = 'class.php?action=remove_class_from_course&id='.$group['id'];
$icon = Display::return_icon('delete.png', get_lang('Remove'));
} else {
$url = 'class.php?action=add_class_to_course&id='.$group['id'];
$icon = Display::return_icon('add.png', get_lang('Add'));
$icon = Display::return_icon('add.png', get_lang('Add'));
}
$group['actions'] = Display::url($icon, $url);
$group['actions'] = Display::url($icon, $url);
$new_result[] = $group;
}
$result = $new_result;
$result = $new_result;
}
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}
//Multidimensional sort
msort($result, $sidx);
msort($result, $sidx);
break;
default:
exit;
default:
exit;
}
//var_dump($result);
$allowed_actions = array('get_careers',
'get_promotions',
$allowed_actions = array('get_careers',
'get_promotions',
'get_usergroups',
'get_usergroups_teacher',
'get_gradebooks',
'get_sessions',
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_grade_models',
'get_gradebooks',
'get_sessions',
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_grade_models',
'get_event_email_template',
'get_user_skill_ranking');
//5. Creating an obj to return a json
if (in_array($action, $allowed_actions)) {
$response = new stdClass();
$response->page = $page;
$response = new stdClass();
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$response->records = $count;
$i=0;
if (!empty($result)) {
foreach ($result as $row) {
@ -474,15 +480,15 @@ if (in_array($action, $allowed_actions)) {
$response->rows[$i]['id']=$i;
} else {
$response->rows[$i]['id']=$row['id'];
}
$array = array();
}
$array = array();
foreach ($columns as $col) {
$array[] = $row[$col];
}
$array[] = isset($row[$col]) ? $row[$col] : null;
}
$response->rows[$i]['cell']=$array;
$i++;
$i++;
}
}
}
echo json_encode($response);
}

@ -41,7 +41,7 @@
CourseManager::has_virtual_courses_from_code($real_course_code, $user_id)
CourseManager::get_target_of_linked_course($virtual_course_code)
TITLE AND CODE FUNCTIONS
TITLE AND CODE FUNCTIONS
CourseManager::create_combined_name($user_is_registered_in_real_course, $real_course_name, $virtual_course_list)
CourseManager::create_combined_code($user_is_registered_in_real_course, $real_course_code, $virtual_course_list)
@ -127,9 +127,9 @@ class CourseManager {
$course_info = api_get_course_info_by_id($course_id);
if (!empty($course_info)) {
prepare_course_repository($course_info['directory'], $course_info['code']);
prepare_course_repository($course_info['directory'], $course_info['code']);
fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $params['exemplary_content']);
if (api_get_setting('gradebook_enable_grade_model') == 'true') {
//Create gradebook_category for the new course and add a gradebook model for the course
if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') {
@ -1005,7 +1005,7 @@ class CourseManager {
$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
WHERE user_id = $user_id AND relation_type<>".COURSE_RELATION_TYPE_RRHH." $condition_course ";
$result = Database::fetch_array(Database::query($sql));
if (!empty($result)) {
@ -1120,7 +1120,7 @@ class CourseManager {
* @param integer $session_id the id of the session
* @param string $limit the LIMIT statement of the sql statement
* @param string $order_by the field to order the users by. Valid values are 'lastname', 'firstname', 'username', 'email', 'official_code' OR a part of a SQL statement that starts with ORDER BY ...
* @param int if using the session_id: 0 or 2 (student, coach), if using session_id = 0 STUDENT or COURSEMANAGER
* @param int if using the session_id: 0 or 2 (student, coach), if using session_id = 0 STUDENT or COURSEMANAGER
* @return array
*/
public static function get_user_list_from_course_code($course_code, $session_id = 0, $limit = '', $order_by = '', $filter_by_status = null) {
@ -1137,46 +1137,46 @@ class CourseManager {
$order_by = '';
}
}
$filter_by_status_condition = null;
if (!empty($session_id)) {
$sql = 'SELECT DISTINCT user.user_id, session_course_user.status as status_session, user.* ';
$sql .= ' FROM '.Database::get_main_table(TABLE_MAIN_USER).' as user ';
$sql .= ' FROM '.Database::get_main_table(TABLE_MAIN_USER).' as user ';
$sql .= ' LEFT JOIN '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).' as session_course_user
ON user.user_id = session_course_user.id_user
AND session_course_user.course_code="'.$course_code.'"
AND session_course_user.id_session = '.$session_id;
$where[] = ' session_course_user.course_code IS NOT NULL ';
// 2 = coach
// 0 = student
if (isset($filter_by_status)) {
// 0 = student
if (isset($filter_by_status)) {
$filter_by_status = intval($filter_by_status);
$filter_by_status_condition = " session_course_user.status = $filter_by_status AND ";
$filter_by_status_condition = " session_course_user.status = $filter_by_status AND ";
}
} else {
} else {
$sql = 'SELECT DISTINCT course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.* ';
$sql .= ' FROM '.Database::get_main_table(TABLE_MAIN_USER).' as user ';
$sql .= ' LEFT JOIN '.Database::get_main_table(TABLE_MAIN_COURSE_USER).' as course_rel_user
ON user.user_id = course_rel_user.user_id AND course_rel_user.relation_type<>'.COURSE_RELATION_TYPE_RRHH.'
AND course_rel_user.course_code="'.$course_code.'"';
$where[] = ' course_rel_user.course_code IS NOT NULL ';
if (isset($filter_by_status) && $filter_by_status != '') {
$filter_by_status = intval($filter_by_status);
$filter_by_status_condition = " course_rel_user.status = $filter_by_status AND ";
}
}
$multiple_access_url = api_get_multiple_access_url();
if ($multiple_access_url) {
$sql .= ' LEFT JOIN '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ON (au.user_id = user.user_id) ';
}
$sql .= ' WHERE '.$filter_by_status_condition.' '.implode(' OR ', $where);
if ($multiple_access_url) {
$current_access_url_id = api_get_current_access_url_id();
$sql .= " AND (access_url_id = $current_access_url_id ) ";
@ -1187,7 +1187,7 @@ class CourseManager {
$users = array();
if (Database::num_rows($rs)) {
while ($user = Database::fetch_array($rs)) {
while ($user = Database::fetch_array($rs)) {
$user_info = $user;
$user_info['status'] = $user['status'];
@ -1247,7 +1247,7 @@ class CourseManager {
$current_access_url_id = api_get_current_access_url_id();
$sql .= " AND (access_url_id = $current_access_url_id ) ";
}
$rs = Database::query($sql);
$rs = Database::query($sql);
$count = 0;
if (Database::num_rows($rs)) {
$user = Database::fetch_array($rs);
@ -1285,7 +1285,7 @@ class CourseManager {
}
// We get the session coach.
$rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id="'.$session_id.'"');
$rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id="'.$session_id.'"');
$session_id_coach = Database::result($rs, 0, 'id_coach');
$user_info = Database::get_user_info_from_id($session_id_coach);
$user_info['status'] = $user['status'];
@ -1324,7 +1324,7 @@ class CourseManager {
// students subscribed to the course through a session
if ($with_session) {
$sql_query = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
$sql_query = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
WHERE course_code = '$course_code' AND status <> 2";
if ($session_id != 0) {
$sql_query .= ' AND id_session = '.$session_id;
@ -1346,11 +1346,11 @@ class CourseManager {
*/
public static function get_teacher_list_from_course_code($course_code) {
$course_code = Database::escape_string($course_code);
$teachers = array();
$sql = "SELECT u.user_id, u.lastname, u.firstname, u.email, u.username, u.status
FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." cu INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u
$teachers = array();
$sql = "SELECT DISTINCT u.user_id, u.lastname, u.firstname, u.email, u.username, u.status
FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." cu INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u
ON (cu.user_id = u.user_id)
WHERE cu.course_code = '$course_code' AND
WHERE cu.course_code = '$course_code' AND
cu.status = 1 ";
$rs = Database::query($sql);
while ($teacher = Database::fetch_array($rs)) {
@ -1404,7 +1404,7 @@ class CourseManager {
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$coaches = array();
$sql = "SELECT u.user_id,u.lastname,u.firstname,u.username FROM $tbl_user u,$tbl_session_course_user scu
$sql = "SELECT DISTINCT u.user_id,u.lastname,u.firstname,u.username FROM $tbl_user u,$tbl_session_course_user scu
WHERE u.user_id = scu.id_user AND scu.id_session = '$session_id' AND scu.course_code = '$course_code' AND scu.status = 2";
$rs = Database::query($sql);
@ -1531,25 +1531,25 @@ class CourseManager {
$course_id = $course_info['real_id'];
$group_list = array();
$session_id != 0 ? $session_condition = ' WHERE g.session_id IN(1,'.intval($session_id).')' : $session_condition = ' WHERE g.session_id = 0';
if ($in_get_empty_group == 0) {
// get only groups that are not empty
$sql = "SELECT DISTINCT g.id, g.name
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
INNER JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id)
$session_condition
$session_condition
ORDER BY g.name";
}
else {
// get all groups even if they are empty
$sql = "SELECT g.id, g.name
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
$session_condition
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
$session_condition
AND c_id = $course_id";
}
$result = Database::query($sql);
while ($group_data = Database::fetch_array($result)) {
$group_data['userNb'] = GroupManager::number_of_students($group_data['id'], $course_id);
$group_list[$group_data['id']] = $group_data;
@ -2751,7 +2751,7 @@ class CourseManager {
$course_image = $store_path.'/course-pic.png'; // image name for courses
$course_medium_image = $store_path.'/course-pic85x85.png';
//$extension = strtolower(substr(strrchr($filename, '.'), 1));
if (file_exists($course_image)) {
@unlink($course_image);
}
@ -2807,7 +2807,7 @@ class CourseManager {
$html .= '<div class="span6">';
$html .='<h3>'.$params['title'].$params['notifications'].'</h3> ';
if (!empty($params['subtitle'])) {
$html .= '<small>'.$params['subtitle'].'</small>';
}
@ -2817,8 +2817,8 @@ class CourseManager {
if (!empty($params['coaches'])) {
$html .= '<h5>'.Display::return_icon('teacher.png', get_lang('Coach'), array(), ICON_SIZE_TINY).$params['coaches'].'</h5>';
}
$html .= '</div>';
$html .= '</div>';
@ -2866,7 +2866,7 @@ class CourseManager {
$rs_special_course = Database::query($sql);
$number_of_courses = Database::num_rows($rs_special_course);
$key = 0;
$html = '';
if ($number_of_courses > 0) {
@ -2887,7 +2887,7 @@ class CourseManager {
$params['icon'] = Display::return_icon('blackboard.png', $course_info['title'], array(), ICON_SIZE_LARGE);
$params['right_actions'] = '';
$params['right_actions'] = '';
if (api_is_platform_admin()) {
if ($load_dirs) {
$params['right_actions'] .= '<a id="document_preview_'.$course['real_id'].'_0" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
@ -2901,9 +2901,9 @@ class CourseManager {
}
} else {
if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
if ($load_dirs) {
if ($load_dirs) {
$params['right_actions'] .= '<a id="document_preview_'.$course['real_id'].'_0" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
$params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course['real_id'].'_0', 'class'=>'document_preview_container'));
$params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course['real_id'].'_0', 'class'=>'document_preview_container'));
}
}
}
@ -2925,11 +2925,11 @@ class CourseManager {
$params['title'] = $course_title;
$params['link'] = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/?id_session=0&amp;autoreg=1';
if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
$params['notifications'] = $show_notification;
}
$html .= self::course_item_html($params, false);
$key++;
}
@ -2963,9 +2963,9 @@ class CourseManager {
$params['title'] = $row['title'];
$html .= self::course_item_parent(self::course_item_html($params, true), self :: display_courses_in_category($row['id'], $load_dirs));
}
// Step 2: We display the course without a user category.
$html .= self :: display_courses_in_category(0, $load_dirs);
$html .= self :: display_courses_in_category(0, $load_dirs);
return $html;
}
@ -2986,7 +2986,7 @@ class CourseManager {
// Get course list auto-register
$special_course_list = self::get_special_course_list();
$without_special_courses = '';
if (!empty($special_course_list)) {
$without_special_courses = ' AND course.code NOT IN ("'.implode('","',$special_course_list).'")';
@ -3007,11 +3007,11 @@ class CourseManager {
}
// Use user's classification for courses (if any).
$sql .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
$result = Database::query($sql);
$result = Database::query($sql);
$status_icon = '';
$html = '';
$course_list = array();
// Browse through all courses.
@ -3020,7 +3020,7 @@ class CourseManager {
//$course['id_session'] = null;
$course_info['id_session'] = null;
$course_info['status'] = $course['status'];
//In order to avoid doubles
if (in_array($course_info['real_id'], $course_list)) {
continue;
@ -3062,7 +3062,7 @@ class CourseManager {
}
}
}
$course_title = $course_info['title'];
$course_title_url = '';
@ -3085,7 +3085,7 @@ class CourseManager {
$params['icon'] = $status_icon;
$params['title'] = $course_title;
$params['teachers'] = $teachers;
if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
$params['notifications'] = $show_notification;
}
@ -3094,7 +3094,7 @@ class CourseManager {
if (empty($user_category_id)) {
$is_subcontent = false;
}
$html .= self::course_item_html($params, $is_subcontent);
$html .= self::course_item_html($params, $is_subcontent);
}
return $html;
}
@ -3216,7 +3216,7 @@ class CourseManager {
$params['title'] = $session_title;
$params['right_actions'] = '';
if ($course_visibility != COURSE_VISIBILITY_CLOSED) {
if ($load_dirs) {
$params['right_actions'] .= '<a id="document_preview_'.$course_info['real_id'].'_'.$course_info['id_session'].'" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
@ -3674,22 +3674,22 @@ class CourseManager {
public static function return_hot_courses($days = 30, $limit = 5) {
global $_configuration;
$limit = intval($limit);
//Getting my courses
$my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id());
$my_course_code_list = array();
foreach ($my_course_list as $course) {
$my_course_code_list[$course['real_id']] = $course['real_id'];
}
if (api_is_drh()) {
$courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
foreach ($courses as $course) {
$my_course_code_list[$course['real_id']] = $course['real_id'];
}
}
}
$table_course_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$table_course_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
@ -3707,7 +3707,7 @@ class CourseManager {
$sql = "SELECT COUNT(course_access_id) course_count, a.course_code, visibility ".
"FROM $table_course c INNER JOIN $table_course_access a ".
" ON (c.code = a.course_code) INNER JOIN $table_course_url u ON u.course_code = a.course_code ".
" ON (c.code = a.course_code) INNER JOIN $table_course_url u ON u.course_code = a.course_code ".
" WHERE u.access_url_id = ".$_configuration['access_url']." AND".
" login_course_date <= now() AND ".
" login_course_date > DATE_SUB(now(), INTERVAL $days DAY) AND".
@ -3719,36 +3719,36 @@ class CourseManager {
$result = Database::query($sql);
$courses = array();
if (Database::num_rows($result)) {
$courses = Database::store_result($result, 'ASSOC');
$courses = self::process_hot_course_item($courses, $my_course_code_list);
$courses = Database::store_result($result, 'ASSOC');
$courses = self::process_hot_course_item($courses, $my_course_code_list);
}
return $courses;
}
public static function process_hot_course_item($courses, $my_course_code_list = array()) {
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
foreach ($courses as &$my_course) {
$course_info = api_get_course_info($my_course['course_code']);
$course_info = api_get_course_info($my_course['course_code']);
$my_course['extra_info'] = $course_info;
$my_course['extra_info']['go_to_course_button'] = '';
$my_course['extra_info']['register_button'] = '';
$access_link = self::get_access_link_by_user(api_get_user_id(), $course_info, $my_course_code_list);
//Course visibility
//Course visibility
if ($access_link && in_array('register', $access_link)) {
$stok = Security::get_token();
$my_course['extra_info']['register_button'] = Display::url(get_lang('Subscribe'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php?action=subscribe&amp;sec_token='.$stok, array('class' => 'btn btn-primary'));
}
if ($access_link && in_array('enter', $access_link)) {
$my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php', array('class' => 'btn btn-primary'));
$my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php', array('class' => 'btn btn-primary'));
}
//Description
$my_course['extra_info']['description_button'] = '';
if ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || in_array($course_info['real_id'], $my_course_code_list) ) {
$my_course['extra_info']['description_button'] = Display::url(get_lang('Description'), api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$course_info['code'], array('class' => 'ajax btn'));
$my_course['extra_info']['description_button'] = Display::url(get_lang('Description'), api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$course_info['code'], array('class' => 'ajax btn'));
}
$my_course['extra_info']['teachers'] = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
@ -3810,8 +3810,8 @@ class CourseManager {
$res = Database::query($sql);
$row = Database::fetch_row($res);
return $row[0];
}
}
/**
* Return a link to go to the course, validating the visibility of the
* course and the user status
@ -3824,40 +3824,40 @@ class CourseManager {
if (empty($uid) or empty($course)) { return false; }
if (empty($user_courses)) {
// get the array of courses to which the user is subscribed
$user_courses = CourseManager::get_courses_list_by_user_id($uid);
$user_courses = CourseManager::get_courses_list_by_user_id($uid);
foreach ($user_courses as $k => $v) {
$user_courses[$k] = $v['real_id'];
}
}
}
if (!isset($course['real_id']) && empty($course['real_id'])) {
$course = api_get_course_info($course['code']);
}
$is_admin = api_is_platform_admin_by_id($uid);
$options = array();
// Register button
if (!api_is_anonymous($uid) &&
!$is_admin &&
if (!api_is_anonymous($uid) &&
!$is_admin &&
(
($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
$course['visibility'] == COURSE_VISIBILITY_REGISTERED && $course['subscribe'] == SUBSCRIBE_ALLOWED
) &&
) &&
$course['subscribe'] == SUBSCRIBE_ALLOWED &&
(!in_array($course['real_id'], $user_courses) || empty($user_courses))
) {
$options[]= 'register';
}
// Go To Course button (only if admin, if course public or if student already subscribed)
if ($is_admin ||
if ($is_admin ||
$course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD && empty($course['registration_code']) ||
(api_user_is_login($uid) && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && empty($course['registration_code']) ) ||
(in_array($course['real_id'], $user_courses) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
(api_user_is_login($uid) && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && empty($course['registration_code']) ) ||
(in_array($course['real_id'], $user_courses) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
) {
$options[]= 'enter';
}
return $options;
return $options;
}
} //end class CourseManager

@ -552,7 +552,7 @@ function _api_get_timezone() {
if ($use_users_timezone == 'true') {
// Get the timezone based on user preference, if it exists
$timezone_user = UserManager::get_extra_user_data_by_field($_user['user_id'],'timezone');
if ($timezone_user['timezone'] != null) {
if (isset($timezone_user['timezone']) && $timezone_user['timezone'] != null) {
$to_timezone = $timezone_user['timezone'];
}
}
@ -603,10 +603,11 @@ function api_get_utc_datetime($time = null, $return_null_if_invalid_date = false
*
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function api_get_local_time($time = null, $to_timezone = null, $from_timezone = null) {
function api_get_local_time($time = null, $to_timezone = null, $from_timezone = null, $return_null_if_invalid_date = false) {
if (!DATE_TIME_INSTALLED) {
// This occurs when PHP < 5.2
if (is_null($time)) {
if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
$time = time();
}
if (is_numeric($time)) {
@ -624,7 +625,10 @@ function api_get_local_time($time = null, $to_timezone = null, $from_timezone =
$to_timezone = _api_get_timezone();
}
// If time is a timestamp, convert it to a string
if (is_null($time)) {
if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
if ($return_null_if_invalid_date) {
return null;
}
$from_timezone = 'UTC';
$time = gmdate('Y-m-d H:i:s');
}

@ -91,13 +91,12 @@ class SortableTable extends HTML_Table {
* Array with names of the other tables defined on the same page of this
* table
*/
public $other_tables;
/**
* Activates the odd even rows
public $other_tables;
/**
* Activates the odd even rows
* **/
public $odd_even_rows_enabled = true;
/**
* Create a new SortableTable
* @param string $table_name A name for the table (default = 'table')
@ -112,8 +111,13 @@ class SortableTable extends HTML_Table {
* @param string $default_order_direction The default order direction;
* either the constant 'ASC' or 'DESC'
*/
public function __construct($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC') {
parent :: __construct (array ('class' => 'data_table'));
public function __construct($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC', $table_id = null) {
if (empty($table_id)) {
$table_id = $table_name.uniqid();
}
$this->table_id = $table_id;
parent :: __construct (array ('class' => 'data_table', 'id' => $table_id));
$this->table_name = $table_name;
$this->additional_parameters = array ();
$this->param_prefix = $table_name.'_';
@ -122,7 +126,7 @@ class SortableTable extends HTML_Table {
$this->page_nr = isset ($_GET[$this->param_prefix.'page_nr']) ? intval($_GET[$this->param_prefix.'page_nr']) : $this->page_nr;
$this->column = isset ($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column;
$this->column = isset ($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column;
//$this->direction = isset ($_SESSION[$this->param_prefix.'direction']) ? $_SESSION[$this->param_prefix.'direction'] : $default_order_direction;
@ -208,7 +212,7 @@ class SortableTable extends HTML_Table {
}
return $this->pager;
}
public function display() {
echo $this->return_table();
}
@ -219,7 +223,7 @@ class SortableTable extends HTML_Table {
public function return_table() {
$empty_table = false;
$content = $this->get_table_html();
if ($this->get_total_number_of_items() == 0) {
$cols = $this->getColCount();
$this->setCellAttributes(1, 0, 'style="font-style: italic;text-align:center;" colspan='.$cols);
@ -232,9 +236,9 @@ class SortableTable extends HTML_Table {
$table_id = 'form_'.$this->table_name.'_id';
$form = $this->get_page_select_form();
$nav = $this->get_navigation_html();
//Only show pagination info when there are items to paginate
//Only show pagination info when there are items to paginate
if ($this->get_total_number_of_items() > $this->default_items_per_page) {
$html = '<table class="data_table_pagination">';
$html .= '<tr>';
@ -250,51 +254,51 @@ class SortableTable extends HTML_Table {
$html .= '</tr>';
$html .= '</table>';
}
if (count($this->form_actions) > 0) {
if (count($this->form_actions) > 0) {
$params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
$html .= '<form id ="'.$table_id.'" class="form-search" method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">';
}
}
$html .= $content;
if (!$empty_table) {
if (!$empty_table) {
if (!empty($this->additional_parameters)) {
foreach($this->additional_parameters as $key => $value) {
$html .= '<input type="hidden" name ="'.Security::remove_XSS($key).'" value ="'.Security::remove_XSS($value).'" />';
$html .= '<input type="hidden" name ="'.Security::remove_XSS($key).'" value ="'.Security::remove_XSS($value).'" />';
}
}
$html .= '<input type="hidden" name="action">';
$html .= '<table style="width:100%;">';
$html .= '<tr>';
$html .= '<td>';
if (count($this->form_actions) > 0) {
$html .= '<div class="btn-toolbar">';
$html .= '<div class="btn-toolbar">';
$html .= '<div class="btn-group">';
$html .= '<a class="btn" href="?'.$params.'&amp;'.$this->param_prefix.'selectall=1" onclick="javascript: setCheckbox(true, \''.$table_id.'\'); return false;">'.get_lang('SelectAll').'</a>';
$html .= '<a class="btn" href="?'.$params.'" onclick="javascript: setCheckbox(false, \''.$table_id.'\'); return false;">'.get_lang('UnSelectAll').'</a> ';
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="btn-group">
<button class="btn" onclick="javascript:return false;">'.get_lang('Actions').'</button>
<button class="btn" onclick="javascript:return false;">'.get_lang('Actions').'</button>
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>';
$html .= '<ul class="dropdown-menu">';
foreach ($this->form_actions as $action => & $label) {
$html .= '<ul class="dropdown-menu">';
foreach ($this->form_actions as $action => & $label) {
$html .= '<li><a data-action ="'.$action.'" href="#" onclick="javascript:action_click(this, \''.$table_id.'\');">'.$label.'</a></li>';
}
$html .= '</ul>';
$html .= '</div>';//btn-group
$html .= '</ul>';
$html .= '</div>';//btn-group
$html .= '</div>'; //toolbar
} else {
$html .= $form;
}
$html .= '</td>';
if ($this->get_total_number_of_items() > $this->default_items_per_page) {
$html .= '<td style="text-align:right;">';
$html .= $nav;
@ -303,7 +307,7 @@ class SortableTable extends HTML_Table {
$html .= '<td> ';
$html .= '</td>';
}
$html .= '</tr>';
$html .= '</table>';
if (count($this->form_actions) > 0) {
@ -348,16 +352,16 @@ class SortableTable extends HTML_Table {
</style>';
// @todo This also must be moved
// Show only navigations if there are more than 1 page
$my_pager = $this->get_pager();
$html .= '<div class="main-grid">';
if ($my_pager->numPages() > 1) {
if ($my_pager->numPages() > 1) {
$html .= '<div class="sub-header">';
$html .= '<div class="grid_selectbox">'.$form.'</div>';
$html .= '<div class="grid_title">'.$this->get_table_title().'</div>';
$html .= '<div class="grid_title">'.$this->get_table_title().'</div>';
$html .= '<div class="grid_nav">'.$nav.'</div>';
$html .= '</div>';
}
@ -386,12 +390,12 @@ class SortableTable extends HTML_Table {
}
}
// Getting the items of the table
$items = $this->get_clean_html(false); //no sort
$items = $this->get_clean_html(false); //no sort
// Generation of style classes must be improved. Maybe we need a a table name to create style on the fly:
// i.e: .whoisonline_table_grid_container instead of .grid_container
// where whoisonline is the table's name like drupal's template engine
$html .= '<div class="grid_container">';
if (is_array($items) && count($items) > 0) {
foreach ($items as & $row) {
@ -402,13 +406,13 @@ class SortableTable extends HTML_Table {
$i++;
}
$html .= '</div>';
}
}
}
$html .= '</div>'; //close grid_container
$html .= '</div>'; //close main grid
$html .= '<div class="clear"></div>';
/*
if (!$empty_table) {
@ -460,7 +464,7 @@ class SortableTable extends HTML_Table {
$message_empty = api_xml_http_response_encode(get_lang('TheListIsEmpty'));
$this->setCellContents(1, 0, $message_empty);
$empty_table = true;
}
}
$html = '';
if (!$empty_table) {
// If we show the pagination
@ -505,10 +509,10 @@ class SortableTable extends HTML_Table {
}
if ($hide_navigation) {
$items = $this->table_data; // This is a faster way to get what we want
} else {
// The normal way
$items = $this->get_clean_html($sort_data); // Getting the items of the table
$items = $this->table_data; // This is a faster way to get what we want
} else {
// The normal way
$items = $this->get_clean_html($sort_data); // Getting the items of the table
}
// Generation of style classes must be improved. Maybe we need a a table name to create style on the fly:
@ -520,19 +524,19 @@ class SortableTable extends HTML_Table {
} else {
$filter = $visibility_options !== false;
}
$item_css_class = $item_css_style = $grid_css_class = $grid_css_style = '';
if (!empty($grid_class)) {
$grid_css_class = $grid_class['main']['class'];
$item_css_class = $grid_class['item']['class'];
$grid_css_style = isset($grid_class['main']['style']) ? $grid_class['main']['style'] : null;
$item_css_style = isset($grid_class['item']['style']) ? $grid_class['item']['style'] : null;
$item_css_style = isset($grid_class['item']['style']) ? $grid_class['item']['style'] : null;
}
$div = '';
$div = '';
if (is_array($items) && count($items) > 0) {
foreach ($items as & $row) {
foreach ($items as & $row) {
$i = 0;
$rows = '';
foreach ($row as & $element) {
@ -541,10 +545,10 @@ class SortableTable extends HTML_Table {
}
$i++;
}
$div .= Display::div($rows, array('class'=>$item_css_class.' '.$this->table_name.'_grid_item', 'style' => $item_css_style));
$div .= Display::div($rows, array('class'=>$item_css_class.' '.$this->table_name.'_grid_item', 'style' => $item_css_style));
}
}
}
$html .= Display::div($div, array('class'=>$grid_css_class.' '.$this->table_name.'_grid_container', 'style' => $grid_css_style));
$html .= '<div class="clear"></div>';
return $html;
@ -557,7 +561,7 @@ class SortableTable extends HTML_Table {
public function get_navigation_html () {
$pager = $this->get_pager();
$pager_links = $pager->getLinks();
$nav = $pager_links['first'].' '.$pager_links['back'];
$nav .= ' '.$pager->getCurrentPageId().' / '.$pager->numPages().' ';
$nav .= $pager_links['next'].' '.$pager_links['last'];
@ -568,16 +572,16 @@ class SortableTable extends HTML_Table {
* Get the HTML-code with the data-table.
*/
public function get_table_html() {
$pager = $this->get_pager();
$pager = $this->get_pager();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
$table_data = $this->get_table_data($from);
if (is_array($table_data)) {
$count = 1;
foreach ($table_data as & $row) {
$row = $this->filter_data($row);
$row = $this->filter_data($row);
$this->addRow($row);
if (isset($row['child_of'])) {
$this->setRowAttributes($count, array('class' => 'hidden hidden_'.$row['child_of']), true);
@ -585,11 +589,11 @@ class SortableTable extends HTML_Table {
$count++;
}
}
if ($this->odd_even_rows_enabled == true) {
$this->altRowAttributes(0, array ('class' => 'row_odd'), array ('class' => 'row_even'), true);
}
foreach ($this->th_attributes as $column => $attributes) {
$this->setCellAttributes(0, $column, $attributes);
}
@ -605,12 +609,12 @@ class SortableTable extends HTML_Table {
* @return array table row items
*/
public function get_clean_html($sort = true) {
$pager = $this->get_pager();
$pager = $this->get_pager();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
$table_data = $this->get_table_data($from, null, null, null, $sort);
$from = $offset[0] - 1;
$table_data = $this->get_table_data($from, null, null, null, $sort);
$new_table_data = array();
if (is_array($table_data)) {
foreach ($table_data as $index => & $row) {
@ -626,7 +630,7 @@ class SortableTable extends HTML_Table {
* should contain.
*/
public function get_page_select_form () {
$total_number_of_items = $this->get_total_number_of_items();
$total_number_of_items = $this->get_total_number_of_items();
if ($total_number_of_items <= $this->default_items_per_page) {
return '';
}
@ -634,11 +638,11 @@ class SortableTable extends HTML_Table {
$param[$this->param_prefix.'direction'] = $this->direction;
$param[$this->param_prefix.'page_nr'] = $this->page_nr;
$param[$this->param_prefix.'column'] = $this->column;
if (is_array($this->additional_parameters)) {
$param = array_merge($param, $this->additional_parameters);
}
foreach ($param as $key => & $value) {
$result[] = '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
}
@ -868,7 +872,7 @@ class SortableTable extends HTML_Table {
* or DESC)
*/
public function get_table_data ($from = null, $per_page = null, $column = null, $direction = null, $sort = null) {
if (!is_null($this->get_data_function)) {
if (!is_null($this->get_data_function)) {
return call_user_func($this->get_data_function, $from, $this->per_page, $this->column, $this->direction);
}
return array ();
@ -900,7 +904,7 @@ class SortableTableFromArray extends SortableTable {
* Get table data to show on current page
* @see SortableTable#get_table_data
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
if ($sort) {
$content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC);
} else {
@ -944,7 +948,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* The array containing all data for this table
*/
private $table_data;
private $doc_filter;
/**
@ -955,7 +959,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* @param int $tablename Name of the table
* @param array $column_show An array with binary values 1: we show the column 2: we don't show it
* @param array $column_order An array of integers that let us decide how the columns are going to be sort.
* @param bool special modification to fix the document name order
* @param bool special modification to fix the document name order
*/
public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename', $column_show = null, $column_order = null, $direction = 'ASC', $doc_filter = false) {
$this->column_show = $column_show;
@ -969,7 +973,7 @@ class SortableTableFromArrayConfig extends SortableTable {
* Get table data to show on current page
* @see SortableTable#get_table_data
*/
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) {
$content = TableSort :: sort_table_config($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC, $this->column_show, $this->column_order, SORT_REGULAR, $this->doc_filter);
return array_slice($content, $from, $this->per_page);
}

Loading…
Cancel
Save