Code

Set mode to read_only if we edit frozen apps
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationParameters.inc
index 9f11eb6b94a78f05aaeb9f6850a631bb73cfcc61..db49a00258ef6324e66075b4713e60852f506a4d 100644 (file)
@@ -1,20 +1,12 @@
 <?php
 class applicationParameters extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage application class parameters";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Parameters  */
   var $option_name= array();
   var $option_value= array();
 
   /* attribute list for save action */
   var $attributes= array("gosaApplicationParameter");
-  var $objectclasses= array();
-
-  var $CopyPasteVars = array("option_name","option_value");
 
   function applicationParameters (&$config, $dn= NULL, $parent= NULL)
   {
@@ -43,47 +35,52 @@ class applicationParameters extends plugin
     plugin::execute();
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
     /* Show tab dialog headers */
     $display= "";
     if ($this->parent !== NULL){
       if ($this->is_account){
-        $display= $this->show_disable_header(_("Remove options"),
-            _("This application has options. You can disable them by clicking below."));
+        $display= $this->show_disable_header(_("Remove options"),msgPool::featuresEnabled(_("parameter")));
       } else {
-        $display= $this->show_enable_header(_("Create options"),
-            _("This application has options disabled. You can enable them by clicking below."));
+        $display= $this->show_enable_header(_("Create options"), msgPool::featuresDisabled(_("parameter")));
         $this->parent->by_object['application']->generateTemplate();
         return ($display);
       }
     }
 
-    /* Add option to list */
-    if (isset($_POST['add_option'])){
-      $i= count($this->option_name);
-      $this->option_name[$i]= "";
-      $this->option_value[$i]= "";
-    }
+    if($this->acl_is_writeable("gosaApplicationParameter")){
 
-    /* Remove value from list */
-    for ($i= 0; $i<count($this->option_name); $i++){
-      if (isset($_POST["remove$i"])){
-        $k= 0;
-        $on= array();
-        $ov= array();
-        for ($j= 0; $j<count($this->option_name); $j++){
-          if ($j != $i){
-            $on[$k]= $this->option_name[$j];
-            $ov[$k]= $this->option_value[$j];
-            $k++;
+      /* Add option to list */
+      if (isset($_POST['add_option'])){
+        $i= count($this->option_name);
+        $this->option_name[$i]= "";
+        $this->option_value[$i]= "";
+      }
+
+      /* Remove value from list */
+      for ($i= 0; $i<count($this->option_name); $i++){
+        if (isset($_POST["remove$i"])){
+          $k= 0;
+          $on= array();
+          $ov= array();
+          for ($j= 0; $j<count($this->option_name); $j++){
+            if ($j != $i){
+              $on[$k]= $this->option_name[$j];
+              $ov[$k]= $this->option_value[$j];
+              $k++;
+            }
           }
+          $this->option_name= $on;
+          $this->option_value= $ov;
+          break;
         }
-        $this->option_name= $on;
-        $this->option_value= $ov;
-        break;
       }
     }
 
@@ -92,10 +89,11 @@ class applicationParameters extends plugin
       $this->option_name[]= "";
       $this->option_value[]= "";
     }
+    
 
 
     $acl = $this->getacl("gosaApplicationParameter")   ;
-    $table= "<table summary=\"\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
+    $table= "<table summary=\""._("Application parameter")."\"><tr><td>"._("Variable")."</td><td>"._("Default value")."</td><td></td></tr>";
     if (count ($this->option_name)){
 
       for ($i= 0; $i < count($this->option_name); $i++){
@@ -127,7 +125,7 @@ class applicationParameters extends plugin
       }
     }
     $table.= "</table>";
-    $table.="<input type=\"submit\" name=\"add_option\" value=\""._("Add option")."\">";
+    $table.="<input type=\"submit\" name=\"add_option\" $tag value=\""._("Add option")."\">";
 
     /* Show main page */
     $smarty= get_smarty();
@@ -156,7 +154,9 @@ class applicationParameters extends plugin
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of application parameters with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events('remove');
@@ -166,7 +166,7 @@ class applicationParameters extends plugin
   /* Save data to object */
   function save_object()
   {
-    if (isset($_POST['option0'])){
+    if (isset($_POST['option0']) && $this->acl_is_writeable("gosaApplicationParameter")){
       for ($i= 0; $i<count($this->option_name); $i++){
         $this->option_name[$i]= $_POST["option$i"];
         $this->option_value[$i]= "";
@@ -187,8 +187,7 @@ class applicationParameters extends plugin
     /* Check for valid option names */
     for ($i= 0; $i<count($this->option_name); $i++){
       if (!preg_match ("/^[a-z0-9_]+$/i", $this->option_name[$i])){
-        $message[]= sprintf(_("Value '%s' specified as option name is not valid."), 
-            $this->option_name[$i]);
+        $message[]= msgPool::invalid(_("Name"), $this->option_name[$i],"/^[a-z0-9_]+$/i");
       }
     }
 
@@ -218,12 +217,28 @@ class applicationParameters extends plugin
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of application parameters with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events('modify');
   }
 
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    $source_o = new applicationParameters($this->config,$source['dn']);
+    $this->option_name = $source_o->option_name;
+    $this->option_value = $source_o->option_value;
+
+    /* Set is_account state so that the save function is called properly */
+    $this->is_account = TRUE;
+  }
+
+
   /* Return plugin informations for acl handling
 #FIXME FAIscript seams to ununsed within this class... */
   static function plInfo()