1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU 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 USA
21 */
23 class divListUsers extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes */
34 var $ShowTemplates ;
35 var $ShowFunctionalUsers;
36 var $ShowUnixUsers;
37 var $ShowMailUsers;
38 var $ShowSambaUsers;
39 var $ShowProxyUsers;
41 /* Subsearch checkbox */
42 var $SubSearch = false;
44 var $parent ;
45 var $ui ;
47 function divListUsers (&$config,$parent)
48 {
49 MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
51 $this->parent = $parent;
52 $this->ui = get_userinfo();
54 /* Set list strings */
55 $this->SetTitle(_("List of users"));
56 $this->SetSummary(_("List of users"));
58 /* Result page will look like a headpage */
59 $this->SetHeadpageMode();
61 $this->EnableAplhabet (true);
63 /* Disable buttonsm */
64 $this->EnableCloseButton(false);
65 $this->EnableSaveButton (false);
67 /* Dynamic action col, depending on snapshot icons */
68 $action_col_size = 122;
69 if($this->parent->snapshotEnabled()){
70 $action_col_size += 38;
71 }
73 /* Toggle all selected / deselected */
74 $chk = "<input type='checkbox' id='select_all' name='select_all'
75 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77 /* set Page header */
78 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
79 $this->AddHeader(array("string"=> " ", "attach"=>"style='width:20px;'"));
80 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
81 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:166px;'"));
82 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
84 $this->AddCheckBox("ShowTemplates" ,msgPool::selectToView(_("Template")) ,sprintf(_("Show %s"),_("templates")), false);
85 $this->AddCheckBox("ShowFunctionalUsers",msgPool::selectToView(_("GOsa object"),"enabled"),sprintf(_("Show %s user"),_("functional")), true);
86 $this->AddCheckBox("ShowUnixUsers" ,msgPool::selectToView(_("Posix"),"enabled") ,sprintf(_("Show %s user"),_("posix")), true);
87 $this->AddCheckBox("ShowMailUsers" ,msgPool::selectToView(_("Mail"),"enabled") ,sprintf(_("Show %s user"),_("mail")), true);
88 $this->AddCheckBox("ShowSambaUsers" ,msgPool::selectToView(_("Samba"),"enabled") ,sprintf(_("Show %s user"),_("samba")), true);
89 $this->AddCheckBox("ShowProxyUsers" ,msgPool::selectToView(_("Proxy"),"enabled") ,sprintf(_("Show %s user"),_("proxy")), true);
91 /* Add SubSearch checkbox */
92 $this->AddCheckBox(SEPERATOR);
93 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
95 /* Name ,Text ,Default , Connect with alphabet */
96 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
97 }
100 function GenHeader()
101 {
102 /* Prepare departments,
103 which are shown in the listbox on top of the listbox
104 */
105 $options= "";
107 /* Get all departments within this subtree */
108 $base = $this->config->current['BASE'];
110 /* Add base */
111 $tmp = array();
112 $tmp[] = array("dn"=>$this->config->current['BASE']);
113 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
114 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
116 $deps = array();
117 foreach($tmp as $tm){
118 $deps[$tm['dn']] = $tm['dn'];
119 }
122 /* Load possible departments */
123 $ui= get_userinfo();
124 $tdeps= $ui->get_module_departments("users");
125 $ids = $this->config->idepartments;
126 $first = "";
127 $found = FALSE;
128 foreach($ids as $dep => $name){
129 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
131 /* Keep first base dn in mind, we could need this
132 * info if no valid base was found
133 */
134 if(empty($first)) {
135 $first = $dep['dn'];
136 }
138 $value = $ids[$dep];
139 if ($this->selectedBase == $dep){
140 $found = TRUE;
141 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
142 } else {
143 $options.= "<option value='".$dep."'>$value</option>";
144 }
145 }
146 }
148 /* The currently used base is not visible with your acl setup.
149 * Set base to first useable base.
150 */
151 if(!$found){
152 $this->selectedBase = $first;
153 }
155 /* Get copy & paste icon */
156 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
157 $acl = $ui->get_permissions($this->selectedBase,"users/user");
159 /* Add default header */
160 $listhead = MultiSelectWindow::get_default_header();
161 $listhead .=
162 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
163 " <input class='center' type='image' src='images/list_submit.png' align='middle'
164 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
167 /* Create Layers menu */
168 $s = ".|"._("Actions")."|\n";
169 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
170 " "._("Create")."|\n";
172 /* Append create options */
173 if(preg_match("/c/",$acl)) {
174 $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
175 " "._("User")."|user_new|\n";
176 $s.= "...|<input class='center' type='image' src='images/list_new.png' alt=''>".
177 " "._("Template")."|user_tplnew|\n";
178 }
180 /* Multiple options */
181 $s.= "..|---|\n";
182 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
183 " "._("Edit")."|"."multiple_edit|\n";
184 $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
185 " "._("Change password")."|"."multiple_password_change|\n";
186 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
187 " "._("Remove")."|"."remove_multiple|\n";
189 /* Add event tag */
190 if(class_available("DaemonEvent")){
191 $events = DaemonEvent::get_event_types(USER_EVENT);
192 if(count($events['BY_CLASS'])){
193 $s.= "..|---|\n";
194 foreach($events['BY_CLASS'] as $name => $event){
195 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
196 }
197 }
198 }
200 /* Add multiple copy & cut icons */
201 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
202 $s.= "..|---|\n";
203 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
204 " "._("Copy")."|"."multiple_copy_systems|\n";
205 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
206 " "._("Cut")."|"."multiple_cut_systems|\n";
208 if($this->parent->CopyPasteHandler->entries_queued()){
209 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
210 $s.="..|".$img." "._("Paste")."|editPaste|\n";
211 }else{
212 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
213 $s.="..|".$img." "._("Paste")."\n";
214 }
215 }
217 /* Add snapshot icons */
218 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
219 $s .= "..|---|\n";
220 $s .= $this->get_snapshot_header(TRUE);
221 }
223 $this->SetDropDownHeaderMenu($s);
224 $this->SetListHeader($listhead);
225 }
227 /* so some basic settings */
228 function execute()
229 {
230 $this->ClearElementsList();
231 $this->GenHeader();
232 }
234 function setEntries($list)
235 {
236 /********************
237 Variable init
238 ********************/
240 $num_users = 0;
241 $num_templates = 0;
243 /* Variable initialation */
244 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
245 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
246 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
247 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
248 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
250 /* Dynamic action col, depending on snapshot icons */
251 $action_col_size = 122;
252 if($this->parent->snapshotEnabled()){
253 $action_col_size += 38;
254 }
256 /* Possilbe objectClass image combinations */
257 $possibleAccounts = array(
258 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
259 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
260 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
261 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
262 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
263 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
265 /* Pictures for Extensions */
266 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
267 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
268 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
269 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
270 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
271 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
272 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
273 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
274 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
275 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
276 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
277 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
278 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
279 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
280 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
281 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
282 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
283 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
285 /********************
286 END :: Variable init
287 ********************/
290 /********************
291 Append entries to divlist
292 ********************/
294 $ui = get_userinfo();
296 // Test Every Entry and generate divlist Array
297 foreach($list as $key => $val){
299 /* Create action icons */
300 $action= "";
302 /* Add copy & cut icons */
303 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
304 $acl = $ui->get_permissions($val['dn'],"users/user");
305 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
306 $action .= "<input class='center' type='image'
307 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
308 $action.= "<input class='center' type='image'
309 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
310 }
312 /* Add deactivate status */
313 $lock_status = "";
315 if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
316 if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
317 $lock_status = "<input class='center' type='image' src='images/closedlock.png'
318 alt='"._("inactive")."' name='toggle_lock_status_%KEY%'>";
319 }else{
320 $lock_status = "<input class='center' type='image' src='images/openlock.png'
321 alt='"._("active")."' name='toggle_lock_status_%KEY%'>";
322 }
323 }else{
324 $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
325 }
327 /* Generate edit icon */
328 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
329 name='user_edit_%KEY%' title='".msgPool::editButton(_("user"))."'>";
331 /* Add deactivate status if we are allowed to */
332 if (preg_match("/w/",$acl_all)){
333 $action.= $lock_status;
334 }
336 /* Add Password change icon, if we are able to write users/password */
337 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
338 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
339 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
340 }else{
341 $action.= "<img class='center' src='images/empty.png' alt=' '
342 title='"._("Not allowed")."'>";
343 }
345 /* Add snapshot icon */
346 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
347 $action.= $this->GetSnapShotActions($val['dn']);
348 }
350 /* Add remove icon, if we are allowed to remove the current user */
351 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
352 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
353 name='user_del_%KEY%' title='"._("Delete user")."'>";
354 }else{
355 $action.= "<img class='center' src='images/empty.png' alt=' '
356 title='"._("Not allowed")."'>";
357 }
359 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
360 if((in_array("goFonAccount" ,$val['objectClass']))){
362 /* Set defaults */
363 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
364 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
365 $fonac = preg_replace("/%title%/", "", $fonac);
367 }else{
368 $fonac=$empty;
369 }
371 /* Set images for different types of objectClasses */
372 foreach($possibleAccounts as $objectClass => $Settigns){
373 if(in_array($objectClass ,$val['objectClass'])){
374 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
375 }else{
376 $$Settigns['VAR'] = $empty;
377 }
378 }
380 /* Create userimg */
381 if(in_array("gosaUserTemplate",$val['objectClass'])){
382 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
383 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
384 $num_templates ++;
385 }else{
386 $s_img_create_from_template = "";
387 $tpl = $userimg;
388 $num_users ++;
389 }
391 /* Insert key into userimg */
392 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
394 // Generate caption for rows
395 if (isset($val["sn"]) && isset($val["givenName"])){
396 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
397 } else {
398 $display= "[".$val["uid"][0]."]";
399 }
401 /* Connect all images */
402 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
404 /* Cutted objects should be displayed in light grey */
405 if($this->parent->CopyPasteHandler){
406 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
407 if($queue_data['dn'] == $val['dn']) {
408 $display = "<font color='#999999'>".$display."</font>";
409 break;
410 }
411 }
412 }
414 /* Create each field */
415 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
416 "attach" => "style='width:20px;'");
417 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
418 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
419 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
420 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
421 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
422 /* Add to list */
423 $add = array($field0,$field1,$field2,$field3,$field4);
424 $this->AddElement($add);
426 // Template or User
427 if(in_array("gosaUserTemplate",$val['objectClass'])){
428 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
429 }else{
430 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
431 }
432 }
435 /* Create summary string for list footer */
436 $num_deps=0;
437 if(!$this->SubSearch){
438 $num_deps = count($this->Added_Departments);
439 }
440 $num_users = count($list);
442 $num_user_str = _("Number of listed users");
443 $num_dep_str = _("Number of listed departments");
445 $str = "<img class='center' src='images/select_user.png'
446 title='".$num_user_str."' alt='".$num_user_str."'> ".$num_users." ";
447 $str.= "<img class='center' src='images/folder.png'
448 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
450 $this->set_List_Bottom_Info($str);
451 }
453 function Save()
454 {
455 MultiSelectWindow :: Save();
456 }
458 function save_object()
459 {
460 /* Save automatic created POSTs like regex, checkboxes */
461 MultiSelectWindow::save_object();
462 }
463 }
464 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
465 ?>