/**
  * Page のプロセス.
  *
  * @return void
  */
 function process()
 {
     $conn = new SC_DBConn();
     $objView = new SC_AdminView();
     $objSess = new SC_Session();
     $objDb = new SC_Helper_DB_Ex();
     // 認証可否の判定
     SC_Utils_Ex::sfIsSuccess($objSess);
     // パラメータ管理クラス
     $this->objFormParam = new SC_FormParam();
     // パラメータ情報の初期化
     $this->lfInitParam();
     // POST値の取得
     $this->objFormParam->setParam($_POST);
     // 通常時は親カテゴリを0に設定する。
     $this->arrForm['parent_category_id'] = isset($_POST['parent_category_id']) ? $_POST['parent_category_id'] : "";
     if (!isset($_POST['mode'])) {
         $_POST['mode'] = "";
     }
     switch ($_POST['mode']) {
         case 'edit':
             $this->objFormParam->convParam();
             $arrRet = $this->objFormParam->getHashArray();
             $this->arrErr = $this->lfCheckError($arrRet);
             if (count($this->arrErr) == 0) {
                 if ($_POST['category_id'] == "") {
                     $objQuery = new SC_Query();
                     $count = $objQuery->count("dtb_category");
                     if ($count < CATEGORY_MAX) {
                         $this->lfInsertCat($_POST['parent_category_id']);
                     } else {
                         print "カテゴリの登録最大数を超えました。";
                     }
                 } else {
                     $this->lfUpdateCat($_POST['category_id']);
                 }
             } else {
                 $this->arrForm = array_merge($this->arrForm, $this->objFormParam->getHashArray());
                 $this->arrForm['category_id'] = $_POST['category_id'];
             }
             break;
         case 'pre_edit':
             // 編集項目のカテゴリ名をDBより取得する。
             $oquery = new SC_Query();
             $where = "category_id = ?";
             $cat_name = $oquery->get("dtb_category", "category_name", $where, array($_POST['category_id']));
             $description = $oquery->get("dtb_category", "description", $where, array($_POST['category_id']));
             // 入力項目にカテゴリ名を入力する。
             $this->arrForm['category_name'] = $cat_name;
             $this->arrForm['description'] = $description;
             // POSTデータを引き継ぐ
             $this->arrForm['category_id'] = $_POST['category_id'];
             break;
         case 'delete':
             $objQuery = new SC_Query();
             // 子カテゴリのチェック
             $where = "parent_category_id = ? AND del_flg = 0";
             $count = $objQuery->count("dtb_category", $where, array($_POST['category_id']));
             if ($count != 0) {
                 $this->arrErr['category_name'] = "※ 子カテゴリが存在するため削除できません。<br>";
             }
             // 登録商品のチェック
             $table = "dtb_product_categories AS T1 LEFT JOIN dtb_products AS T2 ON T1.product_id = T2.product_id";
             $where = "T1.category_id = ? AND T2.del_flg = 0";
             $count = $objQuery->count($table, $where, array($_POST['category_id']));
             if ($count != 0) {
                 $this->arrErr['category_name'] = "※ カテゴリ内に商品が存在するため削除できません。<br>";
             }
             if (!isset($this->arrErr['category_name'])) {
                 // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。)
                 $objDb->sfDeleteRankRecord("dtb_category", "category_id", $_POST['category_id'], "", true);
             }
             break;
         case 'up':
             $objQuery = new SC_Query();
             $objQuery->begin();
             $up_id = $this->lfGetUpRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']);
             if ($up_id != "") {
                 // 上のグループのrankから減算する数
                 $my_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']);
                 // 自分のグループのrankに加算する数
                 $up_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id);
                 if ($my_count > 0 && $up_count > 0) {
                     // 自分のグループに加算
                     $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $up_count);
                     // 上のグループから減算
                     $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id, $my_count);
                 }
             }
             $objQuery->commit();
             break;
         case 'down':
             $objQuery = new SC_Query();
             $objQuery->begin();
             $down_id = $this->lfGetDownRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']);
             if ($down_id != "") {
                 // 下のグループのrankに加算する数
                 $my_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']);
                 // 自分のグループのrankから減算する数
                 $down_count = $this->lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id);
                 if ($my_count > 0 && $down_count > 0) {
                     // 自分のグループから減算
                     $this->lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id, $my_count);
                     // 下のグループに加算
                     $this->lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $down_count);
                 }
             }
             $objQuery->commit();
             break;
         case 'tree':
             break;
         case 'csv':
             require_once CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php";
             $objCSV = new SC_Helper_CSV_Ex();
             // オプションの指定
             $option = "ORDER BY rank DESC";
             // CSV出力タイトル行の作成
             $arrOutput = SC_Utils_Ex::sfSwapArray($objCSV->sfgetCsvOutput(5, " WHERE csv_id = 5 AND status = 1"));
             if (count($arrOutput) <= 0) {
                 break;
             }
             $arrOutputCols = $arrOutput['col'];
             $arrOutputTitle = $arrOutput['disp_name'];
             $head = SC_Utils_Ex::sfGetCSVList($arrOutputTitle);
             $where = "del_flg = 0";
             $data = $objCSV->lfGetCategoryCSV($where, $option, $arrval, $arrOutputCols);
             // CSVを送信する。
             SC_Utils_Ex::sfCSVDownload($head . $data, 'category');
             exit;
             break;
         default:
             $this->arrForm['parent_category_id'] = 0;
             break;
     }
     $this->arrList = $this->lfGetCat($this->arrForm['parent_category_id']);
     $this->arrTree = $objDb->sfGetCatTree($this->arrForm['parent_category_id']);
     $objView->assignobj($this);
     $objView->display(MAIN_FRAME);
 }