function Users_DELETE($wr) { $query = 'DELETE FROM "Users"'; $query .= genWhere($wr); $result = PQuery($query); return $result; }
function genWhere($wr, $sign = '=', $recursive = false) { $where = ''; foreach ($wr as $field => $value) { $field1 = genFieldName($field); if (strlen($where) > 0) { $where .= ' AND '; } if (is_string($value) && preg_match('/^(NOT\\s)?NULL$/', $value)) { $where .= ' ' . $field1 . ' IS ' . pg_escape_string($value) . ''; } else { if (is_string($value) && preg_match('/^\\(\\s*([0-9.]+[, \\s]+)+[0-9.]+\\s*\\)$/', $value)) { $where .= ' ' . $field1 . '~=\'' . pg_escape_string($value) . '\''; } else { if (is_numeric($value)) { $where .= ' ' . $field1 . $sign . $value . ''; } else { if (is_array($value)) { $where .= genWhere(array($field => $value['val']), $value['sign'], true); } else { $where .= ' ' . $field1 . $sign . '\'' . pg_escape_string($value) . '\''; } } } } } return $recursive ? ' ' . $where : ' WHERE ' . $where; }
function OpticalFiber_DELETE($wr, $sign = '=') { $query = 'DELETE FROM "OpticalFiber"'; $query .= genWhere($wr, $sign); $result = PQuery($query); loggingIs(3, 'OpticalFiber', '', $wr['id']); return $result; }
function getNodeFibers($nodeId, $OFJ_id = -1, $CableLine = -1, $tmpT = FALSE) { $wr['NetworkNode'] = $nodeId; if ($OFJ_id != -1) { $wr['OFJ.id'] = $OFJ_id; } if ($CableLine != -1) { $wr['CableLine'] = $CableLine; } $query = 'SELECT "OFJ".id AS "OFJ_id", "OpticalFiber", "OpticalFiberSplice", "OF"."CableLine", "OF".fiber, "OFS"."FiberSpliceOrganizer", round("OFS".attenuation / 100.0, 2) AS attenuation, "OFS".note FROM "' . tmpTable('OpticalFiberJoin', $tmpT) . '" AS "OFJ" LEFT JOIN "' . tmpTable('OpticalFiber', $tmpT) . '" AS "OF" ON "OF".id = "OFJ"."OpticalFiber" LEFT JOIN "' . tmpTable('OpticalFiberSplice', $tmpT) . '" AS "OFS" ON "OFS".id = "OFJ"."OpticalFiberSplice"' . genWhere($wr) . ' ORDER BY "OFJ"."OpticalFiberSplice"'; $result = PQuery($query); return $result; }
function loggingIs($type, $tableName, $values, $record) { $normalTable = $tableName; $action = ''; if (strpos($tableName, "_tmp") !== FALSE) { $normalTable = substr($tableName, 0, strpos($tableName, "_tmp")); } if ($type != 3) { foreach ($values as $field => $value) { $action .= pg_escape_string(' "' . $field . '"=>\'' . $value . '\''); } } $user_res = getCurrUserInfo(); $user = $user_res['rows'][0]['id']; if ($user == "") { $user = 1; } $res = PQuery('SELECT id FROM "LogTableList" WHERE "name"=\'' . $normalTable . '\''); if ($res['count']) { return 0; } $tableId = $res['rows'][0]['id']; if ($type == 1) { $action = 'UPDATED:' . $action; } elseif ($type == 2) { $action = 'ADDED:' . $action; $wr = genWhere($values); $query = 'SELECT * FROM "' . pg_escape_string($tableName) . '"' . $wr; $res = PQuery($query); $record = $res['rows'][0]['id']; } elseif ($type == 3) { $action = 'DELETED'; } if (!$record || $record == '') { $record = 'NULL'; } $query = 'INSERT INTO "LogAdminActions" ("table", "record", "time", "action", "admin") VALUES (' . pg_escape_string($tableId) . ', ' . pg_escape_string($record) . ', NOW(), \'' . $action . '\', ' . pg_escape_string($user) . ')'; $res = PQuery($query); return 1; }
function finishMapSession($userId = -1) { if ($userId == -1) { $user_res = getCurrUserInfo(); $user = $user_res['rows'][0]['id']; } else { $user = $userId; } $wr['UserId'] = $user; $query = 'UPDATE "MapSessions" SET "LastAction" = "LastAction" - INTERVAL \'30 MINUTES\' ' . genWhere($wr); PQuery($query); }
function getNetworkBoxList($sort, $wr, $linesPerPage = -1, $skip = -1) { $query = 'SELECT "NB".id, "NB"."NetworkBoxType", "NB"."inventoryNumber", "NBT"."marking", "NN"."name" AS "NNname", "NN".id AS "NNid" FROM "NetworkBox" AS "NB"'; $query .= ' LEFT JOIN "NetworkBoxType" AS "NBT" ON "NBT".id="NB"."NetworkBoxType"'; $query .= ' LEFT JOIN "NetworkNode" AS "NN" ON "NN"."NetworkBox"="NB".id'; $where = ''; if ($wr != '') { $where = genWhere($wr); } $query .= $where . ' ORDER BY "inventoryNumber"'; if ($sort == 1) { $query .= ' ORDER BY "NB"."inventoryNumber" '; } if ($linesPerPage > 0 and $skip >= 0) { $query .= ' LIMIT ' . $linesPerPage . ' OFFSET ' . $skip; } $result = PQuery($query); $query = 'SELECT COUNT(*) AS "count" FROM "NetworkBox"' . $where; $res = PQuery($query); $result['allPages'] = $res['rows'][0]['count']; return $result; }
function FSOT_DELETE($wr) { $query = 'DELETE FROM "FiberSpliceOrganizerType"'; $query .= genWhere($wr); $result = PQuery($query); loggingIs(3, 'FiberSpliceOrganizerType', '', $wr['id']); return $result; }
function getCableLinePoints($cableLine, $onlyFree = FALSE, $tmpT = FALSE) { $wr['CableLine'] = $cableLine; $query = 'SELECT "clp".id, "clp"."OpenGIS", "clp"."meterSign", "clp"."note", "clp"."sequence", "NN"."OpenGIS" AS "NNOpenGIS" FROM "' . tmpTable('CableLinePoint', $tmpT) . '" AS "clp" LEFT JOIN "' . tmpTable('NetworkNode', $tmpT) . '" AS "NN" ON "NN".id = "clp"."NetworkNode"' . genWhere($wr); if ($onlyFree) { $query .= ' AND "clp"."OpenGIS" IS NOT NULL'; } $query .= ' ORDER BY "sequence"'; $result = PQuery($query); return $result; }