Пример #1
0
 private function saveCustomerFeedbacks($order_id, $file_order_metadata)
 {
     /* echo "<pre>";
     		var_dump($_POST);
     		echo "<pre>";  */
     $email_string = "";
     $wcam_option_model = new WCAM_Option();
     $wpml = new WCAM_Wpml();
     $curr_lang = $wpml->get_current_language();
     $options = $wcam_option_model->get_option();
     $approve_not_yet_text = isset($options['approve_not_yet_text']) && isset($options['approve_not_yet_text'][$curr_lang]) ? $options['approve_not_yet_text'][$curr_lang] : __('Not yet', 'woocommerce-attach-me');
     $approve_yes_text = isset($options['approve_yes_text']) && isset($options['approve_yes_text'][$curr_lang]) ? $options['approve_yes_text'][$curr_lang] : __('Yes', 'woocommerce-attach-me');
     $approve_no_text = isset($options['approve_no_text']) && isset($options['approve_no_text'][$curr_lang]) ? $options['approve_no_text'][$curr_lang] : __('No', 'woocommerce-attach-me');
     $email_approve_box_title = isset($options['email_approve_box_title']) && isset($options['email_approve_box_title'][$curr_lang]) ? $options['email_approve_box_title'][$curr_lang] : __('Customer has approved?', 'woocommerce-attach-me');
     $email_feedback_box_title = isset($options['email_feedback_box_title']) && isset($options['email_feedback_box_title'][$curr_lang]) ? $options['email_feedback_box_title'][$curr_lang] : __('Customer feedback', 'woocommerce-attach-me');
     $email_no_customer_feedback_message = isset($options['email_no_customer_feedback_message']) && isset($options['email_no_customer_feedback_message'][$curr_lang]) ? $options['email_no_customer_feedback_message'][$curr_lang] : __('No customer feedback', 'woocommerce-attach-me');
     foreach ($_POST['wcam_attachment_id'] as $key => $file_id) {
         if (isset($_POST['wcam_customer_approval']) && isset($_POST['wcam_customer_approval'][$file_id])) {
             $file_order_metadata[$file_id]['customer-has-approved'] = $_POST['wcam_customer_approval'][$file_id];
         }
         if (isset($_POST['wcam_customer_feedback']) && isset($_POST['wcam_customer_feedback'][$file_id])) {
             $file_order_metadata[$file_id]['customer-feedback'] = stripslashes($_POST['wcam_customer_feedback'][$file_id]);
         }
         //Email
         if ($file_order_metadata[$file_id]['customer-admin-notification'] == 'yes') {
             $email_string .= '<h3>' . $file_order_metadata[$file_id]['title'] . '</h3>';
             $approve_text;
             if (isset($file_order_metadata[$file_id]['customer-has-approved'])) {
                 switch ($file_order_metadata[$file_id]['customer-has-approved']) {
                     case "none":
                         $approve_text = $approve_not_yet_text;
                         break;
                     case "yes":
                         $approve_text = $approve_yes_text;
                         break;
                     case "no":
                         $approve_text = $approve_no_text;
                         break;
                 }
                 $email_string .= '<strong>' . $email_approve_box_title . '</strong><br/>';
                 $email_string .= $approve_text . '<br/>';
             }
             //Feedback
             if (isset($file_order_metadata[$file_id]['customer-feedback']) && !empty($file_order_metadata[$file_id]['customer-feedback'])) {
                 $email_string .= '<strong>' . $email_feedback_box_title . '</strong><br/>';
                 $email_string .= $file_order_metadata[$file_id]['customer-feedback'] . '<br/>';
             } else {
                 $email_string .= '<strong>' . $email_no_customer_feedback_message . '</strong><br/>';
             }
         }
     }
     if ($email_string != "") {
         $email_sender = new WCAM_Email();
         $email_sender->trigger(get_option('admin_email'), __('New Approval(s)/Feedback(s) for order: ', 'woocommerce-attach-me') . $order_id, $email_string);
     }
     update_post_meta($order_id, '_wcam_attachments_meta', $file_order_metadata);
     return $file_order_metadata;
 }
Пример #2
0
 public function woocommerce_process_shop_ordermeta()
 {
     //$_POST['wcam_attachment_title'] : title array();
     //$_POST["wcam-orderid"] : order id
     //$_FILES['wcam_attachment_file'] : files array();
     //$order_id = intval( $post_data['wcam-orderid'] );
     //var_dump($_POST);
     if (!isset($_POST["wcam-orderid"])) {
         return;
     }
     $order_id = $_POST["wcam-orderid"];
     $file_order_metadata = get_post_meta($order_id, '_wcam_attachments_meta');
     $file_order_metadata = isset($file_order_metadata[0]) ? $file_order_metadata[0] : array();
     $this->errors = "";
     $this->results = "";
     //Delete
     if (isset($_POST['wcam_attachments_to_delete'])) {
         foreach ($_POST['wcam_attachments_to_delete'] as $value) {
             $file_order_metadata = $this->delete_file(intval($value), $file_order_metadata, $order_id);
         }
     }
     //Upload
     if (isset($_FILES)) {
         $titles = isset($_POST['wcam_attachment_title']) ? $_POST['wcam_attachment_title'] : array();
         $file_order_metadata = $this->upload_files($order_id, $file_order_metadata, $_FILES, $titles);
     }
     if (isset($_POST['wcam_attachment_external_url'])) {
         $title = isset($_POST['wcam_attachment_title']) ? $_POST['wcam_attachment_title'] : array();
         foreach ($_POST['wcam_attachment_external_url'] as $index => $url) {
             $id = $_POST['wcam_id'][$index];
             $file_order_metadata[$id]['title'] = !empty($title) && isset($title[$id]) ? $title[$id] : "";
             $file_order_metadata[$id]['id'] = $id;
             $file_order_metadata[$id]['url'] = $url;
             $file_order_metadata[$id]['customer-has-to-be-approved'] = isset($_POST['wcam-customer-approve-checkbox'][$id]) ? $_POST['wcam-customer-approve-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-can-reapprove'] = isset($_POST['wcam-customer-reapprove-checkbox'][$id]) ? $_POST['wcam-customer-reapprove-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-feedback-enabled'] = isset($_POST['wcam-customer-feedback-checkbox'][$id]) ? $_POST['wcam-customer-feedback-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-admin-notification'] = isset($_POST['wcam-customer-admin-notification-checkbox'][$id]) ? $_POST['wcam-customer-admin-notification-checkbox'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-processing-order-email'] = isset($_POST['wcam-attach-file-to-processing-order-email'][$id]) ? $_POST['wcam-attach-file-to-processing-order-email'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-complete-order-email'] = isset($_POST['wcam-attach-file-to-complete-order-email'][$id]) ? $_POST['wcam-attach-file-to-complete-order-email'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-customer-invoice-email'] = isset($_POST['wcam-attach-file-to-customer-invoice-email'][$id]) ? $_POST['wcam-attach-file-to-customer-invoice-email'][$id] : "no";
         }
     }
     if (isset($_POST['wcam_attachment_gallery_url'])) {
         $title = isset($_POST['wcam_attachment_title']) ? $_POST['wcam_attachment_title'] : array();
         foreach ($_POST['wcam_attachment_gallery_url'] as $index => $url) {
             $id = $_POST['wcam_id'][$index];
             $file_order_metadata[$id]['title'] = !empty($title) && isset($title[$id]) ? $title[$id] : "";
             $file_order_metadata[$id]['id'] = $id;
             $file_order_metadata[$id]['media_from_gallery'] = "yes";
             $file_order_metadata[$id]['media_id'] = isset($_POST['wcam_attachment_gallery_media_id']) && isset($_POST['wcam_attachment_gallery_media_id'][$id]) ? $_POST['wcam_attachment_gallery_media_id'][$id] : -1;
             $file_order_metadata[$id]['url'] = $url;
             $file_order_metadata[$id]['customer-has-to-be-approved'] = isset($_POST['wcam-customer-approve-checkbox'][$id]) ? $_POST['wcam-customer-approve-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-can-reapprove'] = isset($_POST['wcam-customer-reapprove-checkbox'][$id]) ? $_POST['wcam-customer-reapprove-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-feedback-enabled'] = isset($_POST['wcam-customer-feedback-checkbox'][$id]) ? $_POST['wcam-customer-feedback-checkbox'][$id] : "no";
             $file_order_metadata[$id]['customer-admin-notification'] = isset($_POST['wcam-customer-admin-notification-checkbox'][$id]) ? $_POST['wcam-customer-admin-notification-checkbox'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-processing-order-email'] = isset($_POST['wcam-attach-file-to-processing-order-email'][$id]) ? $_POST['wcam-attach-file-to-processing-order-email'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-complete-order-email'] = isset($_POST['wcam-attach-file-to-complete-order-email'][$id]) ? $_POST['wcam-attach-file-to-complete-order-email'][$id] : "no";
             $file_order_metadata[$id]['attach-file-to-customer-invoice-email'] = isset($_POST['wcam-attach-file-to-customer-invoice-email'][$id]) ? $_POST['wcam-attach-file-to-customer-invoice-email'][$id] : "no";
         }
     }
     update_post_meta($order_id, '_wcam_attachments_meta', $file_order_metadata);
     //general options
     $wcam_options = array();
     $wcam_options['embed-links-to-complete-mail'] = isset($_POST['wcam-embed-links-to-complete-mail']) ? $_POST['wcam-embed-links-to-complete-mail'] : "no";
     $wcam_options['embed-links-to-complete-mail-text'] = isset($_POST['wcam-embed-links-to-complete-mail-text']) ? $_POST['wcam-embed-links-to-complete-mail-text'] : "";
     update_post_meta($order_id, '_wcam_options', $wcam_options);
     //Email notification
     if (isset($_POST['wcam-notify-via-mail']) && $_POST['wcam-notify-via-mail'] == 'yes') {
         if (isset($_POST['wcam-notification-message']) && isset($_POST['wcam-notification-subject'])) {
             $item_to_attach = isset($_POST['wcam-attachment-ids']) ? explode(",", $_POST['wcam-attachment-ids']) : null;
             $email_sender = new WCAM_Email();
             $order = new WC_Order($order_id);
             /* $user_id = $order->user_id;
             			$user = get_userdata( $user_id ); */
             $user_email = $order->billing_email;
             $message = $_POST['wcam-notification-message'];
             $attachments = array();
             //Download links
             foreach ($file_order_metadata as $id => $meta) {
                 $id = (int) $id;
                 $message = str_replace('[wcam_download_link id=\\"' . $id . '\\"]', '<a href="' . $meta['url'] . '">' . __('download', 'woocommerce-attach-me') . '</a>', htmlspecialchars_decode($message));
             }
             //attachment
             if (isset($item_to_attach)) {
                 foreach ($item_to_attach as $id) {
                     if (isset($file_order_metadata[$id]['absolute_path']) && file_exists($file_order_metadata[$id]['absolute_path'])) {
                         //uploaded file
                         array_push($attachments, $file_order_metadata[$id]['absolute_path']);
                     } else {
                         if (isset($file_order_metadata[$id]['media_from_gallery']) && $file_order_metadata[$id]['media_from_gallery'] == 'yes' && isset($file_order_metadata[$id]['media_id'])) {
                             array_push($attachments, get_attached_file($file_order_metadata[$id]['media_id']));
                         }
                     }
                 }
             }
             $email_sender->trigger($user_email, $_POST['wcam-notification-subject'], $message, $attachments);
             $this->results = __('Message has been sent successfully', 'woocommerce-attach-me');
         } else {
             $this->errors = __('Subject and message cannot be empty.', 'woocommerce-attach-me');
         }
     }
     $this->woocommerce_order_attachments_box(get_post($order_id));
     wp_die();
 }