示例#1
0
    function saveMessage() {

        $my = JFactory::getUser();
        $cfg = BidsHelperTools::getConfig();

        $auctionid = JRequest::getInt("id");
        $comment = JRequest::getString('message', '');
        $id_msg = JRequest::getInt('idmsg', 0);
        $bidder_id= JRequest::getInt('bidder_id', null);

        $auctionmodel = $this->getModel('auction');

        if (!$auctionmodel->load($auctionid)) {
            $this->setRedirect( 'index/php?option=com_bids', JText::_('COM_BIDS_DOES_NOT_EXIST'));
            return;
        }

        $auction = $auctionmodel->get('auction');

        $redirect_link = JHtml::_('auctiondetails.auctionDetailsURL',$auction, false) . '#messages';

        if (!$cfg->bid_opt_allow_messages) {
            $this->setRedirect($redirect_link, JText::_('COM_BIDS_MESSAGING_WAS_DISALLOWED'));
            return;
        }

        if (!$my->id && $cfg->bid_opt_enable_captcha) {
            // if code not good halt
            if (!BidsHelperHtml::verify_captcha()) {
                $this->setRedirect($redirect_link, JText::_('COM_BIDS_MESSAGE_ERROR_CAPTCHA'));
                return;
            }
        }

        //only seller and buyer can send messages
        if ($auction->close_offer) {
            if ( ($auction->userid!=$my->id) && !in_array($my->id,$auction->winnerIds) ) {
                //allow messages between Winner and auctioneer
                $this->setRedirect($redirect_link, JText::_('COM_BIDS_AUCTION_IS_CLOSED'));
                return;
            }
        }

        if ($auction->published != 1) {
            $this->setRedirect($redirect_link, JText::_('COM_BIDS_DOES_NOT_EXIST'));
            return;
        }

        $comment = str_replace("\n", '<br>', $comment);
        $auction->sendNewMessage($comment, $id_msg, $bidder_id);

        $this->setRedirect($redirect_link, JText::_('COM_BIDS_MESSAGE_SUCCESS'));
    }