Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/profile/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require('../../config.php');
00004 require_once($CFG->libdir.'/adminlib.php');
00005 require_once($CFG->dirroot.'/user/profile/lib.php');
00006 require_once($CFG->dirroot.'/user/profile/definelib.php');
00007 
00008 admin_externalpage_setup('profilefields');
00009 
00010 $action   = optional_param('action', '', PARAM_ALPHA);
00011 
00012 $redirect = $CFG->wwwroot.'/user/profile/index.php';
00013 
00014 $strchangessaved    = get_string('changessaved');
00015 $strcancelled       = get_string('cancelled');
00016 $strdefaultcategory = get_string('profiledefaultcategory', 'admin');
00017 $strnofields        = get_string('profilenofieldsdefined', 'admin');
00018 $strcreatefield     = get_string('profilecreatefield', 'admin');
00019 
00020 
00022 
00023 switch ($action) {
00024     case 'movecategory':
00025         $id  = required_param('id', PARAM_INT);
00026         $dir = required_param('dir', PARAM_ALPHA);
00027 
00028         if (confirm_sesskey()) {
00029             profile_move_category($id, $dir);
00030         }
00031         redirect($redirect);
00032         break;
00033     case 'movefield':
00034         $id  = required_param('id', PARAM_INT);
00035         $dir = required_param('dir', PARAM_ALPHA);
00036 
00037         if (confirm_sesskey()) {
00038             profile_move_field($id, $dir);
00039         }
00040         redirect($redirect);
00041         break;
00042     case 'deletecategory':
00043         $id      = required_param('id', PARAM_INT);
00044         profile_delete_category($id);
00045         redirect($redirect,get_string('deleted'));
00046         break;
00047     case 'deletefield':
00048         $id      = required_param('id', PARAM_INT);
00049         $confirm = optional_param('confirm', 0, PARAM_BOOL);
00050 
00051         $datacount = $DB->count_records('user_info_data', array('fieldid'=>$id));
00052         if (data_submitted() and ($confirm and confirm_sesskey()) or $datacount===0) {
00053             profile_delete_field($id);
00054             redirect($redirect,get_string('deleted'));
00055         }
00056 
00057         //ask for confirmation
00058         $fieldname = $DB->get_field('user_info_field', 'name', array('id'=>$id));
00059         $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletefield', 'sesskey'=>sesskey());
00060         $strheading = get_string('profiledeletefield', 'admin', $fieldname);
00061         $PAGE->navbar->add($strheading);
00062         echo $OUTPUT->header();
00063         echo $OUTPUT->heading($strheading);
00064         $formcontinue = new single_button(new moodle_url($redirect, $optionsyes), get_string('yes'), 'post');
00065         $formcancel = new single_button(new moodle_url($redirect), get_string('no'), 'get');
00066         echo $OUTPUT->confirm(get_string('profileconfirmfielddeletion', 'admin', $datacount), $formcontinue, $formcancel);
00067         echo $OUTPUT->footer();
00068         die;
00069         break;
00070     case 'editfield':
00071         $id       = optional_param('id', 0, PARAM_INT);
00072         $datatype = optional_param('datatype', '', PARAM_ALPHA);
00073 
00074         profile_edit_field($id, $datatype, $redirect);
00075         die;
00076         break;
00077     case 'editcategory':
00078         $id = optional_param('id', 0, PARAM_INT);
00079 
00080         profile_edit_category($id, $redirect);
00081         die;
00082         break;
00083     default:
00084         //normal form
00085 }
00086 
00088 echo $OUTPUT->header();
00089 echo $OUTPUT->heading(get_string('profilefields', 'admin'));
00090 
00092 if ($DB->count_records('user_info_category') == 0) {
00093     $defaultcategory = new stdClass();
00094     $defaultcategory->name = $strdefaultcategory;
00095     $defaultcategory->sortorder = 1;
00096     $DB->insert_record('user_info_category', $defaultcategory);
00097     redirect($redirect);
00098 }
00099 
00101 $categories = $DB->get_records('user_info_category', null, 'sortorder ASC');
00102 
00103 foreach ($categories as $category) {
00104     $table = new html_table();
00105     $table->head  = array(get_string('profilefield', 'admin'), get_string('edit'));
00106     $table->align = array('left', 'right');
00107     $table->width = '95%';
00108     $table->attributes['class'] = 'generaltable profilefield';
00109     $table->data = array();
00110 
00111     if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
00112         foreach ($fields as $field) {
00113             $table->data[] = array(format_string($field->name), profile_field_icons($field));
00114         }
00115     }
00116 
00117     echo $OUTPUT->heading(format_string($category->name) .' '.profile_category_icons($category));
00118     if (count($table->data)) {
00119         echo html_writer::table($table);
00120     } else {
00121         echo $OUTPUT->notification($strnofields);
00122     }
00123 
00124 } 
00125 
00126 
00127 
00128 
00129 echo '<hr />';
00130 echo '<div class="profileeditor">';
00131 
00133 $options = profile_list_datatypes();
00134 $popupurl = new moodle_url('/user/profile/index.php?id=0&action=editfield');
00135 echo $OUTPUT->single_select($popupurl, 'datatype', $options, '', array(''=>$strcreatefield), 'newfieldform');
00136 
00137 //add a div with a class so themers can hide, style or reposition the text
00138 html_writer::start_tag('div',array('class'=>'adminuseractionhint'));
00139 echo get_string('or', 'lesson');
00140 html_writer::end_tag('div');
00141 
00143 $options = array('action'=>'editcategory');
00144 echo $OUTPUT->single_button(new moodle_url('index.php', $options), get_string('profilecreatecategory', 'admin'));
00145 
00146 echo '</div>';
00147 
00148 echo $OUTPUT->footer();
00149 die;
00150 
00151 
00152 /***** Some functions relevant to this script *****/
00153 
00159 function profile_category_icons($category) {
00160     global $CFG, $USER, $DB, $OUTPUT;
00161 
00162     $strdelete   = get_string('delete');
00163     $strmoveup   = get_string('moveup');
00164     $strmovedown = get_string('movedown');
00165     $stredit     = get_string('edit');
00166 
00167     $categorycount = $DB->count_records('user_info_category');
00168     $fieldcount    = $DB->count_records('user_info_field', array('categoryid'=>$category->id));
00169 
00171     $editstr = '<a title="'.$stredit.'" href="index.php?id='.$category->id.'&amp;action=editcategory"><img src="'.$OUTPUT->pix_url('t/edit') . '" alt="'.$stredit.'" class="iconsmall" /></a> ';
00172 
00175     if ( ($categorycount > 1) or ($fieldcount == 0) ) {
00176         $editstr .= '<a title="'.$strdelete.'" href="index.php?id='.$category->id.'&amp;action=deletecategory';
00177         $editstr .= '"><img src="'.$OUTPUT->pix_url('t/delete') . '" alt="'.$strdelete.'" class="iconsmall" /></a> ';
00178     } else {
00179         $editstr .= '<img src="'.$OUTPUT->pix_url('spacer') . '" alt="" class="iconsmall" /> ';
00180     }
00181 
00183     if ($category->sortorder > 1) {
00184         $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$category->id.'&amp;action=movecategory&amp;dir=up&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/up') . '" alt="'.$strmoveup.'" class="iconsmall" /></a> ';
00185     } else {
00186         $editstr .= '<img src="'.$OUTPUT->pix_url('spacer') . '" alt="" class="iconsmall" /> ';
00187     }
00188 
00190     if ($category->sortorder < $categorycount) {
00191         $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$category->id.'&amp;action=movecategory&amp;dir=down&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/down') . '" alt="'.$strmovedown.'" class="iconsmall" /></a> ';
00192     } else {
00193         $editstr .= '<img src="'.$OUTPUT->pix_url('spacer') . '" alt="" class="iconsmall" /> ';
00194     }
00195 
00196     return $editstr;
00197 }
00198 
00204 function profile_field_icons($field) {
00205     global $CFG, $USER, $DB, $OUTPUT;
00206 
00207     $strdelete   = get_string('delete');
00208     $strmoveup   = get_string('moveup');
00209     $strmovedown = get_string('movedown');
00210     $stredit     = get_string('edit');
00211 
00212     $fieldcount = $DB->count_records('user_info_field', array('categoryid'=>$field->categoryid));
00213     $datacount  = $DB->count_records('user_info_data', array('fieldid'=>$field->id));
00214 
00216     $editstr = '<a title="'.$stredit.'" href="index.php?id='.$field->id.'&amp;action=editfield"><img src="'.$OUTPUT->pix_url('t/edit') . '" alt="'.$stredit.'" class="iconsmall" /></a> ';
00217 
00219     $editstr .= '<a title="'.$strdelete.'" href="index.php?id='.$field->id.'&amp;action=deletefield';
00220     $editstr .= '"><img src="'.$OUTPUT->pix_url('t/delete') . '" alt="'.$strdelete.'" class="iconsmall" /></a> ';
00221 
00223     if ($field->sortorder > 1) {
00224         $editstr .= '<a title="'.$strmoveup.'" href="index.php?id='.$field->id.'&amp;action=movefield&amp;dir=up&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/up') . '" alt="'.$strmoveup.'" class="iconsmall" /></a> ';
00225      } else {
00226         $editstr .= '<img src="'.$OUTPUT->pix_url('spacer') . '" alt="" class="iconsmall" /> ';
00227     }
00228 
00230     if ($field->sortorder < $fieldcount) {
00231         $editstr .= '<a title="'.$strmovedown.'" href="index.php?id='.$field->id.'&amp;action=movefield&amp;dir=down&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/down') . '" alt="'.$strmovedown.'" class="iconsmall" /></a> ';
00232     } else {
00233         $editstr .= '<img src="'.$OUTPUT->pix_url('spacer') . '" alt="" class="iconsmall" /> ';
00234     }
00235 
00236     return $editstr;
00237 }
00238 
00239 
00240 
 All Data Structures Namespaces Files Functions Variables Enumerations