Skip to content

Commit

Permalink
Version 3.1.0
Browse files Browse the repository at this point in the history
Added share key option.
  • Loading branch information
spvickers committed Jun 11, 2020
1 parent e2ab099 commit 9fdf4a9
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"docs": "http://www.spvsoftwareproducts.com/php/rating/"
},
"require": {
"celtic/lti": "^3.0.0"
"celtic/lti": "^3.2.1"
}
}
2 changes: 1 addition & 1 deletion src/config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
###
define('APP_NAME', 'Rating');
define('SESSION_NAME', 'php-rating');
define('VERSION', '3.0.0');
define('VERSION', '3.1.0');

###
### Database connection settings
Expand Down
20 changes: 18 additions & 2 deletions src/css/rating.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
table.items {
table.items, table.shares {
border: 1;
margin: 10px;
}
table.shares {
border-collapse: collapse;
}
table.shares tr th, table.shares td {
border: 1px solid #000;
}
tr.notvisible {
background-color: #c0c0c0;
}
Expand All @@ -25,7 +31,7 @@ span.title a {
}
span.label {
display: inline-block;
width: 8em;
width: 11em;
vertical-align: top;
}
.box {
Expand All @@ -35,6 +41,14 @@ span.label {
margin-left: 10px;
background-color: #ffffc0;
}
.sharebox {
float: right;
border: 2px dotted #000;
padding: 1em;
margin-right: 10px;
background-color: #ffffc0;
text-align: center;
}
h1 {
font-size: 120%;
color: #00f;
Expand All @@ -44,6 +58,7 @@ h2 {
color: #00f;
margin: 0;
margin-left: 10px;
padding-top: 10px;
}
img {
border: 0;
Expand All @@ -56,4 +71,5 @@ img {
}
.clear {
clear: both;
padding-top: 10px;
}
182 changes: 128 additions & 54 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use ceLTIc\LTI;
use ceLTIc\LTI\DataConnector;
use ceLTIc\LTI\ResourceLink;

/**
* This page displays a list of items for a resource link. Students are able to rate
Expand Down Expand Up @@ -166,14 +167,15 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-language" content="EN" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>{$title}</title>
<link href="css/rateit.css" media="screen" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="js/jquery.rateit.min.js" type="text/javascript"></script>
<link href="css/rating.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<meta http-equiv="content-language" content="EN" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>{$title}</title>
<link href="css/rateit.css" media="screen" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="js/jquery.rateit.min.js" type="text/javascript"></script>
<script src="js/rating.js" type="text/javascript"></script>
<link href="css/rating.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//<![CDATA[
function doContentItem(todo) {
var el = document.getElementById('id_do');
Expand Down Expand Up @@ -216,7 +218,7 @@ function doOnLoad() {
window.onload=doOnLoad;
//]]>
</script>
</script>
</head>
<body>
Expand Down Expand Up @@ -250,8 +252,8 @@ function doOnLoad() {
EOD;
} else {
$page .= <<< EOD
<table class="items" border="0" cellpadding="3">
<tbody>
<table class="items" border="0" cellpadding="3">
<tbody>
EOD;
$row = 0;
Expand All @@ -277,7 +279,7 @@ function doOnLoad() {
if (!$item->visible) {
$title .= ' [hidden]';
}
if (isset($item->item_text)) {
if (!empty($item->item_text)) {
$text = "<br />\n{$item->item_text}";
} else {
$text = '';
Expand All @@ -291,15 +293,15 @@ function doOnLoad() {
$value = floatToStr($item->tot_ratings / $item->num_ratings);
}
$page .= <<< EOD
<tr class="{$trclass}">
<td><span class="title">{$title}</span>{$text}</td>
<td><div data-id="{$item->item_pk}" title="{$value}" class="rateit" data-rateit-min="0" data-rateit-max="{$item->max_rating}" data-rateit-step="{$step}" data-rateit-value="{$value}" data-rateit-readonly="{$readonly}" data-rateit-mode="font"></div></td>
<tr class="{$trclass}">
<td><span class="title">{$title}</span>{$text}</td>
<td><div data-id="{$item->item_pk}" title="{$value}" class="rateit" data-rateit-min="0" data-rateit-max="{$item->max_rating}" data-rateit-step="{$step}" data-rateit-value="{$value}" data-rateit-readonly="{$readonly}" data-rateit-mode="font"></div></td>
EOD;
if (!$_SESSION['isStudent']) {
$page .= <<< EOD
<td class="aligncentre">
<select name="seq{$item->item_pk}" onchange="location.href='./?do=reorder&amp;id={$item->item_pk}&amp;seq='+this.value;" class="alignright">
<td class="aligncentre">
<select name="seq{$item->item_pk}" onchange="location.href='./?do=reorder&amp;id={$item->item_pk}&amp;seq='+this.value;" class="alignright">
EOD;
for ($i = 1; $i <= count($items); $i++) {
Expand All @@ -309,35 +311,35 @@ function doOnLoad() {
$sel = '';
}
$page .= <<< EOD
<option value="{$i}"{$sel}>{$i}</option>
<option value="{$i}"{$sel}>{$i}</option>
EOD;
}
$page .= <<< EOD
</select>
</td>
<td class="iconcolumn aligncentre">
<a href="./?id={$item->item_pk}"><img src="images/edit.png" title="Edit item" alt="Edit item" /></a>&nbsp;<a href="./?do=delete&amp;id={$item->item_pk}" onclick="return confirm('Delete item; are you sure?');"><img src="images/delete.png" title="Delete item" alt="Delete item" /></a>
</td>
</select>
</td>
<td class="iconcolumn aligncentre">
<a href="./?id={$item->item_pk}"><img src="images/edit.png" title="Edit item" alt="Edit item" /></a>&nbsp;<a href="./?do=delete&amp;id={$item->item_pk}" onclick="return confirm('Delete item; are you sure?');"><img src="images/delete.png" title="Delete item" alt="Delete item" /></a>
</td>
EOD;
}
$page .= <<< EOD
</tr>
</tr>
EOD;
}
}
$page .= <<< EOD
</tbody>
</table>
</tbody>
</table>
EOD;
}
}

// Display form for adding/editing an item
if ($ok && !$_SESSION['isStudent']) {
if ($ok && !$_SESSION['isStudent'] && ($_SESSION['resource_pk'] === $_SESSION['user_resource_pk'])) {
if (isset($update_item->item_pk)) {
$mode = 'Update';
} else {
Expand All @@ -352,15 +354,35 @@ function doOnLoad() {
$checked = '';
}
$page .= <<< EOD
<h2>{$mode} item</h2>
<form action="./" method="post">
<div class="box">
<span class="label">Title:<span class="required" title="required">*</span></span>&nbsp;<input name="title" type="text" size="50" maxlength="200" value="{$title}" /><br />
<span class="label">URL:</span>&nbsp;<input name="url" type="text" size="75" maxlength="200" value="{$url}" /><br />
<span class="label">Description:</span>&nbsp;<textarea name="text" rows="3" cols="60">{$text}</textarea><br />
<span class="label">Visible?</span>&nbsp;<input name="visible" type="checkbox" value="1"{$checked} /><br />
<span class="label">Maximum rating:<span class="required" title="required">*</span></span>&nbsp;<select name="max_rating">
<h2>{$mode} item</h2>
<form action="./" method="get">
<div class="sharebox">
<strong>New share key</strong><br /><br />
Life:&nbsp;<select id="life">
<option value="1">1 hour</option>
<option value="2">2 hours</option>
<option value="12">12 hours</option>
<option value="24">1 day</option>
<option value="48">2 days</option>
<option value="72" selected="selected">3 days</option>
<option value="96">4 days</option>
<option value="120">5 days</option>
<option value="168">1 week</option>
</select><br />
Auto approve?&nbsp;<input type="checkbox" id="auto_approve" value="yes" /><br /><br />
<input type="button" value="Generate" onclick="return doGenerateKey();" />
</div>
</form>
<form action="./" method="post">
<div class="box">
<span class="label">Title:<span class="required" title="required">*</span></span>&nbsp;<input name="title" type="text" size="50" maxlength="200" value="{$title}" /><br />
<span class="label">URL:</span>&nbsp;<input name="url" type="text" size="75" maxlength="200" value="{$url}" /><br />
<span class="label">Description:</span>&nbsp;<textarea name="text" rows="3" cols="60">{$text}</textarea><br />
<span class="label">Visible?</span>&nbsp;<input name="visible" type="checkbox" value="1"{$checked} /><br />
<span class="label">Maximum rating:<span class="required" title="required">*</span></span>&nbsp;<select name="max_rating">
EOD;
for ($i = 3; $i <= 10; $i++) {
Expand All @@ -370,7 +392,7 @@ function doOnLoad() {
$sel = '';
}
$page .= <<< EOD
<option value="{$i}"{$sel}>{$i}</option>
<option value="{$i}"{$sel}>{$i}</option>
EOD;
}
Expand All @@ -387,27 +409,27 @@ function doOnLoad() {
$sel4 = ' selected="selected"';
}
$page .= <<< EOD
</select><br />
<span class="label">Rating step:<span class="required" title="required">*</span></span>&nbsp;<select name="step">
<option value="4"{$sel4}>0.25</option>
<option value="2"{$sel2}>0.5</option>
<option value="1"{$sel1}>1</option>
</select><br />
<br />
<input type="hidden" name="do" id="id_do" value="add" />
<input type="hidden" name="id" value="{$id}" />
<span class="label"><span class="required" title="required">*</span>&nbsp;=&nbsp;required field</span>&nbsp;<input type="submit" value="{$mode} item" />
</select><br />
<span class="label">Rating step:<span class="required" title="required">*</span></span>&nbsp;<select name="step">
<option value="4"{$sel4}>0.25</option>
<option value="2"{$sel2}>0.5</option>
<option value="1"{$sel1}>1</option>
</select><br />
<br />
<input type="hidden" name="do" id="id_do" value="add" />
<input type="hidden" name="id" value="{$id}" />
<span class="label"><span class="required" title="required">*</span>&nbsp;=&nbsp;required field</span>&nbsp;<input type="submit" value="{$mode} item" />
EOD;

if (isset($update_item->item_pk)) {
$page .= <<< EOD
&nbsp;<input type="reset" value="Cancel" onclick="location.href='./';" />
&nbsp;<input type="reset" value="Cancel" onclick="location.href='./';" />
EOD;
}
$page .= <<< EOD
</div>
</div>
EOD;
if ($_SESSION['isContentItem'] && !isset($update_item->item_pk)) {
Expand All @@ -416,18 +438,70 @@ function doOnLoad() {
$disabled = ' disabled="disabled"';
}
$page .= <<< EOD
<p class="clear">
<br />
<input type="submit" value="Cancel content" onclick="return doContentItem('cancelci');" />
<input type="submit" value="Create content item" onclick="return doContentItem('saveci');"{$disabled} />
</p>
<p class="clear">
<br />
<input type="submit" value="Cancel content" onclick="return doContentItem('cancelci');" />
<input type="submit" value="Create content item" onclick="return doContentItem('saveci');"{$disabled} />
</p>
EOD;
}
$page .= <<< EOD
</form>
</form>
EOD;

$data_connector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX);
$resource_link = ResourceLink::fromRecordId($_SESSION['resource_pk'], $data_connector);
$shares = $resource_link->getShares();
if (count($shares) > 0) {
$page .= <<< EOD
<h2 class="clear">Shares</h2>
<table class="shares" border="0" cellpadding="3">
<thead>
<tr>
<th>Source</th>
<th>Title</th>
<th>Approved</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
EOD;
$i = 0;
foreach ($shares as $share) {
$i++;
if ($share->approved) {
$shareApproved = 'tick';
$shareApproved_alt = 'Approved';
$action = 'Suspend';
} else {
$shareApproved = 'cross';
$shareApproved_alt = 'Not approved';
$action = 'Approve';
}
$page .= <<< EOD
<tr>
<td>{$share->consumerName}</td>
<td>{$share->title}</td>
<td class="aligncentre"><img id="img{$i}" src="images/{$shareApproved}.gif" alt="{$shareApproved_alt}" title="{$shareApproved_alt}" /></td>
<td class="aligncentre">
<input type="button" id="btn{$i}" value="{$action}" onclick="return doApprove({$i}, '{$action}', {$share->resourceLinkId});" />
<a href="share.php?do=cancel&rlid={$share->resourceLinkId}"><input type="button" value="Cancel" onclick="return confirm('Cancel share; are you sure?');" /></a>
</td>
</tr>
EOD;
}
$page .= <<< EOD
</tbody>
</table>
EOD;
}
}

// Page footer
Expand Down
Loading

0 comments on commit 9fdf4a9

Please sign in to comment.