From ebadf3e9611b64650885c52bdc2c484a4064c809 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Sat, 5 Nov 2011 22:03:08 +0000 Subject: [PATCH] // fix update view.tpl in AdminCustomerController and Added new helper : HelperView git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9908 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/themes/template/customers/view.tpl | 727 +++++++++--------- .../themes/template/helper/view/view.tpl | 43 ++ classes/AdminController.php | 25 +- classes/Helper.php | 1 - classes/HelperView.php | 62 ++ .../admin/AdminCustomersController.php | 32 +- 6 files changed, 504 insertions(+), 386 deletions(-) create mode 100644 admin-dev/themes/template/helper/view/view.tpl create mode 100644 classes/HelperView.php diff --git a/admin-dev/themes/template/customers/view.tpl b/admin-dev/themes/template/customers/view.tpl index 6b4606fca..c5f0fd34e 100644 --- a/admin-dev/themes/template/customers/view.tpl +++ b/admin-dev/themes/template/customers/view.tpl @@ -23,389 +23,394 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - - -
-
- - - -
- - {$customer->firstname} {$customer->lastname} - -
- {$customer->email} -

- {l s='ID:'} {$customer->id|string_format:"%06d"}
- {l s='Registration date:'} {$registration_date}
- {l s='Last visit:'} {if $customer_stats['last_visit']}{$last_visit}{else}{l s='never'}{/if}
- {if $count_better_customers != '-'}{l s='Rank: #'} {$count_better_customers}
{/if} - {if $shop_is_feature_active}{l s='Shop:'} {$name_shop}
{/if} -
- -
-
- - - -
- {l s='Newsletter:'} {if $customer->newsletter}{else}{/if}
- {l s='Opt-in:'} {if $customer->optin}{else}{/if}
- {l s='Age:'} {$customer_stats['age']} {if isset($customer->birthday['age'])}({$customer_birthday}){else}{l s='unknown'}{/if}

- {l s='Last update:'} {$last_update}
- {l s='Status:'} {if $customer->active}{else}{/if} - - {if $customer->isGuest()} -
- {l s='This customer is registered as'} {l s='guest'} - {if !$customer_exists} -
- -

- {l s='This feature generates a random password and sends an e-mail to the customer'} -
- {else} -
{l s='A registered customer account exists with the same email address'} - {/if} + }); + } + + +
+
+ + +
- {/if} -
- -
 
- -
- - {l s='Add a private note'} - -

{l s='This note will be displayed to all the employees but not to the customer.'}

-
-
- - -
-
- -
 
- - -

{l s='Messages'} ({count($messages)})

-{if count($messages)} - - - - - - - {foreach $messages AS $message} - - - - - - {/foreach} -
{l s='Status'}{l s='Message'}{l s='Sent on'}
{$message['status']} - - {$message['message']}... - - {$message['date_add']}
+ + {$customer->firstname} {$customer->lastname} + +
+ {$customer->email} +

+ {l s='ID:'} {$customer->id|string_format:"%06d"}
+ {l s='Registration date:'} {$registration_date}
+ {l s='Last visit:'} {if $customer_stats['last_visit']}{$last_visit}{else}{l s='never'}{/if}
+ {if $count_better_customers != '-'}{l s='Rank: #'} {$count_better_customers}
{/if} + {if $shop_is_feature_active}{l s='Shop:'} {$name_shop}
{/if} +
+ +
+
+ + + +
+ {l s='Newsletter:'} {if $customer->newsletter}{else}{/if}
+ {l s='Opt-in:'} {if $customer->optin}{else}{/if}
+ {l s='Age:'} {$customer_stats['age']} {if isset($customer->birthday['age'])}({$customer_birthday}){else}{l s='unknown'}{/if}

+ {l s='Last update:'} {$last_update}
+ {l s='Status:'} {if $customer->active}{else}{/if} + + {if $customer->isGuest()} +
+ {l s='This customer is registered as'} {l s='guest'} + {if !$customer_exists} +
+ +

+ {l s='This feature generates a random password and sends an e-mail to the customer'} +
+ {else} +
{l s='A registered customer account exists with the same email address'} + {/if} +
+ {/if} +
+
 
-{else} - {$customer->firstname} {$customer->lastname} {l s='has never contacted you'} -{/if} - -{* display hook specified to this page : AdminCustomers *} -{if $hook !== false} -
{$hook}
-{/if} - -
 
- -

{l s='Groups'} ({count($groups)})

-{if $groups AND count($groups)} - - - - - - - {foreach $groups AS $key => $group} - - - - - - {/foreach} -
{l s='ID'}{l s='Name'}{l s='Actions'}
{$group['id_group']}{$group['name']}
-{/if} -
 
- - -

{l s='Orders'} ({count($orders)})

-{if $orders AND count($orders)} - {assign var=count_ok value=count($orders_ok)} - {if $count_ok} -
-

- {l s='Valid orders:'} {$count_ok} {l s='for'} {$total_ok} -

- + +
+ + {l s='Add a private note'} + +

{l s='This note will be displayed to all the employees but not to the customer.'}

+
+
+ + + +
+ +
 
+ + +

{l s='Messages'} ({count($messages)})

+ {if count($messages)} +
+ + + + + + {foreach $messages AS $message} - - - - - - - + + + - {foreach $orders_ok AS $key => $order} - - - - - - - - - - {/foreach} -
{l s='Status'}{l s='Message'}{l s='Sent on'}
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='State'}{l s='Actions'}{$message['status']} + + {$message['message']}... + + {$message['date_add']}
{$order['id_order']}{$order['date_add']}{$order['nb_products']}{$order['total_paid_real']}{$order['payment']}{$order['order_state']}
-
- {/if} - {assign var=count_ko value=count($orders_ko)} - {if $count_ko} -
-

{l s='Invalid orders:'} {$count_ko}

- - - - - - - - - - - {foreach $orders_ko AS $key => $order} - - - - - - - - - - {/foreach} -
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='State'}{l s='Actions'}
{$order['id_order']}{$order['date_add']}{$order['nb_products']}{$order['total_paid_real']}{$order['payment']}{$order['order_state']}
-
+ {/foreach} +
 
+ {else} + {$customer->firstname} {$customer->lastname} {l s='has never contacted you'} {/if} -{else} - {$customer->firstname} {$customer->lastname} {l s='has not placed any orders yet'} -{/if} - -{if $products AND count($products)} -
 
-

{l s='Products'} ({count($products)})

- - - - - - - - {foreach $products AS $key => $product} - - - - - - - {/foreach} -
{l s='Date'}{l s='Name'}{l s='Quantity'}{l s='Actions'}
{$product['date_add']}{$product['product_name']}{$product['product_quantity']}
-{/if} -
 
- -

{l s='Addresses'} ({count($addresses)})

-{if count($addresses)} - - - - - - - - - - {foreach $addresses AS $key => $address} - - - - - - - - - {/foreach} -
{l s='Company'}{l s='Name'}{l s='Address'}{l s='Country'}{l s='Phone number(s)'}{l s='Actions'}
{if $address['company']}{$address['company']}{else}--{/if}{$address['firstname']} {$address['lastname']}{$address['address1']} {if $address['address2']}{$address['address2']}{/if} {$address['postcode']} {$address['city']}{$address['country']} - {if $address['phone']} - {$address['phone']} - {if $address['phone_mobile']}
{$address['phone_mobile']}{/if} - {else} - {if $address['phone_mobile']}
{$address['phone_mobile']}{else}--{/if} - {/if} -
- - -
-{else} - {$customer->firstname} {$customer->lastname} {l s='has not registered any addresses yet'} -{/if} - -
 
-

{l s='Discounts'} ({count($discounts)})

-{if count($discounts)} - - - - - - - - - - - {foreach $discounts AS $key => $discount} - - - - - - - - - - {/foreach} -
{l s='ID'}{l s='Code'}{l s='Type'}{l s='Value'}{l s='Qty available'}{l s='Status'}{l s='Actions'}
{$discount['id_discount']}{$discount['name']}{$discount['type']}{$discount['value']}{$discount['quantity_for_user']}{l s='Status'} - - -
-{else} - {$customer->firstname} {$customer->lastname} {l s='has no discount vouchers'}. -{/if} -
 
- -
-

{l s='Carts'} ({count($carts)})

- {if $carts AND count($carts)} + + {* display hook specified to this page : AdminCustomers *} + {if $hook !== false} +
{$hook}
+ {/if} + +
 
+ +

{l s='Groups'} ({count($groups)})

+ {if $groups AND count($groups)} - - - + - {foreach $carts AS $key => $cart} - - - - - - + {foreach $groups AS $key => $group} + + + + + + {/foreach} +
{l s='ID'}{l s='Date'}{l s='Total'}{l s='Carrier'}{l s='Name'} {l s='Actions'}
{$cart['id_cart']}{$cart['date_add']}{$cart['total_price']}{$cart['name']}
{$group['id_group']}{$group['name']}
+ {/if} +
 
+ + +

{l s='Orders'} ({count($orders)})

+ {if $orders AND count($orders)} + {assign var=count_ok value=count($orders_ok)} + {if $count_ok} +
+

+ {l s='Valid orders:'} {$count_ok} {l s='for'} {$total_ok} +

+ + + + + + + + + + + {foreach $orders_ok AS $key => $order} + + + + + + + + + + {/foreach} +
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='State'}{l s='Actions'}
{$order['id_order']}{$order['date_add']}{$order['nb_products']}{$order['total_paid_real']}{$order['payment']}{$order['order_state']}
+
+ {/if} + {assign var=count_ko value=count($orders_ko)} + {if $count_ko} +
+

{l s='Invalid orders:'} {$count_ko}

+ + + + + + + + + + + {foreach $orders_ko AS $key => $order} + + + + + + + + + + {/foreach} +
{l s='ID'}{l s='Date'}{l s='Products'}{l s='Total paid'}{l s='Payment'}{l s='State'}{l s='Actions'}
{$order['id_order']}{$order['date_add']}{$order['nb_products']}{$order['total_paid_real']}{$order['payment']}{$order['order_state']}
+
+
 
+ {/if} + {else} + {$customer->firstname} {$customer->lastname} {l s='has not placed any orders yet'} + {/if} + + {if $products AND count($products)} +
 
+

{l s='Products'} ({count($products)})

+ + + + + + + + {foreach $products AS $key => $product} + + + + + + + {/foreach} +
{l s='Date'}{l s='Name'}{l s='Quantity'}{l s='Actions'}
{$product['date_add']}{$product['product_name']}{$product['product_quantity']}
+ {/if} +
 
+ +

{l s='Addresses'} ({count($addresses)})

+ {if count($addresses)} + + + + + + + + + + {foreach $addresses AS $key => $address} + + + + + + + {/foreach}
{l s='Company'}{l s='Name'}{l s='Address'}{l s='Country'}{l s='Phone number(s)'}{l s='Actions'}
{if $address['company']}{$address['company']}{else}--{/if}{$address['firstname']} {$address['lastname']}{$address['address1']} {if $address['address2']}{$address['address2']}{/if} {$address['postcode']} {$address['city']}{$address['country']} + {if $address['phone']} + {$address['phone']} + {if $address['phone_mobile']}
{$address['phone_mobile']}{/if} + {else} + {if $address['phone_mobile']}
{$address['phone_mobile']}{else}--{/if} + {/if} +
+ + +
{else} - {l s='No cart available'}. + {$customer->firstname} {$customer->lastname} {l s='has not registered any addresses yet'} {/if} -
- -{if count($interested)} -
-

{l s='Products'} ({count($interested)})

+ +
 
+

{l s='Discounts'} ({count($discounts)})

+ {if count($discounts)} - {foreach $interested as $key => $p} - - - - + + + + + + + + + + {foreach $discounts AS $key => $discount} + + + + + + + + + + {/foreach} +
{$p['id']}{$p['name']}
{l s='ID'}{l s='Code'}{l s='Type'}{l s='Value'}{l s='Qty available'}{l s='Status'}{l s='Actions'}
{$discount['id_discount']}{$discount['name']}{$discount['type']}{$discount['value']}{$discount['quantity_for_user']}{l s='Status'} + + +
+ {else} + {$customer->firstname} {$customer->lastname} {l s='has no discount vouchers'}. + {/if} +
 
+ +
+

{l s='Carts'} ({count($carts)})

+ {if $carts AND count($carts)} + + + + + + + + + {foreach $carts AS $key => $cart} + + + + + + + + {/foreach} +
{l s='ID'}{l s='Date'}{l s='Total'}{l s='Carrier'}{l s='Actions'}
{$cart['id_cart']}{$cart['date_add']}{$cart['total_price']}{$cart['name']}
+ {else} + {l s='No cart available'}. + {/if} +
+ + {if count($interested)} +
+

{l s='Products'} ({count($interested)})

+ + {foreach $interested as $key => $p} + + + + + + {/foreach} +
{$p['id']}{$p['name']}
+
+ {/if} + +
 
+ + {* Last connections *} + {if count($connections)} +

{l s='Last connections'}

+ + + + + + + + + {foreach $connections as $connection} + + + + + + {/foreach}
{l s='Date'}{l s='Pages viewed'}{l s='Total time'}{l s='Origin'}{l s='IP Address'}
{$connection['date_add']}{$connection['pages']}{$connection['time']}{$connection['http_referer']}{$connection['ipaddress']}
-
-{/if} - -
 
- -{* Last connections *} -{if count($connections)} -

{l s='Last connections'}

- - - - - - - - - {foreach $connections as $connection} +
 
+ {/if} + + {if count($referrers)} +

{l s='Referrers'}

+
{l s='Date'}{l s='Pages viewed'}{l s='Total time'}{l s='Origin'}{l s='IP Address'}
- - - - - + + + {if $shop_is_feature_active}{/if} - {/foreach} -
{$connection['date_add']}{$connection['pages']}{$connection['time']}{$connection['http_referer']}{$connection['ipaddress']}{l s='Date'}{l s='Name'}{l s='Shop'}
-
 
-{/if} + {foreach $referrers as $referrer} + + {$referrer['date_add']} + {$referrer['name']} + {if $shop_is_feature_active}{$referrer['shop_name']}{/if} + + {/foreach} + +
 
+ {/if} +{/block} -{if count($referrers)} -

{l s='Referrers'}

- - - - - {if $shop_is_feature_active}{/if} - - {foreach $referrers as $referrer} - - - - {if $shop_is_feature_active}{/if} - - {/foreach} -
{l s='Date'}{l s='Name'}{l s='Shop'}
{$referrer['date_add']}{$referrer['name']}{$referrer['shop_name']}
-
 
-{/if} - {l s='Back to customer list'}
\ No newline at end of file diff --git a/admin-dev/themes/template/helper/view/view.tpl b/admin-dev/themes/template/helper/view/view.tpl new file mode 100644 index 000000000..8c63d6447 --- /dev/null +++ b/admin-dev/themes/template/helper/view/view.tpl @@ -0,0 +1,43 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
+
+ {if $show_toolbar} + {include file="toolbar.tpl" toolbar_btn=$toolbar_btn} +
+

+ {block name=pageTitle} + {$title|default:' '} + {/block} +

+
+ {/if} +
{block name="leadin"}{/block}
+
+
+ +{block name="override_tpl"}{/block} diff --git a/classes/AdminController.php b/classes/AdminController.php index 93fbe39de..670628479 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -73,6 +73,7 @@ class AdminControllerCore extends Controller public $tpl_form_vars = array(); public $tpl_list_vars = array(); + public $tpl_view_vars = array(); public $fields_value = false; @@ -289,6 +290,10 @@ class AdminControllerCore extends Controller array_pop($tabs); $tabs[] = array('name' => sprintf($this->l('Add %s'), $this->table)); break; + case 'view': + array_pop($tabs); + $tabs[] = array('name' => sprintf($this->l('View %s'), $this->table)); + break; } // note : this should use a tpl file foreach ($tabs AS $key => $item) @@ -1003,17 +1008,17 @@ class AdminControllerCore extends Controller // Template override $tpl = $this->tpl_folder.'content.tpl'; - $tpl_action = $this->tpl_folder.$this->display.'.tpl'; + //$tpl_action = $this->tpl_folder.$this->display.'.tpl'; // Check if action template has been override // new smarty : template_dir is an array. // @todo : add override path to the smarty config, and checking all array item - if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl_action)) + /*if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl_action)) { if (method_exists($this, $this->display.Tools::toCamelCase($this->className))) $this->{$this->display.Tools::toCamelCase($this->className)}(); $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); - } + }*/ // Check if content template has been override if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl)) @@ -1332,6 +1337,17 @@ class AdminControllerCore extends Controller */ public function initView() { + if (empty($this->toolbar_title)) + $this->initToolbarTitle(); + + $helper = new HelperView($this); + $helper->override_folder = $this->tpl_folder; + $helper->tpl_vars = $this->tpl_view_vars; + $this->setHelperDisplay($helper); + $view = $helper->generateView(); + $this->toolbar_fix = false; + + return $view; } /** @@ -1672,7 +1688,10 @@ class AdminControllerCore extends Controller if (isset($_GET['view'.$this->table])) { if ($this->tabAccess['view'] === '1') + { $this->display = 'view'; + $this->action = 'view'; + } else $this->_errors[] = Tools::displayError('You do not have permission to view here.'); } diff --git a/classes/Helper.php b/classes/Helper.php index ebb58188f..1c3b3812f 100755 --- a/classes/Helper.php +++ b/classes/Helper.php @@ -63,7 +63,6 @@ class HelperCore public function __construct() { $this->context = Context::getContext(); - } /*public function setTpl($tpl) diff --git a/classes/HelperView.php b/classes/HelperView.php new file mode 100644 index 000000000..9dedebaf9 --- /dev/null +++ b/classes/HelperView.php @@ -0,0 +1,62 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9194 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class HelperViewCore extends Helper +{ + public $id; + public $toolbar = true; + public $table; + public $token; + + /** @var if not null, a title will be added on that list */ + public $title = null; + + public function __construct() + { + $this->base_folder = 'helper/view/'; + $this->base_tpl = 'view.tpl'; + parent::__construct(); + } + + public function generateView() + { + $this->tpl = $this->createTemplate($this->base_tpl); + + $this->tpl->assign(array( + 'title' => $this->title, + 'current' => $this->currentIndex, + 'title' => $this->title, + 'token' => $this->token, + 'table' => $this->table, + 'show_toolbar' => $this->show_toolbar, + 'toolbar_fix' => $this->toolbar_fix, + 'toolbar_btn' => $this->toolbar_btn + )); + + return parent::generate(); + } +} diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 5a6d6d258..f90a2fb9a 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -34,16 +34,8 @@ class AdminCustomersControllerCore extends AdminController $this->lang = false; $this->deleted = true; - $this->addRowAction('edit'); - $this->addRowAction('view'); - $this->addRowAction('delete'); - - $this->requiredDatabase = true; - $this->context = Context::getContext(); - $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); - $this->default_form_language = $this->context->language->id; $genders_icon = array('default' => 'unknown.gif'); @@ -152,6 +144,12 @@ class AdminCustomersControllerCore extends AdminController public function initList() { + $this->addRowAction('edit'); + $this->addRowAction('view'); + $this->addRowAction('delete'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + $this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5)) AS `age`, ( SELECT c.date_add FROM '._DB_PREFIX_.'guest g LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest @@ -366,13 +364,6 @@ class AdminCustomersControllerCore extends AdminController return parent::initForm(); } - public function initContent() - { - if ($this->display == 'view') - return $this->initView(); - parent::initContent(); - } - public function initView() { if (!($customer = $this->loadObject())) @@ -492,11 +483,7 @@ class AdminCustomersControllerCore extends AdminController for ($i = 0; $i < $total_referrers; $i++) $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], $this->default_form_language, true); - $this->context->smarty->assign(array( - 'table' => $this->table, - 'current' => self::$currentIndex, - 'token' => $this->token, - 'content' => $this->content, + $this->tpl_view_vars = array( 'customer' => $customer, 'gender_image' => $gender_image, @@ -550,7 +537,10 @@ class AdminCustomersControllerCore extends AdminController // Referrers 'referrers' => $referrers, - )); + 'show_toolbar' => true + ); + + return parent::initView(); } public function postProcess()