Remove Session::read('message'); use Display::addFlash, remove api_set_failure/api_get_failure

pull/2487/head
jmontoyaa 10 years ago
parent 917ab67fdb
commit 208bcb14a1
  1. 11
      main/admin/access_url_edit.php
  2. 10
      main/admin/access_url_edit_course_category_to_url.php
  3. 35
      main/admin/access_url_edit_courses_to_url.php
  4. 10
      main/admin/access_url_edit_usergroup_to_url.php
  5. 7
      main/admin/access_url_edit_users_to_url.php
  6. 5
      main/admin/access_urls.php
  7. 53
      main/admin/archive_cleanup.php
  8. 2
      main/admin/course_add.php
  9. 10
      main/admin/course_edit.php
  10. 15
      main/admin/course_list.php
  11. 3
      main/admin/course_user_import.php
  12. 3
      main/admin/course_user_import_by_email.php
  13. 22
      main/admin/index.php
  14. 10
      main/admin/sub_language.php
  15. 24
      main/admin/user_add.php
  16. 9
      main/admin/user_edit.php
  17. 18
      main/course_info/infocours.php
  18. 11
      main/exercise/hotpotatoes.php
  19. 1
      main/group/group.php
  20. 4
      main/inc/lib/course.lib.php
  21. 24
      main/inc/lib/fileUpload.lib.php
  22. 4
      main/inc/lib/myspace.lib.php
  23. 11
      main/inc/lib/usermanager.lib.php
  24. 18
      main/lp/aicc.class.php
  25. 3
      main/lp/lp_list.php
  26. 28
      main/lp/lp_upload.php
  27. 15
      main/lp/scorm.class.php
  28. 6
      main/social/groups.php
  29. 2
      main/upload/form.scorm.php
  30. 4
      main/upload/index.php
  31. 58
      main/upload/upload.scorm.php
  32. 13
      main/user/resume_session.php
  33. 10
      main/user/session_list.php
  34. 1
      main/webservices/lp.php
  35. 12
      main/webservices/registration.soap.php
  36. 16
      main/webservices/webservice_user.php
  37. 11
      main/work/add_document.php
  38. 12
      tests/main/inc/lib/main_api.lib.test.php

@ -95,7 +95,8 @@ if ($form->validate()) {
}
Security::clear_token();
$tok = Security::get_token();
header('Location: ' . $url_to_go . '?action=show_message&message=' . urlencode($message) . '&sec_token=' . $tok);
Display::addFlash(Display::return_message($message));
header('Location: ' . $url_to_go . '?sec_token=' . $tok);
exit();
}
} else {
@ -145,14 +146,6 @@ $interbreadcrumb[] = array("url" => 'access_urls.php', "name" => get_lang('Multi
Display :: display_header($tool_name);
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'show_message' :
Display :: display_normal_message(stripslashes($_GET['message']));
break;
}
}
// URL Images
$form->addElement('file', 'url_image_1', 'URL Image 1 (PNG)');
$form->addElement('file', 'url_image_2', 'URL Image 2 (PNG)');

@ -88,10 +88,12 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
if ($form_sent == 1) {
if ($access_url_id == 0) {
header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
Display::addFlash(Display::return_message(get_lang('SelectURL')));
header('Location: access_url_edit_users_to_url.php?');
} elseif (is_array($list)) {
UrlManager::updateUrlRelCourseCategory($list, $access_url_id);
header('Location: access_urls.php?action=show_message&message='.get_lang('Updated'));
Display::addFlash(Display::return_message(get_lang('Updated')));
header('Location: access_urls.php');
}
exit;
}
@ -101,10 +103,6 @@ Display::display_header($tool_name);
api_display_tool_title($tool_name);
if ($_GET['action'] == 'show_message') {
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
}
$noUserGroupList = $userGroupList = array();
$ajax_search = $add_type == 'unique' ? true : false;

@ -83,21 +83,23 @@ $UserList = $SessionList = array();
$users = $sessions = array();
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
$course_list = $_POST['course_list'];
if (!is_array($course_list)) {
$course_list = array();
}
if ($form_sent == 1) {
if ($access_url_id==0) {
header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
} elseif (is_array($course_list)) {
UrlManager::update_urls_rel_course($course_list, $access_url_id);
header('Location: access_urls.php?action=show_message&message='.get_lang('CoursesWereEdited'));
}
}
$form_sent = $_POST['form_sent'];
$course_list = $_POST['course_list'];
if (!is_array($course_list)) {
$course_list = array();
}
if ($form_sent == 1) {
if ($access_url_id == 0) {
Display::addFlash(Display::return_message(get_lang('SelectURL')));
header('Location: access_url_edit_users_to_url.php?');
} elseif (is_array($course_list)) {
UrlManager::update_urls_rel_course($course_list, $access_url_id);
Display::addFlash(Display::return_message(get_lang('CoursesWereEdited')));
header('Location: access_urls.php?');
}
}
}
Display::display_header($tool_name);
@ -108,9 +110,6 @@ echo '</div>';
api_display_tool_title($tool_name);
if (isset($_GET['action']) && $_GET['action'] == 'show_message')
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
$no_course_list = $course_list = array();
$ajax_search = $add_type == 'unique' ? true : false;

@ -88,10 +88,12 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
if ($form_sent == 1) {
if ($access_url_id == 0) {
header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
Display::addFlash(Display::return_message(get_lang('SelectURL')));
header('Location: access_url_edit_users_to_url.php');
} elseif (is_array($course_list)) {
UrlManager::update_urls_rel_usergroup($course_list, $access_url_id);
header('Location: access_urls.php?action=show_message&message='.get_lang('Updated'));
Display::addFlash(Display::return_message(get_lang('Updated')));
header('Location: access_urls.php');
}
exit;
}
@ -108,10 +110,6 @@ echo '</div>';
api_display_tool_title($tool_name);
if ($_GET['action'] == 'show_message') {
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
}
$noUserGroupList = $userGroupList = array();
$ajax_search = $add_type == 'unique' ? true : false;

@ -88,7 +88,8 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
}
if ($form_sent == 1) {
if ($access_url_id == 0) {
header('Location: access_url_edit_users_to_url.php?action=show_message&message=' . get_lang('SelectURL'));
Display::addFlash(Display::return_message(get_lang('SelectURL')));
header('Location: access_url_edit_users_to_url.php');
exit;
} elseif (is_array($UserList)) {
$result = UrlManager::update_urls_rel_user($UserList, $access_url_id);
@ -147,10 +148,6 @@ echo '</div>';
api_display_tool_title($tool_name);
if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
}
$nosessionUsersList = $sessionUsersList = array();
$ajax_search = $add_type == 'unique' ? true : false;

@ -29,10 +29,6 @@ $url_list = UrlManager::get_url_data();
// Actions
if (isset($_GET['action'])) {
if ($_GET['action'] == 'show_message') {
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
}
$url_id = (empty($_GET['url_id']) ? 0 : intval($_GET['url_id']));
switch ($_GET['action']) {
@ -71,7 +67,6 @@ if (isset($_GET['action'])) {
}
break;
}
}
$parameters['sec_token'] = Security::get_token();

@ -21,46 +21,27 @@ $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmi
$form = new FormValidator('archive_cleanup_form', 'post', '', '', array(), FormValidator::LAYOUT_BOX);
$form->addButtonSend(get_lang('ArchiveDirCleanupProceedButton'));
$message = null;
if ($form->validate()) {
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$htaccess = @file_get_contents($archive_path.'.htaccess');
$result = rmdirr($archive_path, true, true);
\Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles();
if (!empty($htaccess)) {
@file_put_contents($archive_path.'/.htaccess', $htaccess);
}
if ($result) {
$message = 'ArchiveDirCleanupSucceeded';
$type = 'confirmation';
} else {
$message = 'ArchiveDirCleanupFailed';
$type = 'error';
}
header('Location: '.api_get_self().'?msg='.$message.'&type='.$type);
exit;
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$htaccess = @file_get_contents($archive_path.'.htaccess');
$result = rmdirr($archive_path, true, true);
\Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles();
if (!empty($htaccess)) {
@file_put_contents($archive_path.'/.htaccess', $htaccess);
}
if ($result) {
Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupSucceeded')));
} else {
Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupFailed'), 'error'));
}
header('Location: '.api_get_self());
exit;
}
Display::display_header(get_lang('ArchiveDirCleanup'));
Display::display_warning_message(get_lang('ArchiveDirCleanupDescr'));
if (isset($_GET['msg']) && isset($_GET['type'])) {
if (in_array($_GET['msg'], array('ArchiveDirCleanupSucceeded', 'ArchiveDirCleanupFailed')))
switch($_GET['type']) {
case 'error':
$message = Display::return_message(get_lang($_GET['msg']), 'error');
break;
case 'confirmation':
$message = Display::return_message(get_lang($_GET['msg']), 'confirm');
}
}
if (!empty($message)) {
echo $message;
}
$form->display();
Display::display_footer();

@ -210,7 +210,7 @@ if ($form->validate()) {
$course_info = CourseManager::create_course($course);
header('Location: course_list.php'.($course_info===false?'?action=show_msg&warn='.api_get_last_failure():''));
header('Location: course_list.php');
exit;
}

@ -262,9 +262,11 @@ if ($form->validate()) {
if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) {
api_warn_hosting_contact('hosting_limit_active_courses');
api_set_failure(get_lang('PortalActiveCoursesLimitReached'));
Display::addFlash(
Display::return_message(get_lang('PortalActiveCoursesLimitReached'))
);
header('Location: course_list.php?action=show_msg&warn=' . urlencode(get_lang('PortalActiveCoursesLimitReached')));
header('Location: course_list.php');
exit;
}
}
@ -373,9 +375,9 @@ if ($form->validate()) {
$course_id = $courseInfo['real_id'];
Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
if ($visual_code_is_used) {
header('Location: course_list.php?action=show_msg&warn=' . urlencode($warn));
Display::addFlash(Display::return_message($warn));
header('Location: course_list.php');
} else {
header('Location: course_list.php');
}

@ -343,21 +343,6 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
} else {
$interbreadcrumb[] = array ('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
$tool_name = get_lang('CourseList');
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'show_msg':
if (!empty($_GET['warn'])) {
$message = Display::return_message(urldecode($_GET['warn']), 'warning');
}
if (!empty($_GET['msg'])) {
$message = Display::return_message(urldecode($_GET['msg']));
}
break;
default:
break;
}
}
if (isset($_GET['delete_course'])) {
CourseManager::delete_course($_GET['delete_course']);
$obj_cat = new Category();

@ -191,7 +191,8 @@ if ($form->validate()) {
Security::clear_token();
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&warn='.urlencode($warn).'&sec_token='.$tok);
Display::addFlash(Display::return_message($warn));
header('Location: user_list.php?sec_token='.$tok);
exit();
}
}

@ -192,7 +192,8 @@ if ($form->validate()) {
Security::clear_token();
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&warn='.urlencode($warn).'&sec_token='.$tok);
Display::addFlash(Display::return_message($warn));
header('Location: user_list.php?sec_token='.$tok);
exit();
}
}

@ -33,35 +33,23 @@ if (api_is_multiple_url_enabled()) {
}
// Displaying the header
$message = '';
if (api_is_platform_admin()) {
if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) &&
!is_writable(api_get_path(SYS_ARCHIVE_PATH))
) {
$message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'warning');
Display::addFlash(
Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'warning')
);
}
/* ACTION HANDLING */
if (!empty($_POST['Register'])) {
api_register_campus(!$_POST['donotlistcampus']);
$message = Display :: return_message(get_lang('VersionCheckEnabled'), 'confirmation');
Display::addFlash($message);
}
$keyword_url = Security::remove_XSS((empty($_GET['keyword']) ? '' : $_GET['keyword']));
}
if (isset($_GET['msg']) && isset($_GET['type'])) {
if (in_array($_GET['msg'], array('ArchiveDirCleanupSucceeded', 'ArchiveDirCleanupFailed'))) {
switch ($_GET['type']) {
case 'error':
$message = Display::return_message(get_lang($_GET['msg']), 'error');
break;
case 'confirmation':
$message = Display::return_message(get_lang($_GET['msg']), 'confirm');
}
}
}
$blocks = array();
// Instantiate Hook Event for Admin Block
@ -340,7 +328,6 @@ if (api_is_platform_admin()) {
$blocks['settings']['label'] = api_ucfirst(get_lang('System'));
$blocks['settings']['class'] = 'block-admin-settings';
$items = array();
$items[] = array('url' => 'special_exports.php', 'label' => get_lang('SpecialExports'));
$items[] = array('url' => 'system_status.php', 'label' => get_lang('SystemStatus'));
@ -602,5 +589,4 @@ if (api_is_platform_admin()) {
$admin_template = $tpl->get_template('admin/settings_index.tpl');
$content = $tpl->fetch($admin_template);
$tpl->assign('content', $content);
$tpl->assign('message', $message);
$tpl->display_one_col_template();

@ -99,15 +99,7 @@ echo $intro;
echo '<br />';
printf(get_lang('ParentLanguageX'), $language_name);
echo '</div>';
if (!empty($_SESSION['msg'])) {
echo $_SESSION['msg'];
unset($_SESSION['msg']);
} else {
echo '<br />';
}
echo '<br />';
$txt_search_word = (!empty($_REQUEST['txt_search_word']) ? Security::remove_XSS($_REQUEST['txt_search_word']) : '');
$html ='<div style="float:left" class="actions">';
$html.='<form style="float:left" id="Searchlanguage" name="Searchlanguage" method="GET" action="sub_language.php">';

@ -393,16 +393,8 @@ if ($form->validate()) {
Security::clear_token();
$tok = Security::get_token();
if ($user_id === false) {
//If any error ocurred during user creation, print it (api_failureList
// stores values as separate words, so rework it
$message = '';
$message_bits = explode(' ',api_get_last_failure());
foreach ($message_bits as $bit) {
$message .= ucfirst($bit);
}
} else {
if (!empty($picture['name'])) {
if (!empty($user_id)) {
if (!empty($picture['name'])) {
$picture_uri = UserManager::update_user_picture(
$user_id,
$_FILES['picture']['name'],
@ -433,17 +425,19 @@ if ($form->validate()) {
$extraFieldValues = new ExtraFieldValue('user');
$user['item_id'] = $user_id;
$extraFieldValues->saveFieldValues($user);
$message = get_lang('UserAdded');
}
if (isset($user['submit_plus'])) {
//we want to add more. Prepare report message and redirect to the same page (to clean the form)
header('Location: user_add.php?message='.urlencode($message).'&sec_token='.$tok);
exit ();
Display::addFlash(Display::return_message($message));
header('Location: user_add.php?sec_token='.$tok);
exit;
} else {
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
exit ();
Display::addFlash(Display::return_message($message));
header('Location: user_list.php?sec_token='.$tok);
exit;
}
}
} else {

@ -577,15 +577,15 @@ if ($form->validate()) {
$extraFieldValue->saveFieldValues($user);
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
Display::addFlash(Display::return_message(get_lang('UserUpdated')));
header('Location: user_list.php?sec_token='.$tok);
exit();
}
}
$message = null;
if ($error_drh) {
$err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
$message = Display::return_message($err_msg, 'error');
Display::addFlash(Display::return_message(get_lang('StatusCanNotBeChangedToHumanResourcesManager'), 'error'));
}
$content = null;
@ -602,6 +602,5 @@ $content .= '<a class="thumbnail expand-image" href="'.$bigImage.'" /><img src="
$content .= '</div>';
$tpl = new Template($tool_name);
$tpl->assign('message', $message);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -511,8 +511,12 @@ if ($form->validate() && is_settings_editable()) {
$num = CourseManager::countActiveCourses($urlId);
if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) {
api_warn_hosting_contact('hosting_limit_active_courses');
api_set_failure(get_lang('PortalActiveCoursesLimitReached'));
$url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?action=course_active_warning&'.api_get_cidreq();
Display::addFlash(
Display::return_message(get_lang('PortalActiveCoursesLimitReached'))
);
$url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.api_get_cidreq();
header("Location: $url");
exit;
}
@ -579,7 +583,7 @@ if ($form->validate() && is_settings_editable()) {
$cidReset = true;
$cidReq = $course_code;
require '../inc/local.inc.php';
$url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?action=show_message&'.api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).'course_info/infocours.php?'.api_get_cidreq();
header("Location: $url");
exit;
}
@ -590,14 +594,6 @@ Display :: display_header($nameTools, MODULE_HELP_NAME);
if ($show_delete_watermark_text_message) {
Display :: display_normal_message(get_lang('FileDeleted'));
}
if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
Display :: display_normal_message(get_lang('ModifDone'));
}
if (isset($_GET['action']) && $_GET['action'] == 'course_active_warning') {
Display :: display_warning_message(get_lang('PortalActiveCoursesLimitReached'));
}
echo '<script>
$(function() {
$("#course_settings").accordion({

@ -209,19 +209,8 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
'QuizAdded',
api_get_user_id()
);
} else {
if ($finish == 2) {
// delete?
//$dialogBox .= get_lang('NoImg');
}
$finish = 0;
// error
if (api_failure::get_last_failure() == 'not_enough_space') {
$dialogBox .= get_lang('NoSpace');
} elseif (api_failure::get_last_failure() == 'php_file_in_zip_file') {
$dialogBox .= get_lang('ZipNoPhp');
}
}
}
}

@ -44,7 +44,6 @@ $course_id = api_get_course_int_id();
* Self-registration and un-registration
*/
$my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
$my_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null;
$my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
$my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
$my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;

@ -6130,7 +6130,9 @@ class CourseManager
if ($num >= $_configuration[$accessUrlId][$param]) {
api_warn_hosting_contact($param);
return api_set_failure(get_lang($msgLabel));
Display::addFlash(
Display::return_message($msgLabel)
);
}
}
return false;

@ -904,7 +904,11 @@ function treat_uploaded_file($uploaded_file, $base_work_dir, $upload_path, $max_
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
if (!enough_size($uploaded_file['size'], $base_work_dir, $max_filled_space)) {
return api_failure::set_failure('not_enough_space');
Display::addFlash(
Display::return_message(get_lang('NoSpace'))
);
return false;
}
if ($uncompress == 'unzip' && preg_match('/.zip$/', strtolower($uploaded_file['name']))) {
@ -955,7 +959,11 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
$realFileSize = 0;
foreach ($zip_content_array as & $this_content) {
if (preg_match('~.(php.*|phtml)$~i', $this_content['filename'])) {
return api_failure::set_failure('php_file_in_zip_file');
Display::addFlash(
Display::return_message(get_lang('ZipNoPhp'))
);
return false;
} elseif (stristr($this_content['filename'], 'imsmanifest.xml')) {
$ok_scorm = true;
} elseif (stristr($this_content['filename'], 'LMS')) {
@ -975,11 +983,19 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
}
if (!$ok_scorm && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM) {
return api_failure::set_failure('not_scorm_content');
Display::addFlash(
Display::return_message(get_lang('NotScormContent'))
);
return false;
}
if (!enough_size($realFileSize, $base_work_dir, $max_filled_space)) {
return api_failure::set_failure('not_enough_space');
Display::addFlash(
Display::return_message(get_lang('NoSpace'))
);
return false;
}
// It happens on Linux that $upload_path sometimes doesn't start with '/'

@ -2675,8 +2675,8 @@ class MySpace
$registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".api_get_person_name($user['FirstName'], $user['LastName'])."</a> - ".$addedto.'<br />';
}
}
header('Location: course.php?id_session='.$id_session.'&action=show_message&message='.urlencode($registered_users));
Display::addFlash(Display::return_message($registered_users));
header('Location: course.php?id_session='.$id_session);
exit;
}

@ -213,7 +213,6 @@ class UserManager
* @return mixed new user id - if the new user creation succeeds, false otherwise
* @desc The function tries to retrieve user id from the session.
* If it exists, the current user id is the creator id. If a problem arises,
* it stores the error message in global $api_failureList
* @assert ('Sam','Gamegie',5,'sam@example.com','jo','jo') > 1
* @assert ('Pippin','Took',null,null,'jo','jo') === false
*/
@ -308,7 +307,11 @@ class UserManager
// First check wether the login already exists
if (!self::is_username_available($loginName)) {
return api_set_failure('login-pass already taken');
Display::addFlash(
Display::return_message(get_lang('LoginAlreadyTaken'))
);
return false;
}
$currentDate = api_get_utc_datetime();
@ -477,7 +480,9 @@ class UserManager
}
Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $return);
} else {
return api_set_failure('error inserting in Database');
Display::addFlash(Display::return_message(get_lang('ErrorContactPlatformAdmin')));
return false;
}
if (is_array($extra) && count($extra) > 0) {

@ -392,7 +392,10 @@ class aicc extends learnpath
if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
// If a php file is found, do not authorize (security risk).
if ($this->debug > 1) {error_log('New LP - aicc::import_package() - Found unauthorized file: '.$thisContent['filename'], 0); }
return api_failure::set_failure('php_file_in_zip_file');
Display::addFlash(
Display::return_message(get_lang('ZipNoPhp'))
);
return false;
} elseif (preg_match('?.*/aicc/$?', $thisContent['filename'])) {
// If a directory named 'aicc' is found, package type = aicc, but continue,
// because we need to find the right AICC files;
@ -460,13 +463,20 @@ class aicc extends learnpath
}
if ($package_type == '' || !$mandatory)
// && defined('CHECK_FOR_AICC') && CHECK_FOR_AICC)
{
return api_failure::set_failure('not_aicc_content');
Display::addFlash(
Display::return_message(get_lang('FileError'))
);
return false;
}
if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
return api_failure::set_failure('not_enough_space');
Display::addFlash(
Display::return_message(get_lang('NoSpace'))
);
return false;
}
// It happens on Linux that $new_dir sometimes doesn't start with '/'

@ -83,9 +83,6 @@ if ($is_allowed_to_edit) {
break;
}
}
if (api_failure::get_last_failure()) {
$message = Display::return_message(api_failure::get_last_failure());
}
$actions .= Display::url(
Display::return_icon('new_folder.png', get_lang('AddCategory'), array(), ICON_SIZE_MEDIUM),

@ -27,7 +27,10 @@ $user_file = isset($_GET['user_file']) ? $_GET['user_file'] : array();
$user_file = $user_file ? $user_file : array();
$is_error = isset($user_file['error']) ? $user_file['error'] : false;
if (isset($_POST) && $is_error) {
return api_failure::set_failure('upload_file_too_big');
Display::addFlash(
Display::return_message(get_lang('UplFileTooBig'))
);
return false;
unset($_FILES['user_file']);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) {
@ -60,10 +63,6 @@ if (isset($_POST) && $is_error) {
require_once 'scorm.class.php';
$oScorm = new scorm();
$manifest = $oScorm->import_package($_FILES['user_file'], $current_dir);
if (!$manifest) {
//if api_set_failure
return api_failure::set_failure(api_failure::get_last_failure());
}
if (!empty($manifest)) {
$oScorm->parse_manifest($manifest);
$fixTemplate = api_get_configuration_value('learnpath_fix_xerte_template');
@ -147,8 +146,6 @@ if (isset($_POST) && $is_error) {
}
$oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
} else {
// Show error message stored in $oScrom->error_msg.
}
$oScorm->set_proximity($proximity);
$oScorm->set_maker($maker);
@ -180,7 +177,9 @@ if (isset($_POST) && $is_error) {
break;
case '':
default:
return api_failure::set_failure('not_a_learning_path');
Display::addFlash(Display::return_message(get_lang('ScormUnknownPackageFormat')));
return false;
break;
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
// end if is_uploaded_file
@ -204,7 +203,9 @@ if (isset($_POST) && $is_error) {
$result = learnpath::verify_document_size($s);
if ($result == true) {
return api_failure::set_failure('upload_file_too_big');
Display::addFlash(
Display::return_message(get_lang('UplFileTooBig'))
);
}
$type = learnpath::get_package_type($s, basename($s));
@ -213,9 +214,6 @@ if (isset($_POST) && $is_error) {
require_once 'scorm.class.php';
$oScorm = new scorm();
$manifest = $oScorm->import_local_package($s, $current_dir);
if ($manifest === false) { //if ap i_set_failure
return api_failure::set_failure(api_failure::get_last_failure());
}
if (!empty($manifest)) {
$oScorm->parse_manifest($manifest);
$oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
@ -255,6 +253,10 @@ if (isset($_POST) && $is_error) {
break;
case '':
default:
return api_failure::set_failure('not_a_learning_path');
Display::addFlash(
Display::return_message(get_lang('ScormUnknownPackageFormat'))
);
return false;
break;
}
}

@ -341,7 +341,7 @@ class scorm extends learnpath
'modified_on' => $now,
'publicated_on' => $now
];
$lp_id = Database::insert($new_lp, $params);
if ($lp_id) {
@ -628,12 +628,21 @@ class scorm extends learnpath
if ($package_type== '') {
// && defined('CHECK_FOR_SCORM') && CHECK_FOR_SCORM)
if ($this->debug > 1) { error_log('New LP - Package type is empty', 0); }
return api_failure::set_failure('not_scorm_content');
Display::addFlash(
Display::return_message(get_lang('NotScormContent'))
);
return false;
}
if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
if ($this->debug > 1) { error_log('New LP - Not enough space to store package', 0); }
return api_failure::set_failure('not_enough_space');
Display::addFlash(
Display::return_message(get_lang('NoSpace'))
);
return false;
}
// It happens on Linux that $new_dir sometimes doesn't start with '/'

@ -277,11 +277,6 @@ if (!empty($create_group_item)) {
$headers = array(get_lang('Newest'), get_lang('Popular'), get_lang('MyGroups'));
$social_right_content .= Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse');
$show_message = null;
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'topic_deleted') {
$show_message = Display::return_message(get_lang('Deleted'), 'success');
}
$tpl = new Template(null);
// Block Social Avatar
@ -295,7 +290,6 @@ $social_menu_block = SocialManager::show_social_menu($show_menu);
$templateName = 'social/groups.tpl';
$tpl->setHelp('Groups');
$tpl->assign('message', $show_message);
$tpl->assign('social_menu_block', $social_menu_block);
$tpl->assign('social_right_content', $social_right_content);
$social_layout = $tpl->get_template($templateName);

@ -55,7 +55,7 @@ echo '</div>';
$form = new FormValidator(
'',
'POST',
'upload.php?'.api_get_cidreq(),
api_get_path(WEB_CODE_PATH).'upload/upload.php?'.api_get_cidreq(),
'',
array(
'id' => "upload_form",

@ -70,7 +70,7 @@ Event::event_access_tool(TOOL_UPLOAD);
* Prepare the header
*/
$htmlHeadXtra[] = '<script language="javascript" src="../inc/lib/javascript/upload.js" type="text/javascript"></script>';
$htmlHeadXtra[] = '<script type="text/javascript">
$htmlHeadXtra[] = '<script>
var myUpload = new upload(0);
</script>';
@ -85,7 +85,7 @@ switch ($my_tool) {
case TOOL_DROPBOX:
case TOOL_STUDENTPUBLICATION:
case TOOL_DOCUMENT:
default :
default:
require 'form.document.php';
break;
}

@ -14,49 +14,29 @@ require_once '../lp/lp_upload.php';
// Reinit current working directory as many functions in upload change it
chdir($cwdir);
$error = api_failure::get_last_failure();
if (api_get_setting('search_enabled') === 'true') {
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$specific_fields = get_specific_field_list();
if ($error == 'upload_file_too_big') {
$msg = urlencode(get_lang('UplFileTooBig'));
$dialogtype = 'error';
} else {
if ($error == 'not_a_learning_path') {
$msg = urlencode(get_lang('ScormUnknownPackageFormat'));
$dialogtype = 'error';
} elseif ($error == 'not_enough_space') {
$msg = urlencode(
get_lang('ScormNotEnoughSpaceInCourseToInstallPackage')
);
$dialogtype = 'error';
} elseif ($error == 'not_scorm_content') {
$msg = urlencode(get_lang('ScormPackageFormatNotScorm'));
$dialogtype = 'error';
} else {
if (api_get_setting('search_enabled') == 'true') {
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$specific_fields = get_specific_field_list();
foreach ($specific_fields as $specific_field) {
$values = explode(',', trim($_POST[$specific_field['code']]));
if (!empty($values)) {
foreach ($values as $value) {
$value = trim($value);
if (!empty($value)) {
add_specific_field_value(
$specific_field['id'],
api_get_course_id(),
TOOL_LEARNPATH,
$oScorm->lp_id,
$value
);
}
}
foreach ($specific_fields as $specific_field) {
$values = explode(',', trim($_POST[$specific_field['code']]));
if (!empty($values)) {
foreach ($values as $value) {
$value = trim($value);
if (!empty($value)) {
add_specific_field_value(
$specific_field['id'],
api_get_course_id(),
TOOL_LEARNPATH,
$oScorm->lp_id,
$value
);
}
}
}
$msg = urlencode(get_lang('UplUploadSucceeded'));
$dialogtype = 'confirmation';
}
}
header('location: ../lp/lp_controller.php?action=list&dialog_box=' . $msg . '&dialogtype=' . $dialogtype);
//Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
header('location: ../lp/lp_controller.php?action=list');
exit;

@ -75,10 +75,11 @@ if ($allowTutors === 'true') {
$result = UrlManager::add_user_to_url($user_id, $url_id);
$user_info = api_get_user_info($user_id);
if ($result) {
$message = Display::return_message(
Display::addFlash(
Display::return_message(
get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
'confirm'
);
));
}
break;
case 'delete':
@ -119,14 +120,6 @@ if ($allowTutors === 'true') {
}
Display::display_header($tool_name);
if (!empty($_GET['warn'])) {
Display::display_warning_message(urldecode($_GET['warn']));
}
if (!empty($message)) {
echo $message;
}
echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
echo Display::page_subheader(get_lang('GeneralProperties').$url);

@ -24,16 +24,6 @@ Display::display_header($tool_name);
$allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
if ($allowTutors == 'true') {
$error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
$error_message = Security::remove_XSS($_GET['message']);
}
if (!empty($error_message)) {
Display::display_normal_message($error_message, false);
}
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&from_course_session=1';
if (isset($_REQUEST['keyword'])) {

@ -197,7 +197,6 @@ function WSImportLP($params)
if (!$manifest) {
if ($debug) error_log('manifest.xml file not found');
//if api_set_failure
return 'manifest.xml file not found';
}

@ -333,10 +333,8 @@ function WSCreateUsers($params)
// First check wether the login already exists.
if (!UserManager::is_username_available($loginName)) {
if (api_set_failure('login-pass already taken')) {
$results[] = 0;
continue;
}
$results[] = 0;
continue;
}
$userId = UserManager::create_user(
@ -886,10 +884,8 @@ function WSCreateUsersPasswordCrypted($params)
}
// First check wether the login already exists
if (!UserManager::is_username_available($loginName)) {
if (api_set_failure('login-pass already taken')) {
$results[] = 0;
continue;
}
$results[] = 0;
continue;
}
$sql = "INSERT INTO $table_user SET

@ -220,7 +220,7 @@ class WSUser extends WS {
* @return mixed New user id generated by the system, WSError otherwise
*/
protected function createUserHelper($firstname, $lastname, $status, $login, $password, $encrypt_method, $user_id_field_name, $user_id_value, $visibility, $email, $language, $phone, $expiration_date, $extras = array()) {
global $api_failureList;
// Add the original user id field name and value to the extra fields if needed
$extras_associative = array();
if($user_id_field_name != "chamilo_user_id") {
@ -233,14 +233,17 @@ class WSUser extends WS {
}
$result = UserManager::create_user($firstname, $lastname, $status, $email, $login, $password, '', $language, $phone, '', PLATFORM_AUTH_SOURCE, $expiration_date, $visibility, 0, $extras_associative, $encrypt_method);
if (!$result) {
$failure = $api_failureList[0];
return new WSError(104, 'There was an error creating the user');
/*$failure = $api_failureList[0];
if($failure == 'login-pass already taken') {
return new WSError(102, 'This username is already taken');
} else if($failure == 'encrypt_method invalid') {
return new WSError(103, 'The encryption of the password is invalid');
} else {
return new WSError(104, 'There was an error creating the user');
}
}*/
} else {
return $result;
}
@ -349,7 +352,6 @@ class WSUser extends WS {
$expiration_date,
$extras
) {
global $api_failureList;
$user_id = $this->getUserId($user_id_field_name, $user_id_value);
if($user_id instanceof WSError) {
return $user_id;
@ -382,12 +384,12 @@ class WSUser extends WS {
$encrypt_method
);
if (!$result) {
$failure = $api_failureList[0];
if($failure == 'encrypt_method invalid') {
/*if($failure == 'encrypt_method invalid') {
return new WSError(103, 'The encryption of the password is invalid');
} else {
return new WSError(105, 'There was an error updating the user');
}
}*/
return new WSError(105, 'There was an error updating the user');
} else {
return $result;
}

@ -11,8 +11,6 @@ $current_course_tool = TOOL_STUDENTPUBLICATION;
$workId = isset($_GET['id']) ? intval($_GET['id']) : null;
$docId = isset($_GET['document_id']) ? intval($_GET['document_id']) : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
$message = Session::read('show_message');
Session::erase('show_message');
if (empty($workId)) {
api_not_allowed(true);
@ -55,7 +53,7 @@ switch ($action) {
if (empty($docId)) {
Display :: display_header(null);
echo $message;
$documents = getAllDocumentToWork($workId, api_get_course_int_id());
if (!empty($documents)) {
echo Display::page_subheader(get_lang('DocumentsAdded'));
@ -103,20 +101,17 @@ if (empty($docId)) {
if (empty($data)) {
addDocumentToWork($docId, $workId, api_get_course_int_id());
$message = Display::return_message(get_lang('Added'), 'success');
Display::addFlash(Display::return_message(get_lang('Added'), 'success'));
} else {
$message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
Display::addFlash(Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning'));
}
Session::write('show_message', $message);
$url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
header('Location: '.$url);
exit;
}
Display::display_header(null);
echo $message;
$form->display();
}

@ -209,24 +209,12 @@ class TestMainApi extends UnitTestCase {
$this->assertTrue($res);
}
function testApiSetFailure(){
global $api_failureList;
$failureType=true;
$res = api_set_failure($failureType);
$this->assertTrue(is_bool($res));
$this->assertTrue($api_failureList);
}
function testApiSetAnonymous(){
$res = api_set_anonymous();
$this->assertTrue(is_bool($res));
}
function testApiGetLastFailure(){
$res= api_Get_last_failure();
$this->assertTrue($res);
}
function testApiGetSessionId(){
$res = api_get_session_id();
$this->assertTrue(is_numeric($res));

Loading…
Cancel
Save