} } ?> </div> <div class="nav_links"> <?php $reg_link = '<a class="nav_link" href="' . iclicker_service::block_url('registration.php') . '">' . iclicker_service::msg('reg.title') . '</a>'; $nav_links = $reg_link . PHP_EOL; // the other links $nav_links .= ' | <a class="nav_link current_nav_link" href="' . iclicker_service::block_url('instructor.php') . '">' . iclicker_service::msg('inst.title') . '</a>' . PHP_EOL; if (iclicker_service::$block_iclicker_sso_enabled) { $nav_links .= ' | <a class="nav_link" href="' . iclicker_service::block_url('instructor_sso.php') . '">' . iclicker_service::msg('inst.sso.title') . '</a>' . PHP_EOL; } if (iclicker_service::is_admin()) { $nav_links .= ' | <a class="nav_link" href="' . iclicker_service::block_url('admin.php') . '">' . iclicker_service::msg('admin.title') . '</a>' . PHP_EOL; } echo $nav_links; ?> </div> <div class="iclicker_version">Version <?php echo iclicker_service::VERSION; ?> (<?php echo iclicker_service::BLOCK_VERSION; ?> )</div> </div>
public function processAdmin() { global $CFG; $adminPath = iclicker_service::block_url('admin.php'); $this->results['adminPath'] = $adminPath; $this->results['status_url'] = iclicker_service::block_url('runner_status.php'); // admin check if (!iclicker_service::is_admin()) { throw new ClickerSecurityException("Current user is not an admin and cannot access the admin view"); } // get sorting params $pageNum = 1; $perPageNum = 20; // does not change if (optional_param('page', null, PARAM_ALPHANUM) != null) { $pageNum = required_param('page', PARAM_INT); if ($pageNum < 1) { $pageNum = 1; } } $sort = 'clicker_id'; if (optional_param('sort', null, PARAM_ALPHANUM) != null) { $sort = required_param('sort', PARAM_ALPHANUMEXT); } $this->results['sort'] = $sort; // get filtering params $search = optional_param('search', null, PARAM_ALPHANUMEXT); if (empty($search)) { $search = null; } $startDate = null; $startDateText = ''; if (optional_param('start_date', null, PARAM_ALPHANUMEXT) != null) { $startDate = required_param('start_date', PARAM_ALPHANUMEXT); $startDate = strtotime($startDate); if ($startDate) { $startDateText = date('Y-m-d', $startDate); } else { $startDate = null; } } $endDate = null; $endDateText = ''; if (optional_param('end_date', null, PARAM_ALPHANUMEXT) != null) { $endDate = required_param('end_date', PARAM_ALPHANUMEXT); $endDate = strtotime($endDate); if ($endDate) { // need to make this the end of the day $endDT = new DateTime('@' . $endDate); $endDT->setTimezone(new DateTimeZone(date_default_timezone_get())); $endDT->setTime(23, 59, 59); $endDate = $endDT->getTimestamp(); $endDateText = date('Y-m-d', $endDate); } else { $endDate = null; } } if ("POST" == $this->method) { if (optional_param('activate', null, PARAM_ALPHANUM) != null) { // First arrived at this page $activate = required_param('activate', PARAM_BOOL); if (optional_param('registrationId', null, PARAM_ALPHANUMEXT) == null) { $this->addMessage(self::KEY_ERROR, "reg.activate.registrationId.empty", null); } else { $reg_id = required_param('registrationId', PARAM_INT); // save a new clicker registration $cr = iclicker_service::set_registration_active($reg_id, $activate); if ($cr) { $args = new stdClass(); $args->cid = $cr->clicker_id; $args->user = iclicker_service::get_user_displayname($cr->owner_id); $this->addMessage(self::KEY_INFO, "admin.activate.success." . ($cr->activated ? 'true' : 'false'), $args); } } } else { if (optional_param('remove', null, PARAM_ALPHANUM) != null) { if (optional_param('registrationId', null, PARAM_ALPHANUMEXT) == null) { $this->addMessage(self::KEY_ERROR, "reg.activate.registrationId.empty", null); } else { $reg_id = required_param('registrationId', PARAM_INT); $cr = iclicker_service::get_registration_by_id($reg_id); if ($cr) { iclicker_service::remove_registration($reg_id); $args = new stdClass(); $args->cid = $cr->clicker_id; $args->rid = $reg_id; $args->user = iclicker_service::get_user_displayname($cr->owner_id); $this->addMessage(self::KEY_INFO, "admin.delete.success", $args); } } } else { if (optional_param('purge', null, PARAM_ALPHANUM) != null) { // actually do the purging $count = iclicker_service::purge_registrations($search, $startDate, $endDate); $this->addMessage(self::KEY_INFO, "admin.purge.success", $count); // reset all search params to defaults $search = null; $startDate = null; $endDate = null; $pageNum = 1; $perPageNum = 20; $sort = 'clicker_id'; } else { // invalid POST error_log('WARN: Invalid POST: does not contain remove, purge, or activate, nothing to do'); } } } } // put search and sort data into the page $this->results['search'] = $search; $this->results['startDate'] = $startDate; $this->results['startDateText'] = $startDateText; $this->results['endDate'] = $endDate; $this->results['endDateText'] = $endDateText; $this->results['page'] = $pageNum; $this->results['perPage'] = $perPageNum; $this->results['sort'] = $sort; // put config data into page $this->results['sso_enabled'] = iclicker_service::$block_iclicker_sso_enabled; $this->results['sso_shared_key'] = iclicker_service::$block_iclicker_sso_shared_key; $this->results['domainURL'] = iclicker_service::$domain_URL; $this->results['adminEmailAddress'] = empty($CFG->block_iclicker_notify_emails) ? '' : $CFG->block_iclicker_notify_emails; // put error data into page $this->results['recent_failures'] = iclicker_service::get_failures(); // handling the calcs for paging $first = ($pageNum - 1) * $perPageNum; $totalCount = iclicker_service::count_all_registrations($search, $startDate, $endDate); $pageCount = floor(($totalCount + $perPageNum - 1) / $perPageNum); $this->results['total_count'] = $totalCount; $this->results['page_count'] = $pageCount; $this->results['registrations'] = iclicker_service::get_all_registrations($first, $perPageNum, $sort, $search, $startDate, $endDate); $pagerHTML = ""; if ($totalCount > 0) { $timestamp = microtime(); for ($i = 0; $i < $pageCount; $i++) { $currentPage = $i + 1; $currentStart = $i * $perPageNum + 1; $currentEnd = $currentStart + $perPageNum - 1; if ($currentEnd > $totalCount) { $currentEnd = $totalCount; } $marker = '[' . $currentStart . '..' . $currentEnd . ']'; if ($currentPage == $pageNum) { // make it bold and not a link $pagerHTML .= '<span class="paging_current paging_item">' . $marker . '</span>' . "\n"; } else { // make it a link $pagingURL = $adminPath . '?page=' . $currentPage . '&sort=' . $sort; if (isset($search)) { $pagingURL .= '&search=' . urlencode($search); } if (!empty($startDateText)) { $pagingURL .= '&start_date=' . urlencode($startDateText); } if (!empty($endDateText)) { $pagingURL .= '&end_date=' . urlencode($endDateText); } $pagingURL .= '&nc=' . ($timestamp . $currentPage); $pagerHTML .= '<a class="paging_link paging_item" href="' . $pagingURL . '">' . $marker . '</a>' . "\n"; } } $this->results['pagerHTML'] = $pagerHTML; } }
</div> </div> </div> <div class="nav_links"> <?php $reg_link = '<a class="nav_link current_nav_link" href="' . iclicker_service::block_url('registration.php') . '">' . iclicker_service::msg('reg.title') . '</a>'; $nav_links = $reg_link . PHP_EOL; // the other links if (iclicker_service::is_admin()) { $nav_links .= ' | <a class="nav_link" href="' . iclicker_service::block_url('admin.php') . '">' . iclicker_service::msg('admin.title') . '</a>' . PHP_EOL; } else { if (iclicker_service::is_instructor()) { $nav_links .= ' | <a class="nav_link" href="' . iclicker_service::block_url('instructor.php') . '">' . iclicker_service::msg('inst.title') . '</a>' . PHP_EOL; if (iclicker_service::$block_iclicker_sso_enabled) { $nav_links .= ' | <a class="nav_link" href="' . iclicker_service::block_url('instructor_sso.php') . '">' . iclicker_service::msg('inst.sso.title') . '</a>' . PHP_EOL; } } } echo $nav_links; ?> </div> <div class="iclicker_version">Version <?php echo iclicker_service::VERSION; ?> (<?php echo iclicker_service::BLOCK_VERSION; ?> )</div>
//log.warn("i>clicker: " + $output, $e); $status = 400; //BAD_REQUEST; } catch (ClickerSSLRequiredException $e) { $valid = false; $output = "SSL_REQUIRED: " . $e; //log.warn("i>clicker: " + $output, $e); $status = 426; //UPGRADE_REQUIRED; } catch (Exception $e) { $valid = false; $output = "Failure occurred: " . $e; //log.warn("i>clicker: " + $output, $e); $status = 500; //INTERNAL_SERVER_ERROR; } } if ($valid) { // send the response $cntlr->setStatus(200); $cntlr->setContentType('application/xml'); $output = iclicker_controller::XML_HEADER . $output; $cntlr->sendResponse($output); } else { // error with info about how to do it right $cntlr->setStatus($status); $cntlr->setContentType('text/plain'); // add helpful info to the output $msg = "ERROR {$status}: Invalid request (" . $cntlr->method . " /" . $cntlr->path . ")" . "\n\n=INFO========================================================================================\n" . $output . "\n\n-HELP----------------------------------------------------------------------------------------\n" . "Valid request paths include the following (without the block prefix: " . iclicker_service::block_url('rest.php') . "):\n" . "POST /authenticate - authenticate by sending credentials (" . iclicker_controller::LOGIN . "," . iclicker_controller::PASSWORD . ") \n" . " return status 204 (valid login) \n" . "POST /verifykey - check the encoded key is valid and matches the shared key \n" . " return 200 if valid OR 501 if SSO not enabled OR 400/401 if key is bad \n" . "POST /register - Add a new clicker registration, return 200 for success or 400 with \n" . " registration response (XML) for failure \n" . "GET /courses - returns the list of courses for the current user (XML) \n" . "GET /students/{course_id} - returns the list of student enrollments for the given course (XML) \n" . " or 403 if user is not an instructor in the specified course \n" . "POST /gradebook/{course_id} - send the gradebook data into the system, returns errors on failure (XML) \n" . " or 'True' if no errors, 400 if the xml is missing or course_id is invalid, \n" . " 403 if user is not an instructor in the specified course \n" . "\n" . " - Authenticate by sending credentials (" . iclicker_controller::LOGIN . "," . iclicker_controller::PASSWORD . ") in the request parameters \n" . " -- SSO authentication requires an encoded key (" . iclicker_controller::SSO_KEY . ") in the request parameters \n" . " -- The response headers will include the sessionId when credentials are valid \n" . " -- Invalid credentials or sessionId will result in a 401 (invalid credentials) or 403 (not authorized) status \n" . " - Use " . iclicker_controller::COMPENSATE_METHOD . " param to override the http method being used (e.g. POST /courses?" . iclicker_controller::COMPENSATE_METHOD . "=GET will force the method to be a GET despite sending as a POST) \n" . " - Send data as the http request BODY or as a form parameter called " . iclicker_controller::XML_DATA . " \n" . " - All endpoints return 403 if user is not an instructor \n" . " - Version: " . iclicker_service::VERSION . " (" . iclicker_service::BLOCK_VERSION . ") \n"; $cntlr->sendResponse($msg); }
/** * Determines the content to display in a block * * Blocks use two properties of $this->content: "text" and "footer". * The text is displayed as-is as the block content, and the footer is displayed below the content in a smaller font size. * * List blocks use $this->content->footer in the exact same way, * but they ignore $this->content->text. * Moodle expects such blocks to set two other properties when the get_content() method is called: * $this->content->items and $this->content->icons. * $this->content->items should be a numerically indexed array containing elements that * represent the HTML for each item in the list that is going to be displayed. * Usually these items will be HTML anchor tags which provide links to some page. * $this->content->icons should also be a numerically indexed array, with exactly as many items * as $this->content->items has. Each of these items should be a fully qualified HTML <img> tag, * with "src", "height", "width" and "alt" attributes. Obviously, it makes sense to keep the images * small and of a uniform size. * In order to tell Moodle that we want to have a list block instead of the standard text block, * we need to make a small change to our block class declaration. * Instead of extending class block_base, our block will extend class block_list. * * You can hide the block by displaying nothing. That means that both * $this->content->text and $this->content->footer are each equal to the * empty string (''). Moodle performs this check by calling the block's * is_empty() method, and if the block is indeed empty then it is not * displayed at all. * * @return string the content to display in the block */ function get_content() { // for iclicker we will just render links here and possibly an indicator to show if you have registered a clicker global $CFG, $USER, $COURSE; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; if (iclicker_service::get_current_user_id()) { $this->content->text = "<div class='iclicker_nav_items'>\n"; $reg_link = '<a href="' . iclicker_service::block_url('registration.php') . '">' . iclicker_service::msg('reg.title') . '</a><br/>'; $this->content->text .= " " . $reg_link . "\n"; // also show the list of currently registered clickers $clicker_list_html = ''; if ($clickers = iclicker_service::get_registrations_by_user(null, true)) { $clicker_list_html .= " <ul class='iclicker_clickerids'>" . PHP_EOL; foreach ($clickers as $clicker) { $clicker_list_html .= " <li class='iclicker_clickerid'>{$clicker->clicker_id}</li>" . PHP_EOL; } $clicker_list_html .= " </ul>\n"; } $this->content->text .= $clicker_list_html; // the other links if (iclicker_service::is_admin()) { $link = '<a href="' . iclicker_service::block_url('admin.php') . '">' . iclicker_service::msg('admin.title') . '</a><br/>' . PHP_EOL; $this->content->text .= " " . $link . "\n"; // remove inst link after testing complete //$link = '<b><i>remove inst link</i></b> <a href="'.iclicker_service::block_url('instructor.php').'">'.iclicker_service::msg('inst.title').'</a>'; //$this->content->text .= " ".$link."\n"; } else { if (iclicker_service::is_instructor()) { $link = '<a href="' . iclicker_service::block_url('instructor.php') . '">' . iclicker_service::msg('inst.title') . '</a><br/>' . PHP_EOL; $sso_link = ''; if (iclicker_service::$block_iclicker_sso_enabled) { $sso_link = '<a class="nav_link" href="' . iclicker_service::block_url('instructor_sso.php') . '">' . iclicker_service::msg('inst.sso.title') . '</a><br/>' . PHP_EOL; } $this->content->text .= ' ' . $link . $sso_link; } } // close out the html $this->content->text .= "</div>" . PHP_EOL; } // FOOTER //$this->content->footer = '<a href="'.$CFG->wwwroot.'/blocks/iclicker/page.php?blockid='.$this->instance->id.'&courseid='.$COURSE->id.'">'.get_string('addpage', 'block_iclicker').'</a>'; $this->content->footer = ''; // Sample list items //$this->content->items[] = '<a href="some_file.php">Menu Option 1</a>'; //$this->content->icons[] = '<img src="images/icons/1.gif" class="icon" alt="" />'; return $this->content; }