/** * Page のプロセス. * * @return void */ function process() { $objView = new SC_AdminView(); $this->objLayout = new SC_Helper_PageLayout_Ex(); // 認証可否の判定 $objSess = new SC_Session(); SC_Utils_Ex::sfIsSuccess($objSess); // ページ一覧を取得 $this->arrPageList = $this->objLayout->lfgetPageData(); // ブロックIDを取得 if (isset($_POST['page_id'])) { $page_id = $_POST['page_id']; } else { if (isset($_GET['page_id'])) { $page_id = $_GET['page_id']; } else { $page_id = ''; } } $this->page_id = $page_id; // メッセージ表示 if (isset($_GET['msg']) && $_GET['msg'] == "on") { $this->tpl_onload = "alert('登録が完了しました。');"; } // page_id が指定されている場合にはテンプレートデータの取得 if (is_numeric($page_id) and $page_id != '') { $arrPageData = $this->objLayout->lfgetPageData(" page_id = ? ", array($page_id)); if ($arrPageData[0]['tpl_dir'] === "") { $this->arrErr['page_id_err'] = "※ 指定されたページは編集できません。"; // 画面の表示 $objView->assignobj($this); $objView->display(MAIN_FRAME); exit; } // テンプレートファイルが存在していれば読み込む $tpl_file = USER_TEMPLATE_PATH . "/" . TEMPLATE_NAME . "/" . $arrPageData[0]['filename'] . ".tpl"; if (file_exists($tpl_file)) { $arrPageData[0]['tpl_data'] = file_get_contents($tpl_file); // 存在してなければ, 指定されたテンプレートのファイルを読み込む } else { $arrPageData[0]['tpl_data'] = file_get_contents(TEMPLATE_DIR . $arrPageData[0]['filename'] . ".tpl"); } // チェックボックスの値変更 $arrPageData[0]['header_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['header_chk'], true); $arrPageData[0]['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['footer_chk'], true); // ディレクトリを画面表示用に編集 $arrPageData[0]['directory'] = str_replace(USER_DIR, '', $arrPageData[0]['php_dir']); $this->arrPageData = $arrPageData[0]; } // プレビュー処理 if (!isset($_POST['mode'])) { $_POST['mode'] = ""; } if ($_POST['mode'] == 'preview') { $page_id_old = $page_id; // プレビューの場合ページIDを0にセットする。 $page_id = "0"; $url = basename($_POST['url']); $tmpPost = $_POST; $tmpPost['page_id'] = $page_id; $tmpPost['url'] = $url; $tmpPost['tpl_dir'] = USER_PATH . "templates/preview/"; $arrPreData = $this->objLayout->lfgetPageData("page_id = ?", array($page_id)); // tplファイルの削除 $del_tpl = USER_PATH . "templates/" . $arrPreData[0]['filename'] . '.tpl'; if (file_exists($del_tpl)) { unlink($del_tpl); } // DBへデータを更新する $this->lfEntryPageData($tmpPost); // TPLファイル作成 $preview_tpl = USER_PATH . "templates/preview/" . TEMPLATE_NAME . "/" . $url . '.tpl'; $this->lfCreateFile($preview_tpl); // blocposition を削除 $objDBConn = new SC_DbConn(); // DB操作オブジェクト $sql = 'delete from dtb_blocposition where page_id = 0'; $ret = $objDBConn->query($sql); if ($page_id_old != "") { // 登録データを取得 $sql = "SELECT 0, target_id, bloc_id, bloc_row FROM dtb_blocposition WHERE page_id = ?"; $ret = $objDBConn->getAll($sql, array($page_id_old)); if (count($ret) > 0) { // blocposition を複製 $sql = " insert into dtb_blocposition ("; $sql .= " page_id,"; $sql .= " target_id,"; $sql .= " bloc_id,"; $sql .= " bloc_row"; $sql .= " )values(?, ?, ?, ?)"; // 取得件数文INSERT実行 foreach ($ret as $key => $val) { $ret = $objDBConn->query($sql, $val); } } } $_SESSION['preview'] = "ON"; $this->sendRedirect($this->getLocation(URL_DIR . "preview/index.php", array("filename" => $arrPageData[0]["filename"]))); exit; } // データ登録処理 if ($_POST['mode'] == 'confirm') { // エラーチェック $this->arrErr = $this->lfErrorCheck($_POST); // エラーがなければ更新処理を行う if (count($this->arrErr) == 0) { // DBへデータを更新する $this->lfEntryPageData($_POST); // ベースデータでなければファイルを削除し、PHPファイルを作成する if (!$this->objLayout->lfCheckBaseData($page_id)) { // ファイル削除 $this->objLayout->lfDelFile($arrPageData[0]); // PHPファイル作成 $cre_php = USER_PATH . $_POST['url'] . ".php"; $this->lfCreatePHPFile($cre_php); } // TPLファイル作成 $cre_tpl = USER_TEMPLATE_PATH . "/" . TEMPLATE_NAME . "/" . basename($_POST['url']) . '.tpl'; $this->lfCreateFile($cre_tpl); // 編集可能ページの場合にのみ処理を行う if ($arrPageData[0]['edit_flg'] != 2) { // 新規作成した場合のために改にページIDを取得する $arrPageData = $this->objLayout->lfgetPageData(" url = ? ", array(USER_URL . $_POST['url'] . ".php")); $page_id = $arrPageData[0]['page_id']; } $this->sendRedirect($this->getLocation("./main_edit.php", array("page_id" => $page_id, "msg" => "on"))); exit; } else { // エラーがあれば入力時のデータを表示する $this->arrPageData = $_POST; $this->arrPageData['header_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['header_chk']), true); $this->arrPageData['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['footer_chk']), true); $this->arrPageData['directory'] = $_POST['url']; $this->arrPageData['filename'] = ""; } } // データ削除処理 ベースデータでなければファイルを削除 if ($_POST['mode'] == 'delete' and !$this->objLayout->lfCheckBaseData($page_id)) { $this->objLayout->lfDelPageData($_POST['page_id']); $this->sendRedirect($this->getLocation("./main_edit.php")); exit; } // 画面の表示 $objView->assignobj($this); $objView->display(MAIN_FRAME); }
/** * プレビューするデータを DB に保存する. * * @param array $arrPageData ページ情報の配列 * @return void */ function lfSetPreData($arrPageData, &$objLayout) { $objDBConn = new SC_DbConn(); // DB操作オブジェクト $sql = ""; // データ更新SQL生成用 $ret = ""; // データ更新結果格納用 $arrUpdData = array(); // 更新データ生成用 $filename = $arrPageData[0]['filename']; $arrPreData = $objLayout->lfgetPageData(" page_id = ? ", array("0")); // XXX tplファイルの削除 $del_tpl = USER_PATH . "templates/" . $filename . '.tpl'; if (file_exists($del_tpl)) { unlink($del_tpl); } $tplfile = TEMPLATE_DIR . $filename; // filename が空の場合にはMYページと判断 if ($filename == "") { $tplfile = TEMPLATE_DIR . "mypage/index"; $filename = 'mypage'; } // プレビュー用tplファイルのコピー $copyTo = USER_PATH . "templates/preview/" . TEMPLATE_NAME . "/" . $filename . ".tpl"; if (!is_dir(dirname($copyTo))) { mkdir(dirname($copyTo)); } copy($tplfile . ".tpl", $copyTo); // 更新データの取得 $sql = "select page_name, header_chk, footer_chk from dtb_pagelayout where page_id = ?"; $ret = $objDBConn->getAll($sql, array($arrPageData[0]['page_id'])); // dbデータのコピー $sql = " update dtb_pagelayout set "; $sql .= " page_name = ?"; $sql .= " ,header_chk = ?"; $sql .= " ,footer_chk = ?"; $sql .= " ,url = ?"; $sql .= " ,tpl_dir = ?"; $sql .= " ,filename = ?"; $sql .= " where page_id = 0"; $arrUpdData = array($ret[0]['page_id'], $ret[0]['page_id'], $ret[0]['page_id'], USER_DIR . "templates/" . TEMPLATE_NAME . "/", USER_DIR . "templates/" . TEMPLATE_NAME . "/", $filename); $objDBConn->query($sql, $arrUpdData); }
/** * ブロック情報を取得する. * * @param string $where Where句文 * @param array $arrVal Where句の絞込条件値 * @return array ブロック情報 */ function lfgetBlocData($where = '', $arrVal = '') { $objDBConn = new SC_DbConn(); // DB操作オブジェクト $sql = ""; // データ取得SQL生成用 $arrRet = array(); // データ取得用 // SQL生成 $sql = " SELECT "; $sql .= "\tbloc_id"; $sql .= "\t,bloc_name"; $sql .= "\t,tpl_path"; $sql .= "\t,filename"; $sql .= " \t,create_date"; $sql .= " \t,update_date"; $sql .= " \t,php_path"; $sql .= " \t,del_flg"; $sql .= " FROM "; $sql .= " \tdtb_bloc"; // where句の指定があれば追加 if ($where != '') { $sql .= " WHERE " . $where; } $sql .= " ORDER BY \tbloc_id"; $arrRet = $objDBConn->getAll($sql, $arrVal); return $arrRet; }
/** * ブロック情報を取得する. * * @param string $where WHERE句 * @param array $arrVal WHERE句の値を格納した配列 * @return ブロック情報 */ function getPageData($where = '', $arrVal = '') { $objDBConn = new SC_DbConn(); // DB操作オブジェクト $sql = ""; // データ取得SQL生成用 $arrRet = array(); // データ取得用 // SQL生成(url と update_date 以外は不要?) $sql .= " SELECT"; $sql .= " page_id"; // ページID $sql .= " ,page_name"; // 名称 $sql .= " ,url"; // URL $sql .= " ,php_dir"; // php保存先ディレクトリ $sql .= " ,tpl_dir"; // tpl保存先ディdレクトリ $sql .= " ,filename"; // ファイル名称 $sql .= " ,header_chk "; // ヘッダー使用FLG $sql .= " ,footer_chk "; // フッター使用FLG $sql .= " ,author"; // authorタグ $sql .= " ,description"; // descriptionタグ $sql .= " ,keyword"; // keywordタグ $sql .= " ,update_url"; // 更新URL $sql .= " ,create_date"; // データ作成日 $sql .= " ,update_date"; // データ更新日 $sql .= " FROM "; $sql .= " dtb_pagelayout"; // where句の指定があれば追加 if ($where != '') { $sql .= " WHERE " . $where; } $sql .= " ORDER BY \tpage_id"; return $objDBConn->getAll($sql, $arrVal); }
/** * Page のプロセス. * * @return void */ function process() { $conn = new SC_DbConn(); $objSite = new SC_SiteInfo($conn); if (MELMAGA_SEND != true) { exit; } //リアルタイム配信モードがオンのとき if ($_GET['mode'] == 'now') { //---- 未送信データを取得する $time_data = $conn->getAll("SELECT send_id FROM dtb_send_history WHERE complete_count = 0 AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC"); } else { // postgresql と mysql とでSQLをわける if (DB_TYPE == "pgsql") { $sql = "SELECT send_id FROM dtb_send_history "; $sql .= "WHERE start_date BETWEEN current_timestamp + '- 5 minutes' AND current_timestamp + '5 minutes' AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC"; } else { if (DB_TYPE == "mysql") { $sql = "SELECT send_id FROM dtb_send_history "; $sql .= "WHERE start_date BETWEEN date_add(now(),INTERVAL -5 minute) AND date_add(now(),INTERVAL 5 minute) AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC"; } } //---- 30分毎にCronが送信時間データ確認 $time_data = $conn->getAll($sql); } //未送信メルマガの数 $count = count($time_data); //未送信メルマガがあれば送信処理を続ける。なければ中断する。 if ($count > 0) { print "start sending <br />\n"; } else { print "not found <br />\n"; exit; } //---- メール送信準備 for ($i = 0; $i < $count; $i++) { // 送信先リストの取得 $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)"; $list_data[] = $conn->getAll($sql, array($time_data[$i]["send_id"])); // 送信先データの取得 $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?"; $mail_data[] = $conn->getAll($sql, array($time_data[$i]["send_id"])); } //---- 送信結果フラグ用SQL $sql_flag = "UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?"; //---- メール生成と送信 for ($i = 0; $i < $count; $i++) { for ($j = 0; $j < count($list_data[$i]); $j++) { $customerName = ""; $mailBody = ""; $sendFlag = ""; //-- 顧客名の変換 $name = trim($list_data[$i][$j]["name"]); if ($name == "") { $name = "お客"; } $customerName = htmlspecialchars($name); $subjectBody = ereg_replace("{name}", $customerName, $mail_data[$i][0]["subject"]); $mailBody = ereg_replace("{name}", $customerName, $mail_data[$i][0]["body"]); $this->objMail->setItem($list_data[$i][$j]["email"], $subjectBody, $mailBody, $objSite->data["email03"], $objSite->data["company_name"], $objSite->data["email03"], $objSite->data["email04"], $objSite->data["email04"]); //-- テキストメール配信の場合 if ($mail_data[$i][0]["mail_method"] == 2) { $sendResut = $this->objMail->sendMail(); //-- HTMLメール配信の場合 } else { $sendResut = $this->objMail->sendHtmlMail(); } //-- 送信完了なら1、失敗なら-1をメール送信結果フラグとしてDBに挿入 if (!$sendResut) { $sendFlag = "-1"; } else { $sendFlag = "1"; // 完了を 1 増やす $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?"; $conn->query($sql, array($mail_data[$i][0]["send_id"])); } $conn->query($sql_flag, array($sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"])); } //--- メール全件送信完了後の処理 $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?"; $conn->query($completeSql, array($time_data[$i]["send_id"])); //--- 送信完了 報告メール $compSubject = date("Y年m月d日H時i分" . " 下記メールの配信が完了しました。"); // 管理者宛に変更 $this->objMail->setTo($objSite->data["email03"]); $this->objMail->setSubject($compSubject); //-- テキストメール配信の場合 if ($mail_data[$i][0]["mail_method"] == 2) { $sendResut = $this->objMail->sendMail(); //-- HTMLメール配信の場合 } else { $sendResut = $this->objMail->sendHtmlMail(); } } if ($_GET['mode'] = "now") { header("Location: " . URL_DIR . "admin/mail/history.php"); } echo "complete\n"; }