diff --git a/extdbms/lib/Controllers/CommonController.php b/extdbms/lib/Controllers/CommonController.php
index 4dfc2dd..810b6d3 100644
--- a/extdbms/lib/Controllers/CommonController.php
+++ b/extdbms/lib/Controllers/CommonController.php
@@ -3,8 +3,6 @@
namespace lib\Controllers;
use lib\Core\Controller as Core;
-use lib\Models\ClientModel;
-use lib\Models\ServiceModel;
class CommonController extends Core
{
diff --git a/extdbms/lib/Controllers/DBMS/Client/CouponController.php b/extdbms/lib/Controllers/DBMS/Client/CouponController.php
index 5545c0a..522fb85 100644
--- a/extdbms/lib/Controllers/DBMS/Client/CouponController.php
+++ b/extdbms/lib/Controllers/DBMS/Client/CouponController.php
@@ -21,10 +21,11 @@ class CouponController extends ClientController
return $this->_memberService;
}
//IdcCouponUseMK.jsp -> domain_coupon_use.php
- //CLI 접속방법 : php index.php site/client/counpon
- //WEB 접속방법 : http://localhost/site/client/coupon
+ //CLI 접속방법 : php index.php site/client/counpon/index
+ //WEB 접속방법 : http://localhost/site/client/coupon/index
public function index(array $params)
{
+ //사용자정보
if (!array_key_exists('client_code', $params)) {
throw new \Exception("client_code 값이 정의되지 않았습니다.");
}
@@ -35,7 +36,10 @@ class CouponController extends ClientController
}
$this->client = $client;
//전체 관리자정보(등록자)
- $member_code = $params['member_code'];
+ if (!array_key_exists('mkid', $params)) {
+ throw new \Exception("mkid 값이 정의되지 않았습니다.");
+ }
+ $member_code = $params['mkid'];
$member = $this->getMemberService()->getEntityByCode($member_code);
if (!$member) {
throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
@@ -48,8 +52,8 @@ class CouponController extends ClientController
$this->getServiceService()->getModel()->setContinue(true);
$this->total = $this->getServiceService()->getCount();
//limit, offset 설정
- $this->curPage = intval($params['curPage'] ?? $this->getRequest()->get('curPage') ?? 1);
- $this->perPage = intval($params['perPage'] ?? $this->getRequest()->get('perPage') ?? VIEW_LIST_PERPAGE);
+ $this->curPage = intval($params['curPage'] ?? $this->request->get('curPage') ?? 1);
+ $this->perPage = intval($params['perPage'] ?? $this->request->get('perPage') ?? VIEW_LIST_PERPAGE);
$this->getServiceService()->getModel()->limit($this->perPage);
$this->getServiceService()->getModel()->offset(($this->curPage - 1) * $this->perPage);
$this->services = $this->getServiceService()->getEntities();
@@ -61,4 +65,106 @@ class CouponController extends ClientController
$this->total_coupon = $total_coupon;
return $this->render(__FUNCTION__);
}
+ //IdcCouponBuyMK.jsp -> domain_coupon_buy.php
+ //CLI 접속방법 : php index.php site/client/counpon/insert_form
+ //WEB 접속방법 : http://localhost/site/client/coupon/insert_form
+ public function insert_form(array $params)
+ {
+ if (!array_key_exists('service_code', $params)) {
+ throw new \Exception("service_code 값이 정의되지 않았습니다.");
+ }
+ $service_code = $params['service_code'];
+ $service = $this->getServiceService()->getEntityByCode($service_code);
+ if (!$service) {
+ throw new \Exception("[$service_code]에 해당하는 서비스정보가 존재하지 않습니다.");
+ }
+ $this->service = $service;
+ //사용자정보
+ $client = $this->getClientService()->getEntityByCode($service->getClientCode());
+ if (!$client) {
+ throw new \Exception("[{$service->getClientCode()}]에 해당하는 사용자정보가 존재하지 않습니다.");
+ }
+ $this->client = $client;
+ //전체 관리자정보(등록자)
+ if (!array_key_exists('mkid', $params)) {
+ throw new \Exception("mkid 값이 정의되지 않았습니다.");
+ }
+ $member_code = $params['mkid'];
+ $member = $this->getMemberService()->getEntityByCode($member_code);
+ if (!$member) {
+ throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
+ }
+ $this->member = $member;
+ //쿠폰내역
+ $this->getServiceService()->getModel()->where("client_code", $client_code);
+ $this->getServiceService()->getModel()->whereNotIn("service_line", ['vpn', 'test', 'soloLine', 'substitution']);
+ //Query문 Rest여부 -> 같은조건에 Count 받고, 결과값을 받고 싶을때는 continue()
+ $this->getServiceService()->getModel()->setContinue(true);
+ $this->total = $this->getServiceService()->getCount();
+ //limit, offset 설정
+ $this->curPage = intval($params['curPage'] ?? $this->request->get('curPage') ?? 1);
+ $this->perPage = intval($params['perPage'] ?? $this->request->get('perPage') ?? VIEW_LIST_PERPAGE);
+ $this->getServiceService()->getModel()->limit($this->perPage);
+ $this->getServiceService()->getModel()->offset(($this->curPage - 1) * $this->perPage);
+ $this->services = $this->getServiceService()->getEntities();
+ $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
+ $total_coupon = 0;
+ foreach ($this->services as $service) {
+ $total_coupon += $service->getCoupon();
+ }
+ $this->total_coupon = $total_coupon;
+ return $this->render(__FUNCTION__);
+ }
+
+ //IdcCouponBuyMK.jsp -> domain_coupon_buy.php
+ //CLI 접속방법 : php index.php site/client/counpon/insert_form
+ //WEB 접속방법 : http://localhost/site/client/coupon/insert_form
+ public function insert(array $params)
+ {
+ if (!array_key_exists('service_code', $params)) {
+ throw new \Exception("service_code 값이 정의되지 않았습니다.");
+ }
+ $service_code = $params['service_code'];
+ $service = $this->getServiceService()->getEntityByCode($service_code);
+ if (!$service) {
+ throw new \Exception("[$service_code]에 해당하는 서비스정보가 존재하지 않습니다.");
+ }
+ $this->service = $service;
+ //사용자정보
+ $client = $this->getClientService()->getEntityByCode($service->getClientCode());
+ if (!$client) {
+ throw new \Exception("[{$service->getClientCode()}]에 해당하는 사용자정보가 존재하지 않습니다.");
+ }
+ $this->client = $client;
+ //전체 관리자정보(등록자)
+ if (!array_key_exists('mkid', $params)) {
+ throw new \Exception("mkid 값이 정의되지 않았습니다.");
+ }
+ $member_code = $params['mkid'];
+ $member = $this->getMemberService()->getEntityByCode($member_code);
+ if (!$member) {
+ throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
+ }
+ $this->member = $member;
+ try {
+ $this->getServiceService()->getModel()->setTransaction(true);
+ //서비스 수정
+ $this->getServiceService()->getModel()->where("client_code", $client_code);
+ $this->getServiceService()->update();
+ // $coupon_query = "update servicedb set coupon=(coupon-$_GET[onetime_sub]), coupon_use=(coupon_use+$_GET[onetime_sub]) where service_code='$_GET[service_code]'";
+ // @mysql_query($coupon_query, $db_connect) or die($db_i_error);
+
+ // $onetime_query = "INSERT INTO `onetimedb` (`client_code`, `service_code`, `onetime_case`, `onetime_sub`, `onetime_amount`, `onetime_payment`, `onetime_nonpayment`, `onetime_accountStatus`, `onetime_request_date`, `onetime_payment_date`, `onetime_note`, `onetime_handle_date`, `onetime_manager`, `client_name`, `server_code`) VALUES ('$_GET[client_code]', '$_GET[service_code]', 'domain', '$_GET[onetime_sub]', '0', '0', '0', 'complete', '$_GET[onetime_request_date]', '$_GET[onetime_request_date]', '도메인 쿠폰사용 / $_GET[onetime_note]', '$_GET[onetime_request_date]', '$_GET[mkid]', '$member[name]', '$service[server_code]')";
+ // @mysql_query($onetime_query, $db_connect) or die($db_i_error);
+
+ // $history_query = "INSERT INTO `historydb` (`service_code`, `server_code`, `behavior_case`, `behavior`, `behavior_date`, `note`, `client_name`) VALUES ('$_GET[service_code]', '$service[server_code]', '도메인 쿠폰 구매 / $_GET[onetime_sub] 개', '도메인 쿠폰 구매', '$_GET[onetime_request_date]', '$member[name]', '$service[Client_Name]')";
+ // @mysql_query($history_query, $db_connect) or die($db_i_error);
+ $this->getServiceService()->getModel()->commit();
+ return $this->render(__FUNCTION__);
+ } catch (\PDOException $e) {
+ $this->getServiceService()->getModel()->rollback();
+ echo $e->getMessage();
+ return $this->redirect->back()->withInput()->with('error', ['message' => '쿠폰 사용에 실패하였습니다.']);
+ }
+ }
} //Class
diff --git a/extdbms/lib/Controllers/DBMS/Client/PaymentController.php b/extdbms/lib/Controllers/DBMS/Client/PaymentController.php
index 8c7100e..47042be 100644
--- a/extdbms/lib/Controllers/DBMS/Client/PaymentController.php
+++ b/extdbms/lib/Controllers/DBMS/Client/PaymentController.php
@@ -50,7 +50,7 @@ class PaymentController extends ClientController
$exclude_clients = ['C116', 'C219'];
//mode 당일,1일전,2일전,3일전,custom
$today = date("Y-m-d");;
- $mode = $params['mode'] ?? $this->getRequest()->get('mode') ?? 'all';
+ $mode = $params['mode'] ?? $this->request->get('mode') ?? 'all';
switch ($mode) {
case 'today':
$this->getServiceService()->getModel()->where("service_payment_date = CURDATE()");
@@ -89,8 +89,8 @@ class PaymentController extends ClientController
$this->getServiceService()->getModel()->setContinue(true);
$this->total = $this->getServiceService()->getCount();
//limit, offset 설정
- $this->curPage = intval($params['curPage'] ?? $this->getRequest()->get('curPage') ?? 1);
- $this->perPage = intval($params['perPage'] ?? $this->getRequest()->get('perPage') ?? VIEW_LIST_PERPAGE);
+ $this->curPage = intval($params['curPage'] ?? $this->request->get('curPage') ?? 1);
+ $this->perPage = intval($params['perPage'] ?? $this->request->get('perPage') ?? VIEW_LIST_PERPAGE);
$this->getServiceService()->getModel()->limit($this->perPage);
$this->getServiceService()->getModel()->offset(($this->curPage - 1) * $this->perPage);
$this->entities = $this->getServiceService()->getEntities();
diff --git a/extdbms/lib/Core/Controller.php b/extdbms/lib/Core/Controller.php
index 6ab13ad..6e05675 100644
--- a/extdbms/lib/Core/Controller.php
+++ b/extdbms/lib/Core/Controller.php
@@ -5,13 +5,25 @@ namespace lib\Core;
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Configs' . DIRECTORY_SEPARATOR . 'Constant.php';
use lib\Configs\View;
+use lib\Http\Redirect;
use lib\Http\Request;
+use lib\Http\Session;
+use Lib\Http\Url;
abstract class Controller
{
private ?View $_view = null;
- private ?Request $_request = null;
- protected function __construct() {} //
+ final protected ?Url $url = null;
+ final protected ?Session $session = null;
+ final protected ?Redirect $redirect = null;
+ final protected ?Request $request = null;
+ protected function __construct()
+ {
+ $this->url = new Url();
+ $this->session = new Session();
+ $this->redirect = new Redirect($this->session);
+ $this->request = new Request();
+ } //
final public function __get($name)
{
return $this->getView()->$name;
@@ -31,11 +43,4 @@ abstract class Controller
{
return $this->getView()->render($path);
}
- final public function getRequest(): Request
- {
- if ($this->_request === null) {
- $this->_request = new Request();
- }
- return $this->_request;
- }
} //Class
diff --git a/extdbms/lib/Database/QueryBuilder.php b/extdbms/lib/Database/QueryBuilder.php
index 621cb0e..95b2489 100644
--- a/extdbms/lib/Database/QueryBuilder.php
+++ b/extdbms/lib/Database/QueryBuilder.php
@@ -306,7 +306,10 @@ class QueryBuilder
foreach ($data as $col => $val) {
$stmt->bindValue(':' . $col, $val);
}
- return $stmt->execute();
+ if ($stmt->execute()) {
+ return (int)$this->pdo->lastInsertId();
+ }
+ return false;
}
final public function update(array $data): bool
diff --git a/extdbms/lib/Http/Redirect.php b/extdbms/lib/Http/Redirect.php
new file mode 100644
index 0000000..fff3b59
--- /dev/null
+++ b/extdbms/lib/Http/Redirect.php
@@ -0,0 +1,52 @@
+session = $session;
+ }
+
+ // 리다이렉트할 때 캐시를 방지하는 헤더 추가
+ private function noCacheHeaders(): void
+ {
+ header("Cache-Control: no-cache, no-store, must-revalidate");
+ header("Pragma: no-cache");
+ header("Expires: 0");
+ }
+
+ // 이전 페이지로 리다이렉트 (캐시 방지)
+ public function back(): self
+ {
+ $this->noCacheHeaders(); // 캐시 방지
+ $backUrl = $_SERVER['HTTP_REFERER'] ?? '/';
+ header("Location: {$backUrl}");
+ return $this;
+ }
+
+ // 특정 URL로 리다이렉트 (캐시 방지)
+ public function to(string $url): self
+ {
+ $this->noCacheHeaders(); // 캐시 방지
+ header("Location: {$url}");
+ return $this;;
+ }
+
+ // 세션에 값 추가 후 리다이렉트
+ public function withInput(): self
+ {
+ $this->session->flashInput($_POST);
+ return $this;
+ }
+
+ // 세션에 에러 메시지 저장 후 리다이렉트
+ public function with(string $key, mixed $value): self
+ {
+ $this->session->flash($key, $value);
+ return $this;
+ }
+}
diff --git a/extdbms/lib/Http/Session.php b/extdbms/lib/Http/Session.php
index b2628f2..cbf756a 100644
--- a/extdbms/lib/Http/Session.php
+++ b/extdbms/lib/Http/Session.php
@@ -7,8 +7,10 @@ class Session extends Http
public function __construct()
{
parent::__construct();
+ $this->start();
}
+ // 세션 시작
public function start(): void
{
if (session_status() === PHP_SESSION_NONE) {
@@ -16,23 +18,51 @@ class Session extends Http
}
}
- public function get(string $key, $default = null): mixed
- {
- return $_SESSION[$key] ?? $default;
- }
-
+ // 세션에 값 저장
public function set(string $key, $value): void
{
$_SESSION[$key] = $value;
}
+ // 세션에서 값 가져오기
+ public function get(string $key): mixed
+ {
+ return $_SESSION[$key] ?? null;
+ }
+
+ // 세션에서 값 삭제
public function remove(string $key): void
{
unset($_SESSION[$key]);
}
- public function destroy(): void
+ // 세션에 에러 메시지 설정
+ public function flash(string $key, $message): void
{
- session_destroy();
+ $_SESSION['flash'][$key] = $message;
+ }
+
+ // 세션에 입력값 설정 (입력값 유지)
+ public function flashInput(array $input): void
+ {
+ $_SESSION['flash']['input'] = $input;
+ }
+
+ // 세션에 flash 메시지가 있는지 확인
+ public function hasFlash(string $key): bool
+ {
+ return isset($_SESSION['flash'][$key]);
+ }
+
+ // flash 메시지 가져오기
+ public function getFlash(string $key): mixed
+ {
+ return $_SESSION['flash'][$key] ?? null;
+ }
+
+ // flash 메시지 삭제
+ public function clearFlash(): void
+ {
+ unset($_SESSION['flash']);
}
}
diff --git a/extdbms/lib/Http/Url.php b/extdbms/lib/Http/Url.php
new file mode 100644
index 0000000..d98fc12
--- /dev/null
+++ b/extdbms/lib/Http/Url.php
@@ -0,0 +1,66 @@
+
+
+namespace Lib\Http;
+
+class Url extends Http
+{
+ protected string $baseUrl;
+ protected string $uri;
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->baseUrl = $this->detectBaseUrl();
+ $this->uri = $this->detectUri();
+ }
+
+ // 현재 전체 URL 반환
+ public function current(): string
+ {
+ return $this->baseUrl . '/' . ltrim($this->uri, '/');
+ }
+
+ // base URL만 반환
+ public function baseURL(): string
+ {
+ return $this->baseUrl;
+ }
+
+ // 세그먼트 배열 반환
+ public function segments(): array
+ {
+ return explode('/', trim($this->uri, '/'));
+ }
+
+ // N번째 세그먼트 반환 (1부터 시작)
+ public function segment(int $n): ?string
+ {
+ $segments = $this->segments();
+ return $segments[$n - 1] ?? null;
+ }
+
+ // 특정 경로에 대한 URL 생성
+ public function to(string $path): string
+ {
+ return rtrim($this->baseUrl, '/') . '/' . ltrim($path, '/');
+ }
+
+ // URI 추출 (도메인 제외)
+ protected function detectUri(): string
+ {
+ $uri = $_SERVER['REQUEST_URI'] ?? '/';
+ $scriptName = dirname($_SERVER['SCRIPT_NAME'] ?? '');
+ $uri = str_replace($scriptName, '', $uri);
+ $uri = strtok($uri, '?'); // 쿼리 스트링 제거
+ return $uri;
+ }
+
+ // base URL 추출
+ protected function detectBaseUrl(): string
+ {
+ $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
+ $host = $_SERVER['HTTP_HOST'] ?? 'localhost';
+ $scriptDir = rtrim(dirname($_SERVER['SCRIPT_NAME'] ?? ''), '/');
+ return $scheme . '://' . $host . $scriptDir;
+ }
+}
diff --git a/extdbms/lib/Services/CommonService.php b/extdbms/lib/Services/CommonService.php
index ba40fdc..87f8b33 100644
--- a/extdbms/lib/Services/CommonService.php
+++ b/extdbms/lib/Services/CommonService.php
@@ -48,4 +48,13 @@ abstract class CommonService extends Core
// echo "
" . $this->getModel()->getLastQuery();
return $count;
}
+
+ public function insert(array $formData): int
+ {
+ $insertId = $this->getModel()->insert($formData);
+ if (!$insertId) {
+ throw new \Exception("Insert Error : " . $this->getModel()->getLastError());
+ }
+ return $insertId;
+ } //
} //Class
diff --git a/extdbms/lib/Views/dbms/client/coupon/index.php b/extdbms/lib/Views/dbms/client/coupon/index.php
index e34893d..4e313e4 100644
--- a/extdbms/lib/Views/dbms/client/coupon/index.php
+++ b/extdbms/lib/Views/dbms/client/coupon/index.php
@@ -24,7 +24,7 @@