Adding 4 level for course categories see #5850

skala
Julio Montoya 12 years ago
parent f7d7d8d2d9
commit 2866dd5d17
  1. 73
      main/admin/course_category.php
  2. 10
      main/inc/lib/auth.lib.php
  3. 22
      main/template/default/auth/courses_categories.php

@ -16,23 +16,30 @@ require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$category = $_GET['category'];
$category = Database::escape_string($category);
$category = Database::escape_string($_GET['category']);
$action = $_GET['action'];
$action = isset($_GET['action']) ? $_GET['action'] : null;
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$errorMsg = '';
$id = isset($_GET['id']) ? $_GET['id'] : null;
$categoryCode = isset($_POST['categoryCode']) ? $_POST['categoryCode'] : null;
$categoryName = isset($_POST['categoryName']) ? $_POST['categoryName'] : null;
$formSent = isset($_POST['formSent']) ? $_POST['formSent'] : false;
$canHaveCourses = 0;
if (!empty($action)) {
if ($action == 'delete') {
deleteNode($_GET['id']);
deleteNode($id);
header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
exit();
} elseif (($action == 'add' || $action == 'edit') && $_POST['formSent']) {
} elseif (($action == 'add' || $action == 'edit') && $formSent) {
$_POST['categoryCode'] = trim($_POST['categoryCode']);
$_POST['categoryName'] = trim($_POST['categoryName']);
@ -40,7 +47,7 @@ if (!empty($action)) {
if ($action == 'add') {
$ret = addNode($_POST['categoryCode'], $_POST['categoryName'], $_POST['canHaveCourses'], $category);
} else {
$ret = editNode($_POST['categoryCode'], $_POST['categoryName'], $_POST['canHaveCourses'], $_GET['id']);
$ret = editNode($_POST['categoryCode'], $_POST['categoryName'], $_POST['canHaveCourses'], $id);
}
if ($ret) {
@ -52,16 +59,17 @@ if (!empty($action)) {
$errorMsg = get_lang('PleaseEnterCategoryInfo');
}
} elseif ($action == 'edit') {
$categoryCode = Database::escape_string($_GET['id']);
$result = Database::query("SELECT name,auth_course_child FROM $tbl_category WHERE code='$categoryCode'");
list($categoryName, $canHaveCourses) = Database::fetch_row($result);
if (!empty($id)) {
$categoryCode = $id;
$sql = "SELECT name, auth_course_child FROM $tbl_category WHERE code='$id'";
$result = Database::query($sql);
list($categoryName, $canHaveCourses) = Database::fetch_row($result);
$canHaveCourses = ($canHaveCourses == 'FALSE') ? 0 : 1;
$canHaveCourses = ($canHaveCourses == 'FALSE') ? 0 : 1;
}
} elseif ($action == 'moveUp') {
moveNodeUp($_GET['id'], $_GET['tree_pos'], $category);
moveNodeUp($id, $_GET['tree_pos'], $category);
header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
exit();
}
@ -106,7 +114,7 @@ if ($action == 'add' || $action == 'edit') {
$form->addElement('header', '', $form_title);
$form->display();
?>
<form method="post" action="<?php echo api_get_self(); ?>?action=<?php echo Security::remove_XSS($action); ?>&category=<?php echo Security::remove_XSS($category); ?>&amp;id=<?php echo Security::remove_XSS($_GET['id']); ?>">
<form method="post" action="<?php echo api_get_self(); ?>?action=<?php echo Security::remove_XSS($action); ?>&category=<?php echo Security::remove_XSS($category); ?>&amp;id=<?php echo $id; ?>">
<input type="hidden" name="formSent" value="1" />
<table border="0" cellpadding="5" cellspacing="0">
<?php
@ -118,17 +126,16 @@ if ($action == 'add' || $action == 'edit') {
<?php
Display::display_normal_message($errorMsg); //main API
?>
</td>
</tr>
<?php
}
?>
<tr>
<td nowrap="nowrap"><?php echo get_lang("CategoryCode"); ?> :</td>
<td><input type="text" name="categoryCode" size="20" maxlength="20" value="<?php echo api_htmlentities(stripslashes($categoryCode), ENT_QUOTES, $charset); ?>" /></td>
<td>
<input type="text" name="categoryCode" size="20" maxlength="20" value="<?php echo api_htmlentities(stripslashes($categoryCode), ENT_QUOTES, $charset); ?>" /></td>
</tr>
<tr>
<td nowrap="nowrap"><?php echo get_lang("CategoryName"); ?> :</td>
@ -144,7 +151,7 @@ if ($action == 'add' || $action == 'edit') {
<tr>
<td>&nbsp;</td>
<?php
if (isset($_GET['id']) && !empty($_GET['id'])) {
if (!empty($id)) {
$class = "save";
$text = get_lang('CategoryMod');
} else {
@ -161,17 +168,17 @@ if ($action == 'add' || $action == 'edit') {
} else {
?>
<div class="actions">
<?php
if (!empty($category) && empty($action)) {
$myquery = "SELECT parent_id FROM $tbl_category WHERE code='$category'";
$result = Database::query($myquery);
$parent_id = 0;
if (Database::num_rows($result) > 0) {
$parent_id = Database::fetch_array($result);
}
<?php
if (!empty($category) && empty($action)) {
$myquery = "SELECT parent_id FROM $tbl_category WHERE code='$category'";
$result = Database::query($myquery);
$parent_id = 0;
if (Database::num_rows($result) > 0) {
$parent_id = Database::fetch_array($result);
}
$parent_id['parent_id'] ? $link = ' (' . $parent_id['parent_id'] . ')' : $link = '';
?>
$parent_id['parent_id'] ? $link = ' (' . $parent_id['parent_id'] . ')' : $link = '';
?>
<a href="<?php echo api_get_self(); ?>?category=<?php echo $parent_id['parent_id']; ?>"><?php echo Display::return_icon('folder_up.png', get_lang("Back"), '', ICON_SIZE_MEDIUM);
if (!empty($parent_id)) echo $link ?></a>
@ -211,16 +218,11 @@ if ($action == 'add' || $action == 'edit') {
}
?>
</ul>
<?php
}
Display::display_footer();
/* * ****** Functions ******* */
function deleteNode($node) {
global $tbl_category, $tbl_course;
$node = Database::escape_string($node);
@ -338,4 +340,5 @@ function compterFils($pere, $cpt) {
}
return ($cpt + 1);
}
}

@ -409,7 +409,7 @@ class Auth {
}
/**
* get the browsing of the course categories (faculties)
* Get the browsing of the course categories (faculties)
* @return array array containing a list with all the categories and subcategories(if needed)
*/
public function browse_course_categories() {
@ -435,12 +435,10 @@ class Auth {
* @return array Courses data
*/
public function browse_courses_in_category($category_code, $random_value = null) {
global $_configuration;
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$TABLE_COURSE_FIELD = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
$TABLE_COURSE_FIELD_VALUE = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
// Get course list auto-register
$sql = "SELECT course_code FROM $TABLE_COURSE_FIELD_VALUE tcfv INNER JOIN $TABLE_COURSE_FIELD tcf ON tcfv.field_id = tcf.id
WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 ";
@ -488,7 +486,7 @@ class Auth {
$id_in = null;
while (list($id) = Database::fetch_row($result)) {
if ($id_in) {
$id_in.=",$id";
$id_in.= ",$id";
} else {
$id_in = "$id";
}
@ -537,7 +535,6 @@ class Auth {
'count_connections' => $count_connections_last_month
);
}
return $courses;
}
@ -571,8 +568,7 @@ class Auth {
$search_term_safe = Database::escape_string($search_term);
$sql_find = "SELECT * FROM $TABLECOURS WHERE (code LIKE '%" . $search_term_safe . "%' OR title LIKE '%" . $search_term_safe . "%' OR tutor_name LIKE '%" . $search_term_safe . "%') $without_special_courses ORDER BY title, visual_code ASC";
global $_configuration;
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
if ($url_access_id != -1) {
$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);

@ -50,6 +50,7 @@ $stok = Security::get_token();
<div id="course_category_well" class="well">
<ul class="nav nav-list">
<?php
if (!empty($browse_course_categories)) {
echo '<a class="btn" href="'.api_get_self().'?action=display_random_courses">'.get_lang('RandomPick').'</a><br /><br />';
@ -72,6 +73,7 @@ $stok = Security::get_token();
}
echo '<li>'.$category_link.'</li>';
// level 2
if (!empty($browse_course_categories[$category_code])) {
foreach ($browse_course_categories[$category_code] as $subcategory1) {
@ -95,10 +97,27 @@ $stok = Security::get_token();
if ($code == $subcategory2_code) {
$subcategory2_link = '<strong>'.$subcategory2_name.' ('.$count_courses_lv3.')</strong>';
} else {
$subcategory2_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory2_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory2_name.'</a> ('.$count_courses_lv3.')';
$subcategory2_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory2_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory2_name.' ('.$count_courses_lv3.') </a>';
}
echo '<li style="margin-left:40px;">'.$subcategory2_link.'</li>';
// level 4
if (!empty($browse_course_categories[$subcategory2_code])) {
foreach ($browse_course_categories[$subcategory2_code] as $subcategory3) {
$subcategory3_name = $subcategory3['name'];
$subcategory3_code = $subcategory3['code'];
$count_courses_lv4 = $subcategory3['count_courses'];
if ($code == $subcategory3_code) {
$subcategory3_link = '<strong>'.$subcategory3_name.' ('.$count_courses_lv4.') </strong>';
} else {
$subcategory3_link = '<a href="'. api_get_self().'?action=display_courses&amp;category_code='.$subcategory3_code.'&amp;hidden_links='.$hidden_links.'">'.$subcategory3_name.' ('.$count_courses_lv4.') </a>';
}
echo '<li style="margin-left:60px;">'.$subcategory3_link.'</li>';
}
}
}
}
}
}
@ -119,7 +138,6 @@ $stok = Security::get_token();
}
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
if (!empty($browse_courses_in_category)) {
foreach ($browse_courses_in_category as $course) {

Loading…
Cancel
Save