Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

1.9.x
Alex 12 years ago
commit 75446eaee2
  1. 58
      main/announcements/announcements.inc.php
  2. 13
      main/announcements/announcements.php
  3. 43
      main/inc/lib/groupmanager.lib.php
  4. 653
      main/inc/lib/internationalization.lib.php
  5. 91
      main/inc/lib/internationalization_internal.lib.php
  6. 20
      main/inc/lib/main_api.lib.php
  7. 5
      main/inc/lib/table_sort.class.php
  8. 19
      main/newscorm/learnpath.class.php
  9. 10
      main/newscorm/lp_list.php

@ -306,7 +306,8 @@ class AnnouncementManager
$sentTo,
$file = array(),
$file_comment = null,
$end_date = null
$end_date = null,
$sendToUsersInSession = false
) {
$_course = api_get_course_info();
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
@ -366,6 +367,12 @@ class AnnouncementManager
}
}
}
if ($sendToUsersInSession) {
self::addAnnouncementToAllUsersInSessions($last_id);
}
return $last_id;
}
}
@ -379,7 +386,7 @@ class AnnouncementManager
* @param string $file_comment
* @return bool|int
*/
public static function add_group_announcement($emailTitle, $newContent, $to, $to_users, $file = array(), $file_comment = '')
public static function add_group_announcement($emailTitle, $newContent, $to, $to_users, $file = array(), $file_comment = '', $sendToUsersInSession = false)
{
$_course = api_get_course_info();
@ -432,6 +439,11 @@ class AnnouncementManager
}
}
}
if ($sendToUsersInSession) {
self::addAnnouncementToAllUsersInSessions($last_id);
}
return $last_id;
}
@ -446,7 +458,7 @@ class AnnouncementManager
* @param mixed attachment
* @param string file comment
*/
public static function edit_announcement($id, $emailTitle, $newContent, $to, $file = array(), $file_comment = '')
public static function edit_announcement($id, $emailTitle, $newContent, $to, $file = array(), $file_comment = '', $sendToUsersInSession = false)
{
global $_course;
@ -478,6 +490,10 @@ class AnnouncementManager
$sql_delete = "DELETE FROM $tbl_item_property WHERE c_id = $course_id AND ref='$id' AND tool='announcement'";
Database::query($sql_delete);
if ($sendToUsersInSession) {
self::addAnnouncementToAllUsersInSessions($id);
}
// store in item_property (first the groups, then the users
if (!is_null($to)) {
@ -503,6 +519,42 @@ class AnnouncementManager
}
}
/**
* @param int $announcementId
*/
public static function addAnnouncementToAllUsersInSessions($announcementId)
{
$courseCode = api_get_course_id();
$_course = api_get_course_info();
$sessionList = SessionManager::get_session_by_course(api_get_course_id());
if (!empty($sessionList)) {
foreach ($sessionList as $sessionInfo) {
$sessionId = $sessionInfo['id'];
$userList = CourseManager::get_user_list_from_course_code($courseCode, $sessionId);
if (!empty($userList)) {
foreach ($userList as $user) {
api_item_property_update(
$_course,
TOOL_ANNOUNCEMENT,
$announcementId,
"AnnouncementUpdated",
api_get_user_id(),
0,
$user['user_id'],
0,
0,
$sessionId
);
}
}
}
}
}
/**
* @param int $insert_id
* @return bool

@ -354,13 +354,14 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
$error_message = get_lang('TitleIsRequired');
$content_to_modify = $newContent;
} else if ($submitAnnouncement) {
$sendToUsersInSession = isset($_POST['send_to_users_in_session']) ? true : false;
if (isset($id) && $id) {
// there is an Id => the announcement already exists => update mode
if ($ctok == $_POST['sec_token']) {
$file_comment = $_POST['file_comment'];
$file = $_FILES['user_upload'];
AnnouncementManager::edit_announcement($id, $emailTitle, $newContent, $_POST['selectedform'], $file, $file_comment);
AnnouncementManager::edit_announcement($id, $emailTitle, $newContent, $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession);
/* MAIL FUNCTION */
if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) {
@ -374,9 +375,9 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
$file = $_FILES['user_upload'];
$file_comment = $_POST['file_comment'];
if (!empty($group_id)) {
$insert_id = AnnouncementManager::add_group_announcement($safe_emailTitle, $safe_newContent, array('GROUP:'.$group_id), $_POST['selectedform'], $file, $file_comment);
$insert_id = AnnouncementManager::add_group_announcement($safe_emailTitle, $safe_newContent, array('GROUP:'.$group_id), $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession);
} else {
$insert_id = AnnouncementManager::add_announcement($safe_emailTitle, $safe_newContent, $_POST['selectedform'], $file, $file_comment);
$insert_id = AnnouncementManager::add_announcement($safe_emailTitle, $safe_newContent, $_POST['selectedform'], $file, $file_comment, $sendToUsersInSession);
}
//store_resources($_SESSION['source_type'],$insert_id);
$_SESSION['select_groupusers']="hide";
@ -646,6 +647,10 @@ if ($display_form) {
echo ' </div>
</div>';
echo '<div class="control-group"><div class="controls">';
echo '<label class="checkbox" ><input name="send_to_users_in_session" type="checkbox" />'.get_lang('SendToUsersInSessions').'</label>';
echo '</div></div>';
if (!isset($announcement_to_modify) ) $announcement_to_modify ='';
($email_ann=='1')?$checked='checked':$checked='';
@ -711,7 +716,7 @@ if ($display_form) {
echo $oFCKeditor->CreateHtml();
echo '</div></div>';
//File attachment
//File attachment
echo ' <div class="control-group">
<div class="controls">
<a href="javascript://" onclick="return plus_attachment();"><span id="plus"><img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AddAnAttachment').'</span></a>

@ -93,12 +93,8 @@ class GroupManager
//condition for the session
$session_id = api_get_session_id();
$my_status_of_user_in_course = CourseManager::get_user_in_course_status($my_user_id, $course_info['code']);
// COURSEMANAGER or STUDENT
if ($my_status_of_user_in_course == COURSEMANAGER || api_is_allowed_to_edit(null, true) || api_is_drh()) {
$can_see_groups = 1;
$sql = "SELECT g.id,
$sql = "SELECT g.id,
g.name,
g.description,
g.category_id,
@ -110,26 +106,12 @@ class GroupManager
ug.user_id is_member
FROM $table_group g
LEFT JOIN $table_group_user ug
ON (ug.group_id = g.id AND ug.user_id = '".api_get_user_id()."' AND ug.c_id = $course_id AND g.c_id = $course_id)";
} elseif ($my_status_of_user_in_course == STUDENT || $_SESSION['studentview'] == 'studentview') {
$can_see_groups = 1;
$sql = "SELECT g.id,
g.name,
g.description,
g.category_id,
g.max_student maximum_number_of_members,
g.secret_directory,
g.self_registration_allowed,
g.self_unregistration_allowed,
g.session_id,
ug.user_id is_member
FROM $table_group g
LEFT JOIN $table_group_user ug
ON (ug.group_id = g.id AND ug.user_id = '".api_get_user_id()."' AND ug.c_id = $course_id AND g.c_id = $course_id)";
} else {
return array();
}
ON (
ug.group_id = g.id AND
ug.user_id = '".api_get_user_id()."' AND
ug.c_id = $course_id AND
g.c_id = $course_id
)";
$sql .= " WHERE 1=1 ";
@ -150,17 +132,12 @@ class GroupManager
}
$sql .= " GROUP BY g.id ORDER BY UPPER(g.name)";
if ($can_see_groups == 1) {
$groupList = Database::query($sql);
} else {
return array();
}
$groupList = Database::query($sql);
$groups = array();
while ($thisGroup = Database::fetch_array($groupList)) {
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id']));
if ($thisGroup['session_id']!=0) {
if ($thisGroup['session_id'] != 0) {
$sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).'
WHERE id='.$thisGroup['session_id'];
$rs_session = Database::query($sql);
@ -2116,7 +2093,6 @@ class GroupManager
self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_WIKI))
&& !(api_is_course_coach() && intval($this_group['session_id']) != $session_id)
) {
$group_name = '<a href="group_space.php?cidReq='.api_get_course_id().'&amp;origin='.$orig.'&amp;gidReq='.$this_group['id'].'">'.
Security::remove_XSS($this_group['name']).'</a> ';
if (!empty($user_id) && !empty($this_group['id_tutor']) && $user_id == $this_group['id_tutor']) {
@ -2201,7 +2177,6 @@ class GroupManager
$group_data[] = $row;
} // end loop
$table = new SortableTableFromArrayConfig($group_data, 1, 20, 'group_category_'.$category_id);
$table->set_additional_parameters(array('category' => $category_id));
$column = 0;

@ -11,7 +11,6 @@
* @package chamilo.library
*/
/**
* Constants
*/
@ -23,33 +22,40 @@ define('SPECIAL_CLOSING_TAG', '=]');
// Predefined date formats in Chamilo provided by the language sub-system.
// To be used as a parameter for the function api_format_date()
define('TIME_NO_SEC_FORMAT', 0); // 15:23
define('DATE_FORMAT_SHORT', 1); // Aug 25, 09
define('DATE_FORMAT_LONG', 2); // Monday August 25, 09
define('DATE_FORMAT_LONG_NO_DAY', 10); // August 25, 2009
define('DATE_TIME_FORMAT_LONG', 3); // Monday August 25, 2009 at 03:28 PM
define('TIME_NO_SEC_FORMAT', 0); // 15:23
define('DATE_FORMAT_SHORT', 1); // Aug 25, 09
define('DATE_FORMAT_LONG', 2); // Monday August 25, 09
define('DATE_FORMAT_LONG_NO_DAY', 10); // August 25, 2009
define('DATE_TIME_FORMAT_LONG', 3); // Monday August 25, 2009 at 03:28 PM
define('DATE_FORMAT_NUMBER', 4); // 25.08.09
define('DATE_FORMAT_NUMBER', 4); // 25.08.09
define('DATE_TIME_FORMAT_LONG_24H', 5); // August 25, 2009 at 15:28
define('DATE_TIME_FORMAT_SHORT', 6); // Aug 25, 2009 at 03:28 PM
define('DATE_TIME_FORMAT_SHORT_TIME_FIRST', 7); // 03:28 PM, Aug 25 2009
define('DATE_FORMAT_NUMBER_NO_YEAR', 8); // 25.08 dd-mm
define('DATE_FORMAT_ONLY_DAYNAME', 9); // Monday, Sunday, etc
define('DATE_TIME_FORMAT_SHORT', 6); // Aug 25, 2009 at 03:28 PM
define('DATE_TIME_FORMAT_SHORT_TIME_FIRST', 7); // 03:28 PM, Aug 25 2009
define('DATE_FORMAT_NUMBER_NO_YEAR', 8); // 25.08 dd-mm
define('DATE_FORMAT_ONLY_DAYNAME', 9); // Monday, Sunday, etc
// Formatting person's name.
define('PERSON_NAME_COMMON_CONVENTION', 0); // Formatting a person's name using the pattern as it has been
// configured in the internationalization database for every language.
// This (default) option would be the most used.
// The followind options may be used in limited number of places for overriding the common convention:
define('PERSON_NAME_WESTERN_ORDER', 1); // Formatting a person's name in Western order: first_name last_name
define('PERSON_NAME_EASTERN_ORDER', 2); // Formatting a person's name in Eastern order: last_name first_name
define('PERSON_NAME_LIBRARY_ORDER', 3); // Contextual: formatting person's name in library order: last_name, first_name
define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER); // Contextual: formatting a person's name assotiated with an email-address. Ivan: I am not sure how seems email servers an clients would interpret name order, so I assign the Western order.
define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); // Contextual: formatting a person's name for data-exporting operarions. For backward compatibility this format has been set to Eastern order.
// The following constants are used for tunning language detection functionality.
// Formatting a person's name using the pattern as it has been
// configured in the internationalization database for every language.
// This (default) option would be the most used.
define('PERSON_NAME_COMMON_CONVENTION', 0);
// The following options may be used in limited number of places for overriding the common convention:
// Formatting a person's name in Western order: first_name last_name
define('PERSON_NAME_WESTERN_ORDER', 1);
// Formatting a person's name in Eastern order: last_name first_name
define('PERSON_NAME_EASTERN_ORDER', 2);
// Contextual: formatting person's name in library order: last_name, first_name
define('PERSON_NAME_LIBRARY_ORDER', 3);
// Contextual: formatting a person's name assotiated with an email-address. Ivan: I am not sure how seems email servers an clients would interpret name order, so I assign the Western order.
define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER);
// Contextual: formatting a person's name for data-exporting operations. For backward compatibility this format has been set to Eastern order.
define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER);
// The following constants are used for tuning language detection functionality.
// We reduce the text for language detection to the given number of characters
// for increaseing speed and to decrease memory consumption.
// for increasing speed and to decrease memory consumption.
define ('LANGUAGE_DETECT_MAX_LENGTH', 2000);
// Maximum allowed difference in so called delta-points for aborting certain language detection.
// The value 80000 is good enough for speed and detection accuracy.
@ -58,15 +64,12 @@ define ('LANGUAGE_DETECT_MAX_LENGTH', 2000);
define ('LANGUAGE_DETECT_MAX_DELTA', 140000);
/**
* Initialization
*/
/**
* Initialization of some internal default valies in the internationalization library.
* Initialization of some internal default values in the internationalization library.
* @return void
* Note: This function should be called only once in the global initialization script.
*/
function api_initialize_internationalization() {
function api_initialize_internationalization()
{
if (MBSTRING_INSTALLED) {
@ini_set('mbstring.func_overload', 0);
@ini_set('mbstring.encoding_translation', 0);
@ -88,6 +91,7 @@ function api_set_internationalization_default_encoding($encoding) {
_api_mb_internal_encoding($encoding);
_api_mb_regex_encoding($encoding);
_api_iconv_set_encoding('iconv_internal_encoding', $encoding);
return $result;
}
@ -680,84 +684,84 @@ function api_format_date($time, $format = null, $language = null) {
switch ($format) {
case DATE_FORMAT_ONLY_DAYNAME:
$date_format = get_lang('dateFormatOnlyDayName', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::SHORT;
$timetype = IntlDateFormatter::NONE;
}
break;
case DATE_FORMAT_NUMBER_NO_YEAR:
$date_format = get_lang('dateFormatShortNumberNoYear', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::SHORT;
$timetype = IntlDateFormatter::NONE;
}
break;
case DATE_FORMAT_NUMBER:
$date_format = get_lang('dateFormatShortNumber', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::SHORT;
$timetype = IntlDateFormatter::NONE;
}
break;
case TIME_NO_SEC_FORMAT:
$date_format = get_lang('timeNoSecFormat', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::NONE;
$timetype = IntlDateFormatter::SHORT;
}
break;
case DATE_FORMAT_SHORT:
$date_format = get_lang('dateFormatShort', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::LONG;
$timetype = IntlDateFormatter::NONE;
}
break;
case DATE_FORMAT_LONG:
$date_format = get_lang('dateFormatLong', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::NONE;
}
break;
case DATE_TIME_FORMAT_LONG:
$date_format = get_lang('dateTimeFormatLong', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
break;
case DATE_FORMAT_LONG_NO_DAY:
$date_format = get_lang('dateFormatLongNoDay', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
break;
case DATE_TIME_FORMAT_SHORT:
$date_format = get_lang('dateTimeFormatShort', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
break;
case DATE_TIME_FORMAT_SHORT_TIME_FIRST:
$date_format = get_lang('dateTimeFormatShortTimeFirst', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
break;
case DATE_TIME_FORMAT_LONG_24H:
$date_format = get_lang('dateTimeFormatLong24H', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
break;
default:
$date_format = get_lang('dateTimeFormatLong', '', $language);
if (IS_PHP_53 && INTL_INSTALLED) {
if (INTL_INSTALLED) {
$datetype = IntlDateFormatter::FULL;
$timetype = IntlDateFormatter::SHORT;
}
@ -766,7 +770,6 @@ function api_format_date($time, $format = null, $language = null) {
$date_format = $format;
}
//if (IS_PHP_53 && INTL_INSTALLED && $datetype !== null && $timetype !== null) {
if (0) {
//if using PHP 5.3 format dates like: $dateFormatShortNumber, can't be used
//
@ -774,9 +777,6 @@ function api_format_date($time, $format = null, $language = null) {
if (is_null($language)) {
$language = api_get_language_isocode();
}
/*$date_formatter = datefmt_create($language, $datetype, $timetype, date_default_timezone_get());
$formatted_date = api_to_system_encoding(datefmt_format($date_formatter, $time), 'UTF-8');*/
$date_formatter = new IntlDateFormatter($language, $datetype, $timetype, date_default_timezone_get());
//$date_formatter->setPattern($date_format);
$formatted_date = api_to_system_encoding($date_formatter->format($time), 'UTF-8');
@ -1273,8 +1273,7 @@ function api_to_system_encoding($string, $from_encoding = null, $check_utf8_vali
if (api_is_valid_utf8($string)) {
return $string;
}
}
elseif (api_is_utf8($from_encoding)) {
} elseif (api_is_utf8($from_encoding)) {
if (!api_is_valid_utf8($string)) {
return $string;
}
@ -1315,8 +1314,7 @@ function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = null)
if (!api_is_utf8($encoding)) { // Just in case.
$string = api_utf8_decode($string, $encoding);
}
}
elseif (_api_convert_encoding_supports($encoding)) {
} elseif (_api_convert_encoding_supports($encoding)) {
if (!api_is_utf8($encoding)) {
$string = _api_convert_encoding($string, 'UTF-8', $encoding);
}
@ -1330,7 +1328,7 @@ function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = null)
}
/**
* Convers HTML entities into normal characters.
* Converts HTML entities into normal characters.
* @param string $string The input string.
* @param int $quote_style (optional) The quote style - ENT_COMPAT (default), ENT_QUOTES, ENT_NOQUOTES.
* @param string $encoding (optional) The encoding (of the result) used in conversion. If it is omited, the platform character set is assumed.
@ -1355,7 +1353,7 @@ function api_html_entity_decode($string, $quote_style = ENT_COMPAT, $encoding =
}
return $string;
}
return $string; // Here the function guves up.
return $string; // Here the function gives up.
}
/**
@ -1552,15 +1550,12 @@ function api_transliterate($string, $unknown = '?', $from_encoding = null) {
}
$ord = $ord & 255;
$result .= isset($map[$bank]['en'][$ord]) ? $map[$bank]['en'][$ord] : $unknown;
$head = '';
}
elseif ($c < "\x80") {
} elseif ($c < "\x80") {
// ASCII byte.
$result .= $c;
$head = '';
}
elseif ($c < "\xc0") {
} elseif ($c < "\xc0") {
// Illegal tail bytes.
if ($head == '') {
$result .= $unknown;
@ -1744,32 +1739,11 @@ function api_str_split($string, $split_length = 1, $encoding = null) {
* @link http://php.net/manual/en/function.mb-stripos
*/
function api_stripos($haystack, $needle, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (!is_string($needle)) {
$needle = (int)$needle;
if (api_is_utf8($encoding)) {
$needle = _api_utf8_chr($needle);
} else {
$needle = chr($needle);
}
}
if ($needle == '') {
return false;
}
if (_api_mb_supports($encoding)) {
return @mb_stripos($haystack, $needle, $offset, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (MBSTRING_INSTALLED) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
return @mb_stripos($haystack, $needle, $offset, 'UTF-8');
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
return api_strpos(api_strtolower($haystack, $encoding), api_strtolower($needle, $encoding), $offset, $encoding);
return mb_stripos($haystack, $needle, $offset, $encoding);
}
return stripos($haystack, $needle, $offset);
}
@ -1790,49 +1764,11 @@ function api_stripos($haystack, $needle, $offset = 0, $encoding = null) {
* @link http://php.net/manual/en/function.mb-stristr
*/
function api_stristr($haystack, $needle, $before_needle = false, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (!is_string($needle)) {
$needle = (int)$needle;
if (api_is_utf8($encoding)) {
$needle = _api_utf8_chr($needle);
} else {
$needle = chr($needle);
}
}
if ($needle == '') {
return false;
}
if (_api_mb_supports($encoding)) {
return @mb_stristr($haystack, $needle, $before_needle, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (MBSTRING_INSTALLED) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
$result = @mb_stristr($haystack, $needle, $before_needle, 'UTF-8');
if ($result === false) {
return false;
}
if (!api_is_utf8($encoding)) {
return api_utf8_decode($result, $encoding);
}
return $result;
}
$result = api_strstr(api_strtolower($haystack, $encoding), api_strtolower($needle, $encoding), $before_needle, $encoding);
if ($result === false) {
return false;
}
if ($before_needle) {
return api_substr($haystack, 0, api_strlen($result, $encoding), $encoding);
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
return api_substr($haystack, api_strlen($haystack, $encoding) - api_strlen($result, $encoding), null, $encoding);
}
if (!IS_PHP_53) {
return stristr($haystack, $needle);
return mb_stristr($haystack, $needle, $before_needle, $encoding);
}
return stristr($haystack, $needle, $before_needle);
}
@ -1864,9 +1800,6 @@ function api_strlen($string, $encoding = null) {
if (_api_iconv_supports($encoding)) {
return @iconv_strlen($string, $encoding);
}
if (api_is_utf8($encoding)) {
return api_byte_count(preg_replace("/[\x80-\xBF]/", '', $string));
}
return strlen($string);
}
@ -1886,43 +1819,10 @@ function api_strpos($haystack, $needle, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (!is_string($needle)) {
$needle = (int)$needle;
if (api_is_utf8($encoding)) {
$needle = _api_utf8_chr($needle);
} else {
$needle = chr($needle);
}
}
if ($needle == '') {
return false;
}
if (_api_is_single_byte_encoding($encoding)) {
return strpos($haystack, $needle, $offset);
}
elseif (_api_mb_supports($encoding)) {
return @mb_strpos($haystack, $needle, $offset, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
if (MBSTRING_INSTALLED) {
return @mb_strpos($haystack, $needle, $offset, 'UTF-8');
}
if (empty($offset)) {
$haystack = explode($needle, $haystack, 2);
if (count($haystack) > 1) {
return api_strlen($haystack[0]);
}
return false;
}
$haystack = api_substr($haystack, $offset);
if (($pos = api_strpos($haystack, $needle)) !== false ) {
return $pos + $offset;
}
return false;
} elseif (_api_mb_supports($encoding)) {
return mb_strpos($haystack, $needle, $offset, $encoding);
}
return strpos($haystack, $needle, $offset);
}
@ -1946,17 +1846,6 @@ function api_strrchr($haystack, $needle, $before_needle = false, $encoding = nul
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (!is_string($needle)) {
$needle = (int)$needle;
if (api_is_utf8($encoding)) {
$needle = _api_utf8_chr($needle);
} else {
$needle = chr($needle);
}
}
if ($needle == '') {
return false;
}
if (_api_is_single_byte_encoding($encoding)) {
if (!$before_needle) {
return strrchr($haystack, $needle);
@ -1966,26 +1855,8 @@ function api_strrchr($haystack, $needle, $before_needle = false, $encoding = nul
return false;
}
return api_substr($haystack, 0, api_strlen($haystack, $encoding) - api_strlen($result, $encoding), $encoding);
}
elseif (_api_mb_supports($encoding)) {
return @mb_strrchr($haystack, $needle, $before_needle, $encoding);
}
elseif (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
$result = @mb_strrchr($haystack, $needle, $before_needle, 'UTF-8');
if ($result === false) {
return false;
}
if (!api_is_utf8($encoding)) {
return api_utf8_decode($result, $encoding);
}
return $result;
}
if (!$before_needle) {
return strrchr($haystack, $needle);
} elseif (_api_mb_supports($encoding)) {
return mb_strrchr($haystack, $needle, $before_needle, $encoding);
}
$result = strrchr($haystack, $needle);
if ($result === false) {
@ -2030,7 +1901,8 @@ function api_strrev($string, $encoding = null) {
* @link http://php.net/manual/en/function.strripos
* @link http://php.net/manual/en/function.mb-strripos
*/
function api_strripos($haystack, $needle, $offset = 0, $encoding = null) {
function api_strripos($haystack, $needle, $offset = 0, $encoding = null)
{
return api_strrpos(api_strtolower($haystack, $encoding), api_strtolower($needle, $encoding), $offset, $encoding);
}
@ -2046,72 +1918,13 @@ function api_strripos($haystack, $needle, $offset = 0, $encoding = null) {
* @link http://php.net/manual/en/function.strrpos
* @link http://php.net/manual/en/function.mb-strrpos
*/
function api_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (!is_string($needle)) {
$needle = (int)$needle;
if (api_is_utf8($encoding)) {
$needle = _api_utf8_chr($needle);
} else {
$needle = chr($needle);
}
}
if ($needle == '') {
return false;
}
if (_api_is_single_byte_encoding($encoding)) {
return strrpos($haystack, $needle, $offset);
}
if (_api_mb_supports($encoding) && IS_PHP_52) {
return @mb_strrpos($haystack, $needle, $offset, $encoding);
} elseif (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
// In PHP 5.1 the $offset parameter didn't exist see http://php.net/manual/en/function.mb-strrpos.php
if (MBSTRING_INSTALLED && IS_PHP_SUP_OR_EQ_51) {
//return @mb_strrpos($haystack, $needle, $offset, 'UTF-8');
//@todo fix the missing $offset parameter
return @mb_strrpos($haystack, $needle, 'UTF-8');
}
if (MBSTRING_INSTALLED && IS_PHP_SUP_OR_EQ_52) {
return @mb_strrpos($haystack, $needle, $offset, 'UTF-8');
}
// This branch (this fragment of code) is an adaptation from the CakePHP(tm) Project, http://www.cakefoundation.org
$found = false;
$haystack = _api_utf8_to_unicode($haystack);
$haystack_count = count($haystack);
$matches = array_count_values($haystack);
$needle = _api_utf8_to_unicode($needle);
$needle_count = count($needle);
$position = $offset;
while (($found === false) && ($position < $haystack_count)) {
if (isset($needle[0]) && $needle[0] === $haystack[$position]) {
for ($i = 1; $i < $needle_count; $i++) {
if ($needle[$i] !== $haystack[$position + $i]) {
if ($needle[$i] === $haystack[($position + $i) -1]) {
$position--;
$found = true;
continue;
}
}
}
if (!$offset && isset($matches[$needle[0]]) && $matches[$needle[0]] > 1) {
$matches[$needle[0]] = $matches[$needle[0]] - 1;
} elseif ($i === $needle_count) {
$found = true;
$position--;
}
}
$position++;
function api_strrpos($haystack, $needle, $offset = 0, $encoding = null)
{
if (_api_mb_supports($encoding)) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
return ($found) ? $position : false;
return mb_strrpos($haystack, $needle, $offset, $encoding);
}
return strrpos($haystack, $needle, $offset);
}
@ -2147,46 +1960,10 @@ function api_strstr($haystack, $needle, $before_needle = false, $encoding = null
return false;
}
if (_api_is_single_byte_encoding($encoding)) {
// Adding the missing parameter $before_needle to the original function strstr(), PHP_VERSION < 5.3
if (!$before_needle) {
return strstr($haystack, $needle);
}
if (!IS_PHP_53) {
$result = explode($needle, $haystack, 2);
if ($result === false || count($result) < 2) {
return false;
}
return $result[0];
}
return strstr($haystack, $needle, $before_needle);
}
if (_api_mb_supports($encoding)) {
return @mb_strstr($haystack, $needle, $before_needle, $encoding);
}
elseif (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$haystack = api_utf8_encode($haystack, $encoding);
$needle = api_utf8_encode($needle, $encoding);
}
$result = @mb_strstr($haystack, $needle, $before_needle, 'UTF-8');
if ($result !== false) {
if (!api_is_utf8($encoding)) {
return api_utf8_decode($result, $encoding);
}
return $result;
}
return false;
}
// Adding the missing parameter $before_needle to the original function strstr(), PHP_VERSION < 5.3
if (!$before_needle) {
return strstr($haystack, $needle);
}
if (!IS_PHP_53) {
$result = explode($needle, $haystack, 2);
if ($result === false || count($result) < 2) {
return false;
}
return $result[0];
return mb_strstr($haystack, $needle, $before_needle, $encoding);
}
return strstr($haystack, $needle, $before_needle);
}
@ -2205,53 +1982,7 @@ function api_strtolower($string, $encoding = null) {
$encoding = _api_mb_internal_encoding();
}
if (_api_mb_supports($encoding)) {
return @mb_strtolower($string, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$string = api_utf8_encode($string, $encoding);
}
if (MBSTRING_INSTALLED) {
$string = @mb_strtolower($string, 'UTF-8');
} else {
// This branch (this fragment of code) is an adaptation from the CakePHP(tm) Project, http://www.cakefoundation.org
$codepoints = _api_utf8_to_unicode($string);
$length = count($codepoints);
$matched = false;
$result = array();
for ($i = 0 ; $i < $length; $i++) {
$codepoint = $codepoints[$i];
if ($codepoint < 128) {
$str = strtolower(chr($codepoint));
$strlen = api_byte_count($str);
for ($ii = 0 ; $ii < $strlen; $ii++) {
$lower = ord($str[$ii]);
}
$result[] = $lower;
$matched = true;
} else {
$matched = false;
$properties = &_api_utf8_get_letter_case_properties($codepoint, 'upper');
if (!empty($properties)) {
foreach ($properties as $key => $value) {
if ($properties[$key]['upper'] == $codepoint && count($properties[$key]['lower'][0]) === 1) {
$result[] = $properties[$key]['lower'][0];
$matched = true;
break 1;
}
}
}
}
if ($matched === false) {
$result[] = $codepoint;
}
}
$string = _api_utf8_from_unicode($result);
}
if (!api_is_utf8($encoding)) {
return api_utf8_decode($string, $encoding);
}
return $string;
return mb_strtolower($string, $encoding);
}
return strtolower($string);
}
@ -2270,91 +2001,7 @@ function api_strtoupper($string, $encoding = null) {
$encoding = _api_mb_internal_encoding();
}
if (_api_mb_supports($encoding)) {
return @mb_strtoupper($string, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$string = api_utf8_encode($string, $encoding);
}
if (MBSTRING_INSTALLED) {
$string = @mb_strtoupper($string, 'UTF-8');
} else {
// This branch (this fragment of code) is an adaptation from the CakePHP(tm) Project, http://www.cakefoundation.org
$codepoints = _api_utf8_to_unicode($string);
$length = count($codepoints);
$matched = false;
$replaced = array();
$result = array();
for ($i = 0 ; $i < $length; $i++) {
$codepoint = $codepoints[$i];
if ($codepoint < 128) {
$str = strtoupper(chr($codepoint));
$strlen = api_byte_count($str);
for ($ii = 0 ; $ii < $strlen; $ii++) {
$lower = ord($str[$ii]);
}
$result[] = $lower;
$matched = true;
} else {
$matched = false;
$properties = &_api_utf8_get_letter_case_properties($codepoint);
$property_count = count($properties);
if (!empty($properties)) {
foreach ($properties as $key => $value) {
$matched = false;
$replace = 0;
if ($length > 1 && count($properties[$key]['lower']) > 1) {
$j = 0;
for ($ii = 0; $ii < count($properties[$key]['lower']); $ii++) {
$next_codepoint = $next_codepoints[$i + $ii];
if (isset($next_codepoint) && ($next_codepoint == $properties[$key]['lower'][$j + $ii])) {
$replace++;
}
}
if ($replace == count($properties[$key]['lower'])) {
$result[] = $properties[$key]['upper'];
$replaced = array_merge($replaced, array_values($properties[$key]['lower']));
$matched = true;
break 1;
}
} elseif ($length > 1 && $property_count > 1) {
$j = 0;
for ($ii = 1; $ii < $property_count; $ii++) {
$next_codepoint = $next_codepoints[$i + $ii - 1];
if (in_array($next_codepoint, $properties[$ii]['lower'])) {
for ($jj = 0; $jj < count($properties[$ii]['lower']); $jj++) {
$next_codepoint = $next_codepoints[$i + $jj];
if (isset($next_codepoint) && ($next_codepoint == $properties[$ii]['lower'][$j + $jj])) {
$replace++;
}
}
if ($replace == count($properties[$ii]['lower'])) {
$result[] = $properties[$ii]['upper'];
$replaced = array_merge($replaced, array_values($properties[$ii]['lower']));
$matched = true;
break 2;
}
}
}
}
if ($properties[$key]['lower'][0] == $codepoint) {
$result[] = $properties[$key]['upper'];
$matched = true;
break 1;
}
}
}
}
if ($matched === false && !in_array($codepoint, $replaced, true)) {
$result[] = $codepoint;
}
}
$string = _api_utf8_from_unicode($result);
}
if (!api_is_utf8($encoding)) {
return api_utf8_decode($string, $encoding);
}
return $string;
return mb_strtoupper($string, $encoding);
}
return strtoupper($string);
}
@ -2383,82 +2030,7 @@ function api_substr($string, $start, $length = null, $encoding = null) {
return substr($string, $start, $length);
}
if (_api_mb_supports($encoding)) {
return @mb_substr($string, $start, $length, $encoding);
}
elseif (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$string = api_utf8_encode($string, $encoding);
}
if (MBSTRING_INSTALLED) {
$string = @mb_substr($string, $start, $length, 'UTF-8');
} else {
// The following branch of code is from the Drupal CMS, see the function drupal_substr().
$strlen = api_byte_count($string);
// Find the starting byte offset
$bytes = 0;
if ($start > 0) {
// Count all the continuation bytes from the start until we have found
// $start characters
$bytes = -1; $chars = -1;
while ($bytes < $strlen && $chars < $start) {
$bytes++;
$c = ord($string[$bytes]);
if ($c < 0x80 || $c >= 0xC0) {
$chars++;
}
}
}
else if ($start < 0) {
// Count all the continuation bytes from the end until we have found
// abs($start) characters
$start = abs($start);
$bytes = $strlen; $chars = 0;
while ($bytes > 0 && $chars < $start) {
$bytes--;
$c = ord($string[$bytes]);
if ($c < 0x80 || $c >= 0xC0) {
$chars++;
}
}
}
$istart = $bytes;
// Find the ending byte offset
if ($length === NULL) {
$bytes = $strlen - 1;
}
else if ($length > 0) {
// Count all the continuation bytes from the starting index until we have
// found $length + 1 characters. Then backtrack one byte.
$bytes = $istart; $chars = 0;
while ($bytes < $strlen && $chars < $length) {
$bytes++;
$c = ord($string[$bytes]);
if ($c < 0x80 || $c >= 0xC0) {
$chars++;
}
}
$bytes--;
}
else if ($length < 0) {
// Count all the continuation bytes from the end until we have found
// abs($length) characters
$length = abs($length);
$bytes = $strlen - 1; $chars = 0;
while ($bytes >= 0 && $chars < $length) {
$c = ord($string[$bytes]);
if ($c < 0x80 || $c >= 0xC0) {
$chars++;
}
$bytes--;
}
}
$iend = $bytes;
$string = substr($string, $istart, max(0, $iend - $istart + 1));
}
if (!api_is_utf8($encoding)) {
$string = api_utf8_decode($string, $encoding);
}
return $string;
return mb_substr($string, $start, $length, $encoding);
}
return substr($string, $start, $length);
}
@ -2476,7 +2048,7 @@ function api_substr_count($haystack, $needle, $encoding = null) {
$encoding = _api_mb_internal_encoding();
}
if (_api_mb_supports($encoding)) {
return @mb_substr_count($haystack, $needle, $encoding);
return mb_substr_count($haystack, $needle, $encoding);
}
return substr_count($haystack, $needle);
}
@ -2544,7 +2116,7 @@ function api_ucfirst($string, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
return api_strtoupper(api_substr($string, 0, 1, $encoding), $encoding) . api_substr($string, 1, api_strlen($string, $encoding), $encoding);
return api_strtoupper(api_substr($string, 0, 1, $encoding), $encoding) . api_substr($string, 1, api_strlen($string, $encoding), $encoding);
}
/**
@ -2556,30 +2128,11 @@ function api_ucfirst($string, $encoding = null) {
* @link http://php.net/manual/en/function.ucwords
*/
function api_ucwords($string, $encoding = null) {
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
if (_api_mb_supports($encoding)) {
return @mb_convert_case($string, MB_CASE_TITLE, $encoding);
}
if (api_is_encoding_supported($encoding)) {
if (!api_is_utf8($encoding)) {
$string = api_utf8_encode($string, $encoding);
}
if (MBSTRING_INSTALLED) {
$string = @mb_convert_case($string, MB_CASE_TITLE, 'UTF-8');
} else {
// The following fragment (branch) of code is based on the function utf8_ucwords() by Harry Fuecks
// See http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
// Note: [\x0c\x09\x0b\x0a\x0d\x20] matches - form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
// This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
$pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
$string = preg_replace_callback($pattern, '_api_utf8_ucwords_callback', $string);
}
if (!api_is_utf8($encoding)) {
return api_utf8_decode($string, $encoding);
if (empty($encoding)) {
$encoding = _api_mb_internal_encoding();
}
return $string;
return mb_convert_case($string, MB_CASE_TITLE, $encoding);
}
return ucwords($string);
}
@ -3603,8 +3156,8 @@ function api_is_encoding_supported($encoding) {
* Note: See the file chamilo/main/inc/lib/internationalization_database/non_utf8_encodings.php
* if you wish to revise the leading non-UTF-8 encoding for your language.
*/
function api_get_non_utf8_encoding($language = null) {
function api_get_non_utf8_encoding($language = null)
{
$language_is_supported = api_is_language_supported($language);
if (!$language_is_supported || empty($language)) {
$language = api_get_interface_language(false, true);
@ -3725,7 +3278,6 @@ function api_detect_encoding($string, $language = null) {
return $result;
}
/**
* String validation functions concerning certain encodings
*/
@ -3751,51 +3303,6 @@ function api_is_valid_ascii(&$string) {
return !preg_match('/[^\x00-\x7F]/S', $string);
}
/**
*
* Experimental translation feature for Chamilo
*
* Install this in Ubuntu
*
* sudo locale-gen es_ES
* sudo apt-get install php-gettext
*
* Install Spanish locale: $ sudo locale-gen es_ES
* Install English locale: $ sudo locale-gen en_US
*
* To view the list of locales installed in ubuntu
* locale -a
*
* In Debian check this file More info: http://algorytmy.pl/doc/php/ref.gettext.php
* sudo vim /etc/locale.gen
*
* Translate po files using this GUI
* sudo apt-get install poedit
*
* Some help here:
*
* Config getext
* http://zez.org/article/articleview/42/3/
* *
* Using getext in ubuntu
* http://www.sourcerally.net/regin/49-How-to-get-PHP-and-gettext-working-%28ubuntu,-debian%29
*
* Getext tutorial
* http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
*
*/
function setting_gettext() {
$domain = 'default';
$locale = api_get_language_isocode();
$locale = 'es_ES';
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain($domain, api_get_path(SYS_LANG_PATH));
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
}
/**
* Return true a date is valid

@ -167,7 +167,6 @@ function _api_compare_n_grams(&$n_grams, $encoding, $max_delta = LANGUAGE_DETECT
return $result;
}
/**
* Appendix to "Date and time formats"
*/
@ -259,7 +258,6 @@ function _api_clean_person_name($person_name) {
return preg_replace(array('/\s+/', '/, ,/', '/,+/', '/^[ ,]/', '/[ ,]$/'), array(' ', ', ', ',', '', ''), $person_name);
}
/**
* Appendix to "Multibyte string conversion functions"
*/
@ -595,7 +593,6 @@ function _api_html_entity_from_unicode($codepoint) {
return '&#'.$codepoint.';';
}
/**
* Appendix to "Common multibyte string functions"
*/
@ -681,7 +678,6 @@ function _api_utf8_ucwords_callback($matches) {
return $matches[2] . api_ucfirst(ltrim($matches[0]), 'UTF-8');
}
/**
* Appendix to "Common sting operations with arrays"
*/
@ -702,7 +698,6 @@ function _api_array_utf8_decode($variable) {
return $variable;
}
/**
* Appendix to "String comparison"
*/
@ -832,7 +827,6 @@ function _api_get_collator_sort_flag($sort_flag = SORT_REGULAR) {
return Collator::SORT_REGULAR;
}
/**
* ICU locales (accessible through intl extension).
*/
@ -884,7 +878,6 @@ function api_get_default_locale() {
return _api_set_default_locale();
}
/**
* Appendix to "Encoding management functions"
*/
@ -1035,7 +1028,7 @@ function _api_iconv_set_encoding($type, $encoding = null) {
}
/**
* Ckecks whether a given encoding is known to define single-byte characters only.
* Checks whether a given encoding is known to define single-byte characters only.
* The result might be not accurate for unknown by this library encodings. This is not fatal,
* then the library picks up conversions plus Unicode related internal algorithms.
* @param string $encoding A given encoding identificator.
@ -1131,85 +1124,3 @@ function _api_html_entity_supports($encoding) {
}
return $supports[$encoding];
}
/**
* Upgrading the PHP5 mbstring extension
*/
// A multibyte replacement of strchr(). This function exists in PHP 5 >= 5.2.0
// See http://php.net/manual/en/function.mb-strrchr
if (MBSTRING_INSTALLED && !function_exists('mb_strchr')) {
function mb_strchr($haystack, $needle, $part = false, $encoding = null) {
if (empty($encoding)) {
$encoding = mb_internal_encoding();
}
return mb_strstr($haystack, $needle, $part, $encoding);
}
}
// A multibyte replacement of stripos(). This function exists in PHP 5 >= 5.2.0
// See http://php.net/manual/en/function.mb-stripos
if (MBSTRING_INSTALLED && !function_exists('mb_stripos')) {
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = mb_internal_encoding();
}
return mb_strpos(mb_strtolower($haystack, $encoding), mb_strtolower($needle, $encoding), $offset, $encoding);
}
}
// A multibyte replacement of stristr(). This function exists in PHP 5 >= 5.2.0
// See http://php.net/manual/en/function.mb-stristr
if (MBSTRING_INSTALLED && !function_exists('mb_stristr')) {
function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
if (empty($encoding)) {
$encoding = mb_internal_encoding();
}
$pos = mb_strpos(mb_strtolower($haystack, $encoding), mb_strtolower($needle, $encoding), 0, $encoding);
if ($pos === false) {
return false;
}
if ($part) {
return mb_substr($haystack, 0, $pos + 1, $encoding);
}
return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
}
}
// A multibyte replacement of strrchr(). This function exists in PHP 5 >= 5.2.0
// See http://php.net/manual/en/function.mb-strrchr
if (MBSTRING_INSTALLED && !function_exists('mb_strrchr')) {
function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
if (empty($encoding)) {
$encoding = mb_internal_encoding();
}
$needle = mb_substr($needle, 0, 1, $encoding);
$pos = mb_strrpos($haystack, $needle, mb_strlen($haystack, $encoding) - 1, $encoding);
if ($pos === false) {
return false;
}
if ($part) {
return mb_substr($haystack, 0, $pos + 1, $encoding);
}
return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
}
}
// A multibyte replacement of strstr(). This function exists in PHP 5 >= 5.2.0
// See http://php.net/manual/en/function.mb-strstr
if (MBSTRING_INSTALLED && !function_exists('mb_strstr')) {
function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
if (empty($encoding)) {
$encoding = mb_internal_encoding();
}
$pos = mb_strpos($haystack, $needle, 0, $encoding);
if ($pos === false) {
return false;
}
if ($part) {
return mb_substr($haystack, 0, $pos + 1, $encoding);
}
return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
}
}

@ -221,16 +221,6 @@ define('USERNAME_PURIFIER', '/[^0-9A-Za-z_\.]/');
define('USERNAME_PURIFIER_MAIL', '/[^0-9A-Za-z_\.@]/');
define('USERNAME_PURIFIER_SHALLOW', '/\s/');
// Constants for detection some important PHP5 subversions.
$php_version = (float) PHP_VERSION;
define('IS_PHP_52', !((float)$php_version < 5.2));
define('IS_PHP_53', !((float)$php_version < 5.3));
define('IS_PHP_SUP_OR_EQ_53', ($php_version >= 5.3));
define('IS_PHP_SUP_OR_EQ_52', ($php_version >= 5.2 && !IS_PHP_53));
define('IS_PHP_SUP_OR_EQ_51', ($php_version >= 5.1 && !IS_PHP_52 && !IS_PHP_53));
// This constant is a result of Windows OS detection, it has a boolean value:
// true whether the server runs on Windows OS, false otherwise.
define('IS_WINDOWS_OS', api_is_windows_os());
@ -7222,20 +7212,20 @@ function api_get_origin()
function api_get_full_setting($variable, $key = null) {
$variable = Database::escape_string($variable);
$sql = "SELECT *
FROM settings_current
FROM settings_current
WHERE variable = '$variable' ";
if (!empty($key)) {
$key = Database::escape_string($key);
$sql .= "AND subkey = '$key'";
}
$result = Database::query($sql);
$setting = array();
while ($row = Database::fetch_assoc($result)) {
$setting[] = $row;
}
return $setting;
}

@ -103,6 +103,7 @@ class TableSort
// Probably an attack
return $data;
}
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
// Probably an attack
return $data;
@ -197,7 +198,8 @@ class TableSort
usort($data, create_function('$a, $b', $compare_function));
}
if (is_array($column_show)) {
if (is_array($column_show) && !empty($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);
@ -214,7 +216,6 @@ class TableSort
// Replace the multi-arrays
$data = $new_order_data;
}
return $data;
}

@ -3390,7 +3390,8 @@ class learnpath
* @param integer Optional attempt number. If none given, takes the highest from the lp_view table
* @return integer DB lp_view id
*/
public function get_view($attempt_num = 0) {
public function get_view($attempt_num = 0)
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::get_view()', 0);
}
@ -3403,19 +3404,25 @@ class learnpath
$lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
$course_id = api_get_course_int_id();
$sessionId = api_get_session_id();
$sql = "SELECT id, view_count FROM $lp_view_table
WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() ." AND user_id = " . $this->get_user_id() . " " .$search .
" ORDER BY view_count DESC";
WHERE
c_id = " . $course_id . " AND
lp_id = " . $this->get_id() . " AND
user_id = " . $this->get_user_id() . " AND
session_id = $sessionId
$search
ORDER BY view_count DESC";
$res = Database::query($sql);
if (Database :: num_rows($res) > 0) {
$row = Database :: fetch_array($res);
$this->lp_view_id = $row['id'];
} else {
// There is no database record, create one.
$sql = "INSERT INTO $lp_view_table (c_id, lp_id,user_id,view_count) VALUES
($course_id, " . $this->get_id() . "," . $this->get_user_id() . ",1)";
$res = Database::query($sql);
$sql = "INSERT INTO $lp_view_table (c_id, lp_id,user_id, view_count, session_id) VALUES
($course_id, " . $this->get_id() . "," . $this->get_user_id() . ", 1, $sessionId)";
Database::query($sql);
$id = Database :: insert_id();
$this->lp_view_id = $id;
}

@ -191,6 +191,7 @@ if (!empty($flat_list)) {
$url_start_lp = 'lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$id;
$name = Security::remove_XSS($details['lp_name']);
$extra = null;
if ($is_allowed_to_edit) {
$url_start_lp .= '&isStudentView=true';
$dsp_desc = '<em>'.$details['lp_maker'].'</em> '.(learnpath::is_lp_visible_for_student($id, api_get_user_id()) ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')');
@ -227,6 +228,12 @@ if (!empty($flat_list)) {
$dsp_edit_close = '</td>';
$token_parameter = "&sec_token=$token";
$dsp_edit_lp = null;
$dsp_publish = null;
$dsp_reinit = null;
$dsp_disk = null;
$copy = null;
$lp_auto_lunch_icon = null;
if ($is_allowed_to_edit) {
@ -355,7 +362,6 @@ if (!empty($flat_list)) {
$copy = Display::url(Display::return_icon('cd_copy.png', get_lang('Copy'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=copy&lp_id=$id");
/* Auto Lunch LP code */
$lp_auto_lunch_icon = '';
if (api_get_course_setting('enable_lp_auto_launch') == 1) {
if ($details['autolaunch'] == 1 && $autolunch_exists == false) {
$autolunch_exists = true;
@ -441,4 +447,4 @@ learnpath::generate_learning_path_folder($course_info);
//Deleting the objects
Session::erase('oLP');
Session::erase('lpobject');
Display::display_footer();
Display::display_footer();

Loading…
Cancel
Save