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