Code

f22979edf3b35b560a59bf1473eff2804813b394
[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     $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   
167     /* Multiple options */ 
168     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
169         title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
170     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
171         title='"._("Copy selected user")."' alt='"._("Copy users")."' name='multiple_copy_users'>&nbsp;";
172     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
173         title='"._("cut selected user")."' alt='"._("Cut users")."' name='multiple_cut_users'>&nbsp;";
175     $listhead .="</div>";;
176     $this->SetListHeader($listhead);
177   }
179   /* so some basic settings */
180   function execute()
181   {
182     $this->ClearElementsList();
183     $this->GenHeader();
184   }
186   function setEntries($list)
187   {
188     /********************
189       Variable init
190      ********************/
192     /* Variable initialation */
193     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
194     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
195     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
196     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
197     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
199     /* Dynamic action col, depending on snapshot icons */
200     $action_col_size = 104;
201     if($this->parent->snapshotEnabled()){
202       $action_col_size += 38;
203     }
205     /* Possilbe objectClass image combinations */  
206     $possibleAccounts = array(
207             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
208             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
209             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
210             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
211             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
212             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
214      /* Pictures for Extensions */
215     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
216                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
217     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
218                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
219     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
220                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
221     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
222                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
223     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
224                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
225     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
226                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
227     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
228                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
229     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
230                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
231     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
232                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
234     /********************
235       END :: Variable init
236      ********************/
238  
239     /********************
240       Append entries to divlist 
241      ********************/
242  
243     $ui = get_userinfo(); 
244   
245     // Test Every Entry and generate divlist Array
246     foreach($list as $key => $val){
248       /* Create action icons */
249       $action= "";
251       /* Add copy & cut icons */     
252       $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"users") ;
253       $acl      = $ui->get_permissions($val['dn'],"users/user");
254       if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
255         $action .= "<input class='center' type='image'
256           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
257         $action.= "<input class='center' type='image'
258           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
259       }
261       /* Generate edit icon */
262       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
263         name='user_edit_%KEY%' title='"._("Edit user")."'>";
265       /* Add Password change icon, if we are able to write users/password */
266       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
267         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
268           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
269       }else{
270         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
271           title='"._("You are not allowed to change the password for this user.")."'>";
272       }
274       /* Add snapshot icon */
275       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
276         $action.= $this->GetSnapShotActions($val['dn']);
277       }
279       /* Add remove icon, if we are allowed to remove the current user */
280       if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
281         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
282           name='user_del_%KEY%' title='"._("Delete user")."'>";
283       }else{
284         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
285           title='"._("You are not allowed to remove this user.")."'>";
286       }
288       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
289       if((in_array("goFonAccount"    ,$val['objectClass']))){
291         /* Set defaults */
292         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
293         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
294         $fonac = preg_replace("/%title%/", "", $fonac);
296       }else{
297         $fonac=$empty;
298       }
300       /* Set images for different types of objectClasses */
301       foreach($possibleAccounts as $objectClass => $Settigns){ 
302         if(in_array($objectClass ,$val['objectClass'])){
303           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
304         }else{
305           $$Settigns['VAR'] = $empty;
306         }
307       }
309       /* Create userimg */
310       if(in_array("gosaUserTemplate",$val['objectClass'])){
311         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
312         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
313       }else{
314         $s_img_create_from_template   = "";
315         $tpl                          = $userimg;
316       }
318       /* Insert key into userimg */
319       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
321       // Generate caption for rows
322       if (isset($val["sn"]) && isset($val["givenName"])){
323         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
324       } else {
325         $display= "[".$val["uid"][0]."]";
326       }
328       /* Connect all images */
329       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
331       /* Create each field */
332       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
333                       "attach" => "style='width:20px;'");
334       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
335       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
336       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
337       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
338                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
339       /* Add to list */
340       $add = array($field0,$field1,$field2,$field3,$field4);
341       $this->AddElement($add);
343       // Template or User
344       if(in_array("gosaUserTemplate",$val['objectClass'])){
345         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
346       }else{
347         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
348       }
349     }
350     
351   }
353   function Save()
354   {
355     MultiSelectWindow :: Save();  
356   }
358   function save_object()
359   {
360     /* Save automatic created POSTs like regex, checkboxes */
361     MultiSelectWindow::save_object();   
362   }
364 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
365 ?>