/** * Save current view properties * * @access public */ function saveProp() { if ($GLOBALS['action'] == 'delete' || $this->isExist) { $queryDisplay = $query[] = 'DROP VIEW ' . brackets($this->view) . ';'; } if ($GLOBALS['action'] != 'delete') { if ($this->isExist) { $viewname = $this->view; } else { $viewname = $_POST['ViewName']; } if (!empty($_POST['ViewName']) && !empty($_POST['ViewProp'])) { $queryDisplay = $query[] = 'CREATE VIEW ' . brackets($viewname) . ' AS ' . urldecode(SQLiteStripSlashes($_POST['ViewProp'])) . ';'; } } $errorMessage = ''; if ($query) { foreach ($query as $req) { $this->connId->getResId("BEGIN;"); $res = $this->connId->getResId($req); $this->connId->getResId("COMMIT;"); if (!$res) { $errorCode = @sqlitem_last_error($this->connId->connId); $errorMessage .= $GLOBALS['traduct']->get(9) . ' ' . $errorCode . ' : ' . @$this->connId->connId->getError() . '\\n'; } } } else { if (empty($_POST['ViewName']) || empty($_POST['ViewProp'])) { $errorMessage .= $GLOBALS['traduct']->get(18); } } if ($GLOBALS['action'] != 'delete') { if ($queryDisplay) { displayQuery($queryDisplay); } if (!empty($errorMessage)) { displayError($errorMessage); $this->viewEditForm(); } } else { $GLOBALS["redirect"] = "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS["dbsel"] . "'; parent.main.location='main.php?dbsel=" . $GLOBALS["dbsel"] . "';</script>"; } }
} if (!$error) { if (isset($_POST['dbVersion']) && $_POST['dbVersion'] && !file_exists($dbFile)) { $newDb = $SQLiteFactory->sqliteGetInstance($dbFile, $_POST['dbVersion']); $newDb->query("CREATE TABLE tempFred (id integer);"); $newDb->query("DROP TABLE tempFred;"); } else { $newDb = $SQLiteFactory->sqliteGetInstance($dbFile); } if ($newDb) { if ($newDb->dbVersion == 2) { $newDb->close(); } else { $newDb = null; } $query = 'INSERT INTO database (name, location) VALUES (' . quotes(SQLiteStripSlashes($_POST['dbname'])) . ', ' . quotes($dbFilename) . ')'; if (!$db->query($query)) { $error = true; $message .= '<li><span style="color: red; font-size: 11px;">' . $GLOBALS['traduct']->get(100) . '</span></li>'; } else { if (DEBUG) { $dbsel = $db->last_insert_id(); } else { $dbsel = @$db->last_insert_id(); } } } } else { $error = true; $message .= '<li><span style="color: red; font-size: 11px;">' . $GLOBALS['traduct']->get(101) . '</span></li>'; }
/** * Cleanup POST query * and convert MySQL type into SQLite type * * @access public * @param array $data data table * @param string $width width of the end table (px or %) */ function cleanup($query) { $query = SQLiteStripSlashes($query); if (!isset($_POST['sqltype'])) { $_POST['sqltype'] = 1; } if ($_POST['sqltype'] == 2) { $query = str_replace("\\'", "''", $query); $query = str_replace("\\\"", "\"\"", $query); } return $query; }
$withForm = true; } if (!isset($DisplayQuery) || empty($DisplayQuery)) { if ($action == 'sql') { $displayResult = false; } if (!empty($table) || !empty($view)) { $DisplayQuery = 'SELECT * FROM ' . quotes(brackets($table, false) . brackets($view, false)); } else { $DisplayQuery = ''; } } else { if (!isset($_FILES)) { $DisplayQuery = urldecode($GLOBALS['DisplayQuery']); } elseif (!empty($_POST['DisplayQuery']) || !empty($_GET['DisplayQuery'])) { $DisplayQuery = SQLiteStripSlashes($DisplayQuery); } } if (!isset($displayResult)) { $displayResult = true; } if (!isset($sql_action)) { $sql_action = ''; } if ($sql_action == 'explain' && !preg_match('#EXPLAIN#i', $DisplayQuery)) { $DisplayQuery = 'EXPLAIN ' . $DisplayQuery; } $SQLiteQuery = new sql($workDb, $DisplayQuery); if ($sql_action != 'modify') { $error = $SQLiteQuery->verify(false); } else {
/** * Escape string To SQLite * * @access public * @param string $string */ function formatString($string) { return @$this->connId->escape(SQLiteStripSlashes($string)); }
/** * save current TRIGGER properties * * @access public */ function saveProp() { if ($GLOBALS['action'] == 'delete' || $this->isExist) { $queryDisplay = $query[] = 'DROP TRIGGER ' . brackets($this->trigger) . ';'; } if ($GLOBALS['action'] != 'delete') { if ($this->isExist) { $triggername = $this->trigger; } else { $triggername = $_POST['TriggerName']; } $queryCreate = 'CREATE TRIGGER ' . brackets($triggername) . ' ' . $_POST['TriggerMoment']; if ($_POST['TriggerMoment'] != '') { $queryCreate .= ' '; } $queryCreate .= $_POST['TriggerEvent'] . ' '; if ($_POST['TriggerEvent'] == 'UPDATE OF') { $queryCreate .= $_POST['ColumnList'] . ' '; } $queryCreate .= 'ON ' . brackets($_POST['TriggerOn']) . ' ' . $_POST['TriggerAction']; if ($_POST['TriggerAction'] != '') { $queryCreate .= ' '; } if ($_POST['TriggerCondition'] == 'WHEN') { $queryCreate .= 'WHEN ' . $_POST['ConditionList'] . ' '; } $queryCreate .= "\n" . 'BEGIN ' . "\n" . SQLiteStripSlashes($_POST['TriggerStep']) . "\n" . ' END;' . "\n"; $queryDisplay = $query[] = $queryCreate; $this->triggerProperties = $queryCreate; } $errorMessage = ''; foreach ($query as $req) { $this->connId->getResId("BEGIN;"); $res = $this->connId->getResId($req); $this->connId->getResId("COMMIT;"); if (!$res) { $errorMessage .= $GLOBALS['traduct']->get(9) . ' ' . $errorCode . ' : ' . @$this->connId->connId->getError() . "\n"; } } displayQuery($queryDisplay); if (!empty($errorMessage)) { displayError($errorMessage); } if ($GLOBALS['action'] != 'delete') { $this->propView(); echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS["dbsel"] . "';</script>"; } else { echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS["dbsel"] . "'; parent.main.location='main.php?dbsel=" . $GLOBALS["dbsel"] . "';</script>"; } }
break; case 'unique': case 'index': $tableProp->saveKey(); break; case 'insertElement': $tableProp->formElement(); break; case 'insertFromFile': $tableProp->formFromFile(); break; case 'saveFromFile': $tableProp->saveFromFile(); break; case 'modifyElement': $tableProp->formElement(urldecode(SQLiteStripSlashes($_GET['query'])), $_GET['pos']); break; case 'saveElement': case 'deleteElement': $tableProp->saveElement(); if (isset($GLOBALS['reBrowse']) && $GLOBALS['reBrowse']) { include_once INCLUDE_LIB . 'browse.php'; } break; case 'empty': $query = 'DELETE FROM ' . brackets($table) . ';'; if ($dbsel) { $workDb->getResId($query); } displayQuery($query, false); $redirect = "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $dbsel . "'; parent.main.location='main.php?dbsel={$dbsel}&table={$table}';</script>";
/** * save record * * @access private */ function saveElement() { if (isset($_GET['pos'])) { $GLOBALS['numId'] = $_GET['pos']; } if (isset($_REQUEST['numId'])) { $GLOBALS['numId'] = $_REQUEST['numId']; } if (isset($_GET['query'])) { $GLOBALS['req'] = urldecode($_GET['query']); } elseif (isset($_POST['req'])) { $GLOBALS['req'] = urldecode($_POST['req']); } if (isset($GLOBALS['req']) && isset($GLOBALS['numId'])) { $oldValue = $this->recupElement($GLOBALS['req'], $GLOBALS['numId']); } if (isset($_POST['valField']) && is_array($_POST['valField'])) { while (list($champ, $value) = each($_POST['valField'])) { $value = SQLiteStripSlashes($value); $cid = $this->getCID($champ); $tempType = $this->infoTable[$cid]['type']; if (isset($_POST['funcs'][$champ]) && !empty($_POST['funcs'][$champ])) { if (preg_match('#CHAR|TEXT|LOB|DATE#i', $tempType)) { $funcVal = quotes($value); } else { $funcVal = $value; } $value = applyFunction($_POST['funcs'][$champ], $funcVal); } elseif (!isset($_POST['nullField'][$champ]) || !$_POST['nullField'][$champ]) { if ($tempType) { if (preg_match('#CHAR|TEXT|LOB|DATE#i', $tempType)) { $value = quotes($value); } } else { $value = quotes($value); } } if (isset($_POST['nullField'][$champ])) { $value = 'NULL'; } if (!isset($_POST['numId']) || $_POST['save_type'] == "as_new_row") { $listColumn[] = brackets($champ); $listValue[] = $value; } else { if (isset($oldValue[$champ]) && $value != quotes($oldValue[$champ]) || !isset($oldValue[$champ]) && $value != "NULL") { $listColumn[] = brackets($champ) . '=' . $value; } } } } $query = ''; if ($GLOBALS['action'] == 'deleteElement') { $query = 'DELETE FROM ' . brackets($GLOBALS['table']) . ' WHERE ROWID=' . $oldValue['ROWID']; } elseif (isset($_POST['numId']) && $_POST['save_type'] != "as_new_row") { if (isset($listColumn) && !empty($listColumn)) { $query = 'UPDATE ' . brackets($GLOBALS['table']) . ' SET ' . implode(', ', $listColumn) . ' WHERE ROWID=' . $oldValue['ROWID']; } } else { if (isset($listColumn) && isset($listValue)) { $query = 'INSERT INTO ' . brackets($GLOBALS['table']) . ' (' . implode(', ', $listColumn) . ') VALUES (' . implode(', ', $listValue) . ')'; } } displayQuery($query); $errorCode = false; if (isset($query) && !empty($query)) { $this->connId->getResId('BEGIN;'); if (!$this->connId->getResId($query)) { echo '<center><span style="color: red;">' . $GLOBALS['traduct']->get(9) . ' : ' . @$this->connId->connId->getError() . '</span></center>'; $this->formElement($GLOBALS['req'], $GLOBALS['numId'], true); } $this->connId->getResId('COMMIT;'); } // return management if (!isset($_REQUEST['after_save']) && isset($_REQUEST['currentPage'])) { $_REQUEST['after_save'] = $_REQUEST['currentPage']; } if (!$errorCode && isset($_REQUEST['after_save'])) { if ($_REQUEST['after_save'] == '') { $this->formElement(isset($GLOBALS['req']) ? $GLOBALS['req'] : '', isset($GLOBALS['numId']) ? $GLOBALS['numId'] : ''); } else { switch ($_REQUEST['after_save']) { case '': case 'properties': $this->tablePropView(); break; case 'browseItem': if (isset($GLOBALS['numId'])) { $GLOBALS['noDisplay'] = true; include_once INCLUDE_LIB . 'ParsingQuery.class.php'; $tabRes = ParsingQuery::noLimit($GLOBALS['req']); $GLOBALS['DisplayQuery'] = $tabRes['query']; $GLOBALS['pageBrowse'] = $_GET['pageBrowse'] = $tabRes['page']; } $GLOBALS['reBrowse'] = true; break; } } } }
/** * return table data * * @access public * @param string $table table name */ function tableContent($table) { $out = '#%BREAK%###%BREAK%#'; $out .= '# ' . $GLOBALS['traduct']->getdirect(133) . ': ' . $table . '#%BREAK%#'; $out .= '##%BREAK%#'; // build nullByName array if (!is_array($this->tableProperties)) { $this->getTableProperties($table); } if (is_array($this->tableProperties)) { foreach ($this->tableProperties as $trash => $tabInfoTable) { $nullByName[$tabInfoTable["name"]] = $tabInfoTable["notnull"]; } } else { $nullByName = array(); } if (isset($_REQUEST['queryExport']) && $_REQUEST['queryExport']) { $query = urldecode(SQLiteStripSlashes($_REQUEST['queryExport'])); } else { $query = 'SELECT * FROM ' . brackets($table); } $this->connId->connId->query($query); while ($ligne = $this->connId->connId->fetch_array(null, SQLITE_ASSOC)) { if (isset($_POST['fullInsert']) && !empty($_POST['fullInsert']) && !isset($columnList)) { for ($i = 0; $i < $this->connId->connId->num_fields(); $i++) { $currentNameField = $this->connId->connId->field_name(null, $i); $columnList[$i] = brackets($currentNameField); } } $columnValue = array(); $out .= 'INSERT INTO ' . brackets($table); if (isset($_POST['fullInsert']) && !empty($_POST['fullInsert'])) { $out .= ' (' . implode(', ', $columnList) . ')'; } while (list($key, $val) = each($ligne)) { $columnValue[$key] = "'" . $this->connId->formatString($val) . "'"; if (isset($nullByName[$key]) && !$nullByName[$key] && $columnValue[$key] == "''") { $columnValue[$key] = "NULL"; } } $out .= " VALUES (" . implode(", ", $columnValue) . ");#%BREAK%#"; } $out = str_replace(";\r\n", "; ", $out); $this->exportContent .= $out; return; }