Code

Fixed object lock output for comma attached dn's
[gosa.git] / plugins / gofax / blocklists / class_blocklistManagement.inc
index af37e1b76d6918281137dc33e3f9743f2b941f56..0e470ae16803bf77d1c82054e0d2d96e8f12ba21 100644 (file)
@@ -33,17 +33,18 @@ class blocklist extends plugin
     /* Get global filter config */
     if (!is_global("blockfilter")){
       $ui= get_userinfo();
-      $base= get_base_from_people($ui->dn);
+      $this->base= get_base_from_people($ui->dn);
       $blockfilter= array("sendlists" => "checked",
           "receivelists" => "checked",
           "entry" => "*",
-          "depselect" => $base,
+          "depselect" => $this->base,
           "regex" => "*");
       register_global("blockfilter", $blockfilter);
     }else{
       $blockfilter = $_SESSION["blockfilter"];
       $this->base = $blockfilter['depselect'];
     }
+
     $ui= get_userinfo();
     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
     $this->acl= get_module_permission($acl, "blocklists", $ui->dn);
@@ -69,6 +70,15 @@ class blocklist extends plugin
       $this->reload();
     }
 
+    /* Cancel dialog */
+    if (isset($_POST['edit_cancel']) || isset($_POST['delete_blocklist_cancel']) ||
+        isset($_POST['delete_blocklist_confirm']) || isset($_POST['delete_lock'])){
+
+      del_lock ($this->dn);
+      $this->clear_fields();
+      unset($_SESSION['objectinfo']);
+    }
+
     /* Test Posts */
     foreach($_POST as $key => $val){
       // Post for delete
@@ -172,24 +182,37 @@ class blocklist extends plugin
     }
 
     /* Edit selected blocklist? */
-    if ($s_action=="edit"){
+    if (($s_action=="edit") && (empty($this->dn))){
       $this->clear_fields();
       $this->dn=$this->blocklists[$s_entry]['dn']; 
-      plugin::plugin ($this->config, $this->dn);
+      if (($user= get_lock($this->dn)) != ""){
+        $_SESSION['dn']= $this->dn;
+        //$this->dn ="";
+        return(gen_locked_message($user, $this->dn));
+      } else {
+# Lock this dn for editing
+        add_lock ($this->dn, $this->ui->dn);
 
-      /* Load missing lists */
-      if (isset($this->attrs["goFaxSBlocklist"])){
-        for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){
-          $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i];
-        }
-        $this->type= 0;
-      } elseif (isset($this->attrs["goFaxRBlocklist"])){
-        for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){
-          $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i];
+        plugin::plugin ($this->config, $this->dn);
+
+        /* Load missing lists */
+        if (in_array("goFaxSBlock",$this->attrs['objectClass'])){
+          if(isset($this->attrs["goFaxSBlocklist"])){
+            for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){
+              $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i];
+            }
+          }
+          $this->type= 0;
+        } elseif (in_array("goFaxRBlock",$this->attrs['objectClass'])){
+          if(isset($this->attrs["goFaxRBlocklist"])){
+            for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){
+              $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i];
+            }
+          }
+          $this->type= 1;
         }
-        $this->type= 1;
+        $_SESSION['objectinfo']= trim($this->dn);
       }
-      $_SESSION['objectinfo']= trim($this->dn);
     }
 
     /* Delete blocklist requested */
@@ -219,14 +242,6 @@ class blocklist extends plugin
       }
     }
 
-    /* Cancel dialog */
-    if (isset($_POST['edit_cancel']) || isset($_POST['delete_blocklist_cancel']) ||
-        isset($_POST['delete_blocklist_confirm']) || isset($_POST['delete_lock'])){
-
-      del_lock ($this->dn);
-      $this->clear_fields();
-      unset($_SESSION['objectinfo']);
-    }
 
     /* Handle interactions: add */
     if (isset($_POST['add_number']) && $_POST['number'] != ""){
@@ -243,8 +258,9 @@ class blocklist extends plugin
     }
 
     /* What about finish? */
-    if (isset($_POST['edit_finish'])){
+    if ((isset($_POST['edit_finish'])) && (!empty($this->dn))){
       $message= $this->check();
+      $this->remove_lock();
 
       /* No errors, save object */
       if (count ($message) == 0){
@@ -253,7 +269,7 @@ class blocklist extends plugin
         if ($this->dn == "new"){
           $this->dn= "cn=$this->cn,ou=gofax,ou=systems,".$this->base;
         }
-
+        
         $this->save ();
         gosa_log ("Blocklist object'".$this->dn."' has been saved");
         $this->dn= "";
@@ -288,12 +304,13 @@ class blocklist extends plugin
 
       /* NEW LIST MANAGMENT */
       $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
-        " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
         " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
+        " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
         " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
+        " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
         " <input class='center' type='image' align='middle' src='images/list_new_blocklist.png' title='"._("Create new blocklist")."' alt='"._("New Blocklist")."' name='user_new'>&nbsp;".
-        " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
+        " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;"._("Base")."&nbsp;<select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
         " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
         "</div>";
 
@@ -375,7 +392,7 @@ class blocklist extends plugin
 
     /* Fill templating stuff */
     $smarty->assign("bases", $this->config->idepartments);
-    $smarty->assign("base_select", $_SESSION['blockfilter']['depselect']);//$this->base);
+    $smarty->assign("base_select", $this->base);
     $smarty->assign("types", array(0 => _("send"), 1 => _("receive")));
     if ($this->dn == "new" || preg_match ("/,ou=incoming,/", $this->dn)){
       $smarty->assign("selectmode", "");
@@ -403,7 +420,7 @@ class blocklist extends plugin
     $this->dn= "";
     $this->description= "";
     $this->cn= "";
-    $this->base= "";
+    $this->base= $_SESSION['blockfilter']['depselect'];
     $this->goFaxBlocklist= array();
   }
 
@@ -448,7 +465,13 @@ class blocklist extends plugin
      * We also need to search for the departments
      * So we are able to navigate like in konquerer
      */
-    $base2 = preg_replace("/ou=people,/i","",$base);
+    $peopleBase = get_people_ou();
+    if(empty($peopleBase)){
+      $base2 = $base;
+    }else{
+      $base2 = preg_replace("/".$peopleBase.",/i","",$base);
+    }
+   
     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
         TRUE, $base2, array("ou", "description"), TRUE);
 
@@ -493,6 +516,10 @@ class blocklist extends plugin
   {
     plugin::save_object();
 
+    if(isset($_POST['base'])){
+      $this->base = $_POST['base'];
+    }
     foreach($this->attributes as $attr){
       if(isset($_POST[$attr])){
         $this->$attr = $_POST[$attr];
@@ -527,8 +554,7 @@ class blocklist extends plugin
       if ($this->dn == 'new'){
         $ldap= $this->config->get_ldap_link();
         $ldap->cd ("ou=gofax,ou=systems,".$this->config->current["BASE"]);
-        $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))".
-            "(cn=".$this->cn."))", array("cn"));
+        $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))(cn=".$this->cn."))", array("cn"));
         if ($ldap->count() != 0){
           $message[]= _("Specified name is already used.");
         }
@@ -548,6 +574,7 @@ class blocklist extends plugin
   function save()
   {
     plugin::save();
+    
 
     /* Type selection */
     if ($this->type == 0){
@@ -564,14 +591,17 @@ class blocklist extends plugin
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
-    $ldap->cd($ldap->getParentDir($this->dn));
-    $ldap->search("cn=$this->cn");
+    $ldap->cd($this->base);
+    $ldap->search("cn=$this->cn",array("cn"));
+    $ldap->cat($this->dn);
     $a= $ldap->fetch();
+    
     if (count($a)){
       if (!isset($this->attrs["$type"."list"])){
         $this->attrs["$type"."list"]= array();
       }
       $ldap->cd($this->dn);
+      $this->cleanup();
       $ldap->modify($this->attrs);
       $this->handle_post_events("modify");
     } else {