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