예제 #1
0
	function form ($form) {
		$db =& DB::get();

		$purchasetable = DatabaseObject::tablename(Purchase::$table);
		$next = $db->query("SELECT auto_increment as id FROM information_schema.tables WHERE table_schema=database() AND table_name='$purchasetable' LIMIT 1");

		$Order = $this->Order;
		$Order->_2COcart_order_id = date('mdy').'-'.date('His').'-'.$next->id;

		// Build the transaction
		$_ = array();

		// Required
		$_['sid']				= $this->settings['sid'];
		$_['total']				= number_format($Order->Cart->Totals->total,$this->precision);
		$_['cart_order_id']		= $Order->_2COcart_order_id;
		$_['vendor_order_id']	= $this->session;
		$_['id_type']			= 1;

		// Extras
		if ($this->settings['testmode'] == "on")
			$_['demo']			= "Y";

		$_['fixed'] 			= "Y";
		$_['skip_landing'] 		= "1";

		$_['x_Receipt_Link_URL'] = $this->settings['returnurl'];

		// Line Items
		foreach($this->Order->Cart->contents as $i => $Item) {
			// $description[] = $Item->quantity."x ".$Item->name.((!empty($Item->optionlabel))?' '.$Item->optionlabel:'');
			$id = $i+1;
			$_['c_prod_'.$id]			= 'ecart_pid-'.$Item->product.','.$Item->quantity;
			$_['c_name_'.$id]			= $Item->name;
			$_['c_description_'.$id]	= !empty($Item->option->label)?$Item->$Item->option->label:'';
			$_['c_price_'.$id]			= number_format($Item->unitprice,$this->precision);

		}

		$_['card_holder_name'] 		= $Order->Customer->firstname.' '.$Order->Customer->lastname;
		$_['street_address'] 		= $Order->Billing->address;
		$_['street_address2'] 		= $Order->Billing->xaddress;
		$_['city'] 					= $Order->Billing->city;
		$_['state'] 				= $Order->Billing->state;
		$_['zip'] 					= $Order->Billing->postcode;
		$_['country'] 				= $Order->Billing->country;
		$_['email'] 				= $Order->Customer->email;
		$_['phone'] 				= $Order->Customer->phone;

		$_['ship_name'] 			= $Order->Customer->firstname.' '.$Order->Customer->lastname;
		$_['ship_street_address'] 	= $Order->Shipping->address;
		$_['ship_street_address2'] 	= $Order->Shipping->xaddress;
		$_['ship_city'] 			= $Order->Shipping->city;
		$_['ship_state'] 			= $Order->Shipping->state;
		$_['ship_zip'] 				= $Order->Shipping->postcode;
		$_['ship_country'] 			= $Order->Shipping->country;

		return $form.$this->format($_);
	}
예제 #2
0
	/**
	 * Shopping constructor
	 *	 
	 * @todo Change table to 'shopping' and update schema
	 *
	 * @return void
	 **/
	function __construct () {
		// Set the database table to use
		$this->_table = DatabaseObject::tablename('shopping');

		// Initialize the session handlers
		parent::__construct();

		// Queue the session to start
		add_action('init',array(&$this,'init'));
	}
 function attach_download($id)
 {
     if (!$id) {
         return false;
     }
     $db = DB::get();
     $table = DatabaseObject::tablename(Asset::$table);
     $db->query("DELETE FROM {$table} WHERE parent='{$this->id}' AND context='price' AND datatype='download'");
     $db->query("UPDATE {$table} SET parent='{$this->id}',context='price',datatype='download' WHERE id='{$id}'");
     do_action('attach_product_download', $id, $this->id);
     return true;
 }
예제 #4
0
파일: ui.php 프로젝트: robbiespire/paQui
function categories_meta_box ($Product) {
	$db =& DB::get();
	$category_table = DatabaseObject::tablename(Category::$table);
	$categories = $db->query("SELECT id,name,parent FROM $category_table ORDER BY parent,name",AS_ARRAY);
	$categories = sort_tree($categories);
	if (empty($categories)) $categories = array();

	$categories_menu = '<option value="0">'.__('Parent Category','Ecart').'&hellip;</option>';
	foreach ($categories as $category) {
		$padding = str_repeat("&nbsp;",$category->depth*3);
		$categories_menu .= '<option value="'.$category->id.'">'.$padding.esc_html($category->name).'</option>';
	}

	$selectedCategories = array();
	foreach ($Product->categories as $category) $selectedCategories[] = $category->id;
?>
<div id="category-menu" class="multiple-select short">
	<ul>
		<?php $depth = 0; foreach ($categories as $category):
		if ($category->depth > $depth) echo "<li><ul>"; ?>
		<?php if ($category->depth < $depth): ?>
			<?php for ($i = $category->depth; $i < $depth; $i++): ?>
				</ul></li>
			<?php endfor; ?>
		<?php endif; ?>
		<li id="category-element-<?php echo $category->id; ?>"><input type="checkbox" name="categories[]" value="<?php echo $category->id; ?>" id="category-<?php echo $category->id; ?>" tabindex="3"<?php if (in_array($category->id,$selectedCategories)) echo ' checked="checked"'; ?> class="category-toggle" /><label for="category-<?php echo $category->id; ?>"><?php echo esc_html($category->name); ?></label></li>
		<?php $depth = $category->depth; endforeach; ?>
		<?php for ($i = 0; $i < $depth; $i++): ?>
			</ul></li>
		<?php endfor; ?>
	</ul>
</div>
<div>
<div id="new-category" class="hidden">
<input type="text" name="new-category" value="" size="15" id="new-category-name" /><br />
<select name="new-category-parent"><?php echo $categories_menu; ?></select>
<button id="add-new-category" type="button" class="button-secondary" tabindex="2"><small><?php _e('Add','Ecart'); ?></small></button>
</div>
<button id="new-category-button" type="button" class="button-secondary" style="margin-top:10px;" tabindex="2"><?php _e('Add New Category','Ecart'); ?></button>
</div>

<?php
}
예제 #5
0
	/**
	 * Interface processor for the customer editor
	 *
	 * Handles rendering the interface, processing updated customer details
	 * and handing saving them back to the database
	 * 
	 * @return void
	 **/
	function editor () {
		global $Ecart,$Customer;
		$db =& DB::get();

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


		if ($_GET['id'] != "new") {
			$Customer = new Customer($_GET['id']);
			$Customer->Billing = new Billing($Customer->id,'customer');
			$Customer->Shipping = new Shipping($Customer->id,'customer');
			if (empty($Customer->id))
				wp_die(__('The requested customer record does not exist.','Ecart'));
		} else $Customer = new Customer();

		if (empty($Customer->info->meta)) remove_meta_box('customer-info','ecart_page_ecart-customers','normal');

		$purchase_table = DatabaseObject::tablename(Purchase::$table);
		$r = $db->query("SELECT count(id) AS purchases,SUM(total) AS total FROM $purchase_table WHERE customer='$Customer->id' LIMIT 1");

		$Customer->orders = $r->purchases;
		$Customer->total = $r->total;


		$countries = array(''=>'&nbsp;');
		$countrydata = Lookup::countries();
		foreach ($countrydata as $iso => $c) {
			if (isset($_POST['settings']) && $_POST['settings']['base_operations']['country'] == $iso)
				$base_region = $c['region'];
			$countries[$iso] = $c['name'];
		}
		$Customer->countries = $countries;

		$regions = Lookup::country_zones();
		$Customer->billing_states = array_merge(array(''=>'&nbsp;'),(array)$regions[$Customer->Billing->country]);
		$Customer->shipping_states = array_merge(array(''=>'&nbsp;'),(array)$regions[$Customer->Shipping->country]);

		include(ECART_ADMIN_PATH."/customers/editor.php");
	}
 function delete()
 {
     $db = DB::get();
     // Delete record
     $id = $this->{$this->_key};
     // Delete related discounts
     $discount_table = DatabaseObject::tablename(Discount::$table);
     if (!empty($id)) {
         $db->query("DELETE LOW_PRIORITY FROM {$discount_table} WHERE promo='{$id}'");
     }
     if (!empty($id)) {
         $db->query("DELETE FROM {$this->_table} WHERE {$this->_key}='{$id}'");
     } else {
         return false;
     }
 }
 function unstock()
 {
     if (!$this->inventory) {
         return;
     }
     global $Shopp;
     $db = DB::get();
     // Update stock in the database
     $table = DatabaseObject::tablename(Price::$table);
     $db->query("UPDATE {$table} SET stock=stock-{$this->quantity} WHERE id='{$this->price}' AND stock > 0");
     // Update stock in the model
     $this->option->stock -= $this->quantity;
     // Handle notifications
     $product = $this->name . ' (' . $this->option->label . ')';
     if ($this->option->stock == 0) {
         return new ShoppError(sprintf(__('%s is now out-of-stock!', 'Shopp'), $product), 'outofstock_warning', SHOPP_STOCK_ERR);
     }
     if ($this->option->stock <= $Shopp->Settings->get('lowstock_level')) {
         return new ShoppError(sprintf(__('%s has low stock levels and should be re-ordered soon.', 'Shopp'), $product), 'lowstock_warning', SHOPP_STOCK_ERR);
     }
 }
function images_meta_box($Category)
{
    $db =& DB::get();
    $Images = array();
    if (!empty($Category->id)) {
        $asset_table = DatabaseObject::tablename(Asset::$table);
        $Images = $db->query("SELECT id,src,properties FROM {$asset_table} WHERE context='category' AND parent={$Category->id} AND datatype='thumbnail' ORDER BY sortorder", AS_ARRAY);
    }
    ?>
	<ul id="lightbox">
		<?php 
    foreach ($Images as $i => $thumbnail) {
        $thumbnail->properties = unserialize($thumbnail->properties);
        ?>
			<li id="image-<?php 
        echo $thumbnail->src;
        ?>
"><input type="hidden" name="images[]" value="<?php 
        echo $thumbnail->src;
        ?>
" />
				<div id="image-<?php 
        echo $thumbnail->src;
        ?>
-details">
				<img src="?shopp_image=<?php 
        echo $thumbnail->id;
        ?>
" width="96" height="96" />
					<div class="details">
						<input type="hidden" name="imagedetails[<?php 
        echo $i;
        ?>
][id]" value="<?php 
        echo $thumbnail->id;
        ?>
" />
						<p><label>Title: </label><input type="text" name="imagedetails[<?php 
        echo $i;
        ?>
][title]" value="<?php 
        echo $thumbnail->properties['title'];
        ?>
" /></p>
						<p><label>Alt: </label><input type="text" name="imagedetails[<?php 
        echo $i;
        ?>
][alt]" value="<?php 
        echo $thumbnail->properties['alt'];
        ?>
" /></p>
						<p class="submit"><input type="button" name="close" value="Close" class="button close" /></p>
					</div>
				</div>
				<button type="button" name="deleteImage" value="<?php 
        echo $thumbnail->src;
        ?>
" title="Delete category image&hellip;" class="deleteButton"><img src="<?php 
        echo SHOPP_PLUGINURI;
        ?>
/core/ui/icons/delete.png" alt="-" width="16" height="16" /></button></li>
		<?php 
    }
    ?>
	</ul>
	<div class="clear"></div>
	<input type="hidden" name="category" value="<?php 
    echo $_GET['id'];
    ?>
" id="image-category-id" />
	<input type="hidden" name="deleteImages" id="deleteImages" value="" />
	<div id="swf-uploader-button"></div>
	<div id="swf-uploader">
	<button type="button" class="button-secondary" name="add-image" id="add-image" tabindex="10"><small><?php 
    _e('Add New Image', 'Shopp');
    ?>
</small></button></div>
	<div id="browser-uploader">
		<button type="button" name="image_upload" id="image-upload" class="button-secondary"><small><?php 
    _e('Add New Image', 'Shopp');
    ?>
</small></button><br class="clear"/>
	</div>
	<p><?php 
    _e('The first image will be the default image. These thumbnails are out of proportion, but will be correctly sized for shoppers.', 'Shopp');
    ?>
</p>
<?php 
}
 /**
  * Deletes the record associated with this object */
 function delete()
 {
     $db = DB::get();
     $id = $this->{$this->_key};
     if (empty($id)) {
         return false;
     }
     // Delete from categories
     $table = DatabaseObject::tablename(Catalog::$table);
     $db->query("DELETE LOW_PRIORITY FROM {$table} WHERE product='{$id}'");
     // Delete prices
     $table = DatabaseObject::tablename(Price::$table);
     $db->query("DELETE LOW_PRIORITY FROM {$table} WHERE product='{$id}'");
     // Delete specs
     $table = DatabaseObject::tablename(Spec::$table);
     $db->query("DELETE LOW_PRIORITY FROM {$table} WHERE product='{$id}'");
     // Delete images/files
     $table = DatabaseObject::tablename(Asset::$table);
     // Delete images
     $images = array();
     $src = $db->query("SELECT id FROM {$table} WHERE parent='{$id}' AND context='product' AND datatype='image'", AS_ARRAY);
     foreach ($src as $img) {
         $images[] = $img->id;
     }
     $this->delete_images($images);
     // Delete product downloads (but keep the file if on file system)
     $db->query("DELETE LOW_PRIORITY FROM {$table} WHERE parent='{$id}' AND context='product'");
     // Delete record
     $db->query("DELETE FROM {$this->_table} WHERE {$this->_key}='{$id}'");
 }
 /**
  * lookups ()
  * Provides fast db lookups with as little overhead as possible */
 function lookups($wp)
 {
     $db =& DB::get();
     // Grab query requests from permalink rewriting query vars
     $admin = false;
     $download = isset($wp->query_vars['shopp_download']) ? $wp->query_vars['shopp_download'] : '';
     $lookup = isset($wp->query_vars['shopp_lookup']) ? $wp->query_vars['shopp_lookup'] : '';
     // Admin Lookups
     if (isset($_GET['page']) && $_GET['page'] == "shopp-lookup") {
         $admin = true;
         $image = $_GET['id'];
         $download = $_GET['download'];
     }
     if (!empty($download)) {
         $lookup = "download";
     }
     if (empty($lookup)) {
         $lookup = isset($_GET['lookup']) ? $_GET['lookup'] : '';
     }
     switch ($lookup) {
         case "purchaselog":
             if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) {
                 die('-1');
             }
             $db =& DB::get();
             if (!isset($_POST['settings']['purchaselog_columns'])) {
                 $_POST['settings']['purchaselog_columns'] = array_keys(array_merge($Purchase, $Purchased));
                 $_POST['settings']['purchaselog_headers'] = "on";
             }
             $this->Flow->settings_save();
             $format = $this->Settings->get('purchaselog_format');
             if (empty($format)) {
                 $format = 'tab';
             }
             switch ($format) {
                 case "csv":
                     new PurchasesCSVExport();
                     break;
                 case "xls":
                     new PurchasesXLSExport();
                     break;
                 case "iif":
                     new PurchasesIIFExport();
                     break;
                 default:
                     new PurchasesTabExport();
             }
             exit;
             break;
         case "customerexport":
             if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) {
                 die('-1');
             }
             $db =& DB::get();
             if (!isset($_POST['settings']['customerexport_columns'])) {
                 $Customer = Customer::exportcolumns();
                 $Billing = Billing::exportcolumns();
                 $Shipping = Shipping::exportcolumns();
                 $_POST['settings']['customerexport_columns'] = array_keys(array_merge($Customer, $Billing, $Shipping));
                 $_POST['settings']['customerexport_headers'] = "on";
             }
             $this->Flow->settings_save();
             $format = $this->Settings->get('customerexport_format');
             if (empty($format)) {
                 $format = 'tab';
             }
             switch ($format) {
                 case "csv":
                     new CustomersCSVExport();
                     break;
                 case "xls":
                     new CustomersXLSExport();
                     break;
                 default:
                     new CustomersTabExport();
             }
             exit;
             break;
         case "receipt":
             if (!defined('WP_ADMIN') || !is_user_logged_in() || !current_user_can('manage_options')) {
                 die('-1');
             }
             if (preg_match("/\\d+/", $_GET['id'])) {
                 $this->Cart->data->Purchase = new Purchase($_GET['id']);
                 $this->Cart->data->Purchase->load_purchased();
             } else {
                 die('-1');
             }
             echo "<html><head>";
             echo '<style type="text/css">body { padding: 20px; font-family: Arial,Helvetica,sans-serif; }</style>';
             echo "<link rel='stylesheet' href='" . SHOPP_TEMPLATES_URI . "/shopp.css' type='text/css' />";
             echo "</head><body>";
             echo $this->Flow->order_receipt();
             if (isset($_GET['print']) && $_GET['print'] == 'auto') {
                 echo '<script type="text/javascript">window.onload = function () { window.print(); window.close(); }</script>';
             }
             echo "</body></html>";
             exit;
             break;
         case "zones":
             $zones = $this->Settings->get('zones');
             if (isset($_GET['country'])) {
                 echo json_encode($zones[$_GET['country']]);
             }
             exit;
             break;
         case "shipcost":
             @session_start();
             $this->ShipCalcs = new ShipCalcs($this->path);
             if (isset($_GET['method'])) {
                 $this->Cart->data->Order->Shipping->method = $_GET['method'];
                 $this->Cart->retotal = true;
                 $this->Cart->updated();
                 $this->Cart->totals();
                 echo json_encode($this->Cart->data->Totals);
             }
             exit;
             break;
         case "category-menu":
             echo $this->Flow->category_menu();
             exit;
             break;
         case "category-products-menu":
             echo $this->Flow->category_products();
             exit;
             break;
         case "spectemplate":
             $db = DB::get();
             $table = DatabaseObject::tablename(Category::$table);
             $result = $db->query("SELECT specs FROM {$table} WHERE id='{$_GET['cat']}' AND spectemplate='on'");
             echo json_encode(unserialize($result->specs));
             exit;
             break;
         case "optionstemplate":
             $db = DB::get();
             $table = DatabaseObject::tablename(Category::$table);
             $result = $db->query("SELECT options,prices FROM {$table} WHERE id='{$_GET['cat']}' AND variations='on'");
             if (empty($result)) {
                 exit;
             }
             $result->options = unserialize($result->options);
             $result->prices = unserialize($result->prices);
             foreach ($result->options as &$menu) {
                 foreach ($menu['options'] as &$option) {
                     $option['id'] += $_GET['cat'];
                 }
             }
             foreach ($result->prices as &$price) {
                 $optionids = explode(",", $price['options']);
                 foreach ($optionids as &$id) {
                     $id += $_GET['cat'];
                 }
                 $price['options'] = join(",", $optionids);
                 $price['optionkey'] = "";
             }
             echo json_encode($result);
             exit;
             break;
         case "newproducts-rss":
             $NewProducts = new NewProducts(array('show' => 5000));
             header("Content-type: application/rss+xml; charset=utf-8");
             echo shopp_rss($NewProducts->rss());
             exit;
             break;
         case "category-rss":
             $this->catalog($wp);
             header("Content-type: application/rss+xml; charset=utf-8");
             echo shopp_rss($this->Category->rss());
             exit;
             break;
         case "download":
             if (empty($download)) {
                 break;
             }
             if ($admin) {
                 $Asset = new Asset($download);
             } else {
                 $db = DB::get();
                 $pricetable = DatabaseObject::tablename(Purchase::$table);
                 $pricetable = DatabaseObject::tablename(Price::$table);
                 $assettable = DatabaseObject::tablename(Asset::$table);
                 require_once "core/model/Purchased.php";
                 $Purchased = new Purchased($download, "dkey");
                 $Purchase = new Purchase($Purchased->purchase);
                 $target = $db->query("SELECT target.* FROM {$assettable} AS target LEFT JOIN {$pricetable} AS pricing ON pricing.id=target.parent AND target.context='price' WHERE pricing.id={$Purchased->price} AND target.datatype='download'");
                 $Asset = new Asset();
                 $Asset->populate($target);
                 $forbidden = false;
                 // Purchase Completion check
                 if ($Purchase->transtatus != "CHARGED" && !SHOPP_PREPAYMENT_DOWNLOADS) {
                     new ShoppError(__('This file cannot be downloaded because payment has not been received yet.', 'Shopp'), 'shopp_download_limit');
                     $forbidden = true;
                 }
                 // Account restriction checks
                 if ($this->Settings->get('account_system') != "none" && (!$this->Cart->data->login || $this->Cart->data->Order->Customer->id != $Purchase->customer)) {
                     new ShoppError(__('You must login to access this download.', 'Shopp'), 'shopp_download_limit', SHOPP_ERR);
                     header('Location: ' . $this->link('account'));
                     exit;
                 }
                 // Download limit checking
                 if ($this->Settings->get('download_limit') && $Purchased->downloads + 1 > $this->Settings->get('download_limit')) {
                     new ShoppError(__('This file can no longer be downloaded because the download limit has been reached.', 'Shopp'), 'shopp_download_limit');
                     $forbidden = true;
                 }
                 // Download expiration checking
                 if ($this->Settings->get('download_timelimit') && $Purchased->created + $this->Settings->get('download_timelimit') < mktime()) {
                     new ShoppError(__('This file can no longer be downloaded because it has expired.', 'Shopp'), 'shopp_download_limit');
                     $forbidden = true;
                 }
                 // IP restriction checks
                 if ($this->Settings->get('download_restriction') == "ip" && !empty($Purchase->ip) && $Purchase->ip != $_SERVER['REMOTE_ADDR']) {
                     new ShoppError(__('The file cannot be downloaded because this computer could not be verified as the system the file was purchased from.', 'Shopp'), 'shopp_download_limit');
                     $forbidden = true;
                 }
                 do_action_ref_array('shopp_download_request', array(&$Purchased));
             }
             if ($forbidden) {
                 header("Status: 403 Forbidden");
                 return;
             }
             if ($Asset->download($download)) {
                 $Purchased->downloads++;
                 $Purchased->save();
                 do_action_ref_array('shopp_download_success', array(&$Purchased));
                 exit;
             }
             break;
     }
 }
예제 #11
0
	function smart ($options=array()) {
		$this->slug = self::$_slug;

		global $Ecart;
		$Cart = $Ecart->Order->Cart;
		$tagtable = DatabaseObject::tablename(Tag::$table);
		$catalogtable = DatabaseObject::tablename(Catalog::$table);

		// Use the current product if available
		if (!empty($Ecart->Product->id))
			$this->product = $Ecart->Product;

		// Or load a product specified
		if (isset($options['product'])) {
			if ($options['product'] == "recent-cartitem") 			// Use most recently added item in the cart
				$this->product = new Product($Cart->Added->product);
			elseif (preg_match('/^[\d+]$/',$options['product']) !== false) 	// Load by specified id
				$this->product = new Product($options['product']);
			else
				$this->product = new Product($options['product'],'slug'); // Load by specified slug
		}

		if (empty($this->product->id)) return false;

		// Load the product's tags if they are not available
		if (empty($this->product->tags))
			$this->product->load_data(array('tags'));

		if (empty($this->product->tags)) return false;

		$tagscope = "";
		if (isset($options['tagged'])) {
			$tagged = new Tag($options['tagged'],'name');

			if (!empty($tagged->id)) {
				$tagscope .= (empty($tagscope)?"":" OR ")."catalog.parent=$tagged->id";
			}

		}

		foreach ($this->product->tags as $tag)
			if (!empty($tag->id))
				$tagscope .= (empty($tagscope)?"":" OR ")."catalog.parent=$tag->id";

		if (!empty($tagscope)) $tagscope = "($tagscope) AND catalog.type='tag'";

		$this->tag = "product-".$this->product->id;
		$this->name = __("Products related to","Ecart")." &quot;".stripslashes($this->product->name)."&quot;";
		$this->uri = urlencode($this->tag);
		$this->controls = false;

		$exclude = "";
		if (!empty($this->product->id)) $exclude = " AND p.id != {$this->product->id}";

		$this->loading = array(
			'columns'=>'count(DISTINCT catalog.id)+SUM(IF('.$tagscope.',100,0)) AS score',
			'joins'=>"LEFT JOIN $catalogtable AS catalog ON catalog.product=p.id LEFT JOIN $tagtable AS t ON t.id=catalog.parent AND catalog.product=p.id",
			'where'=>"($tagscope) $exclude",
			'orderby'=>'score DESC'
			);
		if (isset($options['order'])) $this->loading['order'] = $options['order'];
		if (isset($options['controls']) && value_is_true($options['controls']))
			unset($this->controls);
	}
예제 #12
0
	function query ($request=array()) {
		$db =& DB::get();
		if (empty($request)) $request = $_GET;

		if (!empty($request['start'])) {
			list($month,$day,$year) = explode("/",$request['start']);
			$starts = mktime(0,0,0,$month,$day,$year);
		}

		if (!empty($request['end'])) {
			list($month,$day,$year) = explode("/",$request['end']);
			$ends = mktime(0,0,0,$month,$day,$year);
		}

		$where = "WHERE o.id IS NOT NULL AND p.id IS NOT NULL ";
		if (isset($request['status']) && !empty($request['status'])) $where .= "AND status='{$request['status']}'";
		if (isset($request['s']) && !empty($request['s'])) $where .= " AND (id='{$request['s']}' OR firstname LIKE '%{$request['s']}%' OR lastname LIKE '%{$request['s']}%' OR CONCAT(firstname,' ',lastname) LIKE '%{$request['s']}%' OR transactionid LIKE '%{$request['s']}%')";
		if (!empty($request['start']) && !empty($request['end'])) $where .= " AND  (UNIX_TIMESTAMP(o.created) >= $starts AND UNIX_TIMESTAMP(o.created) <= $ends)";

		$purchasetable = DatabaseObject::tablename(Purchase::$table);
		$purchasedtable = DatabaseObject::tablename(Purchased::$table);
		$offset = ($this->set*$this->limit);

		$c = 0; $columns = array();
		foreach ($this->selected as $column) $columns[] = "$column AS col".$c++;
		$query = "SELECT ".join(",",$columns)." FROM $purchasedtable AS p LEFT JOIN $purchasetable AS o ON o.id=p.purchase $where ORDER BY o.created ASC LIMIT $offset,$this->limit";
		$this->data = $db->query($query,AS_ARRAY);
	}
예제 #13
0
	/**
	 * Ecart 1.1.0 upgrades
	 * 
	 * @since 1.1
	 *
	 * @return void
	 **/
	function upgrade_110 () {
		$db =& DB::get();
		$meta_table = DatabaseObject::tablename('meta');
		$db->query("DELETE FROM $meta_table"); // Clear out previous meta

		// Update product status from the 'published' column
		$product_table = DatabaseObject::tablename('product');
		$db->query("UPDATE $product_table SET status=CAST(published AS unsigned)");

		// Set product publish date based on the 'created' date column
		$db->query("UPDATE $product_table SET publish=created WHERE status='publish'");

		// Update Catalog
		$catalog_table = DatabaseObject::tablename('catalog');
		$db->query("UPDATE $catalog_table set parent=IF(category!=0,category,tag),type=IF(category!=0,'category','tag')");

		// Update specs
		$meta_table = DatabaseObject::tablename('meta');
		$spec_table = DatabaseObject::tablename('spec');
		$db->query("INSERT INTO $meta_table (parent,context,type,name,value,numeral,sortorder,created,modified)
					SELECT product,'product','spec',name,content,numeral,sortorder,now(),now() FROM $spec_table");

		// Update purchase table
		$purchase_table = DatabaseObject::tablename('purchase');
		$db->query("UPDATE $purchase_table SET txnid=transactionid,txnstatus=transtatus");

		// Update image assets
		$meta_table = DatabaseObject::tablename('meta');
		$asset_table = DatabaseObject::tablename('asset');
		$db->query("INSERT INTO $meta_table (parent,context,type,name,value,numeral,sortorder,created,modified)
							SELECT parent,context,'image','processing',CONCAT_WS('::',id,name,value,size,properties,LENGTH(data)),'0',sortorder,created,modified FROM $asset_table WHERE datatype='image'");
		$records = $db->query("SELECT id,value FROM $meta_table WHERE type='image' AND name='processing'",AS_ARRAY);
		foreach ($records as $r) {
			list($src,$name,$value,$size,$properties,$datasize) = explode("::",$r->value);
			$p = unserialize($properties);
			$value = new StdClass();
			if (isset($p['width'])) $value->width = $p['width'];
			if (isset($p['height'])) $value->height = $p['height'];
			if (isset($p['alt'])) $value->alt = $p['alt'];
			if (isset($p['title'])) $value->title = $p['title'];
			$value->filename = $name;
			if (isset($p['mimetype'])) $value->mime = $p['mimetype'];
			$value->size = $size;
			error_log(serialize($value));
			if ($datasize > 0) {
				$value->storage = "DBStorage";
				$value->uri = $src;
			} else {
				$value->storage = "FSStorage";
				$value->uri = $name;
			}
			$value = mysql_real_escape_string(serialize($value));
			$db->query("UPDATE $meta_table set name='original',value='$value' WHERE id=$r->id");
		}

		// Update product downloads
		$meta_table = DatabaseObject::tablename('meta');
		$asset_table = DatabaseObject::tablename('asset');
		$query = "INSERT INTO $meta_table (parent,context,type,name,value,numeral,sortorder,created,modified)
					SELECT parent,context,'download','processing',CONCAT_WS('::',id,name,value,size,properties,LENGTH(data)),'0',sortorder,created,modified FROM $asset_table WHERE datatype='download' AND parent != 0";
		$db->query($query);
		$records = $db->query("SELECT id,value FROM $meta_table WHERE type='download' AND name='processing'",AS_ARRAY);
		foreach ($records as $r) {
			list($src,$name,$value,$size,$properties,$datasize) = explode("::",$r->value);
			$p = unserialize($properties);
			$value = new StdClass();
			$value->filename = $name;
			$value->mime = $p['mimetype'];
			$value->size = $size;
			if ($datasize > 0) {
				$value->storage = "DBStorage";
				$value->uri = $src;
			} else {
				$value->storage = "FSStorage";
				$value->uri = $name;
			}
			$value = mysql_real_escape_string(serialize($value));
			$db->query("UPDATE $meta_table set name='$name',value='$value' WHERE id=$r->id");
		}

		// Update promotions
		$promo_table = DatabaseObject::tablename('promo');
		$records = $db->query("UPDATE $promo_table SET target='Cart' WHERE scope='Order'",AS_ARRAY);

		$FSStorage = array('path' => array());
		// Migrate Asset storage settings
		$image_storage = $this->Settings->get('image_storage_pref');
		if ($image_storage == "fs") {
			$image_storage = "FSStorage";
			$FSStorage['path']['image'] = $this->Settings->get('image_path');
		} else $image_storage = "DBStorage";
		$this->Settings->save('image_storage',$image_storage);

		$product_storage = $this->Settings->get('product_storage_pref');
		if ($product_storage == "fs") {
			$product_storage = "FSStorage";
			$FSStorage['path']['download'] = $this->Settings->get('products_path');
		} else $product_storage = "DBStorage";
		$this->Settings->save('product_storage',$product_storage);

		if (!empty($FSStorage['path'])) $this->Settings->save('FSStorage',$FSStorage);

		// Preserve payment settings

		// Determine active gateways
		$active_gateways = array($this->Settings->get('payment_gateway'));
		$xco_gateways = (array)$this->Settings->get('xco_gateways');
		if (!empty($xco_gateways))
			$active_gateways = array_merge($active_gateways,$xco_gateways);

		// Load 1.0 payment gateway settings for active gateways
		$gateways = array();
		foreach ($active_gateways as $reference) {
			list($dir,$filename) = explode('/',$reference);
			$gateways[] = preg_replace('/[^\w+]/','',substr($filename,0,strrpos($filename,'.')));
		}

		$where = "name like '%".join("%' OR name like '%",$gateways)."%'";
		$query = "SELECT name,value FROM wp_ecart_setting WHERE $where";
		$result = $db->query($query,AS_ARRAY);
		require_once(ECART_MODEL_PATH.'/Lookup.php');
		$paycards = Lookup::paycards();

		// Convert settings to 1.1-compatible settings
		$active_gateways = array();
		foreach ($result as $_) {
			$active_gateways[] = $_->name;		// Add gateway to the active gateways list
			$setting = unserialize($_->value);	// Parse the settings

			// Get rid of legacy settings
			unset($setting['enabled'],$setting['path'],$setting['billing-required']);

			// Convert accepted payment cards
			$accepted = array();
			if (isset($setting['cards']) && is_array($setting['cards'])) {
				foreach ($setting['cards'] as $cardname) {
					// Normalize card names
					$cardname = str_replace(
						array(	"Discover",
								"Diner’s Club",
								"Diners"
						),
						array(	"Discover Card",
								"Diner's Club",
								"Diner's Club"
						),
						$cardname);

					foreach ($paycards as $card)
						if ($cardname == $card->name) $accepted[] = $card->symbol;
				}
				$setting['cards'] = $accepted;
			}
			$this->Settings->save($_->name,$setting); // Save the gateway settings
		}
		// Save the active gateways to populate the payment settings page
		$this->Settings->save('active_gateways',join(',',$active_gateways));

		// Preserve update key
		$oldkey = $this->Settings->get('updatekey');
		if (!empty($oldkey)) {
			$newkey = array(
				($oldkey['status'] == "activated"?1:0),
				$oldkey['key'],
				$oldkey['type']
			);
			$this->Settings->save('updatekey',$newkey);
		}

		$this->roles(); // Setup Roles and Capabilities

	}
예제 #14
0
	function query ($request=array()) {
		$db =& DB::get();
		if (empty($request)) $request = $_GET;

		if (!empty($request['start'])) {
			list($month,$day,$year) = explode("/",$request['start']);
			$starts = mktime(0,0,0,$month,$day,$year);
		}

		if (!empty($request['end'])) {
			list($month,$day,$year) = explode("/",$request['end']);
			$ends = mktime(0,0,0,$month,$day,$year);
		}

		$where = "WHERE c.id IS NOT NULL ";
		if (isset($request['s']) && !empty($request['s'])) $where .= " AND (id='{$request['s']}' OR firstname LIKE '%{$request['s']}%' OR lastname LIKE '%{$request['s']}%' OR CONCAT(firstname,' ',lastname) LIKE '%{$request['s']}%' OR transactionid LIKE '%{$request['s']}%')";
		if (!empty($request['start']) && !empty($request['end'])) $where .= " AND  (UNIX_TIMESTAMP(c.created) >= $starts AND UNIX_TIMESTAMP(c.created) <= $ends)";

		$customer_table = DatabaseObject::tablename(Customer::$table);
		$billing_table = DatabaseObject::tablename(Billing::$table);
		$shipping_table = DatabaseObject::tablename(Shipping::$table);
		$offset = $this->set*$this->limit;

		$c = 0; $columns = array();
		foreach ($this->selected as $column) $columns[] = "$column AS col".$c++;
		$query = "SELECT ".join(",",$columns)." FROM $customer_table AS c LEFT JOIN $billing_table AS b ON c.id=b.customer LEFT JOIN $shipping_table AS s ON c.id=s.customer $where ORDER BY c.created ASC LIMIT $offset,$this->limit";
		$this->data = $db->query($query,AS_ARRAY);
	}
예제 #15
0
파일: Admin.php 프로젝트: robbiespire/paQui
	/**
	 * Renders the recent orders dashboard widget
	 * 
	 * @since 1.0
	 *
	 * @return void
	 **/
	function orders_widget ($args=null) {
		global $Ecart;
		$db = DB::get();
		$defaults = array(
			'before_widget' => '',
			'before_title' => '',
			'widget_name' => '',
			'after_title' => '',
			'after_widget' => ''
		);
		if (!$args) $args = array();
		$args = array_merge($defaults,$args);
		if (!empty($args)) extract( $args, EXTR_SKIP );
		$statusLabels = $this->Settings->get('order_status');

		echo $before_widget;

		echo $before_title;
		echo $widget_name;
		echo $after_title;

		$purchasetable = DatabaseObject::tablename(Purchase::$table);
		$purchasedtable = DatabaseObject::tablename(Purchased::$table);

		$Orders = $db->query("SELECT p.*,count(i.id) as items FROM $purchasetable AS p LEFT JOIN $purchasedtable AS i ON i.purchase=p.id GROUP BY i.purchase ORDER BY created DESC LIMIT 6",AS_ARRAY);

		if (!empty($Orders)) {
		echo '<table class="widefat">';
		echo '<tr><th scope="col">'.__('Name','Ecart').'</th><th scope="col">'.__('Date','Ecart').'</th><th scope="col" class="num">'.__('Items','Ecart').'</th><th scope="col" class="num">'.__('Total','Ecart').'</th><th scope="col" class="num">'.__('Status','Ecart').'</th></tr>';
		echo '<tbody id="orders" class="list orders">';
		$even = false;
		foreach ($Orders as $Order) {
			echo '<tr'.((!$even)?' class="alternate"':'').'>';
			$even = !$even;
			echo '<td><a class="row-title" href="'.add_query_arg(array('page'=>$this->pagename('orders'),'id'=>$Order->id),admin_url('admin.php')).'" title="View &quot;Order '.$Order->id.'&quot;">'.((empty($Order->firstname) && empty($Order->lastname))?'(no contact name)':$Order->firstname.' '.$Order->lastname).'</a></td>';
			echo '<td>'.date("Y/m/d",mktimestamp($Order->created)).'</td>';
			echo '<td class="num">'.$Order->items.'</td>';
			echo '<td class="num">'.money($Order->total).'</td>';
			echo '<td class="num">'.$statusLabels[$Order->status].'</td>';
			echo '</tr>';
		}
		echo '</tbody></table>';
		} else {
			echo '<p>'.__('No orders, yet.','Ecart').'</p>';
		}

		echo $after_widget;

	}
예제 #16
0
function categories_meta_box($Product)
{
    $db =& DB::get();
    $category_table = DatabaseObject::tablename(Category::$table);
    $categories = $db->query("SELECT id,name,parent FROM {$category_table} ORDER BY parent,name", AS_ARRAY);
    $categories = sort_tree($categories);
    if (empty($categories)) {
        $categories = array();
    }
    $categories_menu = '<option value="0" rel="-1,-1">' . __('Parent Category', 'Shopp') . '&hellip;</option>';
    foreach ($categories as $category) {
        $padding = str_repeat("&nbsp;", $category->depth * 3);
        $categories_menu .= '<option value="' . $category->id . '" rel="' . $category->parent . ',' . $category->depth . '">' . $padding . $category->name . '</option>';
    }
    $selectedCategories = array();
    foreach ($Product->categories as $category) {
        $selectedCategories[] = $category->id;
    }
    ?>
<div id="category-menu" class="multiple-select short">
	<ul>
		<?php 
    $depth = 0;
    foreach ($categories as $category) {
        if ($category->depth > $depth) {
            echo "<li><ul>";
        }
        ?>
		<?php 
        if ($category->depth < $depth) {
            ?>
			<?php 
            for ($i = $category->depth; $i < $depth; $i++) {
                ?>
				</ul></li>
			<?php 
            }
            ?>
		<?php 
        }
        ?>
		<li id="category-element-<?php 
        echo $category->id;
        ?>
"><input type="checkbox" name="categories[]" value="<?php 
        echo $category->id;
        ?>
" id="category-<?php 
        echo $category->id;
        ?>
" tabindex="3"<?php 
        if (in_array($category->id, $selectedCategories)) {
            echo ' checked="checked"';
        }
        ?>
 class="category-toggle" /><label for="category-<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</label></li>
		<?php 
        $depth = $category->depth;
    }
    ?>
		<?php 
    for ($i = 0; $i < $depth; $i++) {
        ?>
			</ul></li>
		<?php 
    }
    ?>
	</ul>
</div>
<div id="new-category">
<input type="text" name="new-category" value="" size="15" id="new-category" /><br />
<select name="new-category-parent"><?php 
    echo $categories_menu;
    ?>
</select>
<button id="add-new-category" type="button" class="button-secondary" tabindex="2"><small><?php 
    _e('Add', 'Shopp');
    ?>
</small></button>
</div>

<?php 
}
예제 #17
0
파일: Cart.php 프로젝트: robbiespire/paQui
	/**
	 * Loads promotions applicable to this shopping session if needed
	 *	 
	 * @since 1.1
	 *
	 * @return void
	 **/
	function load () {
		$db = &DB::get();

		// Already loaded
		if (!empty($this->promotions)) return true;

		// Use an offset amount as a buffer to account for how
		// MySQL's UNIX_TIMESTAMP() converts the datetime to a
		// UTC-based timestamp from the Jan 1, 1970 00:00:00 epoch
		// We use 43200 to represent 12-hours (UTC +/- 12 hours) and
		// add 1 to account for the default amount set in the promotion editor
		$offset = 43200 + 1;

		$_table = DatabaseObject::tablename(Promotion::$table);
		$query = "SELECT * FROM $_table WHERE (target='Cart' OR target='Cart Item')
		            AND status='enabled' -- Promo must be enabled, in all cases
					AND (
					    -- Promo is not date based
					    (
					        UNIX_TIMESTAMP(starts) <= $offset
					        AND
					        UNIX_TIMESTAMP(ends) <= $offset
					    )
					    OR
					    -- Promo has start and end dates, check that we are in between
					    (
					        UNIX_TIMESTAMP(starts) > $offset
					        AND
					        UNIX_TIMESTAMP(ends) > $offset
					        AND
					        (".time()." BETWEEN UNIX_TIMESTAMP(starts) AND UNIX_TIMESTAMP(ends))
					    )
					    OR
					    -- Promo has _only_ a start date, check that we are after it
					    (
					        UNIX_TIMESTAMP(starts) > $offset
					        AND
					        UNIX_TIMESTAMP(ends) <= $offset
					        AND
					        UNIX_TIMESTAMP(starts) < ".time()."
					    )
					    OR
					    -- Promo has _only_ an end date, check that we are before it
					    (
					        UNIX_TIMESTAMP(starts) <= $offset
					        AND
					        UNIX_TIMESTAMP(ends) > $offset
					        AND
					        ".time()." < UNIX_TIMESTAMP(ends)
						)
				    ) ORDER BY target DESC";
		$this->promotions = $db->query($query,AS_ARRAY);
	}
 function RelatedProducts($options = array())
 {
     global $Shopp;
     $tagtable = DatabaseObject::tablename(Tag::$table);
     $catalogtable = DatabaseObject::tablename(Catalog::$table);
     // Use the current product if available
     if (!empty($Shopp->Product->id)) {
         $this->product = $Shopp->Product;
     }
     // Or load a product specified
     if (isset($options['product'])) {
         if ($options['product'] == "recent-cartitem") {
             // Use most recently added item in the cart
             $this->product = new Product($Shopp->Cart->contents[$Shopp->Cart->data->added]->product);
         } elseif (preg_match('/^[\\d+]$/', $options['product'])) {
             // Load by specified id
             $this->product = new Product($options['product']);
         } else {
             $this->product = new Product($options['product'], 'slug');
         }
         // Load by specified slug
     }
     if (empty($this->product->id)) {
         return false;
     }
     // Load the product's tags if they are not available
     if (empty($this->product->tags)) {
         $this->product->load_data(array('tags'));
     }
     if (empty($this->product->tags)) {
         return false;
     }
     $tagscope = "";
     if (isset($options['tagged'])) {
         $tagged = new Tag($options['tagged'], 'name');
         if (!empty($tagged->id)) {
             $tagscope .= (empty($tagscope) ? "" : " OR ") . "catalog.tag={$tagged->id}";
         }
     }
     foreach ($this->product->tags as $tag) {
         if (!empty($tag->id)) {
             $tagscope .= (empty($tagscope) ? "" : " OR ") . "catalog.tag={$tag->id}";
         }
     }
     $this->tag = "product-" . $this->product->id;
     $this->name = __("Products related to", "Shopp") . " &quot;" . stripslashes($this->product->name) . "&quot;";
     $this->slug = self::$_slug;
     $this->uri = urlencode($this->tag);
     $this->smart = true;
     $this->controls = false;
     $exclude = "";
     if (!empty($this->product->id)) {
         $exclude = " AND p.id != {$this->product->id}";
     }
     $this->loading = array('columns' => 'count(DISTINCT catalog.id)+SUM(IF(' . $tagscope . ',100,0)) AS score', 'joins' => "LEFT JOIN {$catalogtable} AS catalog ON catalog.product=p.id LEFT JOIN {$tagtable} AS t ON t.id=catalog.tag AND catalog.product=p.id", 'where' => "({$tagscope}) {$exclude}", 'orderby' => 'score DESC');
     if (isset($options['show'])) {
         $this->loading['limit'] = $options['show'];
     }
     if (isset($options['pagination'])) {
         $this->loading['pagination'] = $options['pagination'];
     }
     if (isset($options['order'])) {
         $this->loading['order'] = $options['order'];
     }
     if (isset($options['controls']) && value_is_true($options['controls'])) {
         unset($this->controls);
     }
 }
 function upgrade()
 {
     global $Shopp, $table_prefix;
     $db = DB::get();
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     // Check for the schema definition file
     if (!file_exists(SHOPP_DBSCHEMA)) {
         die("Could not upgrade the Shopp database tables because the table definitions file is missing: " . SHOPP_DBSCHEMA);
     }
     ob_start();
     include SHOPP_DBSCHEMA;
     $schema = ob_get_contents();
     ob_end_clean();
     // Update the table schema
     $tables = preg_replace('/;\\s+/', ';', $schema);
     dbDelta($tables);
     $this->setup_regions();
     $this->setup_countries();
     $this->setup_zones();
     $this->setup_areas();
     $this->setup_vat();
     // Update the version number
     $settings = DatabaseObject::tablename(Settings::$table);
     $db->query("UPDATE {$settings} SET value='" . SHOPP_VERSION . " WHERE name='version'");
     $db->query("DELETE FROM {$settings} WHERE name='data_model' OR name='shipcalc_lastscan");
     return true;
 }
예제 #20
0
	/**
	 * Interface processor for the product list manager
	 *	 
	 * @return void
	 **/
	function products ($workflow=false) {
		global $Ecart;
		$db = DB::get();

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

		$defaults = array(
			'pagenum' => 1,
			'per_page' => 500,
			'id' => 0,
			's' => ''
			);
		$args = array_merge($defaults,$_GET);
		extract($args,EXTR_SKIP);

		$pagenum = absint( $pagenum );
		if ( empty($pagenum) )
			$pagenum = 1;
		if( !$per_page || $per_page < 0 )
			$per_page = 20;
		$start = ($per_page * ($pagenum-1));

		$filters = array();
		// $filters['limit'] = "$start,$per_page";
		if (!empty($s))
			$filters['where'] = "cat.name LIKE '%$s%'";
		else $filters['where'] = "true";

		$Category = new Category($id);

		$catalog_table = DatabaseObject::tablename(Catalog::$table);
		$product_table = DatabaseObject::tablename(Product::$table);
		$columns = "c.id AS cid,p.id,c.priority,p.name";
		$where = "c.parent=$id AND type='category'";
		$query = "SELECT $columns FROM $catalog_table AS c LEFT JOIN $product_table AS p ON c.product=p.id WHERE $where ORDER BY c.priority ASC,p.name ASC LIMIT $start,$per_page";
		$products = $db->query($query);

		$count = $db->query("SELECT count(*) AS total FROM $table");
		$num_pages = ceil($count->total / $per_page);
		$page_links = paginate_links( array(
			'base' => add_query_arg( array('edit'=>null,'pagenum' => '%#%' )),
			'format' => '',
			'total' => $num_pages,
			'current' => $pagenum
		));

		$action = esc_url(
			add_query_arg(
				array_merge(stripslashes_deep($_GET),array('page'=>$this->Admin->pagename('categories'))),
				admin_url('admin.php')
			)
		);


		include(ECART_ADMIN_PATH."/categories/products.php");
	}
 function load_tags($limits = false)
 {
     $db = DB::get();
     if ($limits) {
         $limit = " LIMIT {$limits[0]},{$limits[1]}";
     } else {
         $limit = "";
     }
     $tagtable = DatabaseObject::tablename(Tag::$table);
     $query = "SELECT t.*,count(sc.product) AS products FROM {$this->_table} AS sc LEFT JOIN {$tagtable} AS t ON sc.tag=t.id WHERE sc.tag != 0 GROUP BY t.id ORDER BY t.name ASC{$limit}";
     $this->tags = $db->query($query, AS_ARRAY);
     return true;
 }
예제 #22
0
파일: Meta.php 프로젝트: robbiespire/paQui
	function __construct ($parent=false,$context='product',$type=false,$sort='sortorder') {
		$this->_table = DatabaseObject::tablename(self::$table);

		$params = array(
			'parent' => $parent,
			'context' => $context
		);

		if ($type !== false) $params['type'] = $type;
		if ($parent !== false) $this->load($params);
	}
예제 #23
0
	/**
	 * Retrieves the number of orders in each customized order status label
	 *	 
	 * @return void
	 **/
	function status_counts () {
		$db = DB::get();

		$table = DatabaseObject::tablename(Purchase::$table);
		$labels = $this->Settings->get('order_status');

		if (empty($labels)) return false;
		$status = array();

		$r = $db->query("SELECT status AS id,COUNT(status) AS total FROM $table GROUP BY status ORDER BY status ASC",AS_ARRAY);
		foreach ($labels as $id => $label) {
			$_ = new StdClass();
			$_->label = $label;
			$_->id = $id;
			$_->total = 0;
			foreach ($r as $state) {
				if ($state->id == $id) {
					$_->total = (int)$state->total;	break;
				}
			}
			$status[$id] = $_;
		}

		return $status;
	}
예제 #24
0
파일: Setup.php 프로젝트: robbiespire/paQui
	function system () {
		global $Ecart;
		if ( !(current_user_can('manage_options') && current_user_can('ecart_settings_system')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		add_action('ecart_storage_module_settings',array(&$this,'storage_ui'));

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

			if (!isset($_POST['settings']['error_notifications']))
				$_POST['settings']['error_notifications'] = array();

			$this->settings_save();

			// Reinitialize Error System
			$Ecart->Errors = new EcartErrors($this->Settings->get('error_logging'));
			$Ecart->ErrorLog = new EcartErrorLogging($this->Settings->get('error_logging'));
			$Ecart->ErrorNotify = new EcartErrorNotification($this->Settings->get('merchant_email'),
										$this->Settings->get('error_notifications'));

			$updated = __('Ecart system settings saved.','Ecart');
		} elseif (!empty($_POST['rebuild'])) {
			$db =& DB::get();

			$assets = DatabaseObject::tablename(ProductImage::$table);
			$query = "DELETE FROM $assets WHERE context='image' AND type='image'";
			if ($db->query($query))
				$updated = __('All cached images have been cleared.','Ecart');
		}


		if (isset($_POST['resetlog'])) $Ecart->ErrorLog->reset();

		$notifications = $this->Settings->get('error_notifications');
		if (empty($notifications)) $notifications = array();

		$notification_errors = array(
			ECART_TRXN_ERR => __("Transaction Errors","Ecart"),
			ECART_AUTH_ERR => __("Login Errors","Ecart"),
			ECART_ADDON_ERR => __("Add-on Errors","Ecart"),
			ECART_COMM_ERR => __("Communication Errors","Ecart"),
			ECART_STOCK_ERR => __("Inventory Warnings","Ecart")
			);

		$errorlog_levels = array(
			0 => __("Disabled","Ecart"),
			ECART_ERR => __("General Ecart Errors","Ecart"),
			ECART_TRXN_ERR => __("Transaction Errors","Ecart"),
			ECART_AUTH_ERR => __("Login Errors","Ecart"),
			ECART_ADDON_ERR => __("Add-on Errors","Ecart"),
			ECART_COMM_ERR => __("Communication Errors","Ecart"),
			ECART_STOCK_ERR => __("Inventory Warnings","Ecart"),
			ECART_ADMIN_ERR => __("Admin Errors","Ecart"),
			ECART_DB_ERR => __("Database Errors","Ecart"),
			ECART_PHP_ERR => __("PHP Errors","Ecart"),
			ECART_ALL_ERR => __("All Errors","Ecart"),
			ECART_DEBUG_ERR => __("Debugging Messages","Ecart")
			);

		// Load Storage settings
		$Ecart->Storage->settings();

		// Build the storage options menu
		$storage = array();
		foreach ($Ecart->Storage->active as $module)
			$storage[$module->module] = $module->name;

		$loading = array("ecart" => __('Load on Ecart-pages only','Ecart'),"all" => __('Load on entire site','Ecart'));

		if ($this->Settings->get('error_logging') > 0)
			$recentlog = $Ecart->ErrorLog->tail(500);

		include(ECART_ADMIN_PATH."/settings/system.php");
	}
예제 #25
0
	/**
	 * Interface processor for the promotions list manager
	 *	 
	 * @return void
	 **/
	function promotions () {
		global $Ecart;
		$db = DB::get();

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

		require_once("{$Ecart->path}/core/model/Promotion.php");

		$defaults = array(
			'page' => false,
			'deleting' => false,
			'delete' => false,
			'pagenum' => 1,
			'per_page' => 20,
			's' => ''
			);

		$args = array_merge($defaults,$_GET);
		extract($args,EXTR_SKIP);

		if ($page == "ecart-promotions"
				&& !empty($deleting)
				&& !empty($delete)
				&& is_array($delete)) {
			foreach($delete as $deletion) {
				$Promotion = new Promotion($deletion);
				$Promotion->delete();
			}
		}

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

			if ($_POST['id'] != "new") {
				$Promotion = new Promotion($_POST['id']);
			} else $Promotion = new Promotion();

			if (!empty($_POST['starts']['month']) && !empty($_POST['starts']['date']) && !empty($_POST['starts']['year']))
				$_POST['starts'] = mktime(0,0,0,$_POST['starts']['month'],$_POST['starts']['date'],$_POST['starts']['year']);
			else $_POST['starts'] = 1;

			if (!empty($_POST['ends']['month']) && !empty($_POST['ends']['date']) && !empty($_POST['ends']['year']))
				$_POST['ends'] = mktime(23,59,59,$_POST['ends']['month'],$_POST['ends']['date'],$_POST['ends']['year']);
			else $_POST['ends'] = 1;
			if (isset($_POST['rules'])) $_POST['rules'] = stripslashes_deep($_POST['rules']);

			$Promotion->updates($_POST);
			$Promotion->save();

			do_action_ref_array('ecart_promo_saved',array(&$Promotion));

			$Promotion->reset_discounts();
			if ($Promotion->target == "Catalog")
				$Promotion->build_discounts();

			// Force reload of the session promotions to include any updates
			$Ecart->Promotions->reload();

		}

		$pagenum = absint( $pagenum );
		if ( empty($pagenum) )
			$pagenum = 1;
		if( !$per_page || $per_page < 0 )
			$per_page = 20;
		$start = ($per_page * ($pagenum-1));


		$where = "";
		if (!empty($s)) $where = "WHERE name LIKE '%$s%'";

		$table = DatabaseObject::tablename(Promotion::$table);
		$promocount = $db->query("SELECT count(*) as total FROM $table $where");
		$Promotions = $db->query("SELECT * FROM $table $where",AS_ARRAY);

		$status = array(
			'enabled' => __('Enabled','Ecart'),
			'disabled' => __('Disabled','Ecart')
		);

		$num_pages = ceil($promocount->total / $per_page);
		$page_links = paginate_links( array(
			'base' => add_query_arg( 'pagenum', '%#%' ),
			'format' => '',
			'total' => $num_pages,
			'current' => $pagenum
		));

		include("{$Ecart->path}/core/ui/promotions/promotions.php");
	}
예제 #26
0
파일: Asset.php 프로젝트: robbiespire/paQui
	function loadby_dkey ($key) {
		$db = &DB::get();
		require_once(ECART_MODEL_PATH."/Purchased.php");
		$pricetable = DatabaseObject::tablename(Price::$table);

		$Purchased = new Purchased($key,"dkey");
		if (!empty($Purchased->id)) {
			// Handle purchased line-item downloads
			$Purchase = new Purchase($Purchased->purchase);
			$record = $db->query("SELECT download.* FROM $this->_table AS download LEFT JOIN $pricetable AS pricing ON pricing.id=download.parent WHERE pricing.id=$Purchased->price AND download.context='price' AND download.type='download' LIMIT 1");
			$this->populate($record);
			$this->expopulate();
			$this->purchased = $Purchased->id;
		} else {
			// Handle purchased line-item meta downloads (addon downloads)
			$MetaDownload = new MetaObject(array(
				'context' => 'purchased',
				'type' => 'download',
				'name' => $key
			));
			$this->load($MetaDownload->value);
			$this->purchased = $MetaDownload->parent;
		}

		$this->etag = $key;
	}
function shopp_settings_js($dir = "shopp")
{
    $db =& DB::get();
    $table = DatabaseObject::tablename(Settings::$table);
    $settings = $db->query("SELECT name,value FROM {$table} WHERE name='base_operations'", AS_ARRAY);
    foreach ($settings as $setting) {
        ${$setting->name} = $setting->value;
    }
    $base_operations = unserialize($base_operations);
    $path = array(PLUGINDIR, $dir, 'lang');
    load_plugin_textdomain('Shopp', join(DIRECTORY_SEPARATOR, $path));
    ob_start();
    include "ui/behaviors/settings.js";
    $file = ob_get_contents();
    ob_end_clean();
    header("Content-type: text/javascript");
    header("Content-Disposition: inline; filename=settings.js");
    header("Content-Description: Delivered by WordPress/Shopp " . SHOPP_VERSION);
    header("Content-length: " . strlen($file));
    echo $file;
    exit;
}
예제 #28
0
	/**
	 * Loads all categories for the product list manager category filter menu
	 * 
	 * @return string HTML for a drop-down menu of categories
	 **/
	function category ($id) {
		$db = DB::get();

		$catalog = DatabaseObject::tablename(Catalog::$table);
		$category = DatabaseObject::tablename(Category::$table);
		$products = DatabaseObject::tablename(Product::$table);

		if ($id == "catalog-products") {
			$results = $db->query("SELECT p.id,p.name FROM $products AS p ORDER BY p.name ASC",AS_ARRAY);
		} else $results = $db->query("SELECT p.id,p.name FROM $catalog AS catalog LEFT JOIN $category AS cat ON cat.id = catalog.parent AND catalog.type='category' LEFT JOIN $products AS p ON p.id=catalog.product WHERE cat.id='$id' ORDER BY p.name ASC",AS_ARRAY);
		$products = array();

		$products[0] = __("Select a product&hellip;","Ecart");
		foreach ($results as $result) $products[$result->id] = $result->name;
		return menuoptions($products,0,true);

	}
예제 #29
0
파일: Item.php 프로젝트: robbiespire/paQui
	/**
	 * Determines the stock level of the line item
	 * 
	 * @since 1.1
	 *
	 * @return int The amount of stock available
	 **/
	function getstock () {
		$db = DB::get();
		$stock = apply_filters('ecart_cartitem_stock',false,$this);
		if ($stock !== false) return $stock;

		$table = DatabaseObject::tablename(Price::$table);
		$ids = array($this->priceline);
		if (!empty($this->addons)) foreach ($this->addons as $addon) $ids[] = $addon->id;
		$result = $db->query("SELECT min(stock) AS stock FROM $table WHERE 0 < FIND_IN_SET(id,'".join(',',$ids)."')");
		if (isset($result->stock)) return $result->stock;

		return $this->option->stock;
	}
예제 #30
0
	/**
	 * Deletes the record associated with this object */
	function delete () {
		$db = DB::get();
		$id = $this->{$this->_key};
		if (empty($id)) return false;

		// Delete from categories
		$table = DatabaseObject::tablename(Catalog::$table);
		$db->query("DELETE LOW_PRIORITY FROM $table WHERE product='$id'");

		// Delete prices
		$table = DatabaseObject::tablename(Price::$table);
		$db->query("DELETE LOW_PRIORITY FROM $table WHERE product='$id'");

		// Delete images/files
		$table = DatabaseObject::tablename(ProductImage::$table);

		// Delete images
		$images = array();
		$src = $db->query("SELECT id FROM $table WHERE parent='$id' AND context='product' AND type='image'",AS_ARRAY);
		foreach ($src as $img) $images[] = $img->id;
		$this->delete_images($images);

		// Delete product meta (specs, images, downloads)
		$table = DatabaseObject::tablename(MetaObject::$table);
		$db->query("DELETE LOW_PRIORITY FROM $table WHERE parent='$id' AND context='product'");

		// Delete record
		$db->query("DELETE FROM $this->_table WHERE $this->_key='$id'");

	}