[5918] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | class name : GPCTabSheet |
---|
[17562] | 4 | class version : 1.1.2 |
---|
| 5 | plugin version : 3.5.3 |
---|
| 6 | date : 2012-08-14 |
---|
[5918] | 7 | ------------------------------------------------------------------------------ |
---|
| 8 | author: grum at piwigo.org |
---|
| 9 | << May the Little SpaceFrog be with you >> |
---|
| 10 | ------------------------------------------------------------------------------ |
---|
| 11 | |
---|
| 12 | :: HISTORY |
---|
| 13 | |
---|
| 14 | | release | date | |
---|
| 15 | | 1.0.0 | 2010/04/18 | * create class |
---|
| 16 | | | | |
---|
[6702] | 17 | | 1.1.0 | 2010/06/20 | * add possibility to manage the class names for tabs |
---|
[5918] | 18 | | | | |
---|
[7142] | 19 | | 1.1.1 | 2010/10/01 | * add attribute 'id' for tabs (<li> items) |
---|
[5918] | 20 | | | | |
---|
[17562] | 21 | | 1.1.2 | 2012/08/14 | * bug:2723 - set select() function to be compatible with |
---|
| 22 | | | | piwigo 2.4.3 |
---|
[5918] | 23 | | | | |
---|
| 24 | | | | |
---|
| 25 | |
---|
| 26 | ------------------------------------------------------------------------------ |
---|
| 27 | |
---|
| 28 | this class provides base functions to manage tabsheet navigation |
---|
| 29 | |
---|
| 30 | this class extends the Piwigo tabsheet class |
---|
| 31 | |
---|
| 32 | ---------------------------------------------------------------------- */ |
---|
| 33 | |
---|
| 34 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 35 | |
---|
| 36 | class GPCTabSheet extends tabsheet |
---|
| 37 | { |
---|
| 38 | protected $classes; |
---|
| 39 | protected $id; |
---|
| 40 | protected $tplFile; |
---|
[6702] | 41 | protected $selectedTabClasses='selected_tab'; |
---|
| 42 | protected $unselectedTabClasses='normal_tab'; |
---|
| 43 | protected $normalTabClasses=''; |
---|
| 44 | |
---|
| 45 | |
---|
[5918] | 46 | /* |
---|
| 47 | $name is the tabsheet's name inside the template .tpl file |
---|
| 48 | $titlename in the template is affected by $titlename value |
---|
| 49 | */ |
---|
| 50 | public function __construct($name = 'TABSHEET', $titlename = 'TABSHEET_TITLE', $classes="", $id="", $tplFile="") |
---|
| 51 | { |
---|
| 52 | parent::tabsheet($name, $titlename); |
---|
| 53 | $this->classes=$classes; |
---|
| 54 | $this->id=$id; |
---|
[17562] | 55 | $this->set_id($this->id); |
---|
[5918] | 56 | $this->setTplFile($tplFile); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
[6174] | 60 | function add($name, $caption, $url, $selected = false, $onClick='') |
---|
| 61 | { |
---|
| 62 | if(parent::add($name,$caption,$url,$selected)) |
---|
| 63 | { |
---|
| 64 | $this->sheets[$name]['onClick'] = $onClick; |
---|
| 65 | return(true); |
---|
| 66 | } |
---|
| 67 | return(false); |
---|
| 68 | } |
---|
| 69 | |
---|
[5918] | 70 | public function setClasses($classes) |
---|
| 71 | { |
---|
| 72 | $this->classes=$classes; |
---|
| 73 | return($this->classes); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | public function getClasses() |
---|
| 77 | { |
---|
| 78 | return($this->classes); |
---|
| 79 | } |
---|
| 80 | |
---|
[6702] | 81 | public function setTabsClasses($state, $classes) |
---|
| 82 | { |
---|
| 83 | if($state=='unselected') |
---|
| 84 | { |
---|
| 85 | $this->unselectedTabClasses=$classes; |
---|
| 86 | return($this->unselectedTabClasses); |
---|
| 87 | } |
---|
| 88 | elseif($state=='selected') |
---|
| 89 | { |
---|
| 90 | $this->selectedTabClasses=$classes; |
---|
| 91 | return($this->selectedTabClasses); |
---|
| 92 | } |
---|
| 93 | elseif($state=='normal') |
---|
| 94 | { |
---|
| 95 | $this->normalTabClasses=$classes; |
---|
| 96 | return($this->normalTabClasses); |
---|
| 97 | } |
---|
| 98 | return(""); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | public function getTabsClasses($state) |
---|
| 102 | { |
---|
| 103 | if($state=='unselected') |
---|
| 104 | { |
---|
| 105 | return($this->unselectedTabClasses); |
---|
| 106 | } |
---|
| 107 | elseif($state=='selected') |
---|
| 108 | { |
---|
| 109 | return($this->selectedTabClasses); |
---|
| 110 | } |
---|
| 111 | elseif($state=='normal') |
---|
| 112 | { |
---|
| 113 | return($this->normalTabClasses); |
---|
| 114 | } |
---|
| 115 | return(""); |
---|
| 116 | } |
---|
| 117 | |
---|
[5918] | 118 | public function setId($id) |
---|
| 119 | { |
---|
| 120 | $this->id=$id; |
---|
| 121 | return($this->id); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | public function getId() |
---|
| 125 | { |
---|
| 126 | return($this->id); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | public function setTplFile($fileName) |
---|
| 130 | { |
---|
| 131 | if(file_exists($fileName) or $fileName=="") |
---|
| 132 | { |
---|
| 133 | $this->tplFile=$fileName; |
---|
| 134 | } |
---|
| 135 | return($this->tplFile); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | public function getTplFile() |
---|
| 139 | { |
---|
| 140 | return($this->tplFile); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
[17562] | 144 | public function select($name) |
---|
| 145 | { |
---|
| 146 | /* |
---|
| 147 | * override the tabsheet->select() function (to fix bug:2723) |
---|
| 148 | */ |
---|
| 149 | if($this->id!='') |
---|
| 150 | { |
---|
| 151 | $this->sheets = trigger_event('gpc_tabsheet_before_select', $this->sheets, $this->id); |
---|
| 152 | if (!array_key_exists($name, $this->sheets)) |
---|
| 153 | { |
---|
| 154 | $keys = array_keys($this->sheets); |
---|
| 155 | if(isset($keys[0])) |
---|
| 156 | $name = $keys[0]; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | $this->selected = $name; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | function set_id($id) |
---|
| 163 | { |
---|
| 164 | /* |
---|
| 165 | * override the tabsheet->select() function (to fix bug:2723) |
---|
| 166 | */ |
---|
| 167 | if(method_exists('tabsheet', 'set_id')) |
---|
| 168 | { |
---|
| 169 | parent::set_id($id); |
---|
| 170 | } |
---|
| 171 | else |
---|
| 172 | { |
---|
| 173 | $this->uniqid = $id; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
[5918] | 177 | /* |
---|
| 178 | * Build TabSheet and assign this content to current page |
---|
| 179 | * |
---|
| 180 | * Fill $this->$name {default value = TABSHEET} with HTML code for tabsheet |
---|
| 181 | * Fill $this->titlename {default value = TABSHEET_TITLE} with formated caption of the selected tab |
---|
| 182 | */ |
---|
| 183 | function assign() |
---|
| 184 | { |
---|
| 185 | global $template; |
---|
| 186 | |
---|
| 187 | if($this->tplFile=="") |
---|
| 188 | { |
---|
| 189 | $tplFile=dirname(dirname(__FILE__)).'/templates/GPCTabSheet.tpl'; |
---|
| 190 | } |
---|
| 191 | else |
---|
| 192 | { |
---|
| 193 | $tplFile=$this->tplFile; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | $template->set_filename('tabsheet', $tplFile); |
---|
| 197 | $template->assign('tabsheet', $this->sheets); |
---|
| 198 | $template->assign('tabsheet_selected', $this->selected); |
---|
| 199 | |
---|
| 200 | $selected_tab = $this->get_selected(); |
---|
| 201 | |
---|
| 202 | if (isset($selected_tab)) |
---|
| 203 | { |
---|
| 204 | $template->assign( |
---|
| 205 | array($this->titlename => '['.$selected_tab['caption'].']')); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | if($this->classes!="") $template->assign('tabsheet_classes', $this->classes); |
---|
| 209 | if($this->id!="") $template->assign('tabsheet_id', $this->id); |
---|
| 210 | |
---|
[6702] | 211 | $template->assign('tab_classes', |
---|
| 212 | array( |
---|
| 213 | 'unselected' => $this->getTabsClasses('unselected'), |
---|
| 214 | 'selected' => $this->getTabsClasses('selected'), |
---|
| 215 | 'normal' => $this->getTabsClasses('normal') |
---|
| 216 | ) |
---|
| 217 | ); |
---|
| 218 | |
---|
[5918] | 219 | $template->assign_var_from_handle($this->name, 'tabsheet'); |
---|
| 220 | $template->clear_assign('tabsheet'); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | ?> |
---|