From 7f85cac35a4439b9875d19f80bfcdbea0d32631e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 14 Nov 2014 09:18:27 +0100 Subject: [PATCH] Adding flash messages see BT#9016 Just add messages using for example: Display::addFlash(Display::return_message(get_lang('Save'), 'warning')); Chamilo will show the message and delete it from the session. So the message will not be shown twice. --- main/inc/lib/display.lib.php | 48 +++++++++++++++++++ main/inc/lib/template.lib.php | 5 +- .../inc/lib/wami-recorder/record_document.php | 8 ++++ main/newscorm/lp_add_audio.php | 23 +++++---- main/template/default/layout/page_body.tpl | 8 ++-- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 196beb7a79..b10ccf6d87 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1,6 +1,8 @@ * @todo better organization of the class, methods and variables * @@ -151,8 +152,6 @@ class Template $this->templateFolder = $defaultStyle; } - - $this->assign('template', $this->templateFolder); $this->assign('css_styles', $this->theme); $this->assign('login_class', null); @@ -965,6 +964,8 @@ class Template */ public function display($template) { + $this->assign('flash_messages', Display::getFlashToString()); + Display::cleanFlashMessages(); echo $this->twig->render($template, $this->params); } diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php index f009343ebf..34375a7518 100755 --- a/main/inc/lib/wami-recorder/record_document.php +++ b/main/inc/lib/wami-recorder/record_document.php @@ -1,6 +1,7 @@ set_modified_on(); $lpItem = new learnpathItem($lpItemId); $lpItem->add_audio_from_documents($newDocId); + Display::addFlash( + Display::return_message(get_lang('Updated'), 'info') + ); } } +} else { + Display::addFlash($contents); } diff --git a/main/newscorm/lp_add_audio.php b/main/newscorm/lp_add_audio.php index d2949272ab..56cdf5dd0e 100755 --- a/main/newscorm/lp_add_audio.php +++ b/main/newscorm/lp_add_audio.php @@ -5,9 +5,6 @@ * @author Julio Montoya - Improving the list of templates * @package chamilo.learnpath */ -/** - * INIT SECTION - */ $this_section = SECTION_COURSES; @@ -54,14 +51,14 @@ $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpa switch ($type) { case 'chapter': - $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep')); - $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter')); + $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep')); + $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter')); break; case 'document': - $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep')); + $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep')); break; default: - $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep')); + $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep')); break; } @@ -76,8 +73,8 @@ if (empty($lp_item_id)) { api_not_allowed(); } +$courseInfo = api_get_course_info(); $lp_item = new learnpathItem($lp_item_id); -$tpl = new Template(null); $form = new FormValidator('add_audio', 'post', api_get_self().'?action=add_audio&id='.$lp_item_id, null, array('enctype' => 'multipart/form-data')); $suredel = trim(get_lang('AreYouSureToDelete')); @@ -85,12 +82,12 @@ $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info()); $file = null; if (isset($lp_item->audio) && !empty($lp_item->audio)) { - $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio; - $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq(); + $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio; + $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq(); if (!file_exists($file)) { - $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio; - $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq(); + $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio; + $urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq(); } } @@ -105,6 +102,8 @@ $page .= ''; $recordVoiceForm = Display::page_subheader(get_lang('RecordYourVoice')); $page .= '
'; + +$tpl = new Template(null); $tpl->assign('unique_file_id', api_get_unique_id()); $tpl->assign('course_code', api_get_course_id()); $tpl->assign('php_session_id', session_id()); diff --git a/main/template/default/layout/page_body.tpl b/main/template/default/layout/page_body.tpl index 01d90d9be1..7ded6a426d 100755 --- a/main/template/default/layout/page_body.tpl +++ b/main/template/default/layout/page_body.tpl @@ -5,16 +5,18 @@
{% endif %} +{{ flash_messages }} + {# Page header #} -{% if header != '' %} +{% if header != '' %} {% endif %} {# Show messages #} -{% if message != '' %} +{% if message != '' %}
{{ message}}
-{% endif %} \ No newline at end of file +{% endif %}