| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: index.php,v 1.13 2007/04/30 17:08:52 skodak Exp $ 2 3 require('../../config.php'); 4 require_once($CFG->libdir.'/adminlib.php'); 5 require_once($CFG->dirroot.'/user/profile/lib.php'); 6 require_once($CFG->dirroot.'/user/profile/definelib.php'); 7 8 admin_externalpage_setup('profilefields'); 9 10 $action = optional_param('action', '', PARAM_ALPHA); 11 12 $redirect = $CFG->wwwroot.'/user/profile/index.php'; 13 14 $strchangessaved = get_string('changessaved'); 15 $strcancelled = get_string('cancelled'); 16 $strdefaultcategory = get_string('profiledefaultcategory', 'admin'); 17 $strnofields = get_string('profilenofieldsdefined', 'admin'); 18 $strcreatefield = get_string('profilecreatefield', 'admin'); 19 20 21 /// Do we have any actions to perform before printing the header 22 23 switch ($action) { 24 case 'movecategory': 25 $id = required_param('id', PARAM_INT); 26 $dir = required_param('dir', PARAM_ALPHA); 27 28 if (confirm_sesskey()) { 29 profile_move_category($id, $dir); 30 } 31 redirect($redirect); 32 break; 33 case 'movefield': 34 $id = required_param('id', PARAM_INT); 35 $dir = required_param('dir', PARAM_ALPHA); 36 37 if (confirm_sesskey()) { 38 profile_move_field($id, $dir); 39 } 40 redirect($redirect); 41 break; 42 case 'deletecategory': 43 $id = required_param('id', PARAM_INT); 44 $confirm = optional_param('confirm', 0, PARAM_BOOL); 45 46 if (data_submitted() and $confirm and confirm_sesskey()) { 47 profile_delete_category($id); 48 redirect($redirect); 49 } 50 51 //ask for confirmation 52 $fieldcount = count_records('user_info_field', 'categoryid', $id); 53 $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletecategory', 'sesskey'=>sesskey()); 54 admin_externalpage_print_header(); 55 print_heading('profiledeletecategory', 'admin'); 56 notice_yesno(get_string('profileconfirmcategorydeletion', 'admin', $fieldcount), $redirect, $redirect, $optionsyes, null, 'post', 'get'); 57 admin_externalpage_print_footer(); 58 die; 59 break; 60 case 'deletefield': 61 $id = required_param('id', PARAM_INT); 62 $confirm = optional_param('confirm', 0, PARAM_BOOL); 63 64 if (data_submitted() and $confirm and confirm_sesskey()) { 65 profile_delete_field($id); 66 redirect($redirect); 67 } 68 69 //ask for confirmation 70 $datacount = count_records('user_info_data', 'fieldid', $id); 71 $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletefield', 'sesskey'=>sesskey()); 72 admin_externalpage_print_header(); 73 print_heading('profiledeletefield', 'admin'); 74 notice_yesno(get_string('profileconfirmfielddeletion', 'admin', $datacount), $redirect, $redirect, $optionsyes, null, 'post', 'get'); 75 admin_externalpage_print_footer(); 76 die; 77 break; 78 case 'editfield': 79 $id = optional_param('id', 0, PARAM_INT); 80 $datatype = optional_param('datatype', '', PARAM_ALPHA); 81 82 profile_edit_field($id, $datatype, $redirect); 83 die; 84 break; 85 case 'editcategory': 86 $id = optional_param('id', 0, PARAM_INT); 87 88 profile_edit_category($id, $redirect); 89 die; 90 break; 91 default: 92 //normal form 93 } 94 95 /// Print the header 96 admin_externalpage_print_header(); 97 print_heading(get_string('profilefields', 'admin')); 98 99 /// Check that we have at least one category defined 100 if (count_records('user_info_category') == 0) { 101 $defaultcategory = new object(); 102 $defaultcategory->name = $strdefaultcategory; 103 $defaultcategory->sortorder = 1; 104 insert_record('user_info_category', $defaultcategory); 105 redirect($redirect); 106 } 107 108 /// Show all categories 109 $categories = get_records_select('user_info_category', '', 'sortorder ASC'); 110 111 foreach ($categories as $category) { 112 $table = new object(); 113 $table->head = array(get_string('profilefield', 'admin'), get_string('edit')); 114 $table->align = array('left', 'right'); 115 $table->width = '95%'; 116 $table->class = 'generaltable profilefield'; 117 $table->data = array(); 118 119 if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) { 120 foreach ($fields as $field) { 121 $table->data[] = array($field->name, profile_field_icons($field)); 122 } 123 } 124 125 print_heading(format_string($category->name) .' '.profile_category_icons($category)); 126 if (count($table->data)) { 127 print_table($table); 128 } else { 129 notify($strnofields); 130 } 131 132 } /// End of $categories foreach 133 134 135 136 137 echo '<hr />'; 138 echo '<div class="profileeditor">'; 139 140 /// Create a new field link 141 $options = profile_list_datatypes(); 142 popup_form($CFG->wwwroot.'/user/profile/index.php?id=0&action=editfield&datatype=', $options, 'newfieldform','','choose','','',false,'self',$strcreatefield); 143 144 /// Create a new category link 145 $options = array('action'=>'editcategory'); 146 print_single_button('index.php', $options, get_string('profilecreatecategory', 'admin')); 147 148 echo '</div>'; 149 150 admin_externalpage_print_footer(); 151 die; 152 153 154 /***** Some functions relevant to this script *****/ 155 156 /** 157 * Create a string containing the editing icons for the user profile categories 158 * @param object the category object 159 * @return string the icon string 160 */ 161 function profile_category_icons ($category) { 162 global $CFG, $USER; 163 164 $strdelete = get_string('delete'); 165 $strmoveup = get_string('moveup'); 166 $strmovedown = get_string('movedown'); 167 $stredit = get_string('edit'); 168 169 $categorycount = count_records('user_info_category'); 170 $fieldcount = count_records('user_info_field', 'categoryid', $category->id); 171 172 /// Edit 173 $editstr = '<a title="'.$stredit.'" href="index.php?id='.$category->id.'&action=editcategory"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> '; 174 175 /// Delete 176 /// Can only delete the last category if there are no fields in it 177 if ( ($categorycount > 1) or ($fieldcount == 0) ) { 178 $editstr .= '<a title="'.$strdelete.'" href="index.php?id='.$category->id.'&action=deletecategory'; 179 $editstr .= '"><img src="'.$CFG->pixpath.'/t/delete.gif" alt="'.$strdelete.'" class="iconsmall" /></a> '; 180 } else { 181 $editstr .= '<img src="'.$CFG->pixpath.'/spacer.gif" alt="" class="iconsmall" /> '; 182 } 183 184 /// Move up 185 if ($category->sortorder > 1) { 186 $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$category->id.'&action=movecategory&dir=up&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" class="iconsmall" /></a> '; 187 } else { 188 $editstr .= '<img src="'.$CFG->pixpath.'/spacer.gif" alt="" class="iconsmall" /> '; 189 } 190 191 /// Move down 192 if ($category->sortorder < $categorycount) { 193 $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$category->id.'&action=movecategory&dir=down&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" class="iconsmall" /></a> '; 194 } else { 195 $editstr .= '<img src="'.$CFG->pixpath.'/spacer.gif" alt="" class="iconsmall" /> '; 196 } 197 198 return $editstr; 199 } 200 201 /** 202 * Create a string containing the editing icons for the user profile fields 203 * @param object the field object 204 * @return string the icon string 205 */ 206 function profile_field_icons ($field) { 207 global $CFG, $USER; 208 209 if (empty($str)) { 210 $strdelete = get_string('delete'); 211 $strmoveup = get_string('moveup'); 212 $strmovedown = get_string('movedown'); 213 $stredit = get_string('edit'); 214 } 215 216 $fieldcount = count_records('user_info_field', 'categoryid',$field->categoryid); 217 $datacount = count_records('user_info_data', 'fieldid', $field->id); 218 219 /// Edit 220 $editstr = '<a title="'.$stredit.'" href="index.php?id='.$field->id.'&action=editfield"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> '; 221 222 /// Delete 223 $editstr .= '<a title="'.$strdelete.'" href="index.php?id='.$field->id.'&action=deletefield'; 224 $editstr .= '"><img src="'.$CFG->pixpath.'/t/delete.gif" alt="'.$strdelete.'" class="iconsmall" /></a> '; 225 226 /// Move up 227 if ($field->sortorder > 1) { 228 $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$field->id.'&action=movefield&dir=up&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" class="iconsmall" /></a> '; 229 } else { 230 $editstr .= '<img src="'.$CFG->pixpath.'/spacer.gif" alt="" class="iconsmall" /> '; 231 } 232 233 /// Move down 234 if ($field->sortorder < $fieldcount) { 235 $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$field->id.'&action=movefield&dir=down&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" class="iconsmall" /></a> '; 236 } else { 237 $editstr .= '<img src="'.$CFG->pixpath.'/spacer.gif" alt="" class="iconsmall" /> '; 238 } 239 240 return $editstr; 241 } 242 243 244 ?>
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 |