[1900] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1900] | 23 | |
---|
[2226] | 24 | class tabsheet |
---|
[1900] | 25 | { |
---|
[2226] | 26 | var $sheets; |
---|
[16925] | 27 | var $uniqid; |
---|
[2226] | 28 | var $name; |
---|
| 29 | var $titlename; |
---|
| 30 | var $selected; |
---|
[1900] | 31 | |
---|
[2226] | 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') |
---|
[1900] | 37 | { |
---|
[2226] | 38 | $this->sheets = array(); |
---|
[16925] | 39 | $this->uniqid = null; |
---|
[2226] | 40 | $this->name = $name; |
---|
| 41 | $this->titlename = $titlename; |
---|
| 42 | $this->selected = ""; |
---|
| 43 | } |
---|
[16925] | 44 | |
---|
| 45 | function set_id($id) |
---|
| 46 | { |
---|
| 47 | $this->uniqid = $id; |
---|
| 48 | } |
---|
[2226] | 49 | |
---|
| 50 | /* |
---|
| 51 | add a tab |
---|
| 52 | */ |
---|
| 53 | function add($name, $caption, $url, $selected = false) |
---|
| 54 | { |
---|
| 55 | if (!isset($this->sheets[$name])) |
---|
[1900] | 56 | { |
---|
[2226] | 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 | { |
---|
[16925] | 91 | $this->sheets = trigger_event('tabsheet_before_select', $this->sheets, $this->uniqid); |
---|
[16928] | 92 | if (!array_key_exists($name, $this->sheets)) |
---|
| 93 | { |
---|
| 94 | $keys = array_keys($this->sheets); |
---|
| 95 | $name = $keys[0]; |
---|
| 96 | } |
---|
[2226] | 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 | |
---|
[2530] | 142 | $template->set_filename('tabsheet', 'tabsheet.tpl'); |
---|
[2226] | 143 | $template->assign('tabsheet', $this->sheets); |
---|
| 144 | $template->assign('tabsheet_selected', $this->selected); |
---|
| 145 | |
---|
| 146 | $selected_tab = $this->get_selected(); |
---|
[2290] | 147 | |
---|
[2226] | 148 | if (isset($selected_tab)) |
---|
| 149 | { |
---|
[2290] | 150 | $template->assign( |
---|
[2226] | 151 | array($this->titlename => '['.$selected_tab['caption'].']')); |
---|
[1900] | 152 | } |
---|
[2226] | 153 | |
---|
| 154 | $template->assign_var_from_handle($this->name, 'tabsheet'); |
---|
| 155 | $template->clear_assign('tabsheet'); |
---|
[2223] | 156 | } |
---|
[1900] | 157 | } |
---|
| 158 | |
---|
| 159 | ?> |
---|