diff --git a/extdbms/defense_index.php b/extdbms/defense_index.php
index c37a47c..3e93547 100644
--- a/extdbms/defense_index.php
+++ b/extdbms/defense_index.php
@@ -5,58 +5,136 @@ require_once 'function.php';
require_once 'lib.php';
?>
-
$zonequery = "select * from defensemk where depth = '1' order by idx asc";
$zoneresult = @mysql_query($zonequery, $db_connect) or die($db_q_error);
$zone_num = mysql_num_rows($zoneresult);
?>
-
-for ($i = 0; $i < $zone_num; $i++) {
- $zonedata = mysql_fetch_assoc($zoneresult);
+
+ for ($i = 0; $i < $zone_num; $i++) {
+ $zonedata = mysql_fetch_assoc($zoneresult);
?>
-
=$zonedata[zone]?>
+
= $zonedata[zone] ?>
-}?>
+ } ?>
@@ -65,50 +143,51 @@ $parentsresult = @mysql_query($parentsquery, $db_connect) or die($db_q_error);
$parents_num = mysql_num_rows($parentsresult);
for ($j = 0; $j < $parents_num; $j++) {
$parentsdata = mysql_fetch_assoc($parentsresult);
- ?>
-
- =$parentsdata[parents]?> / =$parentsdata[real_address]?>
-
-
-
+?>
+
+ = $parentsdata[parents] ?> / = $parentsdata[real_address] ?>
+
+
+
$childquery = "select * from defensemk where depth = '3' and zone = '" . $_GET['zone'] . "' and parents = '" . $parentsdata[parents] . "' order by parents asc";
$childresult = @mysql_query($childquery, $db_connect) or die($db_q_error);
$child_num = mysql_num_rows($childresult);
?>
-
+
for ($k = 0; $k < $child_num; $k++) {
$childdata = mysql_fetch_assoc($childresult);
$childidx = $childdata[idx];
- ?>
-
- =$childdata[child] . " / " . $childdata[cs_code] . " / " . $childdata[cs_ip] . " / " . $childdata[server_code] . " / " . $childdata[server_ip] . " / " . $childdata[setup_domain] . " / " . $childdata[setup_firewall] . " / " . $childdata[register_date] . " / " . $childdata[worker]?> - >수정
-
-}?>
-
-}?>
+ } ?>
//DB닫기
mysql_close($db_connect);
-?>
+?>
\ No newline at end of file
diff --git a/extdbms/lib/Controllers/DBMS/DefenceController.php b/extdbms/lib/Controllers/DBMS/DefenceController.php
new file mode 100644
index 0000000..8d987c2
--- /dev/null
+++ b/extdbms/lib/Controllers/DBMS/DefenceController.php
@@ -0,0 +1,32 @@
+getView()->setPath('defence');
+ } //
+ public function getDefenceService(): DefenceService
+ {
+ if ($this->_clientService === null) {
+ $this->_clientService = new DefenceService();
+ }
+ return $this->_clientService;
+ }
+
+ //방어 defense_index.php
+ //CLI 접속방법 : php index.php site/defence/mk/zone/존/parent/부모키/child/자식키
+ //WEB 접속방법 : http://localhostsite/defence/mk/zone/존/parent/부모키/child/자식키
+ public function mk(): string
+ {
+ $this->request = $this->getRequest();
+ $this->entities = $this->getDefenceService()->getMKList($this->getRequest('zone'));
+ return $this->render(__FUNCTION__);
+ }
+} //Class
diff --git a/extdbms/lib/Controllers/DBMS/NavigatorController.php b/extdbms/lib/Controllers/DBMS/NavigatorController.php
index e744952..b66bfb0 100644
--- a/extdbms/lib/Controllers/DBMS/NavigatorController.php
+++ b/extdbms/lib/Controllers/DBMS/NavigatorController.php
@@ -30,7 +30,7 @@ class NavigatorController extends BaseController
{
//전체 고객정보
$this->clients = $this->getClientService()->getEntities();
- $ip = $this->getRequest('ip');
+ $ip = $this->getRequest('ip') ?? '';
//IP형식이 ipv4인지 확인 후 값가져오기
$services = [];
if ($ip && $this->helper->isIPAddress($ip)) {
diff --git a/extdbms/lib/Core/Controller.php b/extdbms/lib/Core/Controller.php
index b8f4e8a..1f0a268 100644
--- a/extdbms/lib/Core/Controller.php
+++ b/extdbms/lib/Core/Controller.php
@@ -38,15 +38,27 @@ abstract class Controller
}
return array_key_exists($key, $this->_segments) ? $this->_segments[$key] : null;
}
- final public function getRequest(mixed $key = null, string $method = "GET"): mixed
+ final public function getRequest(mixed $key = null, mixed $method = null): mixed
{
- $requestDatas = $method === "POST" ? $_POST : $_GET;
- $result = null;
- if (!$key)
- $result = $requestDatas;
- else
- $result = array_key_exists($key, $requestDatas) ? $requestDatas[$key] : null;
- return $result;
+ if ($this->_request === null) {
+ $this->_request = match (strtoupper($method)) {
+ "POST" => $_POST,
+ "GET" => $_GET,
+ default => $_REQUEST,
+ };
+ }
+ if ($key === null) {
+ return $this->_request;
+ }
+ return array_key_exists($key, $this->_request) ? $this->_request[$key] : null;
+ }
+ final public function getPost(mixed $key = null): mixed
+ {
+ return $this->getRequest($key, "POST");
+ }
+ final public function getGet(mixed $key = null): mixed
+ {
+ return $this->getRequest($key, "GET");
}
public function render(string $path)
{
diff --git a/extdbms/lib/Core/Model.php b/extdbms/lib/Core/Model.php
index 961b340..45ec5d2 100644
--- a/extdbms/lib/Core/Model.php
+++ b/extdbms/lib/Core/Model.php
@@ -11,12 +11,12 @@ abstract class Model
private $_db = null;
private $_debug = false;
private $_reset = true;
- private $_querys = [];
+ private $_querys = ['SELECT' => 'SELECT *', 'JOIN' => [], 'ORDERBY' => [], 'LIMIT' => ''];
private $_wheres = [];
private $_lastQuery = "";
protected function __construct()
{
- $this->reset();
+ $this->init();
} //
abstract public function getTable(): string;
abstract public function getPKField(): string;
@@ -39,7 +39,7 @@ abstract class Model
throw new \Exception("❌ DB 연결 실패: " . $e->getMessage());
}
}
- $this->reset();
+ $this->init();
return $this->_db;
}
final public function setDebug($debug)
@@ -50,48 +50,56 @@ abstract class Model
{
return $this->_debug;
}
- private function reset(): void
+ private function init(): void
{
$debug = $_ENV['DATABASE_QUERY_DEBUG'] ?? $_SERVER['DATABASE_QUERY_DEBUG'] ?? 'false';
if ($debug === "true") {
$this->_debug = true;
}
+ $this->_reset = true;
+ $this->_querys = ['SELECT' => 'SELECT *', 'JOIN' => [], 'ORDERBY' => [], 'LIMIT' => ''];
$this->_wheres = [];
- $this->_querys = ["SELECT" => "SELECT *", "JOIN" => "", "ORDERBY" => "", "LIMIT" => ""];
+ $this->_lastQuery = "";
}
final public function getLastQuery(): string
{
return $this->_lastQuery;
}
- private function makeValue(mixed $values): string|null
+
+ //Where절관련
+ private function getWhereValue(mixed $datas, $delimeter = ","): string
{
- if ($values === null) {
- return $values;
+ $value = "";
+ if ($datas === null) {
+ return "NULL";
}
- $temps = [];
- if (is_array($values)) {
- foreach ($values as $value) {
- $temps[] = is_string($value) ? "'{$value}'" : $value;
+ if (is_array($datas)) {
+ $temps = [];
+ foreach ($datas as $data) {
+ $data = trim($data);
+ $temps[] = is_string($data) ? "'{$data}'" : $data;
}
+ $value = implode($delimeter, $temps);
} else {
- $temps[] = is_string($values) ? "'{$values}'" : $values;
+ $value = is_string($datas) ? "'{$datas}'" : $datas;
}
- return implode(",", $temps);
+ return $value;
}
- final public function makeWhere(mixed $columns, mixed $values = null, $delimeter = ","): string
+ private function getWhereColumn(mixed $columns, mixed $datas = null): string
{
$temps = [];
if (is_array($columns)) {
- foreach ($columns as $column => $value) {
- $value = $this->makeValue($value);
- $temps[] = sprintf("%s%s", $column, $value === null ? "" : "=" . $value);
+ //복합배열형태로 들어온 경우
+ foreach ($columns as $column => $data) {
+ $value = $this->getWhereValue($data);
+ $temps[] = "{$column}={$value}";
}
} else {
- $value = $this->makeValue($values);
- $temps[] = sprintf("%s%s", $columns, $value === null ? "" : "=" . $value);
+ $value = $this->getWhereValue($datas);
+ $temps[] = "{$columns}={$value}";
}
// throw new \Exception("DATA:" . $columns . $value === null ? "NULL" : $value);
- return implode($delimeter . " ", $temps);
+ return implode(" ", $temps);
}
final public function getWhere(): string
{
@@ -100,23 +108,14 @@ abstract class Model
final public function where(mixed $columns, mixed $values = null, string $delimeter = "AND"): void
{
- $query = $this->makeWhere($columns, $values, $delimeter);
+ $query = $this->getWhereColumn($columns, $values);
$this->_wheres[] = count($this->_wheres) ? $delimeter . " " . $query : $query;
}
final public function orWhere(mixed $columns, mixed $values = null, string $delimeter = "OR"): void
{
$this->where($columns, $values, $delimeter);
}
- final public function whereIn(string $column, array $values, string $delimeter = "AND", $range = "IN")
- {
- $query = " {$column} {$range} (" . $this->makeValue($values) . ")";
- $this->_wheres[] = count($this->_wheres) ? $delimeter . " " . $query : $query;
- }
- final public function whereNotIn(string $column, array $values, string $delimeter = "AND", $range = "NOT IN")
- {
- $this->whereIn($column, $values, $delimeter, $range);
- }
- final public function like(string $column, string $value, string $option = "both"): void
+ final public function whereLike(string $column, string $value, string $option = "both", string $delimeter = "AND"): void
{
switch ($option) {
case 'before':
@@ -129,7 +128,20 @@ abstract class Model
$value = "%{$value}%";
break;
}
- $this->_wheres[] = "{$column} LIKE '{$value}'";
+ $this->where("{$column} LIKE '{$value}'", null, $delimeter);
+ }
+ final public function orWhereLike(string $column, string $value, string $option = "both", string $delimeter = "OR"): void
+ {
+ $this->whereLike($column, $value, $option, $delimeter);
+ }
+ final public function whereIn(string $column, array $values, string $delimeter = "AND", $range = "IN")
+ {
+ $query = " {$column} {$range} (" . $this->getWhereValue($values) . ")";
+ $this->_wheres[] = count($this->_wheres) ? $delimeter . " " . $query : $query;
+ }
+ final public function whereNotIn(string $column, array $values, string $delimeter = "AND", $range = "NOT IN")
+ {
+ $this->whereIn($column, $values, $delimeter, $range);
}
final public function execute(string $query): bool|PDOStatement
@@ -141,7 +153,7 @@ abstract class Model
$stmt = $this->getConnect()->prepare($query);
$stmt->execute();
if ($this->_reset) {
- $this->reset();
+ $this->init();
}
return $stmt;
}
@@ -149,12 +161,12 @@ abstract class Model
//CURD문
final protected function create_process(mixed $columns, mixed $values = null): bool|PDOStatement
{
- $query = sprintf("INSERT INTO %s VALUES(%s) %s", $this->getTable(), $this->makeWhere($columns, $values), $this->getWhere());
+ $query = sprintf("INSERT INTO %s VALUES(%s) %s", $this->getTable(), $this->getWhereColumn($columns, $values), $this->getWhere());
return $this->execute($query);
} //
final protected function modify_process(mixed $columns, mixed $values = null): bool|PDOStatement
{
- $query = sprintf("UPDATE %s SET %s %s", $this->getTable(), $this->makeWhere($columns, $values), $this->getWhere());
+ $query = sprintf("UPDATE %s SET %s %s", $this->getTable(), $this->getWhereColumn($columns, $values), $this->getWhere());
return $this->execute($query);
} //
final protected function delete_process(): bool|PDOStatement
@@ -164,16 +176,25 @@ abstract class Model
} //
public function select(mixed $columns = "*"): void
{
- $columns = is_array($columns) ? implode(",", $columns) : $columns;
+ $columns = is_array($columns) ? implode(",", $columns) : $columns;
$this->_querys["SELECT"] = "SELECT {$columns}";
}
- final public function join(string $table, mixed $match = null, $type = ""): void
+ //join_type : LEFT, RIGHT, INNER, OUTER
+ final public function join(string $table, mixed $match = null, $join_type = ""): void
{
- $this->_querys["JOIN"] = " {$type} JOIN {$table} ON {$match}";
+ $this->_querys['JOIN'][] = " {$join_type} JOIN {$table} ON {$match}";
}
- final public function orderBy(string $column, string $direction = "DESC"): void
+ final public function orderBy(mixed $columns, string $default_direction = ""): void
{
- $this->_querys["ORDERBY"] = " ORDER BY {$column} {$direction}";
+ $orderBy = "";
+ if (is_array($columns)) {
+ foreach ($columns as $column => $direction) {
+ $this->orderBy($column, $direction ?? $default_direction);
+ }
+ } else {
+ $columns = "{$columns} {$default_direction}";
+ }
+ $this->_querys['ORDERBY'][] = $orderBy;
}
final public function limit(int $start, int $offset = 0): void
{
@@ -182,24 +203,27 @@ abstract class Model
}
//Result
- private function makeResultQuery(string $head, string $tail = ""): string
+ private function getResultQuery(string $head, string $tail = ""): string
{
- return "{$head} FROM {$this->getTable()} {$this->_querys['JOIN']} {$this->getWhere()} {$tail}";
+ $join = count($this->_querys['JOIN']) ? implode(",", $this->_querys['JOIN']) : "";
+ $where = $this->getWhere();
+ $orderby = count($this->_querys['ORDERBY']) ? implode(",", $this->_querys['ORDERBY']) : "";
+ return "{$head} FROM {$this->getTable()} {$join} {$where} {$tail} {$orderby} {$this->_querys['LIMIT']}";
}
public function getResult($mode = PDO::FETCH_ASSOC): mixed
{
- $stmt = $this->execute($this->makeResultQuery($this->_querys['SELECT'], "{$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}"));
+ $stmt = $this->execute($this->getResultQuery($this->_querys['SELECT']));
return $stmt->fetch($mode);
}
public function getResults($mode = PDO::FETCH_ASSOC): mixed
{
- $stmt = $this->execute($this->makeResultQuery($this->_querys['SELECT'], "{$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}"));
+ $stmt = $this->execute($this->getResultQuery($this->_querys['SELECT']));
return $stmt->fetchAll($mode);
}
final public function countAllResults(string $column = "*", $reset = true): int
{
$this->_reset = $reset;
- $stmt = $this->execute($this->makeResultQuery("SELECT COUNT({$column})"));
+ $stmt = $this->execute($this->getResultQuery("SELECT COUNT({$column})"));
$count = $stmt->fetchColumn(0);
$this->_reset = true;
return $count;
diff --git a/extdbms/lib/Entities/DefenceEntity.php b/extdbms/lib/Entities/DefenceEntity.php
new file mode 100644
index 0000000..44cef5d
--- /dev/null
+++ b/extdbms/lib/Entities/DefenceEntity.php
@@ -0,0 +1,34 @@
+getTitle();
+ } //
+ public function getParent(): string
+ {
+ return $this->parents;
+ } //
+ public function getChild(): string
+ {
+ return $this->child;
+ } //
+ public function getRealAddress(): string
+ {
+ return $this->real_address;
+ } //
+} //Class
diff --git a/extdbms/lib/Models/DefenceModel.php b/extdbms/lib/Models/DefenceModel.php
new file mode 100644
index 0000000..2c1dd39
--- /dev/null
+++ b/extdbms/lib/Models/DefenceModel.php
@@ -0,0 +1,17 @@
+getClassName();
+ }
+ public function getModelClass(): string
+ {
+ return Model::class;
+ }
+ public function getEntityClass(): string
+ {
+ return Entity::class;
+ }
+
+ public function getMKList(mixed $zone = null): array
+ {
+ if ($zone !== null) {
+ $this->getModel()->setWhere(['zone' => $zone]);
+ }
+ return $this->getModel()->orderBy(['zone' => 'asc', 'parent' => 'asc', 'child' => 'asc']);
+ }
+}
diff --git a/extdbms/lib/Views/dbms/defence/mk.php b/extdbms/lib/Views/dbms/defence/mk.php
new file mode 100644
index 0000000..b4dd078
--- /dev/null
+++ b/extdbms/lib/Views/dbms/defence/mk.php
@@ -0,0 +1,138 @@
+
+
+
+ getZone() ?>
+ - onclick="location.href=' /DefenseInfoMK.sev?zone== $zone ?>'">= $zone ?>
+
+
+