/** * Return the HTML to edit a specific student. * This could be extended to allow for application specific editing, for example * a Moodle interface to its formslib. * * @param $formid string A suffix to put on all 'id' and index for all 'name' attributes. * This should be unique if being used more than once in a form. * @param $extraclass string Any extra class information to add to the output. * @uses $CFG * @uses $OUTPUT * @return string The form HTML, without the form. */ function edit_form_html($classid, $type = '', $sort = 'name', $dir = 'ASC', $page = 0, $perpage = 0, $namesearch = '', $alpha = '') { global $CFG, $OUTPUT; $output = ''; ob_start(); $columns = array('grade' => array('header' => get_string('grade', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'timegraded' => array('header' => get_string('date_graded', self::LANG_FILE), 'display_function' => 'htmltab_display_function')); if ($dir !== 'DESC') { $dir = 'ASC'; } if (isset($columns[$sort])) { $columns[$sort]['sortable'] = $dir; } else { $sort = 'grade'; // TBD $columns[$sort]['sortable'] = $dir; } //$table->width = "100%"; // TBD $newarr = array(); $tabobj = new stdClass(); foreach ($columns as $column => $cdesc) { switch ($column) { case 'timegraded': $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $this->timegraded, true); break; case 'grade': $tabobj->{$column} = '<input type="text" name="users[' . $user->id . '][grade]" ' . 'value="' . $this->grade . '" size="5" />'; break; case 'locked': $tabobj->{$column} = '<input type="checkbox" name="users[' . $user->id . '][locked]" ' . 'value="1" ' . ($this->locked ? 'checked="checked"' : '') . '/>'; break; default: $tabobj->{$column} = ''; break; } //$table->data[] = $newarr; } $newarr[] = $tabobj; // TBD: student_table() ??? $table = new display_table($newarr, $columns, $this->get_base_url()); if (empty($this->id)) { // TBD: move up and add pmalphabox() and pmshowmatches() ??? pmsearchbox(null, 'search', 'get', get_string('show_all_users', self::LANG_FILE), '<input type="radio" name="stype" value="student" ' . ($type == 'student' ? ' checked' : '') . '/> ' . get_string('students', self::LANG_FILE) . ' <input type="radio" name="stype" value="instructor" ' . ($type == 'instructor' ? ' checked' : '') . '/> ' . get_string('instructors', self::LANG_FILE) . ' <input type="radio" name="stype" vale="" ' . ($type == '' ? ' checked' : '') . '/> ' . get_string('all') . ' '); echo '<form method="post" action="index.php?s=stu&section=curr&class=' . $classid . '" >' . "\n"; echo '<input type="hidden" name="action" value="savenew" />' . "\n"; } else { echo '<form method="post" action="index.php?s=stu&section=curr&class=' . $classid . '" >' . "\n"; echo '<input type="hidden" name="action" value="update" />' . "\n"; echo '<input type="hidden" name="association_id" value="' . $this->id . '" />' . "\n"; echo '<input type="hidden" name="id" value="' . $this->classid . '" />' . "\n"; echo '<input type="hidden" name="userid" value="' . $this->userid . '" />' . "\n"; } if (!empty($newarr)) { // TBD: $newarr or $table? echo $table->get_html(); } if (empty($this->id)) { echo '<br /><input type="submit" value="' . get_string('add_grade', self::LANG_FILE) . '">' . "\n"; } else { echo '<br /><input type="submit" value="' . get_string('update_grade', self::LANG_FILE) . '">' . "\n"; } echo '</form>' . "\n"; $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Return the HTML to edit a specific instructor. * This could be extended to allow for application specific editing, for example * a Moodle interface to its formslib. * * @param int $classid The class ID. * @param string $sort Field to sort on. * @param string $dir Direction of sort. * @param int $page The page to start at. * @param int $perpage Number of records per page. * @param string $namesearch Search string for item name. * @param string $alpha Start initial of item name filter. * @return string The form HTML, without the form. */ public function edit_form_html($classid, $sort = 'name', $dir = 'ASC', $page = 0, $perpage = 30, $namesearch = '', $alpha = '') { global $CFG, $OUTPUT, $SESSION, $PAGE; $action = optional_param('action', '', PARAM_ALPHA); $this->classid = $classid; $output = ''; ob_start(); if (empty($this->id)) { $columns = array('assign' => array('header' => get_string('assign', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'idnumber' => array('header' => get_string('class_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('tag_name', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'assigntime' => array('header' => get_string('assigntime', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false)); } else { $columns = array('idnumber' => array('header' => get_string('class_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('tag_name', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'assigntime' => array('header' => get_string('assigntime', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'display_function' => 'htmltab_display_function', 'sortable' => false)); } if ($dir !== 'DESC') { $dir = 'ASC'; } if (isset($columns[$sort])) { $columns[$sort]['sortable'] = $dir; } else { $sort = 'name'; $columns[$sort]['sortable'] = $dir; } $newarr = array(); $users = array(); if (empty($this->id)) { $users = $this->get_users_avail($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha); $usercount = $this->count_users_avail($namesearch, $alpha); pmalphabox(new moodle_url('/local/elisprogram/index.php', array('s' => 'ins', 'section' => 'curr', 'action' => 'add', 'id' => $classid, 'sort' => $sort, 'dir' => $dir, 'perpage' => $perpage)), 'alpha', get_string('tag_name', self::LANG_FILE) . ':'); $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=ins&section=curr&id={$classid}&action=add&" . "sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&" . "search=" . urlencode($namesearch)); // TBD: .'&' echo $OUTPUT->render($pagingbar); flush(); } else { //error_log("instructor.class.php::edit_form_html(); userid = {$this->userid}"); $user = new stdClass(); $user->name = '?'; if ($tmpuser = new user($this->userid)) { $tmpuser->load(); $user = $tmpuser->to_object(); $user->name = $tmpuser->moodle_fullname(); } $users[] = $user; $usercount = 0; // TBD: 1 ??? } $has_users = is_array($users) && !empty($users) || $users instanceof Iterator && $users->valid() === true ? true : false; if (empty($this->id) && $has_users === false) { $table = NULL; } else { $insobj = new instructor(); //$table->width = "100%"; foreach ($users as $user) { $tabobj = new stdClass(); $assigntime = $this->assigntime; $completetime = $this->completetime; $selection = json_decode(retrieve_session_selection($user->id, 'add')); if ($selection) { $assigntime = pm_timestamp(0, 0, 0, $selection->enrolment_date->month, $selection->enrolment_date->day, $selection->enrolment_date->year); $completetime = pm_timestamp(0, 0, 0, $selection->completion_date->month, $selection->completion_date->day, $selection->completion_date->year); } /* **** debug code ob_start(); var_dump($user); $tmp = ob_get_contents(); ob_end_clean(); error_log("instructor.class.php::edit_form_html() user = $tmp"); **** */ foreach ($columns as $column => $cdesc) { switch ($column) { case 'assign': $tabobj->{$column} = '<input type="checkbox" id="checkbox' . $user->id . '" onClick="select_item(' . $user->id . ')" name="users[' . $user->id . '][assign]" value="1" ' . ($selection ? 'checked="checked"' : '') . '/>' . '<input type="hidden" name="users[' . $user->id . '][idnumber]" ' . 'value="' . $user->idnumber . '" />'; break; case 'name': case 'idnumber': case 'description': $tabobj->{$column} = $user->{$column}; break; case 'assigntime': $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $assigntime, true); break; case 'completetime': $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][endday]', 'users[' . $user->id . '][endmonth]', 'users[' . $user->id . '][endyear]', $completetime, true); break; default: $tabobj->{$column} = ''; break; } } $newarr[] = $tabobj; //$table->data[] = $newarr; } $table = new display_table($newarr, $columns, get_pm_url(), 'sort', 'dir', array('id' => 'selectiontbl')); } unset($users); print_checkbox_selection($classid, 'ins', 'add'); if (empty($this->id)) { pmsearchbox(null, 'search', 'get', get_string('show_all_users', self::LANG_FILE)); echo '<form method="post" action="index.php?s=ins&section=curr&id=' . $classid . '" >' . "\n"; echo '<input type="hidden" name="action" value="savenew" />' . "\n"; } else { echo '<form method="post" action="index.php?s=ins&section=curr&id=' . $classid . '" >' . "\n"; echo '<input type="hidden" name="action" value="update" />' . "\n"; echo '<input type="hidden" name="association_id" value="' . $this->id . '" />' . "\n"; echo '<input type="hidden" name="id" value="' . $this->classid . '" />' . "\n"; echo '<input type="hidden" name="userid" value="' . $this->userid . '" />' . "\n"; } if (!empty($table) && !empty($newarr)) { if ($action == 'add') { $PAGE->requires->js('/local/elisprogram/js/classform.js'); echo '<input type="button" onclick="checkbox_select(true,\'[assign]\')" value="' . get_string('selectall') . '" /> '; echo '<input type="button" onclick="checkbox_select(false,\'[assign]\')" value="' . get_string('deselectall') . '" /> '; } echo $table->get_html(); $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=ins&section=curr&id={$classid}&action=add&" . "sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&" . "search=" . urlencode($namesearch)); // TBD: .'&' echo $OUTPUT->render($pagingbar); } if (empty($this->id)) { if ($has_users === false) { pmshowmatches($alpha, $namesearch); } echo '<br /><input type="submit" value="' . get_string('assign_selected', self::LANG_FILE) . '">' . "\n"; } else { echo '<br /><input type="submit" value="' . get_string('update_assignment', self::LANG_FILE) . '">' . "\n"; } echo '</form>' . "\n"; $output = ob_get_contents(); ob_end_clean(); return $output; }
$row->field = $fieldname; $row->order = $moveupdown; $row->remove = $remove; $subtable_data[] = $row; // TBD *** //$subtable->rowclass[] = 'course_field_row select_all_row'; $count++; } } $subtable = new display_table($subtable_data, $subtable_head, $ME); $subtable->width = '75%'; // TBD $table_class = $report_name; // TBD $table = new display_table(array(), $table_head, $ME); // TBD echo $table->get_html(); echo $subtable->get_html(); // Now append our serialized fields to this output for the javascript to update the form echo ':' . $serialized_fieldidlist . ':' . $serialized_fieldnamelist . ':'; /* Do the serialize/unserialize trick to enable all the functionality of the class * @param object &$object object to fix * @return object $object fixed object */ function fix_object(&$object) { if (!is_object($object) && gettype($object) == 'object') { $object = unserialize(serialize($object)); } return $object; }
function get_completion_page($crsid) { global $CFG, $OUTPUT; $output = ''; $crs = new course($crsid); $table = new stdClass(); $elements = $crs->get_completion_elements(); if (!empty($elements) && $elements->valid() === true) { $columns = array('idnumber' => array('header' => get_string('completion_idnumber', 'local_elisprogram')), 'name' => array('header' => get_string('completion_name', 'local_elisprogram')), 'description' => array('header' => get_string('completion_description', 'local_elisprogram')), 'completion_grade' => array('header' => get_string('completion_grade', 'local_elisprogram')), 'required' => array('header' => get_string('required', 'local_elisprogram'))); if ($this->can_do_edit()) { $columns['actions'] = array('header' => '', 'display_function' => 'htmltab_display_function', 'sortable' => false); } foreach ($columns as $column => $cdesc) { $columndir = "ASC"; $columnicon = $columndir == "ASC" ? "down" : "up"; $columnicon = " <img src=\"" . $OUTPUT->pix_url('t/' . $columnicon) . "\" alt=\"\" />"; ${$column} = $cdesc; $table->head[] = ${$column}; $table->align[] = "left"; $table->wrap[] = false; } $table->head[] = ""; $table->align[] = "center"; $table->wrap[] = true; $newarr = array(); $editstr = get_string('edit'); $editiconattrs = array('class' => 'elisicon-edit elisicon', 'alt' => $editstr, 'title' => $editstr); $delstr = get_string('delete'); $deliconattrs = array('class' => 'elisicon-remove elisicon', 'alt' => $delstr, 'title' => $delstr); foreach ($elements as $element) { $editurl = 'index.php?s=crs§ion=curr&action=eelem&id=' . $crs->id . '&elemid=' . $element->id; $editbutton = html_writer::link($editurl, '', $editiconattrs); $delurl = 'index.php?s=crs§ion=curr&action=delem&id=' . $crs->id . '&elemid=' . $element->id; $deletebutton = html_writer::link($delurl, '', $deliconattrs); $newobj = new stdClass(); foreach ($columns as $column => $cdesc) { if ($column == 'required') { $newobj->required = empty($element->required) ? get_string('no') : get_string('yes'); } else { if ($column == 'actions') { $newobj->actions = $editbutton . ' ' . $deletebutton; } else { $newobj->{$column} = $element->{$column}; } } } $newarr[] = $newobj; } $table = new display_table($newarr, $columns); $output .= $table->get_html(); } else { $output .= '<div align="center">' . get_string('no_completion_elements', 'local_elisprogram') . '</div>'; } unset($elements); $output .= '<br clear="all" />' . "\n"; if ($this->can_do_edit()) { $options = array('s' => 'crs', 'section' => 'curr', 'action' => 'celem', 'id' => $crs->id); $addelement = get_string('add_element', 'local_elisprogram'); $button = new single_button(new moodle_url('index.php', $options), $addelement, 'get', array('disabled' => false, 'title' => $addelement, 'id' => '')); $output .= html_writer::tag('div', $OUTPUT->render($button), array('align' => 'center')); } return $output; }