From db600e7930a303de77a41e70777fcddea3750e90 Mon Sep 17 00:00:00 2001 From: habarnam Date: Sat, 10 May 2008 19:22:10 +0300 Subject: [PATCH] * improved Options and Categories functionality --- adm/_pages/index/code.php | 94 +++++++++++++++++++---------------- adm/_pages/index/pages/categories.tpl | 16 ++++-- adm/_pages/index/pages/options.tpl | 35 +++++++++++-- 3 files changed, 93 insertions(+), 52 deletions(-) diff --git a/adm/_pages/index/code.php b/adm/_pages/index/code.php index 545aaa0..c059dc3 100644 --- a/adm/_pages/index/code.php +++ b/adm/_pages/index/code.php @@ -20,11 +20,11 @@ class index extends tsAdminPage { // avoid making useless queries if $action = edit || delete if (empty($action)) { $action = null; - } elseif (!in_array($action, get_class_methods($this))) { + } elseif (!in_array($action, get_class_methods ($this))) { $action = 'menu'.ucfirst($action); } - - if (!empty ($action)) { + + if (!empty ($action) && in_array($action, get_class_methods ($this))) { $this->$action(); } @@ -196,41 +196,67 @@ class index extends tsAdminPage { public function catedit () { $c = new tdoCategories ($this->db); - $v = tsPage::getRequest('v'); + // id $i = tsPage::getRequest('i'); + // name + $n = tsPage::getRequest('n'); + // description + $d = tsPage::getRequest('d'); - $c->category_name = $v ; + $c->category_name = $n; + $c->category_description = $d; - $c->update ($i); - - tsPage::redirect( tsPage::setRequest(get_class($this)) ); + $c->replace ($i); + + tsPage::redirect ( tsPage::setRequest(get_class($this), array('do' => 'categories'))); } - + + public function menuCategories () { +// tsPage::redirect( tsPage::setRequest(get_class($this)) ); + $c = new tdoCategories($this->db); + + $c->category_active = 'Y'; + $cs = $c->getArray(); + + $this->varArray['categories'] = $cs; + $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'catedit')); + $this->varArray['mainFile'] = dirname(__FILE__) . '/pages/categories.tpl'; + + } + public function optedit () { $o = new tdoOptions($this->db); - - $v = tsPage::getRequest('v'); + // id $i = tsPage::getRequest('i'); - $o->option_value = $v ; - - $o->update ($i); - tsPage::redirect( tsPage::setRequest (get_class($this)) ); + // delete + if (tsPage::getRequest('delete') == 'yes'){ + $rows = $o->delete ($i); + } else { + // value + $v = tsPage::getRequest('v'); + $a = tsPage::getRequest('a') == 'Y' ? 'Y' : 'N'; + $n = tsPage::getRequest('n'); + + if (!empty($n)) { + $o->option_name = $n; + } + + $o->option_value = $v; + $o->option_modif = $a; + + $o->replace ($i); + } + tsPage::redirect( tsPage::setRequest (get_class($this), 'do=options' )); } - public function menuOpt () { + public function menuOptions () { $o = new tdoOptions($this->db); - $o->option_modif = 'Y'; $os = $o->getArray(); - foreach ($os as $opt){ - $opt['action'] = tsPage::setRequest(get_class($this), array('do'=>'optedit', 'id' => $opt['option_id'])); - $options[] = $opt; - } -// var_dump($options); - $this->varArray['options'] = $options; - $this->varArray['mainFile'] = dirname(__FILE__).'/pages/options.tpl'; - //tsPage::redirect( tsPage::setRequest(get_class($this), 'do=opt') ); + $this->varArray['options'] = $os; + $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'optedit')); + $this->varArray['mainFile'] = dirname(__FILE__).'/pages/options.tpl'; } public function menuLogout () { @@ -240,22 +266,4 @@ class index extends tsAdminPage { public function menuMain () { tsPage::redirect( tsPage::setRequest(get_class($this) )); } - - public function menuCategories () { -// tsPage::redirect( tsPage::setRequest(get_class($this)) ); - $c = new tdoCategories($this->db); - - $c->category_active = 'Y'; - $cs = $c->getArray(); -// var_dump($cs); - foreach ($cs as $cat){ - $cat['action'] = tsPage::setRequest(get_class($this), array('do'=>'catedit', 'id' => $opt['category_id'])); - $categories[] = $cat; - } - - - $this->varArray['categories'] = $categories; - $this->varArray['mainFile'] = dirname(__FILE__).'/pages/categories.tpl'; - - } } diff --git a/adm/_pages/index/pages/categories.tpl b/adm/_pages/index/pages/categories.tpl index 92575a2..8ca9dbe 100644 --- a/adm/_pages/index/pages/categories.tpl +++ b/adm/_pages/index/pages/categories.tpl @@ -1,19 +1,25 @@ - +
{foreach from=$categories item=category} -
+



- +
{/foreach} -
+
+
+
- + Add new Cateogry +
+
+
+
\ No newline at end of file diff --git a/adm/_pages/index/pages/options.tpl b/adm/_pages/index/pages/options.tpl index eae908c..5c89003 100644 --- a/adm/_pages/index/pages/options.tpl +++ b/adm/_pages/index/pages/options.tpl @@ -1,11 +1,38 @@ - +
{foreach from=$options item=option} -
+
{$option.option_name|ucfirst} - - + + + +
+ +
{/foreach} +
+
+
+
+ Add new Option +
+
+ +
+
+ + +
+
+ +
+
+
+
\ No newline at end of file -- 2.11.4.GIT