Code

Updated Winstation save:
[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");
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     /* set Page header */
49     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
50     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
51     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:152px;'"));
52     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:102px;border-right:0px;text-align:right;'"));
53     
54     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
55     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
56     $this->AddCheckBox("ShowUnixUsers"      ,_("Select to see users that have posix settings")      ,_("Show unix users")       , true);
57     $this->AddCheckBox("ShowMailUsers"      ,_("Select to see users that have mail settings")       ,_("Show mail users")       , true);
58     $this->AddCheckBox("ShowSambaUsers"     ,_("Select to see users that have samba settings")      ,_("Show samba users")      , true);
59     $this->AddCheckBox("ShowProxyUsers"     ,_("Select to see users that have proxy settings")      ,_("Show proxy users")      , true);
61     /* Add SubSearch checkbox */
62     $this->AddCheckBox(SEPERATOR);
63     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
65     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
66     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
67   }
69   function GenHeader()
70   {
71     /* Prepare departments,
72        which are shown in the listbox on top of the listbox
73      */
74     $options= "";
75     foreach ($this->config->idepartments as $key => $value){
76       if ($this->selectedBase == $key){
77         $options.= "<option selected='selected' value='$key'>$value</option>";
78       } else {
79         $options.= "<option value='$key'>$value</option>";
80       }
81     }
83     /* Get copy & paste icon */ 
84     if($this->parent->CopyPasteHandler){
85       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
86     }else{
87       $Copy_Paste ="";
88     }
90     /* Add default header */
91     $listhead = MultiSelectWindow::get_default_header();
93     $listhead.= " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
94       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
95       " <input class='center' type='image' align='middle' src='images/list_new.png' 
96       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
97       $Copy_Paste.
98       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
99       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
100       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
101       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
102       "</div>";
104     $this->SetListHeader($listhead);
105   }
107   /* so some basic settings */
108   function execute()
109   {
110     $this->ClearElementsList();
111     $this->GenHeader();
112   }
114   function setEntries($list)
115   {
116     /********************
117       Variable init
118      ********************/
120     /* Variable initialation */
121     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
122     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
123     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
124     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
125     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
127     /* Possilbe objectClass image combinations */  
128     $possibleAccounts = array(
129             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
130             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
131             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
132             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
133             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
134             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
136      /* Pictures for Extensions */
137     $usrimg   ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
138                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
139     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
140                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
141     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
142                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
143     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
144                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
145     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
146                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
147     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
148                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
149     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
150                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
151     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
152                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
153     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
154                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
156     /********************
157       END :: Variable init
158      ********************/
160  
161     /********************
162       Append entries to divlist 
163      ********************/
164  
165     // Test Every Entry and generate divlist Array
166     foreach($list as $key => $val){
168       /* Create action icons */
169       $action = "";
171       $dn= $val['dn'];
172       $acl= get_permissions ($dn, $this->ui->subtreeACL);
173       $acl= get_module_permission($acl, "user", $dn);
175       /* Append copy&paste icons if allowed */
176       if($acl == "#all#" && $this->parent->CopyPasteHandler){
177         $action .= "<input class='center' type='image'
178           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
179         $action.= "<input class='center' type='image'
180           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
181       }
183       /* Add edit icon */
184       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
185         name='user_edit_%KEY%' title='"._("Edit user")."'>";
187       /* Add passowrd change icon if allowed */
188       if (chkacl($acl, "password") == ""){
189         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
190           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
191       }
193       /* Add delete icon if delete user is allowed */
194       if (chkacl($acl, "delete") == ""){
195         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
196           name='user_del_%KEY%' title='"._("Delete user")."'>";
197       }
199       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
200       if((in_array("goFonAccount"    ,$val['objectClass']))){
202         /* Set defaults */
203         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
204         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
205         $fonac = preg_replace("/%title%/", "", $fonac);
207       }else{
208         $fonac=$empty;
209       }
211       /* Set images for different types of objectClasses */
212       foreach($possibleAccounts as $objectClass => $Settigns){ 
213         if(in_array($objectClass ,$val['objectClass'])){
214           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
215         }else{
216           $$Settigns['VAR'] = $empty;
217         }
218       }
220       /* Create userimg */
221       if(in_array("gosaUserTemplate",$val['objectClass'])){
222         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
223         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
224       }else{
225         $s_img_create_from_template   = "";
226         $tpl                          = $userimg;
227       }
229       /* Insert key into userimg */
230       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
232       // Generate caption for rows
233       if (isset($val["sn"]) && isset($val["givenName"])){
234         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
235       } else {
236         $display= "[".$val["uid"][0]."]";
237       }
239       /* Connect all images */
240       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
242       /* Create each field */
243       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
244       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
245       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
246       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
247                       "attach" => "style='width:102px;border-right:0px;    text-align:right;'");
248       /* Add to list */
249       $add = array($field1,$field2,$field3,$field4);
250       $this->AddElement($add);
252       // Template or User
253       if(in_array("gosaUserTemplate",$val['objectClass'])){
254         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
255       }else{
256         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
257       }
258     }
259     
260   }
262   function Save()
263   {
264     MultiSelectWindow :: Save();  
265   }
267   function save_object()
268   {
269     /* Save automatic created POSTs like regex, checkboxes */
270     MultiSelectWindow::save_object();   
271   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>