示例#1
0
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_login(SITEID, false);
global $CFG, $PAGE, $OUTPUT, $DB;
require_once $CFG->dirroot . '/local/elisprogram/lib/lib.php';
require_once $CFG->dirroot . '/local/elisprogram/lib/selectionpopup.class.php';
require_once $CFG->dirroot . '/lib/weblib.php';
require_once $CFG->dirroot . '/lib/dml/moodle_database.php';
define('MAX_NUM_ROWS', 50);
$letterselect = optional_param('alpha', '', PARAM_TEXT);
$search = optional_param('search', '', PARAM_TEXT);
$element_update = required_param('id', PARAM_TEXT);
$callback = required_param('callback', PARAM_TEXT);
$baseurl = new moodle_url('/local/elisprogram/classselector.php', array('alpha' => $letterselect, 'search' => $search, 'id' => $element_update, 'callback' => $callback));
$PAGE->set_url($baseurl);
pmalphabox($baseurl);
pmsearchbox('/local/elisprogram/classselector.php');
echo html_writer::start_tag('center');
$alpha = explode(',', get_string('alphabet', 'langconfig'));
$table = new classselectiontable('classselection', $element_update, $callback);
$columns = 'cls.id,cd.syllabus,cls.idnumber';
$where = '';
$alphawhere = '';
$searchwhere = '';
$params = array();
if (!empty($letterselect)) {
    $alphawhere = $DB->sql_like('cd.syllabus', ':alphasyllabus', false) . ' OR ' . $DB->sql_like('cls.idnumber', ':alphaidnumber', false);
    $params['alphasyllabus'] = $letterselect . '%';
    $params['alphaidnumber'] = $letterselect . '%';
}
if (!empty($search)) {
示例#2
0
 /**
  * Return the HTML to for a view page that also allows editing.
  *
  * @param int $classid The class ID.
  * @param string $type The entity type.
  * @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 view_form_html($classid, $type = '', $sort = 'name', $dir = 'ASC', $page = 0, $perpage = 0, $namesearch = '', $alpha = '')
 {
     global $CFG, $OUTPUT, $PAGE, $SESSION;
     $pageid = optional_param('id', 1, PARAM_INT);
     $pagetype = optional_param('s', '', PARAM_ALPHA);
     $target = optional_param('action', '', PARAM_ALPHA);
     $pagename = $pagetype . $pageid . $target;
     $output = '';
     ob_start();
     $can_unenrol = pmclasspage::can_enrol_into_class($classid);
     if (empty($this->id)) {
         $columns = array('select' => array('header' => get_string('select'), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'unenrol' => array('header' => get_string('unenrol', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'idnumber' => array('header' => get_string('student_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('student_name_1', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'enrolmenttime' => array('header' => get_string('enrolment_time', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'completestatusid' => array('header' => get_string('student_status', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'grade' => array('header' => get_string('student_grade', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'credits' => array('header' => get_string('student_credits', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'edited' => array('header' => get_string('student_edited', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'));
         if (!$can_unenrol) {
             unset($columns['unenrol']);
         }
     } else {
         $columns = array('idnumber' => array('header' => get_string('student_idnumber', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'name' => array('header' => get_string('student_name_1', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), 'enrolmenttime' => array('header' => get_string('enrolment_time', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'completetime' => array('header' => get_string('completion_time', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'completestatusid' => array('header' => get_string('student_status', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'grade' => array('header' => get_string('student_grade', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'credits' => array('header' => get_string('student_credits', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'), 'locked' => array('header' => get_string('student_locked', self::LANG_FILE), 'sortable' => false, 'display_function' => 'htmltab_display_function'));
     }
     if ($dir !== 'DESC') {
         $dir = 'ASC';
     }
     if (isset($columns[$sort])) {
         $columns[$sort]['sortable'] = $dir;
     } else {
         $sort = 'name';
         $columns[$sort]['sortable'] = $dir;
     }
     $users = array();
     if (empty($this->id)) {
         $do_select_all = optional_param('do_select_all', '0', PARAM_CLEAN);
         if (!empty($do_select_all) && $do_select_all === '1') {
             // save all users as selected in session (user clicked "select all on all pages" button)
             $users = $this->get_users_enrolled($type, $sort, $dir, 0, 0, '', '');
             foreach ($users as $userid => $user) {
                 $SESSION->associationpage[$pagename][$userid] = new stdClass();
                 $SESSION->associationpage[$pagename][$userid]->id = $userid;
                 $SESSION->associationpage[$pagename][$userid]->selected = true;
                 $SESSION->associationpage[$pagename][$userid]->associd = $user->association_id;
             }
             echo get_string('success', self::LANG_FILE);
             die;
         } else {
             $users = $this->get_users_enrolled($type, $sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha);
             $usercount = $this->count_users_enrolled($type, $namesearch, $alpha);
         }
         pmalphabox(new moodle_url('/local/elisprogram/index.php', array('s' => 'stu', 'section' => 'curr', 'action' => 'bulkedit', 'id' => $classid, 'class' => $classid, 'perpage' => $perpage, 'search' => $namesearch, 'sort' => $sort, 'dir' => $dir)), 'alpha', get_string('lastname', self::LANG_FILE) . ':');
         $pagingbar = new paging_bar($usercount, $page, $perpage, "index.php?s=stu&section=curr&id={$classid}&class={$classid}&&action=bulkedit&" . "sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&stype={$type}" . "&search=" . urlencode($namesearch));
         // TBD: .'&'
         echo $OUTPUT->render($pagingbar);
         flush();
         pmsearchbox(null, 'search', 'get', get_string('show_all_users', self::LANG_FILE));
         // TBD: moved from below
     } else {
         $newuser = new stdClass();
         $newuser->name = '?';
         if ($user = new user($this->userid)) {
             $user->load();
             $newuser = $user->to_object();
             $newuser->name = $user->moodle_fullname();
         }
         $users[] = $newuser;
         $usercount = 0;
     }
     $has_users = is_array($users) && !empty($users) || $users instanceof Iterator && $users->valid() === true ? true : false;
     if (empty($this->id) && $has_users === false) {
         pmshowmatches($alpha, $namesearch);
         $table = null;
     } else {
         $stuobj = new student();
         $newarr = array();
         // $table->width = "100%"; // TBD
         $pmclass = new pmclass($classid);
         if (empty(elis::$config->local_elisprogram->force_unenrol_in_moodle)) {
             $mcourse = $pmclass->get_moodle_course_id();
             $ctx = $mcourse ? context_course::instance($mcourse) : 0;
         }
         foreach ($users as $user) {
             $selected = false;
             $locked = $user->locked;
             $credits = $user->credits;
             $grade = $user->grade;
             $status = $user->completestatusid;
             $enrolmenttime = $user->enrolmenttime;
             $completetime = $user->completetime;
             $unenrol = false;
             $changed = false;
             $selection = retrieve_session_selection_bulkedit($user->id, 'bulkedit');
             if ($selection) {
                 if (isset($selection->selected) && $selection->selected === true) {
                     $selected = $selection->selected;
                 }
                 if (isset($selection->unenrol) && $selection->unenrol === true) {
                     $unenrol = $selection->unenrol;
                 }
                 if (isset($selection->locked) && $selection->locked === true) {
                     $locked = $selection->locked;
                 }
                 if (isset($selection->credits)) {
                     $credits = $selection->credits;
                 }
                 if (isset($selection->grade)) {
                     $grade = $selection->grade;
                 }
                 if (isset($selection->status)) {
                     $status = $selection->status;
                 }
                 if (isset($selection->enrolment_date)) {
                     $enrolmenttime = pm_timestamp(0, 0, 0, $selection->enrolment_date->month, $selection->enrolment_date->day, $selection->enrolment_date->year);
                 }
                 if (isset($selection->completion_date)) {
                     $completetime = pm_timestamp(0, 0, 0, $selection->completion_date->month, $selection->completion_date->day, $selection->completion_date->year);
                 }
                 $changed = true;
             }
             $tabobj = new stdClass();
             foreach ($columns as $column => $cdesc) {
                 switch ($column) {
                     case 'select':
                         $tabobj->{$column} = '<input type="checkbox" onclick="select_item(' . $user->id . ')" name="users[' . $user->id . '][selected]" ' . 'value="1" id="selected' . $user->id . '" ' . ($selected ? 'checked="checked" ' : ' ') . 'onchange="proxy_select(' . $user->id . ')"/>';
                         break;
                     case 'unenrol':
                         if (!empty($mcourse)) {
                             $userobj = new user($user);
                             $muser = $userobj->get_moodleuser();
                             if (!empty($muser)) {
                                 $role_assignment_exists = $this->_db->record_exists_select('role_assignments', "userid = ? AND contextid = ? AND component != 'enrol_elis'", array($muser->id, $ctx->id));
                                 if ($role_assignment_exists) {
                                     // user is assigned a role other than via the elis
                                     // enrolment plugin
                                     $tabobj->{$column} = '';
                                     break;
                                 }
                             }
                         }
                         $tabobj->{$column} = '<input type="checkbox" id="unenrol' . $user->id . '" name="users[' . $user->id . '][unenrol]" ' . 'value="1" onchange="proxy_select(' . $user->id . ')" ' . ($unenrol ? 'checked="checked" ' : ' ') . '/>';
                         break;
                     case 'name':
                     case 'idnumber':
                     case 'description':
                         $tabobj->{$column} = $user->{$column};
                         break;
                     case 'enrolmenttime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][startday]', 'users[' . $user->id . '][startmonth]', 'users[' . $user->id . '][startyear]', $enrolmenttime, true, 'proxy_select(' . $user->id . ')');
                         break;
                     case 'completetime':
                         $tabobj->{$column} = cm_print_date_selector('users[' . $user->id . '][endday]', 'users[' . $user->id . '][endmonth]', 'users[' . $user->id . '][endyear]', $completetime, true, 'proxy_select(' . $user->id . ')');
                         break;
                     case 'completestatusid':
                         $choices = array();
                         foreach (student::$completestatusid_values as $key => $csidv) {
                             $choices[$key] = get_string($csidv, self::LANG_FILE);
                         }
                         $tabobj->{$column} = cm_choose_from_menu($choices, 'users[' . $user->id . '][completestatusid]', $status, '', 'proxy_select(' . $user->id . ')', '', true);
                         break;
                     case 'grade':
                         $tabobj->{$column} = '<input type="text" id="grade' . $user->id . '" id="locked' . $user->id . '" ' . 'name="users[' . $user->id . '][grade]" value="' . $grade . '" ' . 'size="5" onchange="proxy_select(' . $user->id . ')" />';
                         break;
                     case 'credits':
                         $tabobj->{$column} = '<input type="text" id="credits' . $user->id . '" name="users[' . $user->id . '][credits]" ' . 'value="' . $credits . '" size="5" onchange="proxy_select(' . $user->id . ')" />';
                         break;
                     case 'locked':
                         $tabobj->{$column} = '<input type="checkbox" id="locked' . $user->id . '" name="users[' . $user->id . '][locked]" value="1" ' . ($locked ? 'checked="checked" ' : ' ') . 'onchange="proxy_select(' . $user->id . ')" />' . '<input type="hidden" name="users[' . $user->id . '][idnumber]" value="' . $user->idnumber . '" />' . '<input type="hidden" id="associationid' . $user->id . '" name="users[' . $user->id . '][association_id]" ' . 'value="' . $user->association_id . '" />';
                         break;
                     case 'edited':
                         $tabobj->{$column} = '<input type="checkbox" name="users[' . $user->id . '][changed]" id="changed' . $user->id . '" ' . ($changed ? 'checked="checked" ' : ' ') . '/>';
                         break;
                     default:
                         $tabobj->{$column} = '';
                         break;
                 }
             }
             $newarr[] = $tabobj;
             // $table->data[] = $newarr;
         }
         // TBD: student_table() ???
         $table = new display_table($newarr, $columns, $this->get_base_url(), 'sort', 'dir', array('id' => 'selectiontbl', 'width' => '100%'));
     }
     unset($users);
     $ids_for_checkbox_selection = !empty($SESSION->associationpage[$pagename]) && is_array($SESSION->associationpage[$pagename]) ? array_keys($SESSION->associationpage[$pagename]) : array();
     print_ids_for_checkbox_selection($ids_for_checkbox_selection, $classid, 'stu', 'bulkedit');
     if (empty($this->id)) {
         echo '<form method="post" action="index.php?s=stu&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="updatemultiple_confirm" />' . "<br />\n";
         echo '<input type="hidden" name="sesskey" value="' . sesskey() . '"/>';
         echo $this->get_bulk_edit_ui();
     } else {
         echo '<form method="post" action="index.php?s=stu&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="updatemultiple" />' . "\n";
         echo '<input type="hidden" name="sesskey" value="' . sesskey() . '"/>';
         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?
         if (empty($this->id)) {
             $PAGE->requires->js('/local/elisprogram/js/classform_bulkedit.js');
             $numselected_allpages = !empty($SESSION->associationpage[$pagename]) ? count($SESSION->associationpage[$pagename]) : 0;
             $str_numchanged_allpages = get_string('numchanged_allpages', 'local_elisprogram', array('num' => '<span id="numselected_allpages">' . $numselected_allpages . '</span>'));
             echo '<div style="display:inline-block;width:100%">';
             echo '<span style="float:right;font-weight:bold">' . $str_numchanged_allpages . '</span>';
             echo '<input type="button" onclick="checkbox_select(true,\'[selected]\',\'selected\')" value="' . get_string('selectallonpage', self::LANG_FILE) . '" /> ';
             echo '<input type="button" onclick="do_select_all();" value="' . get_string('selectallonallpages', self::LANG_FILE) . '" /> ';
             echo '<input type="button" onclick="checkbox_select(false,\'[selected]\',\'selected\')" value="' . get_string('deselectallonpage', self::LANG_FILE) . '" /> ';
             echo '<input type="button" onclick="do_deselect_all();" value="' . get_string('deselectallonallpages', self::LANG_FILE) . '" /> ';
             echo '</div>';
         }
         echo $table->get_html();
     }
     if (isset($this->id)) {
         $elements = $this->pmclass->course->get_completion_elements();
         if (!empty($elements) && $elements->valid() === true) {
             $select = 'classid = ? AND userid = ? ';
             $grades = $this->_db->get_records_select(student_grade::TABLE, $select, array($this->classid, $this->userid), 'id', 'completionid,id,classid,userid,grade,locked,timegraded,timemodified');
             $columns = array('element' => array('header' => get_string('grade_element', self::LANG_FILE), 'display_function' => 'htmltab_display_function'), '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 = 'element';
                 // TBD
                 $columns[$sort]['sortable'] = $dir;
             }
             // $table->width = "100%"; // TBD
             $newarr = array();
             foreach ($elements as $element) {
                 $tabobj = new stdClass();
                 foreach ($columns as $column => $cdesc) {
                     switch ($column) {
                         case 'element':
                             if (isset($grades[$element->id])) {
                                 $name = 'element[' . $grades[$element->id]->id . ']';
                                 $value = $element->id;
                             } else {
                                 $name = 'newelement[' . $element->id . ']';
                                 $value = $element->id;
                             }
                             $tabobj->{$column} = '<input type="hidden" name="' . $name . '" ' . 'value="' . $value . '" />' . s($element->idnumber);
                             break;
                         case 'timegraded':
                             if (isset($grades[$element->id])) {
                                 $name = 'timegraded[' . $grades[$element->id]->id . ']';
                                 $value = $grades[$element->id]->timegraded;
                             } else {
                                 $name = 'newtimegraded[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = cm_print_date_selector($name . '[startday]', $name . '[startmonth]', $name . '[startyear]', $value, true);
                             break;
                         case 'grade':
                             if (isset($grades[$element->id])) {
                                 $name = 'grade[' . $grades[$element->id]->id . ']';
                                 $value = $grades[$element->id]->grade;
                             } else {
                                 $name = 'newgrade[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = '<input type="text" name="' . $name . '" ' . 'value="' . $value . '" size="5" />';
                             break;
                         case 'locked':
                             if (isset($grades[$element->id])) {
                                 $name = 'locked[' . $grades[$element->id]->id . ']';
                                 $value = $grades[$element->id]->locked;
                             } else {
                                 $name = 'newlocked[' . $element->id . ']';
                                 $value = 0;
                             }
                             $tabobj->{$column} = '<input type="checkbox" name="' . $name . '" ' . 'value="1" ' . ($value ? 'checked="checked"' : '') . '/>';
                             break;
                         default:
                             $tabobj->{$column} = '';
                             break;
                     }
                 }
                 $newarr[] = $tabobj;
                 // $table->data[] = $newarr;
             }
             // TBD: student_table() ???
             $table = new display_table($newarr, $columns, $this->get_base_url(), 'sort', 'dir', array('id' => 'wowwww'));
             if (!empty($table)) {
                 // TBD: $newarr or $table?
                 echo '<br />';
                 echo $table->get_html();
             }
         }
         unset($elements);
     }
     if ($has_users === true) {
         echo '<br /><input type="submit" value="' . get_string('save_enrolment_changes', self::LANG_FILE) . '">' . "\n";
     }
     $cancel_js = "document.location='index.php?s=stu&amp;section=curr&amp;action=default&amp;id={$classid}&amp;" . "sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;search=" . urlencode($namesearch) . "';";
     echo '<input type="button" onclick="' . $cancel_js . '" value="' . get_string('cancel') . '" />';
     echo '<input type="button" onclick="datapersist_do_reset()" value="' . get_string('reset') . '" />';
     echo '</form>' . "\n";
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
示例#3
0
 /**
  * Prints the 'All A B C ...' alphabetical filter bar.
  */
 public function print_alpha()
 {
     pmalphabox($this->url);
 }
示例#4
0
 /**
  * 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&amp;section=curr&amp;id={$classid}&amp;action=add&amp;" . "sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;" . "search=" . urlencode($namesearch));
         // TBD: .'&amp;'
         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&amp;section=curr&amp;id=' . $classid . '" >' . "\n";
         echo '<input type="hidden" name="action" value="savenew" />' . "\n";
     } else {
         echo '<form method="post" action="index.php?s=ins&amp;section=curr&amp;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&amp;section=curr&amp;id={$classid}&amp;action=add&amp;" . "sort={$sort}&amp;dir={$dir}&amp;perpage={$perpage}&amp;alpha={$alpha}&amp;" . "search=" . urlencode($namesearch));
         // TBD: .'&amp;'
         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;
 }
示例#5
0
 function print_selection_filter($filter)
 {
     $id = $this->required_param('id', PARAM_INT);
     pmalphabox(new moodle_url($this->_get_page_url(), array('s' => $this->pagename, 'id' => $id)), 'alpha', get_string('tag_name', self::LANG_FILE) . ':');
     pmsearchbox($this, 'search', 'get', get_string('show_all_users', self::LANG_FILE));
 }