1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | class name : GPCTabSheet |
---|
4 | class version : 1.1.1 |
---|
5 | plugin version : 3.2.1 |
---|
6 | date : 2010-10-01 |
---|
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 | | | | |
---|
17 | | 1.1.0 | 2010/06/20 | * add possibility to manage the class names for tabs |
---|
18 | | | | |
---|
19 | | 1.1.1 | 2010/10/01 | * add attribute 'id' for tabs (<li> items) |
---|
20 | | | | |
---|
21 | | | | |
---|
22 | | | | |
---|
23 | | | | |
---|
24 | |
---|
25 | ------------------------------------------------------------------------------ |
---|
26 | |
---|
27 | this class provides base functions to manage tabsheet navigation |
---|
28 | |
---|
29 | this class extends the Piwigo tabsheet class |
---|
30 | |
---|
31 | ---------------------------------------------------------------------- */ |
---|
32 | |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
34 | |
---|
35 | class GPCTabSheet extends tabsheet |
---|
36 | { |
---|
37 | protected $classes; |
---|
38 | protected $id; |
---|
39 | protected $tplFile; |
---|
40 | protected $selectedTabClasses='selected_tab'; |
---|
41 | protected $unselectedTabClasses='normal_tab'; |
---|
42 | protected $normalTabClasses=''; |
---|
43 | |
---|
44 | |
---|
45 | /* |
---|
46 | $name is the tabsheet's name inside the template .tpl file |
---|
47 | $titlename in the template is affected by $titlename value |
---|
48 | */ |
---|
49 | public function __construct($name = 'TABSHEET', $titlename = 'TABSHEET_TITLE', $classes="", $id="", $tplFile="") |
---|
50 | { |
---|
51 | parent::tabsheet($name, $titlename); |
---|
52 | $this->classes=$classes; |
---|
53 | $this->id=$id; |
---|
54 | $this->setTplFile($tplFile); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | function add($name, $caption, $url, $selected = false, $onClick='') |
---|
59 | { |
---|
60 | if(parent::add($name,$caption,$url,$selected)) |
---|
61 | { |
---|
62 | $this->sheets[$name]['onClick'] = $onClick; |
---|
63 | return(true); |
---|
64 | } |
---|
65 | return(false); |
---|
66 | } |
---|
67 | |
---|
68 | public function setClasses($classes) |
---|
69 | { |
---|
70 | $this->classes=$classes; |
---|
71 | return($this->classes); |
---|
72 | } |
---|
73 | |
---|
74 | public function getClasses() |
---|
75 | { |
---|
76 | return($this->classes); |
---|
77 | } |
---|
78 | |
---|
79 | public function setTabsClasses($state, $classes) |
---|
80 | { |
---|
81 | if($state=='unselected') |
---|
82 | { |
---|
83 | $this->unselectedTabClasses=$classes; |
---|
84 | return($this->unselectedTabClasses); |
---|
85 | } |
---|
86 | elseif($state=='selected') |
---|
87 | { |
---|
88 | $this->selectedTabClasses=$classes; |
---|
89 | return($this->selectedTabClasses); |
---|
90 | } |
---|
91 | elseif($state=='normal') |
---|
92 | { |
---|
93 | $this->normalTabClasses=$classes; |
---|
94 | return($this->normalTabClasses); |
---|
95 | } |
---|
96 | return(""); |
---|
97 | } |
---|
98 | |
---|
99 | public function getTabsClasses($state) |
---|
100 | { |
---|
101 | if($state=='unselected') |
---|
102 | { |
---|
103 | return($this->unselectedTabClasses); |
---|
104 | } |
---|
105 | elseif($state=='selected') |
---|
106 | { |
---|
107 | return($this->selectedTabClasses); |
---|
108 | } |
---|
109 | elseif($state=='normal') |
---|
110 | { |
---|
111 | return($this->normalTabClasses); |
---|
112 | } |
---|
113 | return(""); |
---|
114 | } |
---|
115 | |
---|
116 | public function setId($id) |
---|
117 | { |
---|
118 | $this->id=$id; |
---|
119 | return($this->id); |
---|
120 | } |
---|
121 | |
---|
122 | public function getId() |
---|
123 | { |
---|
124 | return($this->id); |
---|
125 | } |
---|
126 | |
---|
127 | public function setTplFile($fileName) |
---|
128 | { |
---|
129 | if(file_exists($fileName) or $fileName=="") |
---|
130 | { |
---|
131 | $this->tplFile=$fileName; |
---|
132 | } |
---|
133 | return($this->tplFile); |
---|
134 | } |
---|
135 | |
---|
136 | public function getTplFile() |
---|
137 | { |
---|
138 | return($this->tplFile); |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | /* |
---|
143 | * Build TabSheet and assign this content to current page |
---|
144 | * |
---|
145 | * Fill $this->$name {default value = TABSHEET} with HTML code for tabsheet |
---|
146 | * Fill $this->titlename {default value = TABSHEET_TITLE} with formated caption of the selected tab |
---|
147 | */ |
---|
148 | function assign() |
---|
149 | { |
---|
150 | global $template; |
---|
151 | |
---|
152 | if($this->tplFile=="") |
---|
153 | { |
---|
154 | $tplFile=dirname(dirname(__FILE__)).'/templates/GPCTabSheet.tpl'; |
---|
155 | } |
---|
156 | else |
---|
157 | { |
---|
158 | $tplFile=$this->tplFile; |
---|
159 | } |
---|
160 | |
---|
161 | $template->set_filename('tabsheet', $tplFile); |
---|
162 | $template->assign('tabsheet', $this->sheets); |
---|
163 | $template->assign('tabsheet_selected', $this->selected); |
---|
164 | |
---|
165 | $selected_tab = $this->get_selected(); |
---|
166 | |
---|
167 | if (isset($selected_tab)) |
---|
168 | { |
---|
169 | $template->assign( |
---|
170 | array($this->titlename => '['.$selected_tab['caption'].']')); |
---|
171 | } |
---|
172 | |
---|
173 | if($this->classes!="") $template->assign('tabsheet_classes', $this->classes); |
---|
174 | if($this->id!="") $template->assign('tabsheet_id', $this->id); |
---|
175 | |
---|
176 | $template->assign('tab_classes', |
---|
177 | array( |
---|
178 | 'unselected' => $this->getTabsClasses('unselected'), |
---|
179 | 'selected' => $this->getTabsClasses('selected'), |
---|
180 | 'normal' => $this->getTabsClasses('normal') |
---|
181 | ) |
---|
182 | ); |
---|
183 | |
---|
184 | $template->assign_var_from_handle($this->name, 'tabsheet'); |
---|
185 | $template->clear_assign('tabsheet'); |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | ?> |
---|