4f481ff19351cafe8d75cc7b0c591e0afb911ef7
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_conference.inc";
22 class phoneConferenceManagment extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Phone conferences";
26 var $plDescription = "Management";
28 /* CLI vars */
29 var $cli_summary = "Handling of LDAP subtrees";
30 var $cli_description = "Some longer text\nfor help";
31 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* Headpage attributes */
34 var $conferences = array();
36 /* attribute list for save action */
37 var $attributes = array();
38 var $objectclasses = array();
39 var $conftab = false;
41 var $departments =array();
43 /* Initialise Class */
44 function phoneConferenceManagment ($config, $ui)
45 {
46 $this->ui = $ui;
47 $this->dn = "";
48 $this->config = $config;
50 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
51 $this->acl= get_module_permission($acl, "conference", $ui->dn);
53 /* Get global filter config */
54 if (!isset($_SESSION["conferencefilter"])){
55 $base= get_base_from_people($ui->dn);
56 $conferencefilter= array(
57 "regex" => "*");
58 $_SESSION["conferencefilter"] = $conferencefilter;
59 }
60 }
62 /* Execute class and display something */
63 function execute()
64 {
66 /* Call parent execute */
67 plugin::execute();
69 /* Reload departments */
70 $smarty = get_smarty();
71 $display = "";
72 $s_action = ""; // Will contain an action, like del or edit
73 $s_entry = ""; // The entry name for edit delete -...
74 $conferencefilter = $_SESSION["conferencefilter"];
76 if(isset($_POST['regexit'])){
77 $conferencefilter['regex']=$_POST['regexit'];
78 }
80 if(isset($_GET['search'])){
81 if($_GET['search']=="*"){
82 $conferencefilter['regex']=$_GET['search'];
83 }else{
84 $conferencefilter['regex']=$_GET['search']."*";
85 }
86 }
88 $smarty->assign("regex",$conferencefilter['regex']);
90 /* Start for New List Managment */
91 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
92 $s_action="open";
93 $s_entry = base64_decode($_GET['dep_id']);
94 $_SESSION['CurrentMainBase']= $this->config->departments[trim($s_entry)];
95 }
97 foreach($_POST as $key => $post){
98 if(preg_match("/.*new.*/i",$key)){
99 $s_action = "new";
100 // Post for delete
101 }elseif(preg_match("/conf_del.*/",$key)){
102 $s_action = "del";
103 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
104 $s_entry = preg_replace("/_.*$/","",$s_entry);
105 // Post for edit
106 }elseif(preg_match("/conf_edit_.*/",$key)){
107 $s_action="edit";
108 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
109 $s_entry = preg_replace("/_.*$/","",$s_entry);
110 }elseif(preg_match("/dep_back.*/i",$key)){
111 $s_action="back";
112 }elseif(preg_match("/dep_home.*/i",$key)){
113 $s_action="home";
114 }elseif(preg_match("/dep_root.*/i",$key)){
115 $s_action="root";
116 }
117 }
119 /* Edit Entry */
120 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
121 $s_action = "edit";
122 $s_entry = $_GET['id'];
123 }
125 /* Department changed? */
126 if(isset($_POST['CurrentMainBase']) && $_POST['CurrentMainBase']){
127 $_SESSION['CurrentMainBase']= $_POST['CurrentMainBase'];
128 }
130 /* Homebutton is posted */
131 if($s_action=="home"){
132 $_SESSION['CurrentMainBase'] =preg_replace("/^[^,]+,/","",$this->ui->dn);
133 $_SESSION['CurrentMainBase'] =preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
134 }
136 /* back to root */
137 if($s_action=="root"){
138 $_SESSION['CurrentMainBase']=($this->config->current['BASE']);
139 }
141 /* If Backbutton is Posted */
142 if($s_action=="back"){
143 $base_back = preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
144 $base_back = convert_department_dn($base_back);
146 if(isset($this->config->departments[trim($base_back)])){
147 $_SESSION['CurrentMainBase']= $this->config->departments[trim($base_back)];
148 }else{
149 $_SESSION['CurrentMainBase']= $this->config->departments["/"];
150 }
151 }
153 register_global("conferencefilter",$conferencefilter);
154 $this->reload();
156 /* Reset requested? */
157 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
158 if (isset($this->conftab)){
159 del_lock ($this->conftab->dn);
160 unset ($this->conftab);
161 }
162 $this->conftab= NULL;
163 $this->lognames= array();;
164 $this->cn= "";
165 unset ($_SESSION['objectinfo']);
166 }
168 /* Delete Entry if Posted action (s_action) == del
169 * The entry which will be deleted is defined in $s_entry
170 */
171 if ($s_action =="del"){
172 $this->dn= $this->conferences[$s_entry]['dn'];
174 /* Check locking */
175 if (($conf= get_lock($this->dn)) != ""){
176 $_SESSION['dn']= $this->dn;
177 return(gen_locked_message($conf, $this->dn));
178 } else {
179 add_lock ($this->dn, $this->ui->dn);
180 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
181 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
182 return ($display);
183 }
184 }
186 /* If department deletion is accepted ...
187 * Finally delete department
188 */
189 if (isset($_POST['delete_department_confirm'])){
190 if (chkacl($this->acl, "delete") == ""){
191 $this->remove_from_parent();
192 gosa_log ("Department object'".$this->dn."' has been removed");
193 $this->reload ();
194 } else {
195 print_red (_("You have no permission to remove this department."));
196 }
197 }
199 /* Edit Entry if Posted action (s_action) == edit
200 * The entry which will be edited is defined in $s_entry
201 */
202 if (($s_action=="edit") && (!isset($this->conftab->config))){
204 $this->dn= $this->conferences[$s_entry]['dn'];
206 if (($conf= get_lock($this->dn)) != ""){
207 return(gen_locked_message ($conf, $this->dn));
208 }
210 /* Lock the current entry, so everyone will get the above dialog */
211 add_lock ($this->dn, $this->ui->dn);
213 /* Register conftab to trigger edit dialog */
214 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
215 $_SESSION['objectinfo']= $this->dn;
216 }
218 /* Insert new entry*/
219 if($s_action == "new"){
220 $this->dn= "new";
221 /* Set up the users ACL's for this 'dn' */
222 $this->dn= "new";
223 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
224 unset($_SESSION['objectinfo']);//
225 }
227 /* Edit finished, check and save changes */
228 if ((isset($_POST['edit_finish'])) && (isset($this->conftab->config))){
229 /* Check tabs, will feed message array */
230 $this->conftab->last= $this->conftab->current;
231 $this->conftab->save_object();
232 $message= $this->conftab->check();
234 if (count($message) == 0){
235 if($this->conftab->save() == 1){
236 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
237 return;
238 }
239 gosa_log ("goFonConference object '".$this->dn."' has been saved");
241 if ($this->dn != "new"){
242 del_lock ($this->dn);
243 }
245 $this->conftab->save ();
246 del_lock ($this->conftab->dn);;
247 unset ($this->conftab);
248 $this->conftab= NULL;
249 unset ($_SESSION['objectinfo']);
250 } else {
251 show_errors($message);
252 }
254 $this->reload();
255 }
257 /* if edit or new, show dialog */
258 if(($this->conftab) && (isset($this->conftab->config))){
259 $display= $this->conftab->execute();
261 /* Don't show buttons if tab dialog requests this */
262 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
263 $display.= "<p style=\"text-align:right\">\n";
264 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
265 $display.= " \n";
266 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
267 $display.= "</p>";
268 }
269 return ($display);
270 }
272 /* Header + Departmentlist*/
273 $options= "";
274 foreach ($this->config->idepartments as $key => $value){
275 if ($_SESSION['CurrentMainBase'] == $key){
276 $options.= "<option selected='selected' value='$key'>$value</option>";
277 } else {
278 $options.= "<option value='$key'>$value</option>";
279 }
280 }
282 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
283 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
284 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
285 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
286 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
287 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
288 " <input class='center' type='image' align='middle' src='images/list_new_conference.png' title='"._("Create new conference")."' alt='"._("New conference")."' name='user_new'> ".
289 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
290 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
291 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit"). "'> ".
292 "</div>";
294 /* Images for delete / edit */
295 $actions = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
296 $actions.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
298 $actions2= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
299 /* open an entry */
300 $linkopen= "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
302 /* Set Header */
303 $divlist = new divlist("conferenceTabs");
304 $divlist->SetSummary(_("This table displays all available conference rooms."));
305 $divlist->SetEntriesPerPage(0);
306 $divlist->SetHeader(array(
307 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
308 array("string" =>_("Name - Number"), "attach" => "style=''"),
309 array("string" => _("Owner"), "attach" => "style='width:200px;'"),
310 array("string" => _("PIN"), "attach" => "style='width:50px;'"),
311 array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
313 /* Insert departments in divlist*/
314 foreach($this->departments as $key=> $val){
315 if(!isset($this->config->departments[trim($key)])){
316 $this->config->departments[trim($key)]="";
317 }
319 $non_empty="";
320 $keys= str_replace("/","\/",$key);
321 foreach($this->config->departments as $keyd=>$vald ){
322 if(preg_match("/".$keys."\/.*/",$keyd)){
323 $non_empty="full";
324 }
325 }
327 /* Prepare and insert fields*/
328 $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
329 $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
330 $a_field3 = array("string" => " ", "attach" => "style='width:200px;'");
331 $a_field4 = array("string" => " ", "attach" => "style='width:50px;'");
332 $a_field5 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
334 /* Add entries */
335 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
336 }
338 /* Image shown in divlist */
339 $userimg = "<img class='center' src='images/select_conference.png' alt='User' title='%s'>";
341 /* Edit entry link*/
342 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
344 /* Insert conferneces*/
345 foreach($this->conferences as $conferencekey => $conference ){
347 if((isset($conference['goFonPIN'][0]))&&(($this->ui->dn==$conference['goFonConferenceOwner'][0])||($this->acl=="#all#"))){
348 $pin = "<img class='center' src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
349 }else{
350 $pin = " ";
351 }
353 if(isset($conference['telephoneNumber'][0])){
354 $number = " - ".$conference['telephoneNumber'][0];
355 }else{
356 $number = " - ?";
357 }
359 $ldap= $this->config->get_ldap_link();
360 $ldap->cd ($conference['goFonConferenceOwner'][0]);
361 $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
362 $cn = $data['cn'][0];
364 $a_field1 = array("string"=>sprintf($userimg,_("Conference")), "attach" => "style='text-align:center;width:20px;'");
366 if(($this->acl=="#all#")||(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")==""))){
367 $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number), "attach" => "style=''");
368 }else{
369 $a_field2 = array("string"=>$conference['cn'][0].$number, "attach" => "style=''");
370 }
371 $a_field3 = array("string"=> $cn, "attach" => "style='width:200px;'");
372 $a_field4 = array("string"=> $pin, "attach" => "style='width:50px;'");
374 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
375 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
376 }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
377 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='width:52px;border-right:0px;text-align:right;'");
378 }else{
379 $a_field5 = array("string"=>" ", "attach" => "style='width:52px;border-right:0px;text-align:right;'");
380 }
382 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
383 }
385 $smarty->assign("search_image", get_template_path('images/search.png'));
386 $smarty->assign("tree_image", get_template_path('images/tree.png'));
387 $smarty->assign("infoimage", get_template_path('images/info.png'));
388 $smarty->assign("launchimage", get_template_path('images/launch.png'));
389 $smarty->assign("conferences", $divlist->DrawList());
390 $smarty->assign("conferencehead", $listhead);
391 $smarty->assign("deplist", $this->config->idepartments);
392 $smarty->assign("apply", apply_filter());
393 $smarty->assign("alphabet", generate_alphabet());
394 $smarty->assign("hint", print_sizelimit_warning());
396 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
397 return($display);
398 }
401 /* Reload entries for divlist.
402 * First, reload all conferences for the current base, with the given regex
403 * Second, get all departments for the given base and regex
404 * Convert departments dn
405 */
406 function reload()
407 {
408 $conferencefilter = $_SESSION["conferencefilter"];
409 $base = $_SESSION['CurrentMainBase'];
410 $regex = $conferencefilter['regex'];
412 $this->confgerences= get_list("(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",
413 $this->ui->subtreeACL, $base, array("*"), GL_SIZELIMIT);
414 $res3= get_list("(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
415 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
417 $this->departments= array();
419 $tmp = array();
420 foreach ($res3 as $value){
421 $tmp[strtolower($value['dn']).$value['dn']]=$value;
422 }
423 ksort($tmp);
424 foreach($tmp as $value){
425 if(isset($value["description"][0])){
426 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
427 }else{
428 $this->departments[$value['dn']]= get_sub_department($value['dn']);//$value["description"][0];
429 }
430 }
431 }
433 function remove_from_parent()
434 {
435 $cfg = new conference($this->config, $this->dn);
437 $cfg->remove_from_parent();
438 $ldap= $this->config->get_ldap_link();
439 $ldap->cd ($this->dn);
440 $ldap->recursive_remove();
442 /* Optionally execute a command after we're done */
443 $this->postremove();
445 /* Delete references to object groups */
446 $ldap->cd ($this->config->current['BASE']);
447 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
448 while ($ldap->fetch()){
449 $og= new conftab($this->config, $ldap->getDN());
450 unset($og->member[$this->dn]);
451 $og->save ();
452 }
454 }
456 function remove_lock()
457 {
458 if (isset($this->dn)){
459 del_lock ($this->dn);
460 }
461 }
463 }
464 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
465 ?>