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) { $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; }
/** @brief 削除権限があるかどうか */ function isEnableDelete(&$user) { exFrame::init(EXFRAME_PERM); $uid = is_object($user) ? $user->uid() : 0; $flag = false; if ($this->getVar('uid') == $uid) { $flag = exPerm::isPerm('delete_my_answer'); } else { $flag = exPerm::isPerm('delete_other_answer'); } if (!$flag) { $handler =& plzXoo::getHandler('question'); $question =& $handler->get($this->getVar('qid')); if ($question->getVar('uid') == $uid) { return exPerm::isPerm('delete_myposts_answer'); } else { return false; } } return true; }
/** @brief 削除権限があるかどうか */ function isEnableDelete(&$user) { exFrame::init(EXFRAME_PERM); $uid = is_object($user) ? $user->uid() : 0; if ($this->getVar('uid') == $uid) { return exPerm::isPerm('delete_my_question'); } else { return exPerm::isPerm('delete_other_question'); } }
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&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&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&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&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; }