Example #1
0
 public function defaultAction()
 {
     if (!$this->manager->hasLeaveFeedbackPermission()) {
         trigger_error($this->user->lang('E_CANNOT_LEAVE_FEEDBACK'));
     }
     $topic_id = $this->request->variable('topic_id', 0);
     $feedback_reply_id = $this->request->variable('reply_id', 0);
     $rating = $this->request->variable('trader_rating', 0);
     $short_comment = utf8_normalize_nfc(trim($this->request->variable('short_comment', '', true)));
     $long_comment = utf8_normalize_nfc(trim($this->request->variable('long_comment', '', true)));
     if ($feedback_reply_id) {
         $feedback_row = $this->manager->getAllFeedbackInfo($feedback_reply_id);
     }
     $topic_id = $topic_id ? $topic_id : $feedback_row['topic_id'];
     $topic_row = $this->getTopic($topic_id);
     $user_id = $feedback_reply_id ? $feedback_row['from_user_id'] : $topic_row['topic_poster'];
     $err_comments = array();
     $feedback_route = $this->helper->route('rfd_trader_view', array('u' => $user_id));
     $back_url = '<a href=' . append_sid(generate_board_url() . "/viewtopic.php?t=" . $topic_id) . '>&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
     $submit = $this->request->is_set_post('submit');
     $to_user_row = $this->getUser($user_id);
     if ($feedback_reply_id && !$feedback_row) {
         trigger_error($this->user->lang('E_FEEDBACK_NOT_FOUND'));
     }
     if ($feedback_reply_id && $this->user->data['user_id'] != $feedback_row['to_user_id']) {
         trigger_error($this->user->lang('E_CANNOT_RETURN_FEEDBACK'));
     }
     if (!$topic_row) {
         trigger_error($this->user->lang('TOPIC_NOT_FOUND'));
     }
     if (!$to_user_row) {
         trigger_error($this->user->lang('USER_NOT_FOUND'));
     }
     if ($to_user_row['user_id'] == $this->user->data['user_id']) {
         trigger_error($this->user->lang('CANNOT_RATE_SELF') . '</br></br>' . $back_url);
     }
     if ($this->user->data['user_id'] == ANONYMOUS) {
         trigger_error($this->user->lang('LOG_IN'));
     }
     if (!$this->manager->canGiveFeedback($user_id, $this->user->data['user_id'], $topic_id)) {
         trigger_error($this->user->lang('ALREADY_GIVEN_FEEDBACK') . '<br /><br />' . $back_url);
     }
     if ($submit && (strlen($short_comment) < self::MIN_SHORT_LENGTH || strlen($short_comment) > self::MAX_SHORT_LENGTH)) {
         $err_comments['short'] = '* Required 10-200 Characters';
     }
     if ($submit && strlen($long_comment) > self::MAX_LONG_LENGTH) {
         $err_comments['long'] = true;
     }
     if ($submit && !$err_comments['short'] && !$err_comments['long']) {
         if (!check_form_key('give_feedback_form')) {
             trigger_error('FORM_INVALID');
         }
         $feedback_result = $this->manager->giveFeedback($user_id, $this->user->data['user_id'], $feedback_reply_id, $rating, $topic_id, $topic_row['topic_title'], $topic_row['topic_trader_type'], $short_comment, $long_comment);
         $trader_profile_url = '<a href=' . $this->helper->route('rfd_trader_view', array('u' => $to_user_row['user_id'])) . '>' . $this->user->lang['VIEW_PROFILE'] . '&nbsp;' . $to_user_row['username'] . '</a>';
         trigger_error($this->user->lang('FEEDBACK_SUCCESS') . '<br /><br />' . $trader_profile_url);
     }
     add_form_key('give_feedback_form');
     $this->template->assign_vars(array('ERROR' => $err_comments, 'RATING' => $rating, 'SHORT' => $short_comment, 'LONG' => $long_comment, 'USERNAME' => $to_user_row['username'], 'TOPIC_TITLE' => $topic_row['topic_title'], 'TOPIC_TYPE' => $topic_row['topic_trader_type'], 'TRADER_USERNAME' => $to_user_row['username'], 'U_TRADER_FEEDBACK' => $feedback_route, 'U_TRADER_PROFILE' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $to_user_row['user_id'])));
     return $this->helper->render('TraderFeedback.html', $this->user->lang['FEEDBACK_TITLE'] . $to_user_row['username']);
 }