Code

Fixed base in management divLists.
[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 = 104;
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"), _("Ignore 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     $deps[] = array("dn"=>$this->config->current['BASE']);
93     $deps= array_merge($deps,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
94                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
96     /* Load possible departments */
97     $ui= get_userinfo();
98     $tdeps= $ui->get_module_departments("users");
99     $ids = $this->config->idepartments;
100     $first = "";
101     $found = FALSE;
102     foreach($deps as $dep){
103       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
105         /* Keep first base dn in mind, we could need this
106          *  info if no valid base was found
107          */
108         if(empty($first)) {
109           $first = $dep['dn'];
110         }
112         $value = $ids[$dep['dn']]; 
113         if ($this->selectedBase == $dep['dn']){
114           $found = TRUE;
115           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
116         } else {
117           $options.= "<option value='".$dep['dn']."'>$value</option>";
118         }
119       }
120     }
122     /* The currently used base is not visible with your acl setup.
123      * Set base to first useable base. 
124      */
125     if(!$found){
126       $this->selectedBase = $first;
127     }
129     /* Get copy & paste icon */
130     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
131     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
132     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
133       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
134     }else{
135       $Copy_Paste ="";
136     }
138     /* Add default header */
139     $listhead = MultiSelectWindow::get_default_header();
140     
141     if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
142       $listhead .= $this->get_snapshot_header($this->selectedBase);
143     }
145     if(preg_match("/c/",$acl)) {
146       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
147         title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;";
148       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png' 
149         title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;";
150     }
152     $listhead .= $Copy_Paste;
153     
154     $listhead .=
155       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
156       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
157       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
159   
160     /* Multiple options */ 
161     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
162         title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
163     
164     $listhead .="</div>";;
165     $this->SetListHeader($listhead);
166   }
168   /* so some basic settings */
169   function execute()
170   {
171     $this->ClearElementsList();
172     $this->GenHeader();
173   }
175   function setEntries($list)
176   {
177     /********************
178       Variable init
179      ********************/
181     /* Variable initialation */
182     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
183     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
184     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
185     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
186     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
188     /* Dynamic action col, depending on snapshot icons */
189     $action_col_size = 104;
190     if($this->parent->snapshotEnabled()){
191       $action_col_size += 38;
192     }
194     /* Possilbe objectClass image combinations */  
195     $possibleAccounts = array(
196             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
197             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
198             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
199             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
200             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
201             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
203      /* Pictures for Extensions */
204     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
205                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
206     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
207                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
208     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
209                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
210     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
211                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
212     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
213                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
214     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
215                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
216     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
217                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
218     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
219                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
220     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
221                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
223     /********************
224       END :: Variable init
225      ********************/
227  
228     /********************
229       Append entries to divlist 
230      ********************/
231  
232     $ui = get_userinfo(); 
233   
234     // Test Every Entry and generate divlist Array
235     foreach($list as $key => $val){
237       /* Create action icons */
238       $action= "";
240       /* Add copy & cut icons */     
241       $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
242       $acl      = $ui->get_permissions($val['dn'],"users/user");
243       if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
244         $action .= "<input class='center' type='image'
245           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
246         $action.= "<input class='center' type='image'
247           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
248       }
250       /* Generate edit icon */
251       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
252         name='user_edit_%KEY%' title='"._("Edit user")."'>";
254       /* Add Password change icon, if we are able to write users/password */
255       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
256         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
257           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
258       }else{
259         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
260           title='"._("You are not allowed to change the password for this user.")."'>";
261       }
263       /* Add snapshot icon */
264       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
265         $action.= $this->GetSnapShotActions($val['dn']);
266       }
268       /* Add remove icon, if we are allowed to remove the current user */
269       if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
270         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
271           name='user_del_%KEY%' title='"._("Delete user")."'>";
272       }else{
273         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
274           title='"._("You are not allowed to remove this user.")."'>";
275       }
277       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
278       if((in_array("goFonAccount"    ,$val['objectClass']))){
280         /* Set defaults */
281         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
282         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
283         $fonac = preg_replace("/%title%/", "", $fonac);
285       }else{
286         $fonac=$empty;
287       }
289       /* Set images for different types of objectClasses */
290       foreach($possibleAccounts as $objectClass => $Settigns){ 
291         if(in_array($objectClass ,$val['objectClass'])){
292           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
293         }else{
294           $$Settigns['VAR'] = $empty;
295         }
296       }
298       /* Create userimg */
299       if(in_array("gosaUserTemplate",$val['objectClass'])){
300         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
301         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
302       }else{
303         $s_img_create_from_template   = "";
304         $tpl                          = $userimg;
305       }
307       /* Insert key into userimg */
308       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
310       // Generate caption for rows
311       if (isset($val["sn"]) && isset($val["givenName"])){
312         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
313       } else {
314         $display= "[".$val["uid"][0]."]";
315       }
317       /* Connect all images */
318       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
320       /* Create each field */
321       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
322                       "attach" => "style='width:20px;'");
323       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
324       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
325       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
326       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
327                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
328       /* Add to list */
329       $add = array($field0,$field1,$field2,$field3,$field4);
330       $this->AddElement($add);
332       // Template or User
333       if(in_array("gosaUserTemplate",$val['objectClass'])){
334         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
335       }else{
336         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
337       }
338     }
339     
340   }
342   function Save()
343   {
344     MultiSelectWindow :: Save();  
345   }
347   function save_object()
348   {
349     /* Save automatic created POSTs like regex, checkboxes */
350     MultiSelectWindow::save_object();   
351   }
353 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
354 ?>