Code

Fixed object lock output for comma attached dn's
[gosa.git] / plugins / gofax / blocklists / class_blocklistManagement.inc
index 675ea036bf39abfbad84a0f0a5c05f46f1bbf389..0e470ae16803bf77d1c82054e0d2d96e8f12ba21 100644 (file)
@@ -32,18 +32,22 @@ class blocklist extends plugin
 
     /* Get global filter config */
     if (!is_global("blockfilter")){
-      $uii= get_userinfo();
-      $base= get_base_from_people($ui->dn);
+      $ui= get_userinfo();
+      $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);
   }
 
   function execute()
@@ -66,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
@@ -164,32 +177,42 @@ class blocklist extends plugin
     /* Create new blocklist? */
     if ($s_action=="new"){
       $this->clear_fields();
-      $this->acl= "#all#";
       $this->dn= "new";
       plugin::plugin ($this->config, $this->dn);
     }
 
     /* Edit selected blocklist? */
-    if ($s_action=="edit"){
+    if (($s_action=="edit") && (empty($this->dn))){
       $this->clear_fields();
       $this->dn=$this->blocklists[$s_entry]['dn']; 
-      $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-      $this->acl= get_module_permission($this->acl, "blocklists", $this->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 */
@@ -210,9 +233,7 @@ class blocklist extends plugin
 
     /* Finally delete blocklist */
     if (isset($_POST['delete_blocklist_confirm'])){
-      $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-      $acl= get_module_permission($acl, "blocklists", $this->dn);
-      if (chkacl($acl, "all") == ""){
+      if (chkacl($this->acl, "delete") == ""){
         $this->remove_from_parent();
         gosa_log ("Blocklist object'".$this->dn."' has been removed");
         $this->reload ();
@@ -221,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'] != ""){
@@ -245,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){
@@ -255,10 +269,9 @@ 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->acl= "#none#";
         $this->dn= "";
         del_lock ($this->ui->dn);
         unset($_SESSION['objectinfo']);
@@ -291,24 +304,25 @@ class blocklist extends plugin
 
       /* NEW LIST MANAGMENT */
       $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_blocklist.png' title='"._("Create new blocklist")."' alt='"._("New Blocklist")."' 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;".
+        " <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;"._("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>";
 
-      $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
-      $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
+      $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
+      $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
 
 
       $divlist = new divlist("faxtabs");
       $divlist->SetHeader(array(
-            array("string" => "&nbsp;"),
-            array("string" => _("Blocklist name")." / "._("Department")),
-            array("string" => _("Actions"), "attach" => "style='border:none'" )));
+            array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
+            array("string" => _("Blocklist name")." / "._("Department"), "attach" => "style=''"),
+            array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
 
 
       $divlist->SetSummary(_("This table displays faxblocklists for the selected tree."));
@@ -329,22 +343,22 @@ class blocklist extends plugin
           }
         }
 
-        $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
-        $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
-        $field3 = array("string" => "&nbsp;", "attach" => "style='border:none'");
+        $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
+        $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
+        $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
         $divlist->AddEntry(array($field1,$field2,$field3));
       }
 
       // User and Template  Images
-      $blockimg = "<img src='images/list_blocklist.png' alt='User' title='%s'>";
+      $blockimg = "<img class='center' src='images/list_blocklist.png' alt='User' title='%s'>";
       $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
       foreach($this->blocklists as $key => $val){
         // Generate Array to Add
         $display= "[".$val["cn"][0]."]";
-        $field1 = array("string" => sprintf($blockimg,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
-        $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
-        $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:40px'");
+        $field1 = array("string" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
+        $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
+        $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
         $divlist->AddEntry( array($field1,$field2,$field3));
       }
 
@@ -378,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", "");
@@ -406,9 +420,8 @@ class blocklist extends plugin
     $this->dn= "";
     $this->description= "";
     $this->cn= "";
-    $this->base= "";
+    $this->base= $_SESSION['blockfilter']['depselect'];
     $this->goFaxBlocklist= array();
-    $this->acl= "#none#";
   }
 
   function reload()
@@ -452,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);
 
@@ -463,10 +482,10 @@ class blocklist extends plugin
     }
     ksort($tmp);
     foreach($tmp as $value){
-      if($value["description"][0]!=".."){
+      if(isset($value["description"][0])){
         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
       }else{
-        $this->departments[$value['dn']]=$value["description"][0];
+        $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
       }
     }
 
@@ -497,18 +516,17 @@ class blocklist extends plugin
   {
     plugin::save_object();
 
-    /* Save type, needed to detect objectClass */
-    if (isset($_POST['type']) && chkacl($this->acl, "cn") == ""){
-      $this->type= $_POST['type'];
+    if(isset($_POST['base'])){
+      $this->base = $_POST['base'];
     }
-
-    /* Save base, since this is no LDAP attribute */
-    if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
-      $this->base= $_POST['base'];
+    foreach($this->attributes as $attr){
+      if(isset($_POST[$attr])){
+        $this->$attr = $_POST[$attr];
+      }
     }
   }
 
-
   /* Check values */
   function check()
   {
@@ -521,10 +539,7 @@ class blocklist extends plugin
       $new_dn= $this->dn;
     }
 
-    $ui= get_userinfo();
-    $acl= get_permissions ($new_dn, $ui->subtreeACL);
-    $acl= get_module_permission($acl, "blocklist", $new_dn);
-    if (chkacl($acl, "create") != ""){
+    if (chkacl($this->acl, "create") != ""){
       $message[]= _("You have no permissions to create a blocklist on this 'Base'.");
     }
 
@@ -539,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.");
         }
@@ -560,6 +574,7 @@ class blocklist extends plugin
   function save()
   {
     plugin::save();
+    
 
     /* Type selection */
     if ($this->type == 0){
@@ -576,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 {