Code

Some little changes:
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 7 Nov 2005 06:57:13 +0000 (06:57 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 7 Nov 2005 06:57:13 +0000 (06:57 +0000)
Please use save_object to store posts in the class object.
Save_object is called everytime when the tab is submitted.
All the checkbox settings wasn't kept when switching to another tab and back.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1843 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/personal/nagios/class_nagiosAccount.inc
plugins/personal/nagios/nagios.tpl

index b342c08d93174c2e42c7e41b1857e6ec3b35945f..9465e97e73245e331f49da1e13051e0c5de28f87 100644 (file)
 
 class nagiosAccount extends plugin
 {
-       /* Definitions */
-       var $plHeadline= "Nagios";
-       var $plDescription= "This does something";
-       
-       /* CLI vars */
-       var $cli_summary= "Manage users nagios account";
-       var $cli_description= "Manage Account and autorization\nfor Nagios";
-       var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+  /* Definitions */
+  var $plHeadline= "Nagios";
+  var $plDescription= "This does something";
+
+  /* CLI vars */
+  var $cli_summary= "Manage users nagios account";
+  var $cli_description= "Manage Account and autorization\nfor Nagios";
+  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* plugin specific values */
-  var $NagiosAlias= "";
-  var $NagiosPager= "";
-  var $NagiosMail= "";
-  var $HostNotificationPeriod= "";
-  var $ServiceNotitificationPeriod= "";
-  var $HostNotificationCommands= "";
-  var $ServiceNotificationCommands= "";
-  var $HostNotitificationOptions= "";
-  var $ServiceNotificationOptions= "";
-
-  var $AuthorizedAllHosts= "";
-  var $AuthorizedAllServices= "";
-  var $AuthorizedSystemCommands= "";
-  var $AuthorizedAllHostCommands= "";
-  var $AuthorizedAllServiceCommands= "";
-  var $AuthorizedConfigurationInformation= "";
-  var $AuthorizedSystemInformation= "";
+  var $NagiosAlias  = "";
+  var $NagiosPager  = "";
+  var $NagiosMail   = "";
+
+  var $HostNotificationOptions      = "";
+  var $HostNotificationPeriod       = "";
+  var $ServiceNotificationPeriod    = "";
+  var $ServiceNotitificationPeriod  = "";
+  var $HostNotificationCommands     = "";
+  var $ServiceNotificationCommands  = "";
+  var $HostNotitificationOptions    = "";
+  var $ServiceNotificationOptions   = "";
+
+  var $AuthorizedAllHosts                 = "unchecked";
+  var $AuthorizedAllServices              = "unchecked";
+  var $AuthorizedSystemCommands           = "unchecked";
+  var $AuthorizedAllHostCommands          = "unchecked";
+  var $AuthorizedAllServiceCommands       = "unchecked";
+  var $AuthorizedConfigurationInformation = "unchecked";
+  var $AuthorizedSystemInformation        = "unchecked";
 
   /* attribute list for save action */
-  
-       var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
+
+  var $attributes= array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
       "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
       "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
       "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
       "AuthorizedConfigurationInformation", "AuthorizedSystemInformation");
 
+  var $is_chk_box = array("AuthorizedAllHosts","AuthorizedAllServices","AuthorizedSystemCommands",
+      "AuthorizedAllHostCommands","AuthorizedAllServiceCommands",
+      "AuthorizedConfigurationInformation","AuthorizedSystemInformation");
+
   var $objectclasses= array("nagiosContact","nagiosAuth");
 
   /* constructor, if 'dn' is set, the node loads the given
-       'dn' from LDAP */
+     'dn' from LDAP */
   function nagiosAccount ($config, $dn= NULL)
   {
     /* Configuration is fine, allways */
     $this->config= $config;
-    
-       plugin::plugin ($config, $dn);
+
+    plugin::plugin ($config, $dn);
 
     /* Save initial account state */  
-         $this->initially_was_account= $this->is_account;
+    $this->initially_was_account= $this->is_account;
   }
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Load templating engine */
     $smarty= get_smarty();
     $display= "";
 
-         /* Do we need to flip is_account state? */
-         if (isset($_POST['modify_state'])){
-           $this->is_account= !$this->is_account;
-         }
-  
-         /* Do we represent a valid account? */
-           if (!$this->is_account && $this->parent == NULL){
-             $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-                     _("This account has no nagios extensions.")."</b>";
-    
-        $display.= back_to_main();
-        return ($display);
-           }
-  
-         /* Show tab dialog headers */
-         if ($this->parent != NULL){
+    /* Do we need to flip is_account state? */
+    if (isset($_POST['modify_state'])){
+      $this->is_account= !$this->is_account;
+    }
+
+    /* Do we represent a valid account? */
+    if (!$this->is_account && $this->parent == NULL){
+      $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
+        _("This account has no nagios extensions.")."</b>";
+
+      $display.= back_to_main();
+      return ($display);
+    }
+
+    /* Show tab dialog headers */
+    if ($this->parent != NULL){
       if ($this->is_account){
         $display= $this->show_header(_("Remove nagios account"),
             _("This account has nagios features enabled. You can disable them by clicking below."));
       } else {
         $display= $this->show_header(_("Create nagios account"), _("This account has nagios features disabled. You can enable them by clicking below."));
         return($display);
-           }
-         }
-         
-    foreach(array("NagiosAlias", "NagiosPager", "NagiosMail", "HostNotificationPeriod",
-                  "ServiceNotificationPeriod", "HostNotificationCommands", "ServiceNotificationCommands",
-                  "HostNotificationOptions", "ServiceNotificationOptions", "AuthorizedAllHosts", "AuthorizedAllServices",
-                  "AuthorizedSystemCommands", "AuthorizedAllHostCommands", "AuthorizedAllServiceCommands",
-                  "AuthorizedConfigurationInformation", "AuthorizedSystemInformation") as $val) {
-
-    $smarty->assign("$val", $this->$val);
-    $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
+      }
     }
-    $smarty->assign('ServiceNotificationOptionsValues',array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
-    $smarty->assign('HostNotificationOptionsValues',array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
-
-
-    $smarty->assign('ServiceNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
-    $smarty->assign('HostNotificationPeriodValues',array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
-
-       $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
-           return ($display);
 
+    /* Assign attributes an ACL to smarty */
+    foreach($this->attributes as $val) { 
+      $smarty->assign("$val", $this->$val);
+      $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
+      if(in_array($val,$this->is_chk_box)){
+        if($this->$val == "checked"){
+          $smarty->assign($val."CHK", " checked ");
+        }else{
+          $smarty->assign($val."CHK", "");
+        }
+      }
+    }
+    $smarty->assign('ServiceNotificationOptionsValues'  ,array("d,u,r,v"=>"d,u,r,v" ,"d,u,r"=>"d,u,r" ,"d,u"=>"d,u"));
+    $smarty->assign('HostNotificationOptionsValues'     ,array("w,u,c,r"=>"w,u,c,r" ,"w,u,c"=>"w,u,c" ,"c,w"=>"c,w"));
+    $smarty->assign('ServiceNotificationPeriodValues'   ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
+    $smarty->assign('HostNotificationPeriodValues'      ,array("24x7"=>"24x7" ,"24x5"=>"24x5" ,"8x5"=>"8x5"));
+    $display.= $smarty->fetch (get_template_path('nagios.tpl', TRUE, dirname(__FILE__)));
+    return ($display);
   }
 
   /* Save to LDAP */
@@ -126,41 +132,26 @@ class nagiosAccount extends plugin
     $ldap= $this->config->get_ldap_link();
 
     /* Call parents save to prepare $this->attrs */
-         plugin::save();
+    plugin::save();
 
     /* Adapt attributes if needed */
     //$method= new $this->method($this->config);
     //$id= $method->uattrib;
     //$method->fixAttributesOnStore($this);
 
-       $check="unchecked";
-       if(isset($_POST['AuthorizedSystemInformation'])){$check="checked";}$this->attrs['AuthorizedSystemInformation']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedConfigurationInformation'])){$check="checked";}$this->attrs['AuthorizedConfigurationInformation']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedSystemCommands'])){$check="checked";}$this->attrs['AuthorizedSystemCommands']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedAllServices'])){$check="checked";}$this->attrs['AuthorizedAllServices']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedAllHosts'])){$check="checked";}$this->attrs['AuthorizedAllHosts']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedAllServiceCommands'])){$check="checked";}$this->attrs['AuthorizedAllServiceCommands']=$check;
-       $check="unchecked";
-       if(isset($_POST['AuthorizedAllHostCommands'])){$check="checked";}$this->attrs['AuthorizedAllHostCommands']=$check;
-         /* Write back to ldap */
-         $ldap->cd($this->dn);
-         $ldap->modify($this->attrs);
-         show_ldap_error($ldap->get_error());
-       
-         /* Optionally execute a command after we're done */
-         if ($this->initially_was_account == $this->is_account){
-           if ($this->is_modified){
-                   $this->handle_post_events("modify");
-           }
-         } else {
-           $this->handle_post_events("add");
+    /* Write back to ldap */
+    $ldap->cd($this->dn);
+    $ldap->modify($this->attrs);
+    show_ldap_error($ldap->get_error());
+
+    /* Optionally execute a command after we're done */
+    if ($this->initially_was_account == $this->is_account){
+      if ($this->is_modified){
+        $this->handle_post_events("modify");
+      }
+    } else {
+      $this->handle_post_events("add");
     }
-       
   }
 
   function check()
@@ -183,24 +174,34 @@ class nagiosAccount extends plugin
         $message[]= _("Please enter a valid email address in 'NagiosMail' field.");
       }
     }
-       return($message);
+    return($message);
   }
-  
+
+
+  /* Use Save_object for every Post handling */
   function save_object()
   {
-
     if (isset($_POST['nagiosTab'])){
       /* Save ldap attributes */
       plugin::save_object();
+
+      /* Specialhandling for checkboxes */
+      foreach($this->is_chk_box as $val){
+        if(isset($_POST[$val])){
+          $this->$val = "checked";
+        }else{
+          $this->$val = "unchecked";
+        }
+      }
     }
   }
 
   function remove_from_parent()
   {
-         /* Cancel if there's nothing to do here */
-         if (!$this->initially_was_account){
-           return;
-         }
+    /* Cancel if there's nothing to do here */
+    if (!$this->initially_was_account){
+      return;
+    }
 
     /* include global link_info */
     $ldap= $this->config->get_ldap_link();
@@ -209,19 +210,18 @@ class nagiosAccount extends plugin
     plugin::remove_from_parent();
 
     /* Adapt attributes if needed */
-//     $method= new $this->method($this->config);
-//     $method->fixAttributesOnRemove($this);
-    
+    //     $method= new $this->method($this->config);
+    //     $method->fixAttributesOnRemove($this);
 
     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
-      $this->attributes, "Save");
+        $this->attributes, "Save");
     $ldap->cd($this->dn);
     $ldap->modify($this->attrs);
     show_ldap_error($ldap->get_error());
-                        
+
     /* remove the entry from LDAP */
     unset ($this->attrs['uid']);
-                
+
     /* Optionally execute a command after we're done */
     $this->handle_post_events('remove');
   }
index 24355eb8ac04ebb47f68b502c4bd508de6cd7534..b5cc3e99f17246eb8a5db66c15ca8c167dd3b9f1 100644 (file)
 <td style="width:100%; vertical-align:top;">
    <h2><img alt="" align="middle" src="images/rightarrow.png"> {t}Nagios authentification{/t}</h2>
    <table summary="">
-       <tr><td><input type="checkbox" name="AuthorizedSystemInformation" value="{$AuthorizedSystemInformation}"  {$AuthorizedSystemInformation}>{t}can view system informations{/t}</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedSystemInformation" value="1" {$AuthorizedSystemInformationACL}  
+{$AuthorizedSystemInformationCHK}>{t}can view system informations{/t}</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedConfigurationInformation" {$AuthorizedConfigurationInformationACL} value="{$AuthorizedConfigurationInformation}" {$AuthorizedConfigurationInformation}>authorized_for_configuration_information</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedConfigurationInformation" {$AuthorizedConfigurationInformationACL} value="1" 
+{$AuthorizedConfigurationInformationCHK}>authorized_for_configuration_information</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedSystemCommands" {$AuthorizedSystemCommandsACL} value="{$AuthorizedSystemCommands}" {$AuthorizedSystemCommands}>authorized_for_system_commands</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedSystemCommands" {$AuthorizedSystemCommandsACL} value="1" 
+{$AuthorizedSystemCommandsCHK}>authorized_for_system_commands</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedAllServices" {$AuthorizedAllServicesACL} value="{$AuthorizedAllServices}" {$AuthorizedAllServices}>authorized_for_all_services</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedAllServices" {$AuthorizedAllServicesACL} value="1" 
+{$AuthorizedAllServicesCHK}>authorized_for_all_services</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedAllHosts" {$AuthorizedAllHostsACL} value="{$AuthorizedAllHosts}" {$AuthorizedAllHosts}>authorized_for_all_hosts</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedAllHosts" {$AuthorizedAllHostsACL} value="1" 
+{$AuthorizedAllHostsCHK}>authorized_for_all_hosts</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedAllServiceCommands" {$AuthorizedAllServiceCommandsACL} value="{$AuthorizedAllServiceCommands}" {$AuthorizedAllServiceCommands}>authorized_for_all_service_commands</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedAllServiceCommands" {$AuthorizedAllServiceCommandsACL} value="1" {$AuthorizedAllServiceCommandsCHK}>authorized_for_all_service_commands</td></tr>
        
-       <tr><td><input type="checkbox" name="AuthorizedAllHostCommands" {$AuthorizedAllHostCommandsACL} value="{$AuthorizedAllHostCommands}" AuthorizedAllHostCommands}>authorized_for_all_host_commands</td></tr>
+       <tr><td><input type="checkbox" name="AuthorizedAllHostCommands" {$AuthorizedAllHostCommandsACL} value="1" 
+{$AuthorizedAllHostCommandsCHK}>authorized_for_all_host_commands</td></tr>
 
    </table>
 </td>