Fix session messages using addflash function

1.10.x
Julio Montoya 10 years ago
parent 50a50668e7
commit 14a5a5607f
  1. 2
      main/inc/lib/promotion.lib.php
  2. 234
      main/inc/lib/sessionmanager.lib.php
  3. 4
      main/session/session_category_add.php
  4. 7
      main/session/session_category_edit.php
  5. 11
      main/session/session_category_list.php
  6. 11
      main/session/session_import.php
  7. 6
      main/session/session_user_import.php
  8. 4
      tests/phpunit/classes/SessionManager.lib.php

@ -90,7 +90,7 @@ class Promotion extends Model
$new_session_list = array();
foreach($session_list as $item) {
$sid = SessionManager::copy_session($item['id'], true, false, false, true);
$sid = SessionManager::copy($item['id'], true, false, false, true);
$new_session_list[] = $sid;
}

@ -3347,7 +3347,7 @@ class SessionManager
* @return int The new session ID on success, 0 otherwise
* @todo make sure the extra session fields are copied too
*/
public static function copy_session(
public static function copy(
$id,
$copy_courses = true,
$copy_users = true,
@ -6467,7 +6467,7 @@ class SessionManager
* @param string $list_type
* @return array
*/
public static function get_session_columns($list_type = 'simple')
public static function getGridColumns($list_type = 'simple')
{
//Column config
$operators = array('cn', 'nc');
@ -6563,4 +6563,234 @@ class SessionManager
$params['coach_access_end_date'] = isset($params['coach_access_end_date']) ? api_get_local_time($params['coach_access_end_date'], null, null, true) : null;
return $params;
}
/**
* Gets the admin session list callback of the session/session_list.php
* page with all user/details in the right fomat
* @param array
* @result array Array of rows results
* @asset ('a') === false
*/
public static function get_sessions_admin_complete($options = array())
{
if (!is_array($options)) {
return false;
}
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
$tbl_session_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$tbl_session_field_options = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
$where = 'WHERE 1 = 1 ';
$user_id = api_get_user_id();
if (!api_is_platform_admin()) {
if (api_is_session_admin() &&
api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false'
) {
$where.=" AND s.session_admin_id = $user_id ";
}
}
$coach_name = " CONCAT(u.lastname , ' ', u.firstname) as coach_name ";
if (api_is_western_name_order()) {
$coach_name = " CONCAT(u.firstname, ' ', u.lastname) as coach_name ";
}
$today = api_get_utc_datetime();
$inject_extra_fields = null;
$extra_fields = array();
$extra_fields_info = array();
//for now only sessions
$extra_field = new ExtraField('session');
$double_fields = array();
$extra_field_option = new ExtraFieldOption('session');
if (isset($options['extra'])) {
$extra_fields = $options['extra'];
if (!empty($extra_fields)) {
foreach ($extra_fields as $extra) {
$inject_extra_fields .= " IF (fv.field_id = {$extra['id']}, fvo.option_display_text, NULL ) as {$extra['field']} , ";
if (isset($extra_fields_info[$extra['id']])) {
$info = $extra_fields_info[$extra['id']];
} else {
$info = $extra_field->get($extra['id']);
$extra_fields_info[$extra['id']] = $info;
}
if ($info['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
$double_fields[$info['id']] = $info;
}
}
}
}
$options_by_double = array();
foreach ($double_fields as $double) {
$my_options = $extra_field_option->get_field_options_by_field(
$double['id'],
true
);
$options_by_double['extra_'.$double['field_variable']] = $my_options;
}
//sc.name as category_name,
$select = "
SELECT * FROM (
SELECT DISTINCT
IF (
(s.access_start_date <= '$today' AND '$today' < s.access_end_date) OR
(s.access_start_date = '0000-00-00 00:00:00' AND s.access_end_date = '0000-00-00 00:00:00' ) OR
(s.access_start_date IS NULL AND s.access_end_date IS NULL) OR
(s.access_start_date <= '$today' AND ('0000-00-00 00:00:00' = s.access_end_date OR s.access_end_date IS NULL )) OR
('$today' < s.access_end_date AND ('0000-00-00 00:00:00' = s.access_start_date OR s.access_start_date IS NULL) )
, 1, 0) as session_active,
s.name,
s.nbr_courses,
s.nbr_users,
s.display_start_date,
s.display_end_date,
$coach_name,
access_start_date,
access_end_date,
s.visibility,
u.user_id,
$inject_extra_fields
c.title as course_title,
s.id ";
if (!empty($options['where'])) {
if (!empty($options['extra'])) {
$options['where'] = str_replace(' 1 = 1 AND', '', $options['where']);
$options['where'] = str_replace('AND', 'OR', $options['where']);
foreach ($options['extra'] as $extra) {
$options['where'] = str_replace($extra['field'], 'fv.field_id = '.$extra['id'].' AND fvo.option_value', $options['where']);
}
}
$options['where'] = str_replace('course_title', 'c.title', $options['where']);
$where .= ' AND '.$options['where'];
}
if (!empty($options['limit'])) {
$where .= " LIMIT ".$options['limit'];
}
$query = "$select FROM $tbl_session s
LEFT JOIN $tbl_session_field_values fv
ON (fv.item_id = s.id)
LEFT JOIN $extraFieldTable f
ON f.id = fv.field_id
LEFT JOIN $tbl_session_field_options fvo
ON (fv.field_id = fvo.field_id)
LEFT JOIN $tbl_session_rel_course src
ON (src.session_id = s.id)
LEFT JOIN $tbl_course c
ON (src.c_id = c.id)
LEFT JOIN $tbl_session_category sc
ON (s.session_category_id = sc.id)
INNER JOIN $tbl_user u
ON (s.id_coach = u.user_id) ".
$where;
if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select
FROM $tbl_session s
LEFT JOIN $tbl_session_field_values fv ON (fv.session_id = s.id)
LEFT JOIN $tbl_session_field_options fvo ON (fv.field_id = fvo.field_id)
LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id)
LEFT JOIN $tbl_course c ON (src.c_id = c.id)
LEFT JOIN $tbl_session_category sc ON (s.session_category_id = sc.id)
INNER JOIN $tbl_user u ON (s.id_coach = u.user_id)
INNER JOIN $table_access_url_rel_session ar ON (ar.session_id = s.id)
$where";
}
}
$query .= ") AS session_table";
if (!empty($options['order'])) {
$query .= " ORDER BY ".$options['order'];
}
//error_log($query);
//echo $query;
$result = Database::query($query);
$formatted_sessions = array();
if (Database::num_rows($result)) {
$sessions = Database::store_result($result, 'ASSOC');
foreach ($sessions as $session) {
$session_id = $session['id'];
$session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']);
$session['coach_name'] = Display::url($session['coach_name'], "user_information.php?user_id=".$session['user_id']);
if ($session['session_active'] == 1) {
$session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL);
} else {
$session['session_active'] = Display::return_icon('error.png', get_lang('Inactive'), array(), ICON_SIZE_SMALL);
}
$session = self::convert_dates_to_local($session);
switch ($session['visibility']) {
case SESSION_VISIBLE_READ_ONLY: //1
$session['visibility'] = get_lang('ReadOnly');
break;
case SESSION_VISIBLE: //2
case SESSION_AVAILABLE: //4
$session['visibility'] = get_lang('Visible');
break;
case SESSION_INVISIBLE: //3
$session['visibility'] = api_ucfirst(get_lang('Invisible'));
break;
}
//Cleaning double selects
foreach ($session as $key => &$value) {
if (isset($options_by_double[$key]) || isset($options_by_double[$key.'_second'])) {
$options = explode('::', $value);
}
$original_key = $key;
if (strpos($key, '_second') === false) {
} else {
$key = str_replace('_second', '', $key);
}
if (isset($options_by_double[$key])) {
if (isset($options[0])) {
if (isset($options_by_double[$key][$options[0]])) {
if (strpos($original_key, '_second') === false) {
$value = $options_by_double[$key][$options[0]]['option_display_text'];
} else {
$value = $options_by_double[$key][$options[1]]['option_display_text'];
}
}
}
}
}
// Magic filter
if (isset($formatted_sessions[$session_id])) {
$formatted_sessions[$session_id] = self::compare_arrays_to_merge($formatted_sessions[$session_id], $session);
} else {
$formatted_sessions[$session_id] = $session;
}
}
}
return $formatted_sessions;
}
}

@ -46,8 +46,10 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$month_end,
$day_end
);
if ($return == strval(intval($return))) {
header('Location: session_category_list.php?action=show_message&message='.urlencode(get_lang('SessionCategoryAdded')));
Display::addFlash(Display::return_message(get_lang('SessionCategoryAdded')));
header('Location: session_category_list.php');
exit();
}
}

@ -60,11 +60,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$day_end
);
if ($return == strval(intval($return))) {
header(
'Location: session_category_list.php?action=show_message&message=' . urlencode(
get_lang('SessionCategoryUpdate')
)
);
Display::addFlash(Display::return_message(get_lang('SessionCategoryUpdate')));
header('Location: session_category_list.php');
exit();
}
}

@ -40,7 +40,8 @@ $order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) :
if ($action == 'delete_on_session' || $action == 'delete_off_session') {
$delete_session = ($action == 'delete_on_session') ? true : false;
SessionManager::delete_session_category($idChecked, $delete_session);
header('Location: '.api_get_self().'?sort='.$sort.'&action=show_message&message='.urlencode(get_lang('SessionCategoryDelete')));
Display::addFlash(Display::return_message(get_lang('SessionCategoryDelete')));
header('Location: '.api_get_self().'?sort='.$sort);
exit();
}
@ -104,14 +105,6 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
$nbr_results = sizeof($Sessions);
$tool_name = get_lang('ListSessionCategory');
Display::display_header($tool_name);
if (!empty($_GET['warn'])) {
Display::display_warning_message(urldecode($_GET['warn']), false);
}
if (isset($_GET['action'])) {
Display::display_confirmation_message(stripslashes($_GET['message']), false);
}
$keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
?>

@ -13,11 +13,6 @@ api_protect_admin_script(true);
api_protect_limit_for_session_admin();
$form_sent = 0;
$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']);
}
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
@ -517,10 +512,12 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
if ($file_type == 'csv') {
$session_id = current($sessionList);
}
header('Location: resume_session.php?id_session='.$session_id.'&warn='.urlencode($warn));
Display::addFlash(Display::return_message($warn));
header('Location: resume_session.php?id_session='.$session_id);
exit;
} else {
header('Location: session_list.php?action=show_message&message='.urlencode(get_lang('FileImported').' '.$error_message).'&warn='.urlencode($warn));
Display::addFlash(Display::return_message(get_lang('FileImported').' '.$error_message));
header('Location: session_list.php');
exit;
}
} else {

@ -17,12 +17,6 @@ $session_id = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
SessionManager::protectSession($session_id);
$form_sent = 0;
$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']);
}
$tool_name = get_lang('ImportUsers');
//$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));

@ -459,10 +459,10 @@ class SessionManagerTest extends PHPUnit_Framework_TestCase
}
/**
* @covers SessionManager::copy_session
* @covers SessionManager::copy
* @todo Implement testCopy_session().
*/
public function testCopy_session()
public function testCopy()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(

Loading…
Cancel
Save