Commit 14e476b6 authored by Anthony.Suerte's avatar Anthony.Suerte

Advertisement Page Fix [Added Validation and File Deletion]

parent e63e05c0
...@@ -554,6 +554,9 @@ ...@@ -554,6 +554,9 @@
<E_ERROR_UPLOAD_ADMIN_FAILED> <E_ERROR_UPLOAD_ADMIN_FAILED>
アップロード失敗。 もう一度お試しください。 アップロード失敗。 もう一度お試しください。
</E_ERROR_UPLOAD_ADMIN_FAILED> </E_ERROR_UPLOAD_ADMIN_FAILED>
<E_ERROR_UPLOAD_ADMIN_INVALID>
無効なアップロードファイル
</E_ERROR_UPLOAD_ADMIN_INVALID>
<E_ERROR_NO_PAGE_ACCESS> <E_ERROR_NO_PAGE_ACCESS>
あなたは次のページにアクセスするための権限を持っていません。 あなたは次のページにアクセスするための権限を持っていません。
</E_ERROR_NO_PAGE_ACCESS> </E_ERROR_NO_PAGE_ACCESS>
......
...@@ -556,6 +556,9 @@ ...@@ -556,6 +556,9 @@
<E_ERROR_UPLOAD_ADMIN_FAILED> <E_ERROR_UPLOAD_ADMIN_FAILED>
Failed to upload file. Please Try Again Failed to upload file. Please Try Again
</E_ERROR_UPLOAD_ADMIN_FAILED> </E_ERROR_UPLOAD_ADMIN_FAILED>
<E_ERROR_UPLOAD_ADMIN_INVALID>
Uploaded file is invalid.
</E_ERROR_UPLOAD_ADMIN_INVALID>
<E_ERROR_NAME_REQUIRED> <E_ERROR_NAME_REQUIRED>
Name is a mandatory field. Name is a mandatory field.
</E_ERROR_NAME_REQUIRED> </E_ERROR_NAME_REQUIRED>
......
...@@ -22,34 +22,34 @@ class LogicAdvertisements extends AdvertisementModelClass { ...@@ -22,34 +22,34 @@ class LogicAdvertisements extends AdvertisementModelClass {
* @return : TRUE:ロジック成功、FALSE:ロジック失敗 * @return : TRUE:ロジック成功、FALSE:ロジック失敗
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function logic() { function logic() {
try { try {
// 初期データ処理 $this -> init();
if($this -> init()){
$this -> lists();
}elseif($this -> getType() == TYPE_IMAGE_MANAGER_UPLOAD_COMPLETE){ switch($this -> getType()){
if($this -> checkChiket()) { case TYPE_IMAGE_MANAGER_UPLOAD_COMPLETE:
$this -> popUpSessionMessage(INFO, 'I_COMPLATE_SAVE', array()); $this -> insertNewAd();
}
$this -> insertActivity();
$this -> loadImageAds();
$this -> listsImages(); $this -> listsImages();
}elseif($this -> getType() == TYPE_IMAGE_MANAGER || $this -> getType() == TYPE_SEARCH){ break;
case TYPE_IMAGE_MANAGER:
case TYPE_SEARCH:
$this -> listsImages(); $this -> listsImages();
}elseif($this -> getType() == TYPE_IMAGE_MANAGER_DETAIL){ break;
case TYPE_IMAGE_MANAGER_DETAIL:
$this -> selectAdDetails(); $this -> selectAdDetails();
}elseif($this -> getType() == TYPE_UPDATE){ break;
case TYPE_UPDATE:
$this -> insertActivity(); $this -> insertActivity();
$this -> update(); $this -> update();
}elseif($this -> getType() == TYPE_DELETE){ break;
case TYPE_DELETE:
$this -> insertActivity(); $this -> insertActivity();
$this -> deleteAd(); $this -> deleteAd();
$this -> listsImages(); $this -> listsImages();
}else{ break;
default:
$this -> lists(); $this -> lists();
break;
} }
} catch (Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
...@@ -61,15 +61,19 @@ class LogicAdvertisements extends AdvertisementModelClass { ...@@ -61,15 +61,19 @@ class LogicAdvertisements extends AdvertisementModelClass {
* @return : なし * @return : なし
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function lists() { function lists() {
//set variables
//$where = null;
$where = $this -> getWhere(); $where = $this -> getWhere();
//$this -> getWhere();
$this -> setResult($this -> accessSelect('LIST_CLICKED_ADS', $where)); $this -> setResult($this -> accessSelect('LIST_CLICKED_ADS', $where));
} }
function insertNewAd(){
if($this -> loadImageAds()){
$this -> insertActivity();
$this -> accessModify('INSERT_ADS', $this -> getImageAdRegistData());
$this -> popUpSessionMessage(INFO, 'I_COMPLATE_SAVE', array());
}else{
$this -> popUpSessionMessage(ERROR, 'E_ERROR_UPLOAD_ADMIN_INVALID', array());
}
}
function listsImages() { function listsImages() {
$this -> setImages($this -> accessSelect('LIST_IMAGES', $this -> getWhereAds())); $this -> setImages($this -> accessSelect('LIST_IMAGES', $this -> getWhereAds()));
...@@ -89,7 +93,15 @@ class LogicAdvertisements extends AdvertisementModelClass { ...@@ -89,7 +93,15 @@ class LogicAdvertisements extends AdvertisementModelClass {
} }
function deleteAd(){ function deleteAd(){
$this -> accessModify('DELETE_AD_FILE', $this -> getDeleteData(), false); $deleteData = $this -> getDeleteData();
$adDetails = $this -> getRowData($this -> accessSelect('SELECT_AD_DETAILS', $deleteData));
$toDelete = SYSTEM_DOCUMENT_ADS."/{$adDetails["file_name"]}";
if(@file_exists($toDelete))
unlink($toDelete);
$this -> accessModify('DELETE_AD_FILE', $deleteData, false);
} }
function insertActivity(){ function insertActivity(){
......
...@@ -23,6 +23,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -23,6 +23,7 @@ class AdvertisementModelClass extends ModelClassEx {
private $fileName = NO_STRING; private $fileName = NO_STRING;
private $adName = NO_STRING; private $adName = NO_STRING;
private $sequence = NO_STRING; private $sequence = NO_STRING;
private $saveName = NO_STRING;
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* @function_name: コントロールパネルシステムindexモデルクラスコンストラクタ * @function_name: コントロールパネルシステムindexモデルクラスコンストラクタ
...@@ -48,7 +49,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -48,7 +49,7 @@ class AdvertisementModelClass extends ModelClassEx {
$this -> setParameter(); $this -> setParameter();
// チェック // チェック
$this -> validate(); return $this -> validate();
} catch (Exception $e) { } catch (Exception $e) {
throw new Exception(NO_STRING); throw new Exception(NO_STRING);
...@@ -99,7 +100,6 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -99,7 +100,6 @@ class AdvertisementModelClass extends ModelClassEx {
* @return : TRUE:成功、FALSE:失敗 * @return : TRUE:成功、FALSE:失敗
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
public function validate() { public function validate() {
// ログインチェック // ログインチェック
if(!$this -> checkAdminUserLogin()) { if(!$this -> checkAdminUserLogin()) {
throw new Exception(NO_STRING); throw new Exception(NO_STRING);
...@@ -124,13 +124,11 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -124,13 +124,11 @@ class AdvertisementModelClass extends ModelClassEx {
$this -> setType(TYPE_IMAGE_MANAGER); $this -> setType(TYPE_IMAGE_MANAGER);
} }
}elseif($this -> getType() == TYPE_UPDATE) { }elseif($this -> getType() == TYPE_UPDATE) {
if(!in_array($this -> location, ['menu', 'login'])){
if(!in_array($this -> location, array('menu', 'login'))){
$this -> setType(TYPE_IMAGE_MANAGER_DETAIL); $this -> setType(TYPE_IMAGE_MANAGER_DETAIL);
} }
$lang = array('en', 'ja', 'sc', 'tc', 'id'); if(!in_array($this -> language, ['en', 'ja', 'sc', 'tc', 'id'])){
if(!in_array($this -> language, $lang)){
$this -> setType(TYPE_IMAGE_MANAGER_DETAIL); $this -> setType(TYPE_IMAGE_MANAGER_DETAIL);
} }
}elseif($this -> getType() == TYPE_IMAGE_MANAGER_UPLOAD_COMPLETE) { }elseif($this -> getType() == TYPE_IMAGE_MANAGER_UPLOAD_COMPLETE) {
...@@ -139,8 +137,11 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -139,8 +137,11 @@ class AdvertisementModelClass extends ModelClassEx {
$this -> setType(TYPE_IMAGE_MANAGER); $this -> setType(TYPE_IMAGE_MANAGER);
} }
if(!$this -> isUpload(PARAM_IMG1)) {
$this -> popUpSessionMessage(ERROR, 'E_ERROR_UPLOAD_ADMIN_INVALID', array());
$this -> setType(TYPE_IMAGE_MANAGER);
}
} }
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
...@@ -244,7 +245,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -244,7 +245,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : 結果セット * @parameter : 結果セット
* @return : 検索条件配列 * @return : 検索条件配列
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function getWhere() { public function getWhere() {
// 変数宣言部 // 変数宣言部
$where = NO_STRING; $where = NO_STRING;
$rtn = array(); $rtn = array();
...@@ -274,7 +275,6 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -274,7 +275,6 @@ class AdvertisementModelClass extends ModelClassEx {
} }
$start = ($this -> getTargetPage() - VAL_INT_1) * VAR_DEFAULT_PAGE_COUNT; $start = ($this -> getTargetPage() - VAL_INT_1) * VAR_DEFAULT_PAGE_COUNT;
$end = $this -> getTargetPage() * VAR_DEFAULT_PAGE_COUNT;
$page = ' LIMIT ' . $start . DELIMIT_COMMA . VAL_INT_50; $page = ' LIMIT ' . $start . DELIMIT_COMMA . VAL_INT_50;
...@@ -289,7 +289,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -289,7 +289,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : * @parameter :
* @return : * @return :
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function echoFrom() { public function echoFrom() {
echo $this -> from; echo $this -> from;
} }
...@@ -298,7 +298,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -298,7 +298,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : * @parameter :
* @return : * @return :
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function echoTo() { public function echoTo() {
echo $this -> to; echo $this -> to;
} }
...@@ -307,7 +307,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -307,7 +307,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : * @parameter :
* @return : * @return :
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function echoMail() { public function echoMail() {
echo $this -> mail; echo $this -> mail;
} }
...@@ -316,7 +316,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -316,7 +316,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : * @parameter :
* @return : * @return :
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function echoIP() { public function echoIP() {
echo $this -> IP; echo $this -> IP;
} }
...@@ -325,13 +325,12 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -325,13 +325,12 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : * @parameter :
* @return : * @return :
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function echoAdsId() { public function echoAdsId() {
echo $this -> adsID; echo $this -> adsID;
} }
public function echoLanguageList() { public function echoLanguageList() {
// 変数宣言部 // 変数宣言部
$language[] = array(PARAM_DATA_KEY => 'en' $language[] = array(PARAM_DATA_KEY => 'en'
, PARAM_DATA_VALUE => 'EN'); , PARAM_DATA_VALUE => 'EN');
...@@ -344,13 +343,6 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -344,13 +343,6 @@ class AdvertisementModelClass extends ModelClassEx {
$language[] = array(PARAM_DATA_KEY => 'id' $language[] = array(PARAM_DATA_KEY => 'id'
, PARAM_DATA_VALUE => 'ID'); , PARAM_DATA_VALUE => 'ID');
// foreach($language as $row) {
// $lists[] = array(PARAM_DATA_KEY => $this -> getColumnData($row, COLUMN_CURRENCY_NAME)
// , PARAM_DATA_VALUE => $this -> getColumnData($row, COLUMN_CURRENCY_NAME));
// }
echo $this -> dispListOption($language, $this -> language); echo $this -> dispListOption($language, $this -> language);
} }
...@@ -359,51 +351,39 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -359,51 +351,39 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : なし * @parameter : なし
* @return : なし * @return : なし
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function loadImageAds() { public function loadImageAds() {
// echo $this -> adsID;
// echo $this -> location;
// echo $this -> language;
// echo $this -> link;
// die();
// 変数宣言部
$path = NO_STRING;
$saveName = NO_STRING;
$flg = false;
$oldName = NO_STRING;
$imgFlg = NO_STRING;
$uploads = array();
// ルートディレクトリを取得する // ルートディレクトリを取得する
$path = SYSTEM_DOCUMENT_ADS; $path = SYSTEM_DOCUMENT_ADS;
// 該当ディレクトリの確認 // 該当ディレクトリの確認
if(!file_exists($path)) { if(!file_exists($path))
mkdir($path, 0777); mkdir($path, 0777);
} else { else
chmod($path, 0777); chmod($path, 0777);
}
// 画像1の存在確認
if($this -> isUpload(PARAM_IMG1)) {
// 保存ファイル名 $this -> saveName = basename($_FILES[PARAM_IMG1][PARAM_NAME]);
$info = new SplFileInfo($_FILES[PARAM_IMG1][PARAM_NAME]);
$saveName = basename($_FILES[PARAM_IMG1][PARAM_NAME]);
// 画像の移動 // 画像の移動
if(move_uploaded_file($_FILES[PARAM_IMG1][PARAM_TMP_NAME], $path . DELIMIT_SLASH . $saveName)) { if(move_uploaded_file($_FILES[PARAM_IMG1][PARAM_TMP_NAME], $path . DELIMIT_SLASH . $this -> saveName)) {
// アップロードファイル名
$oldName = basename($_FILES[PARAM_IMG1][PARAM_NAME]);
$imgFlg = $this -> getImg1Flg();
// ファイルパーミッションの変更 // ファイルパーミッションの変更
chmod($path . DELIMIT_SLASH . $saveName, 0777); chmod($path . DELIMIT_SLASH . $this -> saveName, 0777);
// データの登録 return true;
$this -> accessModify('INSERT_ADS', array(10, $saveName, $this -> adsID, $this -> location, $this -> link, $this -> language, $this -> getAdminUserData(PARAM_UID)));
} }
return false;
} }
public function getImageAdRegistData(){
return [
VAL_INT_10,
$this -> saveName,
$this -> adsID,
$this -> location,
$this -> link,
$this -> language,
$this -> getAdminUserData(PARAM_UID)
];
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
...@@ -411,8 +391,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -411,8 +391,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : パラメータ * @parameter : パラメータ
* @return : 存在する:true、存在しない:false * @return : 存在する:true、存在しない:false
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function isUpload($param) { public function isUpload($param) {
// 変数宣言部 // 変数宣言部
$rtn = false; $rtn = false;
...@@ -435,14 +414,12 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -435,14 +414,12 @@ class AdvertisementModelClass extends ModelClassEx {
return $this -> img1Flg; return $this -> img1Flg;
} }
function echoImageList(){ public function echoImageList(){
// 変数宣言部 // 変数宣言部
$rtn = NO_STRING; $rtn = NO_STRING;
$row = null; $row = null;
if($this -> isLoopData($this -> rs2)) { if($this -> isLoopData($this -> rs2)) {
$listCount = count($this -> rs2);
for($cnt = 0; $cnt < count($this -> rs2); $cnt++) { for($cnt = 0; $cnt < count($this -> rs2); $cnt++) {
$row = $this -> getRowData($this -> rs2, $cnt); $row = $this -> getRowData($this -> rs2, $cnt);
...@@ -481,23 +458,23 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -481,23 +458,23 @@ class AdvertisementModelClass extends ModelClassEx {
echo $rtn; echo $rtn;
} }
function echoFileName(){ public function echoFileName(){
echo $this -> fileName; echo $this -> fileName;
} }
function echoAdName(){ public function echoAdName(){
echo $this -> adName; echo $this -> adName;
} }
function echoLink(){ public function echoLink(){
echo $this -> link; echo $this -> link;
} }
function echoID(){ public function echoID(){
echo $this -> adID; echo $this -> adID;
} }
function echoLocation(){ public function echoLocation(){
$location = array('login', 'menu'); $location = array('login', 'menu');
$options = array(); $options = array();
$rtn = NO_STRING; $rtn = NO_STRING;
...@@ -519,7 +496,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -519,7 +496,7 @@ class AdvertisementModelClass extends ModelClassEx {
echo $rtn; echo $rtn;
} }
function echoLanguage(){ public function echoLanguage(){
$language = array('en', 'ja', 'sc', 'tc', 'id'); $language = array('en', 'ja', 'sc', 'tc', 'id');
$options = array(); $options = array();
$rtn = NO_STRING; $rtn = NO_STRING;
...@@ -541,15 +518,15 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -541,15 +518,15 @@ class AdvertisementModelClass extends ModelClassEx {
echo $rtn; echo $rtn;
} }
function echoAdLanguage(){ public function echoAdLanguage(){
echo $this -> language; echo $this -> language;
} }
function echoAdLocation(){ public function echoAdLocation(){
echo $this -> language; echo $this -> language;
} }
function getUpdateData(){ public function getUpdateData(){
$rtn = array(); $rtn = array();
$rtn[] = $this -> adName; $rtn[] = $this -> adName;
...@@ -560,7 +537,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -560,7 +537,7 @@ class AdvertisementModelClass extends ModelClassEx {
return $rtn; return $rtn;
} }
function getUpdateSequence(){ public function getUpdateSequence(){
$rtn = array(); $rtn = array();
$adID = array(); $adID = array();
$condition = array(); $condition = array();
...@@ -583,7 +560,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -583,7 +560,7 @@ class AdvertisementModelClass extends ModelClassEx {
//return $rtn; //return $rtn;
} }
function getWhereAds(){ public function getWhereAds(){
$rtn = array(); $rtn = array();
$whereStr = NO_STRING; $whereStr = NO_STRING;
...@@ -609,16 +586,13 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -609,16 +586,13 @@ class AdvertisementModelClass extends ModelClassEx {
} }
function getDeleteData(){ public function getDeleteData(){
return [
$rtn = array(); $this -> adID
$rtn[] = $this -> adID; ];
return $rtn;
} }
function checkExistImage($fileName){ public function checkExistImage($fileName){
$rtn = true; $rtn = true;
$file = $this -> accessSelect('CHECK_EXIST_AD', array($fileName)); $file = $this -> accessSelect('CHECK_EXIST_AD', array($fileName));
...@@ -629,16 +603,12 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -629,16 +603,12 @@ class AdvertisementModelClass extends ModelClassEx {
return $rtn; return $rtn;
} }
function sessionLocation(){ public function sessionLocation(){
return $_SESSION['location']; return $_SESSION['location'];
} }
function sessionLanguage(){ public function sessionLanguage(){
return $_SESSION['language']; return $_SESSION['language'];
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
...@@ -646,8 +616,7 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -646,8 +616,7 @@ class AdvertisementModelClass extends ModelClassEx {
* @parameter : none * @parameter : none
* @return : 表示用HTML文字列 * @return : 表示用HTML文字列
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
function getActivity(){ public function getActivity(){
$type = $this -> getType(); $type = $this -> getType();
$details = array(); $details = array();
...@@ -701,12 +670,10 @@ class AdvertisementModelClass extends ModelClassEx { ...@@ -701,12 +670,10 @@ class AdvertisementModelClass extends ModelClassEx {
return $rtn; return $rtn;
} }
function getFileDetailsByID($id, $column){ public function getFileDetailsByID($id, $column){
$row = $this -> accessSelect('SELECT_AD_DETAILS', array($id)); $row = $this -> accessSelect('SELECT_AD_DETAILS', array($id));
$details = $this -> getColumnData($row[0], $column); $details = $this -> getColumnData($row[0], $column);
return $details; return $details;
} }
} }
\ No newline at end of file
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment