Example #1
0
 function display_default()
 {
     global $CFG, $DB, $OUTPUT;
     $level = $this->required_param('level', PARAM_ACTION);
     if (!($ctxlvl = \local_eliscore\context\helper::get_level_from_name($level))) {
         print_error('invalid_context_level', 'local_elisprogram');
     }
     $tmppage = new moodle_url($this->url);
     $tabs = array();
     $contextlevels = \local_eliscore\context\helper::get_legacy_levels();
     foreach ($contextlevels as $contextlevel => $val) {
         $tmppage->param('level', $contextlevel);
         $tabs[] = new tabobject($contextlevel, $tmppage->out(), get_string($contextlevel, 'local_elisprogram'));
     }
     print_tabs(array($tabs), $level);
     $fields = field::get_for_context_level($ctxlvl);
     $fields = $fields ? $fields : array();
     $categories = field_category::get_for_context_level($ctxlvl);
     $categories = $categories ? $categories : array();
     // divide the fields into categories
     $category_names = array();
     $fieldsbycategory = array();
     foreach ($categories as $category) {
         $category_names[$category->id] = $category->name;
         $fieldsbycategory[$category->id] = array();
     }
     foreach ($fields as $field) {
         $fieldsbycategory[$field->categoryid][] = $field;
     }
     $deletetxt = get_string('delete');
     $edittxt = get_string('edit');
     $syncerr = false;
     if (empty($category_names)) {
         echo $OUTPUT->heading(get_string('field_no_categories_defined', 'local_elisprogram'));
     }
     foreach ($fieldsbycategory as $categoryid => $fields) {
         $categorypage = new moodle_url($this->url);
         $categorypage->params(array('action' => 'deletecategory', 'id' => $categoryid, 'level' => $level));
         $deletelink = $categorypage->out();
         $categorypage->param('action', 'editcategory');
         $editlink = $categorypage->out();
         if (isset($category_names[$categoryid])) {
             echo "<h2>{$category_names[$categoryid]} ";
             echo "<a href=\"{$editlink}\" class=\"elisicon elisicon-edit\" alt=\"{$edittxt}\" title=\"{$edittxt}\"></a>";
             echo "<a href=\"{$deletelink}\" class=\"elisicon elisicon-remove\" alt=\"{$deletetxt}\" title=\"{$deletetxt}\"></a>";
             echo "</h2>\n";
         }
         if (empty($fields)) {
             print_string('field_no_fields_defined', 'local_elisprogram');
         } else {
             if ($level == 'user') {
                 require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
                 $table = new customuserfieldtable($fields, array('name' => array('header' => get_string('name')), 'datatype' => array('header' => get_string('field_datatype', 'local_elisprogram')), 'syncwithmoodle' => array('header' => get_string('field_syncwithmoodle', 'local_elisprogram')), 'buttons' => array('header' => '')), $this->url);
             } else {
                 $table = new customfieldtable($fields, array('name' => array('header' => get_string('name')), 'datatype' => array('header' => 'Data type'), 'buttons' => array('header' => '')), $this->url);
             }
             echo $table->get_html();
             $syncerr = $syncerr || !empty($table->syncerr);
         }
     }
     if ($syncerr) {
         print_string('moodle_field_sync_warning', 'local_elisprogram');
     }
     // button for new category
     $options = array('s' => 'field', 'action' => 'editcategory', 'level' => $level);
     $button = new single_button(new moodle_url('index.php', $options), get_string('field_create_category', 'local_elisprogram'), 'get', array('disabled' => false, 'title' => get_string('field_create_category', 'local_elisprogram'), 'id' => ''));
     echo $OUTPUT->render($button);
     if (!empty($category_names)) {
         if ($level == 'user') {
             // create new field from Moodle field
             $sql = 'shortname NOT IN
                     (SELECT shortname FROM {' . field::TABLE . '} ef
                     INNER JOIN {' . field_contextlevel::TABLE . '} cl
                     ON ef.id = cl.fieldid WHERE cl.contextlevel = :contextlevel)';
             $moodlefields = $DB->get_records_select('user_info_field', $sql, array('contextlevel' => $ctxlvl, 'sortorder' => 'id,name'));
             $moodlefields = $moodlefields ? $moodlefields : array();
             $tmppage->param('action', 'editfield');
             $tmppage->param('from', 'moodle');
             $tmppage->param('level', 'user');
             echo '<div>';
             //popup_form("{$tmppage->url}&amp;id=",
             //           array_map(create_function('$x', 'return $x->name;'), $moodlefields),
             //           'frommoodleform', '', 'choose', '', '', false, 'self', get_string('field_from_moodle', 'local_elisprogram'));
             $actionurl = new moodle_url($tmppage->out());
             $single_select = new single_select($actionurl, 'id', array_map(create_function('$x', 'return $x->name;'), $moodlefields), null, array('' => get_string('field_from_moodle', 'local_elisprogram')));
             echo $OUTPUT->render($single_select);
             echo '</div>';
             $options = array('s' => 'field', 'action' => 'forceresync');
             $button = new single_button(new moodle_url('index.php', $options), get_string('field_force_resync', 'local_elisprogram'), 'get', array('disabled' => false, 'title' => get_string('field_force_resync', 'local_elisprogram'), 'id' => ''));
             echo $OUTPUT->render($button);
         } else {
             // create new field from scratch
             $options = array('s' => 'field', 'action' => 'editfield', 'level' => $level);
             $button = new single_button(new moodle_url('index.php', $options), get_string('field_create_new', 'local_elisprogram'), 'get', array('disabled' => false, 'title' => get_string('field_create_new', 'local_elisprogram'), 'id' => ''));
             echo $OUTPUT->render($button);
         }
     }
 }