Code

Fixed locking
[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"=>_("Username")." / "._("Department")));
61     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
62     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
63     
64     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
65     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
66     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
67     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
68     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
69     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
71     /* Add SubSearch checkbox */
72     $this->AddCheckBox(SEPERATOR);
73     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
75     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
76     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
77   }
80   function GenHeader()
81   {
82     /* Prepare departments,
83        which are shown in the listbox on top of the listbox
84      */
85     $options= "";
87     /* Get all departments within this subtree */ 
88     $base = $this->config->current['BASE'];
89     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
90                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
92     /* Load possible departments */
93     $ui= get_userinfo();
94     $tdeps= $ui->get_module_departments("users");
95     $ids = $this->config->idepartments;
96     foreach($deps as $dep){
97       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
98         $value = $ids[$dep['dn']]; 
99         if ($this->selectedBase == $dep['dn']){
100           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
101         } else {
102           $options.= "<option value='".$dep['dn']."'>$value</option>";
103         }
104       }
105     }
107     /* Get copy & paste icon */
108     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
109     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
110     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
111       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
112     }else{
113       $Copy_Paste ="";
114     }
116     /* Add default header */
117     $listhead = MultiSelectWindow::get_default_header();
118     
119     if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
120       $listhead .= $this->get_snapshot_header($this->selectedBase);
121     }
123     if(preg_match("/c/",$acl)) {
124       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
125         title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;";
126       $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png' 
127         title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;";
128     }
130     $listhead .= $Copy_Paste;
131     
132     $listhead .=
133       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
134       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
135       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
137   
138     /* Multiple options */ 
139     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
140         title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_user'>&nbsp;";
141     
142     $listhead .="</div>";;
143     $this->SetListHeader($listhead);
144   }
146   /* so some basic settings */
147   function execute()
148   {
149     $this->ClearElementsList();
150     $this->GenHeader();
151   }
153   function setEntries($list)
154   {
155     /********************
156       Variable init
157      ********************/
159     /* Variable initialation */
160     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
161     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
162     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
163     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
164     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
166     /* Dynamic action col, depending on snapshot icons */
167     $action_col_size = 104;
168     if($this->parent->snapshotEnabled()){
169       $action_col_size += 38;
170     }
172     /* Possilbe objectClass image combinations */  
173     $possibleAccounts = array(
174             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
175             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
176             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
177             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
178             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
179             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
181      /* Pictures for Extensions */
182     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
183                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
184     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
185                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
186     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
187                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
188     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
189                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
190     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
191                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
192     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
193                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
194     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
195                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
196     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
197                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
198     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
199                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
201     /********************
202       END :: Variable init
203      ********************/
205  
206     /********************
207       Append entries to divlist 
208      ********************/
209  
210     $ui = get_userinfo(); 
211   
212     // Test Every Entry and generate divlist Array
213     foreach($list as $key => $val){
215       /* Create action icons */
216       $action= "";
218       /* Add copy & cut icons */     
219       $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
220       $acl      = $ui->get_permissions($val['dn'],"users/user");
221       if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
222         $action .= "<input class='center' type='image'
223           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
224         $action.= "<input class='center' type='image'
225           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
226       }
228       /* Generate edit icon */
229       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
230         name='user_edit_%KEY%' title='"._("Edit user")."'>";
232       /* Add Password change icon, if we are able to write users/password */
233       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
234         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
235           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
236       }else{
237         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
238           title='"._("You are not allowed to change the password for this user.")."'>";
239       }
241       /* Add snapshot icon */
242       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
243         $action.= $this->GetSnapShotActions($val['dn']);
244       }
246       /* Add remove icon, if we are allowed to remove the current user */
247       if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
248         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
249           name='user_del_%KEY%' title='"._("Delete user")."'>";
250       }else{
251         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
252           title='"._("You are not allowed to remove this user.")."'>";
253       }
255       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
256       if((in_array("goFonAccount"    ,$val['objectClass']))){
258         /* Set defaults */
259         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
260         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
261         $fonac = preg_replace("/%title%/", "", $fonac);
263       }else{
264         $fonac=$empty;
265       }
267       /* Set images for different types of objectClasses */
268       foreach($possibleAccounts as $objectClass => $Settigns){ 
269         if(in_array($objectClass ,$val['objectClass'])){
270           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
271         }else{
272           $$Settigns['VAR'] = $empty;
273         }
274       }
276       /* Create userimg */
277       if(in_array("gosaUserTemplate",$val['objectClass'])){
278         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
279         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
280       }else{
281         $s_img_create_from_template   = "";
282         $tpl                          = $userimg;
283       }
285       /* Insert key into userimg */
286       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
288       // Generate caption for rows
289       if (isset($val["sn"]) && isset($val["givenName"])){
290         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
291       } else {
292         $display= "[".$val["uid"][0]."]";
293       }
295       /* Connect all images */
296       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
298       /* Create each field */
299       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."' >");
300       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
301       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
302       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
303       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
304                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
305       /* Add to list */
306       $add = array($field0,$field1,$field2,$field3,$field4);
307       $this->AddElement($add);
309       // Template or User
310       if(in_array("gosaUserTemplate",$val['objectClass'])){
311         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
312       }else{
313         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
314       }
315     }
316     
317   }
319   function Save()
320   {
321     MultiSelectWindow :: Save();  
322   }
324   function save_object()
325   {
326     /* Save automatic created POSTs like regex, checkboxes */
327     MultiSelectWindow::save_object();   
328   }
330 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
331 ?>