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

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

Merged revision(s) 16925 from trunk:
feature 2703: make it easy for plugins to add tabs in admin screens
add a trigger a give an id to each core tabsheets

  • Property svn:eol-style set to LF
File size: 4.1 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    $this->selected = $name;
93  }
94
95  /*
96    set $titlename value
97  */
98  function set_titlename($titlename)
99  {
100    $this->titlename = $titlename;
101    return $this->titlename;
102  }
103
104  /*
105    returns $titlename value
106  */
107  function get_titlename()
108  {
109    return $this->titlename;
110  }
111
112  /*
113    returns properties of selected tab
114  */
115  function get_selected()
116  {
117    if (!empty($this->selected))
118    {
119      return $this->sheets[$this->selected];
120    }
121    else
122    {
123      return null;
124    }
125  }
126
127  /*
128   * Build TabSheet and assign this content to current page
129   *
130   * Fill $this->$name {default value = TABSHEET} with HTML code for tabsheet
131   * Fill $this->titlename {default value = TABSHEET_TITLE} with formated caption of the selected tab
132   */
133  function assign()
134  {
135    global $template;
136
137    $template->set_filename('tabsheet', 'tabsheet.tpl');
138    $template->assign('tabsheet', $this->sheets);
139    $template->assign('tabsheet_selected', $this->selected);
140
141    $selected_tab = $this->get_selected();
142
143    if (isset($selected_tab))
144    {
145      $template->assign(
146        array($this->titlename => '['.$selected_tab['caption'].']'));
147    }
148
149    $template->assign_var_from_handle($this->name, 'tabsheet');
150    $template->clear_assign('tabsheet');
151  }
152}
153
154?>
Note: See TracBrowser for help on using the repository browser.