public function execute()
 {
     $userService = ServiceFactory::factory('User');
     $address = prepare_address();
     $updateResult = $userService->updateAddress($address);
     if ($updateResult === true) {
         $this->setSuccess();
         return;
     }
     $this->setError(KancartResult::ERROR_USER_INPUT_PARAMETER, join(',', $updateResult));
 }
 public function execute()
 {
     $shippingAddressBookId = max($_REQUEST['shipping_address_book_id'], $_REQUEST['billing_address_book_id']);
     $shippingAddressJson = max($_REQUEST['shipping_address'], $_REQUEST['billing_address']);
     if ($shippingAddressBookId) {
         $shippingAddress = array();
         if ($shippingAddressJson) {
             $shippingAddressJson = htmlspecialchars_decode($shippingAddressJson, ENT_COMPAT);
             $this->exportAddressToRequest(json_decode($shippingAddressJson, true));
             $shippingAddress = prepare_address();
         }
         $this->updateAddress($shippingAddressBookId, $shippingAddress);
     } else {
         //add a new address to db
         $shippingAddressJson = htmlspecialchars_decode($shippingAddressJson, ENT_COMPAT);
         $this->exportAddressToRequest(json_decode($shippingAddressJson, true));
         $this->addAddress(prepare_address());
     }
     $this->setSuccess(ServiceFactory::factory('Checkout')->detail());
 }
示例#3
0
function submitFaxes() {

    /* Submit a group of messages or an individual message 
     * and show the results to the user */

    global $grpid, $msgid_list, $msgid;
    global $repid_list, $fyr_who;
    global $representatives_info, $fyr_voting_area;
    global $fyr_values, $cobrand;
    
    // Set up some brief error descriptions
    $errors = cobrand_message_sending_errors($cobrand);
    if (!$errors) { 
        $errors = array("problem-generic" => "Message Rejected", 
                        "problem-lords" => "You have sent too many messages to Lords", 
                        "problem-lords-similar" => "Too many similar messages have been sent",
                        "problem-postcodes" => "You seem to be sending messages with several different postcodes", 
                        "problem-similar" => "Your message is near-identical with others sent previously");
    }
 
    // send the message to each representative
    $any_success = false;
    $error_msg = "";
    
    if ($grpid) {

        // No questionnaire for group mails
        $no_questionnaire = true;

        // check the group id  
        if (!preg_match("/^[0-9a-f]{20}$/i", $grpid)) {
        template_show_error('Sorry, but your browser seems to be transmitting
            erroneous data to us. Please try again, or contact us at
            <a href="mailto:team&#64;writetothem.com">team&#64;writetothem.com</a>.');
                exit;
        }
        // double check that the group_id isn't already being used
        // This could mean that these messages have already been
        // queued or (with a very small probability) that someone
        // else got the same group id 
        $result = msg_check_group_unused($grpid);    
        if (isset($result)) {
            $error_msg .= rabx_mail_error_msg($result->code, $result->text) . "<br>";        
                     template_show_error("Sorry, we were unable to send your messages for the following reasons: <br>" . $error_msg);
            exit;
        }   
    } else {
        $no_questionnaire = false;
        $msgid_list = array($msgid);
        $repid_list = array($fyr_who);
    }      
        
    # set up the address      
    $address = prepare_address();
    check_message_length();
    # check the msgids
    foreach ($msgid_list as $msgid) {
        check_message_id($msgid);
    }
    $cocode = $fyr_values['cocode'];
    if (!$cocode)
        $cocode = null;
    $message_array = prepare_message_array($address);
    $result = msg_write_messages($msgid_list,
                                     $message_array,
                                     $repid_list,
                                     $fyr_values['signedbody'],
                                     $cobrand, $cocode, $grpid, $no_questionnaire);       

    #check for error    
    if (rabx_is_error($result)) {
        template_show_error(rabx_mail_error_msg($result->code, $result->text));
        exit;

    } 

    foreach (array_keys($result) as $id) {
        $res = $result[$id];
        $rep_id = $res['recipient_id'];        
        $abuse_res = $res['abuse_result'];
        $status = $res['status_code'];
        $err = $res['error_text'];
        $code = $res['error_code'];
        if ($status != 0) {
            $rep_name = "<strong>" . $fyr_voting_area['rep_prefix'] . " " .
            $representatives_info[$rep_id]['name'] . " " . $fyr_voting_area['rep_suffix'] . "</strong>";
            
            if ($status == 1) {
                # FYR Error code
                if ($grpid) { 
                    $error_msg .= $rep_name . ": " . rabx_mail_error_msg($code, $err) . "<br>";
                } else {
                    template_show_error(rabx_mail_error_msg($code, $err));
                    exit;
                }
            } elseif ($status == 2) {
                # flagged for abuse
                if ($grpid) {
                    if (array_key_exists($abuse_res, $errors)) {
                        $error_msg .= "<p>" . $rep_name . ": " . $errors[$abuse_res]
                            . " <a href=\"/"  . $abuse_res . "\">read more</a></p>";
                    } else {
                        $error_msg .= "<p>" .$rep_name . ": Message Rejected</p>";
                    }
                } else {
                    template_draw($abuse_res,  $fyr_values);
                    exit;
                }
            }
        } else {
            $any_success = true;
        }   

    }
          
    if (!$any_success) {
        // None of the messages could be sent
        template_show_error("Sorry, we were unable to send your messages for the following reasons: <br>" . $error_msg);
    } elseif ($error_msg) {
        // Some problems 
        $error_msg = "
    <p style=\"text-align: center; color: #ff0000; \">Note: 
    Some of your messages could not be sent for the following reasons: </p>
    " . $error_msg;
        show_check_email($error_msg);
    } else {
        //no problems
        show_check_email($error_msg);
    } 
 
}