MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / user / profile / index.php
blobce32ecf15665f6118900ac257f5a56386bb87276
1 <?php //$Id$
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');
8 admin_externalpage_setup('profilefields');
10 $action = optional_param('action', '', PARAM_ALPHA);
12 $redirect = $CFG->wwwroot.'/user/profile/index.php';
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');
21 /// Do we have any actions to perform before printing the header
23 switch ($action) {
24 case 'movecategory':
25 $id = required_param('id', PARAM_INT);
26 $dir = required_param('dir', PARAM_ALPHA);
28 if (confirm_sesskey()) {
29 profile_move_category($id, $dir);
31 redirect($redirect);
32 break;
33 case 'movefield':
34 $id = required_param('id', PARAM_INT);
35 $dir = required_param('dir', PARAM_ALPHA);
37 if (confirm_sesskey()) {
38 profile_move_field($id, $dir);
40 redirect($redirect);
41 break;
42 case 'deletecategory':
43 $id = required_param('id', PARAM_INT);
44 $confirm = optional_param('confirm', 0, PARAM_BOOL);
46 if (data_submitted() and $confirm and confirm_sesskey()) {
47 profile_delete_category($id);
48 redirect($redirect);
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);
64 if (data_submitted() and $confirm and confirm_sesskey()) {
65 profile_delete_field($id);
66 redirect($redirect);
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);
82 profile_edit_field($id, $datatype, $redirect);
83 die;
84 break;
85 case 'editcategory':
86 $id = optional_param('id', 0, PARAM_INT);
88 profile_edit_category($id, $redirect);
89 die;
90 break;
91 default:
92 //normal form
95 /// Print the header
96 admin_externalpage_print_header();
97 print_heading(get_string('profilefields', 'admin'));
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);
108 /// Show all categories
109 $categories = get_records_select('user_info_category', '', 'sortorder ASC');
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();
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));
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);
132 } /// End of $categories foreach
137 echo '<hr />';
138 echo '<div class="profileeditor">';
140 /// Create a new field link
141 $options = profile_list_datatypes();
142 popup_form($CFG->wwwroot.'/user/profile/index.php?id=0&amp;action=editfield&amp;datatype=', $options, 'newfieldform','','choose','','',false,'self',$strcreatefield);
144 /// Create a new category link
145 $options = array('action'=>'editcategory');
146 print_single_button('index.php', $options, get_string('profilecreatecategory', 'admin'));
148 echo '</div>';
150 admin_externalpage_print_footer();
151 die;
154 /***** Some functions relevant to this script *****/
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
161 function profile_category_icons ($category) {
162 global $CFG, $USER;
164 $strdelete = get_string('delete');
165 $strmoveup = get_string('moveup');
166 $strmovedown = get_string('movedown');
167 $stredit = get_string('edit');
169 $categorycount = count_records('user_info_category');
170 $fieldcount = count_records('user_info_field', 'categoryid', $category->id);
172 /// Edit
173 $editstr = '<a title="'.$stredit.'" href="index.php?id='.$category->id.'&amp;action=editcategory"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
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.'&amp;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" /> ';
184 /// Move up
185 if ($category->sortorder > 1) {
186 $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$category->id.'&amp;action=movecategory&amp;dir=up&amp;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" /> ';
191 /// Move down
192 if ($category->sortorder < $categorycount) {
193 $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$category->id.'&amp;action=movecategory&amp;dir=down&amp;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" /> ';
198 return $editstr;
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
206 function profile_field_icons ($field) {
207 global $CFG, $USER;
209 if (empty($str)) {
210 $strdelete = get_string('delete');
211 $strmoveup = get_string('moveup');
212 $strmovedown = get_string('movedown');
213 $stredit = get_string('edit');
216 $fieldcount = count_records('user_info_field', 'categoryid',$field->categoryid);
217 $datacount = count_records('user_info_data', 'fieldid', $field->id);
219 /// Edit
220 $editstr = '<a title="'.$stredit.'" href="index.php?id='.$field->id.'&amp;action=editfield"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
222 /// Delete
223 $editstr .= '<a title="'.$strdelete.'" href="index.php?id='.$field->id.'&amp;action=deletefield';
224 $editstr .= '"><img src="'.$CFG->pixpath.'/t/delete.gif" alt="'.$strdelete.'" class="iconsmall" /></a> ';
226 /// Move up
227 if ($field->sortorder > 1) {
228 $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$field->id.'&amp;action=movefield&amp;dir=up&amp;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" /> ';
233 /// Move down
234 if ($field->sortorder < $fieldcount) {
235 $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$field->id.'&amp;action=movefield&amp;dir=down&amp;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" /> ';
240 return $editstr;