function grabFiles($parentPath) { $directory = array_diff(scandir($parentPath), array('..', '.')); $leftNode[] = NULL; foreach ($directory as $child) { if (!is_dir($parentPath . $child)) { generateInsert($parentPath . $child); } else { generateDirInsert($parentPath . $child . '/'); array_push($leftNode, $child); } } foreach ($leftNode as $dir) { if ($dir != NULL) { grabFiles($parentPath . $dir . '/'); } } }
function saveToDB() { if (isset($_REQUEST["on_success"])) { $onSuccess = $_REQUEST["on_success"]; } else { $onSuccess = ""; } if (isset($_REQUEST["on_error"])) { $onFailure = $_REQUEST["on_error"]; } else { $onFailure = ""; } $sysDb = false; $fFormat = str_replace("yy", "Y", getConfig("DATE_FORMAT")); $date = date($fFormat); $oriData = array(); $oriData["date"] = $date; $oriData["doc"] = $date; $oriData["doe"] = $date; $oriData["time"] = date(getConfig("TIME_FORMAT")); $oriData["toc"] = date(getConfig("TIME_FORMAT")); $oriData["toe"] = date(getConfig("TIME_FORMAT")); $oriData["tsoc"] = $oriData["dtoc"] = date($fFormat . " " . getConfig("TIME_FORMAT")); $oriData["tsoe"] = $oriData["dtoe"] = $oriData["dtoc"]; $oriData["last_modified"] = $oriData["dtoc"]; $usr = getUserInfo(); $oriData["username"] = $usr["SESS_USER_NAME"]; $oriData["userid"] = $usr["SESS_USER_ID"]; $oriData["privilegeid"] = $_SESSION["SESS_PRIVILEGE_ID"]; $oriData["scanBy"] = $_SESSION["SESS_USER_ID"]; $oriData["submittedby"] = $usr["SESS_USER_ID"]; $oriData["createdBy"] = $usr["SESS_USER_ID"]; $oriData["guid"] = $usr["SESS_GUID"]; $oriData["site"] = SITENAME; $dataPost = $_POST; if (isset($_REQUEST["frmMode"])) { $sMode = $_REQUEST["frmMode"]; } else { $sMode = "updateinsert"; } if (isset($dataPost["frmID"])) { $sForm = urldecode($dataPost["frmID"]); } else { $sForm = "-1"; } $sTable = urldecode($dataPost["submit_table"]); $sWhereCol = urldecode($dataPost["submit_wherecol"]); if (strpos("#" . $sTable, $GLOBALS["DBCONFIG"]["DB_SYSTEM"]) == 1) { $sysDb = true; } $tblCols = _db($sysDb)->getTableInfo($sTable); if ($tblCols == null) { exit("Error::Source DataTable Not Found."); } unset($dataPost["frmID"]); unset($dataPost["submit_table"]); unset($dataPost["submit_wherecol"]); if (isset($dataPost[$sWhereCol]) && $dataPost[$sWhereCol] == "-1") { exit("Error::No Data Found"); } if (isset($_FILES) && count($_FILES) > 0) { $maxUdirLength = strlen(APPROOT . APPS_USERDATA_FOLDER); $bpath = APPROOT . APPS_USERDATA_FOLDER . "attachments/"; if (!is_dir($bpath)) { exit("Error::Attachment Folder Not Found"); } $bpath .= md5($sForm) . "/"; if (!is_dir($bpath)) { mkdir($bpath, true, 0777); } foreach ($_FILES as $key => $value) { if ($value['error'] == 0) { $fPath = $bpath . $_SESSION['SESS_USER_ID'] . "-" . $value['name']; if (!move_uploaded_file($value['tmp_name'], $fPath)) { exit("Error::Attachment Save Error For {$key}"); } else { $dataPost[$key] = substr($fPath, $maxUdirLength); } } else { exit("Error::Attachment Upload Error For {$key}"); } } } $sql = ""; if ($sMode == "update") { $sWhereCol = explode(",", $sWhereCol); $arr = array(); foreach ($sWhereCol as $a => $b) { if (isset($dataPost[$b])) { $arr[$b] = $dataPost[$b]; unset($dataPost[$b]); } } $sWhereCol = $arr; $sql = generateUpdate($sTable, $tblCols, $oriData, $dataPost, $sWhereCol); } elseif ($sMode == "insert") { $sql = generateInsert($sTable, $tblCols, $oriData, $dataPost); } elseif ($sMode == "updateinsert") { $dataPost1 = $dataPost; $sWhereCol = explode(",", $sWhereCol); $arr = array(); foreach ($sWhereCol as $a => $b) { if (isset($dataPost[$b])) { $arr[$b] = $dataPost[$b]; unset($dataPost[$b]); } } $sWhereCol = $arr; $q = "SELECT count(*) as cnt FROM {$sTable} where " . generateWhere($sWhereCol); $res1 = _dbQuery($q, $sysDb); if ($res1 && _db()->recordCount($res1) > 0) { $data = _db()->fetchData($res1); _db($sysDb)->freeResult($res1); if ($data["cnt"] > 0) { $sql = generateUpdate($sTable, $tblCols, $oriData, $dataPost, $sWhereCol); $sMode = "update"; } else { $sql = generateInsert($sTable, $tblCols, $oriData, $dataPost1); $sMode = "insert"; } } else { $sql = generateInsert($sTable, $tblCols, $oriData, $dataPost1); $sMode = "insert"; } } if ($sMode == "update" && count($sWhereCol) <= 0) { echo "Error:: Where Condition Not Satisfied For Update Query."; exit; } //exit("Error:: $sql"); if (strlen($sql) > 0) { $a = _dbQuery($sql, $sysDb); if ($a) { if ($sMode == "insert") { printResult("{$sTable}", _db($sysDb)->insert_id()); } else { if (_db($sysDb)->affected_rows() > 0) { if (in_array("last_modified", $tblCols[0]) && in_array("id", $tblCols[0])) { $q = "SELECT id FROM {$sTable} ORDER BY last_modified DESC LIMIT " . _db($sysDb)->affected_rows(); $b = _dbQuery($q, $sysDb); if ($b) { $data = _dbData($b); _db($sysDb)->freeResult($b); $ids = array(); foreach ($data as $a => $b) { array_push($ids, $b['id']); } $ids = implode(",", $ids); printResult("{$sTable}", "{$ids}"); } } elseif (in_array("tsoe", $tblCols[0]) && in_array("id", $tblCols[0])) { $q = "SELECT id FROM {$sTable} ORDER BY tsoe DESC LIMIT " . _db($sysDb)->affected_rows(); $b = _dbQuery($q, $sysDb); if ($b) { $data = _dbData($b); _db($sysDb)->freeResult($b); $ids = array(); foreach ($data as $a => $b) { array_push($ids, $b['id']); } $ids = implode(",", $ids); printResult("{$sTable}", "{$ids}"); } } elseif (count($sWhereCol) > 0) { $where = generateWhere($sWhereCol); $q = "SELECT id FROM {$sTable} WHERE {$where}"; $b = _dbQuery($q, $sysDb); if ($b) { $data = _dbData($b); _db($sysDb)->freeResult($b); $ids = array(); foreach ($data as $a => $b) { array_push($ids, $b['id']); } $ids = implode(",", $ids); printResult("{$sTable}", "{$ids}"); } } } else { $where = generateWhere($sWhereCol); $q = "SELECT id FROM {$sTable} WHERE {$where}"; $b = _dbQuery($q, $sysDb); if ($b) { $data = _dbData($b); _db($sysDb)->freeResult($b); $ids = array(); foreach ($data as $a => $b) { array_push($ids, $b['id']); } $ids = implode(",", $ids); printResult("{$sTable}", "{$ids}"); } } } if ($sysDb) { initUserCredentials(); } if (function_exists($onSuccess)) { call_user_func($onSuccess); } else { echo $onSuccess; } if (function_exists("log_ActivityEvent")) { log_ActivityEvent("FORM Submited Success ::{$sForm}/{$sTable}, For ID::" . _db()->insert_id(), "User", 4, "forms", _dbtable("forms")); } } else { $stmt = explode(" ", trim($sql)); $stmt = strtoupper($stmt[0]); if ($GLOBALS['DBCONFIG']["DB_READ_ONLY"] == "true") { echo "Error:: DBMS In ReadOnly Mode. No New Data Will Be Added Or Deleted From System.<br/>Please Contact Server Administrator."; } elseif (strpos(strtoupper("##" . $GLOBALS['DBCONFIG']["BLOCK_STATEMENTS"]), $stmt) > 1) { echo "Error:: Following Database Operation Is Prohibitted On DBMS By Server Administrator.<br/>Please Contact Server Administrator."; } else { if (strlen($onFailure) > 0) { echo $onFailure; } else { echo "Error:: " . _db($sysDb)->getError() . "<br/>"; } if (MASTER_DEBUG_MODE == 'true') { echo _db($sysDb)->getError(); } if (function_exists("log_ActivityEvent")) { log_ActivityEvent("FORM Submit Failed ::{$sForm}/{$sTable}", "User", 4, "forms", _dbtable("forms")); } } } } else { if (strlen($onFailure) > 0) { echo $onFailure; } else { echo "Error:: " . _db($sysDb)->getErrorNo() . "<br/>"; } if (MASTER_DEBUG_MODE == 'true') { echo _db($sysDb)->getError(); } if (function_exists("log_ActivityEvent")) { log_ActivityEvent("FORM SQL Creation Error ::{$sForm}/{$sTable}", "User", 4, "forms", _dbtable("forms")); } } }