Browse Source

Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

Yannick Warnier 9 years ago
parent
commit
e7ef42756e

+ 1 - 0
composer.json

@@ -75,6 +75,7 @@
         "bower-asset/fullcalendar": "2.3.2",
         "bower-asset/simplewebrtc": "1.15.*",
         "bower-asset/select2": "4.*",
+        "bower-asset/MathJax": "2.5.*",
         "clue/graph": "~0.9.0",
         "graphp/graphviz": "~0.2.0",
         "graphp/algorithms": "~0.8.0",

+ 1 - 0
main/document/showinframes.php

@@ -185,6 +185,7 @@ $js_glossary_in_documents =	'
   {
     load: [
         { type:"script", id:"_fr1", src:"'.api_get_jquery_web_path().'"},
+        { type:"script", id:"_fr7", src:"'.api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML"},
         { type:"script", id:"_fr4", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/jquery-ui.min.js"},
         { type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/jquery-ui.min.css"},
         { type:"stylesheet", id:"_fr6", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/theme.css"},

+ 4 - 2
main/inc/lib/agenda.lib.php

@@ -1602,8 +1602,10 @@ class Agenda
 
                 if (api_is_allowed_to_edit() && $this->type == 'course') {
                     $event['editable'] = true;
-                    if ($coachCanEdit == false) {
-                        $event['editable'] = false;
+                    if (!empty($session_id)) {
+                        if ($coachCanEdit == false) {
+                            $event['editable'] = false;
+                        }
                     }
                 }
 

+ 64 - 25
main/inc/lib/course_category.lib.php

@@ -60,13 +60,19 @@ function getCategories($category)
     $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
     $category = Database::escape_string($category);
     $conditions = null;
-    $whereCondition = null;
+    $whereCondition = '';
+
     if (isMultipleUrlSupport()) {
         $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
         $conditions = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
         $whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
     }
 
+    $parentIdCondition = " AND (t1.parent_id IS NULL OR t1.parent_id = '' )";
+    if (!empty($category)) {
+        $parentIdCondition =  " AND t1.parent_id  = '$category' ";
+    }
+
     $sql = "SELECT
                 t1.name,
                 t1.code,
@@ -76,10 +82,13 @@ function getCategories($category)
                 COUNT(DISTINCT t3.code) AS nbr_courses
                 FROM $tbl_category t1
                 $conditions
-                LEFT JOIN $tbl_category t2 ON t1.code=t2.parent_id
-                LEFT JOIN $tbl_course t3 ON t3.category_code=t1.code
+                LEFT JOIN $tbl_category t2
+                ON t1.code = t2.parent_id
+                LEFT JOIN $tbl_course t3
+                ON t3.category_code=t1.code
                 WHERE
-                    t1.parent_id " . (empty($category) ? "IS NULL" : "='$category'") . "
+                    1 = 1
+                    $parentIdCondition
                     $whereCondition
                 GROUP BY t1.name,
                          t1.code,
@@ -87,9 +96,15 @@ function getCategories($category)
                          t1.tree_pos,
                          t1.children_count
                 ORDER BY t1.tree_pos";
+
     $result = Database::query($sql);
 
-    return Database::store_result($result);
+    $categories = Database::store_result($result);
+    foreach ($categories as $category) {
+        $category['nbr_courses'] =  1;
+    }
+
+    return $categories;
 }
 
 
@@ -107,7 +122,6 @@ function addNode($code, $name, $canHaveCourses, $parent_id)
     $code = trim($code);
     $name = trim($name);
     $parent_id = trim($parent_id);
-    $canHaveCourses = $canHaveCourses;
 
     $code = CourseManager::generate_course_code($code);
     $sql = "SELECT 1 FROM $tbl_category
@@ -123,7 +137,7 @@ function addNode($code, $name, $canHaveCourses, $parent_id)
     $params = [
         'name' => $name,
         'code' => $code,
-        'parent_id' => empty($parent_id) ? "NULL" : $parent_id,
+        'parent_id' => empty($parent_id) ? '' : $parent_id,
         'tree_pos' => $tree_pos,
         'children_count' => 0,
         'auth_course_child' => $canHaveCourses
@@ -160,11 +174,13 @@ function updateParentCategoryChildrenCount($categoryId, $delta = 1)
     // Now we're at the top, get back down to update each child
     //$children_count = courseCategoryChildrenCount($categoryId);
     if ($delta >= 0) {
-        $sql = "UPDATE $tbl_category SET children_count = (children_count + $delta) WHERE code = '$categoryId'";
+        $sql = "UPDATE $tbl_category SET children_count = (children_count + $delta)
+                WHERE code = '$categoryId'";
     } else {
-        $sql = "UPDATE $tbl_category SET children_count = (children_count - ".abs($delta).") WHERE code = '$categoryId'";
+        $sql = "UPDATE $tbl_category SET children_count = (children_count - ".abs($delta).")
+                WHERE code = '$categoryId'";
     }
-    $result = Database::query($sql);
+    Database::query($sql);
 }
 
 /**
@@ -234,8 +250,9 @@ function editNode($code, $name, $canHaveCourses, $old_code)
 /**
  * Move a node up on display
  * @param string $code
- * @param string $tree_pos
- * @param int $parent_id
+ * @param int $tree_pos
+ * @param string $parent_id
+ *
  * @return bool
  */
 function moveNodeUp($code, $tree_pos, $parent_id)
@@ -243,28 +260,47 @@ function moveNodeUp($code, $tree_pos, $parent_id)
     $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
     $code = Database::escape_string($code);
     $tree_pos = intval($tree_pos);
-    $parent_id = intval($parent_id);
+    $parent_id = Database::escape_string($parent_id);
+
+    $parentIdCondition = " AND (parent_id IS NULL OR parent_id = '' )";
+    if (!empty($parent_id)) {
+        $parentIdCondition = " AND parent_id = '$parent_id' ";
+    }
+
     $sql = "SELECT code,tree_pos
-        FROM $tbl_category
-        WHERE parent_id " . (empty($parent_id) ? "IS NULL" : " = $parent_id") . " AND tree_pos < $tree_pos
-        ORDER BY tree_pos DESC LIMIT 0,1";
+            FROM $tbl_category
+            WHERE
+                tree_pos < $tree_pos
+                $parentIdCondition
+            ORDER BY tree_pos DESC
+            LIMIT 0,1";
+
     $result = Database::query($sql);
     if (!$row = Database::fetch_array($result)) {
-
-        $sql = "SELECT code,tree_pos FROM $tbl_category
-            WHERE parent_id " . (empty($parent_id) ? "IS NULL" : " = $parent_id") . " AND tree_pos > $tree_pos
-            ORDER BY tree_pos DESC LIMIT 0,1";
+        $sql = "SELECT code, tree_pos
+                FROM $tbl_category
+                WHERE
+                    tree_pos > $tree_pos
+                    $parentIdCondition
+                ORDER BY tree_pos DESC
+                LIMIT 0,1";
         $result2 = Database::query($sql);
-        if (!$row2 = Database::fetch_array($result2)) {
+        if (!$row = Database::fetch_array($result2)) {
             return false;
         }
     }
 
-    Database::query("UPDATE $tbl_category SET tree_pos='" . $row['tree_pos'] . "' WHERE code='$code'");
-    Database::query("UPDATE $tbl_category SET tree_pos='$tree_pos' WHERE code='" . $code . "'");
+    $sql = "UPDATE $tbl_category
+            SET tree_pos ='" . $row['tree_pos'] . "'
+            WHERE code='$code'";
+    Database::query($sql);
 
-    return true;
+    $sql = "UPDATE $tbl_category
+            SET tree_pos = '$tree_pos'
+            WHERE code= '" . $row['code'] . "'";
+    Database::query($sql);
 
+    return true;
 }
 
 /**
@@ -313,6 +349,7 @@ function getChildren($categoryCode)
 
 /**
  * @param string $categoryCode
+ *
  * @return array
  */
 function getParents($categoryCode)
@@ -323,7 +360,8 @@ function getParents($categoryCode)
 
     $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
     $categoryCode = Database::escape_string($categoryCode);
-    $sql = "SELECT code, parent_id FROM $tbl_category WHERE code = '$categoryCode'";
+    $sql = "SELECT code, parent_id FROM $tbl_category
+            WHERE code = '$categoryCode'";
 
     $result = Database::query($sql);
     $children = array();
@@ -351,6 +389,7 @@ function getParentsToString($categoryCode)
             $categories[] = $category['code'];
         }
         $categoriesInString = implode(' > ', $categories).' > ';
+
         return $categoriesInString;
     }
     return null;

+ 4 - 4
main/inc/lib/template.lib.php

@@ -626,10 +626,6 @@ class Template
             $js_files[] = 'fontresize.js';
         }
 
-        if (api_get_setting('include_asciimathml_script') == 'true') {
-            $js_files[] = 'asciimath/ASCIIMathML.js';
-        }
-
         $js_files[] = 'tag/jquery.fcbkcomplete.js';
 
         $js_file_to_string = null;
@@ -649,6 +645,10 @@ class Template
             'imagemap-resizer/js/imageMapResizer.min.js'
         ];
 
+        if (api_get_setting('include_asciimathml_script') == 'true') {
+            $bowerJsFiles[] = 'MathJax/MathJax.js?config=AM_HTMLorMML';
+        }
+
         if ($isoCode != 'en') {
             $bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-' . $isoCode . '.js';
             $bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-' . $isoCode . '.min.js';