示例#1
0
 function additems($list)
 {
     global $curoutcomes, $seenoutcomes, $cid;
     $outarr = array();
     $list = substr($list, 1, -1);
     $i = 0;
     $nd = 0;
     $last = 0;
     $listarr = array();
     while ($i < strlen($list)) {
         if ($list[$i] == '[') {
             $nd++;
         } else {
             if ($list[$i] == ']') {
                 $nd--;
             } else {
                 if ($list[$i] == ',' && $nd == 0) {
                     $listarr[] = substr($list, $last, $i - $last);
                     $last = $i + 1;
                 }
             }
         }
         $i++;
     }
     $listarr[] = substr($list, $last);
     //new group:  newgrp###, name in newg###
     //ext group:  grp### name in g###
     //new outcome: new###, name in newo###
     //ext outcome: ###, name in o###
     foreach ($listarr as $it) {
         if (strpos($it, 'grp') !== false) {
             //is outcome group
             $pos = strpos($it, ':');
             if ($pos === false) {
                 $block = array("outcomes" => array());
                 $pts[0] = $it;
             } else {
                 $pts[0] = substr($it, 0, $pos);
                 $pts[1] = substr($it, $pos + 1);
                 $subarr = additems($pts[1]);
                 $block = array("outcomes" => $subarr);
             }
             if (substr($pts[0], 0, 3) == 'new') {
                 $name = stripslashes($_POST['newg' . substr($pts[0], 6)]);
             } else {
                 $name = stripslashes($_POST['g' . substr($pts[0], 3)]);
             }
             $block['name'] = $name;
             $outarr[] = $block;
         } else {
             //is an outcome
             if (substr($it, 0, 3) == 'new') {
                 $ocnt = substr($it, 3);
                 $query = "INSERT INTO imas_outcomes (courseid, name) VALUES ";
                 $query .= "('{$cid}','{$_POST['newo' . $ocnt]}')";
                 $result = mysql_query($query) or die("Query failed : " . mysql_error());
                 $newid = mysql_insert_id();
                 $seenoutcomes[] = $newid;
                 $outarr[] = $newid;
             } else {
                 if (isset($curoutcomes[$it])) {
                     if (stripslashes($_POST['o' . $it]) != $curoutcomes[$it]) {
                         $query = "UPDATE imas_outcomes SET name='{$_POST['o' . $it]}' WHERE id='{$it}' AND courseid='{$cid}'";
                         $result = mysql_query($query) or die("Query failed : " . mysql_error());
                     }
                     $outarr[] = $it;
                     $seenoutcomes[] = $it;
                 }
             }
         }
     }
     return $outarr;
 }
示例#2
0
function additems($list)
{
    global $items;
    $outarr = array();
    $list = substr($list, 1, -1);
    $i = 0;
    $nd = 0;
    $last = 0;
    $listarr = array();
    while ($i < strlen($list)) {
        if ($list[$i] == '[') {
            $nd++;
        } else {
            if ($list[$i] == ']') {
                $nd--;
            } else {
                if ($list[$i] == ',' && $nd == 0) {
                    $listarr[] = substr($list, $last, $i - $last);
                    $last = $i + 1;
                }
            }
        }
        $i++;
    }
    $listarr[] = substr($list, $last);
    foreach ($listarr as $it) {
        if (strpos($it, '-') !== false) {
            //is block
            $pos = strpos($it, ':');
            if ($pos === false) {
                $pts[0] = $it;
            } else {
                $pts[0] = substr($it, 0, $pos);
                $pts[1] = substr($it, $pos + 1);
            }
            $blocktree = explode('-', $pts[0]);
            $sub = $items;
            for ($i = 1; $i < count($blocktree) - 1; $i++) {
                $sub = $sub[$blocktree[$i] - 1]['items'];
            }
            $block = $sub[$blocktree[count($blocktree) - 1] - 1];
            if ($pos === false) {
                $block['items'] = array();
            } else {
                $subarr = additems($pts[1]);
                $block['items'] = $subarr;
            }
            $outarr[] = $block;
        } else {
            //regular item
            $outarr[] = $it;
        }
    }
    return $outarr;
}