function execute(&$controller, &$request, &$user)
 {
     // FIXME
     $id = isset($_REQUEST['qid']) ? intval($_REQUEST['qid']) : 0;
     // FIXME
     $handler =& plzXoo::getHandler('question');
     $question =& $handler->get($id);
     if (!is_object($question)) {
         return VIEW_ERROR;
     }
     // 権限の確認
     if (!$question->isEnableDelete($user)) {
         $request->setAttribute('message', _MD_PLZXOO_ERROR_PERMISSION);
         return VIEW_ERROR;
     }
     // FIXME
     $editform = new exConfirmTicketForm();
     $editform->setErrorMessage(_MD_PLZXOO_ERROR_TICKET);
     if ($editform->init(strtolower(get_class($this))) == ACTIONFORM_POST_SUCCESS) {
         $editform->release();
         return $handler->delete($question) ? VIEW_SUCCESS : VIEW_ERROR;
     }
     $handler =& plzXoo::getHandler('category');
     $category =& $handler->get($question->getVar('cid'));
     $request->setAttribute('editform', $editform);
     $request->setAttribute('question', $question);
     $request->setAttribute('category', $category);
     return VIEW_INPUT;
 }
 function delete(&$obj, $force = false)
 {
     // handlers
     $module_handler =& xoops_gethandler('module');
     $notification_handler =& xoops_gethandler('notification');
     $question_handler =& plzXoo::getHandler('question');
     $answer_handler =& plzXoo::getHandler('answer');
     // get this module
     $module =& $module_handler->getByDirname('plzXoo');
     $module_id = $module->getVar('mid');
     // ----------------------------------------------
     // 子カテゴリーがあったらエラー
     // ----------------------------------------------
     $cid = $obj->getVar('cid');
     $child_handler =& plzXoo::getHandler('category');
     $children =& $child_handler->getObjects(new Criteria('pid', $cid));
     if (!empty($children)) {
         return false;
     }
     // ----------------------------------------------
     // ぶら下がっている質問・回答をすべて削除
     // ----------------------------------------------
     $questions =& $question_handler->getObjects(new Criteria('cid', $cid));
     foreach ($questions as $question) {
         $qid = $question->getVar('qid');
         $answers =& $answer_handler->getObjects(new Criteria('qid', $qid));
         foreach ($answers as $answer) {
             $answer_handler->delete($answer);
         }
         $question_handler->delete($question);
     }
     // delete notifications about this category
     $notification_handler->unsubscribeByItem($module_id, 'category', $obj->getVar('cid'));
     return parent::delete($obj, $force);
 }
 function &execute(&$controller, &$request, &$user)
 {
     $objs =& $request->getAttribute('questions');
     $questions = array();
     foreach ($objs as $obj) {
         $arr =& $obj->getStructure();
         $arr['size_str'] = @sprintf(_MD_PLZXOO_FORMAT_ANSWERS_COUNT, $arr['size']);
         $questions[] =& $arr;
         unset($arr);
     }
     $listController =& $request->getAttribute('listController');
     $renderer = new mojaLE_XoopsTplRenderer($controller, $request, $user);
     $renderer->setTemplate('plzxoo_index.html');
     $renderer->setAttribute('questions', $questions);
     $renderer->setAttribute('listController', $listController->getStructure());
     exFrame::init(EXFRAME_PERM);
     $renderer->setAttribute('enable_post_question', exPerm::isPerm('post_question'));
     $cat_handler =& plzXoo::getHandler('category');
     $cat_obj =& $cat_handler->get(intval(@$_GET['cid']));
     if (is_object($cat_obj)) {
         $cat_arr = $cat_obj->getStructure();
         $renderer->setAttribute('category', $cat_arr);
         $renderer->setAttribute('xoops_pagetitle', $cat_arr['name']);
     } else {
         $renderer->setAttribute('category', array('children' => plzXooCategoryObject::getChildren(0), 'cid' => 0));
         $renderer->setAttribute('searchtxt4disp', htmlspecialchars($listController->filter_->txt_, ENT_QUOTES));
     }
     /*
     		echo "<pre>" ;
     		var_dump( $cat_obj->getStructure() ) ;
     		exit ;*/
     return $renderer;
 }
 function execute(&$controller, &$request, &$user)
 {
     exFrame::init(EXFRAME_PERM);
     // 閲覧権限のチェック
     exPerm::GuardRedirect('view_detail', 'index.php', _MD_PLZXOO_ERROR_PERMISSION);
     $id = isset($_REQUEST['qid']) ? intval($_REQUEST['qid']) : 0;
     $handler =& plzXoo::getHandler('question');
     $question =& $handler->get($id);
     if (!is_object($question)) {
         return VIEW_ERROR;
     }
     // ステータスが1,2と異なるものは管理者以外キック
     if (!in_array($question->getVar('status'), array(1, 2))) {
         if (!is_object($GLOBALS['xoopsUser']) || !$GLOBALS['xoopsUser']->isAdmin()) {
             return VIEW_ERROR;
         }
     }
     $handler =& plzXoo::getHandler('answer');
     $criteria = new Criteria('qid', $id);
     $criteria->setSort('input_date');
     $criteria->setOrder('DESC');
     $answers =& $handler->getObjects($criteria);
     $request->setAttribute('question', $question);
     $request->setAttribute('answers', $answers);
     return VIEW_SUCCESS;
 }
 function init()
 {
     $handler =& plzXoo::getHandler('category');
     $this->listController_ = new ListController();
     $this->listController_->filter_ =& $this->filter_;
     $this->listController_->filter_->fetch();
     $this->listController_->fetch($handler->getCount($this->listController_->filter_->getCriteria()), 20);
     $objs = $handler->getObjects($this->listController_->getCriteria());
     foreach ($objs as $obj) {
         $this->_row_data_[] = $obj->getStructure();
     }
     return COMPONENT_MODEL_INIT_SUCCESS;
 }
 function &execute(&$controller, &$request, &$user)
 {
     $question =& $request->getAttribute('question');
     $answers_obj =& $request->getAttribute('answers');
     // prepare for points decoration
     $points = explode('|', @$GLOBALS['xoopsModuleConfig']['points']);
     rsort($points, SORT_NUMERIC);
     $point_decorations = array();
     $rank = 0;
     foreach ($points as $point) {
         $point = intval($point);
         $rank++;
         if (defined('_MD_PLZXOO_FORMAT_POINT_RESULT_RANK' . $rank)) {
             $point_decorations[$point] = sprintf(constant('_MD_PLZXOO_FORMAT_POINT_RESULT_RANK' . $rank), $point);
         } else {
             $point_decorations[$point] = sprintf(_MD_PLZXOO_FORMAT_POINT_RESULT_GENERAL, $point);
         }
     }
     $answers = array();
     foreach ($answers_obj as $answer) {
         $ret = $answer->getStructure();
         $ret['enable_edit'] = $answer->isEnableEdit($user);
         $ret['enable_delete'] = $answer->isEnableDelete($user);
         $ret['point_decorated'] = empty($point_decorations[$ret['point']]) ? $ret['point'] : $point_decorations[$ret['point']];
         $answers[] =& $ret;
         unset($ret);
     }
     // 権限チェック
     $question_arr = $question->getStructure();
     $question_arr['enable_edit'] = $question->isEnableEdit($user);
     $question_arr['enable_delete'] = $question->isEnableDelete($user);
     // メッセージ権限のチェック
     $question_arr['enable_message'] = is_object($user) ? $user->isAdmin() || $user->uid() == $question->getVar('uid') : false;
     $renderer = new mojaLE_XoopsTplRenderer($controller, $request, $user);
     $renderer->setTemplate('plzxoo_detail.html');
     $renderer->setAttribute('question', $question_arr);
     $renderer->setAttribute('answers', $answers);
     $renderer->setAttribute('enable_post_answer', exPerm::isPerm('post_answer') && is_object($user) && $question->getVar('uid') != $user->uid() | exPerm::isPerm('post_answer_myself'));
     // GIJ
     $renderer->setAttribute('is_detail', true);
     $renderer->setAttribute('mod_config', @$GLOBALS['xoopsModuleConfig']);
     $cat_handler =& plzXoo::getHandler('category');
     $cat_obj =& $cat_handler->get($question->getVar('cid'));
     if (is_object($cat_obj)) {
         $renderer->setAttribute('category', $cat_obj->getStructure());
     } else {
         $renderer->setAttribute('category', array());
     }
     $renderer->setAttribute('xoops_pagetitle', $question_arr['subject']);
     return $renderer;
 }
 function execute(&$controller, &$request, &$user)
 {
     // FIXME
     $id = isset($_REQUEST['aid']) ? intval($_REQUEST['aid']) : 0;
     // FIXME
     $handler =& plzXoo::getHandler('answer');
     $obj =& $handler->get($id);
     if (!is_object($obj)) {
         $request->setAttribute("message", _MD_PLZXOO_ERROR_ANSWER_NOT_EXISTS);
         return VIEW_ERROR;
     }
     $q_handler =& plzXoo::getHandler('question');
     $question =& $q_handler->get($obj->getVar('qid'));
     $c_handler =& plzXoo::getHandler('category');
     $category =& $c_handler->get($question->getVar('cid'));
     // この質問がアクティブなのか確認
     if (!is_object($question)) {
         return VIEW_ERROR;
     }
     if (!($question->getVar('status') <= 2)) {
         return VIEW_ERROR;
     }
     // この回答への権限を確認
     if ($question->getVar('uid') != $user->uid() && !$user->isAdmin()) {
         $request->setAttribute("message", _MD_PLZXOO_ERROR_PERMISSION);
         return VIEW_ERROR;
     }
     // 回答が終了しているならポイントも投函可能なフォームを渡す
     //$editform = ($question->getVar('status')==2) ?
     //		new AnswerResponsePointEditForm() : new AnswerResponseEditForm();
     $editform = new AnswerResponseEditForm();
     if ($editform->init($obj) == ACTIONFORM_POST_SUCCESS) {
         $editform->update($obj);
         // update size of question
         $question->setVar('modified_date', time());
         $q_handler->insert($question);
         // update answer
         $request->setAttribute('answer', $obj);
         $obj->setVar('modified_date', time());
         // trigger notification of question:updt
         $notification_handler =& xoops_gethandler('notification');
         $notification_handler->triggerEvent('question', $question->getVar('qid'), 'updt', array('QUESTION_SUBJECT' => $question->getVar('subject'), 'UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_MODC, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $question->getVar('qid')));
         return $handler->insert($obj) ? VIEW_SUCCESS : VIEW_ERROR;
     }
     $request->setAttribute('editform', $editform);
     $request->setAttribute('answer', $obj);
     $request->setAttribute('question', $question);
     $request->setAttribute('category', $category);
     return VIEW_INPUT;
 }
 function execute(&$controller, &$request, &$user)
 {
     $handler =& plzXoo::getHandler('question');
     $listController = new ListController();
     $listController->filter_ = new CategorySearchFilter();
     $listController->filter_->fetch();
     $per_page = intval(@$GLOBALS['xoopsModuleConfig']['listview_per_page']);
     if ($per_page <= 0) {
         $per_page = 20;
     }
     $listController->fetch($handler->getCount($listController->filter_->getCriteria()), $per_page);
     $criteria = $listController->getCriteria();
     // ¼èÆÀ
     $objs =& $handler->getObjects($criteria);
     $request->setAttribute('questions', $objs);
     $listController->freeze();
     $request->setAttribute('listController', $listController);
     return VIEW_SUCCESS;
 }
 function fetch(&$master)
 {
     $this->pid_ = intval($_POST['pid']);
     // pid ÂÅÅöÀ­¸¡ºº
     if ($this->pid_) {
         $handler =& plzXoo::getHandler('category');
         $obj =& $handler->get($this->pid_);
         if (!is_object($obj)) {
             $this->addError(_MD_PLZXOO_ERROR_PID_INJURY);
         }
     }
     $this->name_ = trim($_POST['name']);
     if (!$this->name_) {
         $this->addError(_MD_PLZXOO_ERROR_NAME_REQUIRED);
     }
     if (!$this->validateMaxLength($this->name_, 255)) {
         $this->addError(_MD_PLZXOO_ERROR_NAME_SIZEOVER);
     }
     $this->description_ = $_POST['description'];
     $this->weight_ = intval($_POST['weight']);
 }
 function execute(&$controller, &$request, &$user)
 {
     $id = isset($_REQUEST['cid']) ? intval($_REQUEST['cid']) : 0;
     $handler =& plzXoo::getHandler('category');
     $obj =& $handler->get($id);
     if (!is_object($obj)) {
         $obj =& $handler->create();
     }
     $editform = new CategoryEditForm();
     if ($editform->init($obj) == ACTIONFORM_POST_SUCCESS) {
         $editform->update($obj);
         $request->setAttribute('obj', $obj);
         return $handler->insert($obj) ? VIEW_SUCCESS : VIEW_ERROR;
     }
     // View にカテゴリ一覧を送る
     $categories =& $handler->getObjects();
     $request->setAttribute('editform', $editform);
     $request->setAttribute('obj', $obj);
     $request->setAttribute('categories', $categories);
     return VIEW_INPUT;
 }
 function fetch(&$master)
 {
     if (!exOnetimeTicket::inquiry(strtolower(get_class($this)))) {
         $this->addError(_MD_PLZXOO_ERROR_TICKET);
         // 再発行
         $this->ticket_ = new exOnetimeTicket(strtolower(get_class($this)), 3600);
         $this->ticket_->setSession();
     } else {
         exOnetimeTicket::unsetSession(strtolower(get_class($this)));
     }
     $this->subject_ = trim(@$_POST['subject']);
     if (!$this->subject_) {
         $this->addError(_MD_PLZXOO_ERROR_SUBJECT_REQUIRED);
     }
     if (!$this->validateMaxLength($this->subject_, 255)) {
         $this->addError(_MD_PLZXOO_ERROR_SUBJECT_SIZEOVER);
     }
     // 指定されたカテゴリが存在するか確認
     $this->cid_ = intval(@$_POST['cid']);
     $handler =& plzXoo::getHandler('category');
     if (!is_object($handler->get($this->cid_))) {
         $this->addError(_MD_PLZXOO_ERROR_CID_INJURY);
     }
     $this->priority_ = intval(@$_POST['priority']);
     if (!$this->validateInRange($this->priority_, 1, 5)) {
         $this->addError(_MD_PLZXOO_ERROR_PRIORITY_RANGEOVER);
     }
     // 管理者だけがstatusの直接変更権限を持つ
     if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin()) {
         $this->status_ = intval(@$_POST['status']);
         $status_keys = array_keys($GLOBALS['plzxoo_status_mapping']);
         if (!$this->validateInRange($this->status_, min($status_keys), max($status_keys))) {
             $this->addError(_MD_PLZXOO_ERROR_STATUS_RANGEOVER);
         }
     }
     $this->body_ = @$_POST['body'];
     if (!$this->body_) {
         $this->addError(_MD_PLZXOO_ERROR_BODY_REQUIRED);
     }
 }
 function execute(&$controller, &$request, &$user)
 {
     // FIXME
     $id = isset($_REQUEST['cid']) ? intval($_REQUEST['cid']) : 0;
     // FIXME
     $handler =& plzXoo::getHandler('category');
     $obj =& $handler->get($id);
     if (!is_object($obj)) {
         return VIEW_ERROR;
     }
     // =======================================================================
     // Permission Check etc...  削除権限のチェックなどが必要ならここにコードを書く
     // =======================================================================
     // FIXME
     $editform = new exConfirmTicketForm();
     $editform->setErrorMessage(_MD_A_PLZXOO_ERROR_TICKET);
     if ($editform->init(strtolower(get_class($this))) == ACTIONFORM_POST_SUCCESS) {
         $editform->release();
         return $handler->delete($obj) ? VIEW_SUCCESS : VIEW_ERROR;
     }
     $request->setAttribute('editform', $editform);
     $request->setAttribute('obj', $obj);
     return VIEW_INPUT;
 }
 function delete(&$obj, $force = false)
 {
     // get parent (question)
     $qHandler =& plzXoo::getHandler('question');
     $question =& $qHandler->get($obj->getVar('qid'));
     // notification delete
     $ret = parent::delete($obj, $force);
     // update parent (question)
     $question->updateSize();
     $question->setVar('modified_date', time());
     $qHandler->insert($question);
     return $ret;
 }
 function delete(&$obj, $force = false)
 {
     // remove children (answer)
     $handler =& plzXoo::getHandler('answer');
     $answers =& $handler->getObjects(new Criteria('qid', $obj->getVar('qid')));
     foreach ($answers as $answer) {
         $handler->delete($answer);
     }
     // get parent (category)
     $handler =& plzXoo::getHandler('category');
     $category =& $handler->get($obj->getVar('cid'));
     // delete notifications
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname('plzXoo');
     $module_id = $module->getVar('mid');
     $notification_handler =& xoops_gethandler('notification');
     $notification_handler->unsubscribeByItem($module_id, 'question', $obj->getVar('qid'));
     $ret = parent::delete($obj, $force);
     // update parent (category)
     $category->updateSize();
     // $category->setVar('modified_date',time());
     $handler->insert($category);
     return $ret;
 }
 function execute(&$controller, &$request, &$user)
 {
     exFrame::init(EXFRAME_PERM);
     // 回答権限のチェック
     exPerm::GuardRedirect('post_answer', 'index.php', _MD_PLZXOO_ERROR_PERMISSION);
     $qid = isset($_REQUEST['qid']) ? intval($_REQUEST['qid']) : 0;
     $qHandler =& plzXoo::getHandler('question');
     // ここで qid を確認
     $question =& $qHandler->get($qid);
     if (!is_object($question)) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_QUESTION_NOT_EXISTS);
         return VIEW_ERROR;
     } elseif ($question->getVar('status') != 1) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_QUESTION_CLOSED);
         return VIEW_ERROR;
     } elseif (is_object($user) && $question->getVar('uid') == $user->uid()) {
         exPerm::GuardRedirect('post_answer_myself', 'index.php', _MD_PLZXOO_ERROR_PERMISSION);
         // GIJ
     }
     $id = isset($_REQUEST['aid']) ? intval($_REQUEST['aid']) : 0;
     $handler =& plzXoo::getHandler('answer');
     $obj =& $handler->get($id);
     if (!is_object($obj)) {
         $is_new = true;
         $obj =& $handler->create();
         $obj->setVar('uid', $user->uid());
         $obj->setVar('qid', $qid);
     } else {
         $is_new = false;
         // 権限の確認
         if (!$obj->isEnableEdit($user)) {
             $request->setAttribute('error_message', _MD_PLZXOO_ERROR_PERMISSION);
             return VIEW_ERROR;
         }
     }
     $editform =& new EditAnswerForm();
     if ($editform->init($obj) == ACTIONFORM_POST_SUCCESS) {
         $editform->update($obj);
         // 入力内容をオブジェクトに受け取る
         $request->setAttribute('question', $question);
         $obj->setVar('modified_date', time());
         if ($handler->insert($obj)) {
             // update size of question
             $question->updateSize();
             $question->setVar('modified_date', time());
             $qHandler->insert($question);
             // notifications
             $notification_handler =& xoops_gethandler('notification');
             if ($is_new) {
                 // trigger notification of question:newa
                 $notification_handler->triggerEvent('question', $question->getVar('qid'), 'newa', array('QUESTION_SUBJECT' => $question->getVar('subject'), 'ANSWER_UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_NEWA, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $question->getVar('qid')));
                 // trigger notification of question:updt
                 $notification_handler->triggerEvent('question', $question->getVar('qid'), 'updt', array('QUESTION_SUBJECT' => $question->getVar('subject'), 'UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_NEWA, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $question->getVar('qid')));
                 // auto register a notification question:updt into answerer
                 if (!empty($GLOBALS['xoopsModuleConfig']['autonotify_answerer'])) {
                     $notification_handler->subscribe('question', $question->getVar('qid'), 'updt');
                 }
             } else {
                 // trigger notification of question:updt
                 $notification_handler->triggerEvent('question', $question->getVar('qid'), 'updt', array('QUESTION_SUBJECT' => $question->getVar('subject'), 'UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_MODA, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $question->getVar('qid')));
             }
             return VIEW_SUCCESS;
         } else {
             return VIEW_ERROR;
         }
     }
     $handler =& plzXoo::getHandler('category');
     $category =& $handler->get($question->getVar('cid'));
     $request->setAttribute('editform', $editform);
     $request->setAttribute('category', $category);
     $request->setAttribute('question', $question);
     $request->setAttribute('answer', $obj);
     return VIEW_INPUT;
 }
 function execute(&$controller, &$request, &$user)
 {
     $qid = isset($_REQUEST['qid']) ? intval($_REQUEST['qid']) : 0;
     $handler =& plzXoo::getHandler('question');
     // ここで qid を確認
     $question =& $handler->get($qid);
     if (!is_object($question)) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_QUESTION_NOT_EXISTS);
         return VIEW_ERROR;
     } elseif ($question->getVar('status') != 1) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_QUESTION_CLOSED);
         return VIEW_ERROR;
     } elseif (!is_object($user)) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_PERMISSION);
         return VIEW_ERROR;
     }
     // ここで権限を確認
     if ($question->getVar('uid') != $user->uid() && !$user->isAdmin()) {
         $request->setAttribute('error_message', _MD_PLZXOO_ERROR_PERMISSION);
         return VIEW_ERROR;
     }
     $editform =& new exConfirmTicketForm();
     if ($editform->init('plzXooClose') == ACTIONFORM_POST_SUCCESS) {
         // ポイントそのものValidation
         $points = explode('|', @$GLOBALS['xoopsModuleConfig']['points']);
         $points_allowed = array();
         foreach ($points as $key => $point_tmp) {
             @(list($point, $max) = explode(':', $point_tmp));
             if (empty($max)) {
                 $max = 0x7fff;
             }
             // fixme :lol:
             $point = intval($point_tmp);
             $points_allowed[$point] = intval($max);
         }
         foreach ($_POST['points'] as $point) {
             if (empty($points_allowed[$point])) {
                 // ポイント数オーバー
                 $request->setAttribute('error_message', _MD_PLZXOO_ERROR_POINT_RULE);
                 return VIEW_ERROR;
             }
             $points_allowed[$point]--;
         }
         // ポイントの登録処理
         $answer_handler =& plzXoo::getHandler('answer');
         $member_handler =& xoops_gethandler('member');
         foreach ($_POST['points'] as $aid => $point) {
             $point = intval($point);
             $answer =& $answer_handler->get(intval($aid));
             if (!is_object($answer)) {
                 // 指定されたaidが存在するか
                 $request->setAttribute('error_message', _MD_PLZXOO_ERROR_ANSWER_NOT_EXISTS);
                 return VIEW_ERROR;
             } elseif ($answer->getVar('qid') != $qid) {
                 // 指定されたaidがqidのものか
                 $request->setAttribute('error_message', _MD_PLZXOO_ERROR_ANSWER_NOT_EXISTS);
                 return VIEW_ERROR;
             }
             // answerテーブルにポイント保存
             $answer->setVar('point', $point);
             $answer->setVar('modified_date', time());
             $answer_handler->insert($answer);
             $answerer =& $member_handler->getUser($answer->getVar('uid'));
             // 投稿数も増やす(設定points2postsでON/OFF)
             if (!empty($GLOBALS['xoopsModuleConfig']['points2posts']) && is_object($answerer)) {
                 for ($i = 0; $i < $point; $i++) {
                     $answerer->incrementPost();
                 }
             }
         }
         // trigger notification of question:updt
         $notification_handler =& xoops_gethandler('notification');
         $notification_handler->triggerEvent('question', $question->getVar('qid'), 'updt', array('QUESTION_SUBJECT' => $question->getVar('subject'), 'UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_CLOSE, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $question->getVar('qid')));
         $editform->sessionClear();
         // セッションクリア
         $question->setVar('status', 2);
         $request->setAttribute('question', $question);
         $question->setVar('modified_date', time());
         return $handler->insert($question) ? VIEW_SUCCESS : VIEW_ERROR;
     }
     $request->setAttribute('editform', $editform);
     $request->setAttribute('question', $question);
     $handler =& plzXoo::getHandler('answer');
     $criteria = new Criteria('qid', $qid);
     $criteria->setSort('input_date');
     $criteria->setOrder('DESC');
     $answers =& $handler->getObjects($criteria);
     $request->setAttribute('answers', $answers);
     $handler =& plzXoo::getHandler('category');
     $category =& $handler->get($question->getVar('cid'));
     $request->setAttribute('category', $category);
     return VIEW_INPUT;
 }
 function execute(&$controller, &$request, &$user)
 {
     exFrame::init(EXFRAME_PERM);
     // 投函権限のチェック
     exPerm::GuardRedirect('post_question', 'index.php', _MD_PLZXOO_ERROR_PERMISSION);
     $id = isset($_REQUEST['qid']) ? intval($_REQUEST['qid']) : 0;
     $handler =& plzXoo::getHandler('question');
     $obj = null;
     if ($id) {
         $obj =& $handler->get($id);
     }
     if (!is_object($obj)) {
         $is_new = true;
         $obj =& $handler->create();
         $obj->setVar('uid', $user->uid());
         // 自動承認がなければ、承認待ちへ
         if (!exPerm::isPerm('post_question_auto_approve')) {
             $obj->setVar('status', 4);
             $is_need_approve = true;
             $is_new = false;
         }
     } else {
         $is_new = false;
         // 編集権限の確認
         if (!$obj->isEnableEdit($user)) {
             $request->setAttribute('message', _MD_PLZXOO_ERROR_PERMISSION);
             return VIEW_ERROR;
         }
         // ステータスが無効のものは管理者以外編集不能
         if ($obj->getVar('status') == 3) {
             if (!is_object($GLOBALS['xoopsUser']) || !$GLOBALS['xoopsUser']->isAdmin()) {
                 return VIEW_ERROR;
             }
         }
     }
     $prev_status = $obj->getVar('status');
     $editform =& new EditQuestionForm();
     if ($editform->init($obj) == ACTIONFORM_POST_SUCCESS) {
         $editform->update($obj);
         // 入力内容をオブジェクトに受け取る
         // 承認処理のチェック
         $obj->setVar('modified_date', time());
         if ($handler->insert($obj)) {
             // update size of category
             $category_handler =& plzXoo::getHandler('category');
             $category =& $category_handler->get($obj->getVar('cid'));
             $category->updateSize();
             $category_handler->insert($category);
             // notifications
             $notification_handler =& xoops_gethandler('notification');
             if ($is_new || $prev_status == 4 && $obj->getVar('status') == 1) {
                 // 新規または承認後の通知処理
                 // trigger notification of global:newq
                 $notification_handler->triggerEvent('global', 0, 'newq', array('QUESTION_SUBJECT' => $obj->getVar('subject'), 'QUESTION_UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_NEWQ, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $obj->getVar('qid')));
                 // trigger notification of category:newq
                 $notification_handler->triggerEvent('category', $obj->getVar('cid'), 'newq', array('QUESTION_SUBJECT' => $obj->getVar('subject'), 'QUESTION_UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_NEWQ, 'CATEGORY_NAME' => $category->getVar('name'), 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $obj->getVar('qid')));
                 // auto register a notification question:newa into questioner
                 if (!empty($GLOBALS['xoopsModuleConfig']['autonotify_questioner'])) {
                     $notification_handler->subscribe('question', $obj->getVar('qid'), 'newa', null, null, $obj->getVar('uid'));
                 }
             } else {
                 if ($is_need_approve) {
                     // 承認待ちの通知処理 (waiting)
                     // trigger notification of global:neww
                     $notification_handler->triggerEvent('global', 0, 'neww', array('QUESTION_SUBJECT' => $obj->getVar('subject'), 'QUESTION_UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_NEWW, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $obj->getVar('qid')));
                 } else {
                     // trigger notification of question:updt
                     $notification_handler->triggerEvent('question', $obj->getVar('qid'), 'updt', array('QUESTION_SUBJECT' => $obj->getVar('subject'), 'UNAME' => $user->getVar('uname'), 'CONDITION' => _MD_PLZXOO_LANG_NOTIFY_MODQ, 'QUESTION_URI' => XOOPS_URL . "/modules/plzXoo/index.php?action=detail&amp;qid=" . $obj->getVar('qid')));
                 }
             }
             // message
             if (empty($is_need_approve)) {
                 $request->setAttribute('success_message', _MD_PLZXOO_MESSAGE_POSTQ_AUTO_APPROVED);
             } else {
                 $request->setAttribute('success_message', _MD_PLZXOO_MESSAGE_POSTQ_NEED_APPROVE);
             }
             return VIEW_SUCCESS;
         } else {
             return VIEW_ERROR;
         }
     }
     // カテゴリ一覧を取得
     $cHandler =& plzXoo::getHandler('category');
     $categories =& $cHandler->getObjects();
     $request->setAttribute('editform', $editform);
     $request->setAttribute('question', $obj);
     $request->setAttribute('categories', $categories);
     return VIEW_INPUT;
 }