|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once("../config.php"); 00028 require_once("lib.php"); 00029 00030 $categoryedit = optional_param('categoryedit', -1,PARAM_BOOL); 00031 $delete = optional_param('delete',0,PARAM_INT); 00032 $hide = optional_param('hide',0,PARAM_INT); 00033 $show = optional_param('show',0,PARAM_INT); 00034 $move = optional_param('move',0,PARAM_INT); 00035 $moveto = optional_param('moveto',-1,PARAM_INT); 00036 $moveup = optional_param('moveup',0,PARAM_INT); 00037 $movedown = optional_param('movedown',0,PARAM_INT); 00038 00039 $site = get_site(); 00040 00041 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 00042 00043 $PAGE->set_url('/course/index.php'); 00044 $PAGE->set_context($systemcontext); 00045 $PAGE->set_pagelayout('admin'); 00046 00047 if (can_edit_in_category()) { 00048 if ($categoryedit !== -1) { 00049 $USER->editing = $categoryedit; 00050 } 00051 require_login(); 00052 $adminediting = $PAGE->user_is_editing(); 00053 } else { 00054 if ($CFG->forcelogin) { 00055 require_login(); 00056 } 00057 $adminediting = false; 00058 } 00059 00060 $stradministration = get_string('administration'); 00061 $strcategories = get_string('categories'); 00062 $strcategory = get_string('category'); 00063 $strcourses = get_string('courses'); 00064 $stredit = get_string('edit'); 00065 $strdelete = get_string('delete'); 00066 $straction = get_string('action'); 00067 $strfulllistofcourses = get_string('fulllistofcourses'); 00068 00069 00071 if (!$adminediting) { 00072 00074 $countcategories = $DB->count_records('course_categories'); 00075 00076 if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) { 00077 $strcourses = get_string('courses'); 00078 $strcategories = get_string('categories'); 00079 00080 $PAGE->navbar->add($strcategories); 00081 $PAGE->set_title("$site->shortname: $strcategories"); 00082 $PAGE->set_heading($COURSE->fullname); 00083 $PAGE->set_button(update_category_button()); 00084 echo $OUTPUT->header(); 00085 echo $OUTPUT->heading($strcategories); 00086 echo $OUTPUT->skip_link_target(); 00087 echo $OUTPUT->box_start('categorybox'); 00088 print_whole_category_list(); 00089 echo $OUTPUT->box_end(); 00090 print_course_search(); 00091 } else { 00092 $PAGE->navbar->add($strfulllistofcourses); 00093 $PAGE->set_title("$site->shortname: $strfulllistofcourses"); 00094 $PAGE->set_heading($COURSE->fullname); 00095 $PAGE->set_button(update_category_button()); 00096 echo $OUTPUT->header(); 00097 echo $OUTPUT->skip_link_target(); 00098 echo $OUTPUT->box_start('courseboxes'); 00099 print_courses(0); 00100 echo $OUTPUT->box_end(); 00101 } 00102 00103 echo $OUTPUT->container_start('buttons'); 00104 if (has_capability('moodle/course:create', $systemcontext)) { 00107 $options = array('category' => $CFG->defaultrequestcategory); 00108 echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get'); 00109 } 00110 print_course_request_buttons($systemcontext); 00111 echo $OUTPUT->container_end(); 00112 echo $OUTPUT->footer(); 00113 exit; 00114 } 00116 require_once($CFG->libdir.'/adminlib.php'); 00117 admin_externalpage_setup('coursemgmt'); 00118 00120 if (!empty($delete) and confirm_sesskey()) { 00121 if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) { 00122 print_error('invalidcategoryid'); 00123 } 00124 $context = get_context_instance(CONTEXT_COURSECAT, $delete); 00125 require_capability('moodle/category:manage', $context); 00126 require_capability('moodle/category:manage', get_category_or_system_context($deletecat->parent)); 00127 00128 $heading = get_string('deletecategory', 'moodle', format_string($deletecat->name, true, array('context' => $context))); 00129 require_once('delete_category_form.php'); 00130 $mform = new delete_category_form(null, $deletecat); 00131 $mform->set_data(array('delete'=>$delete)); 00132 00133 if ($mform->is_cancelled()) { 00134 redirect('index.php'); 00135 00136 } else if (!$data= $mform->get_data()) { 00137 require_once($CFG->libdir . '/questionlib.php'); 00138 echo $OUTPUT->header(); 00139 echo $OUTPUT->heading($heading); 00140 $mform->display(); 00141 echo $OUTPUT->footer(); 00142 exit(); 00143 } 00144 00145 echo $OUTPUT->header(); 00146 echo $OUTPUT->heading($heading); 00147 00148 if ($data->fulldelete) { 00149 $deletedcourses = category_delete_full($deletecat, true); 00150 00151 foreach($deletedcourses as $course) { 00152 echo $OUTPUT->notification(get_string('coursedeleted', '', $course->shortname), 'notifysuccess'); 00153 } 00154 echo $OUTPUT->notification(get_string('coursecategorydeleted', '', format_string($deletecat->name, true, array('context' => $context))), 'notifysuccess'); 00155 00156 } else { 00157 category_delete_move($deletecat, $data->newparent, true); 00158 } 00159 00160 // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. 00161 if ($delete == $CFG->defaultrequestcategory) { 00162 set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent'=>0))); 00163 } 00164 00165 echo $OUTPUT->continue_button('index.php'); 00166 00167 echo $OUTPUT->footer(); 00168 die; 00169 } 00170 00172 if (!$categories = get_categories()) { 00173 // Try and make one 00174 $tempcat = new stdClass(); 00175 $tempcat->name = get_string('miscellaneous'); 00176 $tempcat->id = $DB->insert_record('course_categories', $tempcat); 00177 $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id); 00178 mark_context_dirty('/'.SYSCONTEXTID); 00179 fix_course_sortorder(); // Required to build course_categories.depth and .path. 00180 } 00181 00183 if (!empty($move) and ($moveto >= 0) and confirm_sesskey()) { 00184 if ($cattomove = $DB->get_record('course_categories', array('id'=>$move))) { 00185 require_capability('moodle/category:manage', get_category_or_system_context($cattomove->parent)); 00186 if ($cattomove->parent != $moveto) { 00187 $newparent = $DB->get_record('course_categories', array('id'=>$moveto)); 00188 require_capability('moodle/category:manage', get_category_or_system_context($moveto)); 00189 move_category($cattomove, $newparent); 00190 } 00191 } 00192 } 00193 00195 if ($hide and confirm_sesskey()) { 00196 if ($tempcat = $DB->get_record('course_categories', array('id'=>$hide))) { 00197 require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent)); 00198 if ($tempcat->visible == 1) { 00199 course_category_hide($tempcat); 00200 } 00201 } 00202 } else if ($show and confirm_sesskey()) { 00203 if ($tempcat = $DB->get_record('course_categories', array('id'=>$show))) { 00204 require_capability('moodle/category:manage', get_category_or_system_context($tempcat->parent)); 00205 if ($tempcat->visible == 0) { 00206 course_category_show($tempcat); 00207 } 00208 } 00209 } 00210 00212 if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { 00213 fix_course_sortorder(); 00214 $swapcategory = NULL; 00215 00216 if (!empty($moveup)) { 00217 require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveup)); 00218 if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) { 00219 if ($swapcategory = $DB->get_records_select('course_categories', "sortorder<? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder DESC', '*', 0, 1)) { 00220 $swapcategory = reset($swapcategory); 00221 } 00222 } 00223 } else { 00224 require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $movedown)); 00225 if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) { 00226 if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { 00227 $swapcategory = reset($swapcategory); 00228 } 00229 } 00230 } 00231 if ($swapcategory and $movecategory) { 00232 $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id)); 00233 $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id)); 00234 } 00235 00236 // finally reorder courses 00237 fix_course_sortorder(); 00238 } 00239 00241 echo $OUTPUT->header(); 00242 echo $OUTPUT->heading($strcategories); 00243 00245 $strcategories = get_string('categories'); 00246 $strcourses = get_string('courses'); 00247 $strmovecategoryto = get_string('movecategoryto'); 00248 $stredit = get_string('edit'); 00249 00250 $displaylist = array(); 00251 $parentlist = array(); 00252 00253 $displaylist[0] = get_string('top'); 00254 make_categories_list($displaylist, $parentlist); 00255 00256 echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">'; 00257 echo '<th class="header" scope="col">'.$strcategories.'</th>'; 00258 echo '<th class="header" scope="col">'.$strcourses.'</th>'; 00259 echo '<th class="header" scope="col">'.$stredit.'</th>'; 00260 echo '<th class="header" scope="col">'.$strmovecategoryto.'</th>'; 00261 echo '</tr>'; 00262 00263 print_category_edit(NULL, $displaylist, $parentlist); 00264 echo '</table>'; 00265 00266 echo '<div class="buttons">'; 00267 if (has_capability('moodle/course:create', $systemcontext)) { 00268 // print create course link to first category 00269 $options = array('category' => $CFG->defaultrequestcategory); 00270 $options['returnto'] = 'topcat'; 00271 echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get'); 00272 } 00273 00274 // Print button for creating new categories 00275 if (has_capability('moodle/category:manage', $systemcontext)) { 00276 $options = array('parent'=>0); 00277 echo $OUTPUT->single_button(new moodle_url('editcategory.php', $options), get_string('addnewcategory'), 'get'); 00278 } 00279 00280 print_course_request_buttons($systemcontext); 00281 echo '</div>'; 00282 00283 echo $OUTPUT->footer(); 00284 00285 function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) { 00287 00288 global $CFG, $USER, $OUTPUT; 00289 00290 static $str = NULL; 00291 00292 if (is_null($str)) { 00293 $str = new stdClass; 00294 $str->edit = get_string('edit'); 00295 $str->delete = get_string('delete'); 00296 $str->moveup = get_string('moveup'); 00297 $str->movedown = get_string('movedown'); 00298 $str->edit = get_string('editthiscategory'); 00299 $str->hide = get_string('hide'); 00300 $str->show = get_string('show'); 00301 $str->cohorts = get_string('cohorts', 'cohort'); 00302 $str->spacer = $OUTPUT->spacer().' '; 00303 } 00304 00305 if (!empty($category)) { 00306 00307 if (!isset($category->context)) { 00308 $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id); 00309 } 00310 00311 echo '<tr><td align="left" class="name">'; 00312 for ($i=0; $i<$depth;$i++) { 00313 echo ' '; 00314 } 00315 $linkcss = $category->visible ? '' : ' class="dimmed" '; 00316 echo '<a '.$linkcss.' title="'.$str->edit.'" '. 00317 ' href="category.php?id='.$category->id.'&categoryedit=on&sesskey='.sesskey().'">'. 00318 format_string($category->name, true, array('context' => $category->context)).'</a>'; 00319 echo '</td>'; 00320 00321 echo '<td class="count">'.$category->coursecount.'</td>'; 00322 00323 echo '<td class="icons">'; 00324 00325 if (has_capability('moodle/category:manage', $category->context)) { 00326 echo '<a title="'.$str->edit.'" href="editcategory.php?id='.$category->id.'"><img'. 00327 ' src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.$str->edit.'" /></a> '; 00328 00329 echo '<a title="'.$str->delete.'" href="index.php?delete='.$category->id.'&sesskey='.sesskey().'"><img'. 00330 ' src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.$str->delete.'" /></a> '; 00331 00332 if (!empty($category->visible)) { 00333 echo '<a title="'.$str->hide.'" href="index.php?hide='.$category->id.'&sesskey='.sesskey().'"><img'. 00334 ' src="'.$OUTPUT->pix_url('t/hide') . '" class="iconsmall" alt="'.$str->hide.'" /></a> '; 00335 } else { 00336 echo '<a title="'.$str->show.'" href="index.php?show='.$category->id.'&sesskey='.sesskey().'"><img'. 00337 ' src="'.$OUTPUT->pix_url('t/show') . '" class="iconsmall" alt="'.$str->show.'" /></a> '; 00338 } 00339 00340 if (has_capability('moodle/cohort:manage', $category->context) or has_capability('moodle/cohort:view', $category->context)) { 00341 echo '<a title="'.$str->cohorts.'" href="'.$CFG->wwwroot.'/cohort/index.php?contextid='.$category->context->id.'"><img'. 00342 ' src="'.$OUTPUT->pix_url('i/cohort') . '" class="iconsmall" alt="'.$str->cohorts.'" /></a> '; 00343 } 00344 00345 if ($up) { 00346 echo '<a title="'.$str->moveup.'" href="index.php?moveup='.$category->id.'&sesskey='.sesskey().'"><img'. 00347 ' src="'.$OUTPUT->pix_url('t/up') . '" class="iconsmall" alt="'.$str->moveup.'" /></a> '; 00348 } else { 00349 echo $str->spacer; 00350 } 00351 if ($down) { 00352 echo '<a title="'.$str->movedown.'" href="index.php?movedown='.$category->id.'&sesskey='.sesskey().'"><img'. 00353 ' src="'.$OUTPUT->pix_url('t/down') . '" class="iconsmall" alt="'.$str->movedown.'" /></a> '; 00354 } else { 00355 echo $str->spacer; 00356 } 00357 } 00358 echo '</td>'; 00359 00360 echo '<td align="left">'; 00361 if (has_capability('moodle/category:manage', $category->context)) { 00362 $tempdisplaylist = $displaylist; 00363 unset($tempdisplaylist[$category->id]); 00364 foreach ($parentslist as $key => $parents) { 00365 if (in_array($category->id, $parents)) { 00366 unset($tempdisplaylist[$key]); 00367 } 00368 } 00369 $popupurl = new moodle_url("index.php?move=$category->id&sesskey=".sesskey()); 00370 $select = new single_select($popupurl, 'moveto', $tempdisplaylist, $category->parent, null, "moveform$category->id"); 00371 echo $OUTPUT->render($select); 00372 } 00373 echo '</td>'; 00374 echo '</tr>'; 00375 } else { 00376 $category = new stdClass(); 00377 $category->id = '0'; 00378 } 00379 00380 if ($categories = get_categories($category->id)) { // Print all the children recursively 00381 $countcats = count($categories); 00382 $count = 0; 00383 $first = true; 00384 $last = false; 00385 foreach ($categories as $cat) { 00386 $count++; 00387 if ($count == $countcats) { 00388 $last = true; 00389 } 00390 $up = $first ? false : true; 00391 $down = $last ? false : true; 00392 $first = false; 00393 00394 print_category_edit($cat, $displaylist, $parentslist, $depth+1, $up, $down); 00395 } 00396 } 00397 }