Code

ba668dd7dc800e150d90f124bbf9e81a9b02c92c
[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 default base */
35     if(!isset($_SESSION['CurrentMainBase'])){
36       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
37     }
38     $this->selectedBase = $_SESSION['CurrentMainBase'];
40     /* Set list strings */
41     $this->SetTitle(_("List of users"));
42     $this->SetSummary(_("List of users"));
44     /* Result page will look like a headpage */
45     $this->SetHeadpageMode();
46     $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."));
48     $this->EnableAplhabet   (true);
49   
50     /* Disable buttonsm */
51     $this->EnableCloseButton(false);
52     $this->EnableSaveButton (false);
54     /* set Page header */
55     $this->AddHeader(array("string"=>"&nbsp;",          "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:102px;border-right:0px;text-align:right;'"));
59     
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   }
75   function GenHeader()
76   {
77     /* Prepare departments,
78        which are shown in the listbox on top of the listbox
79      */
80     $options= "";
81     foreach ($this->config->idepartments as $key => $value){
82       if ($this->selectedBase == $key){
83         $options.= "<option selected='selected' value='$key'>$value</option>";
84       } else {
85         $options.= "<option value='$key'>$value</option>";
86       }
87     }
89     /* Get copy & paste icon */ 
90     if($this->parent->CopyPasteHandler){
91       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
92     }else{
93       $Copy_Paste ="";
94     }
96     /* Create header with selected base */
97     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
98       " <input class='center' type='image' src='images/list_root.png' align='middle' 
99       title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
100       " <input class='center' type='image' align='middle' src='images/list_back.png' 
101       title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;".
102       " <input class='center' type='image' align='middle' src='images/list_home.png' 
103       title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;".
104       " <input class='center' type='image' src='images/list_reload.png' align='middle' 
105       title='"._("Reload list")."' name='submit_department' alt='".        _("Submit")."'>&nbsp;".
106       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
107       " <input class='center' type='image' align='middle' src='images/list_new_user.png' 
108       title='"._("Create new user")."' alt='"._("New user")."'           name='user_new'>&nbsp;".
109       " <input class='center' type='image' align='middle' src='images/list_new.png' 
110       title='"._("Create new template")."' alt='"._("New template")."'        name='user_tplnew'>&nbsp;".
111       $Copy_Paste.
112       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
113       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
114       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
115       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
116       "</div>";
118     $this->SetListHeader($listhead);
119   }
121   /* so some basic settings */
122   function execute()
123   {
124     $this->ClearElementsList();
125     $this->GenHeader();
126   }
128   function setEntries($list)
129   {
130     /********************
131       Variable init
132      ********************/
134     /* Variable initialation */
135     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
136     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
137     $userimg    = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
138     $tplimg     = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
139     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
141     /* Create action icons */
142     $action = "";
143     if($this->parent->CopyPasteHandler){
144       $action .= "<input class='center' type='image'
145         src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
146       $action.= "<input class='center' type='image'
147         src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
148     }
149     $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
150       name='user_edit_%KEY%' title='"._("Edit user")."'>";
151     $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
152       name='user_chgpw_%KEY%' title='"._("Change password")."'>";
153     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
154       name='user_del_%KEY%' title='"._("Delete user")."'>";
155     
156     /* Possilbe objectClass image combinations */  
157     $possibleAccounts = array(
158             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
159             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
160             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
161             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
162             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
163             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
165      /* Pictures for Extensions */
166     $usrimg   ="<input class='center' type='image' src='images/penguin.png' alt='"._("GOsa")."'
167                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
168     $posiximg = "<input class='center' type='image' src='images/select_user.png' alt='"._("Posix")."'
169                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
170     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
171                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
172     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
173                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
174     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
175                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
176     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
177                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
178     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
179                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
180     $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
181                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
182     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
183                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
185     /********************
186       END :: Variable init
187      ********************/
189     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
190      * Read Sip Table for specified account (for each user with phoneAccount).
191      * Check the attributes ip port and regseconds.
192      * If regseconds is set and >0 , the phone is logged in.
193      * Else the phone is currently not logged.
194      * If we can't read any Data from the DB or there is no goFon DB specified
195      * show old style without status icons.
196      */
197     $r_db   =false;
198     $r_con  =false;
199     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
200       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
201       $r_con = false;
202       $r_db  = false;
203       if(is_callable("mysql_pconnect")){
204         $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
205         // Check if we are  connected correctly
206         if($r_con){
207           $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
208         }
209       }
210     }
211    
212  
213     /********************
214       Append entries to divlist 
215      ********************/
216  
217     // Test Every Entry and generate divlist Array
218     foreach($list as $key => $val){
220       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
221       $connected  = ""; // This string represents timestamp or offline status
222       $ip_port    = ""; // String that will represent ip : port of the connected phone
223       if((in_array("goFonAccount"    ,$val['objectClass']))){
225         /* Set defaults */
226         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
227         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
228         $fonac = preg_replace("/%title%/", "", $fonac);
230         /* Database connection is ok ?*/
231         if(($r_db)&&(is_callable("mysql_query"))){
232           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
233           $mysql_entry = @mysql_fetch_row($res);
234           if(is_array($mysql_entry)){
235             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
236               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
237               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
238               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
239               $fonac = preg_replace("/%title%/", $connected, $fonac);
240               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
241             }
242             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
243               $connected = " | "._("Offline");
244               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
245               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
246               $fonac = preg_replace("/%title%/", $connected, $fonac);
247             }
248           }
249         }
250       }else{
251         $fonac=$empty;
252       }
254       /* Set images for different types of objectClasses */
255       foreach($possibleAccounts as $objectClass => $Settigns){ 
256         if(in_array($objectClass ,$val['objectClass'])){
257           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
258         }else{
259           $$Settigns['VAR'] = $empty;
260         }
261       }
263       /* Create userimg */
264       if(in_array("gosaUserTemplate",$val['objectClass'])){
265         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
266         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
267       }else{
268         $s_img_create_from_template   = "";
269         $tpl                          = $userimg;
270       }
272       /* Insert key into userimg */
273       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
275       // Generate caption for rows
276       if (isset($val["sn"]) && isset($val["givenName"])){
277         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
278       } else {
279         $display= "[".$val["uid"][0]."]";
280       }
282       /* Connect all images */
283       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp".$netatalk;
285       /* Create each field */
286       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
287       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='dn:&nbsp;".@LDAP::fix($val['dn'])."'");
288       $field3 = array("string" => $UseImg, "attach" => "style='width:152px;'");
289       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
290                       "attach" => "style='width:102px;border-right:0px;    text-align:right;'");
291       /* Add to list */
292       $add = array($field1,$field2,$field3,$field4);
293       $this->AddElement($add);
295       // Template or User
296       if(in_array("gosaUserTemplate",$val['objectClass'])){
297         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
298       }else{
299         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
300       }
301     }
302     
303     /* close database connection, if it was opened */
304     if(isset($r_con)){
305       if((is_callable("mysql_close"))&&($r_con)){
306         @mysql_close($r_con);
307       }
308     }
310   }
312   function Save()
313   {
314     MultiSelectWindow :: Save();  
315   }
317   function save_object()
318   {
319     /* Save automatic created POSTs like regex, checkboxes */
320     MultiSelectWindow::save_object();   
321   }
323 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
324 ?>