Code

Updated user list, allow multiple password changes.
[gosa.git] / plugins / admin / users / class_divListUsers.inc
1 <?php
3 class divListUsers extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
13   /* CheckBoxes */
14   var $ShowTemplates ;
15   var $ShowFunctionalUsers;
16   var $ShowUnixUsers;
17   var $ShowMailUsers;
18   var $ShowSambaUsers;
19   var $ShowProxyUsers;
21   /* Subsearch checkbox */
22   var $SubSearch              = false;
24   var $parent             ;
25   var $ui                 ;
27   function divListUsers ($config,$parent)
28   {
29     MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
30     
31     $this->parent       = $parent;
32     $this->ui           = get_userinfo();
34     /* Set list strings */
35     $this->SetTitle(_("List of users"));
36     $this->SetSummary(_("List of users"));
38     /* Result page will look like a headpage */
39     $this->SetHeadpageMode();
40     $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."));
42     $this->EnableAplhabet   (true);
43   
44     /* Disable buttonsm */
45     $this->EnableCloseButton(false);
46     $this->EnableSaveButton (false);
48     /* Dynamic action col, depending on snapshot icons */
49     $action_col_size = 122;
50     if($this->parent->snapshotEnabled()){
51       $action_col_size += 38;
52     }
54     /* Toggle all selected / deselected */
55     $chk = "<input type='checkbox' id='select_all' name='select_all' 
56                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
58     /* set Page header */
59     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
60     $this->AddHeader(array("string"=> "&nbsp;",          "attach"=>"style='width:20px;'"));
61     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
62     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
63     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
64     
65     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
66     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
67     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
68     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
69     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
70     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
72     /* Add SubSearch checkbox */
73     $this->AddCheckBox(SEPERATOR);
74     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
76     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
77     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
78   }
81   function GenHeader()
82   {
83     /* Prepare departments,
84        which are shown in the listbox on top of the listbox
85      */
86     $options= "";
88     /* Get all departments within this subtree */ 
89     $base = $this->config->current['BASE'];
91     /* Add base */
92     $tmp = array();
93     $tmp[] = array("dn"=>$this->config->current['BASE']);
94     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
95                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
96     
97     $deps = array();
98     foreach($tmp as $tm){
99       $deps[$tm['dn']] = $tm['dn'];
100     }    
103     /* Load possible departments */
104     $ui= get_userinfo();
105     $tdeps= $ui->get_module_departments("users");
106     $ids = $this->config->idepartments;
107     $first = "";
108     $found = FALSE;
109     foreach($ids as $dep => $name){
110       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
112         /* Keep first base dn in mind, we could need this
113          *  info if no valid base was found
114          */
115         if(empty($first)) {
116           $first = $dep['dn'];
117         }
119         $value = $ids[$dep]; 
120         if ($this->selectedBase == $dep){
121           $found = TRUE;
122           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
123         } else {
124           $options.= "<option value='".$dep."'>$value</option>";
125         }
126       }
127     }
129     /* The currently used base is not visible with your acl setup.
130      * Set base to first useable base. 
131      */
132     if(!$found){
133       $this->selectedBase = $first;
134     }
136     /* Get copy & paste icon */
137     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
138     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
139     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
140       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
141     }else{
142       $Copy_Paste ="";
143     }
145     /* Add default header */
146     $listhead = MultiSelectWindow::get_default_header();
147     
148     if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
149       $listhead .= $this->get_snapshot_header($this->selectedBase);
150     }
152     if(preg_match("/c/",$acl)) {
153       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
154         title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;";
155       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png' 
156         title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;";
157     }
159     $listhead .= $Copy_Paste;
160     
161     $listhead .=
162       _("Base")."&nbsp;<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")."'>&nbsp;";
166     /* Multiple options */ 
167     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
168         title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
169     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/list_password.png'
170         title='"._("Change password")."' alt='"._("Change password")."' name='multiple_password_change'>&nbsp;";
172     /* Add multiple copy & cut icons */
173     if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
174       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
175         title='"._("Copy selected user")."' alt='"._("Copy users")."' name='multiple_copy_users'>&nbsp;";
176       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
177         title='"._("cut selected user")."' alt='"._("Cut users")."' name='multiple_cut_users'>&nbsp;";
178     }
180     $listhead .="</div>";;
181     $this->SetListHeader($listhead);
182   }
184   /* so some basic settings */
185   function execute()
186   {
187     $this->ClearElementsList();
188     $this->GenHeader();
189   }
191   function setEntries($list)
192   {
193     /********************
194       Variable init
195      ********************/
196     
197     $num_users      = 0;
198     $num_templates  = 0;
200     /* Variable initialation */
201     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
202     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
203     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
204     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
205     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
207     /* Dynamic action col, depending on snapshot icons */
208     $action_col_size = 122;
209     if($this->parent->snapshotEnabled()){
210       $action_col_size += 38;
211     }
213     /* Possilbe objectClass image combinations */  
214     $possibleAccounts = array(
215             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
216             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
217             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
218             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
219             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
220             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
222      /* Pictures for Extensions */
223     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
224                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
225     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
226                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
227     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
228                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
229     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
230                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
231     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
232                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
233     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
234                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
235     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
236                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
237     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
238                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
239     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
240                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
242     /********************
243       END :: Variable init
244      ********************/
246  
247     /********************
248       Append entries to divlist 
249      ********************/
250  
251     $ui = get_userinfo(); 
252   
253     // Test Every Entry and generate divlist Array
254     foreach($list as $key => $val){
255   
256       /* Create action icons */
257       $action= "";
259       /* Add copy & cut icons */     
260       $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
261       $acl      = $ui->get_permissions($val['dn'],"users/user");
262       if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
263         $action .= "<input class='center' type='image'
264           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
265         $action.= "<input class='center' type='image'
266           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
267       }
269       /* Add deactivate status */
270       $lock_status = "";
272       if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
273         if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
274           $lock_status = "<input class='center' type='image' src='images/closedlock.png'
275             alt='"._("Deactivated")."' name='toggle_lock_status_%KEY%'>";
276         }else{
277           $lock_status = "<input class='center' type='image' src='images/openlock.png'
278             alt='"._("Active")."' name='toggle_lock_status_%KEY%'>";
279         }
280       }else{
281         $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
282       }
284       /* Generate edit icon */
285       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
286         name='user_edit_%KEY%' title='"._("Edit user")."'>";
288       /* Add deactivate status if we are allowed to */
289       if (preg_match("/w/",$acl_all)){
290         $action.= $lock_status;
291       }
293       /* Add Password change icon, if we are able to write users/password */
294       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
295         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
296           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
297       }else{
298         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
299           title='"._("You are not allowed to change the password for this user.")."'>";
300       }
302       /* Add snapshot icon */
303       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
304         $action.= $this->GetSnapShotActions($val['dn']);
305       }
307       /* Add remove icon, if we are allowed to remove the current user */
308       if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
309         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
310           name='user_del_%KEY%' title='"._("Delete user")."'>";
311       }else{
312         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
313           title='"._("You are not allowed to remove this user.")."'>";
314       }
316       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
317       if((in_array("goFonAccount"    ,$val['objectClass']))){
319         /* Set defaults */
320         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
321         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
322         $fonac = preg_replace("/%title%/", "", $fonac);
324       }else{
325         $fonac=$empty;
326       }
328       /* Set images for different types of objectClasses */
329       foreach($possibleAccounts as $objectClass => $Settigns){ 
330         if(in_array($objectClass ,$val['objectClass'])){
331           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
332         }else{
333           $$Settigns['VAR'] = $empty;
334         }
335       }
337       /* Create userimg */
338       if(in_array("gosaUserTemplate",$val['objectClass'])){
339         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
340         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
341         $num_templates ++;
342       }else{
343         $s_img_create_from_template   = "";
344         $tpl                          = $userimg;
345         $num_users ++;
346       }
348       /* Insert key into userimg */
349       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
351       // Generate caption for rows
352       if (isset($val["sn"]) && isset($val["givenName"])){
353         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
354       } else {
355         $display= "[".$val["uid"][0]."]";
356       }
358       /* Connect all images */
359       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
361       /* Cutted objects should be displayed in light grey */ 
362       if($this->parent->CopyPasteHandler){
363         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
364           if($queue_data['dn'] == $val['dn']) {
365             $display = "<font color='#999999'>".$display."</font>";
366             break;
367           }
368         }
369       }
371       /* Create each field */
372       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
373                       "attach" => "style='width:20px;'");
374       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
375       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
376       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
377       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
378                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
379       /* Add to list */
380       $add = array($field0,$field1,$field2,$field3,$field4);
381       $this->AddElement($add);
383       // Template or User
384       if(in_array("gosaUserTemplate",$val['objectClass'])){
385         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
386       }else{
387         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
388       }
389     }
392     /* Create summary string for list footer */
393     $num_deps=0;
394     if(!$this->SubSearch){
395       $num_deps = count($this->Added_Departments);
396     }
397     $num_users = count($list);
399     $num_user_str = _("Number of listed users");
400     $num_dep_str = _("Number of listed departments");
402     $str = "<img class='center' src='images/select_user.png'
403               title='".$num_user_str."' alt='".$num_user_str."'>&nbsp;".$num_users."&nbsp;&nbsp;&nbsp;&nbsp;";
404     $str.= "<img class='center' src='images/folder.png'
405               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
407     $this->set_List_Bottom_Info($str);
408   }
410   function Save()
411   {
412     MultiSelectWindow :: Save();  
413   }
415   function save_object()
416   {
417     /* Save automatic created POSTs like regex, checkboxes */
418     MultiSelectWindow::save_object();   
419   }
421 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
422 ?>