57de90f6136a82f870359fd55c19744718a36c69
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 if (chkacl($this->acl, "delete") == ""){
193 $this->remove_from_parent();
194 gosa_log ("Department object'".$this->dn."' has been removed");
195 $this->reload ();
196 } else {
197 print_red (_("You have no permission to remove this department."));
198 }
199 }
201 /* Edit Entry if Posted action (s_action) == edit
202 * The entry which will be edited is defined in $s_entry
203 */
204 if ($s_action=="edit"){
206 $this->dn= $this->conferences[$s_entry]['dn'];
208 if (($conf= get_lock($this->dn)) != ""){
209 return(gen_locked_message ($conf, $this->dn));
210 }
212 /* Lock the current entry, so everyone will get the above dialog */
213 add_lock ($this->dn, $this->ui->dn);
215 /* Register conftab to trigger edit dialog */
216 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
217 $_SESSION['objectinfo']= $this->dn;
218 }
220 /* Insert new entry*/
221 if($s_action == "new"){
222 $this->dn= "new";
223 /* Set up the users ACL's for this 'dn' */
224 $this->dn= "new";
225 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
226 unset($_SESSION['objectinfo']);//
227 }
229 /* Edit finished, check and save changes */
230 if (isset($_POST['edit_finish'])){
231 /* Check tabs, will feed message array */
232 $this->conftab->last= $this->conftab->current;
233 $this->conftab->save_object();
234 $message= $this->conftab->check();
236 if (count($message) == 0){
237 if($this->conftab->save() == 1){
238 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
239 return;
240 }
241 gosa_log ("goFonConference object '".$this->dn."' has been saved");
243 if ($this->dn != "new"){
244 del_lock ($this->dn);
245 }
247 $this->conftab->save ();
248 del_lock ($this->conftab->dn);;
249 unset ($this->conftab);
250 $this->conftab= NULL;
251 unset ($_SESSION['objectinfo']);
252 } else {
253 show_errors($message);
254 }
256 $this->reload();
257 }
259 /* if edit or new, show dialog */
260 if($this->conftab){
261 $display= $this->conftab->execute();
263 /* Don't show buttons if tab dialog requests this */
264 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
265 $display.= "<p style=\"text-align:right\">\n";
266 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
267 $display.= " \n";
268 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
269 $display.= "</p>";
270 }
271 return ($display);
272 }
274 /* Header + Departmentlist*/
275 $options= "";
276 foreach ($this->config->idepartments as $key => $value){
277 if ($conferencefilter['depselect'] == $key){
278 $options.= "<option selected='selected' value='$key'>$value</option>";
279 } else {
280 $options.= "<option value='$key'>$value</option>";
281 }
282 }
284 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
285 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
286 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
287 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
288 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
289 " <input class='center' type='image' align='middle' src='images/list_new_conference.png' title='"._("Create new conference")."' alt='"._("New conference")."' name='user_new'> ".
290 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
291 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
292 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit"). "'> ".
293 "</div>";
295 /* Images for delete / edit */
296 $actions = "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
297 $actions.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
299 $actions2= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
300 /* open an entry */
301 $linkopen= "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
303 /* Set Header */
304 $divlist = new divlist("conferenceTabs");
305 $divlist->SetSummary(_("This table displays all available conference rooms."));
306 $divlist->SetEntriesPerPage(0);
307 $divlist->SetHeader(array(
308 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
309 array("string" =>_("Name - Number"), "attach" => "style=''"),
310 array("string" => _("Owner"), "attach" => "style='width:200px;'"),
311 array("string" => _("PIN"), "attach" => "style='width:50px;'"),
312 array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
314 /* Insert departments in divlist*/
315 foreach($this->departments as $key=> $val){
316 if(!isset($this->config->departments[trim($key)])){
317 $this->config->departments[trim($key)]="";
318 }
320 $non_empty="";
321 $keys= str_replace("/","\/",$key);
322 foreach($this->config->departments as $keyd=>$vald ){
323 if(preg_match("/".$keys."\/.*/",$keyd)){
324 $non_empty="full";
325 }
326 }
328 /* Prepare and insert fields*/
329 $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
330 $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
331 $a_field3 = array("string" => " ", "attach" => "style='width:200px;'");
332 $a_field4 = array("string" => " ", "attach" => "style='width:50px;'");
333 $a_field5 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
335 /* Add entries */
336 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
337 }
339 /* Image shown in divlist */
340 $userimg = "<img class='center' src='images/select_conference.png' alt='User' title='%s'>";
342 /* Edit entry link*/
343 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
345 /* Insert conferneces*/
346 foreach($this->conferences as $conferencekey => $conference ){
348 if((isset($conference['goFonPIN'][0]))&&(($this->ui->dn==$conference['goFonConferenceOwner'][0])||($this->acl=="#all#"))){
349 $pin = "<img class='center' src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
350 }else{
351 $pin = " ";
352 }
354 if(isset($conference['telephoneNumber'][0])){
355 $number = " - ".$conference['telephoneNumber'][0];
356 }else{
357 $number = " - ?";
358 }
360 $ldap= $this->config->get_ldap_link();
361 $ldap->cd ($conference['goFonConferenceOwner'][0]);
362 $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
363 $cn = $data['cn'][0];
365 $a_field1 = array("string"=>sprintf($userimg,_("Conference")), "attach" => "style='text-align:center;width:20px;'");
367 if(($this->acl=="#all#")||(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")==""))){
368 $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number), "attach" => "style=''");
369 }else{
370 $a_field2 = array("string"=>$conference['cn'][0].$number, "attach" => "style=''");
371 }
372 $a_field3 = array("string"=> $cn, "attach" => "style='width:200px;'");
373 $a_field4 = array("string"=> $pin, "attach" => "style='width:50px;'");
375 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
376 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
377 }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
378 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='width:52px;border-right:0px;text-align:right;'");
379 }else{
380 $a_field5 = array("string"=>" ", "attach" => "style='width:52px;border-right:0px;text-align:right;'");
381 }
383 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
384 }
386 $smarty->assign("search_image", get_template_path('images/search.png'));
387 $smarty->assign("tree_image", get_template_path('images/tree.png'));
388 $smarty->assign("infoimage", get_template_path('images/info.png'));
389 $smarty->assign("launchimage", get_template_path('images/launch.png'));
390 $smarty->assign("conferences", $divlist->DrawList());
391 $smarty->assign("conferencehead", $listhead);
392 $smarty->assign("deplist", $this->config->idepartments);
393 $smarty->assign("apply", apply_filter());
394 $smarty->assign("alphabet", generate_alphabet());
395 $smarty->assign("hint", print_sizelimit_warning());
397 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
398 return($display);
399 }
402 /* Reload entries for divlist.
403 * First, reload all conferences for the current base, with the given regex
404 * Second, get all departments for the given base and regex
405 * Convert departments dn
406 */
407 function reload()
408 {
409 $conferencefilter = $_SESSION["conferencefilter"];
410 $base = $conferencefilter['depselect'];
411 $regex = $conferencefilter['regex'];
413 $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
414 $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
416 $this->departments= array();
418 $tmp = array();
419 foreach ($res3 as $value){
420 $tmp[strtolower($value['dn']).$value['dn']]=$value;
421 }
422 ksort($tmp);
423 foreach($tmp as $value){
424 if(isset($value["description"][0])){
425 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
426 }else{
427 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
428 }
429 }
430 }
432 function remove_from_parent()
433 {
434 $cfg = new conference($this->config, $this->dn);
436 $cfg->remove_from_parent();
437 $ldap= $this->config->get_ldap_link();
438 $ldap->cd ($this->dn);
439 $ldap->recursive_remove();
441 /* Optionally execute a command after we're done */
442 $this->postremove();
444 /* Delete references to object groups */
445 $ldap->cd ($this->config->current['BASE']);
446 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
447 while ($ldap->fetch()){
448 $og= new conftab($this->config, $ldap->getDN());
449 unset($og->member[$this->dn]);
450 $og->save ();
451 }
453 }
455 function remove_lock()
456 {
457 if (isset($this->dn)){
458 del_lock ($this->dn);
459 }
460 }
462 }
463 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
464 ?>