1 <?php
3 class MultiSelectWindow{
5 var $bool_DisplayAlpahabet = false;
6 var $bool_DisplayCloseButton= true;
7 var $bool_DisplaySaveButton = true;
9 var $SaveButtonString = "";
10 var $CloseButtonString = "";
11 var $string_Title = "";
12 var $string_ListHeader = "";
13 var $string_Summary = "";
14 var $string_Information = "";
16 var $array_Header = array();
17 var $array_Elements = array();
18 var $array_Checkboxes = array();
19 var $array_Regexes = array();
21 var $config = "";
23 var $is_closed = false;
24 var $is_saved = false;
26 function ClearElementsList()
27 {
28 $this->array_Elements = array();
29 }
31 function AddRegex($name,$string,$value,$conn)
32 {
33 $arr = array();
34 $arr['name'] = $name;
35 $arr['string'] = $string;
36 $arr['value'] = $value;
37 $arr['connAlpha'] = $conn; // Connect with alphabet select
38 $this->array_Regexes[] = $arr;
39 }
41 function MultiSelectWindow($config){
42 $this->config = $config;
43 $this->SaveButtonString = _("Save");
44 $this->CloseButtonString = _("Close");
45 }
47 function SetTitle($str){
48 $this->string_Title = $str;
49 }
51 function SetListHeader($str){
52 $this->string_ListHeader = $str;
53 }
55 function SetSummary($str){
56 $this->string_Summary = $str;
57 }
59 function SetSaveButtonString($str){
60 $this->SaveButtonString = $str;
61 }
63 function SetCloseButtonString($str){
64 $this->CloseButtonString = $str;
65 }
67 function SetInformation($str){
68 $this->string_Information = $str;
69 }
71 function EnableAplhabet($bool){
72 $this->bool_DisplayAlpahabet = $bool;
73 }
75 function AddHeader($arr){
76 $this->array_Header[] = $arr;
77 }
79 function AddElement($arr){
80 $this->array_Elements[] = $arr;
81 }
83 function AddCheckBox($name,$value,$string,$default){
84 $arr = array();
85 $arr['name'] = $name;
86 $arr['string'] = $string;
87 $arr['value'] = $value;
88 $arr['default'] = $default;
89 $this->array_Checkboxes[] = $arr;
90 }
92 function isClosed()
93 {
94 return($this->is_closed);
95 }
97 function EnableCloseButton($bool)
98 {
99 $this->bool_DisplayCloseButton = $bool;
100 }
102 function EnableSaveButton ($bool)
103 {
104 $this->bool_DisplaySaveButton = $bool;
105 }
107 function Draw()
108 {
109 $smarty = get_smarty();
111 $divlist = new divlist($this->string_Title);
112 $divlist->SetSummary($this->string_Summary);
113 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
115 /* set Header informations
116 */
117 $header = array();
118 foreach($this->array_Header as $head){
119 $header[] = $head;
120 }
121 $divlist->SetHeader($header);
123 /* set Entries
124 */
125 $elements = array();
126 foreach($this->array_Elements as $element){
127 $divlist->AddEntry($element);
128 }
130 /* Create checkboxes fields
131 */
132 $boxes = "";
133 $boxClick = " onClick='document.mainform.submit();' ";
134 foreach($this->array_Checkboxes as $box){
135 if($box['default'] == true){
136 $boxes .="<input type='checkbox' name='".$box['name']."' value='".$box['value']."' checked ".$boxClick."> ".$box['string']."<br>";
137 }else{
138 $boxes .="<input type='checkbox' name='".$box['name']."' value='".$box['value']."'".$boxClick.";> ".$box['string']."<br>";
139 }
140 }
141 $smarty->assign("CheckBoxes", $boxes);
143 /* Assign regex fields
144 */
145 $regexes = "";
146 foreach($this->array_Regexes as $regex){
147 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
148 <tr>
149 <td>
150 <label for=\"".$regex['name']."\">
151 <img alt=\"".$regex['string']."\" src=\"images/search.png\" align=middle>
152 </label>
153 </td>
154 <td width=\"99%\">
155 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
156 value='".$regex['value']."' title=\"".$regex['string']."\">
157 </td>
158 </tr>
159 </table>";
160 }
161 $smarty->assign("regexes" , $regexes );
163 /* Assign alphabet and display it
164 */
165 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
166 $smarty->assign("alphabet", generate_alphabet());
168 $smarty->assign("Header" , $this->string_ListHeader );
169 $smarty->assign("Summary" , $this->string_Summary);
170 $smarty->assign("Title" , $this->string_Title);
171 $smarty->assign("Information" , $this->string_Information);
173 $smarty->assign("DivList" , $divlist->DrawList());
175 $smarty->assign("search_image", get_template_path('images/search.png'));
176 $smarty->assign("searchu_image", get_template_path('images/search_user.png'));
177 $smarty->assign("tree_image", get_template_path('images/tree.png'));
178 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
179 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
180 $smarty->assign("apply", apply_filter());
182 /* Button handling */
183 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
184 $smarty->assign("CloseButtonString",$this->CloseButtonString);
186 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
187 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
189 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
190 return($display);
191 }
193 function Close()
194 {
195 $this->is_closed = true;
196 }
198 function Save()
199 {
200 $this->is_saved = true;
201 }
203 function save_object()
204 {
205 if(isset($_POST['MultiSelectWindow'])){
207 /* Check posts from checkboxes
208 */
209 foreach($this->array_Checkboxes as $key => $box){
210 if(isset($_POST[$box['name']])){
211 $this->array_Checkboxes[$key]['default'] = true;
212 $this->$box['name'] = true;
213 }else{
214 $this->array_Checkboxes[$key]['default'] = false;
215 $this->$box['name'] = false;
216 }
217 }
219 /* Check regex posts */
220 foreach($this->array_Regexes as $key => $box){
221 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
222 $this->$box['name'] = $_POST[$box['name']];
223 }
225 /* call close/save if buttons are pressed */
226 if(isset($_POST['CloseMultiSelectWindow'])){
227 $this->Close();
228 }
230 if(isset($_POST['SaveMultiSelectWindow'])){
231 $this->Save();
232 }
233 }
235 /* check for alphabet selection
236 Check which regexes are connected to the alphabet
237 */
238 if(isset($_GET['search'])){
239 foreach($this->array_Regexes as $key => $box){
240 /* check if this regex is connected to the alphabet selection */
241 if(($box['connAlpha'])&&(isset($_GET['search']))){
242 $val = $_GET['search']."*";
243 $val = preg_replace("/\*\**/","*",$val);
244 $this->array_Regexes[$key]['value'] = $val;
245 $this->$box['name'] = $val;
246 }
247 }
248 }
250 }
251 }
253 ?>