/** * 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 $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. * * @return string The form HTML, without the form. */ function edit_form_html($classid, $sort = 'name', $dir = 'ASC', $page = 0, $perpage = 0, $namesearch = '', $alpha = '') { global $CFG; $output = ''; ob_start(); $table = new stdClass(); if (empty($this->id)) { $columns = array('assign' => 'Assign', 'idnumber' => 'ID Number', 'name' => 'Name', 'assigntime' => 'Assigned Time', 'completetime' => 'Completion Time'); } else { $columns = array('idnumber' => 'ID Number', 'name' => 'Name', 'assigntime' => 'Assigned Time', 'completetime' => 'Completion Time'); } foreach ($columns as $column => $cdesc) { if ($sort != $column) { $columnicon = ""; $columndir = "ASC"; } else { $columndir = $dir == "ASC" ? "DESC" : "ASC"; $columnicon = $dir == "ASC" ? "down" : "up"; $columnicon = " <img src=\"{$CFG->pixpath}/t/{$columnicon}.gif\" alt=\"\" />"; } if ($column == 'name' || $column == 'description') { ${$column} = "<a href=\"index.php?s=ins&section=curr&id={$classid}&" . "action=add&sort={$column}&dir={$columndir}&search=" . urlencode(stripslashes($namesearch)) . "&alpha={$alpha}\">" . $cdesc . "</a>{$columnicon}"; } else { ${$column} = $cdesc; } $table->head[] = ${$column}; $table->align[] = "left"; $table->wrap[] = true; } if (empty($this->id)) { $users = $this->get_users_avail($sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha); $usercount = $this->count_users_avail($namesearch, $alpha); $alphabet = explode(',', get_string('alphabet')); $strall = get_string('all'); /// Bar of first initials echo "<p style=\"text-align:center\">"; echo get_string('tag_name', 'block_curr_admin') . " : "; if ($alpha) { echo " <a href=\"index.php?s=ins&section=curr&action=add&id={$classid}&" . "sort=name&dir=ASC&perpage={$perpage}\">{$strall}</a> "; } else { echo " <b>{$strall}</b> "; } foreach ($alphabet as $letter) { if ($letter == $alpha) { echo " <b>{$letter}</b> "; } else { echo " <a href=\"index.php?s=ins&section=curr&action=add&id={$classid}&" . "sort=name&dir=ASC&perpage={$perpage}&alpha={$letter}\">{$letter}</a> "; } } echo "</p>"; print_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(stripslashes($namesearch)) . "&"); flush(); } else { $user = $this->user; $user->name = cm_fullname($this->user); $users[] = $user; $usercount = 0; } if (empty($this->id) && !$users) { $match = array(); if ($namesearch !== '') { $match[] = s($namesearch); } if ($alpha) { $match[] = 'name' . ": {$alpha}" . "___"; } $matchstring = implode(", ", $match); echo get_string('no_users_matching', 'block_curr_admin') . $matchstring; $table = NULL; } else { $insobj = new instructor(); $table->width = "100%"; foreach ($users as $user) { $newarr = array(); foreach ($columns as $column => $cdesc) { switch ($column) { case 'assign': $newarr[] = '<input type="checkbox" name="users[' . $user->id . '][assign]" value="1" />' . '<input type="hidden" name="users[' . $user->id . '][idnumber]" ' . 'value="' . $user->idnumber . '" />'; break; case 'name': case 'idnumber': case 'description': $newarr[] = $user->{$column}; break; case 'assigntime': $newarr[] = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $this->assigntime, true); break; case 'completetime': $newarr[] = cm_print_date_selector('users[' . $user->id . '][endday]', 'users[' . $user->id . '][endmonth]', 'users[' . $user->id . '][endyear]', $this->completetime, true); break; default: $newarr[] = ''; break; } } $table->data[] = $newarr; } } if (empty($this->id)) { echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"index.php\" method=\"get\"><fieldset>"; echo '<input type="hidden" name="s" value="ins" />'; echo '<input type="hidden" name="section" value="curr" />'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="id" value="' . $classid . '" />'; echo '<input type="hidden" name="sort" value="' . $sort . '" />'; echo '<input type="hidden" name="dir" value="' . $dir . '" />'; echo "<input type=\"text\" name=\"search\" value=\"" . s($namesearch, true) . "\" size=\"20\" />"; echo "<input type=\"submit\" value=\"" . get_string('search', 'block_curr_admin') . "\" />"; if ($namesearch) { echo "<input type=\"button\" onclick=\"document.location='index.php?s=ins&section=curr&" . "action=add&id={$classid}';\" value=\"" . get_string('show_all_users', 'block_curr_admin') . "\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; 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)) { print_table($table); print_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(stripslashes($namesearch)) . "&"); } if (empty($this->id)) { echo '<br /><input type="submit" value="' . get_string('assign_selected', 'block_curr_admin') . '">' . "\n"; } else { echo '<br /><input type="submit" value="' . get_string('update_assignment', 'block_curr_admin') . '">' . "\n"; } echo '</form>' . "\n"; $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * 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. * * @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 = ''; ob_start(); $table = new stdClass(); $columns = array('grade' => 'Grade', 'locked' => 'Locked', 'timegraded' => 'Date Graded'); foreach ($columns as $column => $cdesc) { if ($sort != $column) { $columnicon = ""; $columndir = "ASC"; } else { $columndir = $dir == "ASC" ? "DESC" : "ASC"; $columnicon = $dir == "ASC" ? "down" : "up"; $columnicon = " <img src=\"{$CFG->pixpath}/t/{$columnicon}.gif\" alt=\"\" />"; } if ($column == 'name' || $column == 'description') { ${$column} = "<a href=\"index.php?s=stu&section=curr&class={$classid}&" . "action=add&sort={$column}&dir={$columndir}&stype={$type}&search=" . urlencode(stripslashes($namesearch)) . "&alpha={$alpha}\">" . $cdesc . "</a>{$columnicon}"; } else { ${$column} = $cdesc; } $table->head[] = ${$column}; $table->align[] = "left"; $table->wrap[] = true; } $table->width = "100%"; $newarr = array(); foreach ($columns as $column => $cdesc) { switch ($column) { case 'timegraded': $newarr[] = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $this->timegraded, true); break; case 'grade': $newarr[] = '<input type="text" name="users[' . $user->id . '][grade]" ' . 'value="' . $this->grade . '" size="5" />'; break; case 'locked': $newarr[] = '<input type="checkbox" name="users[' . $user->id . '][locked]" ' . 'value="1" ' . ($this->locked ? 'checked="checked"' : '') . '/>'; break; default: $newarr[] = ''; break; } $table->data[] = $newarr; } if (empty($this->id)) { echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"index.php\" method=\"get\"><fieldset>"; echo '<input type="hidden" name="s" value="stu" />'; echo '<input type="hidden" name="section" value="curr" />'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="class" value="' . $classid . '" />'; echo '<input type="hidden" name="sort" value="' . $sort . '" />'; echo '<input type="hidden" name="dir" value="' . $dir . '" />'; echo '<input type="radio" name="stype" value="student" ' . ($type == 'student' ? ' checked' : '') . '/> Students ' . '<input type="radio" name="stype" value="instructor" ' . ($type == 'instructor' ? ' checked' : '') . '/> Instructors ' . '<input type="radio" name="stype" vale="" ' . ($type == '' ? ' checked' : '') . '/> All '; echo "<input type=\"text\" name=\"search\" value=\"" . s($namesearch, true) . "\" size=\"20\" />"; echo "<input type=\"" . get_string('search', 'block_curr_admin') . "\" value=\"Search\" />"; if ($namesearch) { echo "<input type=\"button\" onclick=\"document.location='index.php?s=stu&section=curr&" . "action=add&id={$classid}';\" value=\"Show All Users\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; 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($table)) { print_table($table); } if (empty($this->id)) { echo '<br /><input type="submit" value="' . get_string('add_grade', 'block_curr_admin') . '">' . "\n"; } else { echo '<br /><input type="submit" value="' . get_string('update_grade', 'block_curr_admin') . '">' . "\n"; } echo '</form>' . "\n"; $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * 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; }