Skip to content

Commit

Permalink
Remove use of $_SESSION
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Aug 31, 2017
1 parent 9cc9903 commit 7412d55
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 47 deletions.
4 changes: 3 additions & 1 deletion main/social/home.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @package chamilo.social
* @author Julio Montoya <gugli100@gmail.com>
Expand All @@ -15,7 +17,7 @@
$show_full_profile = true;
// social tab
$this_section = SECTION_SOCIAL;
unset($_SESSION['this_section']);
Session::erase('this_section');

api_block_anonymous_users();

Expand Down
6 changes: 4 additions & 2 deletions main/social/myfiles.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @author Juan Carlos Trabado herodoto@telefonica.net
* @package chamilo.social
Expand Down Expand Up @@ -80,13 +82,13 @@ function register_friend(element_input) {
}

if (api_get_setting('allow_social_tool') == 'true') {
$_SESSION['this_section'] = SECTION_SOCIAL;
Session::write('this_section', SECTION_SOCIAL);
$interbreadcrumb[] = array(
'url' => 'profile.php',
'name' => get_lang('SocialNetwork')
);
} else {
$_SESSION['this_section'] = SECTION_COURSES;
Session::write('this_section', SECTION_COURSES);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_PATH).'user_portal.php',
'name' => get_lang('MyCourses')
Expand Down
58 changes: 25 additions & 33 deletions main/survey/fillsurvey.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @package chamilo.survey
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
Expand Down Expand Up @@ -138,12 +140,12 @@
}

$survey_invitation = Database::fetch_array($result, 'ASSOC');

$surveyUserFromSession = Session::read('surveyuser');
// Now we check if the user already filled the survey
if (!isset($_POST['finish_survey']) &&
(
$isAnonymous &&
isset($_SESSION['surveyuser']) &&
!empty($surveyUserFromSession) &&
SurveyUtil::isSurveyAnsweredFlagged($survey_invitation['survey_code'], $survey_invitation['c_id'])
) ||
($survey_invitation['answered'] == 1 && !isset($_GET['user_id']))
Expand Down Expand Up @@ -517,8 +519,8 @@
// Displaying the survey introduction
if (!isset($_GET['show'])) {
// The first thing we do is delete the session
unset($_SESSION['paged_questions']);
unset($_SESSION['page_questions_sec']);
Session::erase('paged_questions');
Session::erase('page_questions_sec');
$paged_questions_sec = array();

if (!empty($survey_data['survey_introduction'])) {
Expand Down Expand Up @@ -573,14 +575,14 @@
$_GET['show'] = 0;
$show = 0;
// We unset the sessions
unset($_SESSION['paged_questions']);
unset($_SESSION['page_questions_sec']);
Session::erase('paged_questions');
Session::erase('page_questions_sec');
$paged_questions_sec = array();
} else {
echo '<div id="survey_content" class="survey_content">'.get_lang('UpdateInformation').'</div>';
// We unset the sessions
unset($_SESSION['paged_questions']);
unset($_SESSION['page_questions_sec']);
Session::erase('paged_questions');
Session::erase('page_questions_sec');
$paged_questions_sec = array();
$form->display();
}
Expand Down Expand Up @@ -610,8 +612,8 @@
);
}

unset($_SESSION['paged_questions']);
unset($_SESSION['page_questions_sec']);
Session::erase('paged_questions');
Session::erase('page_questions_sec');
Display::display_footer();
exit();
}
Expand All @@ -628,11 +630,10 @@
// As long as there is no pagebreak fount we keep adding questions to the page
$questions_displayed = array();
$counter = 0;
$paged_questions = array();

$paged_questions = Session::read('paged_questions');
// If non-conditional survey
if ($survey_data['survey_type'] === '0') {
if (empty($_SESSION['paged_questions'])) {
if (empty($paged_questions)) {
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
Expand All @@ -647,21 +648,19 @@
$paged_questions[$counter][] = $row['question_id'];
}
}
$_SESSION['paged_questions'] = $paged_questions;
} else {
$paged_questions = $_SESSION['paged_questions'];
Session::write('paged_questions', $paged_questions);
}

// Redefinition of variables and session ids to fix issue of survey not
// showing questions - see support.chamilo.org #5529
$course_id = $survey_invitation['c_id'];
$_SESSION['_cid'] = $course_id;
$_SESSION['_real_cid'] = $course_id;
Session::write('_cid', $course_id);
Session::write('_real_cid', $course_id);

if (array_key_exists($_GET['show'], $paged_questions)) {
if (isset($_GET['user_id'])) {
// Get the user into survey answer table (user or anonymus)
$my_user_id = ($survey_data['anonymous'] == 1) ? $_SESSION['surveyuser'] : api_get_user_id();
$my_user_id = ($survey_data['anonymous'] == 1) ? $surveyUserFromSession : api_get_user_id();

$sql = "SELECT
survey_question.survey_group_sec1,
Expand Down Expand Up @@ -924,7 +923,6 @@
// We only get highest 3
$secondary = '';
$combi = '';

for ($i = 0; $i <= $group_cant; $i++) {
$group1 = $groups[$i];
$group2 = $groups[$i + 1];
Expand All @@ -946,12 +944,6 @@
}
}
}
/*
echo '<pre>';
echo 'Pair of Groups <br /><br />';
echo $combi;
echo '</pre>';
*/
// Create the new select with the questions from the secondary phase
if (empty($_SESSION['page_questions_sec']) &&
!is_array($_SESSION['page_questions_sec']) &&
Expand All @@ -976,11 +968,11 @@
$paged_questions_sec[$counter][] = $row['question_id'];
}
}
$_SESSION['paged_questions_sec'] = $paged_questions_sec;
Session::write('page_questions_sec', $paged_questions_sec);
} else {
$paged_questions_sec = $_SESSION['paged_questions_sec'];
$paged_questions_sec = Session::read('page_questions_sec');
}
$paged_questions = $_SESSION['paged_questions']; // For the sake of pages counting
$paged_questions = Session::read('paged_questions'); // For the sake of pages counting
//$paged_questions = $paged_questions_sec; // For the sake of pages counting coming up at display time...
if ($shuffle == '') {
$shuffle = ' BY survey_question.sort, survey_question_option.sort ASC ';
Expand Down Expand Up @@ -1053,7 +1045,7 @@
}
} else {
// We need this variable only in the 2nd set of questions when personality is set.
unset($_SESSION['page_questions_sec']);
Session::erase('page_questions_sec');
$paged_questions_sec = array();

// Only the questions from the basic group
Expand Down Expand Up @@ -1086,9 +1078,9 @@
}
}
}
$_SESSION['paged_questions'] = $paged_questions;
Session::write('paged_questions', $paged_questions);
} else {
$paged_questions = $_SESSION['paged_questions'];
$paged_questions = Session::read('paged_questions');
}
$order_sql = $shuffle;
if ($shuffle == '') {
Expand Down Expand Up @@ -1320,7 +1312,7 @@
$numberofpages += count($paged_questions_sec);
} else {
// We need this variable only if personality == 1
unset($_SESSION['page_questions_sec']);
Session::erase('page_questions_sec');
$paged_questions_sec = array();
}

Expand Down
8 changes: 5 additions & 3 deletions main/survey/surveyUtil.class.php
Expand Up @@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */

use Chamilo\CourseBundle\Entity\CSurvey;
use ChamiloSession as Session;

/**
* This class offers a series of general utility functions for survey querying and display
Expand Down Expand Up @@ -106,11 +107,12 @@ public static function store_answer(

// Make the survey anonymous
if ($survey_data['anonymous'] == 1) {
if (!isset($_SESSION['surveyuser'])) {
$surveyUser = Session::read('surveyuser');
if (empty($surveyUser)) {
$user = md5($user.time());
$_SESSION['surveyuser'] = $user;
Session::write('surveyuser', $user);
} else {
$user = $_SESSION['surveyuser'];
$user = Session::read('surveyuser');
}
}

Expand Down
2 changes: 1 addition & 1 deletion main/ticket/categories.php
Expand Up @@ -24,7 +24,7 @@
$isAdmin = api_is_platform_admin();

$this_section = 'tickets';
unset($_SESSION['this_section']);
Session::erase('this_section');

$table = new SortableTable(
'TicketCategories',
Expand Down
4 changes: 3 additions & 1 deletion main/ticket/priorities.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* This script is the Tickets plugin main entry point
* @package chamilo.plugin.ticket
Expand All @@ -18,7 +20,7 @@
$webLibPath = api_get_path(WEB_LIBRARY_PATH);

$this_section = 'tickets';
unset($_SESSION['this_section']);
Session::erase('this_section');

$table = new SortableTable(
'TicketProject',
Expand Down
4 changes: 3 additions & 1 deletion main/ticket/projects.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* This script is the Tickets plugin main entry point
* @package chamilo.plugin.ticket
Expand All @@ -16,7 +18,7 @@
$webLibPath = api_get_path(WEB_LIBRARY_PATH);

$this_section = 'tickets';
unset($_SESSION['this_section']);
Session::erase('this_section');

$table = new SortableTable(
'TicketProject',
Expand Down
4 changes: 3 additions & 1 deletion main/ticket/report.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @package chamilo.plugin.ticket
*/
Expand All @@ -15,7 +17,7 @@
}

$this_section = 'Reports';
unset($_SESSION['this_section']);
Session::erase('this_section');

$htmlHeadXtra[] = '<script>
$(document).ready(function(){
Expand Down
4 changes: 3 additions & 1 deletion main/ticket/status.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* This script is the Tickets plugin main entry point
* @package chamilo.plugin.ticket
Expand All @@ -18,7 +20,7 @@
$webLibPath = api_get_path(WEB_LIBRARY_PATH);

$this_section = 'tickets';
unset($_SESSION['this_section']);
Session::erase('this_section');

$table = new SortableTable(
'TicketProject',
Expand Down
4 changes: 3 additions & 1 deletion main/ticket/tickets.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* This script is the Tickets plugin main entry point
* @package chamilo.plugin.ticket
Expand Down Expand Up @@ -51,7 +53,7 @@ function display_advanced_search_form () {
</script>';

$this_section = 'tickets';
unset($_SESSION['this_section']);
Session::erase('this_section');

$action = isset($_GET['action']) ? $_GET['action'] : '';
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
Expand Down
2 changes: 1 addition & 1 deletion main/tracking/courseLog.php
Expand Up @@ -86,7 +86,7 @@

if ($export_csv) {
if (!empty($session_id)) {
$_SESSION['id_session'] = $session_id;
Session::write('id_session', $session_id);
}
ob_start();
}
Expand Down
4 changes: 3 additions & 1 deletion main/tracking/course_log_tools.php
@@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @package chamilo.tracking
*/
Expand Down Expand Up @@ -54,7 +56,7 @@

if ($export_csv) {
if (!empty($session_id)) {
$_SESSION['id_session'] = $session_id;
Session::write('id_session', $session_id);
}
ob_start();
}
Expand Down

0 comments on commit 7412d55

Please sign in to comment.