Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_Contents_Inquiry.php

Documentation is available at LC_Page_Admin_Contents_Inquiry.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. // {{{ requires
  25. require_once(CLASS_PATH . "pages/LC_Page.php");
  26.  
  27. /**
  28.  * アンケート管理 のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id$
  33.  */
  34.  
  35.     // }}}
  36.     // {{{ functions
  37.  
  38.     /**
  39.      * Page を初期化する.
  40.      *
  41.      * @return void 
  42.      */
  43.     function init() {
  44.         parent::init();
  45.         $this->tpl_mainpage = 'contents/inquiry.tpl';
  46.         $this->tpl_mainno = 'contents';
  47.         $this->tpl_subnavi = 'contents/subnavi.tpl';
  48.         $this->tpl_subno = "inquiry";
  49.         $this->tpl_subtitle = 'アンケート管理';
  50.         $this->arrCVSCOL = array(
  51.  
  52.                 );
  53.  
  54.         $this->arrCVSTITLE = array(
  55.                              '回答ID',
  56.                              '質問ID',
  57.                              '回答日時',
  58.                              'アンケートタイトル',
  59.                              '顧客名1',
  60.                              '顧客名2',
  61.                              '顧客名カナ1',
  62.                              '顧客名カナ2',
  63.                              '郵便番号1',
  64.                              '郵便番号2',
  65.                              '都道府県',
  66.                              '住所1',
  67.                              '住所2',
  68.                              '電話番号1',
  69.                              '電話番号2',
  70.                              '電話番号3',
  71.                              'メールアドレス',
  72.                              '回答1',
  73.                              '回答2',
  74.                              '回答3',
  75.                              '回答4',
  76.                              '回答5',
  77.                              '回答6'
  78.                              );
  79.     }
  80.  
  81.     /**
  82.      * Page のプロセス.
  83.      *
  84.      * @return void 
  85.      */
  86.     function process() {
  87.         $objQuery = new SC_Query();
  88.         $objView = new SC_AdminView();
  89.         $objSess = new SC_Session();
  90.  
  91.         // 認証可否の判定
  92.         SC_Utils_Ex::sfIsSuccess($objSess);
  93.  
  94.         $arrActive = array( "0"=>"稼働", "1"=>"非稼働" );
  95.         $arrQuestion = array( "0"=>"使用しない", "1"=>"テキストエリア", "2"=>"テキストボックス"
  96.                               , "3"=>"チェックボックス", "4"=>"ラジオボタン"
  97.                               );
  98.  
  99.         $result = $objQuery->select('*, cast(create_date as date) as disp_date', 'dtb_question', 'del_flg = 0 ORDER BY question_id');
  100.         $this->list_data = $result;
  101.  
  102.         if (!isset($_GET['mode'])) $_GET['mode'] = "";
  103.  
  104.         // アンケートを作成ボタン押下時
  105.         if ( $_GET['mode'] == 'regist' ){
  106.  
  107.             for ( $i=0; $i<count($_POST["question"]); $i++ ) {
  108.                 $_POST['question'][$i]['name'] = mb_convert_kana( trim ( $_POST['question'][$i]['name'] ), "K" );
  109.                 for ( $j=0; $j<count( $_POST['question'][$i]['option'] ); $j++ ){
  110.                     $_POST['question'][$i]['option'][$j] = mb_convert_kana( trim ( $_POST['question'][$i]['option'][$j] ) );
  111.                 }
  112.             }
  113.  
  114.             for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
  115.                 if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
  116.                     $temp_data = array();
  117.                     // 項目間(テキストボックス)があいていたら詰めていく
  118.                     for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
  119.                         if( strlen( $_POST["question"][$i]["option"][$j] ) > 0 ) $temp_data[] = mb_convert_kana( trim ( $_POST["question"][$i]["option"][$j]  ), "asKVn" );
  120.                     }
  121.                     $_POST["question"][$i]["option"] = $temp_data;
  122.                 } else {
  123.                     $_POST["question"][$i]["option"] = NULL;
  124.                 }
  125.             }
  126.  
  127.             $error = $this->lfErrCheck();
  128.  
  129.             if ( ! $error  ){
  130.                 // 新規登録
  131.                 if ( ! is_numeric($_POST['question_id']) ){
  132.  
  133.                     //登録
  134.                     $value = serialize($_POST);
  135.                     if (DB_TYPE == "pgsql") {
  136.                         $question_id = $objQuery->nextval('dtb_question', 'question_id');
  137.                     }
  138.  
  139.                     $sql_val = array( 'question' => $value, 'question_name' => $_POST['title'] ,'question_id' => $question_id ,'create_date' => 'now()');
  140.                     $objQuery->insert('dtb_question', $sql_val);
  141.                     $this->MESSAGE = "登録が完了しました";
  142.  
  143.                     if (DB_TYPE == "mysql") {
  144.                         $question_id = $objQuery->nextval('dtb_question', 'question_id');
  145.                     }
  146.  
  147.                     $this->QUESTION_ID = $question_id;
  148.                     $this->reload(null, true);
  149.  
  150.                 // 編集
  151.                 } else {
  152.                     //編集
  153.                     $value = serialize($_POST);
  154.                     $sql_val = array( 'question'=>$value, 'question_name'=>$_POST['title'] );
  155.                     $objQuery->update('dtb_question', $sql_val, 'question_id = ?',  array($_POST['question_id']) );
  156.                     $this->MESSAGE = "編集が完了しました";
  157.                     $this->QUESTION_ID = $_POST['question_id'];
  158.                     $this->reload(null, true);
  159.                 }
  160.             } else {
  161.  
  162.                 //エラー表示
  163.                 $this->ERROR = $error;
  164.                 $this->QUESTION_ID = $_REQUEST['question_id'];
  165.                 $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR);
  166.             }
  167.  
  168.         // 削除ボタン押下時
  169.         } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) )  ){
  170.  
  171.             $sqlval = array('del_flg' => 1);
  172.             $objQuery->update('dtb_question', $sqlval, 'question_id = ?', array( $_GET['question_id'] ) );
  173.             $this->reload(null, true);
  174.  
  175.         // CSVダウンロードボタン押下時
  176.         } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){
  177.             require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
  178.  
  179.             $objCSV = new SC_Helper_CSV_Ex();
  180.             $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE);
  181.             $sql =<<<__EOS__
  182.                     SELECT
  183.                          dtb_question_result.result_id
  184.                         ,dtb_question_result.question_id
  185.                         ,dtb_question_result.create_date
  186.                         ,dtb_question.question_name
  187.                         ,dtb_question_result.name01
  188.                         ,dtb_question_result.name02
  189.                         ,dtb_question_result.kana01
  190.                         ,dtb_question_result.kana02
  191.                         ,dtb_question_result.zip01
  192.                         ,dtb_question_result.zip02
  193.                         ,dtb_question_result.pref
  194.                         ,dtb_question_result.addr01
  195.                         ,dtb_question_result.addr02
  196.                         ,dtb_question_result.tel01
  197.                         ,dtb_question_result.tel02
  198.                         ,dtb_question_result.tel03
  199.                         ,dtb_question_result.mail01
  200.                         ,dtb_question_result.question01
  201.                         ,dtb_question_result.question02
  202.                         ,dtb_question_result.question03
  203.                         ,dtb_question_result.question04
  204.                         ,dtb_question_result.question05
  205.                         ,dtb_question_result.question06
  206.                     FROM dtb_question_result
  207.                         LEFT JOIN dtb_question
  208.                             ON dtb_question_result.question_id = dtb_question.question_id
  209.                     WHERE 0=0
  210.                         AND dtb_question_result.del_flg = 0
  211.                         AND dtb_question_result.question_id = ?
  212.                     ORDER BY dtb_question_result.result_id ASC
  213. __EOS__;
  214.  
  215.             $list_data = $objQuery->getAll($sql, array($_GET['question_id']));
  216.             $data = "";
  217.             for($i = 0; $i < count($list_data); $i++) {
  218.                 // 各項目をCSV出力用に変換する。
  219.                 $data .= $objCSV->lfMakeCSV($list_data[$i]);
  220.             }
  221.             // CSVを送信する
  222.             SC_Utils_Ex::sfCSVDownload($head.$data);
  223.             exit;
  224.  
  225.         // 初回表示 or 編集ボタン押下時
  226.         } else {
  227.             if (!isset($_GET['question_id'])) $_GET['question_id'] = "";
  228.  
  229.             if ( is_numeric($_GET['question_id']) ){
  230.  
  231.                 $sql = "SELECT question FROM dtb_question WHERE question_id = ?";
  232.                 $result = $objQuery->getOne($sql, array($_GET['question_id']));
  233.  
  234.                 if ( $result ){
  235.                     $_POST = unserialize( $result );
  236.                     $this->QUESTION_ID = $_GET['question_id'];
  237.                 }
  238.             }
  239.         }
  240.  
  241.         //各ページ共通
  242.         $this->cnt_question = 6;
  243.         $this->arrActive = $arrActive;
  244.         $this->arrQuestion = $arrQuestion;
  245.  
  246.         //---- ページ表示
  247.         $objView->assignobj($this);
  248.         $objView->display(MAIN_FRAME);
  249.     }
  250.  
  251.     /**
  252.      * デストラクタ.
  253.      *
  254.      * @return void 
  255.      */
  256.     function destroy() {
  257.         parent::destroy();
  258.     }
  259.  
  260.     // ------------  エラーチェック処理部 ------------
  261.  
  262.     function lfGetErrColor( $arr, $err_color ){
  263.  
  264.         foreach ( $arr as $key=>$val ) {
  265.             if ( is_string($val) && strlen($val) > 0 ){
  266.                 $return[$key] = $err_color;
  267.             } elseif ( is_array( $val ) ) {
  268.                 $return[$key] = $this->lfGetErrColor ( $val, $err_color);
  269.             }
  270.         }
  271.         return $return;
  272.     }
  273.  
  274.  
  275.     // ------------  エラーチェック処理部 ------------
  276.  
  277.     function lfErrCheck (){
  278.  
  279.         $objErr = new SC_CheckError();
  280.         $errMsg = "";
  281.  
  282.         $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) );
  283.  
  284.         $_POST["title"] = mb_convert_kana( trim (  $_POST["title"] ), "K" );
  285.         $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) );
  286.  
  287.         $_POST["contents"] = mb_convert_kana( trim (  $_POST["contents"] ), "K" );
  288.         $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
  289.  
  290.  
  291.         if ( ! $_POST['question'][0]["name"] ){
  292.             $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません";
  293.         }
  294.  
  295.         // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。
  296.         for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
  297.  
  298.             if ( $_POST["question"][$i]["kind"] ) {
  299.                 if (strlen($_POST["question"][$i]["name"]) == 0) {
  300.                     $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。";
  301.                 } else if ( strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) {
  302.                     $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN  ."字以内で入力して下さい。";
  303.                 }
  304.             }
  305.  
  306.             if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
  307.  
  308.                 for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
  309.                     // 同じ回答がないかチェック
  310.                     if (strlen($_POST["question"][$i]["option"][$j]) > 0) {
  311.                         $checkArray = $_POST["question"][$i]["option"];
  312.                         // 自身の値をunset
  313.                         unset($checkArray[$j]);
  314.                         if (in_array($_POST["question"][$i]["option"][$j], $checkArray)) {
  315.                             $objErr->arrErr["question"][$i]["option"][$j] = "同じ質問に同じ回答は設定出来ません。";
  316.                         }
  317.                     }
  318.                 }
  319.  
  320.                 if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0
  321.                                                                                  && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。";
  322.  
  323.             }
  324.         }
  325.  
  326.         return $this->lfGetArrInput( $objErr->arrErr );
  327.  
  328.     }
  329.  
  330.  
  331.     function lfGetArrInput( $arr ){
  332.         // 値が入力された配列のみを返す
  333.  
  334.         if ( is_array($arr) ){
  335.             foreach ( $arr as $key=>$val ) {
  336.                 if ( is_string($val) && strlen($val) > 0 ){
  337.                     $return[$key] = $val;
  338.                 } elseif ( is_array( $val ) ) {
  339.                     $data = $this->lfGetArrInput ( $val );
  340.                     if ( $data ){
  341.                         $return[$key] = $data;
  342.                     }
  343.                 }
  344.             }
  345.         }
  346.         return $return;
  347.     }
  348. }
  349. ?>

Documentation generated on Fri, 24 Feb 2012 13:58:36 +0900 by Seasoft