source: branches/2.4/admin/include/tabsheet.class.php @ 16929

Last change on this file since 16929 was 16929, checked in by mistic100, 12 years ago

Merged revision(s) 16928 from trunk:
feature 2703: make it easy for plugins to add tabs in admin screens
centralize all core tabs in one file

  • Property svn:eol-style set to LF
File size: 4.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24class tabsheet
25{
26  var $sheets;
27  var $uniqid;
28  var $name;
29  var $titlename;
30  var $selected;
31
32  /*
33    $name is the tabsheet's name inside the template .tpl file
34    $titlename in the template is affected by $titlename value
35  */
36  function tabsheet($name = 'TABSHEET', $titlename = 'TABSHEET_TITLE')
37  {
38    $this->sheets = array();
39    $this->uniqid = null;
40    $this->name = $name;
41    $this->titlename = $titlename;
42    $this->selected = "";
43  }
44 
45  function set_id($id)
46  {
47    $this->uniqid = $id;
48  }
49
50  /*
51     add a tab
52  */
53  function add($name, $caption, $url, $selected = false)
54  {
55    if (!isset($this->sheets[$name]))
56    {
57      $this->sheets[$name] = array('caption' => $caption,
58                                   'url' => $url);
59      if($selected)
60      {
61        $this->selected=$name;
62      }
63      return true;
64    }
65    return false;
66  }
67
68  /*
69     remove a tab
70  */
71  function delete($name)
72  {
73    if (isset($this->sheets[$name]))
74    {
75      array_splice($this->sheets, $name, 1);
76
77      if ($this->selected == $name)
78      {
79        $this->selected = "";
80      }
81      return true;
82    }
83    return false;
84  }
85
86  /*
87     select a tab to be active
88  */
89  function select($name)
90  {
91    $this->sheets = trigger_event('tabsheet_before_select', $this->sheets, $this->uniqid);
92    if (!array_key_exists($name, $this->sheets))
93    {
94      $keys = array_keys($this->sheets);
95      $name = $keys[0];
96    }
97    $this->selected = $name;
98  }
99
100  /*
101    set $titlename value
102  */
103  function set_titlename($titlename)
104  {
105    $this->titlename = $titlename;
106    return $this->titlename;
107  }
108
109  /*
110    returns $titlename value
111  */
112  function get_titlename()
113  {
114    return $this->titlename;
115  }
116
117  /*
118    returns properties of selected tab
119  */
120  function get_selected()
121  {
122    if (!empty($this->selected))
123    {
124      return $this->sheets[$this->selected];
125    }
126    else
127    {
128      return null;
129    }
130  }
131
132  /*
133   * Build TabSheet and assign this content to current page
134   *
135   * Fill $this->$name {default value = TABSHEET} with HTML code for tabsheet
136   * Fill $this->titlename {default value = TABSHEET_TITLE} with formated caption of the selected tab
137   */
138  function assign()
139  {
140    global $template;
141
142    $template->set_filename('tabsheet', 'tabsheet.tpl');
143    $template->assign('tabsheet', $this->sheets);
144    $template->assign('tabsheet_selected', $this->selected);
145
146    $selected_tab = $this->get_selected();
147
148    if (isset($selected_tab))
149    {
150      $template->assign(
151        array($this->titlename => '['.$selected_tab['caption'].']'));
152    }
153
154    $template->assign_var_from_handle($this->name, 'tabsheet');
155    $template->clear_assign('tabsheet');
156  }
157}
158
159?>
Note: See TracBrowser for help on using the repository browser.