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