コード例 #1
0
ファイル: Service.php プロジェクト: robbiespire/paQui
	/**
	 * Interface processor for the order manager
	 *	 
	 * @return void
	 **/
	function manager () {
		global $Ecart,$UI,$Notes;
		global $is_IIS;

		if ( !(is_ecart_userlevel() || current_user_can('ecart_orders')) )
			wp_die(__('You do not have sufficient permissions to access this page.','Ecart'));

		$Purchase = $Ecart->Purchase;
		$Purchase->Customer = new Customer($Purchase->customer);

		// Handle Order note processing
		if (!empty($_POST['note'])) {
			$user = wp_get_current_user();
			$Note = new MetaObject();
			$Note->parent = $Purchase->id;
			$Note->context = 'purchase';
			$Note->type = 'order_note';
			$Note->name = 'note';
			$Note->value = new stdClass();
			$Note->value->author = $user->ID;
			$Note->value->message = $_POST['note'];
			$Note->save();
		}
		if (!empty($_POST['delete-note'])) {
			$noteid = key($_POST['delete-note']);
			$Note = new MetaObject($noteid);
			$Note->delete();
		}
		if (!empty($_POST['edit-note'])) {
			$noteid = key($_POST['note-editor']);
			$Note = new MetaObject($noteid);
			$Note->value->message = $_POST['note-editor'][$noteid];
			$Note->save();
		}
		$Notes = new ObjectMeta($Purchase->id,'purchase','order_note');

		if (!empty($_POST['update'])) {
			check_admin_referer('ecart-save-order');

			if ($_POST['txnstatus'] != $Purchase->txnstatus)
				do_action_ref_array('ecart_order_txnstatus_update',array(&$_POST['txnstatus'],&$Purchase));


			$Purchase->updates($_POST);

			$mailstatus = false;
			if ($_POST['notify'] == "yes") {
				$labels = $this->Settings->get('order_status');
				// Save a reference to this purchase in Ecart
				// so the Template API works when generating the receipt
				$Ecart->Purchase =& $Purchase;

				// Send the e-mail notification
				$addressee = "$Purchase->firstname $Purchase->lastname";
				$address = "$Purchase->email";

				$email = array();
				$email['from'] = '"'.get_bloginfo("name").'"';
				if ($Ecart->Settings->get('merchant_email'))
					$email['from'] .= ' <'.$Ecart->Settings->get('merchant_email').'>';
				if($is_IIS) $email['to'] = $address;
				else $email['to'] = '"'.html_entity_decode($addressee,ENT_QUOTES).'" <'.$address.'>';
				$email['subject'] = __('Order Updated','Ecart');
				$email['url'] = get_bloginfo('siteurl');
				$email['sitename'] = get_bloginfo('name');

				if ($_POST['receipt'] == "yes")
					$email['receipt'] = $Purchase->receipt();

				$email['status'] = strtoupper($labels[$Purchase->status]);
				$email['message'] = wpautop(stripslashes($_POST['message']));

				if (file_exists(ECART_TEMPLATES."/notification.html")) $template = ECART_TEMPLATES."/notification.html";
				if (file_exists(ECART_TEMPLATES."/notify.php")) $template = ECART_TEMPLATES."/notify.php";

				if (ecart_email($template,$email)) $mailsent = true;

			}

			$Purchase->save();
			if ($mailsent) $updated = __('Order status updated & notification email sent.','Ecart');
			else $updated = __('Order status updated.','Ecart');
		}

		$targets = $this->Settings->get('target_markets');
		$UI->txnStatusLabels = Lookup::payment_status_labels();
		$UI->statusLabels = $this->Settings->get('order_status');
		if (empty($statusLabels)) $statusLabels = array('');

		include(ECART_ADMIN_PATH."/orders/order.php");
	}