Пример #1
0
 private function show_alert($index)
 {
     if (valid_input($index, VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
         return;
     } else {
         if ($index >= count($this->alerts)) {
             return;
         }
     }
     list($title, $type, $column) = $this->alerts[(int) $index];
     $cache = new cache($this->db, "dashboard_" . $this->user->username);
     if (($list = $cache->{$column}) === NULL) {
         $function = "get_" . $type . "_statistics";
         $list = $this->model->{$function}($column);
         $cache->store($column, $list, $this->settings->dashboard_page_refresh * 60 - 1);
     }
     if ($list == false) {
         return;
     }
     $this->output->open_tag("list", array("title" => $title));
     foreach ($list as $name => $item) {
         $this->output->add_tag("item", $name, array("count" => $item["today"], "change" => $item["change"]));
     }
     $this->output->close_tag();
 }
Пример #2
0
 public function filename_oke($file)
 {
     if (trim($file) == "") {
         return false;
     }
     return valid_input($file, VALIDATE_NUMBERS . VALIDATE_LETTERS . "/-_. ");
 }
Пример #3
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save collection") {
             /* Save collection
              */
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_collection_form($_POST);
             } else {
                 if (isset($_POST["id"]) == false) {
                     /* Create collection
                      */
                     if ($this->model->create_collection($_POST) == false) {
                         $this->show_collection_form($_POST);
                     } else {
                         $this->show_collection_overview();
                     }
                 } else {
                     /* Update collection
                      */
                     if ($this->model->update_collection($_POST) == false) {
                         $this->show_collection_form($_POST);
                     } else {
                         $this->show_collection_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete collection") {
                 /* Delete collection
                  */
                 if ($this->model->delete_collection($_POST["id"]) == false) {
                     $this->output->add_message("Error deleting collection.");
                     $this->show_collection_form($_POST);
                 } else {
                     $this->show_collection_overview();
                 }
             } else {
                 $this->show_collection_overview();
             }
         }
     } else {
         if ($this->page->pathinfo[2] == "new") {
             $collection = array();
             $this->show_collection_form($collection);
         } else {
             if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 if (($collection = $this->model->get_collection($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "Collection not found.");
                 } else {
                     $this->show_collection_form($collection);
                 }
             } else {
                 $this->show_collection_overview();
             }
         }
     }
 }
Пример #4
0
 public function save_oke($item)
 {
     $result = parent::save_oke($item);
     if (valid_input($item["name"], VALIDATE_LETTERS . "_", VALIDATE_NONEMPTY) == false) {
         $this->output->add_message("Invalid name");
         $result = false;
     }
     return $result;
 }
Пример #5
0
 public function execute()
 {
     $this->output->description = "News";
     $this->output->keywords = "news";
     $this->output->title = "News";
     $this->output->add_alternate("News", "application/rss+xml", "/news.xml");
     if ($this->page->type == "xml") {
         /* RSS feed
          */
         $rss = new RSS($this->output);
         if ($rss->fetch_from_cache("news_rss") == false) {
             $rss->title = $this->settings->head_title . " news";
             $rss->description = $this->settings->head_description;
             if (($news = $this->model->get_news(0, $this->settings->news_rss_page_size)) != false) {
                 foreach ($news as $item) {
                     $link = "/news/" . $item["id"];
                     $rss->add_item($item["title"], $item["content"], $link, $item["timestamp"]);
                 }
             }
             $rss->to_output();
         }
     } else {
         if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
             /* News item
              */
             if (($item = $this->model->get_news_item($this->page->pathinfo[1])) == false) {
                 $this->output->add_tag("result", "Unknown news item");
             } else {
                 $this->output->title = $item["title"] . " - News";
                 $item["timestamp"] = date("j F Y, H:i", strtotime($item["timestamp"]));
                 $this->output->record($item, "news");
             }
         } else {
             /* News overview
              */
             if (($count = $this->model->count_news()) === false) {
                 $this->output->add_tag("result", "Database error");
                 return;
             }
             $paging = new pagination($this->output, "news", $this->settings->news_page_size, $count);
             if (($news = $this->model->get_news($paging->offset, $paging->size)) === false) {
                 $this->output->add_tag("result", "Database error");
                 return;
             }
             foreach ($news as $item) {
                 $item["timestamp"] = date("j F Y, H:i", $item["timestamp"]);
                 $this->output->record($item, "news");
             }
             $paging->show_browse_links(7, 3);
         }
     }
 }
Пример #6
0
 public function show_item_form($item)
 {
     if (valid_input($item["id"], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
         if (($users = $this->model->get_users($item["id"])) !== false) {
             $this->output->open_tag("users");
             foreach ($users as $user) {
                 $this->output->record($user, "user");
             }
             $this->output->close_tag();
         }
     }
     parent::show_item_form($item);
 }
Пример #7
0
 public function execute()
 {
     if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
         $this->show_collection_overview();
     } else {
         if (($collection = $this->model->get_collection($this->page->pathinfo[1])) == false) {
             $this->output->add_tag("result", "Collection not found.");
         } else {
             $this->show_collection($collection);
         }
     }
     $this->output->add_tag("title", $this->title);
     $this->output->title = $this->title;
 }
Пример #8
0
 public function execute()
 {
     if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
         $this->show_album($this->page->pathinfo[1]);
     } else {
         if (valid_input($this->page->pathinfo[1], VALIDATE_NONCAPITALS . VALIDATE_NUMBERS . "_.", VALIDATE_NONEMPTY)) {
             $this->show_photo($this->page->pathinfo[1]);
         } else {
             $this->show_albums();
         }
     }
     $this->output->add_tag("title", $this->title);
     $this->output->title = $this->title;
 }
Пример #9
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save message") {
             /* Update message
              */
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_message_form($_POST);
             } else {
                 if ($this->model->update_message($_POST) === false) {
                     $this->output->add_message("Database error while updating message.");
                     $this->show_message_form($_POST);
                 } else {
                     $topic_id = $this->model->get_topic_id($_POST["id"]);
                     $this->user->log_action("forum message %d (topic:%d) updated", $_POST["id"], $topic_id);
                     $this->show_message_overview();
                 }
             }
         } else {
             if ($_POST["submit_button"] == "delete") {
                 /* Delete message
                  */
                 $topic_id = $this->model->get_topic_id($_POST["id"]);
                 if ($this->model->delete_message($_POST["message_id"]) == false) {
                     $this->output->add_tag("result", "Database error while deleting message.");
                 } else {
                     $this->user->log_action("forum message %d (topic:%d) deleted", $_POST["message_id"], $topic_id);
                     $this->show_message_overview();
                 }
             } else {
                 $this->show_message_overview();
             }
         }
     } else {
         if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
             /* Edit existing message
              */
             if (($message = $this->model->get_message($this->page->pathinfo[2])) == false) {
                 $this->output->add_tag("result", "Message not found.");
             } else {
                 $this->show_message_form($message);
             }
         } else {
             /* Show message overview
              */
             $this->show_message_overview();
         }
     }
 }
Пример #10
0
 public function __construct($db, $settings, $user)
 {
     $this->db = $db;
     $this->settings = $settings;
     $this->user = $user;
     /* AJAX request
      */
     if ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" || $_GET["output"] == "ajax") {
         $this->ajax_request = true;
     }
     /* Select module
      */
     if (is_true(ENFORCE_HTTPS) && $_SERVER["HTTPS"] != "on") {
         header(sprintf("Location: https://%s%s", $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
         header("Strict-Transport-Security: max-age=31536000");
         $this->module = ERROR_MODULE;
         $this->http_code = 301;
     } else {
         if (is_false(WEBSITE_ONLINE) && $_SERVER["REMOTE_ADDR"] != WEBSITE_ONLINE) {
             $this->module = "banshee/offline";
         } else {
             if ($this->db->connected == false) {
                 if (module_exists("setup") && is_true(DEBUG_MODE)) {
                     $this->module = "setup";
                 } else {
                     $this->module = ERROR_MODULE;
                     $this->http_code = 500;
                 }
             } else {
                 list($this->url) = explode("?", $_SERVER["REQUEST_URI"], 2);
                 $path = trim($this->url, "/");
                 if ($path == "") {
                     $page = $this->settings->start_page;
                 } else {
                     if (valid_input($path, VALIDATE_URL, VALIDATE_NONEMPTY)) {
                         $page = $path;
                     } else {
                         $this->module = ERROR_MODULE;
                         $this->http_code = 404;
                     }
                 }
                 $this->pathinfo = explode("/", $page);
             }
         }
     }
     if ($this->module === null) {
         $this->select_module($page);
     }
 }
Пример #11
0
 public function save_oke($page)
 {
     $result = true;
     if (valid_input(trim($page["url"]), VALIDATE_URL, VALIDATE_NONEMPTY) == false) {
         $this->output->add_message("URL is empty or contains invalid characters.");
         $result = false;
     } else {
         if (strpos($page["url"], "//") !== false || $page["url"][0] !== "/") {
             $this->output->add_message("Invalid URL.");
             $result = false;
         }
     }
     if (in_array($page["language"], array_keys(config_array(SUPPORTED_LANGUAGES))) == false) {
         $this->output->add_message("Language not supported.");
         $result = false;
     }
     if (($layouts = $this->get_layouts()) != false) {
         if (in_array($page["layout"], $layouts) == false) {
             $this->output->add_message("Invalid layout.");
             $result = false;
         }
     }
     if (trim($page["title"]) == "") {
         $this->output->add_message("Empty title not allowed.");
         $result = false;
     }
     if (valid_input($page["language"], VALIDATE_NONCAPITALS, 2) == false) {
         $this->output->add_message("Invalid language code.");
         $result = false;
     }
     $module = ltrim($page["url"], "/");
     $public_pages = page_to_module(config_file("public_pages"));
     $private_pages = page_to_module(config_file("private_pages"));
     if (in_array($module, $public_pages) || in_array($module, $private_pages)) {
         $this->output->add_message("URL belongs to a module.");
         $result = false;
     } else {
         $query = "select * from pages where id!=%d and url=%s limit 1";
         if (($page = $this->db->execute($query, $page["id"], $page["url"])) != false) {
             if (count($page) > 0) {
                 $this->output->add_message("URL belongs to another page.");
                 $result = false;
             }
         }
     }
     return $result;
 }
Пример #12
0
 public function execute()
 {
     if (($letters = $this->model->get_first_letters()) === false) {
         $this->output->add_tag("result", "Database error");
         return;
     }
     $this->output->description = "Dictionary";
     if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
         /* Show word
          */
         if (($word = $this->model->get_word($this->page->pathinfo[1])) == false) {
             $this->output->add_tag("result", "Unknown word");
             return;
         }
         $this->output->keywords = $word["word"] . ", dictionary";
         $this->output->title = $word["word"] . " - Dictionary";
         $first_letter = strtolower(substr($word["word"], 0, 1));
         $this->output->open_tag("word");
         $this->show_letters($letters, $first_letter);
         $this->output->record($word, "word");
         $this->output->close_tag();
     } else {
         /* Show overview
          */
         $this->output->keywords = "dictionary";
         $this->output->title = "Dictionary";
         if (valid_input($this->page->pathinfo[1], VALIDATE_NONCAPITALS, 1) == false) {
             $first_letter = $letters[0]["char"];
         } else {
             $first_letter = $this->page->pathinfo[1];
         }
         if (($words = $this->model->get_words($first_letter)) === false) {
             $this->output->add_tag("result", "Database error.");
             return;
         }
         $this->output->open_tag("overview");
         $this->show_letters($letters, $first_letter);
         $this->output->open_tag("words");
         foreach ($words as $word) {
             $this->output->record($word, "word");
         }
         $this->output->close_tag();
         $this->output->close_tag();
     }
 }
Пример #13
0
 public function execute()
 {
     $this->output->description = "Poll";
     $this->output->keywords = "poll";
     if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
         /* Show poll
          */
         if (($poll = $this->model->get_poll($this->page->pathinfo[1])) == false) {
             $this->output->add_tag("result", "Poll not found");
         } else {
             $this->output->title = $poll["question"] . " - Poll";
             $this->output->open_tag("poll", array("id" => $poll["id"]));
             $this->output->add_tag("question", $poll["question"]);
             $votes = 0;
             foreach ($poll["answers"] as $answer) {
                 $votes += (int) $answer["votes"];
             }
             $this->output->open_tag("answers", array("votes" => $votes));
             foreach ($poll["answers"] as $answer) {
                 unset($answer["poll_id"]);
                 $answer["percentage"] = $votes > 0 ? round(100 * (int) $answer["votes"] / $votes) : 0;
                 $this->output->record($answer, "answer");
             }
             $this->output->close_tag();
             $this->output->close_tag();
         }
     } else {
         $this->show_active_poll();
         /* Poll overview
          */
         $this->output->title = "Poll";
         if (($polls = $this->model->get_polls()) === false) {
             $this->output->add_tag("result", "Database error");
         } else {
             $active_poll_id = $this->model->get_active_poll_id();
             $this->output->open_tag("polls");
             foreach ($polls as $poll) {
                 if ($poll["id"] != $active_poll_id) {
                     $this->output->add_tag("question", $poll["question"], array("id" => $poll["id"]));
                 }
             }
             $this->output->close_tag();
         }
     }
 }
Пример #14
0
 public function save_oke($word)
 {
     $result = true;
     if (valid_input($word["word"], VALIDATE_LETTERS . VALIDATE_NUMBERS . " -_", VALIDATE_NONEMPTY) == false) {
         $this->output->add_message("Word contains invalid characters or is empty.");
         $result = false;
     } else {
         if (valid_input($word["word"], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
             $this->output->add_message("Word must contain letters.");
             $result = false;
         }
     }
     if (trim($word["short_description"]) == "") {
         $this->output->add_message("The short description cannot be empty.");
         $result = false;
     }
     return $result;
 }
Пример #15
0
 public function vote($answer)
 {
     if ($_POST["submit_button"] != "Vote") {
         return false;
     }
     if ($answer == null) {
         return false;
     }
     $_SERVER["REQUEST_METHOD"] = "GET";
     if (valid_input($answer, VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
         return false;
     }
     if (($poll = $this->get_active_poll()) == false) {
         return false;
     }
     $today = strtotime("today 00:00:00");
     if ($poll["end"] < $today) {
         return false;
     }
     if ($this->user_may_vote($poll["id"]) == false) {
         return false;
     }
     $query = "select * from poll_answers where poll_id=%d order by answer";
     if (($answers = $this->db->execute($query, $poll["id"])) == false) {
         return false;
     }
     $answer = (int) $answer;
     if ($answer >= count($answers)) {
         return false;
     }
     $answer_id = $answers[$answer]["id"];
     setcookie("last_poll_id", (int) $poll["id"], time() + 100 * DAY);
     $_COOKIE["last_poll_id"] = (int) $poll["id"];
     /* Log selected item
      */
     if (($fp = fopen("../logfiles/poll.log", "a")) != false) {
         fputs($fp, $_SERVER["REMOTE_ADDR"] . "|" . date("Y-m-d H:i:s") . "|" . $poll["id"] . "|" . $answer . "\n");
         fclose($fp);
     }
     $query = "update poll_answers set votes=votes+1 where id=%d";
     return $this->db->query($query, $answer_id) != false;
 }
Пример #16
0
 public function valid_signup($data)
 {
     $result = true;
     if (strlen($data["username"]) < $this->minimum_username_length || valid_input($data["username"], VALIDATE_NONCAPITALS, VALIDATE_NONEMPTY) == false) {
         $this->output->add_message("Your username must consist of lowercase letters with a mimimum length of %d.", $this->minimum_username_length);
         $result = false;
     }
     if (valid_email($data["email"]) == false) {
         $this->output->add_message("Invalid e-mail address.");
         $result = false;
     }
     if ($result == false) {
         return false;
     }
     if (strlen($data["password"]) < $this->minimum_password_length) {
         $this->output->add_message("The length of your password must be equal or greater than %d.", $this->minimum_password_length);
         $result = false;
     }
     if (strlen($data["fullname"]) < $this->mimimum_fullname_length) {
         $this->output->add_message("The length of your name must be equal or greater than %d.", $this->mimimum_fullname_length);
         $result = false;
     }
     $query = "select * from users where username=%s or email=%s";
     if (($users = $this->db->execute($query, $data["username"], $data["email"])) === false) {
         $this->output->add_message("Error while validating sign up.");
         return false;
     }
     foreach ($users as $user) {
         if ($user["username"] == $data["username"]) {
             $this->output->add_message("This username is already taken.");
             $result = false;
         }
         if ($data["email"] != "") {
             if ($user["email"] == $data["email"]) {
                 $this->output->add_message("This e-mail address has already been used to register an account.");
                 $result = false;
             }
         }
     }
     return $result;
 }
Пример #17
0
 public function __construct($output, $name, $page_size, $list_size)
 {
     $this->output = $output;
     $this->name = $name;
     $this->page_size = $page_size;
     $this->list_size = $list_size;
     if ($this->page_size <= 0 || $this->list_size <= 0) {
         $this->error = true;
         return;
     }
     /* Calculate maximum page number
      */
     $this->max_page = $this->list_size / $this->page_size;
     if ($this->max_page == floor($this->max_page)) {
         $this->max_page -= 1;
     } else {
         $this->max_page = floor($this->max_page);
     }
     /* Initialize session storage
      */
     if (is_array($_SESSION["pagination"]) == false) {
         $_SESSION["pagination"] = array();
     }
     if (isset($_SESSION["pagination"][$name]) == false) {
         $_SESSION["pagination"][$name] = $this->page;
     }
     /* Calulate page number
      */
     $this->page =& $_SESSION["pagination"][$name];
     if (isset($_GET["offset"])) {
         if (valid_input($_GET["offset"], VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
             $this->page = 0;
         } else {
             if (($this->page = (int) $_GET["offset"]) > $this->max_page) {
                 $this->page = $this->max_page;
             }
         }
     }
     #$this->output->add_css("banshee/pagination.css");
 }
Пример #18
0
 public function execute()
 {
     if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
         $offset = 0;
     } else {
         $offset = $this->page->pathinfo[2];
     }
     if (isset($_SESSION["admin_actionlog_size"]) == false) {
         $_SESSION["admin_actionlog_size"] = $this->model->get_log_size();
     }
     $paging = new pagination($this->output, "admin_actionlog", $this->settings->admin_page_size, $_SESSION["admin_actionlog_size"]);
     if (($log = $this->model->get_action_log($paging->offset, $paging->size)) === false) {
         $this->output->add_tag("result", "Error reading action log.");
         return;
     }
     $users = array($this->user->id => $this->user->username);
     $this->output->open_tag("log");
     $this->output->open_tag("list");
     foreach ($log as $entry) {
         $user_id = $entry["user_id"];
         list($user_id, $switch_id) = explode(":", $user_id);
         if (isset($users[$user_id]) == false) {
             if (($user = $this->model->get_user($user_id)) !== false) {
                 $users[$user_id] = $user["username"];
             }
         }
         if (isset($users[$switch_id]) == false) {
             if (($switch = $this->model->get_user($switch_id)) !== false) {
                 $users[$switch_id] = $switch["username"];
             }
         }
         $entry["username"] = isset($users[$user_id]) ? $users[$user_id] : "-";
         $entry["switch"] = isset($users[$switch_id]) ? $users[$switch_id] : "-";
         $this->output->record($entry, "entry");
     }
     $this->output->close_tag();
     $paging->show_browse_links();
     $this->output->close_tag();
 }
Пример #19
0
	/**
	 * Provides support for the ecart('cartitem') tags
	 * 
	 * @since 1.1
	 *
	 * @return mixed
	 **/
	function tag ($id,$property,$options=array()) {
		global $Ecart;

		// Return strings with no options
		switch ($property) {
			case "id": return $id;
			case "product": return $this->product;
			case "name": return $this->name;
			case "type": return $this->type;
			case "link":
			case "url":
				return ecarturl(ECART_PRETTYURLS?$this->slug:array('ecart_pid'=>$this->product));
			case "sku": return $this->sku;
		}

		$taxes = isset($options['taxes'])?value_is_true($options['taxes']):null;
		if (in_array($property,array('price','newprice','unitprice','total','tax','options')))
			$taxes = ecart_taxrate($taxes,$this->taxable,$this) > 0?true:false;

		// Handle currency values
		$result = "";
		switch ($property) {
			case "discount": $result = (float)$this->discount; break;
			case "unitprice": $result = (float)$this->unitprice+($taxes?$this->unittax:0); break;
			case "unittax": $result = (float)$this->unittax; break;
			case "discounts": $result = (float)$this->discounts; break;
			case "tax": $result = (float)$this->tax; break;
			case "total": $result = (float)$this->total+($taxes?($this->unittax*$this->quantity):0); break;
		}
		if (is_float($result)) {
			if (isset($options['currency']) && !value_is_true($options['currency'])) return $result;
			else return money($result);
		}

		// Handle values with complex options
		switch ($property) {
			case "taxrate": return percentage($this->taxrate*100,array('precision' => 1)); break;
			case "quantity":
				$result = $this->quantity;
				if ($this->type == "Donation" && $this->donation['var'] == "on") return $result;
				if (isset($options['input']) && $options['input'] == "menu") {
					if (!isset($options['value'])) $options['value'] = $this->quantity;
					if (!isset($options['options']))
						$values = "1-15,20,25,30,35,40,45,50,60,70,80,90,100";
					else $values = $options['options'];

					if (strpos($values,",") !== false) $values = explode(",",$values);
					else $values = array($values);
					$qtys = array();
					foreach ($values as $value) {
						if (strpos($value,"-") !== false) {
							$value = explode("-",$value);
							if ($value[0] >= $value[1]) $qtys[] = $value[0];
							else for ($i = $value[0]; $i < $value[1]+1; $i++) $qtys[] = $i;
						} else $qtys[] = $value;
					}
					$result = '<select name="items['.$id.']['.$property.']">';
					foreach ($qtys as $qty)
						$result .= '<option'.(($qty == $this->quantity)?' selected="selected"':'').' value="'.$qty.'">'.$qty.'</option>';
					$result .= '</select>';
				} elseif (isset($options['input']) && valid_input($options['input'])) {
					if (!isset($options['size'])) $options['size'] = 5;
					if (!isset($options['value'])) $options['value'] = $this->quantity;
					$result = '<input type="'.$options['input'].'" name="items['.$id.']['.$property.']" id="items-'.$id.'-'.$property.'" '.inputattrs($options).'/>';
				} else $result = $this->quantity;
				break;
			case "remove":
				$label = __("Remove");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['class'])) $class = ' class="'.$options['class'].'"';
				else $class = ' class="remove"';
				if (isset($options['input'])) {
					switch ($options['input']) {
						case "button":
							$result = '<button type="submit" name="remove['.$id.']" value="'.$id.'"'.$class.' tabindex="">'.$label.'</button>'; break;
						case "checkbox":
						    $result = '<input type="checkbox" name="remove['.$id.']" value="'.$id.'"'.$class.' tabindex="" title="'.$label.'"/>'; break;
					}
				} else {
					$result = '<a href="'.href_add_query_arg(array('cart'=>'update','item'=>$id,'quantity'=>0),ecarturl(false,'cart')).'"'.$class.'>'.$label.'</a>';
				}
				break;
			case "optionlabel": $result = $this->option->label; break;
			case "options":
				$class = "";
				if (!isset($options['before'])) $options['before'] = '';
				if (!isset($options['after'])) $options['after'] = '';
				if (isset($options['show']) &&
					strtolower($options['show']) == "selected")
					return (!empty($this->option->label))?
						$options['before'].$this->option->label.$options['after']:'';

				if (isset($options['class'])) $class = ' class="'.$options['class'].'" ';
				if (count($this->variations) > 1) {
					$result .= $options['before'];
					$result .= '<input type="hidden" name="items['.$id.'][product]" value="'.$this->product.'"/>';
					$result .= ' <select name="items['.$id.'][price]" id="items-'.$id.'-price"'.$class.'>';
					$result .= $this->options($this->priceline);
					$result .= '</select>';
					$result .= $options['after'];
				}
				break;
			case "addons-list":
			case "addonslist":
				if (empty($this->addons)) return false;
				$defaults = array(
					'before' => '',
					'after' => '',
					'class' => '',
					'exclude' => '',
					'prices' => true,

				);
				$options = array_merge($defaults,$options);
				extract($options);

				$classes = !empty($class)?' class="'.join(' ',$class).'"':'';
				$excludes = explode(',',$exclude);
				$prices = value_is_true($prices);

				$result .= $before.'<ul'.$classes.'>';
				foreach ($this->addons as $id => $addon) {
					if (in_array($addon->label,$excludes)) continue;

					$price = ($addon->onsale?$addon->promoprice:$addon->price);
					if ($this->taxrate > 0) $price = $price+($price*$this->taxrate);

					if ($prices) $pricing = " (".($addon->unitprice < 0?'-':'+').money($price).")";
					$result .= '<li>'.$addon->label.$pricing.'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "hasinputs":
			case "has-inputs": return (count($this->data) > 0); break;
			case "inputs":
				if (!isset($this->_data_loop)) {
					reset($this->data);
					$this->_data_loop = true;
				} else next($this->data);

				if (current($this->data) !== false) return true;
				else {
					unset($this->_data_loop);
					reset($this->data);
					return false;
				}
				break;
			case "input":
				$data = current($this->data);
				$name = key($this->data);
				if (isset($options['name'])) return $name;
				return $data;
				break;
			case "inputs-list":
			case "inputslist":
				if (empty($this->data)) return false;
				$before = ""; $after = ""; $classes = ""; $excludes = array();
				if (!empty($options['class'])) $classes = ' class="'.$options['class'].'"';
				if (!empty($options['exclude'])) $excludes = explode(",",$options['exclude']);
				if (!empty($options['before'])) $before = $options['before'];
				if (!empty($options['after'])) $after = $options['after'];

				$result .= $before.'<ul'.$classes.'>';
				foreach ($this->data as $name => $data) {
					if (in_array($name,$excludes)) continue;
					$result .= '<li><strong>'.$name.'</strong>: '.$data.'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "coverimage":
			case "thumbnail":
				$defaults = array(
					'class' => '',
					'width' => 48,
					'height' => 48,
					'size' => false,
					'fit' => false,
					'sharpen' => false,
					'quality' => false,
					'bg' => false,
					'alt' => false,
					'title' => false
				);

				$options = array_merge($defaults,$options);
				extract($options);

				if ($this->image !== false) {
					$img = $this->image;

					if ($size !== false) $width = $height = $size;
					$scale = (!$fit)?false:esc_attr(array_search($fit,$img->_scaling));
					$sharpen = (!$sharpen)?false:esc_attr(min($sharpen,$img->_sharpen));
					$quality = (!$quality)?false:esc_attr(min($quality,$img->_quality));
					$fill = (!$bg)?false:esc_attr(hexdec(ltrim($bg,'#')));
					$scaled = $img->scaled($width,$height,$scale);

					$alt = empty($alt)?$img->alt:$alt;
					$title = empty($title)?$img->title:$title;
					$title = empty($title)?'':' title="'.esc_attr($title).'"';
					$class = !empty($class)?' class="'.esc_attr($class).'"':'';

					if (!empty($options['title'])) $title = ' title="'.esc_attr($options['title']).'"';
					$alt = esc_attr(!empty($img->alt)?$img->alt:$this->name);
					return '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'"'.$class.' />';
				}
				break;

		}
		if (!empty($result)) return $result;

		return false;
	}
Пример #20
0
 public function execute()
 {
     $this->page_size = $this->settings->admin_page_size;
     /* Work-around for the most f*****g annoying crap browser in the world: IE
      */
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         foreach ($_FILES as $i => $file) {
             if ($file["type"] == "image/pjpeg") {
                 $files[$i]["type"] = "image/jpeg";
             }
         }
         if ($_POST["title"] == "" && isset($_POST["photo_album_id"])) {
             if (($count = $this->model->count_photos_in_album($_POST["photo_album_id"])) !== false) {
                 $_POST["title"] = "Photo " . ($count + 1);
             }
         }
     }
     if (isset($_SESSION["photo_album"]) == false) {
         if (($albums = $this->model->get_albums()) != false) {
             $_SESSION["photo_album"] = (int) $albums[0]["id"];
         }
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["submit_button"] == "album") {
     }
     if (($album_count = $this->model->count_albums()) === false) {
         $this->output->add_tag("result", "Error counting albums");
         return;
     } else {
         if ($album_count == 0) {
             $this->output->add_tag("result", "No albums have been created. Click <a href=\"/cms/albums\">here</a> to create a new photo album.");
             return;
         }
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "album") {
             /* Select album
              */
             if ($this->model->valid_album_id($_POST["album"])) {
                 $_SESSION["photo_album"] = (int) $_POST["album"];
             } else {
                 $this->output->add_system_warning("Invalid album id");
             }
             $this->show_overview();
         } else {
             if ($_POST["submit_button"] == "Upload photos") {
                 /* Upload photos
                  */
                 if ($this->model->upload_oke($_FILES["photos"]) == false) {
                     $this->show_overview();
                 } else {
                     if ($this->model->create_photos($_FILES["photos"], $_POST) == false) {
                     } else {
                         $this->show_overview();
                     }
                 }
             } else {
                 if ($_POST["submit_button"] == "Save photo") {
                     /* Save photo
                      */
                     if ($this->model->edit_oke($_POST) == false) {
                         $this->show_edit_form($_POST);
                     } else {
                         if ($this->model->update_photo($_POST) == false) {
                             $this->show_edit_form($_POST);
                         } else {
                             $this->show_overview();
                         }
                     }
                 } else {
                     if ($_POST["submit_button"] == "Delete photo") {
                         /* Delete photo
                          */
                         if ($this->model->delete_photo($_POST["id"]) == false) {
                             $this->output->add_message("Error while deleting photo.");
                             $this->show_edit_form($_POST);
                         } else {
                             $this->show_overview();
                         }
                     } else {
                         $this->show_overview();
                     }
                 }
             }
         }
     } else {
         if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
             if (($photo = $this->model->get_photo($this->page->pathinfo[2])) != false) {
                 $this->show_edit_form($photo);
             } else {
                 $this->output->add_tag("result", "Photo not found.");
             }
         } else {
             $this->show_overview();
         }
     }
 }
Пример #21
0
 public function execute()
 {
     $this->output->title = $this->name . " administration";
     if (is_a($this->model, "tablemanager_model") == false) {
         print "Tablemanager model has not been defined.\n";
         return false;
     }
     /* Check class settings
      */
     if ($this->model->class_settings_oke() == false) {
         return false;
     }
     /* Start
      */
     $this->output->add_css("banshee/tablemanager.css");
     $this->output->open_tag("tablemanager");
     $this->output->add_tag("name", $this->name);
     if ($this->back !== null) {
         $this->output->add_tag("back", $this->back);
     }
     if ($this->icon !== null) {
         $this->output->add_tag("icon", $this->icon);
     }
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         /* Handle forum submit
          */
         $this->handle_submit();
     } else {
         if ($this->page->pathinfo[$this->pathinfo_offset] == "new") {
             /* Show form for new item
              */
             $item = array();
             foreach ($this->model->elements as $name => $element) {
                 if (isset($element["default"])) {
                     $item[$name] = $element["default"];
                 } else {
                     if ($element["type"] == "date") {
                         $item[$name] = date("Y-m-d");
                     } else {
                         if ($element["type"] == "timestamp") {
                             $item[$name] = date("Y-m-d H:i");
                         }
                     }
                 }
             }
             $this->show_item_form($item);
         } else {
             if (valid_input($this->page->pathinfo[$this->pathinfo_offset], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Show form for existing item
                  */
                 if (($item = $this->model->get_item($this->page->pathinfo[$this->pathinfo_offset])) == false) {
                     $this->output->add_tag("result", $this->name . " not found.");
                 } else {
                     $this->show_item_form($item);
                 }
             } else {
                 /* Show item overview
                  */
                 if (count($_GET) == 0) {
                     $_SESSION["tablemanager_search_" . $this->model->table] = null;
                 }
                 $this->show_overview();
             }
         }
     }
     $this->output->close_tag();
     return true;
 }
    function tag($property, $options = array())
    {
        global $Shopp;
        switch ($property) {
            case "link":
            case "url":
                if (SHOPP_PERMALINKS) {
                    $url = esc_url(add_query_arg($_GET, $Shopp->shopuri . urldecode($this->slug) . "/"));
                } else {
                    $url = add_query_arg('shopp_pid', $this->id, $Shopp->shopuri);
                }
                return $url;
                break;
            case "found":
                if (empty($this->id)) {
                    return false;
                }
                $load = array('prices', 'images', 'specs');
                if (isset($options['load'])) {
                    $load = explode(",", $options['load']);
                }
                $this->load_data($load);
                return true;
                break;
            case "id":
                return $this->id;
                break;
            case "name":
                return $this->name;
                break;
            case "slug":
                return $this->slug;
                break;
            case "summary":
                return $this->summary;
                break;
            case "description":
                return apply_filters('shopp_product_description', $this->description);
            case "isfeatured":
            case "is-featured":
                return $this->featured == "on";
                break;
            case "price":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                // $taxrate = 0;
                // $taxes = false;
                // $base = $Shopp->Settings->get('base_operations');
                // if ($base['vat']) $taxes = true;
                // if (isset($options['taxes'])) $taxes = (value_is_true($options['taxes']));
                // if ($taxes) $taxrate = $Shopp->Cart->taxrate();
                if (count($this->options) > 0) {
                    $taxrate = shopp_taxrate($options['taxes']);
                    if ($this->pricerange['min']['price'] == $this->pricerange['max']['price']) {
                        return money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate);
                    } else {
                        if (!empty($options['starting'])) {
                            return $options['starting'] . " " . money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate);
                        }
                        return money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate) . " &mdash; " . money($this->pricerange['max']['price'] + $this->pricerange['max']['price'] * $taxrate);
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], $this->prices[0]->tax);
                    return money($this->prices[0]->price + $this->prices[0]->price * $taxrate);
                }
                break;
            case "weight":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                $unit = isset($options['units']) && !value_is_true($options['units']) ? false : $Shopp->Settings->get('weight_unit');
                if (!$this->weightrange['min']) {
                    return false;
                }
                $string = $this->weightrange['min'] == $this->weightrange['max'] ? round($this->weightrange['min'], 3) : round($this->weightrange['min'], 3) . " - " . round($this->weightrange['max'], 3);
                $string .= $unit ? " {$unit}" : "";
                return $string;
                break;
            case "onsale":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (empty($this->prices)) {
                    return false;
                }
                return $this->onsale;
                // if (empty($this->prices)) $this->load_prices();
                $sale = false;
                if (count($this->prices) > 1) {
                    foreach ($this->prices as $pricetag) {
                        if (isset($pricetag->onsale) && $pricetag->onsale == "on") {
                            $sale = true;
                        }
                    }
                    return $sale;
                } else {
                    return $this->prices[0]->onsale == "on" ? true : false;
                }
                break;
            case "saleprice":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $pricetag = 'price';
                if ($this->onsale) {
                    $pricetag = 'saleprice';
                }
                if (count($this->options) > 0) {
                    $taxrate = shopp_taxrate($options['taxes']);
                    if ($this->pricerange['min'][$pricetag] == $this->pricerange['max'][$pricetag]) {
                        return money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate);
                    } else {
                        if (!empty($options['starting'])) {
                            return $options['starting'] . " " . money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate);
                        }
                        return money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate) . " &mdash; " . money($this->pricerange['max'][$pricetag] + $this->pricerange['max'][$pricetag] * $taxrate);
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], $this->prices[0]->tax);
                    return money($this->prices[0]->promoprice + $this->prices[0]->promoprice * $taxrate);
                }
                break;
            case "has-savings":
                return $this->onsale && $this->pricerange['min']['saved'] > 0 ? true : false;
                break;
            case "savings":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $taxrate = shopp_taxrate($options['taxes']);
                if (!isset($options['show'])) {
                    $options['show'] = '';
                }
                if ($options['show'] == "%" || $options['show'] == "percent") {
                    if ($this->options > 1) {
                        if (round($this->pricerange['min']['savings']) == round($this->pricerange['max']['savings'])) {
                            return percentage($this->pricerange['min']['savings']);
                        } else {
                            return percentage($this->pricerange['min']['savings']) . " &mdash; " . percentage($this->pricerange['max']['savings']);
                        }
                    } else {
                        return percentage($this->pricerange['max']['savings']);
                    }
                } else {
                    if ($this->options > 1) {
                        if ($this->pricerange['min']['saved'] == $this->pricerange['max']['saved']) {
                            return money($this->pricerange['min']['saved'] + $this->pricerange['min']['saved'] * $taxrate);
                        } else {
                            return money($this->pricerange['min']['saved'] + $this->pricerange['min']['saved'] * $taxrate) . " &mdash; " . money($this->pricerange['max']['saved'] + $this->pricerange['max']['saved'] * $taxrate);
                        }
                    } else {
                        return money($this->pricerange['max']['saved'] + $this->pricerange['max']['saved'] * $taxrate);
                    }
                }
                break;
            case "freeshipping":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                // if (empty($this->prices)) $this->load_prices();
                return $this->freeshipping;
            case "thumbnail":
                if (empty($this->imagesets)) {
                    $this->load_data(array('images'));
                }
                if (empty($options['class'])) {
                    $options['class'] = '';
                } else {
                    $options['class'] = ' class="' . $options['class'] . '"';
                }
                if (isset($this->thumbnail)) {
                    $img = $this->thumbnail;
                    $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                    $width = isset($options['width']) ? $options['width'] : $img->properties['width'];
                    $height = isset($options['height']) ? $options['height'] : $img->properties['height'];
                    if (isset($options['width']) && !isset($options['height'])) {
                        $scale = $width / $img->properties['width'];
                        $height = round($img->properties['height'] * $scale);
                    }
                    if (isset($options['height']) && !isset($options['width'])) {
                        $scale = $height / $img->properties['height'];
                        $width = round($img->properties['width'] * $scale);
                    }
                    if (!empty($options['title'])) {
                        $title = ' title="' . attribute_escape($options['title']) . '"';
                    }
                    $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $this->name);
                    return '<img src="' . $img->uri . '"' . $title . ' alt="' . $alt . '"  width="' . $width . '" height="' . $height . '" ' . $options['class'] . ' />';
                    break;
                }
                break;
            case "hasimages":
            case "has-images":
                if (empty($options['type'])) {
                    $options['type'] = "thumbnail";
                }
                if (empty($this->images)) {
                    $this->load_data(array('images'));
                }
                if (!empty($this->imagesets[$options['type']])) {
                    $this->imageset =& $this->imagesets[$options['type']];
                    return true;
                } else {
                    return false;
                }
                break;
            case "images":
                if (!$this->imageset) {
                    return false;
                }
                if (!$this->imageloop) {
                    reset($this->imageset);
                    $this->imageloop = true;
                } else {
                    next($this->imageset);
                }
                if (current($this->imageset)) {
                    return true;
                } else {
                    $this->imageloop = false;
                    $this->imageset = false;
                    return false;
                }
                break;
            case "image":
                $img = current($this->imageset);
                if (isset($options['property'])) {
                    switch (strtolower($options['property'])) {
                        case "url":
                            return $img->uri;
                        case "width":
                            return $img->properties['width'];
                        case "height":
                            return $img->properties['height'];
                        case "title":
                            return attribute_escape($img->properties['title']);
                        case "alt":
                            return attribute_escape($img->properties['alt']);
                        default:
                            return $img->id;
                    }
                }
                if (!isset($options['class'])) {
                    $options['class'] = false;
                }
                if (!empty($options['class'])) {
                    $options['class'] = ' class="' . $options['class'] . '"';
                }
                $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                $width = isset($options['width']) ? $options['width'] : $img->properties['width'];
                $height = isset($options['height']) ? $options['height'] : $img->properties['height'];
                if (isset($options['width']) && !isset($options['height'])) {
                    $scale = $width / $img->properties['width'];
                    $height = round($img->properties['height'] * $scale);
                }
                if (isset($options['height']) && !isset($options['width'])) {
                    $scale = $height / $img->properties['height'];
                    $width = round($img->properties['width'] * $scale);
                }
                if (!empty($options['title'])) {
                    $title = ' title="' . attribute_escape($options['title']) . '"';
                }
                $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $this->name);
                $string = "";
                if (!isset($options['zoomfx'])) {
                    $options['zoomfx'] = "shopp-thickbox";
                }
                if (!empty($options['zoom'])) {
                    $string .= '<a href="' . $Shopp->imguri . $img->src . '/' . str_replace('small_', '', $img->name) . '" class="' . $options['zoomfx'] . '" rel="product-gallery">';
                }
                $string .= '<img src="' . $img->uri . '"' . $title . ' alt="' . $alt . '" width="' . $width . '" height="' . $height . '" ' . $options['class'] . ' />';
                if (!empty($options['zoom'])) {
                    $string .= "</a>";
                }
                return $string;
                break;
            case "gallery":
                if (empty($this->images)) {
                    $this->load_data(array('images'));
                }
                if (!isset($options['zoomfx'])) {
                    $options['zoomfx'] = "shopp-thickbox";
                }
                if (!isset($options['preview'])) {
                    $options['preview'] = "click";
                }
                $previews = '<ul class="previews">';
                $firstPreview = true;
                if (!empty($this->imagesets['small'])) {
                    foreach ($this->imagesets['small'] as $img) {
                        if ($firstPreview) {
                            $previews .= '<li id="preview-fill"' . ($firstPreview ? ' class="fill"' : '') . '>';
                            $previews .= '<img src="' . $Shopp->uri . '/core/ui/icons/clear.png' . '" alt="' . $img->datatype . '" width="' . $img->properties['width'] . '" height="' . $img->properties['height'] . '" />';
                            $previews .= '</li>';
                        }
                        $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                        $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $img->name);
                        $rel = isset($options['rel']) && $options['rel'] ? ' rel="product_' . $this->id . '_gallery"' : '';
                        $previews .= '<li id="preview-' . $img->src . '"' . ($firstPreview ? ' class="active"' : '') . '>';
                        $previews .= '<a href="' . $Shopp->imguri . $img->src . '/' . str_replace('small_', '', $img->name) . '" class="product_' . $this->id . '_gallery ' . $options['zoomfx'] . '"' . $rel . '>';
                        $previews .= '<img src="' . $Shopp->imguri . $img->id . '"' . $title . ' alt="' . $alt . '" width="' . $img->properties['width'] . '" height="' . $img->properties['height'] . '" />';
                        $previews .= '</a>';
                        $previews .= '</li>';
                        $firstPreview = false;
                    }
                }
                $previews .= '</ul>';
                $thumbs = "";
                if (isset($this->imagesets['thumbnail']) && count($this->imagesets['thumbnail']) > 1) {
                    $thumbsize = 32;
                    if (isset($options['thumbsize'])) {
                        $thumbsize = $options['thumbsize'];
                    }
                    $thumbwidth = $thumbsize;
                    $thumbheight = $thumbsize;
                    if (isset($options['thumbwidth'])) {
                        $thumbwidth = $options['thumbwidth'];
                    }
                    if (isset($options['thumbheight'])) {
                        $thumbheight = $options['thumbheight'];
                    }
                    $firstThumb = true;
                    $thumbs = '<ul class="thumbnails">';
                    foreach ($this->imagesets['thumbnail'] as $img) {
                        if (isset($options['thumbwidth']) && !isset($options['thumbheight'])) {
                            $scale = $thumbwidth / $img->properties['width'];
                            $thumbheight = round($img->properties['height'] * $scale);
                        }
                        if (isset($options['thumbheight']) && !isset($options['thumbwidth'])) {
                            $scale = $thumbheight / $img->properties['height'];
                            $thumbwidth = round($img->properties['width'] * $scale);
                        }
                        $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                        $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $img->name);
                        $thumbs .= '<li id="thumbnail-' . $img->src . '" class="preview-' . $img->src . ($firstThumb ? ' first' : ' test') . '">';
                        $thumbs .= '<img src="' . $Shopp->imguri . $img->id . '"' . $title . ' alt="' . $alt . '" width="' . $thumbwidth . '" height="' . $thumbheight . '" />';
                        $thumbs .= '</li>';
                        $firstThumb = false;
                    }
                    $thumbs .= '</ul>';
                }
                $result = '<div id="gallery-' . $this->id . '" class="gallery">' . $previews . $thumbs . '</div>';
                $result .= '<script type="text/javascript"><!--
					jQuery(document).ready( function() {  shopp_gallery("#gallery-' . $this->id . '","' . $options['preview'] . '"); }); 
					// --></script>';
                return $result;
                break;
            case "has-categories":
                if (empty($this->categories)) {
                    $this->load_data(array('categories'));
                }
                if (count($this->categories) > 0) {
                    return true;
                } else {
                    return false;
                }
                break;
            case "categories":
                if (!$this->categoryloop) {
                    reset($this->categories);
                    $this->categoryloop = true;
                } else {
                    next($this->categories);
                }
                if (current($this->categories)) {
                    return true;
                } else {
                    $this->categoryloop = false;
                    return false;
                }
                break;
            case "in-category":
                if (empty($this->categories)) {
                    $this->load_data(array('categories'));
                }
                if (isset($options['id'])) {
                    $field = "id";
                }
                if (isset($options['name'])) {
                    $field = "name";
                }
                if (isset($options['slug'])) {
                    $field = "slug";
                }
                foreach ($this->categories as $category) {
                    if ($category->{$field} == $options[$field]) {
                        return true;
                    }
                }
                return false;
            case "category":
                $category = current($this->categories);
                if (isset($options['show'])) {
                    if ($options['show'] == "id") {
                        return $category->id;
                    }
                    if ($options['show'] == "slug") {
                        return $category->slug;
                    }
                }
                return $category->name;
                break;
            case "has-tags":
                if (empty($this->tags)) {
                    $this->load_data(array('tags'));
                }
                if (count($this->tags) > 0) {
                    return true;
                } else {
                    return false;
                }
                break;
            case "tags":
                if (!$this->tagloop) {
                    reset($this->tags);
                    $this->tagloop = true;
                } else {
                    next($this->tags);
                }
                if (current($this->tags)) {
                    return true;
                } else {
                    $this->tagloop = false;
                    return false;
                }
                break;
            case "tagged":
                if (empty($this->tags)) {
                    $this->load_data(array('tags'));
                }
                if (isset($options['id'])) {
                    $field = "id";
                }
                if (isset($options['name'])) {
                    $field = "name";
                }
                foreach ($this->tags as $tag) {
                    if ($tag->{$field} == $options[$field]) {
                        return true;
                    }
                }
                return false;
            case "tag":
                $tag = current($this->tags);
                if (isset($options['show'])) {
                    if ($options['show'] == "id") {
                        return $tag->id;
                    }
                }
                return $tag->name;
                break;
            case "has-specs":
                if (empty($this->specs)) {
                    $this->load_data(array('specs'));
                }
                if (count($this->specs) > 0) {
                    $this->merge_specs();
                    return true;
                } else {
                    return false;
                }
                break;
            case "specs":
                if (!$this->specloop) {
                    reset($this->specs);
                    $this->specloop = true;
                } else {
                    next($this->specs);
                }
                if (current($this->specs)) {
                    return true;
                } else {
                    $this->specloop = false;
                    return false;
                }
                break;
            case "spec":
                $string = "";
                $separator = ": ";
                $delimiter = ", ";
                if (isset($options['separator'])) {
                    $separator = $options['separator'];
                }
                if (isset($options['delimiter'])) {
                    $separator = $options['delimiter'];
                }
                $spec = current($this->specs);
                if (is_array($spec->content)) {
                    $spec->content = join($delimiter, $spec->content);
                }
                if (isset($options['name']) && !empty($options['name']) && isset($this->specskey[$options['name']])) {
                    $spec = $this->specskey[$options['name']];
                    if (is_array($spec)) {
                        if (isset($options['index'])) {
                            foreach ($spec as $index => $entry) {
                                if ($index + 1 == $options['index']) {
                                    $content = $entry->content;
                                }
                            }
                        } else {
                            foreach ($spec as $entry) {
                                $contents[] = $entry->content;
                            }
                            $content = join($delimiter, $contents);
                        }
                    } else {
                        $content = $spec->content;
                    }
                    $string = apply_filters('shopp_product_spec', $content);
                    return $string;
                }
                if (isset($options['name']) && isset($options['content'])) {
                    $string = "{$spec->name}{$separator}" . apply_filters('shopp_product_spec', $spec->content);
                } elseif (isset($options['name'])) {
                    $string = $spec->name;
                } elseif (isset($options['content'])) {
                    $string = apply_filters('shopp_product_spec', $spec->content);
                } else {
                    $string = "{$spec->name}{$separator}" . apply_filters('shopp_product_spec', $spec->content);
                }
                return $string;
                break;
            case "has-variations":
                return $this->variations == "on" && !empty($this->options);
                break;
            case "variations":
                $string = "";
                if (!isset($options['mode'])) {
                    if (!$this->priceloop) {
                        reset($this->prices);
                        $this->priceloop = true;
                    } else {
                        next($this->prices);
                    }
                    $thisprice = current($this->prices);
                    if ($thisprice && $thisprice->type == "N/A") {
                        next($this->prices);
                    }
                    if (current($this->prices)) {
                        return true;
                    } else {
                        $this->priceloop = false;
                        return false;
                    }
                    return true;
                }
                if ($this->outofstock) {
                    return false;
                }
                // Completely out of stock, hide menus
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $defaults = array('defaults' => '', 'disabled' => 'show', 'before_menu' => '', 'after_menu' => '');
                $options = array_merge($defaults, $options);
                if (!isset($options['label'])) {
                    $options['label'] = "on";
                }
                if (!isset($options['required'])) {
                    $options['required'] = __('You must select the options for this item before you can add it to your shopping cart.', 'Shopp');
                }
                if ($options['mode'] == "single") {
                    if (!empty($options['before_menu'])) {
                        $string .= $options['before_menu'] . "\n";
                    }
                    if (value_is_true($options['label'])) {
                        $string .= '<label for="product-options' . $this->id . '">Options: </label> ' . "\n";
                    }
                    $string .= '<select name="products[' . $this->id . '][price]" id="product-options' . $this->id . '">';
                    if (!empty($options['defaults'])) {
                        $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                    }
                    foreach ($this->prices as $pricetag) {
                        if ($pricetag->context != "variation") {
                            continue;
                        }
                        $taxrate = shopp_taxrate($options['taxes'], $pricetag->tax);
                        $currently = $pricetag->sale == "on" ? $pricetag->promoprice : $pricetag->price;
                        $disabled = $pricetag->inventory == "on" && $pricetag->stock == 0 ? ' disabled="disabled"' : '';
                        $price = '  (' . money($currently) . ')';
                        if ($pricetag->type != "N/A") {
                            $string .= '<option value="' . $pricetag->id . '"' . $disabled . '>' . $pricetag->label . $price . '</option>' . "\n";
                        }
                    }
                    $string .= '</select>';
                    if (!empty($options['after_menu'])) {
                        $string .= $options['after_menu'] . "\n";
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], true);
                    ob_start();
                    ?>
					<script type="text/javascript">
					<!--
					(function($) {
						$(document).ready(function () {
							productOptions[<?php 
                    echo $this->id;
                    ?>
] = new Array();
							productOptions[<?php 
                    echo $this->id;
                    ?>
]['pricing'] = <?php 
                    echo json_encode($this->pricekey);
                    ?>
;
							options_default = <?php 
                    echo !empty($options['defaults']) ? 'true' : 'false';
                    ?>
;
							options_required = "<?php 
                    echo $options['required'];
                    ?>
";
							
							productOptions[<?php 
                    echo $this->id;
                    ?>
]['menu'] = new ProductOptionsMenus('select<?php 
                    if (isset($Shopp->Category->slug)) {
                        echo ".category-" . $Shopp->Category->slug;
                    }
                    ?>
.product<?php 
                    echo $this->id;
                    ?>
',<?php 
                    echo $options['disabled'] == "hide" ? "true" : "false";
                    ?>
,productOptions[<?php 
                    echo $this->id;
                    ?>
]['pricing'],<?php 
                    echo empty($taxrate) ? '0' : $taxrate;
                    ?>
);
						});
					})(jQuery)
					//-->
					</script>
					<?php 
                    $script = ob_get_contents();
                    ob_end_clean();
                    $options['after_menu'] = $script . $options['after_menu'];
                    if (isset($this->options['variations'])) {
                        foreach ($this->options['variations'] as $id => $menu) {
                            if (!empty($options['before_menu'])) {
                                $string .= $options['before_menu'] . "\n";
                            }
                            if (value_is_true($options['label'])) {
                                $string .= '<label for="options-' . $id . '">' . $menu['menu'] . '</label> ' . "\n";
                            }
                            $string .= '<select name="products[' . $this->id . '][options][]" class="product' . $this->id . ' options">';
                            if (!empty($options['defaults'])) {
                                $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                            }
                            foreach ($menu['label'] as $key => $option) {
                                $string .= '<option value="' . $menu['id'][$key] . '">' . $option . '</option>' . "\n";
                            }
                            $string .= '</select>';
                            if (!empty($options['after_menu'])) {
                                $string .= $options['after_menu'] . "\n";
                            }
                        }
                    } else {
                        foreach ($this->options as $id => $menu) {
                            if (!empty($options['before_menu'])) {
                                $string .= $options['before_menu'] . "\n";
                            }
                            if (value_is_true($options['label'])) {
                                $string .= '<label for="options-' . $menu['id'] . '">' . $menu['name'] . '</label> ' . "\n";
                            }
                            $category_class = isset($Shopp->Category->slug) ? 'category-' . $Shopp->Category->slug : '';
                            $string .= '<select name="products[' . $this->id . '][options][]" class="' . $category_class . ' product' . $this->id . ' options" id="options-' . $menu['id'] . '">';
                            if (!empty($options['defaults'])) {
                                $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                            }
                            foreach ($menu['options'] as $key => $option) {
                                $string .= '<option value="' . $option['id'] . '">' . $option['name'] . '</option>' . "\n";
                            }
                            $string .= '</select>';
                            if (!empty($options['after_menu'])) {
                                $string .= $options['after_menu'] . "\n";
                            }
                        }
                    }
                }
                return $string;
                break;
            case "variation":
                $variation = current($this->prices);
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $taxrate = shopp_taxrate($options['taxes'], $variation->tax);
                $weightunit = isset($options['units']) && !value_is_true($options['units']) ? false : $Shopp->Settings->get('weight_unit');
                $string = '';
                if (array_key_exists('id', $options)) {
                    $string .= $variation->id;
                }
                if (array_key_exists('label', $options)) {
                    $string .= $variation->label;
                }
                if (array_key_exists('type', $options)) {
                    $string .= $variation->type;
                }
                if (array_key_exists('sku', $options)) {
                    $string .= $variation->sku;
                }
                if (array_key_exists('price', $options)) {
                    $string .= money($variation->price + $variation->price * $taxrate);
                }
                if (array_key_exists('saleprice', $options)) {
                    $string .= money($variation->saleprice + $variation->saleprice * $taxrate);
                }
                if (array_key_exists('stock', $options)) {
                    $string .= $variation->stock;
                }
                if (array_key_exists('weight', $options)) {
                    $string .= round($variation->weight, 3) . ($weightunit ? " {$weightunit}" : false);
                }
                if (array_key_exists('shipfee', $options)) {
                    $string .= money(floatvalue($variation->shipfee));
                }
                if (array_key_exists('sale', $options)) {
                    return $variation->sale == "on";
                }
                if (array_key_exists('shipping', $options)) {
                    return $variation->shipping == "on";
                }
                if (array_key_exists('tax', $options)) {
                    return $variation->tax == "on";
                }
                if (array_key_exists('inventory', $options)) {
                    return $variation->inventory == "on";
                }
                return $string;
                break;
            case "has-addons":
                if (isset($this->options['addons'])) {
                    return true;
                } else {
                    return false;
                }
                break;
                break;
            case "donation":
            case "amount":
            case "quantity":
                if ($this->outofstock) {
                    return false;
                }
                if (!isset($options['value'])) {
                    $options['value'] = 1;
                }
                if (!isset($options['input'])) {
                    $options['input'] = "text";
                }
                if (!isset($options['labelpos'])) {
                    $options['labelpos'] = "before";
                }
                if (!isset($options['label'])) {
                    $label = "";
                } else {
                    $label = '<label for="quantity' . $this->id . '">' . $options['label'] . '</label>';
                }
                $result = "";
                if ($options['labelpos'] == "before") {
                    $result .= "{$label} ";
                }
                if (!$this->priceloop) {
                    reset($this->prices);
                }
                $variation = current($this->prices);
                if (isset($options['input']) && $options['input'] == "menu") {
                    if (!isset($options['options'])) {
                        $values = "1-15,20,25,30,40,50,75,100";
                    } else {
                        $values = $options['options'];
                    }
                    if ($this->inventory && $this->pricerange['max']['stock'] == 0) {
                        return "";
                    }
                    if (strpos($values, ",") !== false) {
                        $values = explode(",", $values);
                    } else {
                        $values = array($values);
                    }
                    $qtys = array();
                    foreach ($values as $value) {
                        if (strpos($value, "-") !== false) {
                            $value = explode("-", $value);
                            if ($value[0] >= $value[1]) {
                                $qtys[] = $value[0];
                            } else {
                                for ($i = $value[0]; $i < $value[1] + 1; $i++) {
                                    $qtys[] = $i;
                                }
                            }
                        } else {
                            $qtys[] = $value;
                        }
                    }
                    $result .= '<select name="products[' . $this->id . '][quantity]" id="quantity-' . $this->id . '">';
                    foreach ($qtys as $qty) {
                        $amount = $qty;
                        $selected = isset($this->quantity) ? $this->quantity : 1;
                        if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
                            if ($variation->donation['min'] == "on" && $amount < $variation->price) {
                                continue;
                            }
                            $amount = money($amount);
                            $selected = $variation->price;
                        } else {
                            if ($this->inventory && $amount > $this->pricerange['max']['stock']) {
                                continue;
                            }
                        }
                        $result .= '<option' . ($qty == $selected ? ' selected="selected"' : '') . ' value="' . $qty . '">' . $amount . '</option>';
                    }
                    $result .= '</select>';
                    if ($options['labelpos'] == "after") {
                        $result .= " {$label}";
                    }
                    return $result;
                }
                if (valid_input($options['input'])) {
                    if (!isset($options['size'])) {
                        $options['size'] = 3;
                    }
                    if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
                        if ($variation->donation['min']) {
                            $options['value'] = $variation->price;
                        }
                        $options['class'] .= " currency";
                    }
                    $result = '<input type="' . $options['input'] . '" name="products[' . $this->id . '][quantity]" id="quantity-' . $this->id . '"' . inputattrs($options) . ' />';
                }
                if ($options['labelpos'] == "after") {
                    $result .= " {$label}";
                }
                return $result;
                break;
            case "input":
                if (!isset($options['type']) || $options['type'] != "menu" && $options['type'] != "textarea" && !valid_input($options['type'])) {
                    $options['type'] = "text";
                }
                if (!isset($options['name'])) {
                    return "";
                }
                if ($options['type'] == "menu") {
                    $result = '<select name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '">';
                    if (isset($options['options'])) {
                        $menuoptions = preg_split('/,(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/', $options['options']);
                    }
                    if (is_array($menuoptions)) {
                        foreach ($menuoptions as $option) {
                            $selected = "";
                            $option = trim($option, '"');
                            if (isset($options['default']) && $options['default'] == $option) {
                                $selected = ' selected="selected"';
                            }
                            $result .= '<option value="' . $option . '"' . $selected . '>' . $option . '</option>';
                        }
                    }
                    $result .= '</select>';
                } elseif ($options['type'] == "textarea") {
                    if (isset($options['cols'])) {
                        $cols = ' cols="' . $options['cols'] . '"';
                    }
                    if (isset($options['rows'])) {
                        $rows = ' rows="' . $options['rows'] . '"';
                    }
                    $result .= '<textarea  name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '"' . $cols . $rows . '>' . $options['value'] . '</textarea>';
                } else {
                    $result = '<input type="' . $options['type'] . '" name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '"' . inputattrs($options) . ' />';
                }
                return $result;
                break;
            case "outofstock":
                if ($this->outofstock) {
                    $label = isset($options['label']) ? $options['label'] : $Shopp->Settings->get('outofstock_text');
                    $string = '<span class="outofstock">' . $label . '</span>';
                    return $string;
                } else {
                    return false;
                }
                break;
            case "buynow":
                if (!isset($options['value'])) {
                    $options['value'] = __("Buy Now", "Shopp");
                }
            case "addtocart":
                if (!isset($options['class'])) {
                    $options['class'] = "addtocart";
                } else {
                    $options['class'] .= " addtocart";
                }
                if (!isset($options['value'])) {
                    $options['value'] = __("Add to Cart", "Shopp");
                }
                $string = "";
                if ($this->outofstock) {
                    $string .= '<span class="outofstock">' . $Shopp->Settings->get('outofstock_text') . '</span>';
                    return $string;
                }
                $string .= '<input type="hidden" name="products[' . $this->id . '][product]" value="' . $this->id . '" />';
                if (!empty($this->prices[0]) && $this->prices[0]->type != "N/A") {
                    $string .= '<input type="hidden" name="products[' . $this->id . '][price]" value="' . $this->prices[0]->id . '" />';
                }
                if (!empty($Shopp->Category)) {
                    if (SHOPP_PERMALINKS) {
                        $string .= '<input type="hidden" name="products[' . $this->id . '][category]" value="' . $Shopp->Category->uri . '" />';
                    } else {
                        $string .= '<input type="hidden" name="products[' . $this->id . '][category]" value="' . (!empty($Shopp->Category->id) ? $Shopp->Category->id : $Shopp->Category->slug) . '" />';
                    }
                }
                $string .= '<input type="hidden" name="cart" value="add" />';
                if (isset($options['ajax'])) {
                    $options['class'] .= " ajax";
                    $string .= '<input type="hidden" name="ajax" value="true" />';
                    $string .= '<input type="button" name="addtocart" ' . inputattrs($options) . ' />';
                } else {
                    $string .= '<input type="submit" name="addtocart" ' . inputattrs($options) . ' />';
                }
                return $string;
        }
    }
Пример #23
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save appointment") {
             /* Save appointment
              */
             if ($this->model->appointment_oke($_POST) == false) {
                 $this->show_appointment_form($_POST);
             } else {
                 if (isset($_POST["id"]) == false) {
                     /* Create appointment
                      */
                     if ($this->model->create_appointment($_POST) == false) {
                         $this->output->add_message("Error while creating appointment.");
                         $this->show_appointment_form($_POST);
                     } else {
                         $this->user->log_action("appointment %d created", $db->last_insert_id);
                         $this->show_agenda_overview();
                     }
                 } else {
                     /* Update appointment
                      */
                     if ($this->model->update_appointment($_POST) == false) {
                         $this->output->add_message("Error while updating appointment.");
                         $this->show_appointment_form($_POST);
                     } else {
                         $this->user->log_action("appointment %d updated", $_POST["id"]);
                         $this->show_agenda_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete appointment") {
                 /* Delete appointment
                  */
                 if ($this->model->delete_appointment($_POST["id"]) == false) {
                     $this->output->add_tag("result", "Error while deleting appointment.");
                 } else {
                     $this->user->log_action("appointment %d deleted", $_POST["id"]);
                     $this->show_agenda_overview();
                 }
             } else {
                 $this->show_agenda_overview();
             }
         }
     } else {
         if ($this->page->pathinfo[2] == "new") {
             /* New appointment
              */
             $appointment = array("begin" => date("Y-m-d"), "end" => date("Y-m-d"));
             $this->show_appointment_form($appointment);
         } else {
             if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Edit appointment
                  */
                 if (($appointment = $this->model->get_appointment($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "Agendapunten niet gevonden.");
                 } else {
                     $this->show_appointment_form($appointment);
                 }
             } else {
                 /* Show month
                  */
                 $this->show_agenda_overview();
             }
         }
     }
 }
Пример #24
0
	function tag ($property,$options=array()) {
		global $Ecart;

		$select_attrs = array('title','required','class','disabled','required','size','tabindex','accesskey');
		$submit_attrs = array('title','class','value','disabled','tabindex','accesskey');

		switch ($property) {
			case "link":
			case "url":
				return ecarturl(ECART_PRETTYURLS?$this->slug:array('ecart_pid'=>$this->id));
				break;
			case "found":
				if (empty($this->id)) return false;
				$load = array('prices','images','specs','tags','categories');
				if (isset($options['load'])) $load = explode(",",$options['load']);
				$this->load_data($load);
				return true;
				break;
			case "relevance": return (string)$this->score; break;
			case "id": return $this->id; break;
			case "name": return apply_filters('ecart_product_name',$this->name); break;
			case "slug": return $this->slug; break;
			case "summary": return apply_filters('ecart_product_summary',$this->summary); break;
			case "description":
				return apply_filters('ecart_product_description',$this->description);
			case "isfeatured":
			case "is-featured":
				return ($this->featured == "on"); break;
			case "price":
			case "saleprice":
				if (empty($this->prices)) $this->load_data(array('prices'));
				$defaults = array(
					'taxes' => null,
					'starting' => ''
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if (!is_null($taxes)) $taxes = value_is_true($taxes);

				$min = $this->min[$property];
				$mintax = $this->min[$property.'_tax'];

				$max = $this->max[$property];
				$maxtax = $this->max[$property.'_tax'];

				$taxrate = ecart_taxrate($taxes,$this->prices[0]->tax,$this);

				if ("saleprice" == $property) $pricetag = $this->prices[0]->promoprice;
				else $pricetag = $this->prices[0]->price;

				if (count($this->options) > 0) {
					$taxrate = ecart_taxrate($taxes,true,$this);
					$mintax = $mintax?$min*$taxrate:0;
					$maxtax = $maxtax?$max*$taxrate:0;

					if ($min == $max) return money($min+$mintax);
					else {
						if (!empty($starting)) return "$starting ".money($min+$mintax);
						return money($min+$mintax)." &mdash; ".money($max+$maxtax);
					}
				} else return money($pricetag+($pricetag*$taxrate));

				break;
			case "taxrate":
				return ecart_taxrate(null,true,$this);
				break;
			case "weight":
				if(empty($this->prices)) $this->load_data(array('prices'));
				$defaults = array(
					'unit' => $Ecart->Settings->get('weight_unit'),
					'min' => $this->min['weight'],
					'max' => $this->max['weight'],
					'units' => true,
					'convert' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if(!isset($this->min['weight'])) return false;

				if ($convert !== false) {
					$min = convert_unit($min,$convert);
					$max = convert_unit($max,$convert);
					if (is_null($units)) $units = true;
					$unit = $convert;
				}

				$range = false;
				if ($min != $max) {
					$range = array($min,$max);
					sort($range);
				}

				$string = ($min == $max)?round($min,3):round($range[0],3)." - ".round($range[1],3);
				$string .= value_is_true($units) ? " $unit" : "";
				return $string;
				break;
			case "onsale":
				if (empty($this->prices)) $this->load_data(array('prices'));
				if (empty($this->prices)) return false;
				return $this->onsale;
				break;
			case "has-savings": return ($this->onsale && $this->min['saved'] > 0); break;
			case "savings":
				if (empty($this->prices)) $this->load_data(array('prices'));
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$taxrate = ecart_taxrate($options['taxes']);
				$range = false;

				if (!isset($options['show'])) $options['show'] = '';
				if ($options['show'] == "%" || $options['show'] == "percent") {
					if ($this->options > 1) {
						if (round($this->min['savings']) != round($this->max['savings'])) {
							$range = array($this->min['savings'],$this->max['savings']);
							sort($range);
						}
						if (!$range) return percentage($this->min['savings'],array('precision' => 0)); // No price range
						else return percentage($range[0],array('precision' => 0))." &mdash; ".percentage($range[1],array('precision' => 0));
					} else return percentage($this->max['savings'],array('precision' => 0));
				} else {
					if ($this->options > 1) {
						if (round($this->min['saved']) != round($this->max['saved'])) {
							$range = array($this->min['saved'],$this->max['saved']);
							sort($range);
						}
						if (!$range) return money($this->min['saved']+($this->min['saved']*$taxrate)); // No price range
						else return money($range[0]+($range[0]*$taxrate))." &mdash; ".money($range[1]+($range[1]*$taxrate));
					} else return money($this->max['saved']+($this->max['saved']*$taxrate));
				}
				break;
			case "freeshipping":
				if (empty($this->prices)) $this->load_data(array('prices'));
				return $this->freeshipping;
			case "hasimages":
			case "has-images":
				if (empty($this->images)) $this->load_data(array('images'));
				return (!empty($this->images));
				break;
			case "images":
				if (!$this->images) return false;
				if (!isset($this->_images_loop)) {
					reset($this->images);
					$this->_images_loop = true;
				} else next($this->images);

				if (current($this->images) !== false) return true;
				else {
					unset($this->_images_loop);
					return false;
				}
				break;
			case "coverimage":
				// Force select the first loaded image
				unset($options['id']);
				$options['index'] = 0;
			case "thumbnail": // deprecated
			case "image":
				if (empty($this->images)) $this->load_data(array('images'));
				if (!(count($this->images) > 0)) return "";

				// Compatibility defaults
				$_size = 96;
				$_width = $Ecart->Settings->get('gallery_thumbnail_width');
				$_height = $Ecart->Settings->get('gallery_thumbnail_height');
				if (!$_width) $_width = $_size;
				if (!$_height) $_height = $_size;

				$defaults = array(
					'img' => false,
					'id' => false,
					'index' => false,
					'class' => '',
					'width' => false,
					'height' => false,
					'size' => false,
					'fit' => false,
					'sharpen' => false,
					'quality' => false,
					'bg' => false,
					'alt' => '',
					'title' => '',
					'zoom' => '',
					'zoomfx' => 'ecart-zoom',
					'property' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				// Select image by database id
				if ($id !== false) {
					for ($i = 0; $i < count($this->images); $i++) {
						if ($img->id == $id) {
							$img = $this->images[$i]; break;
						}
					}
					if (!$img) return "";
				}

				// Select image by index position in the list
				if ($index !== false && isset($this->images[$index]))
					$img = $this->images[$index];

				// Use the current image pointer by default
				if (!$img) $img = current($this->images);

				if ($size !== false) $width = $height = $size;
				if (!$width) $width = $_width;
				if (!$height) $height = $_height;

				$scale = $fit?array_search($fit,$img->_scaling):false;
				$sharpen = $sharpen?min($sharpen,$img->_sharpen):false;
				$quality = $quality?min($quality,$img->_quality):false;
				$fill = $bg?hexdec(ltrim($bg,'#')):false;

				list($width_a,$height_a) = array_values($img->scaled($width,$height,$scale));
				if ($size == "original") {
					$width_a = $img->width;
					$height_a = $img->height;
				}
				if ($width_a === false) $width_a = $width;
				if ($height_a === false) $height_a = $height;

				$alt = esc_attr(empty($alt)?(empty($img->alt)?$img->name:$img->alt):$alt);
				$title = empty($title)?$img->title:$title;
				$titleattr = empty($title)?'':' title="'.esc_attr($title).'"';
				$classes = empty($class)?'':' class="'.esc_attr($class).'"';

				$src = ecarturl($img->id,'images');
				if (ECART_PERMALINKS) $src = trailingslashit($src).$img->filename;

				if ($size != "original")
					$src = add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),$src);

				switch (strtolower($property)) {
					case "id": return $img->id; break;
					case "url":
					case "src": return $src; break;
					case "title": return $title; break;
					case "alt": return $alt; break;
					case "width": return $width_a; break;
					case "height": return $height_a; break;
					case "class": return $class; break;
				}

				$imgtag = '<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' />';

				if (value_is_true($zoom))
					return '<a href="'.ecarturl($img->id,'images').'/'.$img->filename.'" class="'.$zoomfx.'" rel="product-'.$this->id.'">'.$imgtag.'</a>';

				return $imgtag;
				break;
			case "gallery":
				if (empty($this->images)) $this->load_data(array('images'));
				if (empty($this->images)) return false;
				$styles = '';
				$_size = 240;
				$_width = $Ecart->Settings->get('gallery_small_width');
				$_height = $Ecart->Settings->get('gallery_small_height');

				if (!$_width) $_width = $_size;
				if (!$_height) $_height = $_size;

				$defaults = array(

					// Layout settings
					'margins' => 20,
					'rowthumbs' => false,
					// 'thumbpos' => 'after',

					// Preview image settings
					'p.size' => false,
					'p.width' => false,
					'p.height' => false,
					'p.fit' => false,
					'p.sharpen' => false,
					'p.quality' => false,
					'p.bg' => false,
					'p.link' => true,
					'rel' => '',

					// Thumbnail image settings
					'thumbsize' => false,
					'thumbwidth' => false,
					'thumbheight' => false,
					'thumbfit' => false,
					'thumbsharpen' => false,
					'thumbquality' => false,
					'thumbbg' => false,

					// Effects settings
					'zoomfx' => 'ecart-zoom',
					'preview' => 'click',
					'colorbox' => '{}'


				);
				$optionset = array_merge($defaults,$options);

				// Translate dot names
				$options = array();
				$keys = array_keys($optionset);
				foreach ($keys as $key)
					$options[str_replace('.','_',$key)] = $optionset[$key];
				extract($options);

				if ($p_size > 0)
					$_width = $_height = $p_size;

				$width = $p_width > 0?$p_width:$_width;
				$height = $p_height > 0?$p_height:$_height;

				$preview_width = $width;

				$previews = '<ul class="previews">';
				$firstPreview = true;

				// Find the max dimensions to use for the preview spacing image
				$maxwidth = $maxheight = 0;
				foreach ($this->images as $img) {
					$scale = $p_fit?false:array_search($p_fit,$img->_scaling);
					$scaled = $img->scaled($width,$height,$scale);
					$maxwidth = max($maxwidth,$scaled['width']);
					$maxheight = max($maxheight,$scaled['height']);
				}

				if ($maxwidth == 0) $maxwidth = $width;
				if ($maxheight == 0) $maxheight = $height;

				$p_link = value_is_true($p_link);

				foreach ($this->images as $img) {

					$scale = $p_fit?array_search($p_fit,$img->_scaling):false;
					$sharpen = $p_sharpen?min($p_sharpen,$img->_sharpen):false;
					$quality = $p_quality?min($p_quality,$img->_quality):false;
					$fill = $p_bg?hexdec(ltrim($p_bg,'#')):false;
					$scaled = $img->scaled($width,$height,$scale);

					if ($firstPreview) { // Adds "filler" image to reserve the dimensions in the DOM
						$href = ecarturl(ECART_PERMALINKS?trailingslashit('000'):'000','images');
						$previews .= '<li id="preview-fill"'.(($firstPreview)?' class="fill"':'').'>';
						$previews .= '<img src="'.add_query_string("$maxwidth,$maxheight",$href).'" alt=" " width="'.$maxwidth.'" height="'.$maxheight.'" />';
						$previews .= '</li>';
					}
					$title = !empty($img->title)?' title="'.esc_attr($img->title).'"':'';
					$alt = esc_attr(!empty($img->alt)?$img->alt:$img->filename);

					$previews .= '<li id="preview-'.$img->id.'"'.(($firstPreview)?' class="active"':'').'>';

					$href = ecarturl(ECART_PERMALINKS?trailingslashit($img->id).$img->filename:$img->id,'images');
					if ($p_link) $previews .= '<a href="'.$href.'" class="gallery product_'.$this->id.' '.$options['zoomfx'].'"'.(!empty($rel)?' rel="'.$rel.'"':'').'>';
					// else $previews .= '<a name="preview-'.$img->id.'">'; // If links are turned off, leave the <a> so we don't break layout
					$previews .= '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'" />';
					if ($p_link) $previews .= '</a>';
					$previews .= '</li>';
					$firstPreview = false;
				}
				$previews .= '</ul>';

				$thumbs = "";
				$twidth = $preview_width+$margins;

				if (count($this->images) > 1) {
					$default_size = 64;
					$_thumbwidth = $Ecart->Settings->get('gallery_thumbnail_width');
					$_thumbheight = $Ecart->Settings->get('gallery_thumbnail_height');
					if (!$_thumbwidth) $_thumbwidth = $default_size;
					if (!$_thumbheight) $_thumbheight = $default_size;

					if ($thumbsize > 0) $thumbwidth = $thumbheight = $thumbsize;

					$width = $thumbwidth > 0?$thumbwidth:$_thumbwidth;
					$height = $thumbheight > 0?$thumbheight:$_thumbheight;

					$firstThumb = true;
					$thumbs = '<ul class="thumbnails">';
					foreach ($this->images as $img) {
						$scale = $thumbfit?array_search($thumbfit,$img->_scaling):false;
						$sharpen = $thumbsharpen?min($thumbsharpen,$img->_sharpen):false;
						$quality = $thumbquality?min($thumbquality,$img->_quality):false;
						$fill = $thumbbg?hexdec(ltrim($thumbbg,'#')):false;
						$scaled = $img->scaled($width,$height,$scale);

						$title = !empty($img->title)?' title="'.esc_attr($img->title).'"':'';
						$alt = esc_attr(!empty($img->alt)?$img->alt:$img->name);

						$thumbs .= '<li id="thumbnail-'.$img->id.'" class="preview-'.$img->id.(($firstThumb)?' first':'').'">';
						$thumbs .= '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'" />';
						$thumbs .= '</li>'."\n";
						$firstThumb = false;
					}
					$thumbs .= '</ul>';

				}
				if ($rowthumbs > 0) $twidth = ($width+$margins+2)*(int)$rowthumbs;

				$result = '<div id="gallery-'.$this->id.'" class="gallery">'.$previews.$thumbs.'</div>';
				$script = "\t".'EcartGallery("#gallery-'.$this->id.'","'.$preview.'"'.($twidth?",$twidth":"").');';
				add_storefrontjs($script);

				return $result;

				break;
			case "has-categories":
				if (empty($this->categories)) $this->load_data(array('categories'));
				if (count($this->categories) > 0) return true; else return false; break;
			case "categories":
				if (!isset($this->_categories_loop)) {
					reset($this->categories);
					$this->_categories_loop = true;
				} else next($this->categories);

				if (current($this->categories) !== false) return true;
				else {
					unset($this->_categories_loop);
					return false;
				}
				break;
			case "in-category":
				if (empty($this->categories)) $this->load_data(array('categories'));
				if (isset($options['id'])) $field = "id";
				if (isset($options['name'])) $field = "name";
				if (isset($options['slug'])) $field = "slug";
				foreach ($this->categories as $category)
					if ($category->{$field} == $options[$field]) return true;
				return false;
			case "category":
				$category = current($this->categories);
				if (isset($options['show'])) {
					if ($options['show'] == "id") return $category->id;
					if ($options['show'] == "slug") return $category->slug;
				}
				return $category->name;
				break;
			case "hastags":
			case "has-tags":
				if (empty($this->tags)) $this->load_data(array('tags'));
				if (count($this->tags) > 0) return true; else return false; break;
			case "tags":
				if (!isset($this->_tags_loop)) {
					reset($this->tags);
					$this->_tags_loop = true;
				} else next($this->tags);

				if (current($this->tags) !== false) return true;
				else {
					unset($this->_tags_loop);
					return false;
				}
				break;
			case "tagged":
				if (empty($this->tags)) $this->load_data(array('tags'));
				if (isset($options['id'])) $field = "id";
				if (isset($options['name'])) $field = "name";
				foreach ($this->tags as $tag)
					if ($tag->{$field} == $options[$field]) return true;
				return false;
			case "tag":
				$tag = current($this->tags);
				if (isset($options['show'])) {
					if ($options['show'] == "id") return $tag->id;
				}
				return $tag->name;
				break;
			case "hasspecs":
			case "has-specs":
				if (empty($this->specs)) $this->load_data(array('specs'));
				if (count($this->specs) > 0) {
					$this->merge_specs();
					return true;
				} else return false; break;
			case "specs":
				if (!isset($this->_specs_loop)) {
					reset($this->specs);
					$this->_specs_loop = true;
				} else next($this->specs);

				if (current($this->specs) !== false) return true;
				else {
					unset($this->_specs_loop);
					return false;
				}
				break;
			case "spec":
				$string = "";
				$separator = ": ";
				$delimiter = ", ";
				if (isset($options['separator'])) $separator = $options['separator'];
				if (isset($options['delimiter'])) $separator = $options['delimiter'];

				$spec = current($this->specs);
				if (is_array($spec->value)) $spec->value = join($delimiter,$spec->value);

				if (isset($options['name'])
					&& !empty($options['name'])
					&& isset($this->specskey[$options['name']])) {
						$spec = $this->specskey[$options['name']];
						if (is_array($spec)) {
							if (isset($options['index'])) {
								foreach ($spec as $index => $entry)
									if ($index+1 == $options['index'])
										$content = $entry->value;
							} else {
								foreach ($spec as $entry) $contents[] = $entry->value;
								$content = join($delimiter,$contents);
							}
						} else $content = $spec->value;
					$string = apply_filters('ecart_product_spec',$content);
					return $string;
				}

				if (isset($options['name']) && isset($options['content']))
					$string = "{$spec->name}{$separator}".apply_filters('ecart_product_spec',$spec->value);
				elseif (isset($options['name'])) $string = $spec->name;
				elseif (isset($options['content'])) $string = apply_filters('ecart_product_spec',$spec->value);
				else $string = "{$spec->name}{$separator}".apply_filters('ecart_product_spec',$spec->value);
				return $string;
				break;
			case "has-variations":
				return ($this->variations == "on" && (!empty($this->options['v']) || !empty($this->options))); break;
			case "variations":

				$string = "";

				if (!isset($options['mode'])) {
					if (!isset($this->_prices_loop)) {
						reset($this->prices);
						$this->_prices_loop = true;
					} else next($this->prices);
					$price = current($this->prices);

					if ($price && ($price->type == 'N/A' || $price->context != 'variation'))
						next($this->prices);

					if (current($this->prices) !== false) return true;
					else {
						unset($this->_prices_loop);
						return false;
					}
					return true;
				}

				if ($this->outofstock) return false; // Completely out of stock, hide menus
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$defaults = array(
					'defaults' => '',
					'disabled' => 'show',
					'pricetags' => 'show',
					'before_menu' => '',
					'after_menu' => '',
					'label' => 'on',
					'required' => __('You must select the options for this item before you can add it to your shopping cart.','Ecart')
					);
				$options = array_merge($defaults,$options);

				if ($options['mode'] == "single") {
					if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
					if (value_is_true($options['label'])) $string .= '<label for="product-options'.$this->id.'">'. __('Options').': </label> '."\n";

					$string .= '<select name="products['.$this->id.'][price]" id="product-options'.$this->id.'">';
					if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";

					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "variation") continue;

						if (!isset($options['taxes']))
							$taxrate = ecart_taxrate(null,$pricetag->tax);
						else $taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax);
						$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
						$disabled = ($pricetag->inventory == "on" && $pricetag->stock == 0)?' disabled="disabled"':'';

						$price = '  ('.money($currently).')';
						if ($pricetag->type != "N/A")
							$string .= '<option value="'.$pricetag->id.'"'.$disabled.'>'.$pricetag->label.$price.'</option>'."\n";
					}
					$string .= '</select>';
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				} else {
					if (!isset($this->options)) return;

					$menuoptions = $this->options;
					if (!empty($this->options['v'])) $menuoptions = $this->options['v'];

					$baseop = $Ecart->Settings->get('base_operations');
					$precision = $baseop['currency']['format']['precision'];

					if (!isset($options['taxes']))
						$taxrate = ecart_taxrate(null,true,$this);
					else $taxrate = ecart_taxrate(value_is_true($options['taxes']),true,$this);

					$pricekeys = array();
					foreach ($this->pricekey as $key => $pricing) {
						$filter = array('');
						$_ = new StdClass();
						if ($pricing->type != "Donation")
							$_->p = ((isset($pricing->onsale)
										&& $pricing->onsale == "on")?
											(float)$pricing->promoprice:
											(float)$pricing->price);
						$_->i = ($pricing->inventory == "on");
						$_->s = ($pricing->inventory == "on")?$pricing->stock:false;
						$_->tax = ($pricing->tax == "on");
						$_->t = $pricing->type;
						$pricekeys[$key] = $_;
					}

					ob_start();
?><?php if (!empty($options['defaults'])): ?>
	sjss.opdef = true;
<?php endif; ?>
<?php if (!empty($options['required'])): ?>
	sjss.opreq = "<?php echo $options['required']; ?>";
<?php endif; ?>
	pricetags[<?php echo $this->id; ?>] = <?php echo json_encode($pricekeys); ?>;
	new ProductOptionsMenus('select<?php if (!empty($Ecart->Category->slug)) echo ".category-".$Ecart->Category->slug; ?>.product<?php echo $this->id; ?>.options',{<?php if ($options['disabled'] == "hide") echo "disabled:false,"; ?><?php if ($options['pricetags'] == "hide") echo "pricetags:false,"; ?><?php if (!empty($taxrate)) echo "taxrate:$taxrate,"?>prices:pricetags[<?php echo $this->id; ?>]});
<?php
					$script = ob_get_contents();
					ob_end_clean();

					add_storefrontjs($script);

					foreach ($menuoptions as $id => $menu) {
						if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
						if (value_is_true($options['label'])) $string .= '<label for="options-'.$menu['id'].'">'.$menu['name'].'</label> '."\n";
						$category_class = isset($Ecart->Category->slug)?'category-'.$Ecart->Category->slug:'';
						$string .= '<select name="products['.$this->id.'][options][]" class="'.$category_class.' product'.$this->id.' options" id="options-'.$menu['id'].'">';
						if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";
						foreach ($menu['options'] as $key => $option)
							$string .= '<option value="'.$option['id'].'">'.$option['name'].'</option>'."\n";

						$string .= '</select>';
					}
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";
				}

				return $string;
				break;
			case "variation":
				$variation = current($this->prices);

				if (!isset($options['taxes'])) $options['taxes'] = null;
				else $options['taxes'] = value_is_true($options['taxes']);
				$taxrate = ecart_taxrate($options['taxes'],$variation->tax,$this);

				$weightunit = (isset($options['units']) && !value_is_true($options['units']) ) ? false : $Ecart->Settings->get('weight_unit');

				$string = '';
				if (array_key_exists('id',$options)) $string .= $variation->id;
				if (array_key_exists('label',$options)) $string .= $variation->label;
				if (array_key_exists('type',$options)) $string .= $variation->type;
				if (array_key_exists('sku',$options)) $string .= $variation->sku;
				if (array_key_exists('price',$options)) $string .= money($variation->price+($variation->price*$taxrate));
				if (array_key_exists('saleprice',$options)) {
					if (isset($options['promos']) && !value_is_true($options['promos'])) {
						$string .= money($variation->saleprice+($variation->saleprice*$taxrate));
					} else $string .= money($variation->promoprice+($variation->promoprice*$taxrate));
				}
				if (array_key_exists('stock',$options)) $string .= $variation->stock;
				if (array_key_exists('weight',$options)) $string .= round($variation->weight, 3) . ($weightunit ? " $weightunit" : false);
				if (array_key_exists('shipfee',$options)) $string .= money(floatvalue($variation->shipfee));
				if (array_key_exists('sale',$options)) return ($variation->sale == "on");
				if (array_key_exists('shipping',$options)) return ($variation->shipping == "on");
				if (array_key_exists('tax',$options)) return ($variation->tax == "on");
				if (array_key_exists('inventory',$options)) return ($variation->inventory == "on");
				return $string;
				break;
			case "has-addons":
				return ($this->addons == "on" && !empty($this->options['a'])); break;
				break;
			case "addons":

				$string = "";

				if (!isset($options['mode'])) {
					if (!$this->priceloop) {
						reset($this->prices);
						$this->priceloop = true;
					} else next($this->prices);
					$thisprice = current($this->prices);

					if ($thisprice && $thisprice->type == "N/A")
						next($this->prices);

					if ($thisprice && $thisprice->context != "addon")
						next($this->prices);

					if (current($this->prices) !== false) return true;
					else {
						$this->priceloop = false;
						return false;
					}
					return true;
				}

				if ($this->outofstock) return false; // Completely out of stock, hide menus
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$defaults = array(
					'defaults' => '',
					'disabled' => 'show',
					'before_menu' => '',
					'after_menu' => ''
					);

				$options = array_merge($defaults,$options);

				if (!isset($options['label'])) $options['label'] = "on";
				if (!isset($options['required'])) $options['required'] = __('You must select the options for this item before you can add it to your shopping cart.','Ecart');
				if ($options['mode'] == "single") {
					if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
					if (value_is_true($options['label'])) $string .= '<label for="product-options'.$this->id.'">'. __('Options').': </label> '."\n";

					$string .= '<select name="products['.$this->id.'][price]" id="product-options'.$this->id.'">';
					if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";

					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "addon") continue;

						if (isset($options['taxes']))
							$taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax,$this);
						else $taxrate = ecart_taxrate(null,$pricetag->tax,$this);
						$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
						$disabled = ($pricetag->inventory == "on" && $pricetag->stock == 0)?' disabled="disabled"':'';

						$price = '  ('.money($currently).')';
						if ($pricetag->type != "N/A")
							$string .= '<option value="'.$pricetag->id.'"'.$disabled.'>'.$pricetag->label.$price.'</option>'."\n";
					}

					$string .= '</select>';
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				} else {
					if (!isset($this->options['a'])) return;

					$taxrate = ecart_taxrate($options['taxes'],true,$this);

					// Index addon prices by option
					$pricing = array();
					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "addon") continue;
						$pricing[$pricetag->options] = $pricetag;
					}

					foreach ($this->options['a'] as $id => $menu) {
						if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
						if (value_is_true($options['label'])) $string .= '<label for="options-'.$menu['id'].'">'.$menu['name'].'</label> '."\n";
						$category_class = isset($Ecart->Category->slug)?'category-'.$Ecart->Category->slug:'';
						$string .= '<select name="products['.$this->id.'][addons][]" class="'.$category_class.' product'.$this->id.' addons" id="addons-'.$menu['id'].'">';
						if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";
						foreach ($menu['options'] as $key => $option) {

							$pricetag = $pricing[$option['id']];

							if (isset($options['taxes']))
								$taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax,$this);
							else $taxrate = ecart_taxrate(null,$pricetag->tax,$this);

							$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
							if ($taxrate > 0) $currently = $currently+($currently*$taxrate);
							$string .= '<option value="'.$option['id'].'">'.$option['name'].' (+'.money($currently).')</option>'."\n";
						}

						$string .= '</select>';
					}
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				}

				return $string;
				break;

			case "donation":
			case "amount":
			case "quantity":
				if ($this->outofstock) return false;

				$inputs = array('text','menu');
				$defaults = array(
					'value' => 1,
					'input' => 'text', // accepts text,menu
					'labelpos' => 'before',
					'label' => '',
					'options' => '1-15,20,25,30,40,50,75,100',
					'size' => 3
				);
				$options = array_merge($defaults,$options);
				$_options = $options;
				extract($options);

				unset($_options['label']); // Interferes with the text input value when passed to inputattrs()
				$labeling = '<label for="quantity-'.$this->id.'">'.$label.'</label>';

				if (!isset($this->_prices_loop)) reset($this->prices);
				$variation = current($this->prices);
				$_ = array();

				if ("before" == $labelpos) $_[] = $labeling;
				if ("menu" == $input) {
					if ($this->inventory && $this->max['stock'] == 0) return "";

					if (strpos($options,",") !== false) $options = explode(",",$options);
					else $options = array($options);

					$qtys = array();
					foreach ((array)$options as $v) {
						if (strpos($v,"-") !== false) {
							$v = explode("-",$v);
							if ($v[0] >= $v[1]) $qtys[] = $v[0];
							else for ($i = $v[0]; $i < $v[1]+1; $i++) $qtys[] = $i;
						} else $qtys[] = $v;
					}
					$_[] = '<select name="products['.$this->id.'][quantity]" id="quantity-'.$this->id.'">';
					foreach ($qtys as $qty) {
						$amount = $qty;
						$selection = (isset($this->quantity))?$this->quantity:1;
						if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
							if ($variation->donation['min'] == "on" && $amount < $variation->price) continue;
							$amount = money($amount);
							$selection = $variation->price;
						} else {
							if ($this->inventory && $amount > $this->max['stock']) continue;
						}
						$selected = ($qty==$selection)?' selected="selected"':'';
						$_[] = '<option'.$selected.' value="'.$qty.'">'.$amount.'</option>';
					}
					$_[] = '</select>';
				} elseif (valid_input($input)) {
					if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
						if ($variation->donation['min']) $_options['value'] = $variation->price;
						$_options['class'] .= " currency";
					}
					$_[] = '<input type="'.$input.'" name="products['.$this->id.'][quantity]" id="quantity-'.$this->id.'"'.inputattrs($_options).' />';
				}

				if ("after" == $labelpos) $_[] = $labeling;
				return join("\n",$_);
				break;
			case "input":
				if (!isset($options['type']) ||
					($options['type'] != "menu" && $options['type'] != "textarea" && !valid_input($options['type']))) $options['type'] = "text";
				if (!isset($options['name'])) return "";
				if ($options['type'] == "menu") {
					$result = '<select name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.inputattrs($options,$select_attrs).'>';
					if (isset($options['options']))
						$menuoptions = preg_split('/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/',$options['options']);
					if (is_array($menuoptions)) {
						foreach($menuoptions as $option) {
							$selected = "";
							$option = trim($option,'"');
							if (isset($options['default']) && $options['default'] == $option)
								$selected = ' selected="selected"';
							$result .= '<option value="'.$option.'"'.$selected.'>'.$option.'</option>';
						}
					}
					$result .= '</select>';
				} elseif ($options['type'] == "textarea") {
					if (isset($options['cols'])) $cols = ' cols="'.$options['cols'].'"';
					if (isset($options['rows'])) $rows = ' rows="'.$options['rows'].'"';
					$result .= '<textarea name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.$cols.$rows.inputattrs($options).'>'.$options['value'].'</textarea>';
				} else {
					$result = '<input type="'.$options['type'].'" name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.inputattrs($options).' />';
				}

				return $result;
				break;
			case "outofstock":
				if ($this->outofstock) {
					$label = isset($options['label'])?$options['label']:$Ecart->Settings->get('outofstock_text');
					$string = '<span class="outofstock">'.$label.'</span>';
					return $string;
				} else return false;
				break;
			case "buynow":
				if (!isset($options['value'])) $options['value'] = __("Buy Now","Ecart");
			case "addtocart":

				if (!isset($options['class'])) $options['class'] = "addtocart";
				else $options['class'] .= " addtocart";
				if (!isset($options['value'])) $options['value'] = __("Add to Cart","Ecart");
				$string = "";

				if ($this->outofstock) {
					$string .= '<span class="outofstock">'.$Ecart->Settings->get('outofstock_text').'</span>';
					return $string;
				}
				if (isset($options['redirect']) && !isset($options['ajax']))
					$string .= '<input type="hidden" name="redirect" value="'.$options['redirect'].'" />';

				$string .= '<input type="hidden" name="products['.$this->id.'][product]" value="'.$this->id.'" />';

				if (!empty($this->prices[0]) && $this->prices[0]->type != "N/A")
					$string .= '<input type="hidden" name="products['.$this->id.'][price]" value="'.$this->prices[0]->id.'" />';

				if (!empty($Ecart->Category)) {
					if (ECART_PRETTYURLS)
						$string .= '<input type="hidden" name="products['.$this->id.'][category]" value="'.$Ecart->Category->uri.'" />';
					else
						$string .= '<input type="hidden" name="products['.$this->id.'][category]" value="'.((!empty($Ecart->Category->id))?$Ecart->Category->id:$Ecart->Category->slug).'" />';
				}

				$string .= '<input type="hidden" name="cart" value="add" />';
				if (isset($options['ajax'])) {
					if ($options['ajax'] == "html") $options['class'] .= ' ajax-html';
					else $options['class'] .= " ajax";
					$string .= '<input type="hidden" name="ajax" value="true" />';
					$string .= '<input type="button" name="addtocart" '.inputattrs($options).' />';
				} else {
					$string .= '<input type="submit" name="addtocart" '.inputattrs($options).' />';
				}

				return $string;
		}


	}
Пример #25
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save FAQ") {
             /* Save FAQ
              */
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_faq_form($_POST);
             } else {
                 if (isset($_POST["id"]) === false) {
                     /* Create FAQ
                      */
                     if ($this->model->create_faq($_POST) == false) {
                         $this->output->add_message("Error while creating F.A.Q.");
                         $this->show_faq_form($_POST);
                     } else {
                         $this->user->log_action("faq %d created", $this->db->last_insert_id);
                         $this->show_faq_overview();
                     }
                 } else {
                     /* Update FAQ
                      */
                     if ($this->model->update_faq($_POST) == false) {
                         $this->output->add_message("Error while updating F.A.Q.");
                         $this->show_faq_form($_POST);
                     } else {
                         $this->user->log_action("faq %d updated", $_POST["id"]);
                         $this->show_faq_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete FAQ") {
                 /* Delete FAQ
                  */
                 if ($this->model->delete_faq($_POST["id"]) == false) {
                     $this->output->add_message("Error while deleting F.A.Q.");
                     $this->show_faq_form($_POST);
                 } else {
                     $this->user->log_action("faq %d deleted", $_POST["id"]);
                     $this->show_faq_overview();
                 }
             } else {
                 $this->show_faq_overview();
             }
         }
     } else {
         if ($this->page->pathinfo[2] == "new") {
             /* New FAQ
              */
             $faq = array("section" => 1);
             $this->show_faq_form($faq);
         } else {
             if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Edit existing FAQ
                  */
                 if (($faq = $this->model->get_faq($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "FAQ not found.");
                 } else {
                     $this->show_faq_form($faq);
                 }
             } else {
                 /* FAQ overview
                  */
                 $this->show_faq_overview();
             }
         }
     }
 }
Пример #26
0
 public function execute()
 {
     $months_of_year = config_array(MONTHS_OF_YEAR);
     $this->output->title = "Weblog";
     $this->output->description = "Weblog";
     $this->output->keywords = "weblog";
     $this->output->add_alternate("Weblog", "application/rss+xml", "/weblog.xml");
     $this->url = array("url" => $this->page->page);
     /* Sidebar
      */
     $this->output->open_tag("sidebar");
     /* Tags
      */
     if (($tags = $this->model->get_all_tags()) != false) {
         $this->output->open_tag("tags");
         foreach ($tags as $tag) {
             $this->output->add_tag("tag", $tag["tag"], array("id" => $tag["id"]));
         }
         $this->output->close_tag();
     }
     /* Years
      */
     if (($years = $this->model->get_years()) != false) {
         $this->output->open_tag("years");
         foreach ($years as $year) {
             $this->output->add_tag("year", $year["year"]);
         }
         $this->output->close_tag();
     }
     /* Periods
      */
     if (($periods = $this->model->get_periods()) != false) {
         $this->output->open_tag("periods");
         foreach ($periods as $period) {
             $link = array("link" => $period["year"] . "/" . $period["month"]);
             $text = $months_of_year[$period["month"] - 1] . " " . $period["year"];
             $this->output->add_tag("period", $text, $link);
         }
         $this->output->close_tag();
     }
     $this->output->close_tag();
     if ($this->page->type == "xml") {
         /* RSS feed
          */
         $rss = new RSS($this->output);
         if ($rss->fetch_from_cache("weblog_rss") == false) {
             $rss->title = $this->settings->head_title . " weblog";
             $rss->description = $this->settings->head_description;
             if (($weblogs = $this->model->get_last_weblogs($this->settings->weblog_rss_page_size)) != false) {
                 foreach ($weblogs as $weblog) {
                     $link = "/weblog/" . $weblog["id"];
                     $rss->add_item($weblog["title"], $weblog["content"], $link, $weblog["timestamp"]);
                 }
             }
             $rss->to_output();
         }
     } else {
         if ($_SERVER["REQUEST_METHOD"] == "POST") {
             /* Comment submits
              */
             if ($this->model->comment_oke($_POST) == false) {
                 $this->show_weblog($_POST["weblog_id"]);
                 $this->show_comment($_POST);
             } else {
                 if ($this->model->add_comment($_POST) == false) {
                     $this->output->add_message("Error while adding comment.");
                     $this->show_weblog($_POST["weblog_id"]);
                     $this->show_comment($_POST);
                 } else {
                     $this->output->add_tag("result", "Comment has been added.", array("url" => $this->page->page . "/" . $_POST["weblog_id"]));
                 }
             }
         } else {
             if ($this->page->pathinfo[1] == "tag" && valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Tagged weblogs
                  */
                 if (($tag = $this->model->get_tag($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "Unknown tag", $this->url);
                 } else {
                     if (($weblogs = $this->model->get_tagged_weblogs($this->page->pathinfo[2])) === false) {
                         $this->output->add_tag("result", "Error fetching tags", $this->url);
                     } else {
                         $this->output->title = "Tag " . $tag . " - Weblog";
                         $this->output->open_tag("list", array("label" => "Weblogs with '" . $tag . "' tag"));
                         foreach ($weblogs as $weblog) {
                             $this->output->record($weblog, "weblog");
                         }
                         $this->output->close_tag();
                     }
                 }
             } else {
                 if ($this->page->pathinfo[1] == "period" && valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY) && valid_input($this->page->pathinfo[3], VALIDATE_NUMBERS)) {
                     /* Weblogs of certain period
                      */
                     if (($weblogs = $this->model->get_weblogs_of_period($this->page->pathinfo[2], $this->page->pathinfo[3])) === false) {
                         $this->output->add_tag("result", "Error fetching weblogs", $this->url);
                     } else {
                         if ($this->page->pathinfo[3] == null) {
                             $this->output->title = "Year " . $this->page->pathinfo[2] . " - Weblog";
                         } else {
                             $month = $months_of_year[$this->page->pathinfo[3] - 1];
                             $this->output->title = $month . " " . $this->page->pathinfo[2] . " - Weblog";
                         }
                         $month = 0;
                         $count = count($weblogs);
                         for ($i = 0; $i < $count; $i++) {
                             if ((int) $weblogs[$i]["month"] != $month) {
                                 if ($month != 0) {
                                     $this->output->close_tag();
                                 }
                                 if ($i < $count) {
                                     $label = $months_of_year[$weblogs[$i]["month"] - 1] . " " . $this->page->pathinfo[2];
                                     $this->output->open_tag("list", array("label" => $label));
                                 }
                             }
                             $this->output->record($weblogs[$i], "weblog");
                             $month = (int) $weblogs[$i]["month"];
                         }
                         if ($month != 0) {
                             $this->output->close_tag();
                         }
                     }
                 } else {
                     if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                         /* Show weblog
                          */
                         $this->show_weblog($this->page->pathinfo[1]);
                         if ($this->user->logged_in) {
                             $this->show_comment(array("author" => $this->user->fullname));
                         }
                     } else {
                         /* Show last weblogs
                          */
                         $this->show_last_weblogs();
                     }
                 }
             }
         }
     }
 }
Пример #27
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         /* Remove weblog RSS from cache
          */
         $this->output->remove_from_cache("weblog_rss");
         if ($_POST["submit_button"] == "Save weblog") {
             /* Save weblog
              */
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_weblog_form($_POST);
             } else {
                 if (isset($_POST["id"]) == false) {
                     /* Create weblog
                      */
                     if ($this->model->create_weblog($_POST) == false) {
                         $this->output->add_message("Database error while creating weblog.");
                         $this->show_weblog_form($_POST);
                     } else {
                         $this->user->log_action("weblog %d created", $this->db->last_insert_id);
                         $this->show_weblog_overview();
                     }
                 } else {
                     /* Update weblog
                      */
                     if ($this->model->update_weblog($_POST) == false) {
                         $this->output->add_message("Database error while updating weblog.");
                         $this->show_weblog_form($_POST);
                     } else {
                         $this->user->log_action("weblog %d updated", $_POST["id"]);
                         $this->show_weblog_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete weblog") {
                 /* Delete weblog
                  */
                 if ($this->model->delete_weblog($_POST["id"]) == false) {
                     $this->output->add_tag("result", "Error while deleting weblog.");
                 } else {
                     $this->user->log_action("weblog %d deleted", $_POST["id"]);
                     $this->show_weblog_overview();
                 }
             } else {
                 $this->show_weblog_overview();
             }
         }
     } else {
         if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
             /* Show weblog
              */
             if (($weblog = $this->model->get_weblog($this->page->pathinfo[2])) == false) {
                 $this->output->add_tag("result", "Weblog not found.");
             } else {
                 $this->show_weblog_form($weblog);
             }
         } else {
             if ($this->page->pathinfo[2] == "new") {
                 /* New weblog
                  */
                 $weblog = array("visible" => 1);
                 $this->show_weblog_form($weblog);
             } else {
                 /* Show weblog overview
                  */
                 $this->show_weblog_overview();
             }
         }
     }
 }
Пример #28
0
 public function execute()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if ($_POST["submit_button"] == "Save page") {
             /* Save page
              */
             $_POST["url"] = "/" . trim($_POST["url"], "/ ");
             if ($this->model->save_oke($_POST) == false) {
                 $this->show_page_form($_POST);
             } else {
                 if (isset($_POST["id"]) == false) {
                     /* Create page
                      */
                     if ($this->model->create_page($_POST) === false) {
                         $this->output->add_message("Database error while creating page.");
                         $this->show_page_form($_POST);
                     } else {
                         $this->user->log_action("page %s created", $_POST["url"]);
                         $this->show_page_overview();
                     }
                 } else {
                     /* Update user
                      */
                     $url = $this->model->get_url($_POST["id"]);
                     if ($this->model->update_page($_POST, $_POST["id"]) === false) {
                         $this->output->add_message("Database error while updating page.");
                         $this->show_page_form($_POST);
                     } else {
                         if ($_POST["url"] == $url) {
                             $name = $_POST["url"];
                         } else {
                             $name = sprintf("%s -> %s", $url, $_POST["url"]);
                         }
                         $this->user->log_action("page %s updated", $name);
                         list($webserver) = explode(" ", $_SERVER["SERVER_SOFTWARE"], 2);
                         if ($this->settings->hiawatha_cache_enabled && $webserver == "Hiawatha") {
                             if ($_POST["url"] == "/" . $this->settings->start_page) {
                                 header("X-Hiawatha-Cache-Remove: all");
                             } else {
                                 header("X-Hiawatha-Cache-Remove: " . $_POST["url"]);
                             }
                         }
                         $this->show_page_overview();
                     }
                 }
             }
         } else {
             if ($_POST["submit_button"] == "Delete page") {
                 /* Delete page
                  */
                 $url = $this->model->get_url($_POST["id"]);
                 if ($this->model->delete_page($_POST["id"]) == false) {
                     $this->output->add_tag("result", "Database error while deleting page.");
                 } else {
                     $this->user->log_action("page %s deleted", $url);
                     $this->show_page_overview();
                 }
             } else {
                 if ($_POST["submit_button"] == "Clear Hiawatha cache") {
                     header("X-Hiawatha-Cache-Remove: all");
                     $this->output->add_system_message("Hiawatha webserver cache cleared.");
                     $this->show_page_overview();
                 } else {
                     $this->show_page_overview();
                 }
             }
         }
     } else {
         if ($this->page->pathinfo[2] == "new") {
             /* Show the user webform
              */
             $page = array("url" => "/", "language" => $this->settings->default_language, "layout" => null, "visible" => 1, "roles" => array());
             $this->show_page_form($page);
         } else {
             if (valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
                 /* Show the user webform
                  */
                 if (($page = $this->model->get_page($this->page->pathinfo[2])) == false) {
                     $this->output->add_tag("result", "Page not found.");
                 } else {
                     $this->show_page_form($page);
                 }
             } else {
                 /* Show a list of all users
                  */
                 $this->show_page_overview();
             }
         }
     }
 }
Пример #29
0
 public function save_oke($user)
 {
     $result = true;
     if (isset($user["id"])) {
         if (($current = $this->get_user($user["id"])) == false) {
             $this->output->add_message("User not found.");
             return false;
         }
         /* Non-admins cannot edit admins
          */
         if ($this->user->is_admin == false) {
             if ($this->access_allowed_for_non_admin($current) == false) {
                 $this->output->add_message("You are not allowed to edit this user.");
                 $this->user->log_action("unauthorized update attempt of user %d", $user["id"]);
                 return false;
             }
         }
         /* Username changed need password to be reset
          */
         if ($user["username"] != $current["username"] && $user["password"] == "") {
             $this->output->add_message("Username change needs password to be re-entered.");
             $result = false;
         }
     }
     /* Check username
      */
     if ($user["username"] == "" || $user["fullname"] == "") {
         $this->output->add_message("The username and full name cannot be empty.");
         $result = false;
     } else {
         if (valid_input($user["username"], VALIDATE_LETTERS . VALIDATE_NUMBERS) == false) {
             $this->output->add_message("Invalid characters in username.");
             $result = false;
         } else {
             if (($check = $this->db->entry("users", $user["username"], "username")) != false) {
                 if ($check["id"] != $user["id"]) {
                     $this->output->add_message("Username already exists.");
                     $result = false;
                 }
             }
         }
     }
     /* Check password
      */
     if (isset($user["id"]) == false) {
         if ($user["password"] == "" && is_false($user["generate"])) {
             $this->output->add_message("Fill in the password or let Banshee generate one.");
             $result = false;
         }
     }
     /* Check e-mail
      */
     if (valid_email($user["email"]) == false) {
         $this->output->add_message("Invalid e-mail address.");
         $result = false;
     } else {
         if (($check = $this->db->entry("users", $user["email"], "email")) != false) {
             if ($check["id"] != $user["id"]) {
                 $this->output->add_message("E-mail address already exists.");
                 $result = false;
             }
         }
     }
     /* Check certificate serial
      */
     if (valid_input($user["cert_serial"], VALIDATE_NUMBERS) == false) {
         $this->output->add_message("The certificate serial must be a number.");
         $result = false;
     }
     return $result;
 }
Пример #30
0
 public function delete_oke($item_id)
 {
     if ($this->allow_delete == false) {
         $this->output->add_message("You are not allowed to delete items.");
         return false;
     }
     if (valid_input($item_id, VALIDATE_NUMBERS, VALIDATE_NONEMPTY) == false) {
         $this->output->add_message("Invalid item id.");
         return false;
     }
     return true;
 }