function display() { $search = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); // TODO: with a little more work, we could keep the previously selected sort here $params = $_GET; unset($params['page']); // We want to go back to the first page unset($params['search']); // And clear the search $target = $this->page->get_new_page($params); echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"" . $target->get_url() . "\" method=\"post\">"; echo "<fieldset class=\"invisiblefieldset\">"; echo "<input type=\"text\" name=\"search\" value=\"" . s($search, true) . "\" size=\"20\" />"; echo '<input type="submit" value="' . get_string('search') . '" />'; //remove the "bare" parameter to prevent from loading only part of the page $moodleurl = new moodle_url($target->get_url()); $moodleurl->remove_params('mode'); if ($search) { echo "<input type=\"button\" onclick=\"document.location='" . $moodleurl->out() . "';\" " . "value=\"Show all items\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; }
/** * Customises the backup progress bar * * @global moodle_page $PAGE * @return array */ public function get_progress_bar() { global $PAGE; $stage = self::STAGE_COMPLETE; $currentstage = $this->stage->get_stage(); $items = array(); while ($stage > 0) { $classes = array('backup_stage'); if (floor($stage / 2) == $currentstage) { $classes[] = 'backup_stage_next'; } else { if ($stage == $currentstage) { $classes[] = 'backup_stage_current'; } else { if ($stage < $currentstage) { $classes[] = 'backup_stage_complete'; } } } $item = array('text' => strlen(decbin($stage * 2)) . '. ' . get_string('importcurrentstage' . $stage, 'backup'), 'class' => join(' ', $classes)); if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || $stage * 2 != $currentstage)) { $item['link'] = new moodle_url($PAGE->url, $this->stage->get_params() + array('backup' => $this->get_backupid(), 'stage' => $stage)); } array_unshift($items, $item); $stage = floor($stage / 2); } $selectorlink = new moodle_url($PAGE->url, $this->stage->get_params()); $selectorlink->remove_params('importid'); array_unshift($items, array('text' => '1. ' . get_string('importcurrentstage0', 'backup'), 'class' => join(' ', $classes), 'link' => $selectorlink)); return $items; }
/** * Edit a RTQ question * * @param int $questionid the RTQ questionid * * @return mixed */ public function edit_question($questionid) { global $DB; $actionurl = clone $this->baseurl; $actionurl->param('action', 'editquestion'); $actionurl->param('rtqquestionid', $questionid); $rtqquestion = $DB->get_record('activequiz_questions', array('id' => $questionid), '*', MUST_EXIST); $qrecord = $DB->get_record('question', array('id' => $rtqquestion->questionid), '*', MUST_EXIST); $mform = new add_question_form($actionurl, array('rtq' => $this->rtq, 'questionname' => $qrecord->name, 'defaultmark' => $qrecord->defaultmark, 'showhistoryduringquiz' => $rtqquestion->showhistoryduringquiz, 'edit' => true)); // form handling if ($mform->is_cancelled()) { // redirect back to list questions page $this->baseurl->remove_params('action'); redirect($this->baseurl, null, 0); } else { if ($data = $mform->get_data()) { // process data from the form $question = new \stdClass(); $question->id = $rtqquestion->id; $question->activequizid = $this->rtq->getRTQ()->id; $question->questionid = $rtqquestion->questionid; $question->notime = $data->notime; $question->questiontime = $data->indvquestiontime; $question->tries = $data->numberoftries; $question->points = number_format($data->points, 2); $DB->update_record('activequiz_questions', $question); // ensure there is no action or questionid in the baseurl $this->baseurl->remove_params('action', 'questionid'); redirect($this->baseurl, null, 0); } else { // display the form $mform->set_data(array('indvquestiontime' => $rtqquestion->questiontime, 'notime' => $rtqquestion->notime, 'numberoftries' => $rtqquestion->tries, 'points' => $rtqquestion->points)); $this->renderer->print_editpage_header(); $this->renderer->editrender_addquestionform($mform); $this->renderer->end_editpage(); } } }
public function starred($message, $userid, $type, $offset = 0, $view = false) { $params = array( 'starred' => $message->id(), 'sesskey' => sesskey() ); $url = new moodle_url($this->page->url, $params); $url->param('offset', $offset); $output = html_writer::start_tag('span', array('class' => 'mail_flags')); if ($view) { $url->param('m', $message->id()); $url->remove_params(array('offset')); } if ($message->starred($userid)) { $linkparams = array('title' => get_string('starred', 'local_mail')); $output .= html_writer::link($url, html_writer::tag('span', '', array('class' => 'mail_starred')), $linkparams); } else { $linkparams = array('title' => get_string('unstarred', 'local_mail')); $output .= html_writer::link($url, html_writer::tag('span', '', array('class' => 'mail_unstarred')), $linkparams); } $output .= html_writer::end_tag('span'); return $output; }
$urlparams['userid'] = $userid; $urlparams['start'] = $start; $urlparams['end'] = $end; $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $PAGE->set_course($course); $context = $PAGE->context; if (has_capability('block/timetracker:manageworkers', $context)) { //supervisor print_error('This page is not accessible by a supervisor'); } $worker = $DB->get_record('block_timetracker_workerinfo', array('id' => $userid)); if (!$worker) { print_error('usernotexist', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $course->id); } $index = new moodle_url($CFG->wwwroot . '/blocks/timetracker/index.php', $urlparams); $index->remove_params('userid', 'start', 'end'); $timesheeturl = new moodle_url($CFG->wwwroot . '/blocks/timetracker/timesheet.php', $urlparams); $timesheeturl->remove_params('start', 'end'); $workersigurl = new moodle_url($CFG->wwwroot . '/blocks/timetracker/workersig.php', $urlparams); $conflicts = check_worker_hours_for_conflicts($userid, $start, $end); if (sizeof($conflicts) == 0) { redirect($workersigurl); } $strtitle = get_string('pluginname', 'block_timetracker'); $PAGE->set_url($timesheeturl); $PAGE->set_title($strtitle); $PAGE->set_heading($strtitle); $PAGE->set_pagelayout('base'); echo $OUTPUT->header(); $tabs = get_tabs($urlparams, false, $courseid); $tabs = array($tabs);
/** * Gets a link for this page that will work with JS disabled. * * @global moodle_page $PAGE * @param moodle_page $page * @return moodle_url */ public function get_nojslink(moodle_page $page = null) { if ($page === null) { global $PAGE; $page = $PAGE; } $link = new moodle_url($page->url, array('nonjscomment' => true, 'comment_itemid' => $this->itemid, 'comment_context' => $this->context->id, 'comment_area' => $this->commentarea)); $link->remove_params(array('comment_page')); return $link; }
/** * Prepare comment code in html * @param boolean $return * @return mixed */ public function output($return = true) { global $PAGE, $OUTPUT; static $template_printed; $this->link = $PAGE->url; $murl = new moodle_url($this->link); $murl->remove_params('nonjscomment'); $murl->param('nonjscomment', 'true'); $murl->param('comment_itemid', $this->itemid); $murl->param('comment_context', $this->context->id); $murl->param('comment_area', $this->commentarea); $murl->remove_params('comment_page'); $this->link = $murl->out(); $options = new stdClass(); $options->client_id = $this->cid; $options->commentarea = $this->commentarea; $options->itemid = $this->itemid; $options->page = 0; $options->courseid = $this->courseid; $options->contextid = $this->contextid; $options->env = $this->env; $options->component = $this->component; if ($this->env == 'block_comments') { $options->notoggle = true; $options->autostart = true; } $PAGE->requires->js_init_call('M.core_comment.init', array($options), true); if (!empty(self::$nonjs)) { // return non js comments interface return $this->print_comments(self::$comment_page, $return, true); } $strsubmit = get_string('savecomment'); $strcancel = get_string('cancel'); $strshowcomments = get_string('showcommentsnonjs'); $sesskey = sesskey(); $html = ''; // print html template // Javascript will use the template to render new comments if (empty($template_printed) && !empty($this->viewcap)) { $html .= '<div style="display:none" id="cmt-tmpl">' . $this->template . '</div>'; $template_printed = true; } if (!empty($this->viewcap)) { // print commenting icon and tooltip $icon = $OUTPUT->pix_url('t/collapsed'); $html .= <<<EOD <div class="mdl-left"> <a class="showcommentsnonjs" href="{$this->link}">{$strshowcomments}</a> EOD; if ($this->env != 'block_comments') { $html .= <<<EOD <a id="comment-link-{$this->cid}" class="comment-link" href="#"> <img id="comment-img-{$this->cid}" src="{$icon}" alt="{$this->linktext}" title="{$this->linktext}" /> <span id="comment-link-text-{$this->cid}">{$this->linktext} {$this->count}</span> </a> EOD; } $html .= <<<EOD <div id="comment-ctrl-{$this->cid}" class="comment-ctrl"> <ul id="comment-list-{$this->cid}" class="comment-list"> <li class="first"></li> EOD; // in comments block, we print comments list right away if ($this->env == 'block_comments') { $html .= $this->print_comments(0, true, false); $html .= '</ul>'; $html .= $this->get_pagination(0); } else { $html .= <<<EOD </ul> <div id="comment-pagination-{$this->cid}" class="comment-pagination"></div> EOD; } // print posting textarea if (!empty($this->postcap)) { $html .= <<<EOD <div class='comment-area'> <div class="bd"> <textarea name="content" rows="2" cols="20" id="dlg-content-{$this->cid}"></textarea> </div> <div class="fd" id="comment-action-{$this->cid}"> <a href="#" id="comment-action-post-{$this->cid}"> {$strsubmit} </a> EOD; if ($this->env != 'block_comments') { $html .= "<span> | </span><a href=\"#\" id=\"comment-action-cancel-{$this->cid}\"> {$strcancel} </a>"; } $html .= <<<EOD </div> </div> <div class="clearer"></div> EOD; } $html .= <<<EOD </div><!-- end of comment-ctrl --> </div> EOD; } else { $html = ''; } if ($return) { return $html; } else { echo $html; } }
/** * Display a repository instance list (with edit/delete/create links) * * @static * @param stdClass $context the context for which we display the instance * @param string $typename if set, we display only one type of instance */ public static function display_instances_list($context, $typename = null) { global $CFG, $USER, $OUTPUT; $output = $OUTPUT->box_start('generalbox'); //if the context is SYSTEM, so we call it from administration page $admin = $context->id == SYSCONTEXTID ? true : false; if ($admin) { $baseurl = new moodle_url('/' . $CFG->admin . '/repositoryinstance.php', array('sesskey' => sesskey())); $output .= $OUTPUT->heading(get_string('siteinstances', 'repository')); } else { $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid' => $context->id, 'sesskey' => sesskey())); } $namestr = get_string('name'); $pluginstr = get_string('plugin', 'repository'); $settingsstr = get_string('settings'); $deletestr = get_string('delete'); // Retrieve list of instances. In administration context we want to display all // instances of a type, even if this type is not visible. In course/user context we // want to display only visible instances, but for every type types. The repository::get_instances() // third parameter displays only visible type. $params = array(); $params['context'] = array($context); $params['currentcontext'] = $context; $params['return_types'] = 0; $params['onlyvisible'] = !$admin; $params['type'] = $typename; $instances = repository::get_instances($params); $instancesnumber = count($instances); $alreadyplugins = array(); $table = new html_table(); $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr); $table->align = array('left', 'left', 'center', 'center'); $table->data = array(); $updowncount = 1; foreach ($instances as $i) { $settings = ''; $delete = ''; $type = repository::get_type_by_id($i->options['typeid']); if ($type->get_contextvisibility($context)) { if (!$i->readonly) { $settingurl = new moodle_url($baseurl); $settingurl->param('type', $i->options['type']); $settingurl->param('edit', $i->id); $settings .= html_writer::link($settingurl, $settingsstr); $deleteurl = new moodle_url($baseurl); $deleteurl->param('delete', $i->id); $deleteurl->param('type', $i->options['type']); $delete .= html_writer::link($deleteurl, $deletestr); } } $type = repository::get_type_by_id($i->options['typeid']); $table->data[] = array(format_string($i->name), $type->get_readablename(), $settings, $delete); //display a grey row if the type is defined as not visible if (isset($type) && !$type->get_visible()) { $table->rowclasses[] = 'dimmed_text'; } else { $table->rowclasses[] = ''; } if (!in_array($i->name, $alreadyplugins)) { $alreadyplugins[] = $i->name; } } $output .= html_writer::table($table); $instancehtml = '<div>'; $addable = 0; //if no type is set, we can create all type of instance if (!$typename) { $instancehtml .= '<h3>'; $instancehtml .= get_string('createrepository', 'repository'); $instancehtml .= '</h3><ul>'; $types = repository::get_editable_types($context); foreach ($types as $type) { if (!empty($type) && $type->get_visible()) { // If the user does not have the permission to view the repository, it won't be displayed in // the list of instances. Hiding the link to create new instances will prevent the // user from creating them without being able to find them afterwards, which looks like a bug. if (!has_capability('repository/' . $type->get_typename() . ':view', $context)) { continue; } $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names'); if (!empty($instanceoptionnames)) { $baseurl->param('new', $type->get_typename()); $instancehtml .= '<li><a href="' . $baseurl->out() . '">' . get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_' . $type->get_typename())) . '</a></li>'; $baseurl->remove_params('new'); $addable++; } } } $instancehtml .= '</ul>'; } else { $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names'); if (!empty($instanceoptionnames)) { //create a unique type of instance $addable = 1; $baseurl->param('new', $typename); $output .= $OUTPUT->single_button($baseurl, get_string('createinstance', 'repository'), 'get'); $baseurl->remove_params('new'); } } if ($addable) { $instancehtml .= '</div>'; $output .= $instancehtml; } $output .= $OUTPUT->box_end(); //print the list + creation links print $output; }
$users = $DB->get_records_sql($sql, $params); if ($page * $perpage > count($users)) { $page = 0; } $url = new moodle_url($PAGE->url); $url->remove_params(array('page')); echo $OUTPUT->paging_bar(count($users), $page, $perpage, $url, 'page'); $users = array_slice($users, $page * $perpage, $perpage, true); foreach ($users as $user) { $user->fullname = fullname($user); $user->score = 0; } $strtotals = get_string('totals', 'realtimequiz'); list($usql, $uparams) = $DB->get_in_or_equal(array_keys($users), SQL_PARAMS_NAMED); $nousersurl = new moodle_url($PAGE->url); $nousersurl->remove_params(array('showusers')); $userlink = html_writer::link($nousersurl, get_string('hideusers', 'realtimequiz')); } else { $usersurl = new moodle_url($PAGE->url); $usersurl->param('showusers', 1); $userlink = html_writer::link($usersurl, get_string('showusers', 'realtimequiz')); } echo html_writer::tag('p', $userlink); echo '<br /><table border="1" style="border-style: none;">'; if (!empty($questions)) { foreach ($questions as $question) { echo '<tr class="realtimequiz_report_question"><td width="30%">' . $question->questionnum . '</td>'; $answers = $DB->get_records('realtimequiz_answer', array('questionid' => $question->id), 'id'); if (!empty($answers)) { $iscorrectanswer = false; foreach ($answers as $answer) {
/** * Displays a course filter selector * * @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course. * @param string $label The label to use for the course select. * @return string */ protected function course_filter_selector(moodle_url $returnurl, $label = null) { global $USER, $SESSION, $CFG; if (!isloggedin() or isguestuser()) { return ''; } if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) { $courses = get_courses('all', 'c.shortname', 'c.id,c.shortname'); } else { $courses = enrol_get_my_courses(); } unset($courses[SITEID]); $courseoptions = array(); $courseoptions[SITEID] = get_string('fulllistofcourses'); foreach ($courses as $course) { $coursecontext = context_course::instance($course->id); $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); } if ($this->page->course->id !== SITEID) { $selected = $this->page->course->id; } else { $selected = ''; } $courseurl = new moodle_url($returnurl); $courseurl->remove_params('course'); $select = new single_select($courseurl, 'course', $courseoptions, $selected, null); $select->class = 'cal_courses_flt'; if ($label !== null) { $select->set_label($label); } else { $select->set_label(get_string('listofcourses'), array('class' => 'accesshide')); } return $this->output->render($select); }
/** * strip off action parameters like 'removecontact' * @param moodle_url/string $moodleurl a URL. Typically the current page URL. * @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact). */ function message_remove_url_params($moodleurl) { $newurl = new moodle_url($moodleurl); $newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact'); return $newurl->out(); }
echo $OUTPUT->header(); $ratingoptions = new stdClass(); $ratingoptions->context = $context; $ratingoptions->component = $component; $ratingoptions->ratingarea = $ratingarea; $ratingoptions->itemid = $itemid; $ratingoptions->sort = $sqlsort; $rm = new rating_manager(); $ratings = $rm->get_all_ratings_for_item($ratingoptions); if (!$ratings) { $msg = get_string('noratings', 'rating'); echo html_writer::tag('div', $msg, array('class' => 'mdl-align')); } else { // To get the sort URL, copy the current URL and remove any previous sort. $sorturl = new moodle_url($url); $sorturl->remove_params('sort'); $table = new html_table(); $table->cellpadding = 3; $table->cellspacing = 3; $table->attributes['class'] = 'generalbox ratingtable'; $table->head = array('', html_writer::link(new moodle_url($sorturl, array('sort' => 'firstname')), $strname), html_writer::link(new moodle_url($sorturl, array('sort' => 'rating')), $strrating), html_writer::link(new moodle_url($sorturl, array('sort' => 'time')), $strtime)); $table->colclasses = array('', 'firstname', 'rating', 'time'); $table->data = array(); // If the scale was changed after ratings were submitted some ratings may have a value above the current maximum. // We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0. $maxrating = max(array_keys($scalemenu)); foreach ($ratings as $rating) { if (!$canviewallratings and $USER->id != $rating->userid) { continue; } // Undo the aliasing of the user id column from user_picture::fields().
$cm = get_coursemodule_from_instance("giportfolio", $giportfolio->id, $course->id, false, MUST_EXIST); $url->param('p', $p); } if ($currenttab !== 'all') { $url->param('tab', $currenttab); } $PAGE->set_url($url); require_login($course->id, false, $cm); $context = context_module::instance($cm->id); require_capability('mod/giportfolio:gradegiportfolios', $context); require_capability('mod/giportfolio:viewgiportfolios', $context); $PAGE->set_title(format_string($giportfolio->name)); echo $OUTPUT->header(); // Set up the list of tabs. $allurl = new moodle_url($PAGE->url); $allurl->remove_params('tab'); $sincelastloginurl = new moodle_url($PAGE->url, array('tab' => 'sincelastlogin')); $nocommentsurl = new moodle_url($PAGE->url, array('tab' => 'nocomments')); $tabs = array(new tabobject('all', $allurl, get_string('allusers', 'mod_giportfolio')), new tabobject('sincelastlogin', $sincelastloginurl, get_string('sincelastlogin', 'mod_giportfolio')), new tabobject('nocomments', $nocommentsurl, get_string('nocomments', 'mod_giportfolio'))); echo get_string('studentgiportfolios', 'mod_giportfolio'); echo '</br>'; if ($CFG->version > 2013051400) { echo $OUTPUT->tabtree($tabs, $currenttab); } else { $tabs = array($tabs); echo print_tabs($tabs, $currenttab, array(), array(), true); } echo get_string('filterlist', 'mod_giportfolio'); $tabindex = 1; // Tabindex for quick grading tabbing; Not working for dropdowns yet. // Check to see if groups are being used in this assignment.
function definition() { global $CFG, $USER, $DB, $OUTPUT; $mform =& $this->_form; // Don't forget the underscore! //userid of 0 means we want to see every worker. -- this needs fixing. XXX $canmanage = false; if (has_capability('block/timetracker:manageworkers', $this->context)) { $canmanage = true; } $canview = false; if (has_capability('block/timetracker:viewonly', $this->context)) { $canview = true; } $issiteadmin = false; if (has_capability('moodle/site:config', $this->context)) { $issiteadmin = true; } if ($this->userid == 0 && !($canmanage || $canview)) { print_error('notpermissible', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $this->courseid); } $now = time(); if ($this->userid == 0 && ($canmanage || $canview)) { //supervisor -- show all! $workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $this->courseid)); if (!$workers) { $mform->addElement('html', 'No workers found'); return; } } else { $user = $DB->get_record('block_timetracker_workerinfo', array('id' => $this->userid)); if ($user && $user->id != $this->userid && !($canmanage || $canview)) { print_error('notpermissible', 'block_timetracker', $CFG->wwwroot . '/blocks/timetracker/index.php?id=' . $this->courseid); } } /* $mform->addElement('header','general','Generate Monthly Timesheet'); if($this->userid > 0){ $mform->addElement('html','<center><a href="'.$CFG->wwwroot.'/blocks/timetracker/timesheet.php?id='. $this->courseid.'&userid='. $this->userid.'">Generate Monthly Timesheet</a></center>'); } else { $mform->addElement('html','<center><a href="'.$CFG->wwwroot.'/blocks/timetracker/timesheet.php?id='. $this->courseid.'">Generate Monthly Timesheet</a></center>'); } */ $mform->addElement('header', 'general', 'Report time period'); $mform->addElement('hidden', 'id', $this->courseid); $mform->addElement('hidden', 'userid', $this->userid); $mform->addElement('hidden', 'sesskey', sesskey()); if ($this->reportstart == 0 || $this->reportend == 0) { $starttime = usergetdate($now); $starttime_mid = make_timestamp($starttime['year'], $starttime['mon'] - 1, $starttime['mday']); $this->reportstart = $starttime_mid; $endtime = usergetdate($now); $endtime_mid = make_timestamp($endtime['year'], $endtime['mon'], $endtime['mday'], 23, 59, 59); $this->reportend = $endtime_mid; } $mform->addElement('date_time_selector', 'reportstart', get_string('startreport', 'block_timetracker'), array('optional' => false, 'step' => 1)); $mform->setDefault('reportstart', $this->reportstart); $mform->addHelpButton('reportstart', 'startreport', 'block_timetracker'); $mform->addElement('date_time_selector', 'reportend', get_string('endreport', 'block_timetracker'), array('optional' => false, 'step' => 1)); $mform->setDefault('reportend', $this->reportend); $mform->addHelpButton('reportend', 'endreport', 'block_timetracker'); $mform->addElement('submit', 'datechange', 'Get work units'); $baseurl = $CFG->wwwroot . '/blocks/timetracker'; //************** PENDING WORK UNITS SECTION ****************// //which workers to see? /* $endtime = $this->reportend + ((60*60*23)+60*59); //23:59 $sql = 'SELECT * FROM '.$CFG->prefix.'block_timetracker_pending WHERE timein BETWEEN '. $this->reportstart.' AND '.$endtime.' '; if($this->userid==0 && $this->courseid == 0){ //see all workers, all courses //$pendingunits = $DB->get_records_sql($sql); //bad bad } else if ($this->userid==0 && $this->courseid!=0){ //see all workers, this course $sql .= 'AND courseid='. $this->courseid; } else { //if ($this->userid != 0) //specific user, this course $sql .= 'AND userid='.$this->userid. ' AND courseid='. $this->courseid; } $sql .= ' ORDER BY timein DESC'; $pendingunits = $DB->get_records_sql($sql); $mform->addElement('header', 'general', 'Pending work units'); if(!$pendingunits){ //if they don't have them. $mform->addElement('html','No pending work units<br />'); } else { //if they do have pending $mform->addElement('html', '<table align="center" border="1" cellspacing="10px" '. 'cellpadding="5px" width="95%">'); $headers = '<tr>'; if($this->userid == 0) $headers .= '<td style="font-weight: bold">Name</td>'; $headers .= '<td style="font-weight: bold">Time in</td> <td style="font-weight: bold; text-align: center">Action</td>'; $headers .='</tr>'; $mform->addElement('html',$headers); foreach($pendingunits as $pending){ $row='<tr>'; if($this->userid == 0){ $row .='<td><a href="'.$baseurl. '/reports.php?id='.$this->courseid.'&userid='. $pending->userid.'">'.$workers[$pending->userid]->lastname.', '. $workers[$pending->userid]->firstname.'</a></td>'; } $row.='<td>'.userdate($pending->timein, get_string('datetimeformat','block_timetracker')).'</td>'; $urlparams['id'] = $pending->courseid; $urlparams['userid'] = $pending->userid; $urlparams['sesskey'] = sesskey(); $urlparams['unitid'] = $pending->id; $urlparams['clockout'] = 1; $cout = new moodle_url($CFG->wwwroot.'/blocks/timetracker/timeclock.php', $urlparams); $clockouticon = new pix_icon('clock_stop','Clock out','block_timetracker'); $clockoutaction = $OUTPUT->action_icon($cout, $clockouticon); unset($urlparams['clockout']); $deleteurl = new moodle_url($baseurl.'/deletepending.php', $urlparams); $deleteicon = new pix_icon('clock_delete', get_string('delete'),'block_timetracker'); $deleteaction = $OUTPUT->action_icon( $deleteurl, $deleteicon, new confirm_action('Are you sure you want to delete this '. ' pending work unit?')); if($canmanage){ $urlparams['ispending'] = true; $editurl = new moodle_url($baseurl.'/editunit.php', $urlparams); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('clock_edit', get_string('edit'),'block_timetracker')); unset($urlparams['ispending']); } if($canmanage){ $actions = $clockoutaction.' '.$editaction.' '.$deleteaction; } else { $actions = $clockoutaction.' '.$deleteaction; } $row .= '<td style="text-align: center">'.$actions.'</td>'; $row .= '</tr>'; $mform->addElement('html',$row); } $mform->addElement('html','</table>'); } */ //************** WORK UNITS SECTION ****************// //TODO - courseid is never really 0, unless we're viewing from main page. //which workers to see? $workerdesc = 'Completed work units'; //$endtime = strtotime ('+1 day ', $this->reportend) - 1; //$endtime = $this->reportend + ((60*60*23)+60*59); //23:59 $endtime = strtotime('+59 seconds', $this->reportend); $sql = 'SELECT * FROM ' . $CFG->prefix . 'block_timetracker_workunit WHERE (timeout ' . 'BETWEEN ' . $this->reportstart . ' AND ' . $endtime . ' ' . 'OR timein BETWEEN ' . $this->reportstart . ' AND ' . $endtime . ') '; if ($this->userid == 0 && $this->courseid == 0) { //see all workers, all courses $units = $DB->get_records_sql($sql); } else { if ($this->userid == 0 && $this->courseid != 0) { //see all workers, this course $sql .= 'AND courseid=' . $this->courseid; $workerdesc .= ' for all workers'; } else { //specific user, this course if ($canmanage || $canview) { $allurl = new moodle_url($baseurl . '/reports.php', array('id' => $this->courseid, 'userid' => 0, 'repstart' => $this->reportstart, 'repend' => $this->reportend)); $workerdesc .= ' for ' . $user->firstname . ' ' . $user->lastname . ' [ ' . $OUTPUT->action_link($allurl, 'see all') . ' ]'; } $sql .= ' AND courseid=' . $this->courseid . ' AND userid=' . $this->userid; } } $sql .= ' ORDER BY timein DESC'; $units = $DB->get_records_sql($sql); $mform->addElement('header', 'general', $workerdesc); if (!$units) { //if they don't have them. $mform->addElement('html', 'No completed work units<br />'); } else { //if they do have some $mform->addElement('html', ' <table align="center" cellspacing="10px" cellpadding="5px" width="95%" style="border: 1px solid #000;" >'); $headers = '<tr>'; if ($canmanage || $canview) { $headers .= '<td style="font-weight: bold">Name</td>'; } $headers .= '<td style="font-weight: bold; text-align: center">Time in/out</td>' . '<td style="font-weight: bold; text-align: center">Elapsed</td>'; $headers .= '<td style="font-weight: bold; text-align: center">' . get_string('action') . '</td>'; $headers .= '</tr>'; $mform->addElement('html', $headers); $total = 0; //print_object($workers); foreach ($units as $unit) { $row = '<tr>'; if ($this->userid == 0) { $userurl = new moodle_url($baseurl . '/reports.php'); $userurl->params(array('id' => $this->courseid, 'userid' => $unit->userid, 'repstart' => $this->reportstart, 'repend' => $this->reportend)); $row .= '<td>' . $OUTPUT->action_link($userurl, $workers[$unit->userid]->lastname . ', ' . $workers[$unit->userid]->firstname) . '</td>'; } else { if ($canmanage || $canview) { $row .= '<td>' . $user->lastname . ', ' . $user->firstname . '</td>'; } } //print them here? print all, w/br? if ($unit->timein < $this->reportstart || $unit->timeout > $endtime) { /* error_log("rstart: ". userdate($this->reportstart, '%m/%d/%y %I:%M:%S %p')); error_log("utin: ". userdate($unit->timein, '%m/%d/%y %I:%M:%S %p')); error_log("rend: ". userdate($this->reportend, '%m/%d/%y %I:%M:%S %p')); error_log("utout: ". userdate($unit->timeout, '%m/%d/%y %I:%M:%S %p')); */ $singleurl = new moodle_url($baseurl . '/reports.php'); $singleurl->params(array('id' => $this->courseid, 'userid' => $unit->userid, 'repstart' => $unit->timein - 1, 'repend' => $unit->timeout + 1)); $splitunits = split_unit($unit); $row .= '<td style="text-align: center">'; foreach ($splitunits as $subunit) { $straddle = false; if ($subunit->timein < $this->reportstart || $subunit->timeout > $endtime) { $straddle = true; } /* if($straddle){ error_log("rstart: ". userdate($this->reportstart, '%m/%d/%y %I:%M:%S %p')); error_log('in: '. userdate($subunit->timein, get_string('datetimeformat', 'block_timetracker'))); error_log("rend: ". userdate($endtime, '%m/%d/%y %I:%M:%S %p')); error_log('out: '. userdate($subunit->timeout, get_string('datetimeformat', 'block_timetracker'))); } */ if (!$straddle) { $row .= userdate($subunit->timein, get_string('datetimeformat', 'block_timetracker')); $row .= ' to ' . userdate($subunit->timeout, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />'; } else { if ($subunit->timein > $this->reportstart) { if ($subunit->timeout < $endtime) { $end = $subunit->timeout; } else { $end = $endtime; } $row .= userdate($subunit->timein, get_string('datetimeformat', 'block_timetracker')); $row .= ' to ' . userdate($end, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />'; } else { if ($subunit->timein > $this->reportstart) { $start = $subunit->timein; } else { $start = $this->reportstart; } $row .= userdate($start, get_string('datetimeformat', 'block_timetracker')); $row .= ' to ' . userdate($subunit->timeout, get_string('datetimeformat', 'block_timetracker')); $row .= '<br />'; } } } $row .= 'Partial unit. '; $row .= $OUTPUT->action_link($singleurl, '[ view complete work unit ]'); $row .= '</td>' . "\n"; $row .= '<td style="text-align: center">'; foreach ($splitunits as $subunit) { $straddle = false; if ($subunit->timein < $this->reportstart || $subunit->timeout > $endtime) { $straddle = true; } if (!$straddle) { $currelapsed = $subunit->timeout - $subunit->timein; $hrs = get_hours($currelapsed, $subunit->courseid); $total += $hrs; $row .= $hrs . ' hour(s)'; $row .= '<br />'; } else { if ($subunit->timein > $this->reportstart) { if ($subunit->timeout < $endtime) { $end = $subunit->timeout; } else { $end = $endtime; } $currelapsed = $end - $subunit->timein; } else { if ($subunit->timein > $this->reportstart) { $start = $subunit->timein; } else { $start = $this->reportstart; } $currelapsed = $subunit->timeout - $start; } $hrs = get_hours($currelapsed, $subunit->courseid); $total += $hrs; $row .= $hrs . ' hour(s)'; $row .= '<br />'; } } $row .= '</td>' . "\n"; } else { //unit occurs all in one repstart-repend $row .= '<td style="text-align: center">'; $row .= userdate($unit->timein, get_string('datetimeformat', 'block_timetracker')); $row .= ' to ' . userdate($unit->timeout, get_string('datetimeformat', 'block_timetracker')); $row .= '</td>'; $row .= '<td style="text-align: center">'; $currelapsed = $unit->timeout - $unit->timein; $hrs = get_hours($currelapsed, $unit->courseid); $total += $hrs; $row .= $hrs . ' hour(s)</td>'; } if ($canmanage || $canview) { $urlparams['id'] = $unit->courseid; $urlparams['userid'] = $unit->userid; $urlparams['sesskey'] = sesskey(); $urlparams['unitid'] = $unit->id; $unitdateinfo = usergetdate($unit->timein); if ($unit->timesheetid && !$unit->submitted) { //show greyed out icons and no URL $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/wait.png', 'class' => 'icon')) . '</td>'; } else { if ($unit->timesheetid && $unit->submitted) { $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/certified.png', 'class' => 'icon')) . '</td>'; } else { if (!$unit->canedit) { //show greyed out icons and no URL $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/clock_edit_bw.png', 'class' => 'icon')) . ' ' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/clock_delete_bw.png', 'class' => 'icon')) . '</td>'; } else { $deleteurl = new moodle_url($baseurl . '/deleteworkunit.php', $urlparams); $deleteicon = new pix_icon('clock_delete', get_string('delete'), 'block_timetracker'); $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action('Are you sure you want to delete this work unit?')); //error_log (($now - $unit->timein)-(86400*35)); $editurl = new moodle_url($baseurl . '/editunit.php', $urlparams); $editurl->remove_params('sesskey'); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('clock_edit', get_string('edit'), 'block_timetracker')); $row .= '<td style="text-align: center">'; if ($canmanage) { $row .= $editaction . ' ' . $deleteaction . '</td>'; } else { $row .= ' '; } $row .= '</td>'; } } } } else { $urlparams['id'] = $this->courseid; $urlparams['userid'] = $unit->userid; $urlparams['sesskey'] = sesskey(); $urlparams['unitid'] = $unit->id; $unitdateinfo = usergetdate($unit->timein); if ($unit->timesheetid && !$unit->submitted) { //show greyed out icons and no URL $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/wait.png', 'class' => 'icon')) . '</td>'; } else { if ($unit->timesheetid && $unit->submitted) { $row .= '<td style="text-align: center">' . html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/certified.png', 'class' => 'icon')) . '</td>'; } else { if (!$unit->canedit) { //show greyed out icons and no URL $alertaction = html_writer::empty_tag('img', array('src' => $CFG->wwwroot . '/blocks/timetracker/pix/alert_bw.gif', 'class' => 'icon')); } else { $alerturl = new moodle_url($baseurl . '/alert.php', $urlparams); $alerticon = new pix_icon('alert', 'Alert Supervisor of Error', 'block_timetracker'); $alertaction = $OUTPUT->action_icon($alerturl, $alerticon); $row .= '<td style="text-align:center">' . $alertaction . '</td>'; } } } } $row .= '</tr>'; $mform->addElement('html', $row); } $finalrow = '<tr>'; if ($canmanage) { $finalrow .= '<td> </td>'; } $finalrow .= '<td> </td> <td> </td> <td style="text-align: center; border-top: 1px solid black"><b>Total: </b>' . round($total, 3) . ' hour(s)</td> <td> </td></tr></table>'; $mform->addElement('html', $finalrow); } }
/** * view overview tab */ public function view_overview() { global $PAGE, $OUTPUT; $groupid = optional_param('groupid', 0, PARAM_INT); $groupingid = optional_param('groupingid', 0, PARAM_INT); $orientation = optional_param('orientation', 0, PARAM_BOOL); $url = new moodle_url($PAGE->url, array('sesskey' => sesskey(), 'groupid' => $groupid, 'groupingid' => $groupingid, 'orientation' => $orientation)); // Process submitted form! if (data_submitted() && confirm_sesskey() && optional_param('confirm', 0, PARAM_BOOL)) { // Execution has been confirmed?! $hideform = 0; $pushtomdl = optional_param('pushtomdl', 0, PARAM_BOOL); if ($pushtomdl) { list($error, $message) = $this->push_registrations($groupid, $groupingid); } if ($error) { echo $OUTPUT->notification($message, 'notifyproblem'); } else { echo $OUTPUT->notification($message, 'notifysuccess'); } } else { if (data_submitted() && confirm_sesskey()) { // Display confirm-dialog! $hideform = 1; $pushtomdl = optional_param('pushtomdl', 0, PARAM_BOOL); if ($pushtomdl) { // Try only! list($error, $message) = $this->push_registrations($groupid, $groupingid, true); $attr = array(); $attr['confirm'] = 1; $attr['pushtomdl'] = 1; $attr['sesskey'] = sesskey(); $continue = new moodle_url($PAGE->url, $attr); $cancel = new moodle_url($PAGE->url); if ($error) { $continue->remove_params('confirm', 'group'); $continue = new single_button($continue, get_string('continue'), 'get'); $cancel = null; } echo $this->confirm($message, $continue, $cancel); } else { $hideform = 0; } } else { $hideform = 0; } } if (!$hideform) { $groupings = groups_get_all_groupings($this->course->id); $options = array(0 => get_string('all')); if (count($groupings)) { foreach ($groupings as $grouping) { $options[$grouping->id] = $grouping->name; } } $groupingselect = new single_select($url, 'groupingid', $options, $groupingid, false); $groups = $this->get_active_groups(false, false, 0, 0, $groupingid); $options = array(0 => get_string('all')); if (count($groups)) { foreach ($groups as $group) { $options[$group->id] = $group->name; } } if (!key_exists($groupid, $options)) { $groupid = 0; $url->param('groupid', 0); echo $OUTPUT->box($OUTPUT->notification(get_string('group_not_in_grouping', 'grouptool') . html_writer::empty_tag('br') . get_string('switched_to_all_groups', 'grouptool'), 'notifyproblem'), 'generalbox centered'); } $groupselect = new single_select($url, 'groupid', $options, $groupid, false); $options = array(0 => get_string('portrait', 'grouptool'), 1 => get_string('landscape', 'grouptool')); $orientationselect = new single_select($url, 'orientation', $options, $orientation, false); $syncstatus = $this->get_sync_status(); if ($syncstatus[0]) { /* * Out of sync? --> show button to get registrations from grouptool to moodle * (just register not already registered persons and let the others be) */ $url = new moodle_url($PAGE->url, array('pushtomdl' => 1, 'sesskey' => sesskey())); $button = new single_button($url, get_string('updatemdlgrps', 'grouptool')); echo $OUTPUT->box(html_writer::empty_tag('br') . $OUTPUT->render($button) . html_writer::empty_tag('br'), 'generalbox centered'); } echo html_writer::tag('div', get_string('grouping', 'group') . ' ' . $OUTPUT->render($groupingselect), array('class' => 'centered grouptool_overview_filter')) . html_writer::tag('div', get_string('group', 'group') . ' ' . $OUTPUT->render($groupselect), array('class' => 'centered grouptool_overview_filter')) . html_writer::tag('div', get_string('orientation', 'grouptool') . ' ' . $OUTPUT->render($orientationselect), array('class' => 'centered grouptool_userlist_filter')); // If we don't only get the data, the output happens directly per group! $this->group_overview_table($groupingid, $groupid); } }
print_error('notpermissible', 'block_timetracker'); } $PAGE->navbar->add(get_string('blocks')); $PAGE->navbar->add(get_string('pluginname', 'block_timetracker'), $url); $PAGE->navbar->add($strtitle); echo $OUTPUT->header(); $tabs = get_tabs($urlparams, $canview, $courseid); $tabs = array($tabs); /* FIX THIS AT SOME POINT $timesheetsub=array(); $timesheetsub[] = new tabobject('signed', '#', 'Previously submitted timesheets', false); $tabs[] = $timesheetsub; */ print_tabs($tabs, 'timesheet'); $index = new moodle_url($baseurl . '/index.php', $urlparams); $index->remove_params('userid'); $nextpage = $index; $totalcount = $DB->count_records('block_timetracker_timesheet', array('userid' => $userid)); $timesheets = $DB->get_records('block_timetracker_timesheet', array('userid' => $userid), 'workersignature DESC', '*', $page * $perpage, $perpage); echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $url, 'page'); echo $OUTPUT->box_start(); if (!$timesheets) { echo '<b><center>There are no official timesheets for ' . $userinfo->firstname . ' ' . $userinfo->lastname . '</center></b>'; } else { // Generate data here echo '<table align="center" border="1" cellspacing="10px" cellpadding="5px" width="75%">'; echo ' <tr> <td style="font-weight: bold;">Worker Signature</td> <td style="font-weight: bold;">Supervisor Signature</td> <td style="font-weight: bold;">Processed</td>
/** * Common setup for all pages for editing questions. * @param string $edittab code for this edit tab * @param boolean $requirecmid require cmid? default false * @param boolean $requirecourseid require courseid, if cmid is not given? default true * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars */ function question_edit_setup($edittab, $requirecmid = false, $requirecourseid = true) { global $QUESTION_EDITTABCAPS, $DB; //$thispageurl is used to construct urls for all question edit pages we link to from this page. It contains an array //of parameters that are passed from page to page. $thispageurl = new moodle_url(); $thispageurl->remove_params(); // We are going to explicity add back everything important - this avoids unwanted params from being retained. if ($requirecmid) { $cmid = required_param('cmid', PARAM_INT); } else { $cmid = optional_param('cmid', 0, PARAM_INT); } if ($cmid) { list($module, $cm) = get_module_from_cmid($cmid); $courseid = $cm->course; $thispageurl->params(compact('cmid')); require_login($courseid, false, $cm); $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid); } else { $module = null; $cm = null; if ($requirecourseid) { $courseid = required_param('courseid', PARAM_INT); } else { $courseid = optional_param('courseid', 0, PARAM_INT); } if ($courseid) { $thispageurl->params(compact('courseid')); require_login($courseid, false); $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid); } else { $thiscontext = null; } } if ($thiscontext) { $contexts = new question_edit_contexts($thiscontext); $contexts->require_one_edit_tab_cap($edittab); } else { $contexts = null; } $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT); //pass 'cat' from page to page and when 'category' comes from a drop down menu //then we also reset the qpage so we go to page 1 of //a new cat. $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE); // if empty will be set up later if ($category = optional_param('category', 0, PARAM_SEQUENCE)) { if ($pagevars['cat'] != $category) { // is this a move to a new category? $pagevars['cat'] = $category; $pagevars['qpage'] = 0; } } if ($pagevars['cat']) { $thispageurl->param('cat', $pagevars['cat']); } if ($pagevars['qpage'] > -1) { $thispageurl->param('qpage', $pagevars['qpage']); } else { $pagevars['qpage'] = 0; } $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT); if ($pagevars['qperpage'] > -1) { $thispageurl->param('qperpage', $pagevars['qperpage']); } else { $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE; } $sortoptions = array('alpha' => 'name, qtype ASC', 'typealpha' => 'qtype, name ASC', 'age' => 'id ASC'); if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) { $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder]; $pagevars['qsortorder'] = $sortorder; $thispageurl->param('qsortorder', $sortorder); } else { $pagevars['qsortorderdecoded'] = $sortoptions['typealpha']; $pagevars['qsortorder'] = 'typealpha'; } $defaultcategory = question_make_default_categories($contexts->all()); $contextlistarr = array(); foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) { $contextlistarr[] = "'{$context->id}'"; } $contextlist = join($contextlistarr, ' ,'); if (!empty($pagevars['cat'])) { $catparts = explode(',', $pagevars['cat']); if (!$catparts[0] || FALSE !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) { print_error('invalidcategory', 'quiz'); } } else { $category = $defaultcategory; $pagevars['cat'] = "{$category->id},{$category->contextid}"; } if (($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) { $pagevars['recurse'] = $recurse; $thispageurl->param('recurse', $recurse); } else { $pagevars['recurse'] = 1; } if (($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) { $pagevars['showhidden'] = $showhidden; $thispageurl->param('showhidden', $showhidden); } else { $pagevars['showhidden'] = 0; } if (($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) { $pagevars['showquestiontext'] = $showquestiontext; $thispageurl->param('showquestiontext', $showquestiontext); } else { $pagevars['showquestiontext'] = 0; } //category list page $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT); if ($pagevars['cpage'] != 1) { $thispageurl->param('cpage', $pagevars['cpage']); } return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars); }
/** * Used in navigation * @return array of tabobjects */ function get_tabs($urlparams, $canmanage = false, $courseid = -1) { global $CFG; $basicparams = $urlparams; unset($basicparams['userid']); $tabs = array(); $tabs[] = new tabobject('home', new moodle_url($CFG->wwwroot . '/blocks/timetracker/index.php', $basicparams), 'Main'); $tabs[] = new tabobject('reports', new moodle_url($CFG->wwwroot . '/blocks/timetracker/reports.php', $urlparams), 'Reports'); $tabs[] = new tabobject('timesheets', new moodle_url($CFG->wwwroot . '/blocks/timetracker/timesheet.php', $urlparams), 'Timesheets'); $numalerts = ''; if ($canmanage) { $manageurl = new moodle_url($CFG->wwwroot . '/blocks/timetracker/manageworkers.php', $basicparams); $manageurl->remove_params('userid'); $tabs[] = new tabobject('manage', $manageurl, 'Manage Workers'); $tabs[] = new tabobject('terms', new moodle_url($CFG->wwwroot . '/blocks/timetracker/terms.php', $basicparams), 'Terms'); if ($courseid != -1) { //getnumalerts from $courseid $n = has_course_alerts($courseid); if ($n > 0) { $numalerts = '(' . $n . ')'; } } } $tabs[] = new tabobject('alerts', new moodle_url($CFG->wwwroot . '/blocks/timetracker/managealerts.php', $basicparams), 'Alerts ' . $numalerts); return $tabs; }
require_login($badge->courseid); $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid)); $PAGE->set_pagelayout('standard'); navigation_node::override_active_url($navurl); } else { $PAGE->set_pagelayout('admin'); navigation_node::override_active_url($navurl, true); } $PAGE->set_context($context); $PAGE->set_url('/badges/action.php', array('id' => $badge->id)); if ($return !== 0) { $returnurl = new moodle_url($return); } else { $returnurl = new moodle_url('/badges/overview.php', array('id' => $badge->id)); } $returnurl->remove_params('awards'); if ($copy) { require_sesskey(); require_capability('moodle/badges:createbadge', $context); $cloneid = $badge->make_clone(); // If a user can edit badge details, they will be redirected to the edit page. if (has_capability('moodle/badges:configuredetails', $context)) { redirect(new moodle_url('/badges/edit.php', array('id' => $cloneid, 'action' => 'details'))); } redirect(new moodle_url('/badges/overview.php', array('id' => $cloneid))); } if ($activate) { require_capability('moodle/badges:configurecriteria', $context); $PAGE->url->param('activate', 1); $status = $badge->status == BADGE_STATUS_INACTIVE ? BADGE_STATUS_ACTIVE : BADGE_STATUS_ACTIVE_LOCKED; if ($confirm == 1) {
if ($cal_d !== 0) { $url->param('cal_d', $cal_d); } $PAGE->set_url($url); $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); $PAGE->set_pagelayout('standard'); if ($action === 'delete' && $eventid > 0) { $deleteurl = new moodle_url('/calendar/delete.php', array('id' => $eventid)); if ($courseid > 0) { $deleteurl->param('course', $courseid); } redirect($deleteurl); } $viewcalendarurl = new moodle_url(CALENDAR_URL . 'view.php'); $viewcalendarurl->params($PAGE->url->params()); $viewcalendarurl->remove_params(array('id', 'action')); $now = usergetdate(time()); if (isguestuser()) { // Guests cannot do anything with events redirect(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming', 'course' => $courseid))); } $focus = ''; $site = get_site(); calendar_session_vars(); // If a course has been supplied in the URL, change the filters to show that one $courseexists = false; if ($courseid > 0) { if ($courseid == SITEID) { // If coming from the site page, show all courses $SESSION->cal_courses_shown = calendar_get_default_courses(true); calendar_set_referring_course(0);
/** * Send email to specified user with confirmation text and activation link. * * @param stdClass $user A {@link $USER} object * @param string $confirmationurl user confirmation URL * @return bool Returns true if mail was sent OK and false if there was an error. */ function send_confirmation_email($user, $confirmationurl = null) { global $CFG; $site = get_site(); $supportuser = core_user::get_support_user(); $data = new stdClass(); $data->firstname = fullname($user); $data->sitename = format_string($site->fullname); $data->admin = generate_email_signoff(); $subject = get_string('emailconfirmationsubject', '', format_string($site->fullname)); if (empty($confirmationurl)) { $confirmationurl = '/login/confirm.php'; } $confirmationurl = new moodle_url($confirmationurl); // Remove data parameter just in case it was included in the confirmation so we can add it manually later. $confirmationurl->remove_params('data'); $confirmationpath = $confirmationurl->out(false); // We need to custom encode the username to include trailing dots in the link. // Because of this custom encoding we can't use moodle_url directly. // Determine if a query string is present in the confirmation url. $hasquerystring = strpos($confirmationpath, '?') !== false; // Perform normal url encoding of the username first. $username = urlencode($user->username); // Prevent problems with trailing dots not being included as part of link in some mail clients. $username = str_replace('.', '%2E', $username); $data->link = $confirmationpath . ($hasquerystring ? '&' : '?') . 'data=' . $user->secret . '/' . $username; $message = get_string('emailconfirmation', '', $data); $messagehtml = text_to_html(get_string('emailconfirmation', '', $data), false, false, true); $user->mailformat = 1; // Always send HTML version as well. // Directly email rather than using the messaging system to ensure its not routed to a popup or jabber. return email_to_user($user, $supportuser, $subject, $message, $messagehtml); }
/** * Adds a url to the queue for crawling * * @param string $baseurl * @param string $url relative url * @return the node record or if the url is invalid returns false. */ public function mark_for_crawl($baseurl, $url) { global $DB, $CFG; $url = $this->absolute_url($baseurl, $url); // Filter out non http protocols like mailto:cqulibrary@cqu.edu.au etc. $bits = parse_url($url); if (array_key_exists('scheme', $bits) && $bits['scheme'] != 'http' && $bits['scheme'] != 'https') { return false; } // If this url is external then check the ext whitelist. $mdlw = strlen($CFG->wwwroot); $bad = 0; if (substr($url, 0, $mdlw) === $CFG->wwwroot) { $excludes = str_replace("\r", '', self::get_config()->excludemdlurl); } else { $excludes = str_replace("\r", '', self::get_config()->excludeexturl); } $excludes = explode("\n", $excludes); if (count($excludes) > 0 && $excludes[0]) { foreach ($excludes as $exclude) { if (strpos($url, $exclude) > 0) { $bad = 1; break; } } } if ($bad) { return false; } // Ideally this limit should be around 2000 chars but moodle has DB field size limits. if (strlen($url) > 1333) { return false; } // We ignore differences in hash anchors. $url = strtok($url, "#"); // Now we strip out any unwanted url params. $murl = new \moodle_url($url); $excludes = str_replace("\r", '', self::get_config()->excludemdlparam); $excludes = explode("\n", $excludes); $murl->remove_params($excludes); $url = $murl->out(); // Some special logic, if it looks like a course url or module url // then avoid scraping the URL at all. $shortname = ''; if (preg_match('/\\/course\\/(info|view).php\\?id=(\\d+)/', $url, $matches)) { $course = $DB->get_record('course', array('id' => $matches[2])); if ($course) { $shortname = $course->shortname; } } if (preg_match('/\\/enrol\\/index.php\\?id=(\\d+)/', $url, $matches)) { $course = $DB->get_record('course', array('id' => $matches[1])); if ($course) { $shortname = $course->shortname; } } if (preg_match('/\\/mod\\/(\\w+)\\/(index|view).php\\?id=(\\d+)/', $url, $matches)) { $cm = $DB->get_record_sql("\n SELECT cm.*,\n c.shortname\n FROM {course_modules} cm\n JOIN {course} c ON cm.course = c.id\n WHERE cm.id = ?", array($matches[3])); if ($cm) { $shortname = $cm->shortname; } } if ($shortname) { $bad = 0; $excludes = str_replace("\r", '', self::get_config()->excludecourses); $excludes = explode("\n", $excludes); if (count($excludes) > 0 && $excludes[0]) { foreach ($excludes as $exclude) { if (strpos($shortname, $exclude) !== false) { $bad = 1; break; } } } if ($bad) { return false; } } $node = $DB->get_record('linkchecker_url', array('url' => $url)); if (!$node) { // If not in the queue then add it. $node = (object) array(); $node->createdate = time(); $node->url = $url; $node->external = strpos($url, $CFG->wwwroot) === 0 ? 0 : 1; $node->needscrawl = time(); $node->id = $DB->insert_record('linkchecker_url', $node); } else { if ($node->needscrawl < self::get_config()->crawlstart) { $node->needscrawl = time(); $DB->update_record('linkchecker_url', $node); } } return $node; }
/** * Prepare comment code in html * @param boolean $return * @return mixed */ public function init($return = true) { global $CFG, $COURSE, $PAGE; $this->link = qualified_me(); $murl = new moodle_url($this->link); $murl->remove_params('nonjscomment'); $murl->param('nonjscomment', 'true'); $murl->param('comment_itemid', $this->options->itemid); $murl->param('comment_context', $this->options->context->id); $murl->param('comment_area', $this->options->commentarea); $murl->remove_params('page'); $this->link = $murl->out(); if ($this->env === 'block_comments') { // auto expends comments $PAGE->requires->js_function_call('view_comments', array($this->cid, $this->commentarea, $this->itemid, 0))->on_dom_ready(); $PAGE->requires->js_function_call('comment_hide_link', array($this->cid))->on_dom_ready(); } if (!empty(self::$nonjs)) { return $this->print_comments($this->page, $return); } $strsubmit = get_string('submit'); $strcancel = get_string('cancel'); $sesskey = sesskey(); // print html template if (empty($CFG->commentcommentcode) && !empty($this->viewcap)) { echo '<div style="display:none" id="cmt-tmpl">' . $this->template . '</div>'; // shared parameters for commenting $params = new stdclass(); $params->courseid = $this->course->id; $params->contextid = $this->contextid; $PAGE->requires->data_for_js('comment_params', $params); $CFG->commentcommentcode = true; } if (!empty($this->viewcap)) { // print commenting icon and tooltip $html = <<<EOD <a id="comment-link-{$this->cid}" onclick="return view_comments('{$this->cid}', '{$this->commentarea}', '{$this->itemid}', 0)" href="{$this->link}"> <img id="comment-img-{$this->cid}" src="{$CFG->wwwroot}/pix/t/collapsed.png" alt="{$this->linktext}" title="{$this->linktext}" /> <span>{$this->linktext}</span> </a> <div id="comment-ctrl-{$this->cid}" class="comment-ctrl"> <div class="comment-list-wrapper"> <ul id="comment-list-{$this->cid}" class="comment-list"> </ul> </div> <div id="comment-pagination-{$this->cid}" class="comment-pagination"></div> EOD; // print posting textarea if (!empty($this->postcap)) { $html .= <<<EOD <div class='comment-area'> <div class="bd"> <form method="POST" id="comment-form-{$this->cid}" action="{$CFG->wwwroot}/comment/comment_post.php"> <textarea name="content" rows="1" id="dlg-content-{$this->cid}"></textarea> <input type="hidden" name="contextid" value="{$this->contextid}" /> <input type="hidden" name="action" value="add" /> <input type="hidden" name="area" value="{$this->commentarea}" /> <input type="hidden" name="itemid" value="{$this->itemid}" /> <input type="hidden" name="courseid" value="{$this->course->id}" /> <input type="hidden" name="sesskey" value="{$sesskey}" /> <input type="hidden" name="client_id" value="{$this->cid}" /> </form> </div> <div class="fd" id="comment-action-{$this->cid}"> <a href="###" onclick="post_comment('{$this->cid}')"> {$strsubmit} </a> EOD; if ($this->env != 'block_comments') { $html .= <<<EOD <span> | </span> <a href="###" onclick="view_comments('{$this->cid}')"> {$strcancel} </a> EOD; } $html .= <<<EOD </div> </div> <div style="clear:both"></div> EOD; } $html .= <<<EOD </div> EOD; } else { $html = ''; } if ($return) { return $html; } else { echo $html; } }
/** * Display a repository instance list (with edit/delete/create links) * @global object $CFG * @global object $USER * @global object $OUTPUT * @param object $context the context for which we display the instance * @param string $typename if set, we display only one type of instance */ public static function display_instances_list($context, $typename = null) { global $CFG, $USER, $OUTPUT; $output = $OUTPUT->box_start('generalbox'); //if the context is SYSTEM, so we call it from administration page $admin = ($context->id == SYSCONTEXTID) ? true : false; if ($admin) { $baseurl = new moodle_url('/'.$CFG->admin.'/repositoryinstance.php', array('sesskey'=>sesskey())); $output .= $OUTPUT->heading(get_string('siteinstances', 'repository')); } else { $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid'=>$context->id, 'sesskey'=>sesskey())); } $url = $baseurl; $namestr = get_string('name'); $pluginstr = get_string('plugin', 'repository'); $settingsstr = get_string('settings'); $deletestr = get_string('delete'); //retrieve list of instances. In administration context we want to display all //instances of a type, even if this type is not visible. In course/user context we //want to display only visible instances, but for every type types. The repository::get_instances() //third parameter displays only visible type. $params = array(); $params['context'] = array($context, get_system_context()); $params['currentcontext'] = $context; $params['onlyvisible'] = !$admin; $params['type'] = $typename; $instances = repository::get_instances($params); $instancesnumber = count($instances); $alreadyplugins = array(); $table = new html_table(); $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr); $table->align = array('left', 'left', 'center','center'); $table->data = array(); $updowncount = 1; foreach ($instances as $i) { $settings = ''; $delete = ''; $type = repository::get_type_by_id($i->options['typeid']); if ($type->get_contextvisibility($context)) { if (!$i->readonly) { $url->param('type', $i->options['type']); $url->param('edit', $i->id); $settings .= html_writer::link($url, $settingsstr); $url->remove_params('edit'); $url->param('delete', $i->id); $delete .= html_writer::link($url, $deletestr); $url->remove_params('type'); } } $type = repository::get_type_by_id($i->options['typeid']); $table->data[] = array($i->name, $type->get_readablename(), $settings, $delete); //display a grey row if the type is defined as not visible if (isset($type) && !$type->get_visible()) { $table->rowclasses[] = 'dimmed_text'; } else { $table->rowclasses[] = ''; } if (!in_array($i->name, $alreadyplugins)) { $alreadyplugins[] = $i->name; } } $output .= html_writer::table($table); $instancehtml = '<div>'; $addable = 0; //if no type is set, we can create all type of instance if (!$typename) { $instancehtml .= '<h3>'; $instancehtml .= get_string('createrepository', 'repository'); $instancehtml .= '</h3><ul>'; $types = repository::get_editable_types($context); foreach ($types as $type) { if (!empty($type) && $type->get_visible()) { $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names'); if (!empty($instanceoptionnames)) { $baseurl->param('new', $type->get_typename()); $instancehtml .= '<li><a href="'.$baseurl->out().'">'.get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_'.$type->get_typename())). '</a></li>'; $baseurl->remove_params('new'); $addable++; } } } $instancehtml .= '</ul>'; } else { $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names'); if (!empty($instanceoptionnames)) { //create a unique type of instance $addable = 1; $baseurl->param('new', $typename); $instancehtml .= "<form action='".$baseurl->out()."' method='post'> <p><input type='submit' value='".get_string('createinstance', 'repository')."'/></p> </form>"; $baseurl->remove_params('new'); } } if ($addable) { $instancehtml .= '</div>'; $output .= $instancehtml; } $output .= $OUTPUT->box_end(); //print the list + creation links print($output); }
/** * Displays a view mode selector. * * @param array $modes An array of view modes. * @param string $currentmode The current view mode. * @param moodle_url $url The URL to use when changing actions. Defaults to the page URL. * @param string $param The param name. * @return string */ public function view_mode_selector(array $modes, $currentmode, moodle_url $url = null, $param = 'view') { if ($url === null) { $url = $this->page->url; } $menu = new action_menu(); $menu->attributes['class'] .= ' view-mode-selector vms'; $selected = null; foreach ($modes as $mode => $modestr) { $attributes = array('class' => 'vms-mode', 'data-mode' => $mode); if ($currentmode === $mode) { $attributes['class'] .= ' currentmode'; $selected = $modestr; } if ($selected === null) { $selected = $modestr; } $modeurl = new moodle_url($url, array($param => $mode)); if ($mode === 'default') { $modeurl->remove_params($param); } $menu->add(new action_menu_link_secondary($modeurl, null, $modestr, $attributes)); } $menu->set_menu_trigger(get_string('viewing', 'moodle', $selected)); $html = html_writer::start_div('view-mode-selector vms'); $html .= $this->render($menu); $html .= html_writer::end_div(); return $html; }
/** * strip off action parameters like 'removecontact' * * @deprecated since Moodle 3.2 * @param moodle_url/string $moodleurl a URL. Typically the current page URL. * @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact). */ function message_remove_url_params($moodleurl) { debugging('message_remove_url_params() is deprecated and is no longer used.', DEBUG_DEVELOPER); $newurl = new moodle_url($moodleurl); $newurl->remove_params('addcontact', 'removecontact', 'blockcontact', 'unblockcontact'); return $newurl->out(); }
// We need to make it diferently for normal courses and site course. if (!$isfrontpage) { $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess) FROM {user_lastaccess} WHERE courseid = ? AND timeaccess != 0', array($course->id)); $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid' => $course->id, 'timeaccess' => 0)); } else { $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess) FROM {user} WHERE lastaccess != 0'); $lastaccess0exists = $DB->record_exists('user', array('lastaccess' => 0)); } $now = usergetmidnight(time()); $timeaccess = array(); $baseurl->remove_params('accesssince'); // Makes sense for this to go first. $timeoptions[0] = get_string('selectperiod'); // Days. for ($i = 1; $i < 7; $i++) { if (strtotime('-' . $i . ' days', $now) >= $minlastaccess) { $timeoptions[strtotime('-' . $i . ' days', $now)] = get_string('numdays', 'moodle', $i); } } // Weeks. for ($i = 1; $i < 10; $i++) { if (strtotime('-' . $i . ' weeks', $now) >= $minlastaccess) { $timeoptions[strtotime('-' . $i . ' weeks', $now)] = get_string('numweeks', 'moodle', $i); } } // Months.
/** * chat block * * @param object $request request from client * @param object $response response */ function helpmenow_serverfunc_block($request, &$response) { global $USER, $CFG, $OUTPUT, $DB; #echo "entered serverfunc_block: " . microtime() . "\n"; # DEBUGGING $DB->set_field('block_helpmenow_user', 'lastaccess', time(), array('userid' => $USER->id)); # update our user lastaccess helpmenow_log($USER->id, 'block refresh', ''); $response->last_refresh = get_string('updated', 'block_helpmenow') . ': ' . userdate(time(), '%r'); # datetime for debugging $response->pending = 0; $response->alert = false; #echo "bumped lastaccess/logged: " . microtime() . "\n"; # DEBUGGING /** * queues */ $response->queues_html = ''; $connect = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/connect.php"); $queues = helpmenow_queue::get_queues(); foreach ($queues as $q) { $response->queues_html .= '<div>'; switch ($q->get_privilege()) { case HELPMENOW_QUEUE_HELPEE: case HELPMENOW_QUEUE_HELPER: $sql = "\n SELECT s.*, m.message, m.id AS messageid\n FROM {block_helpmenow_session} s\n JOIN {block_helpmenow_session2user} s2u ON s2u.sessionid = s.id AND s2u.userid = s.createdby\n JOIN {block_helpmenow_message} m ON m.id = (\n SELECT MAX(id) FROM {block_helpmenow_message} m2 WHERE m2.sessionid = s.id AND m2.userid <> s.createdby\n )\n WHERE s.iscurrent = 1\n AND s.createdby = {$USER->id}\n AND s.queueid = {$q->id}\n AND (s2u.last_refresh + 20) < " . time() . "\n AND s2u.last_refresh < m.time\n "; if ($session = $DB->get_record_sql($sql) or $q->is_open()) { $connect->remove_params('sessionid'); $connect->param('queueid', $q->id); $message = $style = ''; if ($session) { $response->pending++; $style = ' style="background-color:yellow"'; $message = '<div style="margin-left: 1em;">' . $session->message . '</div>' . $message; if (helpmenow_notify_once($session->messageid)) { $response->alert = true; } } $response->queues_html .= "<div{$style}>" . create_popup($q->name, $connect->out(), "queue{$q->id}") . "{$message}</div>"; } else { $response->queues_html .= "<div>{$q->name}</div>"; } if ($q->get_privilege() == HELPMENOW_QUEUE_HELPEE) { break; } $instyle = $outstyle = ''; if ($q->helpers[$USER->id]->isloggedin) { $outstyle = 'style="display: none;"'; } else { $instyle = 'style="display: none;"'; } $login_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/login.php"); $login_url->param('queueid', $q->id); $login_url->param('login', 0); $logout = create_popup(get_string('logout', 'block_helpmenow'), $login_url->out(), "login"); $login_url->param('login', 1); $login = create_popup(get_string('login', 'block_helpmenow'), $login_url->out(), "login"); $logout_status = get_string('logout_status', 'block_helpmenow'); $response->queues_html .= <<<EOF <div style="text-align: center; font-size:small; margin-top:.5em; margin-bottom:.5em;"> <div id="helpmenow_logged_in_div_{$q->id}" {$instyle}>{$logout}</div> <div id="helpmenow_logged_out_div_{$q->id}" {$outstyle}>{$logout_status} | {$login}</div> </div> EOF; # sessions $sql = "\n SELECT u.*, s.id AS sessionid, m.message, m.time, m.id AS messageid\n FROM {block_helpmenow_session} s\n JOIN {user} u ON u.id = s.createdby\n JOIN {block_helpmenow_message} m ON m.id = (\n SELECT MAX(id) FROM {block_helpmenow_message} m2 WHERE m2.sessionid = s.id AND m2.userid = s.createdby\n )\n WHERE s.queueid = {$q->id}\n AND s.iscurrent = 1\n "; if (!($sessions = $DB->get_records_sql($sql))) { break; } $response->queues_html .= '<div style="margin-left: 1em;">'; foreach ($sessions as &$s) { $s->pending = true; $sql = "\n SELECT *\n FROM {block_helpmenow_session2user} s2u\n JOIN {user} u ON u.id = s2u.userid\n WHERE s2u.sessionid = {$s->sessionid}\n AND s2u.userid <> {$s->id}\n "; $s->helpers = $DB->get_records_sql($sql); foreach ($s->helpers as $h) { if ($s->pending) { if ($h->last_refresh + 20 > time()) { $s->pending = false; } if ($h->last_refresh > $s->time) { $s->pending = false; } } if (!isset($s->helper_names)) { $s->helper_names = fullname($h); } else { $s->helper_names .= ', ' . fullname($h); } } } unset($s); # sort by unseen messages, lastname, firstname usort($sessions, function ($a, $b) { if (!($a->pending xor $b->pending)) { return strcmp(strtolower("{$a->lastname} {$a->firstname}"), strtolower("{$b->lastname} {$b->firstname}")); } return $a->pending ? -1 : 1; }); foreach ($sessions as $s) { $connect->remove_params('queueid'); $connect->param('sessionid', $s->sessionid); $message = $style = ''; if ($s->pending) { $response->pending++; $style = ' style="background-color:yellow"'; $message .= '"' . $s->message . '"<br />'; if ($q->helpers[$USER->id]->isloggedin) { if (helpmenow_notify_once($s->messageid)) { $response->alert = true; } } } if (isset($s->helper_names)) { $message .= '<small>' . $s->helper_names . '</small><br />'; } $message = '<div style="margin-left: 1em;">' . $message . '</div>'; $response->queues_html .= "<div{$style}>" . create_popup(fullname($s), $connect->out(), $s->sessionid) . "{$message}</div>"; } $response->queues_html .= '</div>'; break; } $desc_message = '<div style="margin-left: 1em; font-size: smaller;">' . $q->description . '</div>'; $response->queues_html .= '</div>' . $desc_message . '<hr />'; } #echo "processed queues: " . microtime() . "\n"; # DEBUGGING # show the correct login state for instructors $isloggedin = $DB->get_field('block_helpmenow_user', 'isloggedin', array('userid' => $USER->id)); if (!is_null($isloggedin)) { $response->isloggedin = $isloggedin ? true : false; } # build contact list $response->users_html = ''; $sql = "\n SELECT u.*, hu.isloggedin, hu.motd, hu.lastaccess AS hmn_lastaccess\n FROM {block_helpmenow_contact} c\n JOIN {user} u ON u.id = c.contact_userid\n JOIN {block_helpmenow_user} hu ON c.contact_userid = hu.userid\n WHERE c.userid = {$USER->id}\n "; $contacts = $DB->get_records_sql($sql); if (!$contacts) { return; } #echo "selected contacts: " . microtime() . "\n"; # DEBUGGING $cutoff = helpmenow_cutoff(); foreach ($contacts as $u) { $u->online = false; if ($u->hmn_lastaccess > $cutoff and (is_null($u->isloggedin) or $u->isloggedin != 0)) { $u->online = true; $sql = "\n SELECT s.id, m.message, m.time, m.id AS messageid, s2u2.last_refresh\n FROM mdl_block_helpmenow_session2user s2u\n JOIN mdl_block_helpmenow_session s ON s.iscurrent = 1 AND s.queueid IS NULL AND s.id = s2u.sessionid\n JOIN mdl_block_helpmenow_session2user s2u2 ON s2u2.sessionid = s.id AND s2u2.userid = {$USER->id}\n JOIN mdl_block_helpmenow_message m ON m.userid = s2u.userid AND m.sessionid = s2u.sessionid\n WHERE s2u.userid = {$u->id}\n ORDER BY m.id DESC\n "; if (!($message = $DB->get_record_sql($sql))) { continue; } print_object($message); if ($message->time < $message->last_refresh + HELPMENOW_BLOCK_ALERT_DELAY) { continue; } $u->message = $message->message; $u->messageid = $message->messageid; } } #echo "selected contact messages: " . microtime() . "\n"; # DEBUGGING # sort by unseen messages, online, lastname, firstname usort($contacts, function ($a, $b) { if (isset($a->message) xor isset($b->message)) { return isset($a->message) ? -1 : 1; } if ($a->online xor $b->online) { return $a->online ? -1 : 1; } return strcmp(strtolower("{$a->lastname} {$a->firstname}"), strtolower("{$b->lastname} {$b->firstname}")); }); #echo "sorted contacts: " . microtime() . "\n"; # DEBUGGING $connect->remove_params('queueid'); $connect->remove_params('sessionid'); foreach ($contacts as $u) { $connect->param('userid', $u->id); $message = ''; $style = 'margin-left: 1em;'; if (!isset($u->isloggedin)) { # if isloggedin is null, the user is always logged in when they are online if ($u->online) { if ($isloggedin) { $name = create_popup(fullname($u), $connect->out(), $u->id); } else { $name = fullname($u); } } else { continue; } } else { # if isloggedin is set, then 0 = loggedout, any other number is the timestamp of when they logged in if ($u->online) { $name = create_popup(fullname($u), $connect->out(), $u->id); $motd = $u->motd; } else { $name = fullname($u); $motd = get_string('offline', 'block_helpmenow'); } $message .= '<div style="font-size: smaller;">' . $motd . '</div>'; } if (isset($u->message)) { $response->pending++; $style .= 'background-color:yellow;'; $message .= '<div>' . $u->message . '</div>'; if (helpmenow_notify_once($u->messageid)) { $response->alert = true; } } $message = '<div style="margin-left: 1em;">' . $message . '</div>'; $response->users_html .= "<div style=\"{$style}\">" . $name . $message . "</div>"; } #echo "printed contacts: " . microtime() . "\n"; # DEBUGGING }