839516b44d2c3760f9565c182afd2b3f3ee46a62
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 $this->config->departments = get_departments();
71 $smarty = get_smarty();
72 $display = "";
73 $s_action = ""; // Will contain an action, like del or edit
74 $s_entry = ""; // The entry name for edit delete -...
75 $conferencefilter = $_SESSION["conferencefilter"];
77 if(isset($_POST['regexit'])){
78 $conferencefilter['regex']=$_POST['regexit'];
79 }
81 if(isset($_GET['search'])){
82 if($_GET['search']=="*"){
83 $conferencefilter['regex']=$_GET['search'];
84 }else{
85 $conferencefilter['regex']=$_GET['search']."*";
86 }
87 }
89 $smarty->assign("regex",$conferencefilter['regex']);
91 /* Start for New List Managment */
92 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
93 $s_action="open";
94 $s_entry = base64_decode($_GET['dep_id']);
95 $_SESSION['CurrentMainBase']= $this->config->departments[trim($s_entry)];
96 }
98 foreach($_POST as $key => $post){
99 if(preg_match("/.*new.*/i",$key)){
100 $s_action = "new";
101 // Post for delete
102 }elseif(preg_match("/conf_del.*/",$key)){
103 $s_action = "del";
104 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
105 $s_entry = preg_replace("/_.*$/","",$s_entry);
106 // Post for edit
107 }elseif(preg_match("/conf_edit_.*/",$key)){
108 $s_action="edit";
109 $s_entry = preg_replace("/conf_".$s_action."_/i","",$key);
110 $s_entry = preg_replace("/_.*$/","",$s_entry);
111 }elseif(preg_match("/dep_back.*/i",$key)){
112 $s_action="back";
113 }elseif(preg_match("/dep_home.*/i",$key)){
114 $s_action="home";
115 }elseif(preg_match("/dep_root.*/i",$key)){
116 $s_action="root";
117 }
118 }
120 /* Edit Entry */
121 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
122 $s_action = "edit";
123 $s_entry = $_GET['id'];
124 }
126 /* Department changed? */
127 if(isset($_POST['CurrentMainBase']) && $_POST['CurrentMainBase']){
128 $_SESSION['CurrentMainBase']= $_POST['CurrentMainBase'];
129 }
131 /* Homebutton is posted */
132 if($s_action=="home"){
133 $_SESSION['CurrentMainBase'] =preg_replace("/^[^,]+,/","",$this->ui->dn);
134 $_SESSION['CurrentMainBase'] =preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
135 }
137 /* back to root */
138 if($s_action=="root"){
139 $_SESSION['CurrentMainBase']=($this->config->current['BASE']);
140 }
142 /* If Backbutton is Posted */
143 if($s_action=="back"){
144 $base_back = preg_replace("/^[^,]+,/","",$_SESSION['CurrentMainBase']);
145 $base_back = convert_department_dn($base_back);
147 if(isset($this->config->departments[trim($base_back)])){
148 $_SESSION['CurrentMainBase']= $this->config->departments[trim($base_back)];
149 }else{
150 $_SESSION['CurrentMainBase']= $this->config->departments["/"];
151 }
152 }
154 register_global("conferencefilter",$conferencefilter);
155 $this->reload();
157 /* Reset requested? */
158 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
159 if (isset($this->conftab)){
160 del_lock ($this->conftab->dn);
161 unset ($this->conftab);
162 }
163 $this->conftab= NULL;
164 $this->lognames= array();;
165 $this->cn= "";
166 unset ($_SESSION['objectinfo']);
167 }
169 /* Delete Entry if Posted action (s_action) == del
170 * The entry which will be deleted is defined in $s_entry
171 */
172 if ($s_action =="del"){
173 $this->dn= $this->conferences[$s_entry]['dn'];
175 /* Check locking */
176 if (($conf= get_lock($this->dn)) != ""){
177 $_SESSION['dn']= $this->dn;
178 return(gen_locked_message($conf, $this->dn));
179 } else {
180 add_lock ($this->dn, $this->ui->dn);
181 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
182 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
183 return ($display);
184 }
185 }
187 /* If department deletion is accepted ...
188 * Finally delete department
189 */
190 if (isset($_POST['delete_department_confirm'])){
191 if (chkacl($this->acl, "delete") == ""){
192 $this->remove_from_parent();
193 gosa_log ("Department object'".$this->dn."' has been removed");
194 $this->reload ();
195 } else {
196 print_red (_("You have no permission to remove this department."));
197 }
198 }
200 /* Edit Entry if Posted action (s_action) == edit
201 * The entry which will be edited is defined in $s_entry
202 */
203 if (($s_action=="edit") && (!isset($this->conftab->config))){
205 $this->dn= $this->conferences[$s_entry]['dn'];
207 if (($conf= get_lock($this->dn)) != ""){
208 return(gen_locked_message ($conf, $this->dn));
209 }
211 /* Lock the current entry, so everyone will get the above dialog */
212 add_lock ($this->dn, $this->ui->dn);
214 /* Register conftab to trigger edit dialog */
215 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
216 $_SESSION['objectinfo']= $this->dn;
217 }
219 /* Insert new entry*/
220 if($s_action == "new"){
221 $this->dn= "new";
222 /* Set up the users ACL's for this 'dn' */
223 $this->dn= "new";
224 $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
225 unset($_SESSION['objectinfo']);//
226 }
228 /* Edit finished, check and save changes */
229 if ((isset($_POST['edit_finish'])) && (isset($this->conftab->config))){
230 /* Check tabs, will feed message array */
231 $this->conftab->last= $this->conftab->current;
232 $this->conftab->save_object();
233 $message= $this->conftab->check();
235 if (count($message) == 0){
236 if($this->conftab->save() == 1){
237 gosa_log ("goFonConference object '".$this->dn."' saving failed.");
238 return;
239 }
240 gosa_log ("goFonConference object '".$this->dn."' has been saved");
242 if ($this->dn != "new"){
243 del_lock ($this->dn);
244 }
246 $this->conftab->save ();
247 del_lock ($this->conftab->dn);;
248 unset ($this->conftab);
249 $this->conftab= NULL;
250 unset ($_SESSION['objectinfo']);
251 } else {
252 show_errors($message);
253 }
255 $this->reload();
256 }
258 /* if edit or new, show dialog */
259 if(($this->conftab) && (isset($this->conftab->config))){
260 $display= $this->conftab->execute();
262 /* Don't show buttons if tab dialog requests this */
263 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
264 $display.= "<p style=\"text-align:right\">\n";
265 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
266 $display.= " \n";
267 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
268 $display.= "</p>";
269 }
270 return ($display);
271 }
273 /* Header + Departmentlist*/
274 $options= "";
275 foreach ($this->config->idepartments as $key => $value){
276 if ($_SESSION['CurrentMainBase'] == $key){
277 $options.= "<option selected='selected' value='$key'>$value</option>";
278 } else {
279 $options.= "<option value='$key'>$value</option>";
280 }
281 }
283 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
284 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
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' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
287 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
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='CurrentMainBase' 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 = $_SESSION['CurrentMainBase'];
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']]=$value['dn']." - [".$value["description"][0]."]";
426 }else{
427 $this->departments[$value['dn']]=$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 ?>