$sub =& $items; if (count($blocktree) > 1) { for ($i = 1; $i < count($blocktree); $i++) { $sub =& $sub[$blocktree[$i] - 1]['items']; //-1 to adjust for 1-indexing } } if (is_array($sub[$blockid])) { //make sure it's really a block $blockitems = $sub[$blockid]['items']; $obid = $sub[$blockid]['id']; if (count($blockitems) > 0) { if (isset($_POST['delcontents']) && $_POST['delcontents'] == 1) { //clear out contents of block require "delitembyid.php"; delrecurse($blockitems); array_splice($sub, $blockid, 1); //remove block and contained items from itemorder } else { array_splice($sub, $blockid, 1, $blockitems); //remove block, replace with items in block } } else { array_splice($sub, $blockid, 1); //empty block; just remove block } } $itemlist = addslashes(serialize($items)); $query = "UPDATE imas_courses SET itemorder='{$itemlist}' WHERE id='{$_GET['cid']}'"; mysql_query($query) or die("Query failed : " . mysql_error()); mysql_query("COMMIT") or die("Query failed :{$query} " . mysql_error());
function delrecurse($itemarr) { //delete items, recursing through blocks as needed foreach ($itemarr as $itemid) { if (is_array($itemid)) { delrecurse($itemid['items']); } else { delitembyid($itemid); } } }