function getpar($name, $description, $default = '') { $value = isset($_GET[$value = api_strtolower($name)]) ? $_GET[$value] : ''; $value = get_magic_quotes_gpc() ? stripslashes($value) : $value; if (!$value) $value = $default; if ($value == '') give_up('URL parameter ' . api_strtoupper($name) . ' - ' . $description . ' - is required'); define(api_strtoupper($name), $value); }
/** * Function to check if a filetype is allowed * @see HTML_QuickForm_Rule * * @param array $file Uploaded file * @param array $extensions Allowed extensions * * @return boolean True if filetype is allowed */ function validate($file, $extensions = array()) { $parts = explode('.', $file['name']); if (count($parts) < 2) { return false; } $ext = $parts[count($parts) - 1]; $extensions = array_map('strtolower', $extensions); return in_array(api_strtolower($ext), $extensions); }
function sort_users($a, $b) { $a = trim(api_strtolower($a[$_SESSION['tracking_column']])); $b = trim(api_strtolower($b[$_SESSION['tracking_column']])); if ($_SESSION['tracking_direction'] == 'DESC') { return strcmp($b, $a); } else { return strcmp($a, $b); } }
/** * Find evaluations by name * @param string $name_mask search string * @return array evaluation objects matching the search criterium * @todo can be written more efficiently using a new (but very complex) sql query */ public function find_evaluations($name_mask, $selectcat) { $rootcat = Category::load($selectcat); $evals = $rootcat[0]->get_evaluations(api_is_allowed_to_create_course() ? null : api_get_user_id(), true); $foundevals = array(); foreach ($evals as $eval) { if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { $foundevals[] = $eval; } } return $foundevals; }
/** * A reverse case-insensitive string comparison callback function for sorting. * @param string $string1 The first string. * @param string $string2 The second string. * @return int Returns 0 if $string1 = $string2 or if there is an error; 1 if $string1 < $string2; -1 if $string1 > $string2. */ function _api_casercmp($string1, $string2) { global $_api_collator, $_api_encoding; $result = collator_compare($_api_collator, api_strtolower(api_utf8_encode($string2, $_api_encoding), 'UTF-8'), api_strtolower(api_utf8_encode($string1, $_api_encoding), 'UTF-8')); return $result === false ? 0 : $result; }
$my_question_id_survey = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null; $my_survey_id_survey = Security::remove_XSS($_GET['survey_id']); $message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null; if (isset($_GET['action'])) { if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) { survey_manager::move_survey_question($my_action_survey, $my_question_id_survey, $my_survey_id_survey); Display::display_confirmation_message(get_lang('SurveyQuestionMoved')); } if ($_GET['action'] == 'delete' and is_numeric($_GET['question_id'])) { survey_manager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']); } } if (isset($_GET['message'])) { // We have created the survey or updated the survey if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully', 'SurveyCreatedSuccesfully'))) { Display::display_confirmation_message(get_lang($message_information) . ', ' . PHP_EOL . api_strtolower(get_lang('YouCanNowAddQuestionToYourSurvey'))); } // We have added a question if (in_array($_GET['message'], array('QuestionAdded', 'QuestionUpdated'))) { Display::display_confirmation_message(get_lang($message_information)); } if (in_array($_GET['message'], array('YouNeedToCreateGroups'))) { Display::display_warning_message(get_lang($message_information), false); } } if (!empty($survey_data['survey_version'])) { echo '<b>' . get_lang('Version') . ': ' . $survey_data['survey_version'] . '</b>'; } // We exit here is the first or last question is a pagebreak (which causes errors) SurveyUtil::check_first_last_question($_GET['survey_id']); // Action links
/** * Returns true if user exists in the platform when asking the password * * @param string $username (email or username) * @return array|boolean */ public static function get_user_accounts_by_username($username) { if (strpos($username, '@')) { $username = api_strtolower($username); $email = true; } else { $username = api_strtolower($username); $email = false; } if ($email) { $condition = "LOWER(email) = '" . Database::escape_string($username) . "' "; } else { $condition = "LOWER(username) = '" . Database::escape_string($username) . "'"; } $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $query = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email,\n status AS status, official_code, phone, picture_uri, creator_id\n\t\t\t\t FROM {$tbl_user}\n\t\t\t\t WHERE ( {$condition} AND active = 1) "; $result = Database::query($query); $num_rows = Database::num_rows($result); if ($result && $num_rows > 0) { return Database::fetch_assoc($result); } return false; }
/** * Checks if a value exists in an array, a case insensitive version of in_array() function with extended multibyte support. * @param mixed $needle The searched value. If needle is a string, the comparison is done in a case-insensitive manner. * @param array $haystack The array. * @param bool $strict (optional) If is set to TRUE then the function will also check the types of the $needle in the $haystack. The default value if FALSE. * @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default. * @return bool Returns TRUE if $needle is found in the array, FALSE otherwise. * @link http://php.net/manual/en/function.in-array.php */ function api_in_array_nocase($needle, $haystack, $strict = false, $encoding = null) { if (is_array($needle)) { foreach ($needle as $item) { if (api_in_array_nocase($item, $haystack, $strict, $encoding)) { return true; } } return false; } if (!is_string($needle)) { return in_array($needle, $haystack, $strict); } $needle = api_strtolower($needle, $encoding); if (!is_array($haystack)) { return false; } foreach ($haystack as $item) { if ($strict && !is_string($item)) { continue; } if (api_strtolower($item, $encoding) == $needle) { return true; } } return false; }
/** * Performs string comparison, case insensitive, language sensitive, with extended multibyte support. * @param string $string1 The first string. * @param string $string2 The second string. * @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then. * @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default. * @return int Returns < 0 if $string1 is less than $string2; > 0 if $string1 is greater than $string2; and 0 if the strings are equal. * This function is aimed at replacing the function strcasecmp() for human-language strings. * @link http://php.net/manual/en/function.strcasecmp */ function api_strcasecmp($string1, $string2, $language = null, $encoding = null) { return api_strcmp(api_strtolower($string1, $encoding), api_strtolower($string2, $encoding), $language, $encoding); }
if (!isset($src)) { $src = null; switch ($lp_type) { case 1: $_SESSION['oLP']->stop_previous_item(); $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); if ($prereq_check === true) { $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list); // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP. $file_info = parse_url($src); $file_info = pathinfo($file_info['path']); if (isset($file_info['extension']) && api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf') ) { $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq(); } $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset } else { $src = 'blank.php?error=prerequisites'; } break; case 2: // save old if asset $_SESSION['oLP']->stop_previous_item(); // save status manually if asset $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); if ($prereq_check === true) { $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
/* Display GUI */ if (empty($first_letter_user)) { $sql = "SELECT count(*) as nb_users FROM {$tbl_user}"; $result = Database::query($sql); $num_row = Database::fetch_array($result); if ($num_row['nb_users'] > 1000) { //if there are too much users to gracefully handle with the HTML select list, // assign a default filter on users names $first_letter_user = '******'; } unset($result); } $first_letter_user = Database::escape_string($first_letter_user); $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname'; $target_name = 'lastname'; $sql = "SELECT user_id,lastname,firstname,username FROM {$tbl_user}\n\t WHERE " . $target_name . " LIKE '" . $first_letter_user . "%' OR " . $target_name . " LIKE '" . api_strtolower($first_letter_user) . "%'\n\t\tORDER BY " . (count($users) > 0 ? "(user_id IN(" . implode(',', $users) . ")) DESC," : "") . " " . $target_name; $result = Database::query($sql); $db_users = Database::store_result($result); unset($result); $sql = "SELECT id, url FROM {$tbl_access_url} WHERE active=1 ORDER BY url"; $result = Database::query($sql); $db_urls = Database::store_result($result); unset($result); ?> <form name="formulaire" method="post" action="<?php echo api_get_self(); ?> " style="margin:0px;"> <input type="hidden" name="form_sent" value="1"/> <table border="0" cellpadding="5" cellspacing="0" width="100%">
/** * Searches a platform setting in all categories except from the Plugins category * @param string $search * @return array */ function search_setting($search) { if (empty($search)) { return array(); } $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $sql = "SELECT * FROM {$table_settings_current}\n WHERE category <> 'Plugins' GROUP BY variable ORDER BY id ASC "; $result = Database::store_result(Database::query($sql), 'ASSOC'); $settings = array(); $search = api_strtolower($search); if (!empty($result)) { foreach ($result as $setting) { $found = false; $title = api_strtolower(get_lang($setting['title'])); // try the title if (strpos($title, $search) === false) { $comment = api_strtolower(get_lang($setting['comment'])); //Try the comment if (strpos($comment, $search) === false) { //Try the variable name if (strpos($setting['variable'], $search) === false) { continue; } else { $found = true; } } else { $found = true; } } else { $found = true; } if ($found) { $settings[] = $setting; } } } return $settings; }
/** * Display the list of student publications, taking into account the user status * @deprecated * @param $id * @param $my_folder_data * @param $work_parents * @param $origin * @param array $userList */ function display_student_publications_list( $id, $my_folder_data, $work_parents, $origin, $userList = array() ) { global $gradebook; // Database table names $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); $course_info = api_get_course_info(api_get_course_id()); $sort_params = array(); if (isset($_GET['column'])) { $sort_params[] = 'column='.Security::remove_XSS($_GET['column']); } if (isset($_GET['page_nr'])) { $sort_params[] = 'page_nr='.Security::remove_XSS($_GET['page_nr']); } if (isset($_GET['per_page'])) { $sort_params[] = 'per_page='.Security::remove_XSS($_GET['per_page']); } if (isset($_GET['direction'])) { $sort_params[] = 'direction='.Security::remove_XSS($_GET['direction']); } $sort_params = implode('&', $sort_params); $my_params = $sort_params; $origin = Security::remove_XSS($origin); $qualification_exists = false; if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) { $qualification_exists = true; } $table_header = array(); $table_has_actions_column = false; $table_header[] = array(get_lang('Type'), false, 'style="width:40px"'); $table_header[] = array(get_lang('Title'), true); if (!empty($id)) { $table_header[] = array(get_lang('FirstName'), true); $table_header[] = array(get_lang('LastName'), true); } $table_header[] = array(get_lang('HandOutDateLimit'), true, 'style="width:200px"'); if ($is_allowed_to_edit) { $table_header[] = array(get_lang('HandedOut'), false); $table_header[] = array(get_lang('Actions'), false, 'style="width:90px"', array('class'=>'td_actions')); $table_has_actions_column = true; if ($qualification_exists) { $table_header[] = array(get_lang('Qualification'), true); } } else { // All users if ($course_info['show_score'] == 0) { $table_header[] = array(get_lang('Others'), false); } } $table_data = array(); // List of all folders if no id was provided $group_id = api_get_group_id(); if (is_array($work_parents)) { foreach ($work_parents as $work_parent) { $sql_select_directory = "SELECT title, url, prop.insert_date, prop.lastedit_date, work.id, author, has_properties, view_properties, description, qualification, weight, allow_text_assignment FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id AND prop.c_id = $course_id) WHERE active IN (0, 1) AND "; if (!empty($group_id)) { // set to select only messages posted by the user's group $sql_select_directory .= " work.post_group_id = '".$group_id."' "; } else { $sql_select_directory .= " work.post_group_id = '0' "; } $sql_select_directory .= " AND work.c_id = $course_id AND work.id = ".$work_parent->id." AND work.filetype = 'folder' AND prop.tool='work' $condition_session"; $result = Database::query($sql_select_directory); $row = Database::fetch_array($result, 'ASSOC'); if (!$row) { // the folder belongs to another session continue; } // form edit directory $homework = array(); if (!empty($row['has_properties'])) { $sql = Database::query('SELECT * FROM '.$work_assigment.' WHERE c_id = '.$course_id.' AND id = "'.$row['has_properties'].'" LIMIT 1'); $homework = Database::fetch_array($sql); } // save original value for later $utc_expiry_time = isset($homework['expires_on']) ? $homework['expires_on'] : null; $work_data = get_work_data_by_id($work_parent->id); $workId = $row['id']; $action = ''; $row = array(); $class = ''; $course_id = api_get_course_int_id(); if (api_is_allowed_to_edit()) { $cant_files = get_count_work($work_data['id']); } else { $isSubscribed = userIsSubscribedToWork(api_get_user_id(), $work_data['id'], $course_id); if ($isSubscribed == false) { continue; } $cant_files = get_count_work($work_data['id'], api_get_user_id()); } $text_file = get_lang('FilesUpload'); if ($cant_files == 1) { $text_file = api_strtolower(get_lang('FileUpload')); } $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), ICON_SIZE_SMALL); $row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.$icon.'</a>'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3, $workId, api_get_session_id()); $link_id = $link_info['id']; $count = 0; if ($link_info !== false) { $gradebook_data = get_resource_from_course_gradebook($link_id); $count = $gradebook_data['weight']; } if ($count > 0) { $add_to_name = Display::label(get_lang('IncludedInEvaluation'), 'info'); } else { $add_to_name = ''; } $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']); // Work name if ($cant_files > 0 ) { $zip = '<a href="downloadfolder.inc.php?id='.$work_data['id'].'&'.api_get_cidreq().'">'. Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL).'</a>'; } $link = 'work_list.php'; if (api_is_allowed_to_edit()) { $link = 'work_list_all.php'; } $url = $zip.'<a href="'.api_get_path(WEB_CODE_PATH).'work/'.$link.'?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'&id='.$work_data['id'].'"'.$class.'>'. $work_title.'</a> '.$add_to_name.'<br />'.$cant_files.' '.$text_file; $row[] = $url; if (!empty($homework)) { // use original utc value saved previously to avoid doubling the utc-to-local conversion ($homework['expires_on'] might have been tainted) $row[] = !empty($utc_expiry_time) && $utc_expiry_time != '0000-00-00 00:00:00' ? api_get_local_time($utc_expiry_time): '-'; } else { $row[] = '-'; } if (!$is_allowed_to_edit) { if ($course_info['show_score'] == 0) { $url = api_get_path(WEB_CODE_PATH).'work/work_list_others.php?'.api_get_cidreq().'&id='.$work_parent->id; $row[] = Display::url(Display::return_icon('group.png', get_lang('Others')), $url); } } if ($origin != 'learnpath') { if ($is_allowed_to_edit) { $cant_files_per_user = getUniqueStudentAttempts( $work_data['id'], $group_id, $course_id, api_get_session_id(), null, $userList ); $row[] = $cant_files_per_user.'/'.count($userList); if (api_resource_is_locked_by_gradebook($workId, LINK_STUDENTPUBLICATION)) { $action .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); $action .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); } else { $action .= '<a href="'.api_get_path(WEB_CODE_PATH).'work/edit_work.php?cidReq='.api_get_course_id().'&origin='.$origin.'&gradebook='.$gradebook.'&id='.$workId.'">'. Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>'; $action .= ' <a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'&delete_dir='.$workId.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('DirDelete').'" >'. Display::return_icon('delete.png',get_lang('DirDelete'),'',ICON_SIZE_SMALL).'</a>'; } $row[] = $action; } else { $row[] = ''; } } $row[] = $work_data['title']; $table_data[] = $row; } } $sorting_options = array(); $sorting_options['column'] = 1; // Here we change the way how the columns are going to be sorted // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" $column_order = array(); $i=0; foreach ($table_header as $item) { $column_order[$i] = $i; $i++; } if (empty($my_folder_data)) { $column_order[1] = 5; } else { $column_order[2] = 2; } // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide $column_show = array(); $column_show[] = 1; // type 0 $column_show[] = 1; // title 1 if (!empty($my_folder_data)) { $column_show[] = 1; // 2 $column_show[] = 1; // 3 if ($qualification_exists) { $column_show[] = 1; // 4 } } $column_show[] = 1; //date if ($table_has_actions_column) { $column_show[] = 1; // modify } $column_show[] = 1; //real date in correct format $column_show[] = 0; //real date in correct format $paging_options = array(); if (isset($_GET['curdirpath'])) { $my_params = array ('curdirpath' => Security::remove_XSS($_GET['curdirpath'])); } $my_params = array ('id' => isset($_GET['id']) ? $_GET['id'] : null); if (isset($_GET['edit_dir'])) { $my_params = array ('edit_dir' => intval($_GET['edit_dir'])); } $my_params['origin'] = $origin; Display::display_sortable_config_table( 'work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order ); }
} if ($index_information == 'english_name') { $msg .= Display::return_message(get_lang('AlreadyExists') . ' "' . get_lang('EnglishName') . '" ' . '(' . $english_name . ')', 'error'); } if ($index_information == 'isocode') { $msg .= Display::return_message(get_lang('CodeDoesNotExists') . ': ' . $isocode . '', 'error'); } if ($index_information == 'execute_add' && $value_information === true) { $allow_insert_info = true; } } if (strlen($original_name) > 0 && strlen($english_name) > 0 && strlen($isocode) > 0) { if ($allow_insert_info === true && $language_id_exist === true) { $english_name = str_replace(' ', '_', $english_name); //Fixes BT#1636 $english_name = api_strtolower($english_name); $isocode = str_replace(' ', '_', $isocode); $str_info = '<br/>' . get_lang('OriginalName') . ' : ' . $original_name . '<br/>' . get_lang('EnglishName') . ' : ' . $english_name . '<br/>' . get_lang('PlatformCharsetTitle') . ' : ' . $isocode; $mkdir_result = SubLanguageManager::add_language_directory($english_name); if ($mkdir_result) { $sl_id = add_sub_language($original_name, $english_name, $isocode, $sublanguage_available, $parent_id); if ($sl_id === false) { SubLanguageManager::remove_language_directory($english_name); $msg .= Display::return_message(get_lang('LanguageDirectoryNotWriteableContactAdmin'), 'error'); } else { // Here we build the confirmation message and we send the user to the sub language terms definition page, using a little hack - see #3712 $_SESSION['msg'] = Display::return_message(get_lang('TheNewSubLanguageHasBeenAdded') . $str_info . $link, 'confirm', false); unset($interbreadcrumb); $_GET['sub_language_id'] = $_REQUEST['sub_language_id'] = $sl_id; require 'sub_language.php'; exit;
function WSCreateUserPasswordCrypted($params) { global $_user, $debug; $debug = 1; if ($debug) { error_log('WSCreateUserPasswordCrypted'); } if ($debug) { error_log(print_r($params, 1)); } if (!WSHelperVerifyKey($params)) { return returnError(WS_ERROR_SECRET_KEY); } $passwordEncryption = api_get_configuration_value('password_encryption'); // Database table definition. $table_user = Database::get_main_table(TABLE_MAIN_USER); $orig_user_id_value = array(); $password = $params['password']; $encrypt_method = $params['encrypt_method']; $firstName = $params['firstname']; $lastName = $params['lastname']; $status = $params['status']; $email = $params['email']; $loginName = $params['loginname']; $official_code = isset($params['official_code']) ? $params['official_code'] : ''; $language = ''; $phone = isset($params['phone']) ? $params['phone'] : ''; $picture_uri = ''; $auth_source = PLATFORM_AUTH_SOURCE; $expiration_date = ''; $active = 1; $hr_dept_id = 0; $extra = null; $original_user_id_name = $params['original_user_id_name']; $original_user_id_value = $params['original_user_id_value']; $orig_user_id_value[] = $params['original_user_id_value']; $extra_list = isset($params['extra']) ? $params['extra'] : ''; if (!empty($passwordEncryption)) { if ($passwordEncryption === $encrypt_method) { if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { $msg = "Encryption {$encrypt_method} is invalid"; if ($debug) { error_log($msg); } return $msg; } else { if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { $msg = "Encryption {$encrypt_method} is invalid"; if ($debug) { error_log($msg); } return $msg; } } } else { $msg = "This encryption {$encrypt_method} is not configured"; if ($debug) { error_log($msg); } return $msg; } } else { $msg = 'The chamilo setting $_configuration["password_encryption"] is not configured'; if ($debug) { error_log($msg); } return $msg; } if (!empty($params['language'])) { $language = $params['language']; } if (!empty($params['phone'])) { $phone = $params['phone']; } if (!empty($params['expiration_date'])) { $expiration_date = $params['expiration_date']; } // Check whether x_user_id exists into user_field_values table. $user_id = UserManager::get_user_id_from_original_id($original_user_id_value, $original_user_id_name); if ($debug) { error_log('Ready to create user'); } if ($user_id > 0) { if ($debug) { error_log('User found with id: ' . $user_id); } // Check whether user is not active //@todo why this condition exists?? $sql = "SELECT user_id FROM {$table_user}\n WHERE user_id ='" . $user_id . "' AND active= '0' "; $resu = Database::query($sql); $r_check_user = Database::fetch_row($resu); $count_check_user = Database::num_rows($resu); if ($count_check_user > 0) { if ($debug) { error_log('User id: ' . $user_id . ' exists and is NOT active. Updating user and setting setting active = 1'); } $sql = "UPDATE {$table_user} SET\n lastname='" . Database::escape_string($lastName) . "',\n firstname='" . Database::escape_string($firstName) . "',\n username='******',"; if (!is_null($auth_source)) { $sql .= " auth_source='" . Database::escape_string($auth_source) . "',"; } $sql .= "\n password='******',\n email='" . Database::escape_string($email) . "',\n status='" . Database::escape_string($status) . "',\n official_code='" . Database::escape_string($official_code) . "',\n phone='" . Database::escape_string($phone) . "',\n expiration_date='" . Database::escape_string($expiration_date) . "',\n active='1',\n hr_dept_id=" . intval($hr_dept_id); $sql .= " WHERE user_id='" . $r_check_user[0] . "'"; if ($debug) { error_log($sql); } Database::query($sql); if (is_array($extra_list) && count($extra_list) > 0) { foreach ($extra_list as $extra) { $extra_field_name = $extra['field_name']; $extra_field_value = $extra['field_value']; // Save the external system's id into user_field_value table. UserManager::update_extra_field_value($r_check_user[0], $extra_field_name, $extra_field_value); } } return $r_check_user[0]; } else { if ($debug) { error_log('User exists but is active. Cant be updated'); } return 0; } } else { if ($debug) { error_log("User not found with original_id = {$original_user_id_value} and original_name = {$original_user_id_name}"); } } // Default language. if (empty($language)) { $language = api_get_setting('language.platform_language'); } if (!empty($_user['user_id'])) { $creator_id = $_user['user_id']; } else { $creator_id = ''; } // First check wether the login already exists if (!UserManager::is_username_available($loginName)) { if ($debug) { error_log("Username {$loginName} is not available"); } return 0; } $sql = "INSERT INTO {$table_user} SET\n lastname = '" . Database::escape_string(trim($lastName)) . "',\n firstname = '" . Database::escape_string(trim($firstName)) . "',\n username = '******',\n username_canonical = '" . Database::escape_string(api_strtolower(trim($loginName))) . "',\n status = '" . Database::escape_string($status) . "',\n password = '******',\n email = '" . Database::escape_string($email) . "',\n official_code = '" . Database::escape_string($official_code) . "',\n picture_uri = '" . Database::escape_string($picture_uri) . "',\n creator_id = '" . Database::escape_string($creator_id) . "',\n auth_source = '" . Database::escape_string($auth_source) . "',\n phone = '" . Database::escape_string($phone) . "',\n language = '" . Database::escape_string($language) . "',\n registration_date = '" . api_get_utc_datetime() . "',\n expiration_date = '" . Database::escape_string($expiration_date) . "',\n hr_dept_id = '" . Database::escape_string($hr_dept_id) . "',\n active = '" . Database::escape_string($active) . "'"; if ($debug) { error_log($sql); } Database::query($sql); $return = Database::insert_id(); if ($return) { $sql = "UPDATE {$table_user} SET user_id = id WHERE id = {$return}"; Database::query($sql); $url_id = api_get_current_access_url_id(); UrlManager::add_user_to_url($return, $url_id); if ($debug) { error_log("Adding user_id = {$return} to URL id {$url_id} "); } // Create extra field for the original_user_id_name UserManager::create_extra_field($original_user_id_name, 1, $original_user_id_name, ''); // Save the remote system's id into user_field_value table. UserManager::update_extra_field_value($return, $original_user_id_name, $original_user_id_value); // Create extra fields if (is_array($extra_list) && count($extra_list) > 0) { foreach ($extra_list as $extra) { $extra_field_name = $extra['field_name']; $extra_field_value = $extra['field_value']; // save new fieldlabel into user_field table UserManager::create_extra_field($extra_field_name, 1, $extra_field_name, ''); // save the external system's id into user_field_value table' UserManager::update_extra_field_value($return, $extra_field_name, $extra_field_value); } } } else { if ($debug) { error_log('Error while inserting a user'); } return 0; } return $return; }
/** * Find links by name * To keep consistency, do not call this method but LinkFactory::find_links instead. * @todo can be written more efficiently using a new (but very complex) sql query */ public function find_links($name_mask, $selectcat) { $rootcat = Category::load($selectcat); $links = $rootcat[0]->get_links(api_is_allowed_to_edit() ? null : api_get_user_id(), true); $foundlinks = array(); foreach ($links as $link) { if (!(api_strpos(api_strtolower($link->get_name()), api_strtolower($name_mask)) === false)) { $foundlinks[] = $link; } } return $foundlinks; }
?> </td> </tr> <tr> <td> </td> </tr> </table> </td> <td valign="top"> <?php if ($resource_added) { Display::display_normal_message(get_lang("ResourceAdded")); } if ($from_learnpath != 'yes') { echo count($addedresource) . " " . api_strtolower(get_lang('ResourcesAdded')) . "<br/>"; } //echo "<hr>"; // Agenda items --> if ($content == "Agenda") { $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $sql = "SELECT agenda.*, toolitemproperties.*\n\t\t\t\t\tFROM " . $TABLEAGENDA . " agenda, " . $TABLE_ITEM_PROPERTY . " toolitemproperties\n\t\t\t\t\tWHERE agenda.id = toolitemproperties.ref\n\t\t\t\t\tAND toolitemproperties.tool='" . TOOL_CALENDAR_EVENT . "'\n\t\t\t\t\tAND toolitemproperties.to_group_id='0'\n\t\t\t\t\tAND toolitemproperties.visibility='1'"; $result = Database::query($sql); while ($myrow = Database::fetch_array($result)) { echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">"; echo "<img src='../img/agenda.gif' alt='agenda'>"; echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get()) . "<br />"; echo "<b>" . $myrow["title"] . "</b></td></tr><tr><td>"; echo $myrow["content"] . "<br />"; showorhide_addresourcelink($content, $myrow["id"]);
/** * @param $item1 * @param $item2 * @return int */ function sort_by_category($item1, $item2) { $cat1 = $this->get_category_cached($item1->get_category_id()); $cat2 = $this->get_category_cached($item2->get_category_id()); $name1 = api_strtolower($this->get_category_name_to_display($cat1)); $name2 = api_strtolower($this->get_category_name_to_display($cat2)); return api_strnatcmp($name1, $name2); }
/** * Static function that parses CSV files into simple arrays, based on a function * by spam at cyber-space dot nl published on php.net (fgetcsv()). * @param string Filepath * @param string CSV delimiter * @param string CSV enclosure * @param boolean Might one field name happen more than once on the same line? (then split by comma in the values) * @return array Simple structured array */ function parse_csv_file($f, $delim = ',', $enclosure = '"', $multiples = false) { $data = @file_get_contents($f); $data = api_convert_encoding($data, api_get_system_encoding(), $this->config_encoding); $enclosed = false; $fldcount = 0; $linecount = 0; $fldval = ''; for ($i = 0; $i < strlen($data); $i++) { $chr = $data{$i}; switch ($chr) { case $enclosure: if ($enclosed && $data{$i+1} == $enclosure) { $fldval .= $chr; ++$i; // Skip the next character. } else $enclosed = !$enclosed; break; case $delim: if (!$enclosed) { $ret_array[$linecount][$fldcount++] = $fldval; $fldval = ''; } else $fldval .= $chr; break; case "\r": if (!$enclosed&&$data{$i+1} == "\n") continue; case "\n": if (!$enclosed) { $ret_array[$linecount++][$fldcount] = $fldval; $fldcount = 0; $fldval = ''; } else $fldval .= $chr; break; case "\\r": if (!$enclosed&&$data{$i+1} == "\\n") continue; case "\\n": if (!$enclosed) { $ret_array[$linecount++][$fldcount] = $fldval; $fldcount = 0; $fldval = ''; } else $fldval .= $chr; break; default: $fldval .= $chr; } } if ($fldval) { $ret_array[$linecount][$fldcount] = $fldval; } // Transform the array to use the first line as titles. $titles = array(); $ret_ret_array = array(); foreach ($ret_array as $line_idx => $line) { if ($line_idx == 0) { $titles = $line; } else { $ret_ret_array[$line_idx] = array(); foreach ($line as $idx => $val) { if ($multiples && !empty($ret_ret_array[$line_idx][api_strtolower($titles[$idx])])) { $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] .= ','.$val; } else { $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] = $val; } } } } return $ret_ret_array; }
$url = $row['title']; } } else { $url = '<a ' . $alt_title . ' href="overview.php?' . api_get_cidreq() . $myorigin . $mylpid . $mylpitemid . '&exerciseId=' . $my_exercise_id . '">' . $cut_title . '</a>'; } //Link of the exercise $item = Display::tag('td', $url . ' ' . $session_img); //count number exercise questions $sqlquery = "SELECT count(*) FROM {$TBL_EXERCICE_QUESTION} WHERE c_id = {$course_id} AND exercice_id = " . $my_exercise_id; $sqlresult = Database::query($sqlquery); $rowi = Database::result($sqlresult, 0); if ($row['random'] > 0) { $row['random'] . ' ' . api_strtolower(get_lang($row['random'] > 1 ? 'Questions' : 'Question')); } else { //show results student $rowi . ' ' . api_strtolower(get_lang($rowi > 1 ? 'Questions' : 'Question')); } //This query might be improved later on by ordering by the new "tms" field rather than by exe_id //Don't remove this marker: note-query-exe-results $qry = "SELECT * FROM {$TBL_TRACK_EXERCICES}\n WHERE exe_exo_id = " . $my_exercise_id . " AND\n exe_user_id = " . api_get_user_id() . " AND\n c_id = '" . api_get_course_int_id() . "' AND\n status <> 'incomplete' AND\n orig_lp_id = 0 AND\n orig_lp_item_id = 0 AND\n session_id = '" . api_get_session_id() . "'\n ORDER BY exe_id DESC"; $qryres = Database::query($qry); $num = Database::num_rows($qryres); //Hide the results $my_result_disabled = $row['results_disabled']; //Time limits are on if ($time_limits) { // Examn is ready to be taken if ($is_actived_time) { //Show results if ($my_result_disabled == 0 || $my_result_disabled == 2) { //More than one attempt
/** * @param array $answer * @param string $user_answer * @return array */ public static function check_fill_in_blanks($answer, $user_answer) { // the question is encoded like this // [A] B [C] D [E] F::10,10,10@1 // number 1 before the "@" means that is a switchable fill in blank question // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 // means that is a normal fill blank question // first we explode the "::" $pre_array = explode('::', $answer); // is switchable fill blank or not $last = count($pre_array) - 1; $is_set_switchable = explode('@', $pre_array[$last]); $switchable_answer_set = false; if (isset($is_set_switchable[1]) && $is_set_switchable[1] == 1) { $switchable_answer_set = true; } $answer = ''; for ($k = 0; $k < $last; $k++) { $answer .= $pre_array[$k]; } // splits weightings that are joined with a comma $answerWeighting = explode(',', $is_set_switchable[0]); // we save the answer because it will be modified //$temp = $answer; $temp = $answer; $answer = ''; $j = 0; //initialise answer tags $user_tags = $correct_tags = $real_text = array(); // the loop will stop at the end of the text while (1) { // quits the loop if there are no more blanks (detect '[') if (($pos = api_strpos($temp, '[')) === false) { // adds the end of the text $answer = $temp; $real_text[] = $answer; break; //no more "blanks", quit the loop } // adds the piece of text that is before the blank //and ends with '[' into a general storage array $real_text[] = api_substr($temp, 0, $pos + 1); $answer .= api_substr($temp, 0, $pos + 1); //take the string remaining (after the last "[" we found) $temp = api_substr($temp, $pos + 1); // quit the loop if there are no more blanks, and update $pos to the position of next ']' if (($pos = api_strpos($temp, ']')) === false) { // adds the end of the text $answer .= $temp; break; } $str = $user_answer; preg_match_all('#\\[([^[]*)\\]#', $str, $arr); $str = str_replace('\\r\\n', '', $str); $choice = $arr[1]; $tmp = api_strrpos($choice[$j], ' / '); $choice[$j] = api_substr($choice[$j], 0, $tmp); $choice[$j] = trim($choice[$j]); //Needed to let characters ' and " to work as part of an answer $choice[$j] = stripslashes($choice[$j]); $user_tags[] = api_strtolower($choice[$j]); //put the contents of the [] answer tag into correct_tags[] $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos)); $j++; $temp = api_substr($temp, $pos + 1); } $answer = ''; $real_correct_tags = $correct_tags; $chosen_list = array(); $good_answer = array(); for ($i = 0; $i < count($real_correct_tags); $i++) { if (!$switchable_answer_set) { //needed to parse ' and " characters $user_tags[$i] = stripslashes($user_tags[$i]); if ($correct_tags[$i] == $user_tags[$i]) { $good_answer[$correct_tags[$i]] = 1; } elseif (!empty($user_tags[$i])) { $good_answer[$correct_tags[$i]] = 0; } else { $good_answer[$correct_tags[$i]] = 0; } } else { // switchable fill in the blanks if (in_array($user_tags[$i], $correct_tags)) { $correct_tags = array_diff($correct_tags, $chosen_list); $good_answer[$correct_tags[$i]] = 1; } elseif (!empty($user_tags[$i])) { $good_answer[$correct_tags[$i]] = 0; } else { $good_answer[$correct_tags[$i]] = 0; } } // adds the correct word, followed by ] to close the blank $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]'; if (isset($real_text[$i + 1])) { $answer .= $real_text[$i + 1]; } } return $good_answer; }
/** * display message box sent showing it into outbox * @return void */ public static function show_message_box_sent() { $table_message = Database::get_main_table(TABLE_MESSAGE); $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); $message_id = ''; if (is_numeric($_GET['id_send'])) { $query = "SELECT * FROM {$table_message}\n WHERE\n user_sender_id=" . api_get_user_id() . " AND\n id=" . intval($_GET['id_send']) . " AND\n msg_status = 4;"; $result = Database::query($query); $message_id = intval($_GET['id_send']); } $path = 'outbox.php'; // get file attachments by message id $files_attachments = self::get_links_message_attachment_files($message_id, 'outbox'); $row = Database::fetch_array($result); $user_con = self::users_connected_by_id(); $band = 0; $reply = ''; for ($i = 0; $i < count($user_con); $i++) { if ($row[1] == $user_con[$i]) { $band = 1; } } echo '<div class=actions>'; echo '<a onclick="close_and_open_outbox()" href="javascript:void(0)">' . Display::return_icon('folder_up.gif', api_xml_http_response_encode(get_lang('BackToOutbox'))) . api_xml_http_response_encode(get_lang('BackToOutbox')) . '</a>'; echo '<a onclick="delete_one_message_outbox(' . $row[0] . ')" href="javascript:void(0)" >' . Display::return_icon('delete.png', api_xml_http_response_encode(get_lang('DeleteMessage'))) . api_xml_http_response_encode(get_lang('DeleteMessage')) . '</a>'; echo '</div><br />'; echo ' <table class="message_view_table" > <TR> <TD width=10> </TD> <TD vAlign=top width="100%"> <TABLE> <TR> <TD width="100%"> <TR> <h1>' . str_replace("\\", "", api_xml_http_response_encode($row[5])) . '</h1></TR> </TD> <TR> <TD>' . api_xml_http_response_encode(get_lang('From') . ' <b>' . GetFullUserName($row[1]) . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . GetFullUserName($row[2])) . '</b> </TD> </TR> <TR> <TD >' . api_xml_http_response_encode(get_lang('Date') . ' ' . $row[4]) . '</TD> </TR> </TR> </TABLE> <br /> <TABLE height="209px" width="100%" bgColor=#ffffff> <TBODY> <TR> <TD vAlign=top>' . str_replace("\\", "", api_xml_http_response_encode($row[6])) . '</TD> </TR> </TBODY> </TABLE> <div id="message-attach">' . (!empty($files_attachments) ? implode('<br />', $files_attachments) : '') . '</div> <DIV class=HT style="PADDING-BOTTOM: 5px"> </DIV></TD> <TD width=10> </TD> </TR> </TABLE>'; }
} if (!isset($src)) { $src = null; switch ($lpType) { case 1: $learnPath->stop_previous_item(); $htmlHeadXtra[] = '<script src="scorm_api.php?' . api_get_cidreq() . '" type="text/javascript" language="javascript"></script>'; $preReqCheck = $learnPath->prerequisites_match($lp_item_id); if ($preReqCheck === true) { $src = $learnPath->get_link('http', $lp_item_id, $get_toc_list); // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP. $file_info = parse_url($src); if (isset($file_info['path'])) { $file_info = pathinfo($file_info['path']); } if (isset($file_info['extension']) && api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) { $src = api_get_path(WEB_CODE_PATH) . 'newscorm/lp_view_item.php?lp_item_id=' . $lp_item_id . '&' . api_get_cidreq(); } $src = $learnPath->fixBlockedLinks($src); $learnPath->start_current_item(); // starts time counter manually if asset } else { $src = 'blank.php?error=prerequisites'; } break; case 2: // save old if asset $learnPath->stop_previous_item(); // save status manually if asset $htmlHeadXtra[] = '<script src="scorm_api.php?' . api_get_cidreq() . '" type="text/javascript" language="javascript"></script>'; $preReqCheck = $learnPath->prerequisites_match($lp_item_id);
/** * Checks a password to see wether it is OK to use. * @param string $password * @return true if the password is acceptable, false otherwise * Notes about what a password "OK to use" is: * 1. The password should be at least 5 characters long. * 2. Only English letters (uppercase or lowercase, it doesn't matter) and digits are allowed. * 3. The password should contain at least 3 letters. * 4. It should contain at least 2 digits. * 5. It should not contain 3 or more consequent (according to ASCII table) characters. */ function api_check_password($password) { $password_length = api_strlen($password); if ($password_length < 5) { return false; } $password = api_strtolower($password); $letters = 0; $digits = 0; $consequent_characters = 0; $previous_character_code = 0; for ($i = 0; $i < $password_length; $i++) { $current_character_code = api_ord(api_substr($password, $i, 1)); if ($i && abs($current_character_code - $previous_character_code) <= 1) { $consequent_characters++; if ($consequent_characters == 3) { return false; } } else { $consequent_characters = 1; } if ($current_character_code >= 97 && $current_character_code <= 122) { $letters++; } elseif ($current_character_code >= 48 && $current_character_code <= 57) { $digits++; } else { return false; } $previous_character_code = $current_character_code; } return $letters >= 3 && $digits >= 2; }
/** * display message box in the inbox * @param int the message id * @param string inbox or outbox strings are available * @todo replace numbers with letters in the $row array pff... * @return string html with the message content */ public static function show_message_box($message_id, $source = 'inbox') { $table_message = Database::get_main_table(TABLE_MESSAGE); $message_id = intval($message_id); if ($source == 'outbox') { if (isset($message_id) && is_numeric($message_id)) { $query = "SELECT * FROM {$table_message}\n WHERE\n user_sender_id = " . api_get_user_id() . " AND\n id = " . $message_id . " AND\n msg_status = 4;"; $result = Database::query($query); } } else { if (is_numeric($message_id) && !empty($message_id)) { $query = "UPDATE {$table_message} SET\n msg_status = '" . MESSAGE_STATUS_NEW . "'\n WHERE\n user_receiver_id=" . api_get_user_id() . " AND\n id='" . $message_id . "'"; Database::query($query); $query = "SELECT * FROM {$table_message}\n WHERE\n msg_status<>4 AND\n user_receiver_id=" . api_get_user_id() . " AND\n id='" . $message_id . "'"; $result = Database::query($query); } } $row = Database::fetch_array($result, 'ASSOC'); $user_sender_id = $row['user_sender_id']; // get file attachments by message id $files_attachments = self::get_links_message_attachment_files($message_id, $source); $user_con = self::users_connected_by_id(); $band = 0; for ($i = 0; $i < count($user_con); $i++) { if ($user_sender_id == $user_con[$i]) { $band = 1; } } $title = Security::remove_XSS($row['title'], STUDENT, true); $content = Security::remove_XSS($row['content'], STUDENT, true); $from_user = api_get_user_info($user_sender_id); $name = $from_user['complete_name']; $user_image = Display::img($from_user['avatar'], $name, array('title' => $name)); $message_content = Display::page_subheader(str_replace("\\", "", $title)); if (api_get_setting('social.allow_social_tool') == 'true') { $message_content .= $user_image . ' '; } $receiverUserInfo = api_get_user_info($row['user_receiver_id']); $message_content .= '<tr>'; if (api_get_setting('social.allow_social_tool') == 'true') { if ($source == 'outbox') { $message_content .= get_lang('From') . ': <a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php?u=' . $user_sender_id . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . $receiverUserInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ' <a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php?u=' . $user_sender_id . '">' . $name . '</a> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } else { if ($source == 'outbox') { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . $receiverUserInfo['complete_name'] . '</b>'; } else { $message_content .= get_lang('From') . ': ' . $name . '</b> ' . api_strtolower(get_lang('To')) . ' <b>' . get_lang('Me') . '</b>'; } } $message_content .= ' ' . get_lang('Date') . ': ' . api_get_local_time($row['send_date']) . ' <br /> <hr style="color:#ddd" /> <table height="209px" width="100%"> <tr> <td valign=top class="view-message-content">' . str_replace("\\", "", $content) . '</td> </tr> </table> <div id="message-attach">' . (!empty($files_attachments) ? implode('<br />', $files_attachments) : '') . '</div> <div style="padding: 15px 0px 5px 0px">'; $social_link = ''; if (isset($_GET['f']) && $_GET['f'] == 'social') { $social_link = 'f=social'; } if ($source == 'outbox') { $message_content .= '<a href="outbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToOutbox')) . '</a>  '; } else { $message_content .= '<a href="inbox.php?' . $social_link . '">' . Display::return_icon('back.png', get_lang('ReturnToInbox')) . '</a>  '; $message_content .= '<a href="new_message.php?re_id=' . $message_id . '&' . $social_link . '">' . Display::return_icon('message_reply.png', get_lang('ReplyToMessage')) . '</a>  '; } $message_content .= '<a href="inbox.php?action=deleteone&id=' . $message_id . '&' . $social_link . '" >' . Display::return_icon('delete.png', get_lang('DeleteMessage')) . '</a> '; $message_content .= '</div></td> <td width=10></td> </tr> </table>'; return $message_content; }
/** * Sorts 2-dimensional table. It is possile changing the columns that will be shown and the way that the columns are to be sorted. * @param array $data The data to be sorted. * @param int $column The column on which the data should be sorted (default = 0) * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC) * @param array $column_show The columns that we will show in the table i.e: $column_show = array('1','0','1') we will show the 1st and the 3th column. * @param array $column_order Changes how the columns will be sorted ie. $column_order = array('0','3','2','3') The column [1] will be sorted like the column [3] * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_DATE, SORT_IMAGE) * @return array The sorted dataset * @author bart.mollet@hogent.be */ public static function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show = null, $column_order = null, $type = SORT_REGULAR, $doc_filter = false) { if (!is_array($data) || empty($data)) { return array(); } if ($column != strval(intval($column))) { // Probably an attack return $data; } if (!in_array($direction, array(SORT_ASC, SORT_DESC))) { // Probably an attack return $data; } // Change columns sort // Here we say that the real way of how the columns are going to be order is manage by the $column_order array if (is_array($column_order)) { $column = isset($column_order[$column]) ? $column_order[$column] : $column; } if ($type == SORT_REGULAR) { if (TableSort::is_image_column($data, $column)) { $type = SORT_IMAGE; } elseif (TableSort::is_date_column($data, $column)) { $type = SORT_DATE; } elseif (TableSort::is_numeric_column($data, $column)) { $type = SORT_NUMERIC; } else { $type = SORT_STRING; } } //This fixs only works in the document tool when ordering by name if ($doc_filter && in_array($type, array(SORT_STRING))) { $data_to_sort = $folder_to_sort = array(); $new_data = array(); if (!empty($data)) { foreach ($data as $document) { if ($document['type'] == 'folder') { $docs_to_sort[$document['id']] = api_strtolower($document['name']); } else { $folder_to_sort[$document['id']] = api_strtolower($document['name']); } $new_data[$document['id']] = $document; } if ($direction == SORT_ASC) { if (!empty($docs_to_sort)) { api_natrsort($docs_to_sort); } if (!empty($folder_to_sort)) { api_natrsort($folder_to_sort); } } else { if (!empty($docs_to_sort)) { api_natsort($docs_to_sort); } if (!empty($folder_to_sort)) { api_natsort($folder_to_sort); } } $new_data_order = array(); if (!empty($docs_to_sort)) { foreach ($docs_to_sort as $id => $document) { $new_data_order[] = $new_data[$id]; } } if (!empty($folder_to_sort)) { foreach ($folder_to_sort as $id => $document) { $new_data_order[] = $new_data[$id]; } } $data = $new_data_order; } } else { $compare_operator = $direction == SORT_ASC ? '>' : '<='; switch ($type) { case SORT_NUMERIC: $compare_function = 'return strip_tags($a[' . $column . ']) ' . $compare_operator . ' strip_tags($b[' . $column . ']);'; break; case SORT_IMAGE: $compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a[' . $column . '], "<img>")), api_strtolower(strip_tags($b[' . $column . '], "<img>"))) ' . $compare_operator . ' 0;'; break; case SORT_DATE: $compare_function = 'return strtotime(strip_tags($a[' . $column . '])) ' . $compare_operator . ' strtotime(strip_tags($b[' . $column . ']));'; break; case SORT_STRING: default: $compare_function = 'return api_strnatcmp(api_strtolower(strip_tags($a[' . $column . '])), api_strtolower(strip_tags($b[' . $column . ']))) ' . $compare_operator . ' 0;'; break; } // Sort the content usort($data, create_function('$a, $b', $compare_function)); } if (is_array($column_show)) { // We show only the columns data that were set up on the $column_show array $new_order_data = array(); $count_data = count($data); $count_column_show = count($column_show); for ($j = 0; $j < $count_data; $j++) { $k = 0; for ($i = 0; $i < $count_column_show; $i++) { if ($column_show[$i]) { $new_order_data[$j][$k] = $data[$j][$i]; } $k++; } } // Replace the multi-arrays $data = $new_order_data; } return $data; }
public function sort_users_desc($a, $b) { return strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']]))); }
function rsort_users($a, $b) { return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']]))); }
/** * @param string $firstLetter * @return array */ public function filterByFirstLetter($firstLetter) { $firstLetter = Database::escape_string($firstLetter); $sql = "SELECT id, name FROM {$this->table}\n\t\t WHERE\n\t\t name LIKE '" . $firstLetter . "%' OR\n\t\t name LIKE '" . api_strtolower($firstLetter) . "%'\n\t\t ORDER BY name DESC "; $result = Database::query($sql); return Database::store_result($result); }
if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') { $isChatFolder = true; } } if ($isChatFolder) { $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js'); $htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH) . 'chat.css'); $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH) . 'javascript/highlight/styles/github.css'); $htmlHeadXtra[] = ' <script> hljs.initHighlightingOnLoad(); </script>'; } $execute_iframe = true; if ($jplayer_supported) { $extension = api_strtolower($pathinfo['extension']); $js_path = api_get_path(WEB_LIBRARY_PATH) . 'javascript/'; $htmlHeadXtra[] = '<link rel="stylesheet" href="' . $js_path . 'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">'; $htmlHeadXtra[] = '<script type="text/javascript" src="' . $js_path . 'jquery-jplayer/jquery.jplayer.min.js"></script>'; $jquery = ' $("#jquery_jplayer_1").jPlayer({ ready: function() { $(this).jPlayer("setMedia", { ' . $extension . ' : "' . $document_data['direct_url'] . '" }); }, errorAlerts: false, warningAlerts: false, //swfPath: "../inc/lib/javascript/jquery-jplayer", swfPath: "' . $js_path . 'jquery-jplayer", //supplied: "m4a, oga, mp3, ogg, wav", supplied: "' . $extension . '",