Source for file course_category.php
Documentation is available at course_category.php
<?php // $Id: course_category.php 14214 2008-01-31 03:31:49Z yannoo $
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
==============================================================================
==============================================================================
// name of the language file that needs to be included
require ('../inc/global.inc.php');
$category= $_GET['category'];
elseif(($action == 'add' || $action == 'edit') && $_POST['formSent'])
$_POST['categoryCode']= trim($_POST['categoryCode']);
$_POST['categoryName']= trim($_POST['categoryName']);
if(!empty($_POST['categoryCode']) && !empty($_POST['categoryName']))
$ret= addNode($_POST['categoryCode'],$_POST['categoryName'],$_POST['canHaveCourses'],$category);
$ret= editNode($_POST['categoryCode'],$_POST['categoryName'],$_POST['canHaveCourses'],$_GET['id']);
$errorMsg= get_lang('CatCodeAlreadyUsed');
$errorMsg= get_lang('PleaseEnterCategoryInfo');
elseif($action == 'edit')
$result= api_sql_query("SELECT name,auth_course_child FROM $tbl_category WHERE code='$categoryCode'",__FILE__ ,__LINE__ );
$canHaveCourses= ($canHaveCourses == 'FALSE')? 0: 1;
elseif($action == 'moveUp')
moveNodeUp($_GET['id'],$_GET['tree_pos'],$category);
$interbreadcrumb[]= array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
//api_display_tool_title($tool_name);
$myquery = "SELECT * FROM $tbl_category WHERE code ='$category'";
$myquery= "SELECT t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count,COUNT(DISTINCT t3.code) AS nbr_courses FROM $tbl_category t1 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'"). " GROUP BY t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count ORDER BY t1.tree_pos";
if(!empty($category) && empty($action))
$myquery = "SELECT parent_id FROM $tbl_category WHERE code='$category'";
<a href=" <?php echo api_get_self(); ?>?category= <?php echo Security::remove_XSS($parent_id); ?>"><< <?php echo get_lang("Back"); if(!empty($parent_id)) echo ' ('. $parent_id. ')'; ?></a>
if($action == 'add' || $action == 'edit')
<input type="hidden" name="formSent" value="1" />
<table border="0" cellpadding="5" cellspacing="0">
<td nowrap="nowrap"> <?php echo get_lang("CategoryCode"); ?> :</td>
<td><input type="text" name="categoryCode" size="20" maxlength="20" value=" <?php echo htmlentities(stripslashes($categoryCode),ENT_QUOTES,$charset); ?>" /></td>
<td nowrap="nowrap"> <?php echo get_lang("CategoryName"); ?> :</td>
<td><input type="text" name="categoryName" size="20" maxlength="100" value=" <?php echo htmlentities(stripslashes($categoryName),ENT_QUOTES,$charset); ?>" /></td>
<td nowrap="nowrap"> <?php echo get_lang("AllowCoursesInCategory"); ?></td>
<input class="checkbox" type="radio" name="canHaveCourses" value="0" <?php if(($action == 'edit' && !$canHaveCourses) || ($action == 'add' && $formSent && !$canHaveCourses)) echo 'checked="checked"'; ?> /> <?php echo get_lang("No"); ?>
<input class="checkbox" type="radio" name="canHaveCourses" value="1" <?php if(($action == 'edit' && $canHaveCourses) || ($action == 'add' && !$formSent || $canHaveCourses)) echo 'checked="checked"'; ?> /> <?php echo get_lang("Yes"); ?>
<td><input type="submit" value=" <?php echo get_lang("Ok"); ?>" /></td>
foreach($Categories as $enreg)
<a href=" <?php echo api_get_self(); ?>?category= <?php echo Security::remove_XSS($enreg['code']); ?>"><img src="../img/folder_document.gif" border="0" title=" <?php echo get_lang("OpenNode"); ?>" alt=" <?php echo get_lang("OpenNode"); ?>" align="absbottom" /></a>
<a href=" <?php echo api_get_self(); ?>?category= <?php echo Security::remove_XSS($category); ?>&action=moveUp&id= <?php echo Security::remove_XSS($enreg['code']); ?>&tree_pos= <?php echo $enreg['tree_pos']; ?>"><img src="../img/up.gif" border="0" title=" <?php echo get_lang("UpInSameLevel"); ?>" alt=" <?php echo get_lang("UpInSameLevel"); ?>" /></a>
<?php echo $enreg['name']; ?>
( <?php echo $enreg['children_count']; ?> <?php echo get_lang("Categories"); ?> - <?php echo $enreg['nbr_courses']; ?> <?php echo get_lang("Courses"); ?>)
==============================================================================
==============================================================================
/******** Functions ********/
global $tbl_category, $tbl_course;
$result= api_sql_query("SELECT parent_id,tree_pos FROM $tbl_category WHERE code='$node'",__FILE__ ,__LINE__ );
if(!empty($row['parent_id']))
api_sql_query("UPDATE $tbl_course SET category_code='". $row['parent_id']. "' WHERE category_code='$node'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET parent_id='". $row['parent_id']. "' WHERE parent_id='$node'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_course SET category_code='' WHERE category_code='$node'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET parent_id=NULL WHERE parent_id='$node'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET tree_pos=tree_pos-1 WHERE tree_pos > '". $row['tree_pos']. "'",__FILE__ ,__LINE__ );
api_sql_query("DELETE FROM $tbl_category WHERE code='$node'",__FILE__ ,__LINE__ );
if(!empty($row['parent_id']))
function addNode($code,$name,$canHaveCourses,$parent_id)
$canHaveCourses= $canHaveCourses? 'TRUE': 'FALSE';
$result= api_sql_query("SELECT 1 FROM $tbl_category WHERE code='$code'",__FILE__ ,__LINE__ );
$result= api_sql_query("SELECT MAX(tree_pos) AS maxTreePos FROM $tbl_category",__FILE__ ,__LINE__ );
$tree_pos= $row['maxTreePos']+ 1;
api_sql_query("INSERT INTO $tbl_category(name,code,parent_id,tree_pos,children_count,auth_course_child) VALUES('$name','$code',". (empty($parent_id)? "NULL": "'$parent_id'"). ",'$tree_pos','0','$canHaveCourses')",__FILE__ ,__LINE__ );
function editNode($code,$name,$canHaveCourses,$old_code)
$canHaveCourses= $canHaveCourses? 'TRUE': 'FALSE';
$result= api_sql_query("SELECT 1 FROM $tbl_category WHERE code='$code'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET name='$name',code='$code',auth_course_child='$canHaveCourses' WHERE code='$old_code'",__FILE__ ,__LINE__ );
$result= api_sql_query("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",__FILE__ ,__LINE__ );
$result= api_sql_query("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",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET tree_pos='". $row['tree_pos']. "' WHERE code='$code'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET tree_pos='$tree_pos' WHERE code='$row[code]'",__FILE__ ,__LINE__ );
$result= api_sql_query("SELECT parent_id FROM $tbl_category WHERE code='$category'",__FILE__ ,__LINE__ );
api_sql_query("UPDATE $tbl_category SET children_count='$children_count' WHERE code='$category'",__FILE__ ,__LINE__ );
$result= api_sql_query("SELECT code FROM $tbl_category WHERE parent_id='$pere'",__FILE__ ,__LINE__ );
|