Code

Added snapshot to conferences
[gosa.git] / plugins / gofon / conference / class_phoneConferenceManagment.inc
index 27b858ee719c15d338b0120ee0806985fc289257..f2b093910e4d6ac414e582a78a267f41aa9bf4f2 100644 (file)
@@ -22,7 +22,7 @@ require "tabs_conference.inc";
 class phoneConferenceManagment extends plugin
 {
   /* Definitions */
-  var $plHeadline                                = "Phone conference";
+  var $plHeadline                                = "Phone conferences";
   var $plDescription                   = "Management";
 
   /* CLI vars */
@@ -30,15 +30,14 @@ class phoneConferenceManagment extends plugin
   var $cli_description         = "Some longer text\nfor help";
   var $cli_parameters                  = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
-  /* Headpage attributes */
-  var $conferences                       = array();
-
   /* attribute list for save action */
   var $attributes                                = array();
   var $objectclasses                   = array();
+
+  var $conferences                       = array();
   var $conftab            = false;
 
-  var $departments  =array();
+  var $DivListConference  = NULL;
 
   /* Initialise Class */
   function phoneConferenceManagment ($config, $ui)
@@ -47,48 +46,34 @@ class phoneConferenceManagment extends plugin
     $this->dn                  = "";
     $this->config              = $config;
 
-    /* Get global filter config */
-    if (!isset($_SESSION["conferencefilter"])){
-      $base= get_base_from_people($ui->dn);
-      $conferencefilter= array(
-          "depselect"       => $base,
-          "regex"           => "*");
-      $_SESSION["conferencefilter"] = $conferencefilter;
-    }
+    $acl= get_permissions ($ui->dn, $ui->subtreeACL);
+    $this->acl= get_module_permission($acl, "conference", $ui->dn);
+
+    $this->DivListConference = new divListConference($this->config,$this);
   }
 
+
   /* Execute class and display something */
   function execute()
   {
+    /* Call parent execute */
+    plugin::execute();
+
+    /***************
+      Variable initialisation
+     ***************/
+  
     /* Reload departments */
-    $this->config->departments = get_departments();
     $smarty                                                      = get_smarty();
     $display                                             = "";
     $s_action                                          = "";  // Will contain an action, like del or edit
     $s_entry                                           = "";  // The entry name for edit delete -...
-    $conferencefilter           = $_SESSION["conferencefilter"]; 
-
-    if(isset($_POST['regexit'])){
-      $conferencefilter['regex']=$_POST['regexit'];
-    }
-
-    if(isset($_GET['search'])){
-      if($_GET['search']=="*"){
-        $conferencefilter['regex']=$_GET['search'];
-      }else{
-        $conferencefilter['regex']=$_GET['search']."*";
-      }
-    }
-
-    $smarty->assign("regex",$conferencefilter['regex']); 
 
-    /* Start for New List Managment */
-    if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
-      $s_action="open";
-      $s_entry = base64_decode($_GET['dep_id']);
-      $conferencefilter['depselect']= "".$this->config->departments[trim($s_entry)];
-    }
 
+    /***************
+      Check posts  
+     ***************/
+  
     foreach($_POST as $key => $post){
       if(preg_match("/.*new.*/i",$key)){
         $s_action = "new";
@@ -102,12 +87,6 @@ class phoneConferenceManagment extends plugin
         $s_action="edit";
         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
         $s_entry  = preg_replace("/_.*$/","",$s_entry);
-      }elseif(preg_match("/dep_back.*/i",$key)){
-        $s_action="back";
-      }elseif(preg_match("/dep_home.*/i",$key)){
-        $s_action="home";
-      }elseif(preg_match("/dep_root.*/i",$key)){
-        $s_action="root";
       } 
     }
 
@@ -117,39 +96,13 @@ class phoneConferenceManagment extends plugin
       $s_entry  = $_GET['id'];
     }
 
-    /* Department changed? */
-    if(isset($_POST['depselect']) && $_POST['depselect']){
-      $conferencefilter['depselect']= $_POST['depselect'];
-    }
-
-    /* Homebutton is posted */
-    if($s_action=="home"){
-      $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
-      $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$conferencefilter['depselect']));
-    }
-    
-    /* back to root */
-    if($s_action=="root"){
-      $conferencefilter['depselect']=($this->config->current['BASE']);
-    }
-
-    /* If Backbutton is Posted */
-    if($s_action=="back"){
-      $base_back          = preg_replace("/^[^,]+,/","",$conferencefilter['depselect']);
-      $base_back          = convert_department_dn($base_back);
-
-      if(isset($this->config->departments[trim($base_back)])){
-        $conferencefilter['depselect']= $this->config->departments[trim($base_back)];
-      }else{
-        $conferencefilter['depselect']= $this->config->departments["/"];
-      }
-    }
-
-    register_global("conferencefilter",$conferencefilter);
-    $this->reload();
 
+    /***************
+      Cancel dialogs 
+     ***************/
+  
     /* Reset requested? */
-    if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
+    if (isset($_POST['edit_cancel'])){
       if (isset($this->conftab)){
         del_lock ($this->conftab->dn);
         unset ($this->conftab);
@@ -160,6 +113,11 @@ class phoneConferenceManagment extends plugin
       unset ($_SESSION['objectinfo']);
     }
 
+
+    /***************
+      Delete 
+     ***************/
+  
     /* Delete Entry if Posted action (s_action) == del
      * The entry which will be deleted is defined in $s_entry
      */
@@ -178,25 +136,32 @@ class phoneConferenceManagment extends plugin
       }
     }
 
+
+    /***************
+      Delete confirmed  
+     ***************/
+  
     /* If department deletion is accepted ...
      * Finally delete department
      */
     if (isset($_POST['delete_department_confirm'])){
-      $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-      $acl= get_module_permission($acl, "goFonConference", $this->dn);
-      if (chkacl($acl, "all") == ""){
+      if (chkacl($this->acl, "delete") == ""){
         $this->remove_from_parent();
         gosa_log ("Department object'".$this->dn."' has been removed");
-        $this->reload ();
       } else {
         print_red (_("You have no permission to remove this department."));
       }
     }
 
+
+    /***************
+      Edit
+     ***************/
+  
     /* Edit Entry if Posted action (s_action) == edit
      * The entry which will be edited is defined in $s_entry
      */
-    if ($s_action=="edit"){
+    if (($s_action=="edit") && (!isset($this->conftab->config))){
 
       $this->dn= $this->conferences[$s_entry]['dn'];
 
@@ -207,24 +172,32 @@ class phoneConferenceManagment extends plugin
       /* Lock the current entry, so everyone will get the  above dialog */
       add_lock ($this->dn, $this->ui->dn);
 
-      /* Set up the users ACL's for this 'dn' */
-      $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-
       /* Register conftab to trigger edit dialog */
       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
-      $this->conftab->set_acl(array(":all"));
       $_SESSION['objectinfo']= $this->dn;
     }
 
+
+    /***************
+      Create new  
+     ***************/
+  
     /* Insert new entry*/    
     if($s_action == "new"){
+      
+      /* Set up the users ACL's for this 'dn' */
       $this->dn= "new";
       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
-      $this->conftab->set_acl(array(':all'));
+      unset($_SESSION['objectinfo']);
     }
 
+
+    /***************
+      Save entry  
+     ***************/
+  
     /* Edit finished, check and save changes */
-    if (isset($_POST['edit_finish'])){
+    if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){
       /* Check tabs, will feed message array */
       $this->conftab->last= $this->conftab->current;
       $this->conftab->save_object();
@@ -237,198 +210,96 @@ class phoneConferenceManagment extends plugin
         }
         gosa_log ("goFonConference object '".$this->dn."' has been saved");
 
-        if ($this->dn != "new"){
-          del_lock ($this->dn);
+        if (!isset($_POST['edit_apply'])){
+          if ($this->dn != "new"){
+            del_lock ($this->dn);
+          }
         }
 
         $this->conftab->save ();
+        del_lock ($this->conftab->dn);;
         unset ($this->conftab);
         $this->conftab= NULL;
         unset ($_SESSION['objectinfo']);
       } else {
         show_errors($message);
       }
-      $this->reload();
     }
 
+
+    /***************
+      Display dialogs   
+     ***************/
+  
     /* if edit or new, show dialog */
-    if($this->conftab){
+    if(($this->conftab) && (isset($this->conftab->config))){
       $display= $this->conftab->execute();
 
       /* Don't show buttons if tab dialog requests this */
       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
         $display.= "<p style=\"text-align:right\">\n";
-        $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
+        $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
         $display.= "&nbsp;\n";
-        $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
+        if ($this->dn != "new"){
+          $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
+          $display.= "&nbsp;\n";
+        }
+        $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
         $display.= "</p>";
       }
       return ($display);
     }
 
-    /* Header + Departmentlist*/
-    $options= "";
-    foreach ($this->config->idepartments as $key => $value){
-      if ($conferencefilter['depselect'] == $key){
-        $options.= "<option selected value='$key'>$value</option>";
-      } else {
-        $options.= "<option value='$key'>$value</option>";
-      }
-    }
-
-    $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
-      " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
-      " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
-      " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
-      " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
-      " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
-      " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
-      _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
-      " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").     "'>&nbsp;".
-      "</div>";
-
-    /* Images for delete / edit */
-    $actions = "<input type='image' src='images/edit.png'               alt='"._("edit")."'      name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
-    $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
-    
-    $actions2= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
-    /* open an entry */
-    $linkopen= "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
-
-    /* Set Header */
-    $divlist  = new divlist("conferenceTabs");
-    $divlist->SetSummary(_("This table displays all available conference rooms."));
-    $divlist->SetEntriesPerPage(20);
-    $divlist->SetHeader(array(
-          array("string" => "&nbsp;"),            
-          array("string" =>_("Name / nummer")),
-          array("string" => _("Owner")),
-          array("string" => _("PIN")),
-          array("string" =>_("Actions"), "attach" => "style='text-align:  right;border:none'")));
-
-    /* Insert departments in divlist*/
-    foreach($this->departments as $key=> $val){
-      if(!isset($this->config->departments[trim($key)])){
-        $this->config->departments[trim($key)]="";
-      }
 
-      $non_empty="";
-      $keys= str_replace("/","\/",$key);
-      foreach($this->config->departments as $keyd=>$vald ){
-        if(preg_match("/".$keys."\/.*/",$keyd)){
-          $non_empty="full";
-        }
-      }
+    /***************
+      display divlist
+     ***************/
 
-      /* Prepare and insert fields*/
-      $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
-      $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
-      $a_field3 = array("string" => "&nbsp;");
-      $a_field4 = array("string" => "&nbsp;");
-      $a_field5 = array("string" => "&nbsp;",  "attach" => "style='text-align:  right;border:none'");
-
-      /* Add entries */
-      $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
+    /* Check if there is a snapshot dialog open */
+    if($str = $this->showSnapshotDialog($this->DivListConference->selectedBase,
+      array("ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase))){
+      return($str);
     }
 
-    /* Image shown in divlist */
-    $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";
-
-    /* Edit entry link*/
-    $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
-
-    /* Insert conferneces*/
-    foreach($this->conferences as $conferencekey => $conference ){
-  
-      if((isset($conference['goFonPIN'][0]))&&($this->ui->dn==$conference['goFonConferenceOwner'][0])){
-        $pin = $conference['goFonPIN'][0];
-      }else{
-        $pin = "&nbsp;";
-      }
-
-      if(isset($conference['telephoneNumber'][0])){
-        $number = " - ".$conference['telephoneNumber'][0];
-      }else{
-        $number = "&nbsp; - ?";
-      }
+    /* Return rendered main page */
+    /* Display dialog with system list */
+    $this->DivListConference->parent = $this;
+    $this->DivListConference->execute();
 
-      $ldap= $this->config->get_ldap_link();
-      $ldap->cd ($conference['goFonConferenceOwner'][0]);
-      $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
-      $cn = $data['cn'][0];
-      $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
-
-      $acl= get_permissions ($conference['dn'], $this->ui->subtreeACL);
-      $this->acl =  get_module_permission($acl, "goFonConference", $conference['dn']);
-
-      if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
-        $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number));
-      }else{  
-        $a_field2 = array("string"=>$conference['cn'][0].$number);
-      }
-      $a_field3 = array("string"=> $cn);
-      $a_field4 = array("string"=> $pin);
-
-      if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
-        $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='text-align:  right;border:none'");
-      }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
-        $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='text-align:  right;border:none'");
-      }else{
-        $a_field5 = array("string"=>"&nbsp;", "attach" => "style='text-align:  right;border:none'");
-      }
-
-      $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
+    /* Add departments if subsearch is disabled */
+    if(!$this->DivListConference->SubSearch){
+      $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5);
     }
-
-    $smarty->assign("search_image",     get_template_path('images/search.png'));
-    $smarty->assign("tree_image",       get_template_path('images/tree.png'));
-    $smarty->assign("infoimage",        get_template_path('images/info.png'));
-    $smarty->assign("launchimage",      get_template_path('images/launch.png'));
-    $smarty->assign("conferences",      $divlist->DrawList());
-    $smarty->assign("conferencehead",  $listhead);
-    $smarty->assign("deplist",          $this->config->idepartments);
-    $smarty->assign("apply",            apply_filter());
-    $smarty->assign("alphabet",         generate_alphabet());
-    $smarty->assign("hint",             print_sizelimit_warning());
-
-    $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
-    return($display);
+    $this->reload();
+    $this->DivListConference->setEntries($this->conferences);
+    return($this->DivListConference->Draw());
   }
 
 
   /* Reload entries for divlist.
-   * First, reload all conferences for the current base, with the given regex
-   * Second, get all departments for the given base and regex
-   * Convert departments dn
+   * reload all conferences for the current base, with the given regex
    */
   function reload()
   {
-    $conferencefilter = $_SESSION["conferencefilter"];
-    $base             = $conferencefilter['depselect'];
-    $regex            = $conferencefilter['regex'];
-
-    $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
-    $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
-
-    $this->departments= array();
-
-    $tmp = array();
-    foreach ($res3 as $value){
-      $tmp[strtolower($value['dn']).$value['dn']]=$value;
-    }
-    ksort($tmp);
-    foreach($tmp as $value){
-      if($value["description"][0]!=".."){
-        $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
-      }else{
-        $this->departments[$value['dn']]=$value["description"][0];
-      }
+    $Base             = "ou=conferences,ou=asterisk,ou=configs,ou=systems,".$this->DivListConference->selectedBase;
+    $SubSearch        = $this->DivListConference->SubSearch;
+    $Regex            = $this->DivListConference->Regex;
+    $Flags            = GL_SIZELIMIT ; 
+    $Filter           = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))";
+    $Attrs            = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber");
+    if($SubSearch){
+      $Flags |= GL_SUBSEARCH;
     }
+
+    $this->conferences= get_list($Filter,  $this->ui->subtreeACL, $Base, $Attrs, $Flags);
   }
 
   function remove_from_parent()
   {
+    $cfg = new conference($this->config, $this->dn);
+
+    $cfg->remove_from_parent();
     $ldap= $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
     $ldap->recursive_remove();
@@ -447,6 +318,11 @@ class phoneConferenceManagment extends plugin
 
   }
 
+  function save_object()
+  {
+    $this->DivListConference->save_object();
+  }
+
   function remove_lock()
   {
     if (isset($this->dn)){