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
25 $id = required_param('id', PARAM_INT
);
26 $dir = required_param('dir', PARAM_ALPHA
);
28 if (confirm_sesskey()) {
29 profile_move_category($id, $dir);
34 $id = required_param('id', PARAM_INT
);
35 $dir = required_param('dir', PARAM_ALPHA
);
37 if (confirm_sesskey()) {
38 profile_move_field($id, $dir);
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);
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();
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);
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();
79 $id = optional_param('id', 0, PARAM_INT
);
80 $datatype = optional_param('datatype', '', PARAM_ALPHA
);
82 profile_edit_field($id, $datatype, $redirect);
86 $id = optional_param('id', 0, PARAM_INT
);
88 profile_edit_category($id, $redirect);
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);
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
)) {
129 notify($strnofields);
132 } /// End of $categories foreach
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&action=editfield&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'));
150 admin_externalpage_print_footer();
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) {
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
);
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> ';
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> ';
181 $editstr .= '<img src="'.$CFG->pixpath
.'/spacer.gif" alt="" class="iconsmall" /> ';
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> ';
188 $editstr .= '<img src="'.$CFG->pixpath
.'/spacer.gif" alt="" class="iconsmall" /> ';
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> ';
195 $editstr .= '<img src="'.$CFG->pixpath
.'/spacer.gif" alt="" class="iconsmall" /> ';
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) {
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
);
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> ';
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> ';
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> ';
230 $editstr .= '<img src="'.$CFG->pixpath
.'/spacer.gif" alt="" class="iconsmall" /> ';
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> ';
237 $editstr .= '<img src="'.$CFG->pixpath
.'/spacer.gif" alt="" class="iconsmall" /> ';