Code

Fixed plugin design which was totaly different from the original idea...
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 17 Jun 2005 14:04:36 +0000 (14:04 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 17 Jun 2005 14:04:36 +0000 (14:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@742 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_plugin.inc
plugins/admin/systems/class_servService.inc
plugins/admin/systems/servservice.tpl

index 642c52b3e0ffbab914dcbf9dbfd3acd99c15ca6c..fb5e55d4a60f42b5e4b4e144dca3b4b460a6039f 100644 (file)
@@ -367,7 +367,7 @@ class plugin
   {
     /* Find postcreate entries for this class */
     $command= search_config($this->config->data['MENU'], get_class($this), "POSTCREATE");
-    if ($command == ""){
+    if ($command == "" && isset($this->config->data['TAB'])){
       $command= search_config($this->config->data['TAB'], get_class($this), "POSTCREATE");
     }
 
@@ -393,7 +393,7 @@ class plugin
   {
     /* Find postcreate entries for this class */
     $command= search_config($this->config->data['MENU'], get_class($this), "POSTMODIFY");
-    if ($command == ""){
+    if ($command == "" && isset($this->config->data['TAB'])){
       $command= search_config($this->config->data['TAB'], get_class($this), "POSTMODIFY");
     }
 
@@ -419,7 +419,7 @@ class plugin
   {
     /* Find postremove entries for this class */
     $command= search_config($this->config->data['MENU'], get_class($this), "POSTREMOVE");
-    if ($command == ""){
+    if ($command == "" && isset($this->config->data['TAB'])){
       $command= search_config($this->config->data['TAB'], get_class($this), "POSTREMOVE");
     }
 
index 3c6fae64c4c4db91ef6e2dddc6b1cc7be17b9330..5343f155d0561b3d8c1fb2a89f2b55fdf63ce366 100644 (file)
@@ -20,131 +20,94 @@ class servservice extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes       = array("goExportEntry","goTimeSource","goLdapBase","goXdmcpIsEnabled","goFontPath" );
+  var $attributes       = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
   var $objectclasses    = array("top","goServer"); 
-  var $additionaloc     = array(
-                
-                          "goNfsServer"     => array("goExportEntry"),
-                          "goNtpServer"     => array("goTimeSource"),
-                          "goLdapServer"    => array("goLdapBase"),
-                          "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
-                          "goSyslogServer"  => array(),
-                          "goCupsServer"    => array()                           
-                          );
-
-
-
-
-
-
-
-
+  var $additionaloc     = array( "goNfsServer"     => array("goExportEntry"),
+                                 "goNtpServer"     => array("goTimeSource"),
+                                 "goLdapServer"    => array("goLdapBase"),
+                                 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
+                                 "goSyslogServer"  => array(),
+                                 "goCupsServer"    => array());
 
   function servservice ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
-
+    
+    /* Assemble final object class list */
     foreach ($this->additionaloc as $oc => $dummy){
       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
         $this->objectclasses[$oc]= $oc;
       }
     }
+
+    /* Load arrays */
+    foreach (array("goTimeSource", "goExportEntry") as $name){
+      $this->$name= array();
+      if (isset($this->attrs[$name])){
+        for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
+          $this->$name[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
+        }
+      }
+    }
+
     /* Always is account... */
     $this->is_account= TRUE;
   }
 
 
-
   function execute()
   {
     /* Fill templating stuff */
     $smarty= get_smarty();
 
-    
     $smarty->assign("staticAddress", "");
-      
-    /*  
-    Handling for Nfs Export Entries
-    */
 
     /* Here we add a new entry  */
-    if(isset($_POST['NewNfsAdd']))
-      {
-      $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
-      }
-     
+    if(isset($_POST['NewNfsAdd']) && $_POST['NewNfsExport'] != "") {
+      $this->goExportEntry[$_POST['NewNfsExport']]= $_POST['NewNfsExport'];
+      asort($this->goExportEntry);
+    }
+
     /* Deleting an Entry, is a bit more complicated than adding one*/
-    if(isset($_POST['DelNfsEnt']))
-      {
-      /* Go through all entries an skip the selected (The one we want to delete)*/
-      foreach($this->attrs['goExportEntry'] as $key => $val)
-        {
-        /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
-        if(($val != $_POST['goExportEntry'] ))
-          {
-          /* Skip the entry that we want to delete*/
-          $new_arr[]=$val;
-          }
+    if(isset($_POST['DelNfsEnt']) && isset($_POST['goExportEntry'])) {
+      foreach ($_POST['goExportEntry'] as $entry){
+        if (isset($this->goExportEntry[$entry])){
+          unset($this->goExportEntry[$entry]);
         }
-      /* Deleting complete so add result to the attrs */
-      $this->attrs['goExportEntry']=$new_arr;
-      }
-
-    /* Set the entry which we want to show in the frontend */
-    if(isset($this->attrs['goExportEntry']))
-      {
-      $this->goExportEntry = ($this->attrs['goExportEntry']);
-      unset($this->goExportEntry['count']);
       }
-
-
-   /*
-    Handling for NTP Export Entries
-    */
+    }
 
     /* Here we add a new entry  */
-    if(isset($_POST['NewNTPAdd']))
-      {
-      $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
-      }
-    
-    /*Deleting an Entry, is a bit more complicated than adding one*/
-    if(isset($_POST['DelNTPEnt']))
-      {
-      /* Go through all entries an skip the selected (The one we want to delete)*/
-      foreach($this->attrs['goTimeSource'] as $key => $val)
-        {
-        /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
-        if($val != $_POST['goTimeSource'] )
-          {
-          /* Skip the entry that we want to delete*/
-          $new_arr[]=$val;
-          }
-        }
-      /* Deleting complete so add result to the attrs */
-      $this->attrs['goTimeSource']=$new_arr;
-      }
+    if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
+      $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
+      asort($this->goTimeSource);
+    }
 
-    /* Set the entry which we want to show in the frontend */
-    if(isset($this->attrs['goTimeSource']))
-      {
-      $this->goTimeSource = ($this->attrs['goTimeSource']);
-      unset($this->goTimeSource['count']);
+    /* Deleting an Entry, is a bit more complicated than adding one*/
+    if(isset($_POST['DelNTPEnt'])) {
+      foreach ($_POST['goTimeSource'] as $entry){
+        if (isset($this->goTimeSource[$entry])){
+          unset($this->goTimeSource[$entry]);
+        }
       }
+    }
 
-
-
-    /* Attributes... */
+    /* Attributes */
     foreach ($this->attributes as $attr){
       $smarty->assign("$attr", $this->$attr);
       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
       $smarty->assign($attr."State","");
     }
 
+    /* Arrays */
+    foreach (array("goTimeSource", "goExportEntry") as $name){
+      $smarty->assign("$name", $this->$name);
+      $smarty->assign("$name"."ACL", chkacl($this->acl, $name));
+      $smarty->assign($name."State","");
+    }
 
     /* Classes... */
-foreach ($this->additionaloc as $oc => $dummy){
+    foreach ($this->additionaloc as $oc => $dummy){
       if (isset($this->objectclasses[$oc])){
         $smarty->assign("$oc", "checked");
         $smarty->assign("$oc"."State", "");
@@ -157,13 +120,17 @@ foreach ($this->additionaloc as $oc => $dummy){
       }
     }
 
+    /* Different handling for checkbox */
+    if($this->goXdmcpIsEnabled == "true"){
+      $smarty->assign("goXdmcpIsEnabled","checked");
+    } else {
+      $smarty->assign("goXdmcpIsEnabled","");
+    }
 
-  if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
-    $smarty->assign("goXdmcpIsEnabled","checked");
-
-  return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
+    return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
   }
 
+
   function remove_from_parent()
   {
     /* This cannot be removed... */
@@ -178,14 +145,23 @@ foreach ($this->additionaloc as $oc => $dummy){
 
       /* Save checkbox state */
       foreach ($this->additionaloc as $oc => $dummy){
-        if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
-          $this->objectclasses[$oc]= $oc;
-        } else {
-          unset($this->objectclasses[$oc]);
+        if (chkacl($this->acl, $oc) == ""){
+          if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
+            $this->objectclasses[$oc]= $oc;
+          } else {
+            unset($this->objectclasses[$oc]);
+          }
         }
       }
+
+      /* Save xdmcp is enabled flag */
+      if (isset($_POST['goXdmcpIsEnabled'])){
+        $this->goXdmcpIsEnabled= "true";
+      } else {
+        $this->goXdmcpIsEnabled= "false";
+      }
+        
     }
   }
 
 
@@ -201,62 +177,34 @@ foreach ($this->additionaloc as $oc => $dummy){
   /* Save to LDAP */
   function save()
   {
-   
+
     /* Normalize lazy objectclass arrays */
     $objectclasses= array();
     foreach($this->objectclasses as $oc){
       $objectclasses[]= $oc;
     }
-    plugin::save();
-    $test = $this->objectclasses;
-    $tmp = array_flip($this->attrs['objectClass']);
-   
-    
-    foreach($this->additionaloc as $key=>$val) {
-      unset($tmp[$key]);
-      }
-   
+    $this->objectclasses= $objectclasses;
 
-    $classes = (array_flip(array_merge(array_flip($test),$tmp)));
+    plugin::save();
 
-    unset($this->attrs['objectClass']);
+    /* Normalize objectclasses */
+    $this->attrs['objectClass']= $this->objectclasses;
 
-    foreach($classes as $class){
-      $this->attrs['objectClass'][]=$class;
-    }
-      
-
-    /* Remove unneeded attributes */
+    /* Remove illegal attributes */
     foreach ($this->additionaloc as $oc => $attrs){
-      if (!in_array($oc, $this->attrs['objectClass'])){
+      if (!in_array($oc, $this->objectclasses)){
         foreach ($attrs as $attr){
           $this->attrs[$attr]= array();
         }
       }
     }
-    $this->attrs = array_reverse($this->attrs);
-
-    /* Check if we are able to set these attributes */
-#fixme : It Would be better to check ObjectClass rights to, but what is to do if there are insuficient rights 
-    foreach($this->additionaloc as $oc => $attrs)
-    {
-      foreach($attrs as $val)
-      {
-      if(chkacl($this->acl,$val)=="")
-        {
-        unset($this->attrs[$val]);
-        unset($this->$val);
-        }
-      }
-    }
-    
+
     /* Write to LDAP */
     $ldap= $this->config->get_ldap_link();
     $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){
index cf6063ce7a939de68f2d93947ea9e2ead5ad76b7..40d437c0dc80f7c708a0d39c4610dd1dd675203b 100644 (file)
@@ -12,7 +12,7 @@
    <table>
     <tr>
      <td>
-               <select style="width:350px;" id="goExportEntry" name="goExportEntry" {$goExportEntryACL} {$goNfsServerState} size=4 multiple >
+               <select style="width:350px;" id="goExportEntry" name="goExportEntry[]" {$goExportEntryACL} {$goNfsServerState} size=4 multiple >
                {html_options values=$goExportEntry output=$goExportEntry}
                        <option disabled></option>
            </select>
@@ -38,7 +38,7 @@
    <table>
     <tr>
      <td>
-        <select style="width:350px;" id="goTimeEntry" name="goTimeSource" {$goNtpServerState} {$goTimeSourceACL}  size=4 multiple>
+        <select style="width:350px;" id="goTimeEntry" name="goTimeSource[]" {$goNtpServerState} {$goTimeSourceACL}  size=4 multiple>
             {html_options values=$goTimeSource output=$goTimeSource}
                        <option disabled></option>
         </select>
@@ -74,7 +74,7 @@
   <table>
        <tr>
         <td colspan=2>
-         <input type="checkbox"  value="1" name="goXdmcpIsEnabled" {$goTerminalServerState} {$goXdmcpIsEnabledACL} id="Temporariid"> {t}Temporary disable login{/t}</td>
+         <input type="checkbox" value="true" name="goXdmcpIsEnabled" {$goTerminalServerState} {$goXdmcpIsEnabledACL} id="Temporariid" {$goXdmcpIsEnabled}> {t}Temporary disable login{/t}</td>
     </tr>
     <tr>
         <td>{t}Font path{/t}</td>