function print_checkbox_selection($classid, $page, $target) { global $SESSION; $pagename = $page . $classid . $target; $baseurl = get_pm_url()->out_omit_querystring() . '?&id=' . $classid . '&s=' . $page . '&target=' . $target; echo '<input type="hidden" id="baseurl" value="' . $baseurl . '" /> '; if (isset($SESSION->associationpage[$pagename])) { $selectedcheckboxes = $SESSION->associationpage[$pagename]; if (is_array($selectedcheckboxes)) { $selection = array(); foreach ($selectedcheckboxes as $selectedcheckbox) { $record = json_decode($selectedcheckbox); $selection[] = $record->id; } $result = implode(',', $selection); echo '<input type="hidden" id="selected_checkboxes" value="' . $result . '" /> '; } } }
protected function get_base_url($withquerystring = true) { if ($withquerystring) { return get_pm_url(); } else { return get_pm_url()->out_omit_querystring(); } }
/** * Tests print_ids_for_checkbox_selection() * Tests printing out saved information for use by javascript. */ public function test_print_ids_for_checkbox_selection() { $page = 'test'; $classid = 1; $target = 'test'; $ids = array(1, 2, 3, 4, 5, 6, 7); ob_start(); print_ids_for_checkbox_selection($ids, $classid, $page, $target); $actual = ob_get_contents(); ob_end_clean(); $baseurl = get_pm_url()->out_omit_querystring() . '?&id=' . $classid . '&s=' . $page . '&target=' . $target; $expected = '<input type="hidden" id="baseurl" value="' . $baseurl . '" /> '; $expected .= '<input type="hidden" id="selfurl" value="' . qualified_me() . '" /> '; $expected .= '<input type="hidden" id="persist_ids_this_page" value="' . implode(',', $ids) . '" /> '; $this->assertEquals($expected, $actual); }
/** * 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; }
function create_selection_table($records, $baseurl) { return new waitlist_table($records, get_pm_url($baseurl)); }