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-2007 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.         $conn = new SC_DBConn();
  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.         $sql = "SELECT *, cast(create_date as date) as disp_date FROM dtb_question WHERE del_flg = 0 ORDER BY question_id";
  100.         $result = $conn->getAll($sql);
  101.         $this->list_data = $result;
  102.  
  103.         if (!isset($_GET['mode'])) $_GET['mode'] = "";
  104.  
  105.         // アンケートを作成ボタン押下時
  106.         if ( $_GET['mode'] == 'regist' ){
  107.  
  108.             for ( $i=0; $i<count($_POST["question"]); $i++ ) {
  109.                 $_POST['question'][$i]['name'] = mb_convert_kana( trim ( $_POST['question'][$i]['name'] ), "K" );
  110.                 for ( $j=0; $j<count( $_POST['question'][$i]['option'] ); $j++ ){
  111.                     $_POST['question'][$i]['option'][$j] = mb_convert_kana( trim ( $_POST['question'][$i]['option'][$j] ) );
  112.                 }
  113.             }
  114.  
  115.             $error = $this->lfErrCheck();
  116.  
  117.             if ( ! $error  ){
  118.                 // 新規登録
  119.                 if ( ! is_numeric($_POST['question_id']) ){
  120.                     $objQuery = new SC_Query();
  121.  
  122.                     //登録
  123.                     $value = serialize($_POST);
  124.                     if (DB_TYPE == "pgsql") {
  125.                         $question_id = $objQuery->nextval('dtb_question', 'question_id');
  126.                     }
  127.  
  128.                     $sql_val = array( $value, $_POST['title'] ,$question_id );
  129.                     $conn->query("INSERT INTO dtb_question ( question, question_name, question_id, create_date) VALUES (?, ?, ?, now())", $sql_val );
  130.                     $this->MESSAGE = "登録が完了しました";
  131.  
  132.                     if (DB_TYPE == "mysql") {
  133.                         $question_id = $objQuery->nextval('dtb_question', 'question_id');
  134.                     }
  135.  
  136.                     $this->QUESTION_ID = $question_id;
  137.                     $this->reload(null, true);
  138.  
  139.                 // 編集
  140.                 } else {
  141.                     //編集
  142.                     $value = serialize($_POST);
  143.                     $sql_val = array( $value, $_POST['title'] ,$_POST['question_id'] );
  144.                     $conn->query("UPDATE dtb_question SET question = ?, question_name = ? WHERE question_id = ?", $sql_val );
  145.                     $this->MESSAGE = "編集が完了しました";
  146.                     $this->QUESTION_ID = $_POST['question_id'];
  147.                     $this->reload(null, true);
  148.                 }
  149.             } else {
  150.  
  151.                 //エラー表示
  152.                 $this->ERROR = $error;
  153.                 $this->QUESTION_ID = $_REQUEST['question_id'];
  154.                 $this->ERROR_COLOR = $this->lfGetErrColor($error, ERR_COLOR);
  155.             }
  156.  
  157.         // 削除ボタン押下時
  158.         } elseif ( ( $_GET['mode'] == 'delete' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) )  ){
  159.  
  160.             $sql = "UPDATE dtb_question SET del_flg = 1 WHERE question_id = ?";
  161.             $conn->query( $sql, array( $_GET['question_id'] ) );
  162.             $this->reload(null, true);
  163.  
  164.         // CSVダウンロードボタン押下時
  165.         } elseif ( ( $_GET['mode'] == 'csv' ) && ( SC_Utils_Ex::sfCheckNumLength($_GET['question_id']) ) ){
  166.             require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
  167.  
  168.             $objCSV = new SC_Helper_CSV_Ex();
  169.             $head = SC_Utils_Ex::sfGetCSVList($this->arrCVSTITLE);
  170.             $sql =<<<__EOS__
  171.                 SELECT
  172.                      dtb_question_result.result_id
  173.                     ,dtb_question_result.question_id
  174.                     ,dtb_question_result.create_date
  175.                     ,dtb_question.question_name
  176.                     ,dtb_question_result.name01
  177.                     ,dtb_question_result.name02
  178.                     ,dtb_question_result.kana01
  179.                     ,dtb_question_result.kana02
  180.                     ,dtb_question_result.zip01
  181.                     ,dtb_question_result.zip02
  182.                     ,dtb_question_result.pref
  183.                     ,dtb_question_result.addr01
  184.                     ,dtb_question_result.addr02
  185.                     ,dtb_question_result.tel01
  186.                     ,dtb_question_result.tel02
  187.                     ,dtb_question_result.tel03
  188.                     ,dtb_question_result.mail01
  189.                     ,dtb_question_result.question01
  190.                     ,dtb_question_result.question02
  191.                     ,dtb_question_result.question03
  192.                     ,dtb_question_result.question04
  193.                     ,dtb_question_result.question05
  194.                     ,dtb_question_result.question06
  195.                 FROM dtb_question_result
  196.                     LEFT JOIN dtb_question
  197.                         ON dtb_question_result.question_id = dtb_question.question_id
  198.                 WHERE 0=0
  199.                     AND dtb_question_result.del_flg = 0
  200.                     AND dtb_question_result.question_id = ?
  201.                 ORDER BY dtb_question_result.result_id ASC
  202. __EOS__;
  203.             $list_data = $conn->getAll($sql, array($_GET['question_id']));
  204.             $data = "";
  205.             for($i = 0; $i < count($list_data); $i++) {
  206.                 // 各項目をCSV出力用に変換する。
  207.                 $data .= $objCSV->lfMakeCSV($list_data[$i]);
  208.             }
  209.             // CSVを送信する
  210.             SC_Utils_Ex::sfCSVDownload($head.$data);
  211.             exit;
  212.  
  213.         // 初回表示 or 編集ボタン押下時
  214.         } else {
  215.             if (!isset($_GET['question_id'])) $_GET['question_id'] = "";
  216.  
  217.             if ( is_numeric($_GET['question_id']) ){
  218.  
  219.                 $sql = "SELECT question FROM dtb_question WHERE question_id = ?";
  220.                 $result = $conn->getOne($sql, array($_GET['question_id']));
  221.  
  222.                 if ( $result ){
  223.                     $_POST = unserialize( $result );
  224.                     $this->QUESTION_ID = $_GET['question_id'];
  225.                 }
  226.             }
  227.         }
  228.  
  229.         //各ページ共通
  230.         $this->cnt_question = 6;
  231.         $this->arrActive = $arrActive;
  232.         $this->arrQuestion = $arrQuestion;
  233.  
  234.         //---- ページ表示
  235.         $objView->assignobj($this);
  236.         $objView->display(MAIN_FRAME);
  237.     }
  238.  
  239.     /**
  240.      * デストラクタ.
  241.      *
  242.      * @return void 
  243.      */
  244.     function destroy() {
  245.         parent::destroy();
  246.     }
  247.  
  248.     // ------------  エラーチェック処理部 ------------
  249.  
  250.     function lfGetErrColor( $arr, $err_color ){
  251.  
  252.         foreach ( $arr as $key=>$val ) {
  253.             if ( is_string($val) && strlen($val) > 0 ){
  254.                 $return[$key] = $err_color;
  255.             } elseif ( is_array( $val ) ) {
  256.                 $return[$key] = $this->lfGetErrColor ( $val, $err_color);
  257.             }
  258.         }
  259.         return $return;
  260.     }
  261.  
  262.  
  263.     // ------------  エラーチェック処理部 ------------
  264.  
  265.     function lfErrCheck (){
  266.  
  267.         $objErr = new SC_CheckError();
  268.         $errMsg = "";
  269.  
  270.         $objErr->doFunc( array( "稼働・非稼働", "active" ), array( "SELECT_CHECK" ) );
  271.  
  272.         $_POST["title"] = mb_convert_kana( trim (  $_POST["title"] ), "K" );
  273.         $objErr->doFunc( array( "アンケート名", "title" ), array( "EXIST_CHECK" ) );
  274.  
  275.         $_POST["contents"] = mb_convert_kana( trim (  $_POST["contents"] ), "K" );
  276.         $objErr->doFunc( array( "アンケート内容" ,"contents", "3000" ), array( "EXIST_CHECK", "MAX_LENGTH_CHECK" ) );
  277.  
  278.  
  279.         if ( ! $_POST['question'][0]["name"] ){
  280.             $objErr->arrErr['question'][0]["name"] = "1つめの質問名が入力されていません";
  281.         }
  282.  
  283.         // チェックボックス、ラジオボタンを選択した場合は最低1つ以上項目を記入させる。
  284.         for( $i = 0; $i < count( $_POST["question"] ); $i++ ) {
  285.  
  286.             if ( $_POST["question"][$i]["kind"] ) {
  287.                 if (strlen($_POST["question"][$i]["name"]) == 0) {
  288.                     $objErr->arrErr["question"][$i]["name"] = "タイトルを入力して下さい。";
  289.                 } else if ( mb_strlen($_POST["question"][$i]["name"]) > STEXT_LEN ) {
  290.                     $objErr->arrErr["question"][$i]["name"] = "タイトルは". STEXT_LEN  ."字以内で入力して下さい。";
  291.                 }
  292.             }
  293.  
  294.             if( $_POST["question"][$i]["kind"] == 3 || $_POST["question"][$i]["kind"] == 4  ) {
  295.  
  296.                 $temp_data = array();
  297.                 for( $j = 0; $j < count( $_POST["question"][$i]["option"] ); $j++ ) {
  298.  
  299.                     // 項目間(テキストボックス)があいていたら詰めていく
  300.                     if( strlen( $_POST["question"][$i]["option"][$j] ) > 0 ) $temp_data[] = mb_convert_kana( trim ( $_POST["question"][$i]["option"][$j]  ), "asKVn" );
  301.  
  302.                 }
  303.  
  304.                 $_POST["question"][$i]["option"] = $temp_data;
  305.  
  306.                 if( ( strlen( $_POST["question"][$i] ["option"][0] ) == 0 ) || ( strlen( $_POST["question"][$i] ["option"][0] ) > 0
  307.                                                                                  && strlen( $_POST["question"][$i] ["option"][1] ) == 0 ) ) $objErr->arrErr["question"][$i]['kind'] = "下記の2つ以上の項目に記入してください。";
  308.             }
  309.         }
  310.  
  311.         return $this->lfGetArrInput( $objErr->arrErr );
  312.  
  313.     }
  314.  
  315.  
  316.     function lfGetArrInput( $arr ){
  317.         // 値が入力された配列のみを返す
  318.  
  319.         if ( is_array($arr) ){
  320.             foreach ( $arr as $key=>$val ) {
  321.                 if ( is_string($val) && strlen($val) > 0 ){
  322.                     $return[$key] = $val;
  323.                 } elseif ( is_array( $val ) ) {
  324.                     $data = $this->lfGetArrInput ( $val );
  325.                     if ( $data ){
  326.                         $return[$key] = $data;
  327.                     }
  328.                 }
  329.             }
  330.         }
  331.         return $return;
  332.     }
  333. }
  334. ?>

Documentation generated on Tue, 28 Apr 2009 18:10:58 +0900 by phpDocumentor 1.4.2