Exemplo n.º 1
0
function computeSourceCells($formula, $dbTable, $ccid, $crid, $cpid, &$aPSCs, $sciri, &$dbtUpdate)
{
    function getCells($cid, $ri, $tid, &$liveDBTable, &$sCs, &$tp, &$dbtUpdate, $sciri, $dbTable, $ccid)
    {
        $cid = $cid == 'index' ? $ccid : $cid;
        if ($cid[0] == '/') {
            foreach ($liveDBTable['cells'][$ri] as $ci => $cell) {
                if (preg_match($cid, $ci)) {
                    array_push($sCs, $ci . "," . ($ri != 'tHR' ? $liveDBTable['cells'][$ri][$liveDBTable['priCol']]['innerHTML'] : "") . ($tid != $dbTable ? "," . $tid : ''));
                    $tp[$ri][$ci]['f']['ee'][] = $tid == $dbTable ? $sciri : $sciri . "," . $dbTable;
                    $dbtUpdate['tables'][$tid]['cells'][$ri][$ci]['f']['ee'] = $tp[$ri][$ci]['f']['ee'] = true_array_unique($tp[$ri][$ci]['f']['ee']);
                }
            }
        } elseif ($cid[0] == '*') {
            array_push($sCs, "index," . ($ri != 'tHR' ? $liveDBTable['cells'][$ri][$liveDBTable['priCol']]['innerHTML'] : "") . "," . ($tid != $dbTable ? "," . $tid : ''));
        } elseif (count($cids = split('~', $cid)) > 1) {
            $rangeE = FALSE;
            foreach ($liveDBTable['cells']['tHR'] as $ci => $cell) {
                if (($ci == $cids[0] or $rangeS) and !$rangeE) {
                    $rangeS = true;
                    if ($ci == $cids[1]) {
                        $rangeE = true;
                    }
                    $rcells[] = $ci;
                }
            }
            if ($rangeE) {
                foreach ($rcells as $rci => $ci) {
                    array_push($sCs, $ci . "," . ($ri != 'tHR' ? $liveDBTable['cells'][$ri][$liveDBTable['priCol']]['innerHTML'] : "") . ($tid != $dbTable ? "," . $tid : ''));
                    $tp[$ri][$ci]['f']['ee'][] = $tid == $dbTable ? $sciri : $sciri . "," . $dbTable;
                    $dbtUpdate['tables'][$tid]['cells'][$ri][$ci]['f']['ee'] = $tp[$ri][$ci]['f']['ee'] = true_array_unique($tp[$ri][$ci]['f']['ee']);
                }
            }
        } elseif ($cid != '') {
            if (isset($liveDBTable['cells'][$ri][$cid])) {
                array_push($sCs, $cid . "," . ($ri != 'tHR' ? $liveDBTable['cells'][$ri][$liveDBTable['priCol']]['innerHTML'] : "") . ($tid != $dbTable ? "," . $tid : ''));
                $tp[$ri][$cid]['f']['ee'][] = $tid == $dbTable ? $sciri : $sciri . "," . $dbTable;
                $dbtUpdate['tables'][$tid]['cells'][$ri][$cid]['f']['ee'] = $tp[$ri][$cid]['f']['ee'] = true_array_unique($tp[$ri][$cid]['f']['ee']);
            }
        }
    }
    $fx = $formula;
    $sCs = array();
    $matches = array();
    preg_match_all('/[0-9a-zA-Z_~]+\\([0-9a-zA-Z_~*]*\\)\\([0-9a-zA-Z_]*\\)/i', $formula, $matches);
    foreach ($matches[0] as $key => &$match) {
        $ml = strlen($match);
        $rstart = strpos($match, '(', 0);
        $rend = strpos($match, ')', 0);
        $rid = substr($match, $rstart + 1, $rend - $rstart - 1);
        $tstart = strpos($match, '(', $rstart + 1);
        $tid = substr($match, $tstart + 1, $ml - $tstart - 2);
        if ($_SESSION['tables'][$tid]) {
            $liveDBTable = getLiveTable($tid);
            $tp = getTableFromFile($tid);
            if ($ca = $aPSCs[$tid]) {
                foreach ($ca as $i => $c) {
                    $c[1] = $c[1] ? rowWithPid($liveDBTable, $c[1]) : 'tHR';
                    foreach ($tp[$c[1]][$c[0]]['f']['ee'] as $e => $ee) {
                        if ($ee == $sciri or $ee == $sciri . "," . $dbTable) {
                            unset($tp[$c[1]][$c[0]]['f']['ee'][$e]);
                            $dbtUpdate['tables'][$tid]['cells'][$c[1]][$c[0]]['f']['ee'] = $tp[$c[1]][$c[0]]['f']['ee'] = true_array_unique($tp[$c[1]][$c[0]]['f']['ee']);
                            break;
                        }
                    }
                }
                unset($aPSCs[$tid]);
            }
            $rid = substr($match, $rstart + 1, $rend - $rstart - 1);
            $cid = substr($match, 0, $rstart);
            if ($rid[0] == '/') {
                foreach ($liveDBTable['cells'] as $ri => $row) {
                    if (preg_match($rid, $row[$liveDBTable['priCol']])) {
                        getCells($cid, $ri, $tid, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                    }
                }
            } elseif ($rid[0] == '*') {
                getCells($cid, 'tHR', $tid, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
            } elseif (count($rids = split('~', $rid)) > 1) {
                $rangeE = FALSE;
                foreach ($liveDBTable['cells'] as $ri => $row) {
                    if (($row[$liveDBTable['priCol']]['innerHTML'] == $rids[0] or $rangeS) and !$rangeE) {
                        $rangeS = true;
                        if ($row[$liveDBTable['priCol']]['innerHTML'] == $rids[1]) {
                            $rangeE = true;
                        }
                        $rrows[] = $ri;
                    }
                }
                if ($rangeE) {
                    foreach ($rrows as $kei => $ri) {
                        getCells($cid, $ri, $tid, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                    }
                }
            } elseif ($rid != '') {
                getCells($cid, rowWithPid($liveDBTable, $rid), $tid, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
            } elseif ($rid == '') {
                getCells($cid, rowWithPid($liveDBTable, $cpid), $tid, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
            }
            putTableInFile($tp, $tid);
            closeLiveTable($liveDBTable);
        }
        $k = 0;
        $formula = str_replace($match, 'var' . $k++, $formula);
    }
    $liveDBTable = getLiveTable($dbTable);
    $tp = getTableFromFile($dbTable);
    if ($ca = $aPSCs[$dbTable]) {
        foreach ($ca as $i => $c) {
            $c[1] = $c[1] ? rowWithPid($liveDBTable, $c[1]) : 'tHR';
            foreach ($tp[$c[1]][$c[0]]['f']['ee'] as $e => $ee) {
                if ($ee == $sciri or $ee == $sciri . "," . $dbTable) {
                    unset($tp[$c[1]][$c[0]]['f']['ee'][$e]);
                    $dbtUpdate['tables'][$dbTable]['cells'][$c[1]][$c[0]]['f']['ee'] = $tp[$c[1]][$c[0]]['f']['ee'] = true_array_unique($tp[$c[1]][$c[0]]['f']['ee']);
                    break;
                }
            }
        }
        unset($aPSCs[$dbTable]);
    }
    foreach ($liveDBTable['cells']['tHR'] as $colName => $column) {
        $start = 0;
        $start = strpos($formula, $colName, $start);
        while ($start > -1) {
            if (preg_match("/[^a-zA-Z0-9_]/", $formula[$start - 1]) or !$formula[$start - 1]) {
                $pst = $start;
                $start += strlen($colName);
                if ($formula[$pst - 1] != ';' and ($formula[$start] != '=' or $formula[$start + 1] == '=') and (preg_match("/[^a-zA-Z0-9_]/", $formula[$start]) or !$formula[$start])) {
                    $cid = $colName;
                    $row = '';
                    unset($col2);
                    if ($formula[$start++] == '~') {
                        foreach ($liveDBTable['cells']['tHR'] as $col2 => $column2) {
                            if (strpos($formula, $col2, $start) == $start) {
                                $colName2 = $col2;
                                break;
                            }
                        }
                    }
                    if ($col2 and $colName2 or !($col2 or $colName2)) {
                        $cid = $colName2 ? $cid . '~' . $colName2 : $cid;
                        $j = $start;
                        unset($rid);
                        while ($formula[$start - 1] == '(' and $formula[$j] != '' and $formula[$j] != ')') {
                            $rid .= $formula[$j++];
                        }
                        if ($rid) {
                            $start = ++$j;
                            if (count($rids = split('~', $rid)) > 1) {
                                $rangeE = FALSE;
                                $rrows = array();
                                foreach ($liveDBTable['cells'] as $ri => $row) {
                                    if (($row[$liveDBTable['priCol']]['innerHTML'] == $rids[0] or $rangeS) and !$rangeE) {
                                        $rangeS = true;
                                        if ($row[$liveDBTable['priCol']]['innerHTML'] == $rids[1]) {
                                            $rangeE = true;
                                        }
                                        $rrows[] = $ri;
                                    }
                                }
                                if ($rangeE) {
                                    foreach ($rrows as $kei => $ri) {
                                        getCells($cid, $ri, $dbTable, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                                    }
                                }
                            } elseif ($rid[0] == '/') {
                                foreach ($liveDBTable['cells'] as $ri => $row) {
                                    if (preg_match($rid, $row[$liveDBTable['priCol']])) {
                                        getCells($cid, $ri, $dbTable, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                                    }
                                }
                            } elseif ($rid == '*') {
                                getCells($cid, 'tHR', $dbTable, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                            } elseif ($rid != '' and $rid != ' ') {
                                getCells($cid, rowWithPid($liveDBTable, $rid), $dbTable, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                            }
                        } else {
                            getCells($cid, $crid, $dbTable, $liveDBTable, $sCs, $tp, $dbtUpdate, $sciri, $dbTable, $ccid);
                        }
                    }
                    $start = strpos($formula, $colName, $start);
                }
            } else {
                $start = strpos($formula, $colName, $start);
            }
        }
    }
    putTableInFile($tp, $dbTable);
    closeLiveTable($liveDBTable);
    foreach ($aPSCs as $tid => $ca) {
        $liveDBTable = getLiveTable($tid);
        $tp = getTableFromFile($tid);
        foreach ($ca as $i => $c) {
            $c[1] = $c[1] ? $c[1] : 'tHR';
            foreach ($tp[$c[1]][$c[0]]['f']['ee'] as $e => $ee) {
                if ($ee == $sciri or $ee == $sciri . "," . $dbTable) {
                    unset($tp[$c[1]][$c[0]]['f']['ee'][$e]);
                    $dbtUpdate['tables'][$tid]['cells'][$c[1]][$c[0]]['f']['ee'] = $tp[$c[1]][$c[0]]['f']['ee'] = true_array_unique($tp[$c[1]][$c[0]]['f']['ee']);
                    break;
                }
            }
        }
        putTableInFile($tp, $tid);
        closeLiveTable($liveDBTable);
        unset($aPSCs[$tid]);
    }
    $sCs = true_array_unique($sCs);
    return $sCs;
}
Exemplo n.º 2
0
$defaultStr = "\"" . implode("\",\"", $Defaul) . "\"";
$extraStr = "\"" . implode("\",\"", $Extr) . "\"";
$commentStr = "\"" . implode("\",\"", $Commen) . "\"";
if (!$liveDBTable['liveD']) {
    $query = "SELECT * FROM `" . $dbTable . "` ORDER BY `index`";
    $result = mysql_query($query, $dbc);
    $error2 = mysql_error($dbc);
}
if ($sm) {
    $cc = count($Field);
    $rc = $rowCount;
}
$rc = $rc ? $rc : 0;
//$rowCount = $rc;
if (!$liveDBTable['liveD']) {
    $tp = getTableFromFile($dbTable);
    foreach ($Field as $i => $colName) {
        for ($j = -1; $j < $rowCount; $j++) {
            if (isset($rInd[$j])) {
                $liveDBTable['cells'][$rInd[$j]][$colName] = $tp[$rInd[$j]][$colName];
                $liveDBTable['cells'][$rInd[$j]][$colName]['innerHTML'] = mysql_result($result, $j, $colName);
            } elseif ($j == -1) {
                $liveDBTable['cells']['tHR'][$colName] = $tp['tHR'][$colName];
                $liveDBTable['cells']['tHR'][$colName]['Type'] = $Type[$i];
                $liveDBTable['cells']['tHR'][$colName]['Null'] = $Null[$i];
                $liveDBTable['cells']['tHR'][$colName]['Key'] = $Key[$i];
                $liveDBTable['cells']['tHR'][$colName]['Default'] = $Default[$i];
                $liveDBTable['cells']['tHR'][$colName]['Extra'] = $Extra[$i];
                $liveDBTable['cells']['tHR'][$colName]['Comment'] = $Comment[$i];
                if ($colName == 'index') {
                    $liveDBTable['cells']['tHR'][$colName]['rowCount'] = $rc;