Skip to content

Commit

Permalink
Remove Session::read('message'); use Display::addFlash
Browse files Browse the repository at this point in the history
Flashes  now works when using Display::display_header
  • Loading branch information
jmontoyaa committed Jul 22, 2016
1 parent b5158a1 commit 917ab67
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 136 deletions.
10 changes: 3 additions & 7 deletions main/admin/configure_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin
*/
use \ChamiloSession as Session;

$cidReset = true;
require_once '../inc/global.inc.php';
Expand All @@ -24,10 +23,7 @@
}

global $_configuration;

$message = '';
$content = '';

$currentUrl = api_get_self() . "?name=$pluginName";

if (isset($pluginInfo['settings_form'])) {
Expand All @@ -46,7 +42,9 @@
$content .= $form->toHtml();
}
} else {
$message = Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning');
Display::addFlash(
Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning')
);
}

if (isset($form)) {
Expand Down Expand Up @@ -108,8 +106,6 @@
);

$tpl = new Template($pluginName, true, true, false, true, false);
$tpl->assign('message', '');
$tpl->assign('content', $content);
$tpl->display_one_col_template();

Session::erase('message');
15 changes: 6 additions & 9 deletions main/admin/skill_list.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* Skill list for management
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin
*/
use ChamiloSession as Session;

$cidReset = true;

Expand All @@ -27,7 +29,7 @@
switch ($action) {
case 'enable':
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);

if (is_null($skill)) {
Display::addFlash(
Display::return_message(
Expand Down Expand Up @@ -60,7 +62,7 @@
break;
case 'disable':
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);

if (is_null($skill)) {
Display::addFlash(
Display::return_message(
Expand All @@ -81,7 +83,7 @@

$skillObj = new Skill();
$childrens = $skillObj->get_children($skill->getId());

foreach ($childrens as $children) {
$skill = $entityManager->find(
'ChamiloCoreBundle:Skill',
Expand Down Expand Up @@ -116,8 +118,6 @@
default:
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));

$message = Session::has('message') ? Session::read('message') : null;

$toolbar = Display::toolbarButton(
get_lang('CreateSkill'),
api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
Expand Down Expand Up @@ -157,7 +157,6 @@
/* View */
$skill = new Skill();
$skillList = $skill->get_all();

$extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;

if ($extraFieldSearchTagId) {
Expand All @@ -173,7 +172,6 @@
}

$tpl = new Template(get_lang('ManageSkills'));
$tpl->assign('message', $message);
$tpl->assign('skills', $skillList);
$tpl->assign('current_tag_id', $extraFieldSearchTagId);
$tpl->assign('tags', $tags);
Expand All @@ -184,6 +182,5 @@
$tpl->assign('content', $content);
$tpl->display_one_col_template();

Session::erase('message');
break;
}
43 changes: 14 additions & 29 deletions main/calendar/agenda.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

/**
* @package chamilo.calendar
*/
Expand Down Expand Up @@ -53,8 +51,8 @@ function plus_repeated_event() {
$('#options2').show();
}
});
</script>
";
</script>";


$htmlHeadXtra[] = '<script>
var counter_image = 1;
Expand Down Expand Up @@ -101,17 +99,15 @@ function add_image_form() {
if (!api_is_allowed_to_edit(null, true) && $event_type === 'course') {
api_not_allowed(true);
}
if ($event_type == 'course') {
if ($event_type === 'course') {
$agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().'&type=course';
} else {
$agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?&type='.$event_type;
}
$course_info = api_get_course_info();
$agenda->type = $event_type;

$message = null;
$content = null;

if (api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_agenda') &&
!api_is_anonymous() &&
Expand Down Expand Up @@ -166,7 +162,7 @@ function add_image_form() {
if ($sendEmail) {
$message .= Display::return_message(get_lang('AdditionalMailWasSentToSelectedUsers'), 'confirmation');
}
Session::write('message', $message);
Display::addFlash($message);
header("Location: $agendaUrl");
exit;
} else {
Expand Down Expand Up @@ -220,7 +216,7 @@ function add_image_form() {
);

$message = Display::return_message(get_lang('Updated'), 'confirmation');
Session::write('message', $message);
Display::addFlash($message);
header("Location: $agendaUrl");
exit;
}
Expand Down Expand Up @@ -264,7 +260,7 @@ function add_image_form() {
}

$message = Display::return_message(get_lang('Updated'), 'confirmation');
Session::write('message', $message);
Display::addFlash($message);
header("Location: $agendaUrl");
exit;
} else {
Expand All @@ -274,31 +270,23 @@ function add_image_form() {
case 'importical':
$actionName = get_lang('Import');
$form = $agenda->getImportCalendarForm();
$content = $form->returnForm();

if ($form->validate()) {
$ical_name = $_FILES['ical_import']['name'];
$ical_type = $_FILES['ical_import']['type'];
$ext = substr($ical_name, (strrpos($ical_name, ".") + 1));

if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
$result = $agenda->importEventFile($course_info, $_FILES['ical_import']);
$is_ical = true;
if (in_array($ext, ['ics', 'ical', 'icalendar', 'ifb'])) {
$content = $agenda->importEventFile($course_info, $_FILES['ical_import']);
$message = Display::return_message(get_lang('AddSuccess'));
} else {
$is_ical = false;
}

if (!$is_ical) {
$message = Display::return_message(get_lang('IsNotiCalFormatFile'), 'error');
$form = $agenda->getImportCalendarForm();
$content = $form->return_form();
break;
} else {
$message = Display::return_message(get_lang('AddSuccess'), 'error');
$content = $result;
}
Session::write('message', $message);
Display::addFlash($message);
$url = api_get_self().'?action=importical&type='.$agenda->type;
header("Location: $url");
exit;
}
$content = $form->returnForm();
break;
case "delete":
if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $eventId) )) {
Expand Down Expand Up @@ -330,9 +318,6 @@ function add_image_form() {
// Tool introduction
$introduction = Display::return_introduction_section(TOOL_CALENDAR_EVENT);

$message = Session::read('message');
Session::erase('message');

$tpl = new Template($actionName);
$tpl->assign('content', $content);
$tpl->assign('actions', $actions);
Expand Down
5 changes: 0 additions & 5 deletions main/calendar/agenda_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@
// Loading Agenda template.
$content = $tpl->fetch('default/agenda/month.tpl');

$message = Session::read('message');
$tpl->assign('message', $message);

Session::erase('message');

$tpl->assign('content', $content);

// Loading main Chamilo 1 col template
Expand Down
95 changes: 52 additions & 43 deletions main/exercise/hotpotatoes_exercise_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
case 'delete':
$fileToDelete = isset($_GET['id']) ? $_GET['id'] : null;
deleteAttempt($fileToDelete);
Session::write('message', Display::return_message(get_lang('ItemDeleted')));
Display::addFlash(Display::return_message(get_lang('ItemDeleted')));
$url = api_get_self().'?'.api_get_cidreq().'&path='.$hotpotatoes_path;
header("Location: $url");
exit;
Expand All @@ -113,41 +113,39 @@
}

Display :: display_header($nameTools);

$actions = Display::div($actions, array('class'=> 'actions'));

$extra = '<script type="text/javascript">
$(document).ready(function() {
$extra = '<script>
$(document).ready(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
autoOpen: false,
show: "blind",
resizable: false,
height:300,
modal: true
});
$("#export_opener").click(function() {
var targetUrl = $(this).attr("href");
$( "#dialog-confirm" ).dialog({
autoOpen: false,
show: "blind",
resizable: false,
height:300,
modal: true
});
$("#export_opener").click(function() {
var targetUrl = $(this).attr("href");
$( "#dialog-confirm" ).dialog({
width:400,
height:300,
buttons: {
"'.addslashes(get_lang('Download')).'": function() {
var export_format = $("input[name=export_format]:checked").val();
var extra_data = $("input[name=load_extra_data]:checked").val();
location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
$( this ).dialog( "close" );
}
width:400,
height:300,
buttons: {
"'.addslashes(get_lang('Download')).'": function() {
var export_format = $("input[name=export_format]:checked").val();
var extra_data = $("input[name=load_extra_data]:checked").val();
location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
$( this ).dialog( "close" );
}
});
$( "#dialog-confirm" ).dialog("open");
return false;
}
});
$( "#dialog-confirm" ).dialog("open");
return false;
});
</script>';
});
</script>';

$extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
$form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
Expand Down Expand Up @@ -193,14 +191,28 @@

// Column config
// @todo fix search firstname/lastname that doesn't work. rmove search for the moment
$column_model = array(
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'50', 'align'=>'left', 'formatter'=>'action_formatter', 'search' => 'false'),
array('name'=>'login', 'hidden'=>'true', 'index'=>'username', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
array('name'=>'group_name', 'index'=>'group_id', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'false'),
array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false')
$column_model = array(
array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'false'),
array(
'name' => 'lastname',
'index' => 'lastname',
'width' => '50',
'align' => 'left',
'formatter' => 'action_formatter',
'search' => 'false',
),
array(
'name' => 'login',
'hidden' => 'true',
'index' => 'username',
'width' => '40',
'align' => 'left',
'search' => 'false',
),
array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'),
array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'),
);

$action_links = '
Expand All @@ -223,10 +235,10 @@ function action_formatter(cellvalue, options, rowObject) {

//Column config
// @todo fix search firstname/lastname that doesn't work. rmove search for the moment
$column_model = array(
array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'false'),
array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false')
$column_model = array(
array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'),
);
}

Expand Down Expand Up @@ -313,8 +325,5 @@ function exportExcel() {
</form>
<?php

$showMessage = Session::read('message');
Session::erase('message');
echo isset($showMessage) ? $showMessage : null;
echo Display::grid_html('results');
Display :: display_footer();
2 changes: 1 addition & 1 deletion main/inc/lib/agenda.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ public function getImportCalendarForm()
$form = new FormValidator(
'frm_import_ical',
'post',
api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&type='.$this->type,
api_get_self().'?action=importical&type='.$this->type,
array('enctype' => 'multipart/form-data')
);
$form->addElement('header', get_lang('ICalFileImport'));
Expand Down
1 change: 0 additions & 1 deletion main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,6 @@ function api_display_tool_view_option() {
$sourceurl = api_get_self().'?'.api_get_cidreq();
} else {
$sourceurl = $_SERVER['REQUEST_URI'];
//$sourceurl = str_replace('&', '&amp;', $sourceurl);
}
}

Expand Down
Loading

0 comments on commit 917ab67

Please sign in to comment.