2009-09-24 07:29:14 +00:00
< ? php
2003-09-21 17:08:41 +00:00
/// This page allows to edit entries categories for a particular instance of glossary
2009-09-24 07:29:14 +00:00
require_once ( " ../../config.php " );
require_once ( " lib.php " );
$id = required_param ( 'id' , PARAM_INT ); // Course Module ID, or
$usedynalink = optional_param ( 'usedynalink' , 0 , PARAM_INT ); // category ID
$confirm = optional_param ( 'confirm' , 0 , PARAM_INT ); // confirm the action
$name = optional_param ( 'name' , '' , PARAM_CLEAN ); // confirm the name
$action = optional_param ( 'action' , '' , PARAM_ALPHA ); // what to do
$hook = optional_param ( 'hook' , '' , PARAM_ALPHANUM ); // category ID
$mode = optional_param ( 'mode' , '' , PARAM_ALPHA ); // cat
$action = strtolower ( $action );
2010-01-16 15:39:56 +00:00
$url = new moodle_url ( '/mod/glossary/editcategories.php' , array ( 'id' => $id ));
2009-09-24 07:29:14 +00:00
if ( $usedynalink !== 0 ) {
$url -> param ( 'usedynalink' , $usedynalink );
}
if ( $confirm !== 0 ) {
$url -> param ( 'confirm' , $confirm );
}
if ( $name !== 'name' ) {
$url -> param ( 'name' , $name );
}
if ( $action !== 'action' ) {
$url -> param ( 'action' , $action );
}
if ( $hook !== 'hook' ) {
$url -> param ( 'hook' , $hook );
}
if ( $mode !== 'mode' ) {
$url -> param ( 'mode' , $mode );
}
$PAGE -> set_url ( $url );
if ( ! $cm = get_coursemodule_from_id ( 'glossary' , $id )) {
print_error ( 'invalidcoursemodule' );
}
if ( ! $course = $DB -> get_record ( " course " , array ( " id " => $cm -> course ))) {
print_error ( 'coursemisconf' );
}
if ( ! $glossary = $DB -> get_record ( " glossary " , array ( " id " => $cm -> instance ))) {
print_error ( 'invalidcoursemodule' );
}
if ( $hook > 0 ) {
if ( $category = $DB -> get_record ( " glossary_categories " , array ( " id " => $hook ))) {
//Check it belongs to the same glossary
if ( $category -> glossaryid != $glossary -> id ) {
print_error ( 'invalidid' , 'glossary' );
}
} else {
print_error ( 'invalidcategoryid' );
}
}
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
require_login ( $course -> id , false , $cm );
2005-12-07 06:21:58 +00:00
2009-09-24 07:29:14 +00:00
$context = get_context_instance ( CONTEXT_MODULE , $cm -> id );
require_capability ( 'mod/glossary:managecategories' , $context );
2004-08-29 22:57:41 +00:00
2009-09-24 07:29:14 +00:00
$strglossaries = get_string ( " modulenameplural " , " glossary " );
$strglossary = get_string ( " modulename " , " glossary " );
2005-02-16 10:40:48 +00:00
2010-01-16 15:39:56 +00:00
$PAGE -> navbar -> add ( $strglossaries , new moodle_url ( '/mod/glossary/index.php' , array ( 'id' => $course -> id )));
2009-09-24 07:29:14 +00:00
$PAGE -> navbar -> add ( get_string ( " categories " , " glossary " ));
2010-05-28 06:38:17 +00:00
if ( ! empty ( $action )) {
$navaction = get_string ( $action ) . " " . moodle_strtolower ( get_string ( " category " , " glossary " ));
$PAGE -> navbar -> add ( $navaction );
}
2009-09-24 07:29:14 +00:00
$PAGE -> set_title ( format_string ( $glossary -> name ));
2010-05-28 06:38:17 +00:00
$PAGE -> set_heading ( $course -> fullname );
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> header ();
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
if ( $hook > 0 ) {
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
if ( $action == " edit " ) {
if ( $confirm ) {
$action = " " ;
2010-09-21 08:37:36 +00:00
$cat = new stdClass ();
2009-09-24 07:29:14 +00:00
$cat -> id = $hook ;
$cat -> name = $name ;
$cat -> usedynalink = $usedynalink ;
2004-08-29 23:28:57 +00:00
2009-09-24 07:29:14 +00:00
$DB -> update_record ( " glossary_categories " , $cat );
add_to_log ( $course -> id , " glossary " , " edit category " , " editcategories.php?id= $cm->id " , $hook , $cm -> id );
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
} else {
2010-04-25 19:20:35 +00:00
echo " <h3 class= \" main \" > " . get_string ( " edit " ) . " " . get_string ( " category " , " glossary " ) . " </h3> " ;
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
$name = $category -> name ;
$usedynalink = $category -> usedynalink ;
require " editcategories.html " ;
echo $OUTPUT -> footer ();
die ;
}
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
} elseif ( $action == " delete " ) {
if ( $confirm ) {
$DB -> delete_records ( " glossary_entries_categories " , array ( " categoryid " => $hook ));
$DB -> delete_records ( " glossary_categories " , array ( " id " => $hook ));
2003-09-21 17:08:41 +00:00
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> box_start ( 'generalbox boxaligncenter errorboxcontent boxwidthnarrow' );
2010-04-25 19:20:35 +00:00
echo " <div> " . get_string ( " categorydeleted " , " glossary " ) . " </div> " ;
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> box_end ();
2004-09-09 09:06:18 +00:00
2009-09-24 07:29:14 +00:00
add_to_log ( $course -> id , " glossary " , " delete category " , " editcategories.php?id= $cm->id " , $hook , $cm -> id );
2004-09-09 09:06:18 +00:00
2009-09-24 07:29:14 +00:00
redirect ( " editcategories.php?id= $cm->id " );
} else {
2010-04-25 19:20:35 +00:00
echo " <p> " . get_string ( " delete " ) . " " . get_string ( " category " , " glossary " ) . " </p> " ;
2009-02-17 16:33:32 +00:00
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> box_start ( 'generalbox boxaligncenter errorboxcontent boxwidthnarrow' );
2010-04-25 19:20:35 +00:00
echo " <div class= \" boxaligncenter deletecatconfirm \" > " . format_text ( $category -> name , FORMAT_PLAIN ) . " <br/> " ;
2004-09-09 09:06:18 +00:00
2009-09-24 07:29:14 +00:00
$num_entries = $DB -> count_records ( " glossary_entries_categories " , array ( " categoryid " => $category -> id ));
if ( $num_entries ) {
print_string ( " deletingnoneemptycategory " , " glossary " );
2004-09-09 09:06:18 +00:00
}
2009-09-24 07:29:14 +00:00
echo " <p> " ;
print_string ( " areyousuredelete " , " glossary " );
echo " </p> " ;
2004-09-09 09:06:18 +00:00
?>
2007-03-30 07:04:43 +00:00
2010-04-25 19:20:35 +00:00
< table border = " 0 " width = " 100 " class = " confirmbuttons " >
2007-03-30 07:04:43 +00:00
< tr >
2009-11-01 14:55:15 +00:00
< td align = " right " style = " width:50% " >
2007-03-30 07:04:43 +00:00
< form id = " form " method = " post " action = " editcategories.php " >
< div >
< input type = " hidden " name = " id " value = " <?php p( $cm->id ) ?> " />
< input type = " hidden " name = " action " value = " delete " />
< input type = " hidden " name = " confirm " value = " 1 " />
< input type = " hidden " name = " mode " value = " <?php echo $mode ?> " />
< input type = " hidden " name = " hook " value = " <?php echo $hook ?> " />
< input type = " submit " value = " <?php print_string( " yes " )?> " />
</ div >
</ form >
</ td >
< td align = " left " style = " width:50% " >
2004-09-09 09:06:18 +00:00
< ? php
2009-09-24 07:29:14 +00:00
unset ( $options );
$options = array ( " id " => $id );
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( " editcategories.php " , $options ), get_string ( " no " ));
2009-09-24 07:29:14 +00:00
echo " </td></tr></table> " ;
echo " </div> " ;
echo $OUTPUT -> box_end ();
2004-09-09 09:06:18 +00:00
}
2009-09-24 07:29:14 +00:00
}
} elseif ( $action == " add " ) {
if ( $confirm ) {
2010-09-04 14:15:48 +00:00
$dupcategory = $DB -> get_records_sql ( " SELECT * FROM { glossary_categories} WHERE " . $DB -> sql_like ( 'name' , '?' , false ) . " AND glossaryid=? " , array ( $name , $glossary -> id ));
2009-09-24 07:29:14 +00:00
if ( $dupcategory ) {
2010-04-25 19:20:35 +00:00
echo " <h3 class= \" main \" > " . get_string ( " add " ) . " " . get_string ( " category " , " glossary " ) . " </h3> " ;
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> box_start ( 'generalbox boxaligncenter errorboxcontent boxwidthnarrow' );
2010-04-25 19:20:35 +00:00
echo " <div> " . get_string ( " duplicatedcategory " , " glossary " ) . " </div> " ;
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> box_end ();
redirect ( " editcategories.php?id= $cm->id &action=add&&name= $name " );
2004-09-09 09:06:18 +00:00
} else {
2009-09-24 07:29:14 +00:00
$action = " " ;
2010-09-21 08:37:36 +00:00
$cat = new stdClass ();
2009-09-24 07:29:14 +00:00
$cat -> name = $name ;
$cat -> usedynalink = $usedynalink ;
$cat -> glossaryid = $glossary -> id ;
$cat -> id = $DB -> insert_record ( " glossary_categories " , $cat );
add_to_log ( $course -> id , " glossary " , " add category " , " editcategories.php?id= $cm->id " , $cat -> id , $cm -> id );
2004-09-09 09:06:18 +00:00
}
2009-09-24 07:29:14 +00:00
} else {
2010-04-25 19:20:35 +00:00
echo " <h3 class= \" main \" > " . get_string ( " add " ) . " " . get_string ( " category " , " glossary " ) . " </h3> " ;
2009-09-24 07:29:14 +00:00
$name = " " ;
require " editcategories.html " ;
2004-09-09 09:06:18 +00:00
}
2009-09-24 07:29:14 +00:00
}
2005-02-16 10:40:48 +00:00
2009-09-24 07:29:14 +00:00
if ( $action ) {
echo $OUTPUT -> footer ();
die ;
}
2003-09-21 17:08:41 +00:00
?>
2007-01-04 21:32:36 +00:00
< form method = " post " action = " editcategories.php " >
2007-03-30 07:04:43 +00:00
< table width = " 40% " class = " boxaligncenter generalbox " cellpadding = " 5 " >
2003-09-21 17:08:41 +00:00
< tr >
2010-04-25 19:20:35 +00:00
< th style = " width:90% " align = " center " >
< ? php p ( get_string ( " categories " , " glossary " )) ?> </th>
< th style = " width:10% " align = " center " >
< ? php p ( get_string ( " action " )) ?> </th>
2003-09-21 17:08:41 +00:00
</ tr >
2007-03-30 07:04:43 +00:00
< tr >< td style = " width:100% " colspan = " 2 " >
2005-02-16 10:40:48 +00:00
2009-11-01 14:55:15 +00:00
2004-09-09 09:06:18 +00:00
2003-09-29 03:06:30 +00:00
< ? php
2008-06-08 10:43:39 +00:00
$categories = $DB -> get_records ( " glossary_categories " , array ( " glossaryid " => $glossary -> id ), " name ASC " );
2004-09-09 09:06:18 +00:00
if ( $categories ) {
2007-03-30 07:04:43 +00:00
echo '<table width="100%">' ;
2004-09-09 09:06:18 +00:00
foreach ( $categories as $category ) {
2008-06-08 10:43:39 +00:00
$num_entries = $DB -> count_records ( " glossary_entries_categories " , array ( " categoryid " => $category -> id ));
2004-09-09 09:06:18 +00:00
?>
2003-09-21 17:08:41 +00:00
2005-02-17 08:38:50 +00:00
< tr >
2010-04-25 19:20:35 +00:00
< td style = " width:80% " align = " left " >
2003-09-29 03:06:30 +00:00
< ? php
2010-04-25 19:20:35 +00:00
echo " <span class= \" bold \" > " . format_text ( $category -> name , FORMAT_PLAIN ) . " </span> <span>( $num_entries " . get_string ( " entries " , " glossary " ) . " )</span> " ;
2003-09-21 17:08:41 +00:00
?>
</ td >
2010-04-25 19:20:35 +00:00
< td style = " width:19% " align = " center " class = " action " >
2003-09-29 03:06:30 +00:00
< ? php
2009-12-16 21:50:45 +00:00
echo " <a href= \" editcategories.php?id= $cm->id &action=delete&mode=cat&hook= $category->id\ " >< img alt = \ " " . get_string ( " delete " ) . " \" src= \" " . $OUTPUT -> pix_url ( 't/delete' ) . " \" class= \" iconsmall \" /></a> " ;
echo " <a href= \" editcategories.php?id= $cm->id &action=edit&mode=cat&hook= $category->id\ " >< img alt = \ " " . get_string ( " edit " ) . " \" src= \" " . $OUTPUT -> pix_url ( 't/edit' ) . " \" class= \" iconsmall \" /></a> " ;
2003-09-21 17:08:41 +00:00
?>
2010-04-25 19:20:35 +00:00
</ td >
2003-09-21 17:08:41 +00:00
</ tr >
2005-02-16 10:40:48 +00:00
2003-09-29 03:06:30 +00:00
< ? php
2009-11-01 14:55:15 +00:00
2003-09-21 17:08:41 +00:00
}
2007-03-30 07:04:43 +00:00
echo '</table>' ;
2003-09-21 17:08:41 +00:00
}
?>
2005-02-16 10:40:48 +00:00
2007-03-30 07:04:43 +00:00
</ td ></ tr >
2003-09-21 17:08:41 +00:00
< tr >
2007-03-30 07:04:43 +00:00
< td style = " width:100% " colspan = " 2 " align = " center " >
2003-09-29 03:06:30 +00:00
< ? php
2005-02-16 10:40:48 +00:00
2003-09-21 17:08:41 +00:00
$options [ 'id' ] = $cm -> id ;
$options [ 'action' ] = " add " ;
2005-02-16 10:40:48 +00:00
2010-04-25 19:20:35 +00:00
echo " <table class= \" editbuttons \" border= \" 0 \" ><tr><td align= \" right \" > " ;
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( " editcategories.php " , $options ), get_string ( " add " ) . " " . get_string ( " category " , " glossary " ));
2004-09-12 16:24:41 +00:00
echo " </td><td align= \" left \" > " ;
2003-09-21 17:08:41 +00:00
unset ( $options [ 'action' ]);
2003-11-15 15:55:47 +00:00
$options [ 'mode' ] = 'cat' ;
$options [ 'hook' ] = $hook ;
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( " view.php " , $options ), get_string ( " back " , " glossary " ));
2003-09-21 17:08:41 +00:00
echo " </td></tr> " ;
2006-11-30 09:50:01 +00:00
echo " </table> " ;
2003-09-21 17:08:41 +00:00
?>
</ td >
</ tr >
</ table >
</ form >
2009-11-01 14:55:15 +00:00
< ? php
2009-08-06 14:13:29 +00:00
echo $OUTPUT -> footer ();