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:152px;'"));
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 /* Create header with selected base */
113 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
114 " <input class='center' type='image' src='images/list_root.png' align='middle'
115 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
116 " <input class='center' type='image' align='middle' src='images/list_back.png'
117 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
118 " <input class='center' type='image' align='middle' src='images/list_home.png'
119 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
120 " <input class='center' type='image' src='images/list_reload.png' align='middle'
121 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
122 " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
125 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
126 $listhead .= $this->get_snapshot_header($this->selectedBase);
127 }
129 if(preg_match("/c/",$acl)) {
130 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_user.png'
131 title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ";
132 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new.png'
133 title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ";
134 }
136 $listhead .= $Copy_Paste;
138 $listhead .=
139 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
140 " <input class='center' type='image' src='images/list_submit.png' align='middle'
141 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
142 "</div>";
144 $this->SetListHeader($listhead);
145 }
147 /* so some basic settings */
148 function execute()
149 {
150 $this->ClearElementsList();
151 $this->GenHeader();
152 }
154 function setEntries($list)
155 {
156 /********************
157 Variable init
158 ********************/
160 /* Variable initialation */
161 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
162 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
163 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
164 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
165 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
167 /* Dynamic action col, depending on snapshot icons */
168 $action_col_size = 104;
169 if($this->parent->snapshotEnabled()){
170 $action_col_size += 38;
171 }
173 /* Possilbe objectClass image combinations */
174 $possibleAccounts = array(
175 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
176 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
177 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
178 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
179 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
180 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
182 /* Pictures for Extensions */
183 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
184 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
185 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
186 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
187 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
188 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
189 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
190 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
191 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
192 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
193 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
194 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
195 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
196 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
197 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
198 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
199 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
200 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
202 /********************
203 END :: Variable init
204 ********************/
206 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
207 * Read Sip Table for specified account (for each user with phoneAccount).
208 * Check the attributes ip port and regseconds.
209 * If regseconds is set and >0 , the phone is logged in.
210 * Else the phone is currently not logged.
211 * If we can't read any Data from the DB or there is no goFon DB specified
212 * show old style without status icons.
213 */
214 $r_db =false;
215 $r_con =false;
216 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
217 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
218 $r_con = false;
219 $r_db = false;
220 if(is_callable("mysql_pconnect")){
221 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
222 // Check if we are connected correctly
223 if($r_con){
224 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
225 }
226 }
227 }
230 /********************
231 Append entries to divlist
232 ********************/
234 $ui = get_userinfo();
236 // Test Every Entry and generate divlist Array
237 foreach($list as $key => $val){
239 /* Create action icons */
240 $action= "";
242 /* Add copy & cut icons */
243 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
244 $acl = $ui->get_permissions($val['dn'],"users/user");
245 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
246 $action .= "<input class='center' type='image'
247 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
248 $action.= "<input class='center' type='image'
249 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
250 }
252 /* Generate edit icon */
253 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
254 name='user_edit_%KEY%' title='"._("Edit user")."'>";
256 /* Add Password change icon, if we are able to write users/password */
257 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
258 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
259 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
260 }else{
261 $action.= "<img class='center' src='images/empty.png' alt=' '
262 title='"._("You are not allowed to change the password for this user.")."'>";
263 }
265 /* Add snapshot icon */
266 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
267 $action.= $this->GetSnapShotActions($val['dn']);
268 }
270 /* Add remove icon, if we are allowed to remove the current user */
271 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
272 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
273 name='user_del_%KEY%' title='"._("Delete user")."'>";
274 }else{
275 $action.= "<img class='center' src='images/empty.png' alt=' '
276 title='"._("You are not allowed to remove this user.")."'>";
277 }
279 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
280 $connected = ""; // This string represents timestamp or offline status
281 $ip_port = ""; // String that will represent ip : port of the connected phone
282 if((in_array("goFonAccount" ,$val['objectClass']))){
284 /* Set defaults */
285 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
286 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
287 $fonac = preg_replace("/%title%/", "", $fonac);
289 /* Database connection is ok ?*/
290 if(($r_db)&&(is_callable("mysql_query"))){
291 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
292 $mysql_entry = @mysql_fetch_row($res);
293 if(is_array($mysql_entry)){
294 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
295 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
296 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
297 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
298 $fonac = preg_replace("/%title%/", $connected, $fonac);
299 #$ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
300 }
301 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
302 $connected = " | "._("Offline");
303 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
304 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
305 $fonac = preg_replace("/%title%/", $connected, $fonac);
306 }
307 }
308 }
309 }else{
310 $fonac=$empty;
311 }
313 /* Set images for different types of objectClasses */
314 foreach($possibleAccounts as $objectClass => $Settigns){
315 if(in_array($objectClass ,$val['objectClass'])){
316 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
317 }else{
318 $$Settigns['VAR'] = $empty;
319 }
320 }
322 /* Create userimg */
323 if(in_array("gosaUserTemplate",$val['objectClass'])){
324 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
325 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
326 }else{
327 $s_img_create_from_template = "";
328 $tpl = $userimg;
329 }
331 /* Insert key into userimg */
332 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
334 // Generate caption for rows
335 if (isset($val["sn"]) && isset($val["givenName"])){
336 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
337 } else {
338 $display= "[".$val["uid"][0]."]";
339 }
341 /* Connect all images */
342 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
344 /* Create each field */
345 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
346 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
347 $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
348 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
349 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
350 /* Add to list */
351 $add = array($field1,$field2,$field3,$field4);
352 $this->AddElement($add);
354 // Template or User
355 if(in_array("gosaUserTemplate",$val['objectClass'])){
356 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
357 }else{
358 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
359 }
360 }
362 /* close database connection, if it was opened */
363 if(isset($r_con)){
364 if((is_callable("mysql_close"))&&($r_con)){
365 @mysql_close($r_con);
366 }
367 }
369 }
371 function Save()
372 {
373 MultiSelectWindow :: Save();
374 }
376 function save_object()
377 {
378 /* Save automatic created POSTs like regex, checkboxes */
379 MultiSelectWindow::save_object();
380 }
381 }
382 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
383 ?>