From 5d2a5f94c1429546af74a42b3a9660dc08855b4c Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Thu, 31 Aug 2017 15:29:35 +0200 Subject: [PATCH] Use ChamiloSession class --- .../hotspot_actionscript_admin.as.php | 4 +- main/exercise/upload_exercise.php | 23 ++++++---- main/inc/ajax/lp.ajax.php | 14 ++++-- main/inc/email_editor.php | 12 +++--- main/inc/lib/document.lib.php | 14 +++--- main/inc/lib/myspace.lib.php | 11 +++-- main/inc/lib/notebook.lib.php | 18 ++++---- main/inc/lib/tracking.lib.php | 43 +++++++++++++++---- main/lp/aicc_api.php | 2 +- main/lp/download.php | 1 - 10 files changed, 92 insertions(+), 50 deletions(-) diff --git a/main/exercise/hotspot_actionscript_admin.as.php b/main/exercise/hotspot_actionscript_admin.as.php index 4adaadf66f..7eb082ee89 100755 --- a/main/exercise/hotspot_actionscript_admin.as.php +++ b/main/exercise/hotspot_actionscript_admin.as.php @@ -1,6 +1,8 @@ type; -$answers = $_SESSION['tmp_answers']; +$answers = Session::read('tmp_answers'); $nbrAnswers = count($answers['answer']); for ($i = 1; $i <= $nbrAnswers; $i++) { diff --git a/main/exercise/upload_exercise.php b/main/exercise/upload_exercise.php index d4ecc90ff0..090219e98b 100755 --- a/main/exercise/upload_exercise.php +++ b/main/exercise/upload_exercise.php @@ -14,6 +14,7 @@ $help_content = 'exercise_upload'; require_once __DIR__.'/../inc/global.inc.php'; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); +$debug = false; $origin = api_get_origin(); if (!$is_allowed_to_edit) { api_not_allowed(true); @@ -538,11 +539,10 @@ function lp_upload_quiz_action_handling() } } - if (isset($_SESSION['lpobject'])) { - if ($debug > 0) { - error_log('New LP - SESSION[lpobject] is defined', 0); - } - $oLP = unserialize($_SESSION['lpobject']); + $lpObject = Session::read('lpobject'); + + if (!empty($lpObject)) { + $oLP = unserialize($lpObject); if (is_object($oLP)) { if ($debug > 0) { error_log('New LP - oLP is object', 0); @@ -555,7 +555,7 @@ function lp_upload_quiz_action_handling() Session::erase('oLP'); Session::erase('lpobject'); } else { - $_SESSION['oLP'] = $oLP; + Session::write('oLP', $oLP); } } } @@ -564,9 +564,16 @@ function lp_upload_quiz_action_handling() $previous = $_SESSION['oLP']->select_previous_item_id(); $parent = 0; // Add a Quiz as Lp Item - $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quizTitle, ''); + $_SESSION['oLP']->add_item( + $parent, + $previous, + TOOL_QUIZ, + $quiz_id, + $quizTitle, + '' + ); // Redirect to home page for add more content - header('location: ../lp/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.intval($_GET['lp_id'])); + header('Location: ../lp/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.intval($_GET['lp_id'])); exit; } else { // header('location: exercise.php?' . api_get_cidreq()); diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index 50b6303c9a..cc86978f34 100755 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -41,9 +41,11 @@ switch ($action) { break; case 'add_lp_item': if (api_is_allowed_to_edit(null, true)) { - if ($_SESSION['oLP']) { + /** @var learnpath $learningPath */ + $learningPath = Session::read('oLP'); + if ($learningPath) { // Updating the lp.modified_on - $_SESSION['oLP']->set_modified_on(); + $learningPath->set_modified_on(); $title = $_REQUEST['title']; if ($_REQUEST['type'] == TOOL_QUIZ) { $title = Exercise::format_title_variable($title); @@ -52,7 +54,7 @@ switch ($action) { $parentId = isset($_REQUEST['parent_id']) ? $_REQUEST['parent_id'] : ''; $previousId = isset($_REQUEST['previous_id']) ? $_REQUEST['previous_id'] : ''; - echo $_SESSION['oLP']->add_item( + echo $learningPath->add_item( $parentId, $previousId, $_REQUEST['type'], @@ -187,7 +189,11 @@ switch ($action) { break; } - $learningPath = learnpath::getLpFromSession(api_get_course_id(), $lpId, api_get_user_id()); + $learningPath = learnpath::getLpFromSession( + api_get_course_id(), + $lpId, + api_get_user_id() + ); $lpItem = $learningPath->getItem($lpItemId); if (empty($lpItem)) { diff --git a/main/inc/email_editor.php b/main/inc/email_editor.php index c7fe0b57a2..6cb1dc3567 100755 --- a/main/inc/email_editor.php +++ b/main/inc/email_editor.php @@ -14,13 +14,13 @@ use ChamiloSession as Session; require_once __DIR__.'/../inc/global.inc.php'; -if (empty($_user['user_id'])) { +if (empty(api_get_user_id())) { api_not_allowed(true); } -if (empty($_SESSION['origin_url'])) { - $origin_url = $_SERVER['HTTP_REFERER']; - Session::write('origin_url', $origin_url); +$originUrl = Session::read('origin_url'); +if (empty($originUrl)) { + Session::write('origin_url', $_SERVER['HTTP_REFERER']); } $action = isset($_GET['action']) ? $_GET['action'] : null; @@ -95,9 +95,9 @@ if ($form->validate()) { get_lang('Anonymous') ); } - $orig = $_SESSION['origin_url']; + $orig = Session::read('origin_url'); Session::erase('origin_url'); - header('location:'.$orig); + header('Location:'.$orig); exit; } Display::display_header(get_lang('SendEmail')); diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 96c91b6c7c..2b2f82800c 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -4802,8 +4802,8 @@ class DocumentManager copy($from_sys, $to_sys); } - //get file from tmp directory - $_SESSION['temp_audio_nanogong'] = $to_sys; + // get file from tmp directory + Session::write('temp_audio_nanogong', $to_sys); return api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip; } @@ -4813,12 +4813,10 @@ class DocumentManager */ public static function removeGeneratedAudioTempFile() { - if (isset($_SESSION['temp_audio_nanogong']) - && !empty($_SESSION['temp_audio_nanogong']) - && is_file($_SESSION['temp_audio_nanogong'])) { - - unlink($_SESSION['temp_audio_nanogong']); - unset($_SESSION['temp_audio_nanogong']); + $tempAudio = Session::read('temp_audio_nanogong'); + if (!empty(isset($tempAudio)) && is_file($tempAudio)) { + unlink($tempAudio); + Session::erase('temp_audio_nanogong'); } } diff --git a/main/inc/lib/myspace.lib.php b/main/inc/lib/myspace.lib.php index 5a5935d22d..c590dd24b7 100644 --- a/main/inc/lib/myspace.lib.php +++ b/main/inc/lib/myspace.lib.php @@ -1,6 +1,7 @@ '; echo ''; - if (!isset($_SESSION['notebook_view']) || - !in_array($_SESSION['notebook_view'], array('creation_date', 'update_date', 'title')) - ) { - $_SESSION['notebook_view'] = 'creation_date'; + $notebookView = Session::read('notebook_view'); + + if (!in_array($notebookView, array('creation_date', 'update_date', 'title'))) { + Session::write('notebook_view', 'creation_date'); } // Database table definition $t_notebook = Database::get_course_table(TABLE_NOTEBOOK); - if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') { - $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction "; + if ($notebookView == 'creation_date' || $notebookView == 'update_date') { + $order_by = " ORDER BY ".$notebookView." $sort_direction "; } else { - $order_by = " ORDER BY ".$_SESSION['notebook_view']." $sort_direction "; + $order_by = " ORDER BY ".$notebookView." $sort_direction "; } //condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); - $cond_extra = ($_SESSION['notebook_view'] == 'update_date') ? " AND update_date <> ''" : " "; + $cond_extra = $notebookView == 'update_date' ? " AND update_date <> ''" : " "; $course_id = api_get_course_int_id(); $sql = "SELECT * FROM $t_notebook diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index cdb014fe67..b198d9a1b3 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -1,6 +1,7 @@ items[$oLP->current]; if (!is_object($oItem)) { diff --git a/main/lp/download.php b/main/lp/download.php index 46ae6fa8e2..7b7e11192d 100755 --- a/main/lp/download.php +++ b/main/lp/download.php @@ -35,7 +35,6 @@ if ($_SESSION['oLP']) { $lp_item_id = $_SESSION['oLP']->current; $lp_item_info = new learnpathItem($lp_item_id); if (!empty($lp_item_info)) { - //if (basename($lp_item_info->path) == basename($doc_url)) { $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id); if ($visible) {