Example #1
0
    public function renderSingle()
    {
        global $CFG;
        $module = $this->module;
        echo '<div style="float:right; padding-left: 5px; vertical-align: text-top;"><ul class="pager">' . "\n";
        $disabled = $this->position == 1 ? ' disabled' : '';
        if ($this->position == 1) {
            echo '<li class="previous disabled"><a href="#" onclick="return false;">&larr; Previous</a></li>' . "\n";
        } else {
            $prev = 'index=' . ($this->position - 1);
            if (isset($this->lessons->modules[$this->position - 2]->anchor)) {
                $prev = 'anchor=' . $this->lessons->modules[$this->position - 2]->anchor;
            }
            echo '<li class="previous"><a href="lessons.php?' . $prev . '">&larr; Previous</a></li>' . "\n";
        }
        echo '<li><a href="lessons.php">All (' . $this->position . ' / ' . count($this->lessons->modules) . ')</a></li>';
        if ($this->position >= count($this->lessons->modules)) {
            echo '<li class="next disabled"><a href="#" onclick="return false;">&rarr; Next</a></li>' . "\n";
        } else {
            $next = 'index=' . ($this->position + 1);
            if (isset($this->lessons->modules[$this->position]->anchor)) {
                $next = 'anchor=' . $this->lessons->modules[$this->position]->anchor;
            }
            echo '<li class="next"><a href="lessons.php?' . $next . '">&rarr; Next</a></li>' . "\n";
        }
        echo "</ul></div>\n";
        echo '<h1>' . $module->title . "</h1>\n";
        if (isset($module->videos)) {
            $videos = $module->videos;
            echo '<ul class="bxslider">' . "\n";
            foreach ($videos as $video) {
                echo '<li><iframe src="https://www.youtube.com/embed/' . $video->youtube . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen ' . ' alt="' . htmlentities($video->title) . '"></iframe>' . "\n";
            }
            echo "</ul>\n";
        }
        if (isset($module->description)) {
            echo '<p>' . $module->description . "</p>\n";
        }
        echo "<ul>\n";
        if (isset($module->slides)) {
            echo '<li><a href="' . $module->slides . '" target="_blank">Slides</a></li>' . "\n";
        }
        if (isset($module->chapters)) {
            echo '<li>Chapters: ' . $module->chapters . '</a></li>' . "\n";
        }
        if (isset($module->assignment)) {
            echo '<li><a href="' . $module->assignment . '" target="_blank">Assignment Specification</a></li>' . "\n";
        }
        if (isset($module->solution)) {
            echo '<li><a href="' . $module->solution . '" target="_blank">Assignment Solution</a></li>' . "\n";
        }
        if (isset($module->references)) {
            if (count($module->references) > 0) {
                echo "<li>References:<ul>\n";
                foreach ($module->references as $reference) {
                    echo '<li><a href="' . $reference->href . '" target="_blank">' . $reference->title . "</a></li>\n";
                }
                echo "</ul></li>\n";
            } else {
                echo '<li>Reference: <a href="' . $module->references->href . '" target="_blank">' . $module->references->title . "</a></li>\n";
            }
        }
        if (isset($module->lti) && isset($_SESSION['secret'])) {
            $ltis = $module->lti;
            if (count($ltis) > 1) {
                echo "<li>Tools:<ul> <!-- start of ltis -->\n";
            }
            $count = 0;
            foreach ($ltis as $lti) {
                $key = isset($_SESSION['oauth_consumer_key']) ? $_SESSION['oauth_consumer_key'] : false;
                $secret = isset($_SESSION['secret']) ? $_SESSION['secret'] : false;
                if (isset($lti->resource_link_id)) {
                    $resource_link_id = $lti->resource_link_id;
                } else {
                    $resource_link_id = 'resource:';
                    if ($this->anchor != null) {
                        $resource_link_id .= $this->anchor . ':';
                    }
                    if ($this->position != null) {
                        $resource_link_id .= $this->position . ':';
                    }
                    if ($count > 0) {
                        $resource_link_id .= '_' . $count;
                    }
                    $resource_link_id .= md5($CFG->context_title);
                }
                $count++;
                $resource_link_title = isset($lti->title) ? $lti->title : $module->title;
                $parms = array('lti_message_type' => 'basic-lti-launch-request', 'resource_link_id' => $resource_link_id, 'resource_link_title' => $resource_link_title, 'tool_consumer_info_product_family_code' => 'tsugi', 'tool_consumer_info_version' => '1.1', 'context_id' => $_SESSION['context_key'], 'context_label' => $CFG->context_title, 'context_title' => $CFG->context_title, 'user_id' => $_SESSION['user_key'], 'lis_person_name_full' => $_SESSION['displayname'], 'lis_person_contact_email_primary' => $_SESSION['email'], 'roles' => 'Learner');
                if (isset($_SESSION['avatar'])) {
                    $parms['user_image'] = $_SESSION['avatar'];
                }
                if (isset($lti->custom)) {
                    foreach ($lti->custom as $custom) {
                        if (isset($custom->value)) {
                            $parms['custom_' . $custom->key] = $custom->value;
                        }
                        if (isset($custom->json)) {
                            $parms['custom_' . $custom->key] = json_encode($custom->json);
                        }
                    }
                }
                $return_url = $CFG->getCurrentUrl();
                if ($this->anchor) {
                    $return_url .= '?anchor=' . urlencode($this->anchor);
                } elseif ($this->position) {
                    $return_url .= '?index=' . urlencode($this->position);
                }
                $parms['launch_presentation_return_url'] = $return_url;
                if (isset($_SESSION['tsugi_top_nav'])) {
                    $parms['ext_tsugi_top_nav'] = $_SESSION['tsugi_top_nav'];
                }
                $form_id = "tsugi_form_id_" . bin2Hex(openssl_random_pseudo_bytes(4));
                $parms['ext_lti_form_id'] = $form_id;
                $endpoint = $lti->launch;
                $parms = LTI::signParameters($parms, $endpoint, "POST", $key, $secret, "Finish Launch", $CFG->product_instance_guid, $CFG->servicename);
                $content = LTI::postLaunchHTML($parms, $endpoint, false, '_pause');
                $title = isset($lti->title) ? $lti->title : "Autograder";
                echo '<li><a href="#" onclick="document.' . $form_id . '.submit();return false">' . htmlentities($title) . '</a></li>' . "\n";
                echo "<!-- Start of content -->\n";
                print $content;
                echo "<!-- End of content -->\n";
            }
            if (count($ltis) > 1) {
                echo "</li></ul><!-- end of ltis -->\n";
            }
        }
        if (!isset($module->discuss)) {
            $module->discuss = true;
        }
        if (!isset($module->anchor)) {
            $module->anchor = $this->position;
        }
        // For now do not add disqus to each page.
        if (false && isset($CFG->disqushost) && isset($_SESSION['id']) && $module->discuss) {
            ?>
<hr/>
<div id="disqus_thread" style="margin-top: 30px;"></div>
<script>

/**
 *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
 *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables */
var disqus_config = function () {
    this.page.url = '<?php 
            echo $CFG->disqushost;
            ?>
';  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = '<?php 
            echo $module->anchor;
            ?>
'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
(function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = '//php-intro.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<?php 
        }
    }
Example #2
0
 private function _generate_key()
 {
     do {
         // Generate a random salt
         $salt = bin2Hex($this->security->get_random_bytes(64));
         // If an error occurred, then fall back to the previous method
         if ($salt === FALSE) {
             $salt = hash('sha256', time() . mt_rand());
         }
         $new_key = substr($salt, 0, config_item('rest_key_length'));
     } while ($this->_key_exists($new_key));
     return $new_key;
 }
Example #3
0
 private function _Insert()
 {
     $ipinga = \ipinga\ipinga::getInstance();
     $sqlfields = array();
     $sqlparams = array();
     $sql = 'insert into ' . $this->tableName . ' (';
     foreach ($this->fieldTypes as $fieldName => $fieldType) {
         // timestamp takes care of itself in the database
         if ($fieldType != 'timestamp') {
             $sqlfields[] = $fieldName;
             $sqlparams[] = ':' . $fieldName;
         }
     }
     $sql = $sql . implode(',', $sqlfields) . ') values (' . implode(',', $sqlparams) . ')';
     $this->lastSql = $sql;
     $this->sqlParams = array();
     $sth = $ipinga->pdo()->prepare($sql);
     foreach ($this->fieldTypes as $fieldName => $fieldType) {
         // id and timestamp take care of themselves in the database
         if ($fieldType != 'timestamp') {
             if ($fieldName == 'created') {
                 $created = date('Y-m-d H:i:s');
                 $sth->bindParam(':' . $fieldName, $created);
                 $this->sqlParams[$fieldName] = $created;
             } elseif ($fieldName == 'passwd') {
                 $passwd = bin2Hex(\ipinga\crypto::encrypt($this->field[$fieldName]));
                 //            $passwd = base64_encode($this->field[$fieldName]);
                 $sth->bindParam(':' . $fieldName, $passwd);
                 $this->sqlParams[$fieldName] = $passwd;
             } else {
                 $sth->bindParam(':' . $fieldName, $this->field[$fieldName]);
                 $this->sqlParams[$fieldName] = $this->field[$fieldName];
             }
         }
     }
     $retval = false;
     try {
         $retval = $sth->execute();
         if ($this->field['id'] == 0) {
             $this->field['id'] = $ipinga->pdo()->lastInsertId();
         }
         $this->saved = true;
     } catch (\PDOException $e) {
         echo $e->getMessage() . '<br>' . $sql . '<br><hr>';
         $this->saved = false;
     }
     return $retval;
 }
Example #4
0
function randomBooleanArray($numBits)
{
    $bytesString = randomBytes($numBits);
    $hexString = bin2Hex($bytesString);
    $booleanArray = hexString_2_booleanArray($hexString);
    return array_slice($booleanArray, 0, $numBits);
}
Example #5
0
 public static function postLaunchHTML($newparms, $endpoint, $debug = false, $iframeattr = false, $endform = false)
 {
     global $LastOAuthBodyBaseString;
     if (isset($newparms["ext_lti_element_id"])) {
         $frame_id = $newparms["ext_lti_element_id"];
     } else {
         $frame_id = "tsugi_random_id_" . bin2Hex(openssl_random_pseudo_bytes(4));
     }
     if (isset($newparms["ext_lti_form_id"])) {
         $form_id = $newparms["ext_lti_form_id"];
     } else {
         $form_id = "tsugi_form_id_" . bin2Hex(openssl_random_pseudo_bytes(4));
     }
     $debug_id = rand(1000, 9999);
     if ($iframeattr == "_blank") {
         $r = "<form action=\"" . $endpoint . "\" name=\"" . $form_id . "\" id=\"" . $form_id . "\" method=\"post\" target=\"_blank\" encType=\"application/x-www-form-urlencoded\">\n";
     } else {
         if ($iframeattr && $iframeattr != '_pause') {
             $r = "<form action=\"" . $endpoint . "\" name=\"" . $form_id . "\" id=\"" . $form_id . "\" method=\"post\" target=\"" . $frame_id . "\" encType=\"application/x-www-form-urlencoded\">\n";
         } else {
             $r = "<form action=\"" . $endpoint . "\" name=\"" . $form_id . "\" id=\"" . $form_id . "\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
         }
     }
     ksort($newparms);
     $submit_text = $newparms['ext_submit'];
     foreach ($newparms as $key => $value) {
         $key = htmlspec_utf8($key);
         $value = htmlspec_utf8($value);
         if ($key == "ext_submit" && $iframeattr != '_pause') {
             $r .= "<input type=\"submit\" name=\"";
         } else {
             $r .= "<input type=\"hidden\" name=\"";
         }
         $r .= $key;
         $r .= "\" class=\"btn btn-primary";
         $r .= "\" value=\"";
         $r .= $value;
         $r .= "\"/>\n";
     }
     if ($debug) {
         $r .= "<script language=\"javascript\"> \n";
         $r .= "  //<![CDATA[ \n";
         $r .= "function basicltiDebug_" . $debug_id . "_Toggle() {\n";
         $r .= "    var ele = document.getElementById(\"basicltiDebug_" . $debug_id . "_\");\n";
         $r .= "    if(ele.style.display == \"block\") {\n";
         $r .= "        ele.style.display = \"none\";\n";
         $r .= "    }\n";
         $r .= "    else {\n";
         $r .= "        ele.style.display = \"block\";\n";
         $r .= "    }\n";
         $r .= "} \n";
         $r .= "  //]]> \n";
         $r .= "</script>\n";
         $r .= "<a class=\"basicltiDebugToggle\" id=\"basicltiDebug_";
         $r .= $debug_id . "_Toggle\" href=\"javascript:basicltiDebug_" . $debug_id . "_Toggle();\">";
         $r .= self::get_string("toggle_debug_data", "basiclti") . "</a>\n";
         $r .= "<div id=\"basicltiDebug_" . $debug_id . "_\" style=\"display:none\">\n";
         $r .= "<b>" . self::get_string("basiclti_endpoint", "basiclti") . "</b><br/>\n";
         $r .= $endpoint . "<br/>\n&nbsp;<br/>\n";
         $r .= "<b>" . self::get_string("basiclti_parameters", "basiclti") . "</b><br/>\n";
         foreach ($newparms as $key => $value) {
             $key = htmlspec_utf8($key);
             $value = htmlspec_utf8($value);
             $r .= "{$key} = {$value}<br/>\n";
         }
         $r .= "&nbsp;<br/>\n";
         $r .= "<p><b>" . self::get_string("basiclti_base_string", "basiclti") . "</b><br/>\n" . $LastOAuthBodyBaseString . "</p>\n";
         $r .= "</div>\n";
     }
     if ($endform) {
         $r .= $endform;
     }
     $r .= "</form>\n";
     if ($iframeattr && $iframeattr != '_blank' && $iframeattr != '_pause') {
         $r .= "<iframe class=\"lti_frameResize\" name=\"" . $frame_id . "\"  id=\"" . $frame_id . "\" src=\"\"\n";
         $r .= $iframeattr . ">\n<p>" . self::get_string("frames_required", "basiclti") . "</p>\n</iframe>\n";
     }
     // Remove session_name (i.e. PHPSESSID) if it was added.
     $r .= " <script type=\"text/javascript\"> \n" . "  //<![CDATA[ \n" . "    var inputs = document.getElementById(\"" . $form_id . "\").childNodes;\n" . "    for (var i = 0; i < inputs.length; i++)\n" . "    {\n" . "        var thisinput = inputs[i];\n" . "        if ( thisinput.name != '" . session_name() . "' ) continue;\n" . "        thisinput.parentNode.removeChild(thisinput);\n" . "    }\n" . "  //]]> \n" . " </script> \n";
     if (!$debug && $iframeattr != '_pause') {
         $ext_submit = "ext_submit";
         $ext_submit_text = $submit_text;
         $r .= " <script type=\"text/javascript\"> \n" . "  //<![CDATA[ \n" . "    document.getElementById(\"" . $form_id . "\").style.display = \"none\";\n" . "    nei = document.createElement('input');\n" . "    nei.setAttribute('type', 'hidden');\n" . "    nei.setAttribute('name', '" . $ext_submit . "');\n" . "    nei.setAttribute('value', '" . $ext_submit_text . "');\n" . "    document.getElementById(\"" . $form_id . "\").appendChild(nei);\n" . "    document." . $form_id . ".submit(); \n" . "    console.log('Autosubmitted " . $form_id . "'); \n" . "  //]]> \n" . " </script> \n";
     }
     return $r;
 }