/**
 * Smarty {end_session} function plugin
 *
 * Type: function<br>
 * Name: end_session<br>
 * Purpose: end session module.<br>
 *
 * @author Naohisa Minagawa <minagawa at web-life dot co dot jp>
 * @param array $params parameters
 * @param object $smarty Smarty object
 * @param object $template template object
 * @return string null
 */
function smarty_function_end_session($params, $template)
{
    // テンプレートに各種変数を割り当て
    $attr = Vizualizer::attr();
    $template = $attr["template"];
    $template->assign("configure", Vizualizer_Configure::values());
    $template->assign("post", Vizualizer::request());
    $template->assign("attr", $attr);
    $template->assign("sessionName", session_name());
    $template->assign("sessionId", session_id());
    Vizualizer_Logger::writeDebug("Page Session Ended.");
}
Example #2
0
 public function execute()
 {
     // クエリのビルド
     $sql = $this->buildQuery();
     // クエリを実行する。
     try {
         $connection = Vizualizer_Database_Factory::begin($this->module);
         Vizualizer_Logger::writeDebug($sql);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return $result;
 }
/**
 * Smarty {start_session} function plugin
 *
 * Type: function<br>
 * Name: start_session<br>
 * Purpose: start session module.<br>
 *
 * @author Naohisa Minagawa <minagawa at web-life dot co dot jp>
 * @param array $params parameters
 * @param object $smarty Smarty object
 * @param object $template template object
 * @return string null
 */
function smarty_function_start_session($params, $template)
{
    // POSTにINPUT=NEWが渡った場合は、入力をクリアする。
    $post = Vizualizer::request();
    /*
     * $inputData = Vizualizer_Session::get(Vizualizer::INPUT_KEY); if
     * (is_array($inputData)) { if (array_key_exists(TEMPLATE_DIRECTORY,
     * $inputData)) { if (isset($post["INPUT"]) && $post["INPUT"] == "NEW") {
     * unset($inputData[TEMPLATE_DIRECTORY]); } //
     * INPUT_DATAのセッションの内容をPOSTに戻す。(POST優先) if
     * (is_array($inputData[TEMPLATE_DIRECTORY])) { foreach
     * ($inputData[TEMPLATE_DIRECTORY] as $key => $value) { if
     * (!isset($post[$key])) { $post[$key] = $value; } } } }
     * Vizualizer_Session::set(Vizualizer::INPUT_KEY, $inputData); }
     */
    Vizualizer_Logger::writeDebug("Page Session Started.");
}
Example #4
0
 /**
  * 拡張ライブラリファイルを読み込む
  *
  * @param string $type 拡張ファイルの種別
  * @param string $name 拡張ファイルのオブジェクト名
  */
 private function load($type, $name, $params = array())
 {
     try {
         $names = explode(".", $name);
         $className = (!in_array($this->namespace, self::$callmap) ? "Vizualizer" . $this->namespace : self::$callmap[$this->namespace]) . "_" . $type . "_" . implode("_", $names);
         if (class_exists($className)) {
             Vizualizer_Logger::writeDebug("Loading: " . $className . "(" . memory_get_usage() . ")");
             return new $className($params);
         } else {
             $className = "Vizualizer_" . $type . "_" . $this->namespace . "_" . implode("_", $names);
             if (class_exists($className)) {
                 Vizualizer_Logger::writeDebug("Loading: " . $className . "(" . memory_get_usage() . ")");
                 return new $className($params);
             }
         }
         Vizualizer_Logger::writeDebug("No Plugin : " . $className);
         return null;
     } catch (Exception $e) {
         Vizualizer_Logger::writeError("Failed to load plugin", $e);
     }
 }
Example #5
0
 public function sendRaw($from, $fromAddress, $to, $subject, $body, $contentType = "text/plain", $transferEncoding = "7bit")
 {
     // メールヘッダを作成
     $header = "";
     $header .= "From: " . $from . "\n";
     $header .= "Reply-To: " . $from . "\n";
     $header .= "MIME-Version: 1.0\n";
     $header .= "Content-Type: " . $contentType . "\n";
     if (!empty($transferEncoding)) {
         $header .= "Content-Transfer-Encoding: " . $transferEncoding . "\n";
     }
     $header .= "X-Mailer: PHP/" . phpversion();
     if (!mail($to, $subject, $body, $header, "-f " . $fromAddress)) {
         Vizualizer_Logger::writeAlert("メール送信に失敗しました。");
     }
 }
Example #6
0
 /**
  * ガーベジコレクションを実行する.
  *
  * 引数 $maxlifetime の代りに 定数 MAX_LIFETIME を使用する.
  *
  * @param integer $maxlifetime セッションの有効期限
  */
 function clean($maxlifetime)
 {
     $limit = Vizualiezr_Data_Calendar::now()->strToTime("-" . $maxlifetime . " secs")->date("Y-m-d H:i:s");
     // セッションに値を設定
     try {
         $delete = new Vizualizer_Query_Delete($this->table);
         $delete->addWhere($this->table->update_time . " < ?", array($limit));
         Vizualizer_Logger::writeDebug($delete->showQuery());
         $delete->execute();
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Example #7
0
 public static function start()
 {
     // REQUEST URIから実際に出力するテンプレートファイルを特定
     $attributes = Vizualizer::attr();
     $attributes["templateName"] = str_replace("?" . $_SERVER["QUERY_STRING"], "", $_SERVER["REQUEST_URI"]);
     if (VIZUALIZER_SUBDIR != "") {
         if (strpos($attributes["templateName"], VIZUALIZER_SUBDIR) === 0) {
             $attributes["templateName"] = substr($attributes["templateName"], strlen(VIZUALIZER_SUBDIR));
         }
     }
     // テンプレートにシンボリックリンクを作成する。
     if (Vizualizer_Configure::get("site_home") !== null && Vizualizer_Configure::get("site_home") !== "") {
         if (!is_dir(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents")) {
             mkdir(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents");
         }
         if (!file_exists(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain"))) {
             Vizualizer_Logger::writeDebug("CREATE SYMBOLIC LINK : " . VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain") . " => " . Vizualizer_Configure::get("site_home"));
             symlink(Vizualizer_Configure::get("site_home"), VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain"));
         }
         if (is_writable(Vizualizer_Configure::get("site_home"))) {
             if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "mobile")) {
                 symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "default", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "mobile");
             }
             if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone")) {
                 symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "default", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone");
             }
             if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "iphone")) {
                 symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "iphone");
             }
             if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "android")) {
                 symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "android");
             }
         }
     }
     // ユーザーのテンプレートを取得する。
     if (Vizualizer_Configure::get("device") !== null) {
         if (Vizualizer_Configure::get("device")->isMobile()) {
             if (Vizualizer_Configure::get("device")->isSmartPhone()) {
                 if (Vizualizer_Configure::get("device")->getDeviceType() == "iPhone") {
                     $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "iphone";
                 } elseif (Vizualizer_Configure::get("device")->getDeviceType() == "Android") {
                     $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "android";
                 }
                 $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "sphone";
             } else {
                 $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "mobile";
             }
         } else {
             $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "default";
         }
     } else {
         $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "default";
     }
     // テンプレートがディレクトリかどうか調べ、ディレクトリの場合はファイル名に落とす。
     // 呼び出し先がディレクトリで最後がスラッシュでない場合は最後にスラッシュを補完
     if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"])) {
         if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) && substr($attributes["templateName"], -1) != DIRECTORY_SEPARATOR) {
             $attributes["templateName"] .= DIRECTORY_SEPARATOR;
         }
         if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) {
             if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.html")) {
                 $attributes["templateName"] .= "index.html";
             } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.htm")) {
                 $attributes["templateName"] .= "index.htm";
             } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.php")) {
                 $attributes["templateName"] .= "index.php";
             } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.xml")) {
                 $attributes["templateName"] .= "index.xml";
             } else {
                 // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく
                 $attributes["templateName"] .= "index.html";
             }
         }
     }
     if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) || is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"])) {
         if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) && substr($attributes["templateName"], -1) != DIRECTORY_SEPARATOR) {
             $attributes["templateName"] .= DIRECTORY_SEPARATOR;
         }
         // 呼び出し先がスラッシュで終わっている場合にはファイル名を補完
         if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) {
             if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.html")) {
                 $attributes["templateName"] .= "index.html";
             } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.htm")) {
                 $attributes["templateName"] .= "index.htm";
             } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.xml")) {
                 $attributes["templateName"] .= "index.xml";
             } else {
                 // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく
                 $attributes["templateName"] .= "index.html";
             }
         }
     }
     if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) {
         // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく
         $attributes["templateName"] .= "index.html";
     }
     // テンプレートの存在するパスを取得する。
     define("TEMPLATE_DIRECTORY", dirname($attributes["templateName"]));
 }
Example #8
0
 public function fetch($limit = null, $offset = null)
 {
     // クエリのビルド
     $sql = $this->buildQuery();
     // クエリの検索件数を制限する。
     if ($limit != null) {
         $sql .= " LIMIT " . $limit;
         if ($offset != null) {
             $sql .= " OFFSET " . $offset;
         }
     }
     // クエリを実行する。
     try {
         $sql = $this->showQuery();
         Vizualizer_Logger::writeDebug($sql);
         $connection = Vizualizer_Database_Factory::conn($this->module);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return new Vizualizer_Query_Select_Result($result);
 }
Example #9
0
 /**
  * デフォルト実行のメソッドになります。
  * このメソッド以外がモジュールとして呼ばれることはありません。
  *
  * @param array $params モジュールの受け取るパラメータ
  */
 public function execute($params)
 {
     // 出力バッファをリセットする。
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     Vizualizer_Logger::$logFilePrefix = "batch_";
     Vizualizer_Logger::$logOutputStandard = true;
     $this->info("Batch " . $this->getName() . " Start.");
     if ($this->getDaemonName() != "") {
         if (count($params) > 3 && $params[3] == "stop") {
             if (($fp = fopen($this->getDaemonName() . ".unlock", "w+")) !== FALSE) {
                 fclose($fp);
             }
         } elseif (($fp = fopen($this->getDaemonName() . ".lock", "a+")) !== FALSE) {
             if (!flock($fp, LOCK_EX | LOCK_NB)) {
                 list($time, $pid) = explode(",", trim(file_get_contents($this->getDaemonName() . ".lock")));
                 // 12時間以上起動し続けている場合は再起動を実施
                 if ($time + 12 * 3600 < time()) {
                     system("kill -KILL " . $pid);
                 }
                 $this->info("Batch " . $this->getName() . " was already running.");
                 die("プログラムは既に実行中です。");
             }
             // デーモンの起動時刻とプロセスIDをロックファイルに記述
             ftruncate($fp, 0);
             fwrite($fp, time() . "," . getmypid());
             if ($this->isUnlocked()) {
                 // 実行前にunlockファイルがある場合は予め削除する。
                 unlink($this->getDaemonName() . ".unlock");
             }
             while (true) {
                 Vizualizer::now()->reset();
                 $this->info("==== START " . $this->getName() . " ROUTINE ======");
                 $this->executeImpl($params);
                 $this->info("==== END " . $this->getName() . " ROUTINE ======");
                 if (file_exists($this->getDaemonName() . ".unlock")) {
                     // unlockファイルがある場合はループを終了
                     unlink($this->getDaemonName() . ".unlock");
                     break;
                 }
                 // 一周回ったら所定秒数ウェイト
                 if ($this->getDaemonInterval() > 10) {
                     sleep($this->getDaemonInterval());
                 } else {
                     sleep(60);
                 }
             }
             fclose($fp);
         }
     } else {
         if (($fp = fopen($this->getDaemonName() . ".lock", "w+")) !== FALSE) {
             if (!flock($fp, LOCK_EX | LOCK_NB)) {
                 $this->info("Batch " . $this->getName() . " was already running.");
                 die("プログラムは既に実行中です。");
             }
             $this->executeImpl($params);
             fclose($fp);
         }
     }
     $this->info("Batch " . $this->getName() . " End.");
 }
Example #10
0
 /**
  * エラーログを出力する。
  * @param string $message ログメッセージ
  * @param Exception $exception エラーの原因となった例外オブジェクト
  */
 protected function error($message, $exception = null)
 {
     Vizualizer_Logger::writeError($message, $exception);
 }
Example #11
0
 /**
  * 現在の状態で挿入クエリを実行する。
  *
  * @param s array $values 挿入データの連想配列
  */
 public function execute($values)
 {
     try {
         $connection = Vizualizer_Database_Factory::begin($this->module);
         $sql = $this->showQuery($values);
         Vizualizer_Logger::writeDebug($sql);
         $result = $connection->query($sql);
     } catch (Exception $e) {
         Vizualizer_Logger::writeError($sql, $e);
         throw new Vizualizer_Exception_Database($e);
     }
     return $result;
 }
Example #12
0
 /**
  * ページ出力用のメソッドをオーバーライドしています。
  * 携帯のページについて、SJISに変換し、カナを半角にしています。
  *
  * @access public
  */
 public function display($template, $cache_id = null, $compile_id = null, $parent = null)
 {
     // キャッシュ無効にするヘッダを送信
     header("P3P: CP='UNI CUR OUR'");
     header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
     header("Last-Modified: " . Vizualizer::now()->gmDate("D, d M Y H:i:s") . " GMT");
     if (array_key_exists("HTTPS", $_SERVER) && $_SERVER['HTTPS'] == 'on') {
         header("Cache-Control: must-revalidate");
         header("Cache-Control: post-check=0, pre-check=0", false);
     } else {
         header("Cache-Control: no-cache, must-revalidate");
         header("Cache-Control: post-check=0, pre-check=0", false);
         header("Pragma: no-cache");
     }
     $attr = Vizualizer::attr();
     $templateEngine = $attr["template"];
     $templateEngine->assign("configure", Vizualizer_Configure::values());
     $templateEngine->assign("post", Vizualizer::request());
     $templateEngine->assign("attr", $attr);
     $templateEngine->assign("session", Vizualizer_Session::values());
     $templateEngine->assign("sessionName", session_name());
     $templateEngine->assign("sessionId", session_id());
     // display template
     Vizualizer_Logger::writeDebug("Template Dir : " . var_export($this->template_dir, true));
     if (Vizualizer_Configure::get("device")->isFuturePhone()) {
         // モバイルの時は出力するHTMLをデータとして取得
         $content = trim($this->core->fetch($template, $cache_id, $compile_id, $parent));
         // カタカナを半角にする。
         $content = mb_convert_kana($content, "k");
         // ソフトバンク以外の場合は、SJISエンコーディングに変換
         if (Vizualizer_Configure::get("device")->getDeviceType() != "Softbank") {
             header("Content-Type: text/html; charset=Shift_JIS");
             if (preg_match("/<meta\\s+http-equiv\\s*=\\s*\"Content-Type\"\\s+content\\s*=\\s*\"([^;]+);\\s*charset=utf-8\"\\s*\\/?>/i", $content, $params) > 0) {
                 header("Content-Type: " . $params[1] . "; charset=Shift_JIS");
                 $content = str_replace($params[0], "<meta http-equiv=\"Content-Type\" content=\"" . $params[1] . "; charset=Shift_JIS\" />", $content);
             } else {
                 header("Content-Type: text/html; charset=Shift_JIS");
             }
             echo mb_convert_encoding($content, "Shift_JIS", "UTF-8");
         } else {
             header("Content-Type: text/html; charset=UTF-8");
             echo $content;
         }
     } else {
         header("Content-Type: text/html; charset=UTF-8");
         echo trim($this->fetch($template, $cache_id, $compile_id, $parent));
     }
 }
Example #13
0
 /**
  * レジからの注文データを取り込む。
  * @param $params バッチ自体のパラメータ
  * @param $data バッチで引き回すデータ
  * @return バッチで引き回すデータ
  */
 protected function importOrders($params, $data)
 {
     try {
         // Use the us-west-2 region and latest version of each client.
         $sharedConfig = array('region' => 'ap-northeast-1', 'version' => 'latest');
         // Create an SDK class used to share configuration across clients.
         $sdk = new Aws\Sdk($sharedConfig);
         // Create an Amazon S3 client using the shared configuration data.
         $client = $sdk->createS3();
         if (count($params) > 3) {
             if ($params[3] == "today") {
                 $time = time();
             } elseif ($params[3] == "yesterday") {
                 $time = strtotime("-1 day");
             } else {
                 $time = strtotime($params[3]);
             }
         } else {
             $time = time();
         }
         // Get the object
         $result = $client->getObject(array('Bucket' => "oder-report", 'Key' => "150/" . date("Ym", $time) . "/sales-" . date("Y-m-d", $time) . ".csv"));
         Vizualizer_Logger::writeDebug($result['Body']);
         $lines = explode("\n", $result['Body']);
         $columns = array();
         $data = array();
         foreach ($lines as $index => $line) {
             if (!empty($line)) {
                 if ($index > 0) {
                     $item = str_getcsv($line);
                     $record = array();
                     foreach ($columns as $i => $key) {
                         $record[$key] = $item[$i];
                     }
                     $data[] = $record;
                 } else {
                     $columns = str_getcsv($line);
                 }
             }
         }
         Vizualizer_Logger::writeDebug(print_r($data, true));
         $sets = array();
         foreach ($data as $item) {
             if ($item["type"] == "summary") {
                 // トランザクションの開始
                 $connection = Vizualizer_Database_Factory::begin("stock");
                 try {
                     $loader = new Vizualizer_Plugin("stock");
                     $model = $loader->loadModel("Order");
                     $model->findByPrimaryKey($item["order_id"]);
                     if (!($model->order_id > 0)) {
                         $model = $loader->loadModel("Order", array("order_id" => $item["order_id"]));
                     }
                     $model->user_id = $item["user_id"];
                     $model->payment_type = $item["payment_type"];
                     $model->order_date = $item["purchase_date"];
                     $model->price = $item["price"];
                     $model->save();
                     // エラーが無かった場合、処理をコミットする。
                     Vizualizer_Database_Factory::commit($connection);
                 } catch (Exception $e) {
                     Vizualizer_Database_Factory::rollback($connection);
                     throw new Vizualizer_Exception_Database($e);
                 }
             }
             if ($item["type"] == "set") {
                 $sets[$item["order_id"] . "-" . $item["set_id"]] = $item;
                 // トランザクションの開始
                 $connection = Vizualizer_Database_Factory::begin("stock");
                 try {
                     $loader = new Vizualizer_Plugin("stock");
                     $model = $loader->loadModel("OrderDetail");
                     $model->order_id = $item["order_id"];
                     $model->set_id = $item["set_id"];
                     $model->set_menu_name = $item["set_menu_name"];
                     $model->order_date = $item["purchase_date"];
                     $model->price = $item["price"];
                     $model->quantity = $item["count"];
                     $model->save();
                     $model = $loader->loadModel("Menu");
                     $model->findBy(array("set_id" => $item["set_id"], "choice_id" => 0));
                     $model->set_id = $item["set_id"];
                     $model->set_menu_name = $sets[$item["order_id"] . "-" . $item["set_id"]]["set_menu_name"];
                     $model->menu_name = $item["menu_name"];
                     $model->price = $item["price"];
                     $model->fixed_flg = "1";
                     $model->save();
                     // エラーが無かった場合、処理をコミットする。
                     Vizualizer_Database_Factory::commit($connection);
                 } catch (Exception $e) {
                     Vizualizer_Database_Factory::rollback($connection);
                     throw new Vizualizer_Exception_Database($e);
                 }
                 // 在庫の引き当てを実施
                 $model = $loader->loadModel("OrderDetail");
                 $models = $model->findAllBy(array("set_id" => $item["set_id"], "ne:provision_flg" => "1"));
                 foreach ($models as $model) {
                     $model->provision();
                 }
             }
             if ($item["type"] == "choice") {
                 // トランザクションの開始
                 $connection = Vizualizer_Database_Factory::begin("stock");
                 try {
                     $loader = new Vizualizer_Plugin("stock");
                     $model = $loader->loadModel("OrderDetail");
                     $model->order_id = $item["order_id"];
                     $model->set_id = $item["set_id"];
                     $model->choice_id = $item["choice_id"];
                     $model->set_menu_name = $sets[$item["order_id"] . "-" . $item["set_id"]]["set_menu_name"];
                     $model->menu_name = $item["menu_name"];
                     $model->price = $item["price"];
                     $model->quantity = $sets[$item["order_id"] . "-" . $item["set_id"]]["count"];
                     $model->save();
                     $model = $loader->loadModel("Menu");
                     $model->findBy(array("set_id" => $item["set_id"], "choice_id" => $item["choice_id"]));
                     $model->set_id = $item["set_id"];
                     $model->choice_id = $item["choice_id"];
                     $model->set_menu_name = $sets[$item["order_id"] . "-" . $item["set_id"]]["set_menu_name"];
                     $model->menu_name = $item["menu_name"];
                     $model->price = $item["price"];
                     $model->fixed_flg = "1";
                     $model->save();
                     // エラーが無かった場合、処理をコミットする。
                     Vizualizer_Database_Factory::commit($connection);
                 } catch (Exception $e) {
                     Vizualizer_Database_Factory::rollback($connection);
                     throw new Vizualizer_Exception_Database($e);
                 }
                 // 在庫の引き当てを実施
                 $model = $loader->loadModel("OrderDetail");
                 $models = $model->findAllBy(array("set_id" => $item["set_id"], "choice_id" => $item["choice_id"], "ne:provision_flg" => "1"));
                 foreach ($models as $model) {
                     $model->provision();
                 }
             }
         }
     } catch (S3Exception $e) {
         echo $e->getMessage() . "\n";
     }
     return $data;
 }
/**
 * Smarty {loadmodule} function plugin
 *
 * Type: function<br>
 * Name: loadmodule<br>
 * Purpose: load framework module.<br>
 *
 * @author Naohisa Minagawa <minagawa at web-life dot co dot jp>
 * @param array $params parameters
 * @param object $smarty Smarty object
 * @param object $template template object
 * @return string null
 */
function smarty_function_loadmodule($params, $template)
{
    // nameパラメータは必須です。
    if (empty($params['name'])) {
        trigger_error("loadmodule: missing name parameter", E_USER_WARNING);
        return;
    }
    if (!empty($params["if"])) {
        $result = true;
        $expression = '$result = ' . str_replace('_POST', '$_POST', $params["if"]) . ';';
        eval($expression);
        if (!$result) {
            return;
        }
    }
    // パラメータを変数にコピー
    $name = $params['name'];
    // errorパラメータはエラー例外時に指定されたテンプレートに変更する。
    if (isset($params["error"])) {
        $error = $params['error'];
    } else {
        $error = "";
    }
    // モジュールのクラスが利用可能か調べる。
    $errors = null;
    try {
        // モジュール用のクラスをリフレクション
        list($namespace, $class) = explode(".", $name, 2);
        $loader = new Vizualizer_Plugin($namespace);
        $object = $loader->loadModule($class);
        if (method_exists($object, "start")) {
            Vizualizer_Logger::writeDebug("=========== " . $name . " start ===========");
            // 検索条件と並べ替えキー以外を無効化する。
            if (isset($params["clear"]) && $params["clear"] == "1") {
                if (isset($params["sort_key"]) && !empty($params["sort_key"])) {
                    $_POST = array("search" => $_POST["search"], $params["sort_key"] => $_POST[$params["sort_key"]]);
                } else {
                    $_POST = array("search" => $_POST["search"]);
                }
            }
            if (!empty($params["key_prefix"])) {
                $object->key_prefix = $params["key_prefix"];
            } else {
                $object->key_prefix = "";
            }
            if (!empty($params["continue"])) {
                $object->continue = $params["continue"];
            } else {
                $object->continue = "";
            }
            $object->execute(new Vizualizer_Plugin_Module_Parameters($params));
            Vizualizer_Logger::writeDebug("=========== " . $name . " end ===========");
        } else {
            Vizualizer_Logger::writeAlert($name . " is not plugin module.");
        }
    } catch (Vizualizer_Exception_Invalid $e) {
        // 入力エラーなどの例外(ただし、メッセージリストを空にすると例外処理を行わない)
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = $e->getErrors();
    } catch (Vizualizer_Exception_Database $e) {
        // システムエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_DATABASE => $e->getMessage());
    } catch (Vizualizer_Exception_System $e) {
        // システムエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_SYSTEM => $e->getMessage());
    } catch (Exception $e) {
        // 不明なエラーの例外処理
        Vizualizer_Logger::writeError($e->getMessage(), $e);
        $errors = array(Vizualizer::ERROR_TYPE_UNKNOWN => $e->getMessage());
    }
    // エラー配列をスタックさせる
    if (is_array($errors) && !empty($errors)) {
        $attr = Vizualizer::attr();
        // エラー用配列が配列になっていない場合は初期化
        $errorData = $attr[Vizualizer::ERROR_KEY];
        if (!is_array($errorData)) {
            $errorData = array();
        }
        // エラー内容をマージさせる。
        foreach ($errors as $key => $message) {
            if ($key != "" && !array_key_exists($key, $errorData)) {
                $errorData[$key] = $message;
            }
        }
        $templateEngine = $attr["template"];
        if (!empty($error)) {
            // errorパラメータが渡っている場合はスタックさせたエラーを全て出力してエラー画面へ
            $templateEngine->assign("ERRORS", $errorData);
            unset($attr[Vizualizer::ERROR_KEY]);
            $info = pathinfo($error);
            switch ($info["extension"]) {
                case "php":
                    // PHPを実行する場合、インクルードパスの最優先をテンプレートのディレクトリに設定
                    ini_set("include_path", Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . PATH_SEPARATOR . ini_get("include_path"));
                    $source = file_get_contents(Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . DIRECTORY_SEPARATOR . $error);
                    // 先頭のPHPタグを除去
                    $source = "?>" . $source;
                    // バッファを除去
                    ob_end_clean();
                    ob_start();
                    eval($source);
                    // 実行後のデータを取得し、バッファを再度除去
                    $source = ob_get_contents();
                    ob_end_clean();
                    ob_start();
                    // ソースデータをリソース化
                    $source = "eval:" . $source;
                    // テンプレートを表示
                    $templateEngine->display($source);
                    exit;
                default:
                    $templateEngine->display($error);
                    exit;
            }
        } else {
            $attr[Vizualizer::ERROR_KEY] = $errorData;
        }
    }
}
Example #15
0
 /**
  * 実行時間計測用のタイマーをリセットする。
  */
 public static function printTimer()
 {
     $time = microtime(TRUE) * 1000;
     Vizualizer_Logger::writeDebug("【Timer】【" . self::$timerName . "】" . round($time - self::$preTimer, 2) . "msec(" . round($time - self::$baseTimer, 2) . "msec)");
     self::$preTimer = $time;
 }