Ugh, tired.

git-svn-id: http://svn.cleancode.org/svn/pickles@135 4d10bc64-7434-11dc-a737-d2d0f8310089
This commit is contained in:
Josh Sherman 2009-06-15 02:24:48 +00:00
parent a157d4962b
commit efb5b6a677
19 changed files with 305 additions and 87 deletions

View file

@ -182,8 +182,6 @@ class Controller extends Object {
$display_type = $module['object']->getDisplay();
}
//var_dump($display_type);
// Creates a new viewer object
$display_class = 'Display_' . $display_type;
$display = new $display_class($config, $error);
@ -206,14 +204,6 @@ class Controller extends Object {
if ($module['object']->getCacheID()) {
$display->cache_id = $module['object']->getCacheID();
}
/*
if (isset($mailer->message)) {
$status = $mailer->send();
$module['object']->setPublic('type', $status['type']);
$module['object']->setPublic('message', $status['message']);
}
*/
}
// If the loaded module has a name, use it to override

View file

@ -94,7 +94,7 @@ class Display_Smarty extends Display_Common {
$template = SITE_PATH . '../templates/' . $this->module_filename . '.tpl';
if (!file_exists($template)) {
$shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_filname == false ? $this->module_filename : $this->shared_filename) . '.tpl';
$shared_template = PICKLES_PATH . 'common/templates/' . ($this->shared_module_filename == false ? $this->module_filename : $this->shared_module_filename) . '.tpl';
if (file_exists($shared_template)) {
$template = $shared_template;

View file

@ -18,7 +18,7 @@
* <http://www.gnu.org/licenses/>.
*
* @author Joshua John Sherman <josh@phpwithpickles.org>
* @copyright Copyright 2007, 2008 Joshua John Sherman
* @copyright Copyright 2007, 2008, 2009 Joshua John Sherman
* @link http://phpwithpickles.org
* @license http://www.gnu.org/copyleft/lesser.html
* @package PICKLES

View file

@ -0,0 +1,18 @@
<?php
class post_delete extends Module {
public function __default() {
if (isset($_REQUEST['id']) && trim($_REQUEST['id']) != '') {
$this->db->delete('posts', array('post_id' => $_REQUEST['id']));
header('Location: /');
}
else {
// @todo Throw error
}
}
}
?>

View file

@ -0,0 +1,13 @@
<?php
class post_edit extends post_new {
public function __default() {
if (isset($_REQUEST['id'])) {
$this->setPublic('post', $this->db->getRow('SELECT post_id, title, body, posted_at, hidden FROM posts WHERE post_id = "' . $_REQUEST['id'] . '";'));
}
}
}
?>

View file

@ -0,0 +1,11 @@
<?php
class post_new extends Module {
public function __construct(Config $config, DB $db, Mailer $mailer, Error $error) {
parent::__construct($config, $db, $mailer, $error);
$this->template = 'post/edit';
}
}
?>

View file

@ -0,0 +1,52 @@
<?php
class post_save extends post_edit {
public function __default() {
parent::__default();
$existing = $this->public['post'];
if ($_REQUEST['id'] != '' && $_REQUEST['id'] != $existing['post_id']) {
// @todo Throw error
}
else {
// Prepends days 1-9 with a 0 since html_select_date doesn't do so
if ($_REQUEST['Date_Day'] < 10) {
$_REQUEST['Date_Day'] = '0' . $_REQUEST['Date_Day'];
}
// Converts the hour to military time
if ($_REQUEST['Time_Meridian'] == 'pm' && $_REQUEST['Time_Hour'] < 12) {
$_REQUEST['Time_Hour'] += 12;
}
else if ($_REQUEST['Time_Meridian'] == 'am' && $_REQUEST['Time_Hour'] == 12) {
$_REQUEST['Time_Hour'] = '00';
}
// Contructs the posted at timestamp
$_REQUEST['posted_at'] = $_REQUEST['Date_Year'] . '-' . $_REQUEST['Date_Month'] . '-' . $_REQUEST['Date_Day'] . ' ' . $_REQUEST['Time_Hour'] . ':' . $_REQUEST['Time_Minute'] . ':' . $_REQUEST['Time_Second'];
// Assembles the data array
$data = array(
'title' => $_REQUEST['title'],
'body' => $_REQUEST['body'],
'posted_at' => $_REQUEST['posted_at'],
'hidden' => $_REQUEST['hidden']
);
if ($_REQUEST['id'] != '') {
if ($_REQUEST['title'] != $existing['title'] || $_REQUEST['body'] != $existing['body'] || $_REQUEST['posted_at'] != $posted_at) {
$this->db->update('posts', $data, array('post_id' => $_REQUEST['id']));
}
}
else {
$this->db->insert('posts', $data);
}
}
header('Location: /weblog');
}
}
?>

66
common/modules/posts.php Executable file
View file

@ -0,0 +1,66 @@
<?php
class posts extends Module {
public function __default() {
// Sets up the pagination variables (5 per page)
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
$offset = $page > 1 ? ($page - 1) * 5 : 0;
// Sets up the first (current) and last page numbers
$this->setPublic('page', $page);
$this->setPublic('last', $this->db->getField('SELECT COUNT(post_id) / 5 FROM posts ' . $where . ';'));
// Constructions additional WHERE logic for non logged in users
if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) {
$where = '';
$this->setPublic('admin', true);
}
else {
$where = 'WHERE posted_at <= NOW() AND hidden IS FALSE';
$this->setPublic('admin', false);
}
// Pulls the posts
$posts = $this->db->getArray('
SELECT p.post_id, p.title, p.body, p.tags, p.posted_at, p.hidden, u.name AS posted_by, u.email, COUNT(c.comment_id) AS comments
FROM posts AS p
LEFT JOIN users AS u ON u.user_id = p.user_id
LEFT JOIN comments AS c ON c.post_id = p.post_id AND c.approved IS TRUE
' . $where . '
GROUP BY p.post_id
ORDER BY posted_at DESC
LIMIT ' . $offset . ', 5;
');
// Pulls all of the tags
$all_tags = array();
$tags = $this->db->getArray('SELECT tag_id, name FROM tags;');
foreach ($tags as $tag) {
$all_tags[$tag['tag_id']] = $tag['name'];
}
// Loops through the posts and translates the tags
foreach ($posts as $post_id => $post) {
$post_tags = array();
if (strpos($post['tags'], ',') !== false) {
$tags = explode(',', $post['tags']);
if (is_array($tags)) {
foreach ($tags as $tag_id) {
$post_tags[] = $all_tags[$tag_id];
}
}
}
$posts[$post_id]['tags'] = $post_tags;
}
// Passes the posts to the display class
$this->setPublic('posts', $posts);
}
}
?>

View file

@ -3,12 +3,18 @@
class store_admin_orders extends store_admin {
public function __default() {
$where = null;
if (isset($_REQUEST['filter'])) {
$where = 'WHERE LOWER(os.name) = LOWER("' . str_replace('-', ' ', $_REQUEST['filter']) . '")';
}
else {
$where = null;
// Validates the filter
$status = $this->db->getRow('SELECT id, name FROM order_statuses WHERE LOWER(name) = LOWER("' . str_replace('-', ' ', $_REQUEST['filter']) . '")');
if ($status != null) {
$where = 'WHERE osu.status_id = "' . $status['id'] . '"';
$this->setPublic('filter', $status['name']);
}
}
$sql = '

View file

@ -0,0 +1,16 @@
<?php
class store_admin_products extends store_admin {
public function __default() {
$sql = '
SELECT DISTINCT id, sku, name, price, in_stock
FROM products
ORDER BY sequence DESC;
';
$this->setPublic('products', $this->db->getArray($sql));
}
}
?>

31
common/templates/post/edit.tpl Executable file
View file

@ -0,0 +1,31 @@
<script type="text/javascript" src="/static/contrib/fckeditor/fckeditor.js"></script>
<form method="post" action="/post/save">
<dl class="post">
<dt>Title:</dt>
<dd><input type="text" name="title" value="{$module.post.title}" /></dd>
<dt>Body:</dt>
<dd><textarea name="body" rows="5" class="form_input">{$module.post.body}</textarea></dd>
<dt>Date:</dt>
<dd>{html_select_date time=$module.post.posted_at}</dd>
<dt>Time:</dt>
<dd>{html_select_time time=$module.post.posted_at use_24_hours=false}</dd>
<dt>Hidden:</dt>
<dd>
<input type="radio" name="hidden" value="1" {if $module.post.hidden == 1} checked="checked"{/if} /> Yes
<input type="radio" name="hidden" value="0" {if $module.post.hidden != 1} checked="checked"{/if} /> No
</dd>
</dl>
<input type="hidden" name="id" value="{$module.post.post_id}" />
<input type="reset" value="Reset" /> <input type="submit" value="Save Post" />
</form>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('body');
oFCKeditor.BasePath = "/static/contrib/fckeditor/";
oFCKeditor.ToolbarSet = "ThatGirlJen";
oFCKeditor.Width = "500px";
oFCKeditor.Height = "250px";
oFCKeditor.ReplaceTextarea();
console.debug(oFCKeditor);
</script>

View file

@ -0,0 +1,18 @@
{if is_array($module.posts)}
{foreach from=$module.posts item=post}
<h2>{$post.title}</h2>
<div class="post-info">Posted by {mailto text=$post.posted_by address=$post.email encode='javascript'} on {$post.posted_at|date_format:"%A, %B %e, %Y"}</div>
<div class="post-body">{$post.body}</div>
<div class="tags">
{if is_array($post.tags)}
{foreach from=$post.tags item=tag name=tags}{if !$smarty.foreach.tags.first}, {/if}<a href="/category/{$tag}" onclick="alert('Not yet... soon.'); return false;">{$tag}</a>{/foreach}
{/if}
</div>
<div class="comments"><a href="#" onclick="alert('Not yet... soon.'); return false;">{$post.comments} Comment{if $post.comments != 1}s{/if}</a></div>
{/foreach}
{if $module.page > 1}<div style="float: left"><a href="/{$module_name.0}/{$module.page-1}">&laquo; Newer</a></div>{/if}
{if $module.page < $module.last}<div style="float: right"><a href="/{$module_name.0}/{$module.page+1}">Older &raquo;</a></div>{/if}
<br style="clear: both" />
{else}
<em>There are currently no posts.</em>
{/if}

View file

@ -24,7 +24,7 @@
<td>
<a href="/store/admin/affiliates/edit/{$affiliate.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Affiliate" title="Edit Affiliate" /></a>
<a href="/store/admin/affiliates/pay/{$affiliate.id}"><img src="/static/contrib/silk/icons/money.png" alt="Pay Affiliate" title="Pay Affiliate" /></a>
<a href="/store/admin/affiliates/delete/{$affiliate.id}" onclick="return confirm('Are you sure you want to delete {$affiliate.first_name} {$affiliate.last_name}?')"><img src="/static/contrib/silk/icons/cross.png" alt="Delete Affiliate" title="Delete Affiliate" /></a>
<a href="/store/admin/affiliates/delete/{$affiliate.id}" onclick="return confirm('Are you sure you want to delete {$affiliate.first_name} {$affiliate.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Affiliate" title="Delete Affiliate" /></a>
</td>
</tr>
{/foreach}

View file

@ -8,7 +8,7 @@
<th class="left">Name</th>
<th>Sort</th>
<th>Products</th>
<th>Hidden</th>
<th>Visible</th>
<th></th>
</tr>
{foreach from=$module.categories item=category}
@ -16,10 +16,10 @@
<td class="left bold">{$category.name}</td>
<td class="bold">{$category.weight}</td>
<td>{$category.product_count}</td>
<td>{if $category.visible == 'N'}Y{/if}</td>
<td><img src="/static/contrib/silk/icons/{if $category.visible == 'Y'}tick{else}cross{/if}.png" /></td>
<td>
<a href="/store/admin/categories/edit/{$category.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Discount" title="Edit Discount" /></a>
<a href="/store/admin/categories/delete/{$category.id}" onclick="return confirm('Are you sure you want to delete {$category.first_name} {$category.last_name}?')"><img src="/static/contrib/silk/icons/cross.png" alt="Delete Discount" title="Delete Discount" /></a>
<a href="/store/admin/categories/delete/{$category.id}" onclick="return confirm('Are you sure you want to delete {$category.first_name} {$category.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Discount" title="Delete Discount" /></a>
</td>
</tr>
{if isset($category.children)}
@ -28,10 +28,10 @@
<td class="left">&nbsp;&nbsp;&nbsp;&nbsp;{$child.name}</td>
<td>{$child.weight}</td>
<td>{$child.product_count}</td>
<td>{if $child.visible == 'N'}Y{/if}</td>
<td><img src="/static/contrib/silk/icons/{if $child.visible == 'Y'}tick{else}cross{/if}.png" /></td>
<td>
<a href="/store/admin/categories/edit/{$child.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Discount" title="Edit Discount" /></a>
<a href="/store/admin/categories/delete/{$child.id}" onclick="return confirm('Are you sure you want to delete {$child.first_name} {$child.last_name}?')"><img src="/static/contrib/silk/icons/cross.png" alt="Delete Discount" title="Delete Discount" /></a>
<a href="/store/admin/categories/delete/{$child.id}" onclick="return confirm('Are you sure you want to delete {$child.first_name} {$child.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Discount" title="Delete Discount" /></a>
</td>
</tr>
{/foreach}

View file

@ -19,7 +19,7 @@
<td>{$customer.order_count}</td>
<td>
<a href="/store/admin/customers/edit/{$customer.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Customer" title="Edit Customer" /></a>
<a href="/store/admin/customers/delete/{$customer.id}" onclick="return confirm('Are you sure you want to delete {$customer.first_name} {$customer.last_name}?')"><img src="/static/contrib/silk/icons/cross.png" alt="Delete Customer" title="Delete Customer" /></a>
<a href="/store/admin/customers/delete/{$customer.id}" onclick="return confirm('Are you sure you want to delete {$customer.first_name} {$customer.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Customer" title="Delete Customer" /></a>
</td>
</tr>
{/foreach}

View file

@ -25,7 +25,7 @@
<td>{if $discount.valid_through == null}<em>Never</em>{else}{$discount.valid_through}{/if}</td>
<td>
<a href="/store/admin/discounts/edit/{$discount.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Discount" title="Edit Discount" /></a>
<a href="/store/admin/discounts/delete/{$discount.id}" onclick="return confirm('Are you sure you want to delete {$discount.first_name} {$discount.last_name}?')"><img src="/static/contrib/silk/icons/cross.png" alt="Delete Discount" title="Delete Discount" /></a>
<a href="/store/admin/discounts/delete/{$discount.id}" onclick="return confirm('Are you sure you want to delete {$discount.first_name} {$discount.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Discount" title="Delete Discount" /></a>
</td>
</tr>
{/foreach}

View file

@ -3,59 +3,6 @@
{literal}
<script type="text/javascript">
// @todo Move this to an external file so that logic isn't in the template
function copyAddress(that) {
if (that.checked == true) {
// Copy the values
document.getElementById('payee_company').value = document.getElementById('contact_company').value;
document.getElementById('payee_first_name').value = document.getElementById('contact_first_name').value;
document.getElementById('payee_last_name').value = document.getElementById('contact_last_name').value;
document.getElementById('payee_address1').value = document.getElementById('contact_address1').value;
document.getElementById('payee_address2').value = document.getElementById('contact_address2').value;
document.getElementById('payee_city').value = document.getElementById('contact_city').value;
document.getElementById('payee_state').value = document.getElementById('contact_state').value;
document.getElementById('payee_zip_code').value = document.getElementById('contact_zip_code').value;
document.getElementById('payee_phone').value = document.getElementById('contact_phone').value;
document.getElementById('payee_fax').value = document.getElementById('contact_fax').value;
// Disable the fields
document.getElementById('payee_company').disabled = true;
document.getElementById('payee_first_name').disabled = true;
document.getElementById('payee_last_name').disabled = true;
document.getElementById('payee_address1').disabled = true;
document.getElementById('payee_address2').disabled = true;
document.getElementById('payee_city').disabled = true;
document.getElementById('payee_state').disabled = true;
document.getElementById('payee_zip_code').disabled = true;
document.getElementById('payee_phone').disabled = true;
document.getElementById('payee_fax').disabled = true;
}
else {
// Clear the values
document.getElementById('payee_company').value = '';
document.getElementById('payee_first_name').value = '';
document.getElementById('payee_last_name').value = '';
document.getElementById('payee_address1').value = '';
document.getElementById('payee_address2').value = '';
document.getElementById('payee_city').value = '';
document.getElementById('payee_state').value = '';
document.getElementById('payee_zip_code').value = '';
document.getElementById('payee_phone').value = '';
document.getElementById('payee_fax').value = '';
// Enable the fields
document.getElementById('payee_company').disabled = false;
document.getElementById('payee_first_name').disabled = false;
document.getElementById('payee_last_name').disabled = false;
document.getElementById('payee_address1').disabled = false;
document.getElementById('payee_address2').disabled = false;
document.getElementById('payee_city').disabled = false;
document.getElementById('payee_state').disabled = false;
document.getElementById('payee_zip_code').disabled = false;
document.getElementById('payee_phone').disabled = false;
document.getElementById('payee_fax').disabled = false;
}
}
function clearForm(responseObject, responseElement) {
if (responseObject != null) {
switch (responseObject.status) {
@ -108,7 +55,7 @@
}
dl {
margin-top: 5px;
width: 400px;
width: 650px;
}
dl dt {
float: left;
@ -118,22 +65,43 @@
}
dl dd {
float: left;
width: 240px;
width: 510px;
padding: 2px;
}
dl dd input {
margin: 2px;
width: 250px;
}
dl dd textarea {
width: 500px;
height: 50px;
}
</style>
{/literal}
<h3>{if isset($module.discount.id)}Update{else}Add{/if} Discount</h3>
<form method="post" action="/store/admin/discounts/save">
<div class="right" style="margin-bottom: -10px;">
Same as contact information?
<input id="payee_same_as_contact" type="checkbox" onclick="copyAddress(this);" name="payee_same_as_contact" style="margin-top: -2px" />
</div>
<div class="float-left">
<dl>
<dt><span class="pink">*</span>Name:</dt>
<dd>
<input type="text" name="name" id="name" style="margin-right: 53px" />
Coupon Code:
<input type="text" name="name" id="name" style="width: 100px;" />
</dd>
<dt>Description:</dt>
<dd><textarea name="description" id="description"></textarea></dd>
<dt>Valid From:</dt>
<dd>
{html_select_date prefix='valid_from_'}
to
{html_select_date prefix='valid_to_'}
</dd>
</dl>
</div>
<br style="clear: left" />
<!--div>
<b>Contact Information:</b>
<dl>
<dt>Company:</dt>
@ -218,7 +186,7 @@
<div class="center">
{if isset($module.discount.id)}<input type="hidden" name="id" value="{$module.discount.id}" />{/if}
<input type="reset" value="Reset Form" /><input type="button" value="Store Information" onclick="ajaxRequest(this.parentNode.parentNode{if !isset($module.discount.id)}, 'clearForm'{/if}); return false;" />
</div>
</div-->
</form>
<script type="text/javascript">
document.getElementById('contact_state').value = "{$module.discount.contact_state}";

View file

@ -1,4 +1,4 @@
<h3>Orders</h3>
<h3>{if $module.filter}{$module.filter} {/if}Orders</h3>
{if is_array($module.orders)}
<table style="width: 100%">
<tr>

View file

@ -0,0 +1,29 @@
<h3>Products</h3>
<div class="float-right">
<img src="/static/contrib/silk/icons/add.png" style="margin: 0 5px -4px 0;"/><a href="/store/admin/products/edit">Add New Product</a>
</div>
{if is_array($module.products)}
<table style="width: 100%">
<tr>
<th class="left">SKU</th>
<th class="left">Name</th>
<th>Photo</th>
<th class="left">Price</th>
<th>In Stock?</th>
<th></th>
</tr>
{foreach from=$module.products item=product}
<tr class="left">
<td>{$product.sku}</td>
<td>{$product.name}</td>
<td class="center"><img src="/static/contrib/silk/icons/{if $category.visible == 'Y'}tick{else}cross{/if}.png" /></td>
<td>${$product.price}</td>
<td class="center"><img src="/static/contrib/silk/icons/{if $product.in_stock == 'Y'}tick{else}cross{/if}.png" /></td>
<td>
<a href="/store/admin/products/edit/{$product.id}"><img src="/static/contrib/silk/icons/pencil.png" alt="Edit Product" title="Edit Product" /></a>
<a href="/store/admin/products/delete/{$product.id}" onclick="return confirm('Are you sure you want to delete {$product.first_name} {$product.last_name}?')"><img src="/static/contrib/silk/icons/delete.png" alt="Delete Product" title="Delete Product" /></a>
</td>
</tr>
{/foreach}
</table>
{/if}