Browse Source

Minor - format code, use php instead of html code

Julio Montoya 6 years ago
parent
commit
3b2bedda22
1 changed files with 165 additions and 170 deletions
  1. 165 170
      main/auth/courses_categories.php

+ 165 - 170
main/auth/courses_categories.php

@@ -20,19 +20,17 @@ $action = in_array($action, $actions) ? $action : 'display_courses';
 
 $showCourses = CoursesAndSessionsCatalog::showCourses();
 $showSessions = CoursesAndSessionsCatalog::showSessions();
-$pageCurrent = isset($pageCurrent) ? $pageCurrent : isset($_GET['pageCurrent']) ? intval($_GET['pageCurrent']) : 1;
-$pageLength = isset($pageLength) ? $pageLength : isset($_GET['pageLength']) ? intval($_GET['pageLength']) : CoursesAndSessionsCatalog::PAGE_LENGTH;
-$pageTotal = intval(ceil(intval($countCoursesInCategory) / $pageLength));
+$pageCurrent = isset($pageCurrent) ? $pageCurrent : isset($_GET['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1;
+$pageLength = isset($pageLength) ? $pageLength : isset($_GET['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH;
+$pageTotal = (int) ceil((int) $countCoursesInCategory / $pageLength);
 $cataloguePagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($pageCurrent, $pageLength, $pageTotal) : '';
 $searchTerm = isset($_REQUEST['search_term']) ? Security::remove_XSS($_REQUEST['search_term']) : '';
 $codeType = isset($_REQUEST['category_code']) ? Security::remove_XSS($_REQUEST['category_code']) : '';
 
+$date = date('Y-m-d');
 if ($showSessions && isset($_POST['date'])) {
     $date = $_POST['date'];
-} else {
-    $date = date('Y-m-d');
 }
-
 $userInfo = api_get_user_info();
 $code = isset($code) ? $code : null;
 
@@ -69,223 +67,220 @@ $code = isset($code) ? $code : null;
 } ?>
     });
 </script>
-<div class="row">
+<?php
+
+echo '<div class="row">
     <div class="col-md-12">
-        <h2 class="title-courses"><?php echo get_lang('CourseManagement'); ?></h2>
+        <h2 class="title-courses">'.get_lang('CourseManagement').'</h2>
         <div class="search-courses">
-            <div class="row">
-<?php if ($showCourses) {
-        ?>
-                    <div class="col-md-<?php echo $showSessions ? '4' : '6'; ?>">
-                        <?php if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) {
-            ?>
-                            <form method="post"
-                                  action="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); ?>">
-                                <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
-                                <input type="hidden" name="search_course" value="1"/>
-                                <label><?php echo get_lang('Search'); ?></label>
-                                <div class="input-group">
-                                    <input class="form-control" type="text" name="search_term"
-                                           value="<?php echo empty($_POST['search_term'])
-                                               ? ''
-                                               : api_htmlentities($searchTerm); ?>"/>
-                                    <div class="input-group-btn">
-                                        <button class="btn btn-default" type="submit">
-                                            <em class="fa fa-search"></em> <?php echo get_lang('Search'); ?>
-                                        </button>
-                                    </div>
-                                </div>
-                            </form>
-                        <?php
-        } ?>
-                    </div>
-                    <div class="col-md-<?php echo $showSessions ? '4' : '6'; ?>">
-<?php
-        $categoriesSelect = '';
-        $cacheAvailable = api_get_configuration_value('apc');
-        $accessUrlId = api_get_current_access_url_id();
-        if ($cacheAvailable === true) {
-            $apcVar = api_get_configuration_value('apc_prefix').'_'.$accessUrlId.'_course_categories_select';
-            if (apcu_exists($apcVar)) {
-                $categoriesSelect = apcu_fetch($apcVar);
-            } else {
-                $categoriesSelect = getOptionSelect($list_categories, $codeType);
-                apcu_store($apcVar, $categoriesSelect, 60);
-            }
+            <div class="row">';
+
+if ($showCourses) {
+    echo '<div class="col-md-'.($showSessions ? '4' : '6').'">';
+    if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) { ?>
+        <form method="post"
+              action="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); ?>">
+            <input type="hidden" name="sec_token" value="<?php echo $stok; ?>">
+            <input type="hidden" name="search_course" value="1"/>
+            <label><?php echo get_lang('Search'); ?></label>
+            <div class="input-group">
+                <input class="form-control" type="text" name="search_term"
+                   value="<?php echo empty($_POST['search_term']) ? '' : api_htmlentities($searchTerm); ?>"/>
+                <div class="input-group-btn">
+                    <button class="btn btn-default" type="submit">
+                        <em class="fa fa-search"></em> <?php echo get_lang('Search'); ?>
+                    </button>
+                </div>
+            </div>
+        </form>
+        <?php
+    }
+    echo '</div>';
+    echo '<div class="col-md-'.($showSessions ? '4' : '6').'">';
+
+    $categoriesSelect = '';
+    $cacheAvailable = api_get_configuration_value('apc');
+    $accessUrlId = api_get_current_access_url_id();
+    if ($cacheAvailable === true) {
+        $apcVar = api_get_configuration_value('apc_prefix').'_'.$accessUrlId.'_course_categories_select';
+        if (apcu_exists($apcVar)) {
+            $categoriesSelect = apcu_fetch($apcVar);
         } else {
             $categoriesSelect = getOptionSelect($list_categories, $codeType);
+            apcu_store($apcVar, $categoriesSelect, 60);
         }
-
-        $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
-        $form = '<form action="'.$webAction.'" method="GET">';
-        $form .= '<input type="hidden" name="action" value="'.$action.'">';
-        $form .= '<input type="hidden" name="pageCurrent" value="'.$pageCurrent.'">';
-        $form .= '<input type="hidden" name="pageLength" value="'.$pageLength.'">';
-        $form .= '<div class="form-group">';
-        $form .= '<label>'.get_lang('CourseCategories').'</label>';
-        $form .= $categoriesSelect;
-        $form .= '</div>';
-        $form .= '</form>';
-        echo $form;
-        echo '</div>';
+    } else {
+        $categoriesSelect = getOptionSelect($list_categories, $codeType);
     }
 
+    $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php';
+    $form = '<form action="'.$webAction.'" method="GET">';
+    $form .= '<input type="hidden" name="action" value="'.$action.'">';
+    $form .= '<input type="hidden" name="pageCurrent" value="'.$pageCurrent.'">';
+    $form .= '<input type="hidden" name="pageLength" value="'.$pageLength.'">';
+    $form .= '<div class="form-group">';
+    $form .= '<label>'.get_lang('CourseCategories').'</label>';
+    $form .= $categoriesSelect;
+    $form .= '</div>';
+    $form .= '</form>';
+    echo $form;
+    echo '</div>';
+}
+
 if ($showSessions) {
-    ?>
-    <div class="col-md-4">
+    $url = CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions');
+    echo '<div class="col-md-4">
         <div class="return-catalog">
             <a class="btn btn-default btn-lg btn-block"
-               href="<?php echo CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); ?>">
-                <em class="fa fa-arrow-right"></em> <?php echo get_lang('SessionList'); ?>
+               href="'.$url.'">
+                <em class="fa fa-arrow-right"></em>'.get_lang('SessionList').'
             </a>
         </div>
     </div>
-<?php
-} ?>
-            </div>
-        </div>
-    </div>
-</div>
-<?php
+    ';
+}
+
+echo '</div></div></div></div>';
+
 if ($showCourses && $action != 'display_sessions') {
-        if (!empty($message)) {
-            echo Display::return_message($message, 'confirmation', false);
-        }
-        if (!empty($error)) {
-            echo Display::return_message($error, 'error', false);
-        }
+    if (!empty($message)) {
+        echo Display::return_message($message, 'confirmation', false);
+    }
+    if (!empty($error)) {
+        echo Display::return_message($error, 'error', false);
+    }
 
-        if (!empty($content)) {
-            echo $content;
-        }
+    if (!empty($content)) {
+        echo $content;
+    }
 
-        if (!empty($searchTerm)) {
-            echo "<p><strong>".get_lang('SearchResultsFor')." ".$searchTerm."</strong><br />";
-        }
+    if (!empty($searchTerm)) {
+        echo "<p><strong>".get_lang('SearchResultsFor')." ".$searchTerm."</strong><br />";
+    }
 
-        $showTeacher = api_get_setting('display_teacher_in_courselist') === 'true';
-        $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
-        $user_id = api_get_user_id();
-        $categoryListFromDatabase = CourseCategory::getCategories();
+    $showTeacher = api_get_setting('display_teacher_in_courselist') === 'true';
+    $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
+    $user_id = api_get_user_id();
+    $categoryListFromDatabase = CourseCategory::getCategories();
 
-        $categoryList = [];
-        if (!empty($categoryListFromDatabase)) {
-            foreach ($categoryListFromDatabase as $categoryItem) {
-                $categoryList[$categoryItem['code']] = $categoryItem['name'];
-            }
+    $categoryList = [];
+    if (!empty($categoryListFromDatabase)) {
+        foreach ($categoryListFromDatabase as $categoryItem) {
+            $categoryList[$categoryItem['code']] = $categoryItem['name'];
         }
+    }
 
-        if (!empty($browse_courses_in_category)) {
-            echo '<div class="grid-courses row">';
-            foreach ($browse_courses_in_category as $course) {
-                $course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
+    if (!empty($browse_courses_in_category)) {
+        echo '<div class="grid-courses row">';
+        foreach ($browse_courses_in_category as $course) {
+            $course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN;
 
-                if ($course_hidden) {
-                    continue;
-                }
+            if ($course_hidden) {
+                continue;
+            }
 
-                $userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
-                $userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
-                $userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
+            $userRegisteredInCourse = CourseManager::is_user_subscribed_in_course($user_id, $course['code']);
+            $userRegisteredInCourseAsTeacher = CourseManager::is_course_teacher($user_id, $course['code']);
+            $userRegistered = $userRegisteredInCourse && $userRegisteredInCourseAsTeacher;
 
-                $course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
-                $course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
-                $course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
-                $course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
+            $course_public = $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD;
+            $course_open = $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM;
+            $course_private = $course['visibility'] == COURSE_VISIBILITY_REGISTERED;
+            $course_closed = $course['visibility'] == COURSE_VISIBILITY_CLOSED;
 
-                $course_subscribe_allowed = $course['subscribe'] == 1;
-                $course_unsubscribe_allowed = $course['unsubscribe'] == 1;
-                $count_connections = $course['count_connections'];
-                $creation_date = substr($course['creation_date'], 0, 10);
+            $course_subscribe_allowed = $course['subscribe'] == 1;
+            $course_unsubscribe_allowed = $course['unsubscribe'] == 1;
+            $count_connections = $course['count_connections'];
+            $creation_date = substr($course['creation_date'], 0, 10);
 
-                // display the course bloc
-                $html = '<div class="col-xs-12 col-sm-6 col-md-4"><div class="items items-courses">';
+            // display the course bloc
+            $html = '<div class="col-xs-12 col-sm-6 col-md-4"><div class="items items-courses">';
 
-                $course['category_title'] = '';
-                if (isset($course['category'])) {
-                    $course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
-                }
+            $course['category_title'] = '';
+            if (isset($course['category'])) {
+                $course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : '';
+            }
 
-                // Display thumbnail
-                $html .= returnThumbnail($course, $userRegistered);
+            // Display thumbnail
+            $html .= returnThumbnail($course, $userRegistered);
 
-                $separator = null;
-                $subscribeButton = return_register_button($course, $stok, $code, $searchTerm);
-                // Start buy course validation
-                // display the course price and buy button if the buycourses plugin is enabled and this course is configured
-                $plugin = BuyCoursesPlugin::create();
-                $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
+            $separator = null;
+            $subscribeButton = return_register_button($course, $stok, $code, $searchTerm);
+            // Start buy course validation
+            // display the course price and buy button if the buycourses plugin is enabled and this course is configured
+            $plugin = BuyCoursesPlugin::create();
+            $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator(
                 $course['real_id'],
                 BuyCoursesPlugin::PRODUCT_TYPE_COURSE
             );
 
-                if ($isThisCourseInSale) {
-                    // set the Price label
-                    $separator = $isThisCourseInSale['html'];
-                    // set the Buy button instead register.
-                    if ($isThisCourseInSale['verificator']) {
-                        $subscribeButton = $plugin->returnBuyCourseButton(
+            if ($isThisCourseInSale) {
+                // set the Price label
+                $separator = $isThisCourseInSale['html'];
+                // set the Buy button instead register.
+                if ($isThisCourseInSale['verificator']) {
+                    $subscribeButton = $plugin->returnBuyCourseButton(
                         $course['real_id'],
                         BuyCoursesPlugin::PRODUCT_TYPE_COURSE
                     );
-                    }
                 }
-                // end buy course validation
+            }
+            // end buy course validation
 
-                // display course title and button bloc
-                $html .= '<div class="description">';
-                $html .= return_title($course, $userRegisteredInCourse);
+            // display course title and button bloc
+            $html .= '<div class="description">';
+            $html .= return_title($course, $userRegisteredInCourse);
 
-                if ($showTeacher) {
-                    $html .= return_teacher($course);
-                }
+            if ($showTeacher) {
+                $html .= return_teacher($course);
+            }
 
-                // display button line
-                $html .= '<div class="toolbar row">';
-                $html .= $separator ? '<div class="col-sm-4">'.$separator.'</div>' : '';
-                $html .= '<div class="col-sm-8">';
-                // if user registered as student
-                if ($userRegisteredInCourse) {
-                    $html .= return_already_registered_label('student');
-                    if (!$course_closed) {
-                        if ($course_unsubscribe_allowed) {
-                            $html .= return_unregister_button($course, $stok, $searchTerm, $code);
-                        }
-                    }
-                } elseif ($userRegisteredInCourseAsTeacher) {
-                    // if user registered as teacher
+            // display button line
+            $html .= '<div class="toolbar row">';
+            $html .= $separator ? '<div class="col-sm-4">'.$separator.'</div>' : '';
+            $html .= '<div class="col-sm-8">';
+            // if user registered as student
+            if ($userRegisteredInCourse) {
+                $html .= return_already_registered_label('student');
+                if (!$course_closed) {
                     if ($course_unsubscribe_allowed) {
                         $html .= return_unregister_button($course, $stok, $searchTerm, $code);
                     }
-                } else {
-                    // if user not registered in the course
-                    if (!$course_closed) {
-                        if (!$course_private) {
-                            if ($course_subscribe_allowed) {
-                                $html .= $subscribeButton;
-                            }
+                }
+            } elseif ($userRegisteredInCourseAsTeacher) {
+                // if user registered as teacher
+                if ($course_unsubscribe_allowed) {
+                    $html .= return_unregister_button($course, $stok, $searchTerm, $code);
+                }
+            } else {
+                // if user not registered in the course
+                if (!$course_closed) {
+                    if (!$course_private) {
+                        if ($course_subscribe_allowed) {
+                            $html .= $subscribeButton;
                         }
                     }
                 }
-                $html .= '</div>';
-                $html .= '</div>';
-                $html .= '</div>';
-                $html .= '</div>';
-                $html .= '</div>';
-                echo $html;
             }
-            echo '</div>';
-        } else {
-            if (!isset($_REQUEST['subscribe_user_with_password']) &&
+            $html .= '</div>';
+            $html .= '</div>';
+            $html .= '</div>';
+            $html .= '</div>';
+            $html .= '</div>';
+            echo $html;
+        }
+        echo '</div>';
+    } else {
+        if (!isset($_REQUEST['subscribe_user_with_password']) &&
             !isset($_REQUEST['subscribe_course'])
         ) {
-                echo Display::return_message(
+            echo Display::return_message(
                 get_lang('ThereAreNoCoursesInThisCategory'),
                 'warning'
             );
-            }
         }
     }
+}
 
 echo '<div class="col-md-12">';
 echo $cataloguePagination;