From b2fb1b880070ad4ee8e65da2cc5ad57a5cfd8969 Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Fri, 24 Oct 2014 10:30:00 -0500 Subject: [PATCH] Add comments. Fix french translation. Change redirection process to a much cleaner one. - refs #7272 --- main/inc/lib/plugin.class.php | 10 ++++++---- plugin/buycourses/lang/french.php | 2 +- plugin/buycourses/src/buy_course.lib.php | 6 +++--- plugin/buycourses/src/index.buycourses.php | 7 ++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/main/inc/lib/plugin.class.php b/main/inc/lib/plugin.class.php index 6982890b6a..d25c19acc9 100755 --- a/main/inc/lib/plugin.class.php +++ b/main/inc/lib/plugin.class.php @@ -645,15 +645,17 @@ class Plugin /** * This method shows or hides plugin's tab * @param boolean Shows or hides the main menu plugin tab + * @param string Plugin starter file path */ - public function manageTab($showTab) + public function manageTab($showTab, $filePath = 'index.php') { $langString = str_replace('Plugin', '', get_class($this)); $pluginName = strtolower($langString); - $pluginUrl = 'plugin/'.$pluginName.'/index.php'; + $pluginUrl = 'plugin/'.$pluginName.'/'.$filePath; if ($showTab === 'true') { - $rsTab = $this->addTab($this->get_lang($langString), $pluginUrl); - if ($rsTab) { + $tabAdded = $this->addTab($this->get_lang($langString), $pluginUrl); + if ($tabAdded) { + // The page must be refreshed to show the recently created tab echo ""; } } else { diff --git a/plugin/buycourses/lang/french.php b/plugin/buycourses/lang/french.php index 9d2775c412..97c20312dc 100644 --- a/plugin/buycourses/lang/french.php +++ b/plugin/buycourses/lang/french.php @@ -2,7 +2,7 @@ $strings['plugin_title'] = "Vente de cours"; $strings['plugin_comment'] = "Vendez vos cours directement depuis votre portail Chamilo, au travers d'un compte PayPal. Plugin en version beta, à utiliser avec précaution. Ni l'association Chamilo ni les développeurs impliqués dans le développement de ce plugin ne sauraient être tenus responsables d'un quelconque inconvénient causé par celui-ci."; $strings['show_main_menu_tab'] = "Montrer l'onglet dans le menu principal"; -$strings['show_main_menu_tab_help'] = "Dans le cas où l'onglet ne se montre pas, il est possible de rajouter le lien suivant à votre portail Chamilo: %s"; +$strings['show_main_menu_tab_help'] = "Dans le cas où vous ne souhaitez pas montrer l'onglet, il est possible de rajouter le lien suivant à votre portail Chamilo: %s"; $strings['Visible'] = "Montrer dans la liste"; $strings['Options'] = "Options"; $strings['Price'] = "Prix"; diff --git a/plugin/buycourses/src/buy_course.lib.php b/plugin/buycourses/src/buy_course.lib.php index 2a030e12b6..e3eb0b6a13 100644 --- a/plugin/buycourses/src/buy_course.lib.php +++ b/plugin/buycourses/src/buy_course.lib.php @@ -196,8 +196,8 @@ function userSessionList() //check if the user is enrolled in the current session if ($currentUserId > 0) { $sql = "SELECT 1 FROM $tableSessionRelUser - WHERE id_session='".$rowSession['session_id']."' AND - id_user ='" . $currentUserId . "';"; + WHERE id_session ='".$rowSession['session_id']."' AND + id_user = $currentUserId"; Database::query($sql); if (Database::affected_rows() > 0) { $rowSession['enrolled'] = "YES"; @@ -521,7 +521,7 @@ function sessionInfo($code) //check if the user is enrolled in the current session if ($currentUserId > 0) { $sql = "SELECT 1 FROM $tableSessionRelUser - WHERE id_user='".$currentUserId."';"; + WHERE id_user = $currentUserId"; Database::query($sql); if (Database::affected_rows() > 0) { $rowSession['enrolled'] = "YES"; diff --git a/plugin/buycourses/src/index.buycourses.php b/plugin/buycourses/src/index.buycourses.php index 81091e6b49..780b757ef9 100644 --- a/plugin/buycourses/src/index.buycourses.php +++ b/plugin/buycourses/src/index.buycourses.php @@ -11,11 +11,12 @@ $plugin = BuyCoursesPlugin::create(); $guess_enable = $plugin->get('unregistered_users_enable'); if ($guess_enable == "true" || isset($_SESSION['_user'])) { + $isAdmin = api_is_platform_admin(); $title = $plugin->get_lang('CourseListOnSale'); $templateName = $plugin->get_lang('BuyCourses'); $tpl = new Template($templateName); - $tpl->assign('isAdmin', api_is_platform_admin()); + $tpl->assign('isAdmin', $isAdmin); $tpl->assign('title', $title); $tpl->assign('BuySessions', $plugin->get_lang('BuySessions')); $tpl->assign('BuyCourses', $templateName); @@ -26,6 +27,6 @@ if ($guess_enable == "true" || isset($_SESSION['_user'])) { $listing_tpl = 'buycourses/view/index.tpl'; $content = $tpl->fetch($listing_tpl); $tpl->assign('content', $content); - preg_match_all('/src\/.*\.php/', $content, $matches); - count($matches[0]) > 1 ? $tpl->display_one_col_template() : header('Location: '.$matches[0][0]); + // If the user is NOT an administrator, redirect it to course/session buy list + $isAdmin ? $tpl->display_one_col_template() : header('Location: src/list.php'); }