Skip to content

Commit

Permalink
Add ancestor tracking to course and assessment copies
Browse files Browse the repository at this point in the history
Move template course / self-enroll course designation to course settings and database instead of config.php
  • Loading branch information
David Lippman committed Apr 29, 2013
1 parent 8aa6db6 commit 8eed44d
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 27 deletions.
30 changes: 24 additions & 6 deletions admin/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,28 @@

$avail = 3 - $_POST['stuavail'] - $_POST['teachavail'];

$istemplate = 0;
if ($myrights==100) {
if (isset($_POST['istemplate'])) {
$istemplate += 1;
}
if (isset($_POST['isselfenroll'])) {
$istemplate += 4;
}
}

$_POST['ltisecret'] = trim($_POST['ltisecret']);

if ($_GET['action']=='modify') {
$query = "UPDATE imas_courses SET name='{$_POST['coursename']}',enrollkey='{$_POST['ekey']}',hideicons='$hideicons',available='$avail',lockaid='{$_POST['lockaid']}',picicons='$picicons',chatset=$chatset,showlatepass=$showlatepass,";
$query .= "allowunenroll='$unenroll',copyrights='$copyrights',msgset='$msgset',toolset='$toolset',topbar='$topbar',cploc='$cploc',theme='$theme',ltisecret='{$_POST['ltisecret']}' WHERE id='{$_GET['id']}'";
$query .= "allowunenroll='$unenroll',copyrights='$copyrights',msgset='$msgset',toolset='$toolset',topbar='$topbar',cploc='$cploc',theme='$theme',ltisecret='{$_POST['ltisecret']}',istemplate=$istemplate WHERE id='{$_GET['id']}'";
if ($myrights<75) { $query .= " AND ownerid='$userid'";}
mysql_query($query) or die("Query failed : " . mysql_error());
} else {
$blockcnt = 1;
$itemorder = addslashes(serialize(array()));
$query = "INSERT INTO imas_courses (name,ownerid,enrollkey,hideicons,picicons,allowunenroll,copyrights,msgset,toolset,chatset,showlatepass,itemorder,topbar,cploc,available,theme,ltisecret,blockcnt) VALUES ";
$query .= "('{$_POST['coursename']}','$userid','{$_POST['ekey']}','$hideicons','$picicons','$unenroll','$copyrights','$msgset',$toolset,$chatset,$showlatepass,'$itemorder','$topbar','$cploc','$avail','$theme','{$_POST['ltisecret']}','$blockcnt');";
$query = "INSERT INTO imas_courses (name,ownerid,enrollkey,hideicons,picicons,allowunenroll,copyrights,msgset,toolset,chatset,showlatepass,itemorder,topbar,cploc,available,istemplate,theme,ltisecret,blockcnt) VALUES ";
$query .= "('{$_POST['coursename']}','$userid','{$_POST['ekey']}','$hideicons','$picicons','$unenroll','$copyrights','$msgset',$toolset,$chatset,$showlatepass,'$itemorder','$topbar','$cploc','$avail',$istemplate,'$theme','{$_POST['ltisecret']}','$blockcnt');";
mysql_query($query) or die("Query failed : " . mysql_error());
$cid = mysql_insert_id();
//if ($myrights==40) {
Expand Down Expand Up @@ -257,15 +267,23 @@
$gbcats[$frid] = mysql_insert_id();
}
$copystickyposts = true;
$query = "SELECT itemorder FROM imas_courses WHERE id='{$_POST['usetemplate']}'";
$query = "SELECT itemorder,ancestors FROM imas_courses WHERE id='{$_POST['usetemplate']}'";
$result = mysql_query($query) or die("Query failed : $query" . mysql_error());
$items = unserialize(mysql_result($result,0,0));
$r = mysql_fetch_row($result);
$items = unserialize($r[0]);
$ancestors = $r[1];
if ($ancestors=='') {
$ancestors = intval($_POST['usetemplate']);
} else {
$ancestors = intval($_POST['usetemplate']).','.$ancestors;
}
$ancestors = addslashes($ancestors);
$newitems = array();
require("../includes/copyiteminc.php");
copyallsub($items,'0',$newitems,$gbcats);
doaftercopy($_POST['usetemplate']);
$itemorder = addslashes(serialize($newitems));
$query = "UPDATE imas_courses SET itemorder='$itemorder',blockcnt='$blockcnt' WHERE id='$cid'";
$query = "UPDATE imas_courses SET itemorder='$itemorder',blockcnt='$blockcnt',ancestors='$ancestors' WHERE id='$cid'";
mysql_query($query) or die("Query failed : " . mysql_error());
copyrubrics();
}
Expand Down
16 changes: 14 additions & 2 deletions admin/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
$ltisecret = $line['ltisecret'];
$chatset = $line['chatset'];
$showlatepass = $line['showlatepass'];
$istemplate = $line['istemplate'];
} else {
$courseid = "Not yet set";
$name = "Enter course name here";
Expand All @@ -151,7 +152,7 @@
$theme = isset($CFG['CPS']['theme'])?$CFG['CPS']['theme'][0]:$defaultcoursetheme;
$chatset = isset($CFG['CPS']['chatset'])?$CFG['CPS']['chatset'][0]:0;
$showlatepass = isset($CFG['CPS']['showlatepass'])?$CFG['CPS']['showlatepass'][0]:0;

$istemplate = 0;
$avail = 0;
$lockaid = 0;
$ltisecret = "";
Expand Down Expand Up @@ -418,12 +419,23 @@
}
echo '</span></span><br class="form" />';
}
if ($myrights==100) {
echo '<span class="form">Mark course as template?</span>';
echo '<span class="formright"><input type=checkbox name="istemplate" value="1" ';
if (($istemplate&1)==1) {echo 'checked="checked"';};
echo ' /> Mark as global template course<br/>';
echo '<input type=checkbox name="isselfenroll" value="4" ';
if (($istemplate&4)==4) {echo 'checked="checked"';};
echo ' /> Mark as self-enroll course';
echo '</span><br class="form" />';
}

if (isset($CFG['CPS']['templateoncreate']) && $_GET['action']=='addcourse' ) {
echo '<span class="form">Use content from a template course:</span>';
echo '<span class="formright"><select name="usetemplate" onchange="templatepreviewupdate(this)">';
echo '<option value="0" selected="selected">Start with blank course</option>';
$query = "SELECT ic.id,ic.name,ic.copyrights FROM imas_courses AS ic,imas_teachers WHERE imas_teachers.courseid=ic.id AND imas_teachers.userid='$templateuser' ORDER BY ic.name";
//$query = "SELECT ic.id,ic.name,ic.copyrights FROM imas_courses AS ic,imas_teachers WHERE imas_teachers.courseid=ic.id AND imas_teachers.userid='$templateuser' ORDER BY ic.name";
$query = "SELECT id,name,copyrights FROM imas_courses WHERE (istemplate&1)=1 AND available<4 ORDER BY name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
Expand Down
12 changes: 9 additions & 3 deletions course/copyitems.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@
exit;
} else if (isset($_GET['action']) && $_GET['action']=="copy") {
if (isset($_POST['copycourseopt'])) {
$tocopy = 'hideicons,allowunenroll,copyrights,msgset,topbar,cploc,picicons,chatset,showlatepass,available,theme';
$tocopy = 'ancestors,hideicons,allowunenroll,copyrights,msgset,topbar,cploc,picicons,chatset,showlatepass,available,theme';

$query = "SELECT $tocopy FROM imas_courses WHERE id='{$_POST['ctc']}'";
$result = mysql_query($query) or die("Query failed :$query " . mysql_error());
$row = mysql_fetch_row($result);
$tocopyarr = explode(',',$tocopy);
if ($row[0]=='') {
$row[0] = intval($_POST['ctc']);
} else {
$row[0] = intval($_POST['ctc']).','.$row[0];
}
$sets = '';
for ($i=0; $i<count($tocopyarr); $i++) {
if ($i>0) {$sets .= ',';}
Expand Down Expand Up @@ -269,7 +274,8 @@
$lastteacher = 0;


$query = "SELECT ic.id,ic.name,ic.copyrights FROM imas_courses AS ic,imas_teachers WHERE imas_teachers.courseid=ic.id AND imas_teachers.userid='$templateuser' AND ic.available<4 ORDER BY ic.name";
//$query = "SELECT ic.id,ic.name,ic.copyrights FROM imas_courses AS ic,imas_teachers WHERE imas_teachers.courseid=ic.id AND imas_teachers.userid='$templateuser' AND ic.available<4 ORDER BY ic.name";
$query = "SELECT id,name,copyrights FROM imas_courses WHERE (istemplate&1)=1 AND available<4 ORDER BY name";
$courseTemplateResults = mysql_query($query) or die("Query failed : " . mysql_error());
}
}
Expand Down Expand Up @@ -590,7 +596,7 @@ function loadothers() {
echo "<li>Loading...</li> </ul>\n </li>\n";

//template courses
if (isset($templateuser)) {
if (mysql_num_rows($courseTemplateResults)>0) {
?>
<li class=lihdr>
<span class=dd>-</span>
Expand Down
10 changes: 8 additions & 2 deletions course/copyoneitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
$tocopy = $_GET['copyid'];
$_POST['append'] = " (Copy)";
$_POST['ctc'] = $cid;
$gbcats = array();
$query = "SELECT id FROM imas_gbcats WHERE courseid='$cid'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
$gbcats[$row[0]] = $row[0];
}

function copysubone(&$items,$parent,$copyinside,&$addtoarr) {
global $blockcnt,$tocopy;
global $blockcnt,$tocopy, $gbcats;
foreach ($items as $k=>$item) {
if (is_array($item)) {
if (($parent.'-'.($k+1)==$tocopy) || $copyinside) { //copy block
Expand Down Expand Up @@ -51,7 +57,7 @@ function copysubone(&$items,$parent,$copyinside,&$addtoarr) {
}
} else {
if ($item==$tocopy || $copyinside) {
$newitem = copyitem($item,false);
$newitem = copyitem($item,$gbcats);
if (!$copyinside) {
array_splice($items,$k+1,0,$newitem);
return 0;
Expand Down
12 changes: 11 additions & 1 deletion course/gbtable2.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function getpts($sc) {
row[0][1][0][8] = tutoredit: 0 no, 1 yes
row[0][1][0][9] = 5 number summary, if not limuser-ed
row[0][1][0][10] = 0 regular, 1 group
row[0][1][0][11] = due date (if $includeduedate is set)
row[0][2] category totals
row[0][2][0][0] = "Category Name"
Expand All @@ -71,6 +72,7 @@ function getpts($sc) {
row[0][2][0][5] = total possible for all
row[0][2][0][6-9] = 5 number summary
row[0][2][0][10] = gbcat id
row[0][2][0][11] = category weight (if weighted grades)
row[0][3][0] = total possible past
row[0][3][1] = total possible past&current
Expand Down Expand Up @@ -535,6 +537,9 @@ function flattenitems($items,&$addto) {
$gb[0][1][$pos][7] = $discuss[$k];
$discusscol[$discuss[$k]] = $pos;
}
if (isset($GLOBALS['includeduedate'])) {
$gb[0][1][$pos][11] = $enddate[$k];
}


$pos++;
Expand Down Expand Up @@ -581,7 +586,9 @@ function flattenitems($items,&$addto) {
$gb[0][1][$pos][7] = $discuss[$k];
$discusscol[$discuss[$k]] = $pos;
}

if (isset($GLOBALS['includeduedate'])) {
$gb[0][1][$pos][11] = $enddate[$k];
}
$pos++;
}
}
Expand Down Expand Up @@ -664,6 +671,9 @@ function flattenitems($items,&$addto) {
$gb[0][2][$pos][4] = $catposscur[$cat];
$gb[0][2][$pos][5] = $catpossfuture[$cat];
}
if ($useweights==1) {
$gb[0][2][$pos][11] = $cats[$cat][5];
}


$overallptspast += $gb[0][2][$pos][3];
Expand Down
16 changes: 16 additions & 0 deletions dbsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
. ' `latepasshrs` SMALLINT(4) UNSIGNED NOT NULL DEFAULT \'24\', '
. ' `picicons` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\','
. ' `newflag` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\','
. ' `istemplate` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\','
. ' `ancestors` TEXT NOT NULL, '
. ' `ltisecret` VARCHAR(10) NOT NULL, '
. ' INDEX(`ownerid`), INDEX(`name`), INDEX(`available`)'
. ' )'
Expand Down Expand Up @@ -225,6 +227,7 @@
. ' `caltag` VARCHAR(254) NOT NULL DEFAULT \'?\', '
. ' `calrtag` VARCHAR(254) NOT NULL DEFAULT \'R\', '
. ' `tutoredit` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\', '
. ' `ancestors` TEXT NOT NULL, '
. ' INDEX (`courseid`), INDEX(`startdate`), INDEX(`enddate`),'
. ' INDEX(`cntingb`), INDEX(`reviewdate`), INDEX(`avail`)'
. ' )'
Expand Down Expand Up @@ -944,6 +947,19 @@
mysql_query($sql) or die("Query failed : $sql " . mysql_error());
echo 'imas_bookmarks created<br/>';

$sql = 'CREATE TABLE `imas_content_track` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userid` INT(10) UNSIGNED NOT NULL,
`courseid` INT(10) UNSIGNED NOT NULL,
`type` VARCHAR(254) UNSIGNED NOT NULL,
`typeid` INT(10) UNSIGNED NOT NULL,
`viewtime` INT(10) UNSIGNED NOT NULL,
INDEX ( `courseid`) , INDEX( `userid`)
) ENGINE = InnoDB';
mysql_query($sql) or die("Query failed : $sql " . mysql_error());
echo 'imas_content_track created<br/>';


$sql = 'CREATE TABLE `imas_dbschema` (
`id` INT( 10 ) UNSIGNED NOT NULL PRIMARY KEY ,
`ver` SMALLINT( 4 ) UNSIGNED NOT NULL
Expand Down
22 changes: 12 additions & 10 deletions forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
echo "<span class=form><label for=\"agree\">I have read and agree to the Terms of Use (below)</label></span><span class=formright><input type=checkbox name=agree></span><br class=form />\n";
}
if (!$emailconfirmation) {
if (isset($CFG['GEN']['selfenrolluser'])) {
$query = "SELECT id,name FROM imas_courses WHERE (istemplate&4)=4 AND available<4 ORDER BY name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$doselfenroll = false;
if (mysql_num_rows($result)>0) {//if (isset($CFG['GEN']['selfenrolluser'])) {
$doselfenroll = true;
echo '<p>Select the course you\'d like to enroll in</p>';
echo '<p><select id="courseselect" name="courseselect" onchange="courseselectupdate(this);">';
echo '<option value="0" selected="selected">My teacher gave me a course ID (enter below)</option>';
$query = "SELECT imas_courses.id,imas_courses.name FROM imas_courses JOIN imas_teachers ON ";
$query .= "imas_courses.id=imas_teachers.courseid WHERE imas_teachers.userid='{$CFG['GEN']['selfenrolluser']}' ORDER by imas_courses.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
Expand All @@ -58,7 +59,7 @@
}
echo '<span class="form"><label for="courseid">Course ID:</label></span><input class="form" type="text" size="20" name="courseid"/><br class="form"/>';
echo '<span class="form"><label for="ekey">Enrollment Key:</label></span><input class="form" type="text" size="20" name="ekey"/><br class="form"/>';
if (isset($CFG['GEN']['selfenrolluser'])) {
if ($doselfenroll) {
echo '</div>';
}
}
Expand Down Expand Up @@ -205,13 +206,14 @@
case "enroll":
echo '<div id="headerforms" class="pagetitle"><h2>Enroll in a Course</h2></div>';
echo "<form method=post action=\"actions.php?action=enroll$gb\">";
if (isset($CFG['GEN']['selfenrolluser'])) {
$query = "SELECT id,name FROM imas_courses WHERE (istemplate&4)=4 AND available<4 ORDER BY name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$doselfenroll = false;
if (mysql_num_rows($result)>0) {//if (isset($CFG['GEN']['selfenrolluser'])) {
$doselfenroll = true;
echo '<p>Select the course you\'d like to enroll in</p>';
echo '<p><select id="courseselect" name="courseselect" onchange="courseselectupdate(this);">';
echo '<option value="0" selected="selected">My teacher gave me a course ID (enter below)</option>';
$query = "SELECT imas_courses.id,imas_courses.name FROM imas_courses JOIN imas_teachers ON ";
$query .= "imas_courses.id=imas_teachers.courseid WHERE imas_teachers.userid='{$CFG['GEN']['selfenrolluser']}' ORDER by imas_courses.name";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
Expand All @@ -224,7 +226,7 @@
}
echo '<span class="form"><label for="cid">Course ID:</label></span><input class="form" type="text" size="20" name="cid"/><br class="form"/>';
echo '<span class="form"><label for="ekey">Enrollment Key:</label></span><input class="form" type="text" size="20" name="ekey"/><br class="form"/>';
if (isset($CFG['GEN']['selfenrolluser'])) {
if ($doselfenroll) {
echo '</div>';
}
echo '<div class=submit><input type=submit value="Sign Up"></div></form>';
Expand Down
26 changes: 24 additions & 2 deletions includes/copyiteminc.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,44 @@ function copyitem($itemid,$gbcats,$sethidden=false) {
//$query = "INSERT INTO imas_assessments (courseid,name,summary,intro,startdate,enddate,timelimit,displaymethod,defpoints,defattempts,deffeedback,defpenalty,shuffle) ";
//$query .= "SELECT '$cid',name,summary,intro,startdate,enddate,timelimit,displaymethod,defpoints,defattempts,deffeedback,defpenalty,shuffle FROM imas_assessments WHERE id='$typeid'";
//mysql_query($query) or die("Query failed : $query" . mysql_error());
$query = "SELECT name,summary,intro,startdate,enddate,reviewdate,timelimit,minscore,displaymethod,defpoints,defattempts,deffeedback,defpenalty,shuffle,gbcategory,password,cntingb,showcat,showhints,showtips,allowlate,exceptionpenalty,noprint,avail,groupmax,endmsg,deffeedbacktext,eqnhelper,caltag,calrtag,msgtoinstr,istutorial,viddata,reqscore,reqscoreaid FROM imas_assessments WHERE id='$typeid'";
$query = "SELECT name,summary,intro,startdate,enddate,reviewdate,timelimit,minscore,displaymethod,defpoints,defattempts,deffeedback,defpenalty,shuffle,gbcategory,password,cntingb,showcat,showhints,showtips,allowlate,exceptionpenalty,noprint,avail,groupmax,endmsg,deffeedbacktext,eqnhelper,caltag,calrtag,msgtoinstr,istutorial,viddata,reqscore,reqscoreaid,ancestors FROM imas_assessments WHERE id='$typeid'";

$result = mysql_query($query) or die("Query failed :$query " . mysql_error());
$row = mysql_fetch_row($result);
$row = mysql_fetch_assoc($result);
if ($sethidden) {$row['avail'] = 0;}
if (isset($gbcats[$row['gbcategory']])) {
$row['gbcategory'] = $gbcats[$row['gbcategory']];
} else {
$row['gbcategory'] = 0;
}
if ($row['ancestors']=='') {
$row['ancestors'] = $typeid;
} else {
$row['ancestors'] = $typeid.','.$row['ancestors'];
}
$reqscoreaid = $row['reqscoreaid'];
unset($row['reqscoreaid']);
$row['name'] .= stripslashes($_POST['append']);

$fields = implode(",",array_keys($row));
$vals = "'".implode("','",addslashes_deep(array_values($row)))."'";

$query = "INSERT INTO imas_assessments (courseid,$fields) VALUES ('$cid',$vals)";
/*$row = mysql_fetch_row($result);
if ($sethidden) {$row[23] = 0;}
if (isset($gbcats[$row[14]])) {
$row[14] = $gbcats[$row[14]];
} else if ($_POST['ctc']!=$cid) {
$row[14] = 0;
}
$reqscoreaid = array_pop($row);
$row[0] .= stripslashes($_POST['append']);
$row = "'".implode("','",addslashes_deep($row))."'";
$query = "INSERT INTO imas_assessments (courseid,name,summary,intro,startdate,enddate,reviewdate,timelimit,minscore,displaymethod,defpoints,defattempts,deffeedback,defpenalty,shuffle,gbcategory,password,cntingb,showcat,showhints,showtips,allowlate,exceptionpenalty,noprint,avail,groupmax,endmsg,deffeedbacktext,eqnhelper,caltag,calrtag,msgtoinstr,istutorial,viddata,reqscore) ";
$query .= "VALUES ('$cid',$row)";
*/
mysql_query($query) or die("Query failed : $query" . mysql_error());
$newtypeid = mysql_insert_id();
if ($reqscoreaid>0) {
Expand Down
Loading

0 comments on commit 8eed44d

Please sign in to comment.