Beispiel #1
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");
	}
 function promotions_list()
 {
     global $Shopp;
     $db = DB::get();
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     require_once "{$this->basepath}/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 == "shopp-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('shopp-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('shopp_promo_saved', array(&$Promotion));
         if ($Promotion->scope == "Catalog") {
             $Promotion->build_discounts();
         }
         // Reset cart promotions cache
         // to force reload for these updates
         $Shopp->Cart->data->Promotions = false;
     }
     $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', 'Shopp'), 'disabled' => __('Disabled', 'Shopp'));
     $num_pages = ceil($promocount->total / $per_page);
     $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum));
     include "{$this->basepath}/core/ui/promotions/promotions.php";
 }