function admin()
 {
     global $Shopp;
     $db =& DB::get();
     if (!defined('WP_ADMIN') || !isset($_GET['page'])) {
         return;
     }
     $Admin = $Shopp->Flow->Admin;
     $adminurl = $Shopp->wpadminurl . "admin.php";
     $defaults = array('page' => false, 'deleting' => false, 'delete' => false, 'id' => false, 'save' => false, 'duplicate' => false, 'next' => false);
     $args = array_merge($defaults, $_REQUEST);
     extract($args, EXTR_SKIP);
     if (strstr($page, $Admin->categories)) {
         if ($page == "shopp-categories" && !empty($deleting) && !empty($delete) && is_array($delete)) {
             foreach ($delete as $deletion) {
                 $Category = new Category($deletion);
                 $db->query("UPDATE {$Category->_table} SET parent=0 WHERE parent={$Category->id}");
                 $Category->delete();
             }
             $redirect = esc_url(add_query_arg(array_merge($_GET, array('delete[]' => null, 'deleting' => null)), $adminurl));
             shopp_redirect($redirect);
         }
         if ($id && $id != "new") {
             $Shopp->Category = new Category($id);
         } else {
             $Shopp->Category = new Category();
         }
         if ($save) {
             $this->save_category($Shopp->Category);
             $this->Notice = '<strong>' . stripslashes($Shopp->Category->name) . '</strong> ' . __('has been saved.', 'Shopp');
             if ($next) {
                 if ($next != "new") {
                     $Shopp->Category = new Category($next);
                 } else {
                     $Shopp->Category = new Category();
                 }
             } else {
                 if (empty($id)) {
                     $id = $Shopp->Category->id;
                 }
                 $Shopp->Category = new Category($id);
             }
         }
     }
     // end $Admin->categories
     if (strstr($page, $Admin->products)) {
         if ($page == "shopp-products" && !empty($deleting) && !empty($delete) && is_array($delete)) {
             foreach ($delete as $deletion) {
                 $Product = new Product($deletion);
                 $Product->delete();
             }
             $redirect = esc_url(add_query_arg(array_merge($_GET, array('delete' => null, 'deleting' => null)), $adminurl));
             shopp_redirect($redirect);
             exit;
         }
         if ($duplicate) {
             $Product = new Product();
             $Product->load($duplicate);
             $Product->duplicate();
             shopp_redirect(add_query_arg('page', $Admin->products, $adminurl));
         }
         if ($id && $id != "new") {
             $Shopp->Product = new Product($id);
             $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags'));
         } else {
             $Shopp->Product = new Product();
             $Shopp->Product->published = "on";
         }
         if ($save) {
             $this->save_product($Shopp->Product);
             $this->Notice = '<strong>' . stripslashes($Shopp->Product->name) . '</strong> ' . __('has been saved.', 'Shopp');
             if ($next) {
                 if ($next == "new") {
                     $Shopp->Product = new Product();
                     $Shopp->Product->published = "on";
                 } else {
                     $Shopp->Product = new Product($next);
                     $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags'));
                 }
             } else {
                 if (empty($id)) {
                     $id = $Shopp->Product->id;
                 }
                 $Shopp->Product = new Product($id);
                 $Shopp->Product->load_data(array('prices', 'specs', 'categories', 'tags'));
             }
         }
     }
     // end $Admin->products
 }
Example #2
0
	/**
	 * Handles loading, saving and deleting products in the context of workflows
	 *	 
	 * @return void
	 **/
	function workflow () {
		global $Ecart;
		$db =& DB::get();

		$defaults = array(
			'page' => false,
			'deleting' => false,
			'delete' => false,
			'id' => false,
			'save' => false,
			'duplicate' => false,
			'next' => false
			);
		$args = array_merge($defaults,$_REQUEST);
		extract($args,EXTR_SKIP);

		if (!defined('WP_ADMIN') || !isset($page)
			|| $page != $this->Admin->pagename('products'))
				return false;

		$adminurl = admin_url('admin.php');


		if ($page == $this->Admin->pagename('products')
				&& !empty($deleting)
				&& !empty($delete)
				&& is_array($delete)) {
			foreach($delete as $deletion) {
				$Product = new Product($deletion);
				$Product->delete();
			}
			$redirect = esc_url(add_query_arg(array_merge($_GET,array('delete'=>null,'deleting'=>null)),$adminurl));
			ecart_redirect($redirect);
		}

		if ($duplicate) {
			$Product = new Product($duplicate);
			$Product->duplicate();
			ecart_redirect(add_query_arg('page',$this->Admin->pagename('products'),$adminurl));
		}

		if (isset($id) && $id != "new") {
			$Ecart->Product = new Product($id);
			$Ecart->Product->load_data(array('prices','specs','categories','tags'));
		} else {
			$Ecart->Product = new Product();
			$Ecart->Product->status = "publish";
		}

		if ($save) {
			$this->save_product($Ecart->Product);
			$this->Notice = '<strong>'.stripslashes($Ecart->Product->name).'</strong> '.__('has been saved.','Ecart');

			if ($next) {
				if ($next == "new") {
					$Ecart->Product = new Product();
					$Ecart->Product->status = "publish";
				} else {
					$Ecart->Product = new Product($next);
					$Ecart->Product->load_data(array('prices','specs','categories','tags'));
				}
			} else {
				if (empty($id)) $id = $Ecart->Product->id;
				$Ecart->Product = new Product($id);
				$Ecart->Product->load_data(array('prices','specs','categories','tags'));
			}
		}

	}