コード例 #1
0
ファイル: aestest.php プロジェクト: shaamimahmed/tsugi
 public function testGet()
 {
     $pw = 'L0ck it up saf3';
     $pt = 'pssst ... đon’t tell anyøne!';
     $encr = AesCtr::encrypt($pt, $pw, 256);
     $this->assertNotEquals($encr, $pw);
     $this->assertNotEquals($encr, $pt);
     $decr = AesCtr::decrypt($encr, $pw, 256);
     $this->assertEquals($decr, $pt);
 }
コード例 #2
0
ファイル: SecureCookie.php プロジェクト: csev/tsugi-php
 /**
  * Utility code to deal with Secure Cookies.
  */
 public static function create($id, $guid, $debug = false)
 {
     global $CFG;
     $pt = $CFG->cookiepad . '::' . $id . '::' . $guid;
     if ($debug) {
         echo "PT1: {$pt}\n";
     }
     $ct = \Tsugi\Crypt\AesCtr::encrypt($pt, $CFG->cookiesecret, 256);
     return $ct;
 }
コード例 #3
0
ファイル: Lessons.php プロジェクト: csev/tsugi-php
    public function renderBadges($allgrades)
    {
        global $CFG;
        echo '<h1>' . $this->lessons->title . "</h1>\n";
        $awarded = array();
        ?>
<ul class="nav nav-tabs">
  <li class="active"><a href="#home" data-toggle="tab" aria-expanded="true">Progress</a></li>
  <li class=""><a href="#profile" data-toggle="tab" aria-expanded="false">Badges Awarded</a></li>
</ul>
<div id="myTabContent" class="tab-content">
  <div class="tab-pane fade active in" id="home">
<?php 
        echo '<table class="table table-striped table-hover "><tbody>' . "\n";
        foreach ($this->lessons->badges as $badge) {
            $threshold = $badge->threshold;
            $count = 0;
            $total = 0;
            $scores = array();
            foreach ($badge->assignments as $resource_link_id) {
                $score = 0;
                if (isset($allgrades[$resource_link_id])) {
                    $score = 100 * $allgrades[$resource_link_id];
                }
                $scores[$resource_link_id] = $score;
                $total = $total + $score;
                $count = $count + 1;
            }
            $max = $count * 100;
            $progress = $max <= 0 ? 100 : intval($total / $max * 100);
            $kind = 'danger';
            if ($progress < 5) {
                $progress = 5;
            }
            if ($progress > 5) {
                $kind = 'warning';
            }
            if ($progress > 50) {
                $kind = 'info';
            }
            if ($progress >= $threshold * 100) {
                $kind = 'success';
                $awarded[] = $badge;
            }
            echo '<tr><td class="info">';
            echo '<i class="fa fa-certificate" aria-hidden="true" style="padding-right: 5px;"></i>';
            echo $badge->title;
            echo '</td><td class="info" style="width: 30%; min-width: 200px;">';
            echo '<div class="progress">';
            echo '<div class="progress-bar progress-bar-' . $kind . '" style="width: ' . $progress . '%"></div>';
            echo '</div>';
            echo "</td></tr>\n";
            foreach ($badge->assignments as $resource_link_id) {
                $score = 0;
                if (isset($allgrades[$resource_link_id])) {
                    $score = 100 * $allgrades[$resource_link_id];
                }
                $progress = intval($score * 100);
                $kind = 'danger';
                if ($progress < 5) {
                    $progress = 5;
                }
                if ($progress > 5) {
                    $kind = 'warning';
                }
                if ($progress > 50) {
                    $kind = 'info';
                }
                if ($progress >= 100) {
                    $kind = 'success';
                }
                $module = $this->getModuleByRlid($resource_link_id);
                $lti = $this->getLtiByRlid($resource_link_id);
                echo '<tr><td>';
                echo '<a href="lessons.php?anchor=' . $module->anchor . '">';
                echo '<i class="fa fa-square-o text-info" aria-hidden="true" style="label label-success; padding-right: 5px;"></i>';
                echo $lti->title . "</a>\n";
                echo '</td><td style="width: 30%; min-width: 200px;">';
                echo '<a href="lessons.php?anchor=' . $module->anchor . '">';
                echo '<div class="progress">';
                echo '<div class="progress-bar progress-bar-' . $kind . '" style="width: ' . $progress . '%"></div>';
                echo '</div>';
                echo '</a>';
                echo "</td></tr>\n";
            }
        }
        echo '</tbody></table>' . "\n";
        ?>
  </div>
  <div class="tab-pane fade" id="profile">
<?php 
        if (count($awarded) < 1) {
            echo "<p>No badges have been awarded yet.</p>";
        } else {
            echo "</ul>\n";
            foreach ($awarded as $badge) {
                echo "<li>";
                $code = basename($badge->image, '.png');
                $decrypted = $_SESSION['id'] . ':' . $code . ':' . $_SESSION['context_id'];
                $encrypted = bin2hex(AesCtr::encrypt($decrypted, $CFG->badge_encrypt_password, 256));
                echo '<a href="badges/images/' . $encrypted . '.png" target="_blank">';
                echo '<img src="badges/images/' . $encrypted . '.png" width="90"></a>';
                echo $badge->title;
                echo "</li>\n";
            }
            echo "</ul>\n";
            ?>
<p>These badges contain the official Open Badge metadata.  You can download the badge and 
put it on your own server, or add the badge to a "badge packpack".  You could validate the badge 
using <a href="http://www.dr-chuck.com/obi-sample/" target="_blank">A simple badge validator</a>.
</p>
<?php 
        }
        ?>
</div>
<?php 
    }