Browse Source

Fixing PHP warnings during installation.

Julio Montoya 11 years ago
parent
commit
bda73ed454

+ 5 - 8
main/inc/global.inc.php

@@ -224,12 +224,13 @@ $app['template.load_plugins'] = true;
 
 $app['configuration'] = $_configuration;
 
-/** Including service providers */
-require_once 'services.php';
 
 $_plugins = array();
 if ($alreadyInstalled) {
 
+    /** Including service providers */
+    require_once 'services.php';
+
     // Setting the static database class
     $database = $app['database'];
 
@@ -325,6 +326,8 @@ require_once $libPath.'internationalization.lib.php';
 require_once $libPath.'internationalization_internal.lib.php';
 
 // Checking if we have a valid language. If not we set it to the platform language.
+$cidReset = null;
+
 if ($alreadyInstalled) {
     // Setting languages
     $app['api_get_languages'] = api_get_languages();
@@ -336,12 +339,6 @@ if ($alreadyInstalled) {
     // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
     api_set_internationalization_default_encoding($charset);
 
-    // include the local (contextual) parameters of this course or section
-    $cidReset = isset($cidReset) ? Database::escape_string($cidReset) : '';
-
-    // $cidReset can be set in URL-parameter
-    $cidReset = (isset($_GET['cidReq']) && ((isset($_SESSION['_cid']) && $_GET['cidReq'] != $_SESSION['_cid']) || (!isset($_SESSION['_cid'])))) ? Database::escape_string($_GET["cidReq"]) : $cidReset;
-
     // require $includePath.'/local.inc.php';
 
     // reconfigure template now we know the user

+ 8 - 5
main/inc/lib/template.lib.php

@@ -923,20 +923,23 @@ class Template
         $navigation = array();
 
         // Campus Homepage
-        $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
+        $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PUBLIC_PATH).'index';
         $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
 
         // My Courses
-
+        /*
         if (api_is_allowed_to_create_course()) {
             // Link to my courses for teachers
-            $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
+            $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'user_portal.php?nosession=true';
             $navigation['mycourses']['title'] = get_lang('MyCourses');
         } else {
             // Link to my courses for students
-            $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php';
+            $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'user_portal.php';
             $navigation['mycourses']['title'] = get_lang('MyCourses');
-        }
+        }*/
+
+        $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'userportal';
+        $navigation['mycourses']['title'] = get_lang('MyCourses');
 
         // My Profile
         $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&courseCode='.$_course['official_code'] : '');

+ 72 - 39
main/inc/routes.php

@@ -361,16 +361,6 @@ $userPermissionsInsideACourse = function (Request $request) use ($app) {
     }
 };
 
-/**
- * Removes course-session data
- * @param Request $request
- */
-$cleanCourseSession = function (Request $request) use ($app) {
-    Session::erase('_cid');
-    Session::erase('_real_cid');
-    Session::erase('_course');
-};
-
 $adminAndQuestionManagerCondition = function (Request $request) use ($app) {
     if (!(api_is_platform_admin() || api_is_question_manager())) {
         //$app->abort(401);
@@ -398,53 +388,92 @@ $afterLogin = function (Request $request) use ($app) {
     }
 };
 
-/** Legacy controller */
-$app->match('/', 'legacy.controller:classicAction', 'GET|POST')
-    ->before($userAccessConditions)
-    ->before($settingCourseConditions)
-    ->before($userPermissionsInsideACourse);
-
 $checkLangs = function (Request $request) use ($app) {
     /*$file = $request->get('file');
-    $info = pathinfo($file);
-    $section = $info['dirname'];*/
+
+    if (!empty($file )) {
+        $info = pathinfo($file);
+        $section = $info['dirname'];
+    }*/
 };
 
-/** main files */
-$app->match('/main/{file}', 'legacy.controller:includeAction', 'GET|POST')
-    ->before($checkLangs)
-    ->before(
-        function() use ($app) {
-            // Do not load breadcrumbs
-            $app['template']->loadBreadcrumb = false;
-        })
-    ->assert('file', '.+')
-    ->assert('type', '.+');
 
+$removeCidReset = function (Request $request) use ($app) {
+    $file = $request->get('file');
+    if (!empty($file)) {
+        $info = pathinfo($file);
+        $section = $info['dirname'];
+
+        if ($section == 'admin') {
+
+            Session::erase('_cid');
+            Session::erase('_real_cid');
+            Session::erase('_course');
+
+            if (!empty($_SESSION)) {
+                foreach ($_SESSION as $key => $item) {
+                    if (strpos($key, 'lp_autolunch_') === false) {
+                        continue;
+                    } else {
+                        if (isset($_SESSION[$key])) {
+                            Session::erase($key);
+                        }
+                    }
+                }
+            }
+
+            // Deleting session info.
+
+            Session::erase('id_session');
+            Session::erase('session_name');
+
+            // Deleting group info.
+            Session::erase('_gid');
+        }
+    }
+};
+
+/** / and /index paths */
+$app->match('/', 'index.controller:indexAction', 'GET')
+    ->assert('type', '.+') //allowing slash "/"
+    ->before($removeCidReset)
+    ->after($afterLogin);
 
-/** web/index */
-$app->match('/index', 'index.controller:indexAction', 'GET|POST')
+$app->match('/index', 'index.controller:indexAction', 'GET')
+    ->before($removeCidReset)
     ->after($afterLogin)
     ->bind('index');
 
 /** Userportal */
-$app->get('/userportal', 'userPortal.controller:indexAction');
+$app->get('/userportal', 'userPortal.controller:indexAction')
+    ->before($removeCidReset);
+
 $app->get('/userportal/{type}/{filter}/{page}', 'userPortal.controller:indexAction')
+    ->before($removeCidReset)
     ->value('type', 'courses') //default values
     ->value('filter', 'current')
     ->value('page', '1')
-    ->bind('userportal')
-    ->after($cleanCourseSession);
+    ->bind('userportal');
 
-//->assert('type', '.+'); //allowing slash "/"
+/** main files */
+$app->match('/main/{file}', 'legacy.controller:classicAction', 'GET|POST')
+    ->before($checkLangs)
+    ->before($removeCidReset)
+    ->before(
+        function() use ($app) {
+            // Do not load breadcrumbs
+            $app['template']->loadBreadcrumb = false;
+        })
+    ->assert('file', '.+')
+    ->assert('type', '.+');
 
-/** Logout */
+/** Logout already implemented by the the security service provider */
 
-$app->get('/logout', 'index.controller:logoutAction')
+/* $app->get('/logout', 'index.controller:logoutAction')
     ->bind('logout')
-    ->after($cleanCourseSession);
+    ->after($cleanCourseSession);*/
 
-/** Login */
+/** Login form */
 $app->match('/login', 'index.controller:loginAction', 'GET|POST')
     ->bind('login');
 
@@ -755,11 +784,15 @@ $app->match('/admin/administrator/question_scores/{id}/delete', 'question_score.
     ->assert('type', '.+')
     ->bind('admin_administrator_question_score_delete');
 
+/*new \ChamiloLMS\Controller\TestController($app);
+new \ChamiloLMS\Controller\TestController($app);*/
+
+
 // Takes a lot of time to load
 //$app->mount('/roles', 'exercise_manager.controller:getProvider');
 
 // Takes a lot of time to load
-//$app->mount('/roles', new ChamiloLMS\Provider\ReflectionControllerProvider('role.controller'));
+///$app->mount('/roles', new ChamiloLMS\Provider\ReflectionControllerProvider('role.controller'));
 
 $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
     ->assert('type', '.+')

+ 0 - 31
src/ChamiloLMS/Controller/CommonController.php

@@ -23,37 +23,6 @@ class CommonController
 
     }
 
-    /**
-     * Reset course session
-     */
-    public function cidReset()
-    {
-        Session::erase('_cid');
-        Session::erase('_real_cid');
-        Session::erase('_course');
-
-        if (!empty($_SESSION)) {
-            foreach ($_SESSION as $key => $item) {
-                if (strpos($key, 'lp_autolunch_') === false) {
-                    continue;
-                } else {
-                    if (isset($_SESSION[$key])) {
-                        Session::erase($key);
-                    }
-                }
-            }
-        }
-        // Deleting session info.
-        if (api_get_session_id()) {
-            Session::erase('id_session');
-            Session::erase('session_name');
-        }
-        // Deleting group info.
-        if (api_get_group_id()) {
-            Session::erase('_gid');
-        }
-    }
-
     /**
      * @param Application $app
      * @param array $breadcrumbs

+ 0 - 2
src/ChamiloLMS/Controller/IndexController.php

@@ -38,8 +38,6 @@ class IndexController extends CommonController
      */
     public function indexAction(Application $app)
     {
-        $this->cidReset();
-
         /** @var \Template $template */
         $template = $app['template'];
         $loginError = $app['request']->get('error');

+ 6 - 9
src/ChamiloLMS/Controller/LegacyController.php

@@ -26,7 +26,7 @@ class LegacyController extends CommonController
      *
      * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|void
      */
-    public function classicAction(Application $app)
+    /*public function classicAction(Application $app)
     {
         // User is not allowed.
         if ($app['allowed'] == false) {
@@ -44,7 +44,7 @@ class LegacyController extends CommonController
         }
 
         return new Response($response, 200, array());
-    }
+    }*/
 
      /**
      * Handles default Chamilo scripts handled by Display::display_header() and display_footer()
@@ -53,7 +53,7 @@ class LegacyController extends CommonController
      *
      * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|void
      */
-    public function includeAction(Application $app, $file)
+    public function classicAction(Application $app, $file)
     {
         /** @var  Request $request */
         $request = $app['request'];
@@ -67,15 +67,12 @@ class LegacyController extends CommonController
         //$_REQUEST = $request->request->all();
 
         // Getting language section
-        $info = pathinfo($file);
-        $section = $info['dirname'];
-
-        if ($section == 'admin') {
-            $this->cidReset();
-        }
+        /*$info = pathinfo($file);
+        $section = $info['dirname'];*/
 
         $mainPath = $app['paths']['sys_root'].'main/';
 
+
         if (is_file($mainPath.$file)) {
 
             // Default values

+ 1 - 3
src/ChamiloLMS/Controller/UserPortalController.php

@@ -25,9 +25,7 @@ class UserPortalController extends CommonController
      */
     public function indexAction(Application $app, $type = 'courses', $filter = 'current', $page = 1)
     {
-        $this->cidReset();
-
-        //@todo Use filters like "after/before|finish" to manage user access
+        // @todo Use filters like "after/before|finish" to manage user access
         api_block_anonymous_users();
 
         //Abort request because the user is not allowed here - @todo use filters