1
0

Initial commit of basket module.

This commit is contained in:
Ben Smith 2009-08-30 19:10:45 +12:00
parent 29c82a7149
commit e9a46ca3cb
22 changed files with 1452 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Configure_Controller extends Controller
{
/**
* the index page of the user homes admin
*/
public function index()
{
$form = basket::get_configure_form();
if (request::method() == "post") {
// @todo move the "save" part of this into a separate controller function
access::verify_csrf();
if ($form->validate()) {
basket::extractForm($form);
message::success(t("Basket Module Configured!"));
//url::redirect("admin/recaptcha");
}
}
else
{
basket::populateForm($form);
}
$view = new Admin_View("admin.html");
$view->content = new View("admin_configure.html");
$view->content->form = $form;
//$view->content->products = ORM::factory("product")->orderby("name")->find_all();
print $view;
}
}

View File

@ -0,0 +1,151 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Product_Lines_Controller extends Controller
{
/**
* the index page of the user homes admin
*/
public function index()
{
$view = new Admin_View("admin.html");
$view->content = new View("admin_product_lines.html");
$view->content->products = ORM::factory("product")->orderby("name")->find_all();
print $view;
}
public function add_product_form() {
print product::get_add_form_admin();
}
public function add_product() {
access::verify_csrf();
$form = product::get_add_form_admin();
$valid = $form->validate();
$name = $form->add_product->inputs["name"]->value;
$product = ORM::factory("product")->where("name", $name)->find();
if ($product->loaded) {
$form->add_product->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
if ($valid) {
$product = product::create(
$name, $form->add_product->cost->value, $form->add_product->description->value);
$product->save();
message::success(t("Created product %product_name", array(
"product_name" => p::clean($product->name))));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error",
"form" => $form->__toString()));
}
}
public function delete_product_form($id) {
$product = ORM::factory("product", $id);
if (!$product->loaded) {
kohana::show_404();
}
print product::get_delete_form_admin($product);
}
public function delete_product($id) {
access::verify_csrf();
if ($id == user::active()->id || $id == user::guest()->id) {
access::forbidden();
}
$product = ORM::factory("product", $id);
if (!$product->loaded) {
kohana::show_404();
}
$form = user::get_delete_form_admin($product);
if($form->validate()) {
$name = $product->name;
$product->delete();
} else {
print json_encode(array("result" => "error",
"form" => $form->__toString()));
}
$message = t("Deleted user %product_name", array("product_name" => p::clean($name)));
log::success("user", $message);
message::success($message);
print json_encode(array("result" => "success"));
}
public function edit_product($id) {
access::verify_csrf();
$product = ORM::factory("product", $id);
if (!$product->loaded) {
kohana::show_404();
}
$form = product::get_edit_form_admin($product);
$valid = $form->validate();
if ($valid) {
$new_name = $form->edit_product->inputs["name"]->value;
if ($new_name != $product->name &&
ORM::factory("product")
->where("name", $new_name)
->where("id !=", $product->id)
->find()
->loaded) {
$form->edit_product->inputs["name"]->add_error("in_use", 1);
$valid = false;
} else {
$product->name = $new_name;
}
}
if ($valid) {
$product->cost = $form->edit_product->cost->value;
$product->description = $form->edit_product->description->value;
$product->save();
message::success(t("Changed product %product_name",
array("product_name" => p::clean($product->name))));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error",
"form" => $form->__toString()));
}
}
public function edit_product_form($id) {
$product = ORM::factory("product", $id);
if (!$product->loaded) {
kohana::show_404();
}
$form = product::get_edit_form_admin($product);
print $form;
}
}

View File

@ -0,0 +1,222 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Basket_Controller extends Controller {
public function view_basket() {
$template = new Theme_View("page.html", "basket");
$view = new View("view_basket.html");
$view->basket = Session_Basket::get();
$template->content = $view;
print $template;
}
private function getCheckoutForm(){
$form = new Forge("basket/confirm", "", "post", array("id" => "checkout", "name" =>"checkout"));
$group = $form->group("contact")->label(t("Contact Details"));
$group->input("fullname")->label(t("Name"))->id("fullname");
$group->input("house")->label(t("House Number / Name"))->id("house");
$group->input("street")->label(t("Street"))->id("street");
$group->input("suburb")->label(t("Suburb"))->id("suburb");
$group->input("town")->label(t("Town or City"))->id("town");
$group->input("postcode")->label(t("Postcode"))->id("postcode");
$group->input("email")->label(t("E-Mail Address"))->id("email");
$group->input("phone")->label(t("Telephone Number"))->id("phone");
return $form;
}
public function checkout () {
$template = new Theme_View("page.html", "basket");
$view = new View("checkout.html");
$basket = Session_Basket::get();
$form = self::getCheckoutForm();
$form->contact->fullname->value($basket->name);
$form->contact->house->value($basket->house);
$form->contact->street->value($basket->street);
$form->contact->suburb->value($basket->suburb);
$form->contact->town->value($basket->town);
$form->contact->postcode->value($basket->postcode);
$form->contact->email->value($basket->email);
$form->contact->phone->value($basket->phone);
$view->form = $form;
$template->content = $view;
print $template;
}
public function confirm () {
access::verify_csrf();
$form = $this->getCheckoutForm();
$valid = $form->validate();
if ($valid){
$basket = Session_Basket::get();
$basket->name = $form->contact->fullname->value;
$basket->house = $form->contact->house->value;
$basket->street = $form->contact->street->value;
$basket->suburb = $form->contact->suburb->value;
$basket->town = $form->contact->town->value;
$basket->postcode = $form->contact->postcode->value;
$basket->email = $form->contact->email->value;
$basket->phone = $form->contact->phone->value;
$template = new Theme_View("page.html", "basket");
$form = new Forge("basket/complete", "", "post", array("id" => "confirm", "name" =>"confirm"));
$view = new View("confirm_order.html");
$view->basket = $basket;
$template->content = $view;
$view->form = $form;
print $template;
}
else
{
die("Invalid confirmation!");
}
}
public function complete () {
access::verify_csrf();
$basket = Session_Basket::get();
//$admin_address = basket::getEmailAddress();
$admin_email = "Order for :
".$basket->name."
".$basket->house."
".$basket->street."
".$basket->suburb."
".$basket->town."
".$basket->postcode."
".$basket->email."
".$basket->phone."
Placed at ".date("d F Y - H:i" ,time())."
Total Owed ".$basket->cost()." in ".basket::getCurrency()."
Items Ordered:
";
// create the order items
foreach ($basket->contents as $basket_item){
$item = $basket_item->getItem();
$prod = ORM::factory("product", $basket_item->product);
$admin_email = $admin_email."
".$item->title." - ".$item->url()."
".$prod->name." - ".$prod->description."
".$basket_item->quantity." @ ".$prod->cost."
";
}
$from = "From: ".basket::getEmailAddress();
mail(basket::getEmailAddress(), "Order from ".$basket->name, $admin_email, $from);
$basket->clear();
$template = new Theme_View("page.html", "basket");
$view = new View("order_complete.html");
$template->content = $view;
print $template;
}
private function getAddToBasketForm(){
$form = new Forge("basket/add_to_basket", "", "post", array("id" => "gAddToBasketForm"));
$group = $form->group("add_to_basket")->label(t("Add To Basket"));
$group->hidden("id");
$group->dropdown("product")
->label(t("Product"))
->options(product::getProductArray());
$group->input("quantity")->label(t("Quantity"))->id("gQuantity");
$group->submit("")->value(t("Add"));
//$group->submit("proceedToCheckout")->value(t("Proceed To Checkout"));
return $form;
}
public function add_to_basket(){
access::verify_csrf();
$form = self::getAddToBasketForm();
$valid = $form->validate();
if ($valid){
$basket = Session_Basket::getOrCreate();
$basket->add(
$form->add_to_basket->id->value,
$form->add_to_basket->product->value,
$form->add_to_basket->quantity->value);
print json_encode(array("result" => "success"));
}
else
{
log_error("invalid form!");
}
}
public function add_to_basket_ajax($id) {
$view = new View("add_to_basket_ajax.html");
// get the item to add
$item = ORM::factory("item", $id);
if (!$item->loaded)
{
//TODO
die("Not loaded id");
}
// get the basket to add to
$form = self::getAddToBasketForm();
$form->add_to_basket->id->value($id);
$form->add_to_basket->quantity->value(1);
$view->form = $form;
$view->item = $item;
print $view;
}
public function remove_item($key) {
$basket = Session_Basket::getOrCreate();
$basket->remove($key);
url::redirect("basket/view_basket");
}
}

View File

@ -0,0 +1,5 @@
#basket {float:right;}
#add_to_basket {float:right}
#basketForm {max-width:200px}
#basketThumb {float:left; padding:10px 10px 0 0;}
#basketThumb img{max-width:100px;}

View File

@ -0,0 +1,156 @@
<?php
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class basket_Core {
static $currencies = array(
"AUD" => "Australian Dollars",
"CAD" => "Canadian Dollars",
"EUR" => "Euros",
"GBP" => "Pounds Sterling",
"JPY" => "Yen",
"USD" => "U.S. Dollars",
"NZD" => "New Zealand Dollar",
"CHF" => "Swiss Franc",
"HKD" => "Hong Kong Dollar",
"SGD" => "Singapore Dollar",
"SEK" => "Swedish Krona",
"DKK" => "Danish Krone",
"PLN" => "Polish Zloty",
"NOK" => "Norwegian Krone",
"HUF" => "Hungarian Forint",
"CZK" => "Czech Koruna",
"ILS" => "Israeli Shekel",
"MXN" => "Mexican Peso");
static $format= array(
"AUD" => "&#36;",
"CAD" => "&#36;",
"EUR" => "&#8364;",
"GBP" => "&#163;",
"JPY" => "&#165;",
"USD" => "&#36;",
"NZD" => "&#36;",
"CHF" => "",
"HKD" => "&#36;",
"SGD" => "&#36;",
"SEK" => "",
"DKK" => "",
"PLN" => "",
"NOK" => "",
"HUF" => "",
"CZK" => "",
"ILS" => "",
"MXN" => "");
static function get_configure_form() {
$form = new Forge("admin/configure", "", "post", array("id" => "gConfigureForm"));
$group = $form->group("configure")->label(t("Configure Basket"));
$group->input("email")->label(t("Order Email Address"))->id("gOrderEmailAddress");
$group->checkbox("paypal")->label(t("Use Paypal"))->id("gPaypal");
$group->input("paypal_account")->label(t("Paypal Account"))->id("gPaypalAddress");
$group->dropdown("currency")
->label(t("Currency"))
->options(self::$currencies);
$group->submit("")->value(t("Save"));
return $form;
}
static function populateForm($form){
$form->configure->email->value(basket::getEmailAddress());
$form->configure->paypal->checked(basket::isPaypal());
$form->configure->paypal_account->value(basket::getPaypalAccount());
$form->configure->currency->selected(basket::getCurrency());
}
static function extractForm($form){
$email = $form->configure->email->value;
$isPaypal = $form->configure->paypal->value;
$paypal_account = $form->configure->paypal_account->value;
$currency = $form->configure->currency->selected;
basket::setEmailAddress($email);
basket::setPaypal($isPaypal);
basket::setPaypalAccount($paypal_account);
basket::setCurrency($currency);
}
static function getEmailAddress(){
return module::get_var("basket","email");
}
static function isPaypal(){
return module::get_var("basket","paypal");
}
static function getPaypalAccount(){
return module::get_var("basket","paypal_account");
}
static function getCurrency(){
$cur = module::get_var("basket","currency");
if (!isset($cur))
{
$cur = "USD";
}
return $cur;
}
static function formatMoney($money){
return self::$format[self::getCurrency()].number_format($money);
}
static function setEmailAddress($email){
module::set_var("basket","email",$email);
}
static function setPaypal($paypal){
module::set_var("basket","paypal",$paypal);
}
static function setPaypalAccount($paypal_account){
module::set_var("basket","paypal_account",$paypal_account);
}
static function setCurrency($currency){
module::set_var("basket","currency",$currency);
}
static function generatePaypalForm($session_basket){
$form = "
<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"paypal_form\">
<input type=\"hidden\" name=\"cmd\" value=\"_cart\"/>
<input type=\"hidden\" name=\"upload\" value=\"1\"/>
<input type=\"hidden\" name=\"currency_code\" value=\"".self::getCurrency()."\">
<input type=\"hidden\" name=\"business\" value=\"".self::getPaypalAccount()."\"/>";
$id = 1;
foreach ($session_basket->contents as $key => $basket_item){
$form = $form."
<input type=\"hidden\" name=\"item_name_$id\" value=\"".$basket_item->getCode()."\"/>
<input type=\"hidden\" name=\"amount_$id\" value=\"$basket_item->cost_per\"/>
<input type=\"hidden\" name=\"quantity_$id\" value=\"$basket_item->quantity\"/>";
$id++;
}
$form = $form."</form>";
return $form;
}
}

View File

@ -0,0 +1,43 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class basket_event_Core{
/**
* adds the shopping basket administration controls to the admin menu
*/
static function admin_menu($menu, $theme){
$menu->add_after("users_groups",
$basket_menu = Menu::factory("submenu")
->id("basket_menu")
->label(t("Basket")));
$basket_menu->append(
Menu::factory("link")
->id("configure")
->label(t("Configure"))
->url(url::site("admin/configure")));
$basket_menu->append(
Menu::factory("link")
->id("product_line")
->label(t("Product Lines"))
->url(url::site("admin/product_lines")));
}
}

View File

@ -0,0 +1,93 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class basket_installer
{
static function install(){
module::set_version("basket", 1);
}
static function activate() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {products} (
`id` int(9) NOT NULL auto_increment,
`name` TEXT NOT NULL,
`cost` INTEGER(9) default 0,
`description` varchar(1024),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
/*
$db->query("CREATE TABLE IF NOT EXISTS {orders} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(1024),
`house` varchar(255),
`street` varchar(255),
`suburb` varchar(255),
`town` varchar(255),
`postcode` varchar(255),
`email` varchar(255),
`phone` varchar(255),
`status` char(1),
`activity_time` int(9),
`created` int(9),
`total` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {order_details} (
`id` int(9) NOT NULL auto_increment,
`order_id` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
`product_name` TEXT NOT NULL,
`product_cost` INTEGER(9) default 0,
`product_description` varchar(1024),
`quantity` INTEGER(9) default 1,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {order_histories} (
`id` int(9) NOT NULL auto_increment,
`order_id` int(9) NOT NULL,
`status_from` char(1),
`status_to` char(1),
`public` boolean,
`date` int(9),
`notes` TEXT default null,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
*/
product::create("4x6",5,"4\"x6\" print");
product::create("8x10",25,"8\"x10\" print");
product::create("8x12",30,"8\"x12\" print");
}
static function deactivate(){
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {products}");
//$db->query("DROP TABLE IF EXISTS {orders}");
//$db->query("DROP TABLE IF EXISTS {order_details}");
//$db->query("DROP TABLE IF EXISTS {order_histories}");
}
}

View File

@ -0,0 +1,46 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class basket_theme_Core {
static function head($theme) {
$theme->css("basket.css");
}
static function header_top($theme) {
$view = new View("basket.html");
$view->basket = Session_Basket::get();
return $view->render();
}
static function admin_head($theme) {
if (strpos(Router::$current_uri, "admin/product_lines") !== false) {
$theme->script("lib/gallery.panel.js");
}
}
static function photo_top($theme)
{
$view = new View("add_to_basket.html");
$view->item = $theme->item();
return $view->render();
}
}

View File

@ -0,0 +1,91 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class product_Core {
static function get_add_form_admin() {
$form = new Forge("admin/product_lines/add_product", "", "post", array("id" => "gAddProductForm"));
$group = $form->group("add_product")->label(t("Add Product"));
$group->input("name")->label(t("Name"))->id("gProductName")
->error_messages("in_use", t("There is already a product with that name"));
$group->input("cost")->label(t("Cost"))->id("gCost");
$group->input("description")->label(t("Description"))->id("gDescription");
$group->submit("")->value(t("Add Product"));
$product = ORM::factory("product");
$form->add_rules_from($product);
return $form;
}
static function get_edit_form_admin($product) {
$form = new Forge("admin/product_lines/edit_product/$product->id", "", "post",
array("id" => "gEditProductForm"));
$group = $form->group("edit_product")->label(t("Edit Product"));
$group->input("name")->label(t("Name"))->id("gProductName")->value($product->name);
$group->inputs["name"]->error_messages(
"in_use", t("There is already a product with that name"));
$group->input("cost")->label(t("Cost"))->id("gCost")->value($product->cost);
$group->input("description")->label(t("Description"))->id("gDescription")->
value($product->description);
$group->submit("")->value(t("Modify Product"));
$form->add_rules_from($product);
return $form;
}
static function get_delete_form_admin($product) {
$form = new Forge("admin/product_lines/delete_product/$product->id", "", "post",
array("id" => "gDeleteProductForm"));
$group = $form->group("delete_product")->label(
t("Are you sure you want to delete product %name?", array("name" => $product->name)));
$group->submit("")->value(t("Delete product %name", array("name" => $product->name)));
return $form;
}
/**
* Create a new product
*
* @param string $name
* @param string $full_name
* @param string $password
* @return User_Model
*/
static function create($name, $cost, $description) {
$product = ORM::factory("product")->where("name", $name)->find();
if ($product->loaded) {
throw new Exception("@todo USER_ALREADY_EXISTS $name");
}
$product->name = $name;
$product->cost = $cost;
$product->description = $description;
$product->save();
return $product;
}
static function getProductArray(){
$products = ORM::factory("product")->find_all();
foreach ($products as $product){
$producta[$product->id] = $product->description." (".basket::formatMoney($product->cost).")";
}
return $producta;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

View File

@ -0,0 +1,151 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class basket_item
{
public $product;
public $item;
public $quantity;
public $cost = 0;
public $cost_per = 0;
public $items;
public function __construct($aProduct, $aItem, $aQuantity){
// TODO check individual product.
$this->product = $aProduct;
$this->item = $aItem;
$this->quantity = $aQuantity;
$this->calculate_cost();
}
private function calculate_cost(){
$prod = ORM::factory("product", $this->product);
$this->cost = $prod->cost * $this->quantity;
$this->cost_per = $prod->cost;
}
public function add($quantity){
$this->quantity += $quantity;
$this->calculate_cost();
}
public function size(){
return $this->quantity;
}
public function getItem(){
$photo = ORM::factory("item", $this->item);
return $photo;
}
public function product_description(){
$prod = ORM::factory("product", $this->product);
return $prod->description;
}
public function getCode(){
$photo = ORM::factory("item", $this->item);
$prod = ORM::factory("product", $this->product);
return $photo->id." - ".$photo->title." - ".$prod->name;
}
}
class Session_Basket_Core {
public $contents = array();
public $name = "";
public $house = "";
public $street = "";
public $suburb = "";
public $town = "";
public $postcode = "";
public $email = "";
public $phone = "";
public function clear(){
if (isset($this->contents)){
foreach ($this->contents as $key => $item){
unset($this->contents[$key]);
}
}
}
private function create_key($product, $id){
return "$product _ $id";
}
public function size(){
$size = 0;
if (isset($this->contents)){
foreach ($this->contents as $product => $basket_item){
$size += $basket_item->size();
}
}
return $size;
}
public function add($id, $product, $quantity){
$key = $this->create_key($product, $id);
if (isset($this->contents[$key])){
$this->contents[$key]->add($id, $quantity);
}
else {
$this->contents[$key] = new basket_item($product, $id, $quantity);
}
}
public function remove($key){
unset($this->contents[$key]);
}
public function cost(){
$cost = 0;
if (isset($this->contents)){
foreach ($this->contents as $product => $basket_item){
$cost += $basket_item->cost;
}
}
return $cost;
}
public static function get(){
return Session::instance()->get("basket");
}
public static function getOrCreate(){
$session = Session::instance();
$basket = $session->get("basket");
if (!$basket)
{
$basket = new Session_Basket();
$session->set("basket", $basket);
}
return $basket;
}
}

View File

@ -0,0 +1,24 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Product_Model extends ORM {
var $rules = array(
"name" => "length[1,32]",
"description" => "length[0,255]");
}

View File

@ -0,0 +1,3 @@
name = "Shopping Basket"
description = "Provides a simple shopping basket and checkout with paypal integration"
version = 1

View File

@ -0,0 +1,8 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="add_to_basket">
<a href="<?= url::site("basket/add_to_basket_ajax/$item->id") ?>"
title="<?= t("Add To Basket") ?>"
class="gDialogLink">
Add To Basket</a>
</div>

View File

@ -0,0 +1,9 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="gAddToBasket">
<div id="basketThumb">
<img src="<?= $item->thumb_url()?>" title="<?= $item->title?>" alt="<?= $item->title?>" />
</div>
<div id="basketForm">
<?= $form ?>
</div>
</div>

View File

@ -0,0 +1,8 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="gAdminConfigure">
<h1> <?= t("Configure Shopping Basket") ?> </h1>
<p>
<?= t("Use this page to configure the shopping basket. If you have paypal you can use this to processs the final payments.") ?>
</p>
<?= $form ?>
</div>

View File

@ -0,0 +1,70 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<div class="gBlock">
<a href="<?= url::site("admin/product_lines/add_product_form") ?>"
class="gDialogLink gButtonLink right ui-icon-left ui-state-default ui-corner-all"
title="<?= t("Create a new Product") ?>">
<span class="ui-icon ui-icon-circle-plus"></span>
<?= t("Add a new Product") ?>
</a>
<h2>
<?= t("Product Lines") ?>
</h2>
<div class="gBlockContent">
<table id="gProductAdminList">
<tr>
<th><?= t("Name") ?></th>
<th><?= t("Cost") ?></th>
<th><?= t("Description") ?></th>
<th><?= t("Actions") ?></th>
</tr>
<? foreach ($products as $i => $product): ?>
<tr id="gProduct-<?= $product->id ?>" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
<td id="product-<?= $product->id ?>" class="core-info ">
<?= p::clean($product->name) ?>
</td>
<td>
<?= basket::formatMoney($product->cost) ?>
</td>
<td>
<?= p::clean($product->description) ?>
</td>
<td class="gActions">
<a href="<?= url::site("admin/product_lines/edit_product_form/$product->id") ?>"
open_text="<?= t("close") ?>"
class="gPanelLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a>
<a href="<?= url::site("admin/product_lines/delete_product_form/$product->id") ?>"
class="gDialogLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a>
</td>
</tr>
<? endforeach ?>
</table>
</div>
</div>

View File

@ -0,0 +1,35 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<div id="basket">
<? if ($theme->page_type != 'basket'): ?>
<? if ($basket): ?>
<a href="<?= url::site("basket/view_basket") ?>"
title="<?= t("View Basket") ?>">
<img src="<?= url::file("modules/basket/images/basket.png") ?>"><br/>
<?= $basket->size()?> items</a>
<? else: ?>
<a href="<?= url::site("basket/view_basket") ?>"
title="<?= t("View Basket") ?>">
<img src="<?= url::file("modules/basket/images/basket.png") ?>"><br/>
<?= t("Empty") ?></a>
<? endif ?>
<? endif ?>
</div>

View File

@ -0,0 +1,64 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<SCRIPT language="JavaScript">
function ive(s)
{
return (s.indexOf(".")>2)&&(s.indexOf("@")>0);
}
function se(v)
{
v.style.backgroundColor="#FAA";
}
function re(v)
{
v.style.backgroundColor="#FFF";
}
function ci(v)
{
if ((!v.value) || (v.value.length==0)) {se(v);return false;}
re(v);
return true;
}
function so(){
var p=true;
var d=document.checkout;
if(!ci(d.fullname)){p=false;}
if((!ci(d.email))||(!ive(d.email.value))){se(d.email);p=false;}
if(!ci(d.phone)){p=false;}
if (p)
{
d.submit();
}
}
</SCRIPT>
<div class="gBlock">
<?= $form ?>
<h2>Payment Details</h2>
<p>After you have confirmed the order we will get in contact with you to arrange payment.</p>
<a href="<?= url::site("basket/view_basket") ?>" class="left gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Basket") ?></a>
<a href="javascript: so()" class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Confirmation") ?></a>
</div>

View File

@ -0,0 +1,82 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<SCRIPT language="JavaScript">
function so(){document.confirm.submit();}
</SCRIPT>
<?= $form ?>
<div class="gBlock">
<h2>Basket Summary</h2>
<div class="gBlockContent">
<table id="gBasketList">
<tr>
<th><?= t("Name") ?></th>
<th><?= t("Product") ?></th>
<th><?= t("Quantity") ?></th>
<th><?= t("Cost") ?></th>
</tr>
<? foreach ($basket->contents as $key => $prod_details): ?>
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
<td id="item-<?= $prod_details->item ?>" class="core-info ">
<? $item = $prod_details->getItem(); ?>
<div>
<?= p::clean($item->title) ?>
</div>
</td>
<td>
<?= p::clean($prod_details->product_description()) ?>
</td>
<td>
<?= p::clean($prod_details->quantity) ?>
</td>
<td>
<?= basket::formatMoney($prod_details->cost) ?>
</td>
</tr>
<? endforeach ?>
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
<td></td><td></td><td>Total Cost</td><td><?= $basket->cost()?></td>
</tr>
</table>
</div>
<table>
<tr><td>
<h2>Delivery Address</h2>
<?= $basket->name ?><br/>
<?= $basket->house ?>,
<?= $basket->street ?><br/>
<?= $basket->suburb ?><br/>
<?= $basket->town ?><br/>
<?= $basket->postcode ?><br/>
</td>
<td>
<h2>Contact Details</h2>
E-mail : <?= $basket->email ?><br/>
Telephone : <?= $basket->phone ?>
</td></tr>
</table>
<a href="<?= url::site("basket/checkout") ?>" class="left gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-arrow-1-w"></span><?= t("Back to Checkout") ?></a>
<a href="javascript: so()" class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Confirm Order") ?></a>
</div>

View File

@ -0,0 +1,24 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<div class="gBlock">
<h2>Thankyou for your order</h2>
You will be contacted soon to arrange payment and delivery.
</div>

View File

@ -0,0 +1,112 @@
<?php defined("SYSPATH") or die("No direct script access.")
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<div class="gBlock">
<? if (basket::isPaypal()): ?>
<?= basket::generatePaypalForm($basket) ?>
<script language="JavaScript">
function co(){
var d=document.paypal_form.submit();
}</script>
<a href="javascript:co();"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay with Credit Card or Paypal") ?></a>
<a href="<?= url::site("basket/checkout") ?>"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay off line") ?></a>
<? else: ?>
<a href="<?= url::site("basket/checkout") ?>"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
<? endif; ?>
<h2>
<?= t("Shopping Basket") ?>
</h2>
<div class="gBlockContent">
<? if (isset($basket->contents ) && count($basket->contents) > 0): ?>
<table id="gBasketList">
<tr>
<th><?= t("Picture") ?></th>
<th><?= t("Product") ?></th>
<th><?= t("Quantity") ?></th>
<th><?= t("Cost") ?></th>
<th><?= t("Actions") ?></th>
</tr>
<? $total=0;?>
<? foreach ($basket->contents as $key => $prod_details): ?>
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
<td id="item-<?= $prod_details->item ?>" class="core-info ">
<? $item = $prod_details->getItem(); ?>
<div id="basketThumb">
<img src="<?= $item->thumb_url()?>" title="<?= $item->title?>" alt="<?= $item->title?>" />
</div>
</td>
<td>
<?= p::clean($prod_details->product_description()) ?>
</td>
<td>
<?= p::clean($prod_details->quantity) ?>
</td>
<td>
<? $total += $prod_details->cost?>
<?= basket::formatMoney($prod_details->cost) ?>
</td>
<td class="gActions">
<!-- a href="<?= url::site("admin/product_lines/edit_product_form/") ?>"
open_text="<?= t("close") ?>"
class="gPanelLink gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-pencil"></span><span class="gButtonText"><?= t("edit") ?></span></a-->
<a href="<?= url::site("basket/remove_item/$key") ?>"
class="gButtonLink ui-state-default ui-corner-all ui-icon-left">
<span class="ui-icon ui-icon-trash"></span><?= t("Remove") ?></a>
</td>
</tr>
<? endforeach ?>
<tr id="" class="<?= text::alternate("gOddRow", "gEvenRow") ?>">
<td></td><td></td><td>Total Cost</td><td><?= basket::formatMoney($total)?></td><td></td>
</tr>
</table>
<? else: ?>
Shopping Basket is Empty
<? endif; ?>
</div>
<? if (basket::isPaypal()): ?>
<a href="javascript:co();"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay with Credit Card or Paypal") ?></a>
<a href="<?= url::site("basket/checkout") ?>"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Pay off line") ?></a>
<? else: ?>
<a href="<?= url::site("basket/checkout") ?>"
class="right gButtonLink ui-state-default ui-corner-all ui-icon-right">
<span class="ui-icon ui-icon-arrow-1-e"></span><?= t("Proceed to Checkout") ?></a>
<? endif; ?>
</div>