1bddbdf660e8fbbb9c9564a476dbae24b91bf334
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 "depselect" => $base,
58 "regex" => "*");
59 $_SESSION["conferencefilter"] = $conferencefilter;
60 }
61 }
63 /* Execute class and display something */
64 function execute()
65 {
67 /* Call parent execute */
68 plugin::execute();
70 /* Reload departments */
71 $this->config->departments = get_departments();
72 $smarty = get_smarty();
73 $display = "";
74 $s_action = ""; // Will contain an action, like del or edit
75 $s_entry = ""; // The entry name for edit delete -...
76 $conferencefilter = $_SESSION["conferencefilter"];
78 if(isset($_POST['regexit'])){
79 $conferencefilter['regex']=$_POST['regexit'];
80 }
82 if(isset($_GET['search'])){
83 if($_GET['search']=="*"){
84 $conferencefilter['regex']=$_GET['search'];
85 }else{
86 $conferencefilter['regex']=$_GET['search']."*";
87 }
88 }
90 $smarty->assign("regex",$conferencefilter['regex']);
92 /* Start for New List Managment */
93 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
94 $s_action="open";
95 $s_entry = base64_decode($_GET['dep_id']);
96 $conferencefilter['depselect']= "".$this->config->departments[trim($s_entry)];
97 }
99 foreach($_POST as $key => $post){
100 if(preg_match("/.*new.*/i",$key)){
101 $s_action = "new";
102 // Post for delete
103 }elseif(preg_match("/conf_del.*/",$key)){
104 $s_action = "del";
105 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
106 $s_entry = preg_replace("/_.*$/","",$s_entry);
107 // Post for edit
108 }elseif(preg_match("/conf_edit_.*/",$key)){
109 $s_action="edit";
110 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
111 $s_entry = preg_replace("/_.*$/","",$s_entry);
112 }elseif(preg_match("/dep_back.*/i",$key)){
113 $s_action="back";
114 }elseif(preg_match("/dep_home.*/i",$key)){
115 $s_action="home";
116 }elseif(preg_match("/dep_root.*/i",$key)){
117 $s_action="root";
118 }
119 }
121 /* Edit Entry */
122 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
123 $s_action = "edit";
124 $s_entry = $_GET['id'];
125 }
127 /* Department changed? */
128 if(isset($_POST['depselect']) && $_POST['depselect']){
129 $conferencefilter['depselect']= $_POST['depselect'];
130 }
132 /* Homebutton is posted */
133 if($s_action=="home"){
134 $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
135 $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$conferencefilter['depselect']));
136 }
138 /* back to root */
139 if($s_action=="root"){
140 $conferencefilter['depselect']=($this->config->current['BASE']);
141 }
143 /* If Backbutton is Posted */
144 if($s_action=="back"){
145 $base_back = preg_replace("/^[^,]+,/","",$conferencefilter['depselect']);
146 $base_back = convert_department_dn($base_back);
148 if(isset($this->config->departments[trim($base_back)])){
149 $conferencefilter['depselect']= $this->config->departments[trim($base_back)];
150 }else{
151 $conferencefilter['depselect']= $this->config->departments["/"];
152 }
153 }
155 register_global("conferencefilter",$conferencefilter);
156 $this->reload();
158 /* Reset requested? */
159 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
160 if (isset($this->conftab)){
161 del_lock ($this->conftab->dn);
162 unset ($this->conftab);
163 }
164 $this->conftab= NULL;
165 $this->lognames= array();;
166 $this->cn= "";
167 unset ($_SESSION['objectinfo']);
168 }
170 /* Delete Entry if Posted action (s_action) == del
171 * The entry which will be deleted is defined in $s_entry
172 */
173 if ($s_action =="del"){
174 $this->dn= $this->conferences[$s_entry]['dn'];
176 /* Check locking */
177 if (($conf= get_lock($this->dn)) != ""){
178 $_SESSION['dn']= $this->dn;
179 return(gen_locked_message($conf, $this->dn));
180 } else {
181 add_lock ($this->dn, $this->ui->dn);
182 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
183 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
184 return ($display);
185 }
186 }
188 /* If department deletion is accepted ...
189 * Finally delete department
190 */
191 if (isset($_POST['delete_department_confirm'])){
192 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
193 $acl= get_module_permission($acl, "conference", $this->dn);
194 if (chkacl($acl, "all") == ""){
195 $this->remove_from_parent();
196 gosa_log ("Department object'".$this->dn."' has been removed");
197 $this->reload ();
198 } else {
199 print_red (_("You have no permission to remove this department."));
200 }
201 }
203 /* Edit Entry if Posted action (s_action) == edit
204 * The entry which will be edited is defined in $s_entry
205 */
206 if ($s_action=="edit"){
208 $this->dn= $this->conferences[$s_entry]['dn'];
210 if (($conf= get_lock($this->dn)) != ""){
211 return(gen_locked_message ($conf, $this->dn));
212 }
214 /* Lock the current entry, so everyone will get the above dialog */
215 add_lock ($this->dn, $this->ui->dn);
217 /* Register conftab to trigger edit dialog */
218 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
219 $this->conftab->set_acl($this->acl);
220 $_SESSION['objectinfo']= $this->dn;
221 }
223 /* Insert new entry*/
224 if($s_action == "new"){
225 $this->dn= "new";
226 /* Set up the users ACL's for this 'dn' */
227 $this->dn= "new";
228 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
229 $this->conftab->set_acl($this->acl);
230 unset($_SESSION['objectinfo']);//
231 }
233 /* Edit finished, check and save changes */
234 if (isset($_POST['edit_finish'])){
235 /* Check tabs, will feed message array */
236 $this->conftab->last= $this->conftab->current;
237 $this->conftab->save_object();
238 $message= $this->conftab->check();
240 if (count($message) == 0){
241 if($this->conftab->save() == 1){
242 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
243 return;
244 }
245 gosa_log ("goFonConference object '".$this->dn."' has been saved");
247 if ($this->dn != "new"){
248 del_lock ($this->dn);
249 }
251 $this->conftab->save ();
252 del_lock ($this->conftab->dn);;
253 unset ($this->conftab);
254 $this->conftab= NULL;
255 unset ($_SESSION['objectinfo']);
256 } else {
257 show_errors($message);
258 }
260 $this->reload();
261 }
263 /* if edit or new, show dialog */
264 if($this->conftab){
265 $display= $this->conftab->execute();
267 /* Don't show buttons if tab dialog requests this */
268 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
269 $display.= "<p style=\"text-align:right\">\n";
270 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
271 $display.= " \n";
272 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
273 $display.= "</p>";
274 }
275 return ($display);
276 }
278 /* Header + Departmentlist*/
279 $options= "";
280 foreach ($this->config->idepartments as $key => $value){
281 if ($conferencefilter['depselect'] == $key){
282 $options.= "<option selected value='$key'>$value</option>";
283 } else {
284 $options.= "<option value='$key'>$value</option>";
285 }
286 }
288 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
289 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
290 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
291 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
292 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
293 " <input class='center' type='image' align='middle' src='images/list_new_conference.png' title='"._("Create new conference")."' alt='"._("New conference")."' name='user_new'> ".
294 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
295 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
296 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit"). "'> ".
297 "</div>";
299 /* Images for delete / edit */
300 $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
301 $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
303 $actions2= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
304 /* open an entry */
305 $linkopen= "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
307 /* Set Header */
308 $divlist = new divlist("conferenceTabs");
309 $divlist->SetSummary(_("This table displays all available conference rooms."));
310 $divlist->SetEntriesPerPage(0);
311 $divlist->SetHeader(array(
312 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
313 array("string" =>_("Name - Number"), "attach" => "style=''"),
314 array("string" => _("Owner"), "attach" => "style='width:200px;'"),
315 array("string" => _("PIN"), "attach" => "style='width:50px;'"),
316 array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
318 /* Insert departments in divlist*/
319 foreach($this->departments as $key=> $val){
320 if(!isset($this->config->departments[trim($key)])){
321 $this->config->departments[trim($key)]="";
322 }
324 $non_empty="";
325 $keys= str_replace("/","\/",$key);
326 foreach($this->config->departments as $keyd=>$vald ){
327 if(preg_match("/".$keys."\/.*/",$keyd)){
328 $non_empty="full";
329 }
330 }
332 /* Prepare and insert fields*/
333 $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
334 $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
335 $a_field3 = array("string" => " ", "attach" => "style='width:200px;'");
336 $a_field4 = array("string" => " ", "attach" => "style='width:50px;'");
337 $a_field5 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
339 /* Add entries */
340 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
341 }
343 /* Image shown in divlist */
344 $userimg = "<img src='images/select_conference.png' alt='User' title='%s'>";
346 /* Edit entry link*/
347 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
349 /* Insert conferneces*/
350 foreach($this->conferences as $conferencekey => $conference ){
352 if((isset($conference['goFonPIN'][0]))&&($this->ui->dn==$conference['goFonConferenceOwner'][0])){
353 $pin = "<img src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
354 }else{
355 $pin = " ";
356 }
358 if(isset($conference['telephoneNumber'][0])){
359 $number = " - ".$conference['telephoneNumber'][0];
360 }else{
361 $number = " - ?";
362 }
364 $ldap= $this->config->get_ldap_link();
365 $ldap->cd ($conference['goFonConferenceOwner'][0]);
366 $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
367 $cn = $data['cn'][0];
369 $a_field1 = array("string"=>sprintf($userimg,_("Conference")), "attach" => "style='text-align:center;width:20px;'");
371 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
372 $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number), "attach" => "style=''");
373 }else{
374 $a_field2 = array("string"=>$conference['cn'][0].$number, "attach" => "style=''");
375 }
376 $a_field3 = array("string"=> $cn, "attach" => "style='width:200px;'");
377 $a_field4 = array("string"=> $pin, "attach" => "style='width:50px;'");
379 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
380 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
381 }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
382 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='width:52px;border-right:0px;text-align:right;'");
383 }else{
384 $a_field5 = array("string"=>" ", "attach" => "style='width:52px;border-right:0px;text-align:right;'");
385 }
387 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
388 }
390 $smarty->assign("search_image", get_template_path('images/search.png'));
391 $smarty->assign("tree_image", get_template_path('images/tree.png'));
392 $smarty->assign("infoimage", get_template_path('images/info.png'));
393 $smarty->assign("launchimage", get_template_path('images/launch.png'));
394 $smarty->assign("conferences", $divlist->DrawList());
395 $smarty->assign("conferencehead", $listhead);
396 $smarty->assign("deplist", $this->config->idepartments);
397 $smarty->assign("apply", apply_filter());
398 $smarty->assign("alphabet", generate_alphabet());
399 $smarty->assign("hint", print_sizelimit_warning());
401 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
402 return($display);
403 }
406 /* Reload entries for divlist.
407 * First, reload all conferences for the current base, with the given regex
408 * Second, get all departments for the given base and regex
409 * Convert departments dn
410 */
411 function reload()
412 {
413 $conferencefilter = $_SESSION["conferencefilter"];
414 $base = $conferencefilter['depselect'];
415 $regex = $conferencefilter['regex'];
417 $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
418 $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
420 $this->departments= array();
422 $tmp = array();
423 foreach ($res3 as $value){
424 $tmp[strtolower($value['dn']).$value['dn']]=$value;
425 }
426 ksort($tmp);
427 foreach($tmp as $value){
428 if(isset($value["description"][0])){
429 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
430 }else{
431 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
432 }
433 }
434 }
436 function remove_from_parent()
437 {
438 $cfg = new conference($this->config, $this->dn);
439 $cfg->remove_from_parent();
440 $ldap= $this->config->get_ldap_link();
441 $ldap->cd ($this->dn);
442 $ldap->recursive_remove();
444 /* Optionally execute a command after we're done */
445 $this->postremove();
447 /* Delete references to object groups */
448 $ldap->cd ($this->config->current['BASE']);
449 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
450 while ($ldap->fetch()){
451 $og= new conftab($this->config, $ldap->getDN());
452 unset($og->member[$this->dn]);
453 $og->save ();
454 }
456 }
458 function remove_lock()
459 {
460 if (isset($this->dn)){
461 del_lock ($this->dn);
462 }
463 }
465 }
466 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
467 ?>