Code

Updated user Management
[gosa.git] / gosa-core / plugins / admin / users / class_divListUsers.inc
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");
50     
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();
60     $this->SetInformation(_("This menu allows you to create, edit and delete selected users. Having a great number of users, you may want to use the range selectors on top of the user list."));
62     $this->EnableAplhabet   (true);
63   
64     /* Disable buttonsm */
65     $this->EnableCloseButton(false);
66     $this->EnableSaveButton (false);
68     /* Dynamic action col, depending on snapshot icons */
69     $action_col_size = 122;
70     if($this->parent->snapshotEnabled()){
71       $action_col_size += 38;
72     }
74     /* Toggle all selected / deselected */
75     $chk = "<input type='checkbox' id='select_all' name='select_all' 
76                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
78     /* set Page header */
79     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
80     $this->AddHeader(array("string"=> "&nbsp;",          "attach"=>"style='width:20px;'"));
81     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
82     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
83     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
84     
85     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
86     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
87     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
88     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
89     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
90     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
92     /* Add SubSearch checkbox */
93     $this->AddCheckBox(SEPERATOR);
94     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
96     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
97     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
98   }
101   function GenHeader()
102   {
103     /* Prepare departments,
104        which are shown in the listbox on top of the listbox
105      */
106     $options= "";
108     /* Get all departments within this subtree */ 
109     $base = $this->config->current['BASE'];
111     /* Add base */
112     $tmp = array();
113     $tmp[] = array("dn"=>$this->config->current['BASE']);
114     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
115                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
116     
117     $deps = array();
118     foreach($tmp as $tm){
119       $deps[$tm['dn']] = $tm['dn'];
120     }    
123     /* Load possible departments */
124     $ui= get_userinfo();
125     $tdeps= $ui->get_module_departments("users");
126     $ids = $this->config->idepartments;
127     $first = "";
128     $found = FALSE;
129     foreach($ids as $dep => $name){
130       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
132         /* Keep first base dn in mind, we could need this
133          *  info if no valid base was found
134          */
135         if(empty($first)) {
136           $first = $dep['dn'];
137         }
139         $value = $ids[$dep]; 
140         if ($this->selectedBase == $dep){
141           $found = TRUE;
142           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
143         } else {
144           $options.= "<option value='".$dep."'>$value</option>";
145         }
146       }
147     }
149     /* The currently used base is not visible with your acl setup.
150      * Set base to first useable base. 
151      */
152     if(!$found){
153       $this->selectedBase = $first;
154     }
156     /* Get copy & paste icon */
157     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
158     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
160     /* Add default header */
161     $listhead = MultiSelectWindow::get_default_header();
162     $listhead .=
163       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
164       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
165       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
168     /* Create Layers menu */
169     $s  = ".|"._("Actions")."|\n";
170     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
171       "&nbsp;"._("Create")."|\n";
173     /* Append create options */
174     if(preg_match("/c/",$acl)) {
175       $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
176         "&nbsp;"._("User")."|user_new|\n";
177       $s.= "...|<input class='center' type='image' src='images/list_new.png' alt=''>".
178         "&nbsp;"._("Template")."|user_tplnew|\n";
179     }
181     /* Multiple options */ 
182     $s.= "..|---|\n";
183     $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
184       "&nbsp;"._("Edit")."|"."multiple_edit|\n";
185     $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
186       "&nbsp;"._("Change password")."|"."multiple_password_change|\n";
187     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
188       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
190     /* Add event tag */
191     if(class_available("DaemonEvent")){
192       $events  = DaemonEvent::get_event_types(USER_EVENT);
193       if(count($events['BY_CLASS'])){
194         $s.= "..|---|\n";
195         foreach($events['BY_CLASS'] as $name => $event){
196           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
197         }
198       }
199     }
201     /* Add multiple copy & cut icons */
202     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
203       $s.= "..|---|\n";
204       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
205         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
206       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
207         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
208       
209       if($this->parent->CopyPasteHandler->entries_queued()){
210         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
211         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
212       }else{
213         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
214         $s.="..|".$img."&nbsp;"._("Paste")."\n";
215       }
216     }
218     /* Add snapshot icons */
219     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
220       $s .= "..|---|\n";
221       $s .= $this->get_snapshot_header(TRUE);
222     }
224     $this->SetDropDownHeaderMenu($s);
225     $this->SetListHeader($listhead);
226   }
228   /* so some basic settings */
229   function execute()
230   {
231     $this->ClearElementsList();
232     $this->GenHeader();
233   }
235   function setEntries($list)
236   {
237     /********************
238       Variable init
239      ********************/
240     
241     $num_users      = 0;
242     $num_templates  = 0;
244     /* Variable initialation */
245     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
246     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
247     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
248     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
249     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
251     /* Dynamic action col, depending on snapshot icons */
252     $action_col_size = 122;
253     if($this->parent->snapshotEnabled()){
254       $action_col_size += 38;
255     }
257     /* Possilbe objectClass image combinations */  
258     $possibleAccounts = array(
259             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
260             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
261             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
262             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
263             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
264             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
266      /* Pictures for Extensions */
267     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
268                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
269     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
270                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
271     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
272                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
273     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
274                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
275     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
276                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
277     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
278                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
279     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
280                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
281     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
282                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
283     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
284                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
286     /********************
287       END :: Variable init
288      ********************/
290  
291     /********************
292       Append entries to divlist 
293      ********************/
294  
295     $ui = get_userinfo(); 
296   
297     // Test Every Entry and generate divlist Array
298     foreach($list as $key => $val){
299   
300       /* Create action icons */
301       $action= "";
303       /* Add copy & cut icons */     
304       $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
305       $acl      = $ui->get_permissions($val['dn'],"users/user");
306       if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
307         $action .= "<input class='center' type='image'
308           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
309         $action.= "<input class='center' type='image'
310           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
311       }
313       /* Add deactivate status */
314       $lock_status = "";
316       if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
317         if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
318           $lock_status = "<input class='center' type='image' src='images/closedlock.png'
319             alt='"._("Deactivated")."' name='toggle_lock_status_%KEY%'>";
320         }else{
321           $lock_status = "<input class='center' type='image' src='images/openlock.png'
322             alt='"._("Active")."' name='toggle_lock_status_%KEY%'>";
323         }
324       }else{
325         $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
326       }
328       /* Generate edit icon */
329       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
330         name='user_edit_%KEY%' title='"._("Edit user")."'>";
332       /* Add deactivate status if we are allowed to */
333       if (preg_match("/w/",$acl_all)){
334         $action.= $lock_status;
335       }
337       /* Add Password change icon, if we are able to write users/password */
338       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
339         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
340           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
341       }else{
342         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
343           title='"._("You are not allowed to change the password for this user.")."'>";
344       }
346       /* Add snapshot icon */
347       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
348         $action.= $this->GetSnapShotActions($val['dn']);
349       }
351       /* Add remove icon, if we are allowed to remove the current user */
352       if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
353         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
354           name='user_del_%KEY%' title='"._("Delete user")."'>";
355       }else{
356         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
357           title='"._("You are not allowed to remove this user.")."'>";
358       }
360       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
361       if((in_array("goFonAccount"    ,$val['objectClass']))){
363         /* Set defaults */
364         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
365         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
366         $fonac = preg_replace("/%title%/", "", $fonac);
368       }else{
369         $fonac=$empty;
370       }
372       /* Set images for different types of objectClasses */
373       foreach($possibleAccounts as $objectClass => $Settigns){ 
374         if(in_array($objectClass ,$val['objectClass'])){
375           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
376         }else{
377           $$Settigns['VAR'] = $empty;
378         }
379       }
381       /* Create userimg */
382       if(in_array("gosaUserTemplate",$val['objectClass'])){
383         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
384         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
385         $num_templates ++;
386       }else{
387         $s_img_create_from_template   = "";
388         $tpl                          = $userimg;
389         $num_users ++;
390       }
392       /* Insert key into userimg */
393       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
395       // Generate caption for rows
396       if (isset($val["sn"]) && isset($val["givenName"])){
397         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
398       } else {
399         $display= "[".$val["uid"][0]."]";
400       }
402       /* Connect all images */
403       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
405       /* Cutted objects should be displayed in light grey */ 
406       if($this->parent->CopyPasteHandler){
407         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
408           if($queue_data['dn'] == $val['dn']) {
409             $display = "<font color='#999999'>".$display."</font>";
410             break;
411           }
412         }
413       }
415       /* Create each field */
416       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
417                       "attach" => "style='width:20px;'");
418       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
419       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
420       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
421       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
422                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
423       /* Add to list */
424       $add = array($field0,$field1,$field2,$field3,$field4);
425       $this->AddElement($add);
427       // Template or User
428       if(in_array("gosaUserTemplate",$val['objectClass'])){
429         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
430       }else{
431         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
432       }
433     }
436     /* Create summary string for list footer */
437     $num_deps=0;
438     if(!$this->SubSearch){
439       $num_deps = count($this->Added_Departments);
440     }
441     $num_users = count($list);
443     $num_user_str = _("Number of listed users");
444     $num_dep_str = _("Number of listed departments");
446     $str = "<img class='center' src='images/select_user.png'
447               title='".$num_user_str."' alt='".$num_user_str."'>&nbsp;".$num_users."&nbsp;&nbsp;&nbsp;&nbsp;";
448     $str.= "<img class='center' src='images/folder.png'
449               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
451     $this->set_List_Bottom_Info($str);
452   }
454   function Save()
455   {
456     MultiSelectWindow :: Save();  
457   }
459   function save_object()
460   {
461     /* Save automatic created POSTs like regex, checkboxes */
462     MultiSelectWindow::save_object();   
463   }
465 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
466 ?>