/**
 * This will check for a user and return the user_id if one can be found
 * @param string $msg the error message
 * @return int the user_id
 * @throws ClickerSecurityException if no user can be found
 */
function iclicker_get_and_check_current_user($msg)
{
    $user_id = iclicker_service::get_current_user_id();
    if (!$user_id) {
        throw new ClickerSecurityException("Only logged in users can {$msg}");
    }
    if (!iclicker_service::is_admin($user_id) && !iclicker_service::is_instructor($user_id)) {
        throw new ClickerSecurityException("Only instructors can " . $msg);
    }
    return $user_id;
}
/* forced to sharing on for now
   <li class="admin_config_list_item">
       <?php echo iclicker_service::msg('config_allow_sharing') ?>:
       <?php echo (iclicker_service::$allow_remote_sharing) ? iclicker_service::msg('app.allowed') : iclicker_service::msg('config_notify_emails_disabled') ?>
   </li> */
?>
            </ul>
        </fieldset>
    </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
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;
    }
}
$nav_links .= ' | <a class="nav_link current_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;
 public function processInstructorSSO()
 {
     $this->results['instPath'] = iclicker_service::block_url('instructor.php');
     // admin/instructor check
     if (!iclicker_service::is_admin() && !iclicker_service::is_instructor()) {
         throw new ClickerSecurityException("Current user is not an instructor and cannot access the instructor view");
     }
     $this->results['sso_enabled'] = iclicker_service::$block_iclicker_sso_enabled;
     $current_user_id = iclicker_service::get_current_user_id();
     if (iclicker_service::$block_iclicker_sso_enabled) {
         $current_user_key = null;
         if ('POST' == $this->method) {
             if (optional_param('generateKey', false, PARAM_ALPHANUM) != null) {
                 // handle generating a new key
                 $current_user_key = iclicker_service::makeUserKey($current_user_id, true);
                 $this->addMessage(self::KEY_INFO, 'inst.sso.generated.new.key', null);
             }
         }
         if ($current_user_key == null) {
             $current_user_key = iclicker_service::makeUserKey($current_user_id, false);
         }
         $this->results['sso_user_key'] = $current_user_key;
     }
     //$current_user_key = iclicker_service::makeUserKey($current_user_id);
     //$this->results['sso_user_key'] = $current_user_key;
 }
 /**
  * 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;
 }