function copysubone(&$items, $parent, $copyinside, &$addtoarr) { global $blockcnt, $tocopy, $gbcats, $outcomes; foreach ($items as $k => $item) { if (is_array($item)) { if ($parent . '-' . ($k + 1) == $tocopy || $copyinside) { //copy block $newblock = array(); $newblock['name'] = $item['name'] . stripslashes($_POST['append']); $newblock['id'] = $blockcnt; $blockcnt++; $newblock['startdate'] = $item['startdate']; $newblock['enddate'] = $item['enddate']; $newblock['avail'] = $item['avail']; $newblock['SH'] = $item['SH']; $newblock['colors'] = $item['colors']; $newblock['fixedheight'] = $item['fixedheight']; $newblock['grouplimit'] = $item['grouplimit']; $newblock['items'] = array(); if (count($item['items']) > 0) { copysubone($items[$k]['items'], $parent . '-' . ($k + 1), true, $newblock['items']); } if (!$copyinside) { array_splice($items, $k + 1, 0, array($newblock)); return 0; } else { $addtoarr[] = $newblock; } } else { if (count($item['items']) > 0) { $nothin = array(); copysubone($items[$k]['items'], $parent . '-' . ($k + 1), false, $nothin); } } } else { if ($item == $tocopy || $copyinside) { $newitem = copyitem($item, $gbcats); if (!$copyinside) { array_splice($items, $k + 1, 0, $newitem); return 0; } else { $addtoarr[] = $newitem; } } } } }
//aid is in source course. Let's look and see if there's an assessment in destination with the same title. //THIS SHOULD BE REMOVED - only included to accomodate people doing things the wrong way. $query = "SELECT name FROM imas_assessments WHERE id=" . intval($_SESSION['place_aid'][1]); $result = mysql_query($query) or die("Query failed : " . mysql_error()); $sourceassessname = addslashes(mysql_result($result, 0, 0)); $query = "SELECT id FROM imas_assessments WHERE name='{$sourceassessname}' AND courseid='{$destcid}'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); if (mysql_num_rows($result) > 0) { $aid = mysql_result($result, 0, 0); } else { // no assessment with same title - need to copy assessment from destination to source course require "includes/copyiteminc.php"; $query = "SELECT id FROM imas_items WHERE itemtype='Assessment' AND typeid='{$_SESSION['place_aid'][1]}'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $cid = $destcid; $newitem = copyitem(mysql_result($result, 0, 0), array()); $query = "SELECT typeid FROM imas_items WHERE id={$newitem}"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $aid = mysql_result($result, 0, 0); $query = "SELECT itemorder FROM imas_courses WHERE id='{$cid}'"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); $items = unserialize(mysql_result($result, 0, 0)); $items[] = $newitem; $items = addslashes(serialize($items)); $query = "UPDATE imas_courses SET itemorder='{$items}' WHERE id='{$cid}'"; mysql_query($query) or die("Query failed : " . mysql_error()); } } } $query = "INSERT INTO imas_lti_placements (org,contextid,linkid,placementtype,typeid) VALUES "; $query .= "('{$_SESSION['ltiorg']}','{$_SESSION['lti_context_id']}','{$_SESSION['lti_resource_link_id']}','assess','{$aid}')";
function copyallsub($items, $parent, &$addtoarr, $gbcats, $sethidden = false) { global $blockcnt, $reqscoretrack, $assessnewid; if (strlen($_POST['append']) > 0 && $_POST['append'][0] != ' ') { $_POST['append'] = ' ' . $_POST['append']; } foreach ($items as $k => $item) { if (is_array($item)) { $newblock = array(); $newblock['name'] = $item['name'] . stripslashes($_POST['append']); $newblock['id'] = $blockcnt; $blockcnt++; $newblock['startdate'] = $item['startdate']; $newblock['enddate'] = $item['enddate']; $newblock['avail'] = $sethidden ? 0 : $item['avail']; $newblock['SH'] = $item['SH']; $newblock['colors'] = $item['colors']; $newblock['public'] = $item['public']; $newblock['fixedheight'] = $item['fixedheight']; $newblock['grouplimit'] = $item['grouplimit']; $newblock['items'] = array(); if (count($item['items']) > 0) { copyallsub($item['items'], $parent . '-' . ($k + 1), $newblock['items'], $gbcats, $sethidden); } $addtoarr[] = $newblock; } else { if ($item != null && $item != 0) { $addtoarr[] = copyitem($item, $gbcats, $sethidden); } } } }