| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: manage.php,v 1.7.2.8 2008/07/16 01:20:48 scyrma Exp $ 2 3 require_once ('../config.php'); 4 require_once($CFG->libdir.'/tablelib.php'); 5 require_once ('lib.php'); 6 7 define('SHOW_ALL_PAGE_SIZE', 50000); 8 define('DEFAULT_PAGE_SIZE', 30); 9 10 $tagschecked = optional_param('tagschecked', array(), PARAM_INT); 11 $newnames = optional_param('newname', array(), PARAM_TAG); 12 $tagtypes = optional_param('tagtypes', array(), PARAM_ALPHA); 13 $action = optional_param('action', '', PARAM_ALPHA); 14 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); 15 16 require_login(); 17 18 if (empty($CFG->usetags)) { 19 print_error('tagsaredisabled', 'tag'); 20 } 21 22 //managing tags requires moodle/tag:manage capability 23 $systemcontext = get_context_instance(CONTEXT_SYSTEM); 24 require_capability('moodle/tag:manage', $systemcontext); 25 26 $navlinks = array(); 27 $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => ''); 28 $navlinks[] = array('name' => get_string('managetags', 'tag'), 'link' => '', 'type' => ''); 29 30 $navigation = build_navigation($navlinks); 31 print_header_simple(get_string('managetags', 'tag'), '', $navigation); 32 33 $err_notice = ''; 34 $notice = ''; 35 36 // get all the possible tag types from db 37 $existing_tagtypes = array(); 38 if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype) FROM {$CFG->prefix}tag")) { 39 foreach ($ptypes as $ptype) { 40 $existing_tagtypes[$ptype->tagtype] = $ptype->tagtype; 41 } 42 } 43 $existing_tagtypes['official'] = get_string('tagtype_official', 'tag'); 44 $existing_tagtypes['default'] = get_string('tagtype_default', 'tag'); 45 46 switch($action) { 47 48 case 'delete': 49 if (!data_submitted() or !confirm_sesskey()) { 50 break; 51 } 52 53 $str_tagschecked = implode(', ', tag_get_name($tagschecked)); 54 tag_delete($tagschecked); 55 $notice = $str_tagschecked.' -- '.get_string('deleted','tag'); 56 break; 57 58 case 'reset': 59 if (!data_submitted() or !confirm_sesskey()) { 60 break; 61 } 62 $str_tagschecked = implode(', ', tag_get_name($tagschecked)); 63 tag_unset_flag($tagschecked); 64 $notice = $str_tagschecked .' -- '. get_string('reset', 'tag'); 65 break; 66 67 case 'changetype': 68 if (!data_submitted() or !confirm_sesskey()) { 69 break; 70 } 71 72 $changed = array(); 73 foreach ($tagschecked as $tag_id) { 74 if (!array_key_exists($tagtypes[$tag_id], $existing_tagtypes)) { 75 //can not add new types here!! 76 continue; 77 } 78 79 // update tag type; 80 if (tag_type_set($tag_id, $tagtypes[$tag_id])) { 81 $changed[] = $tag_id; 82 } 83 } 84 85 if (!empty($changed)) { 86 $str_changed = implode(', ', tag_get_name($changed)); 87 $notice = $str_changed .' -- '. get_string('typechanged','tag'); 88 } 89 break; 90 91 case 'changename': 92 if (!data_submitted() or !confirm_sesskey()) { 93 break; 94 } 95 96 $tags_names_changed = array(); 97 foreach ($tagschecked as $tag_id) { 98 if ($newnames[$tag_id] != '') { 99 if (! $tags_names_updated[] = tag_rename($tag_id, $newnames[$tag_id]) ) { 100 // if tag already exists, or is not a valid tag name, etc. 101 $err_notice .= $newnames[$tag_id]. '-- ' . get_string('namesalreadybeeingused','tag').'<br />'; 102 } else { 103 $tags_names_changed[$tag_id] = $newnames[$tag_id]; 104 } 105 } 106 } 107 108 //notice to inform what tags had their names effectively updated 109 if ($tags_names_changed){ 110 $notice = implode($tags_names_changed, ', '); 111 $notice .= ' -- ' . get_string('updated','tag'); 112 } 113 break; 114 case 'addofficialtag': 115 $new_otags = explode(',', optional_param('otagsadd', '', PARAM_TAG)); 116 $notice = ''; 117 foreach ( $new_otags as $new_otag ) { 118 if ( $new_otag_id = tag_get_id($new_otag) ) { 119 // tag exists, change the type 120 tag_type_set($new_otag_id, 'official'); 121 } else { 122 tag_add($new_otag, 'official'); 123 } 124 $notice .= get_string('addedotag', 'tag', $new_otag) .' '; 125 } 126 break; 127 } 128 129 echo '<br/>'; 130 131 if ($err_notice) { 132 notify($err_notice, 'red'); 133 } 134 if ($notice) { 135 notify($notice, 'green'); 136 } 137 138 // small form to add an official tag 139 print('<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php">'); 140 print('<input type="hidden" name="action" value="addofficialtag">'); 141 print('<div class="tag-management-form generalbox"><label class="accesshide" for="id_otagsadd">'. get_string('addotags', 'tag') .'</label>'. 142 '<input name="otagsadd" id="id_otagsadd" type="text">'. 143 '<input name="addotags" value="'. get_string('addotags', 'tag') .'" onclick="skipClientValidation = true;" id="id_addotags" type="submit">'. 144 '</div>'); 145 print('</form>'); 146 147 //setup table 148 149 $tablecolumns = array('id', 'name', 'fullname', 'count', 'flag', 'timemodified', 'rawname', 'tagtype', ''); 150 $tableheaders = array(get_string('id', 'tag'), 151 get_string('name', 'tag'), 152 get_string('owner', 'tag'), 153 get_string('count', 'tag'), 154 get_string('flag', 'tag'), 155 get_string('timemodified', 'tag'), 156 get_string('newname', 'tag'), 157 get_string('tagtype', 'tag'), 158 get_string('select', 'tag')); 159 160 $table = new flexible_table('tag-management-list-'.$USER->id); 161 162 $baseurl = $CFG->wwwroot.'/tag/manage.php?perpage='.$perpage; 163 164 $table->define_columns($tablecolumns); 165 $table->define_headers($tableheaders); 166 $table->define_baseurl($baseurl); 167 168 $table->sortable(true, 'flag', SORT_DESC); 169 170 $table->set_attribute('cellspacing', '0'); 171 $table->set_attribute('id', 'tag-management-list'); 172 $table->set_attribute('class', 'generaltable generalbox'); 173 174 $table->set_control_variables(array( 175 TABLE_VAR_SORT => 'ssort', 176 TABLE_VAR_HIDE => 'shide', 177 TABLE_VAR_SHOW => 'sshow', 178 TABLE_VAR_IFIRST => 'sifirst', 179 TABLE_VAR_ILAST => 'silast', 180 TABLE_VAR_PAGE => 'spage' 181 )); 182 183 $table->setup(); 184 185 if ($table->get_sql_sort()) { 186 $sort = 'ORDER BY '. $table->get_sql_sort(); 187 } else { 188 $sort = ''; 189 } 190 191 if ($table->get_sql_where()) { 192 $where = 'WHERE '. $table->get_sql_where(); 193 } else { 194 $where = ''; 195 } 196 197 $query = 'SELECT tg.id, tg.name, tg.rawname, tg.tagtype, COUNT(ti.id) AS count, u.id AS owner, tg.flag, tg.timemodified, u.firstname, u.lastname '. 198 'FROM '. $CFG->prefix .'tag_instance ti RIGHT JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid LEFT JOIN '. $CFG->prefix .'user u ON tg.userid = u.id '. 199 $where .' '. 200 'GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, u.id, tg.flag, tg.timemodified, u.firstname, u.lastname '. 201 $sort; 202 203 $totalcount = count_records_sql('SELECT COUNT(DISTINCT(tg.id)) FROM '. $CFG->prefix .'tag tg LEFT JOIN '. $CFG->prefix .'user u ON u.id = tg.userid '. $where); 204 205 $table->initialbars(true); // always initial bars 206 $table->pagesize($perpage, $totalcount); 207 208 echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php"><div>'; 209 210 //retrieve tags from DB 211 if ($tagrecords = get_records_sql($query, $table->get_page_start(), $table->get_page_size())) { 212 213 $taglist = array_values($tagrecords); 214 215 //print_tag_cloud(array_values(get_records_sql($query)), false); 216 //populate table with data 217 foreach ($taglist as $tag ){ 218 $id = $tag->id; 219 $name = '<a href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'">'. tag_display_name($tag) .'</a>'; 220 $owner = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$tag->owner.'">' . fullname($tag) . '</a>'; 221 $count = $tag->count; 222 $flag = $tag->flag; 223 $timemodified = format_time(time() - $tag->timemodified); 224 $checkbox = '<input type="checkbox" name="tagschecked[]" value="'.$tag->id.'" />'; 225 $text = '<input type="text" name="newname['.$tag->id.']" />'; 226 $tagtype = choose_from_menu($existing_tagtypes, 'tagtypes['.$tag->id.']', $tag->tagtype, '', '', '0', true); 227 228 //if the tag if flagged, highlight it 229 if ($tag->flag > 0) { 230 $id = '<span class="flagged-tag">' . $id . '</span>'; 231 $name = '<span class="flagged-tag">' . $name . '</span>'; 232 $owner = '<span class="flagged-tag">' . $owner . '</span>'; 233 $count = '<span class="flagged-tag">' . $count . '</span>'; 234 $flag = '<span class="flagged-tag">' . $flag . '</span>'; 235 $timemodified = '<span class="flagged-tag">' . $timemodified . '</span>'; 236 $tagtype = '<span class="flagged-tag">'. $tagtype. '</span>'; 237 } 238 239 $data = array($id, $name, $owner, $count, $flag, $timemodified, $text, $tagtype, $checkbox); 240 241 $table->add_data($data); 242 } 243 244 echo '<input type="button" onclick="checkall()" value="'.get_string('selectall').'" /> '; 245 echo '<input type="button" onclick="checknone()" value="'.get_string('deselectall').'" /> '; 246 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" /> '; 247 echo '<br/><br/>'; 248 echo '<select id="menuformaction" name="action"> 249 <option value="" selected="selected">'. get_string('withselectedtags', 'tag') .'</option> 250 <option value="reset">'. get_string('resetflag', 'tag') .'</option> 251 <option value="delete">'. get_string('delete', 'tag') .'</option> 252 <option value="changetype">'. get_string('changetype', 'tag') .'</option> 253 <option value="changename">'. get_string('changename', 'tag') .'</option> 254 </select>'; 255 256 echo '<button id="tag-management-submit" type="submit">'. get_string('ok') .'</button>'; 257 } 258 259 $table->print_html(); 260 echo '</div></form>'; 261 262 if ($perpage == SHOW_ALL_PAGE_SIZE) { 263 echo '<div id="showall"><a href="'. $baseurl .'&perpage='. DEFAULT_PAGE_SIZE .'">'. get_string('showperpage', '', DEFAULT_PAGE_SIZE) .'</a></div>'; 264 265 } else if ($totalcount > 0 and $perpage < $totalcount) { 266 echo '<div id="showall"><a href="'. $baseurl .'&perpage='. SHOW_ALL_PAGE_SIZE .'">'. get_string('showall', '', $totalcount) .'</a></div>'; 267 } 268 269 echo '<br/>'; 270 271 print_footer(); 272 273 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |