Code

Fixed Already exists errormsg, for fai objects
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 5 Oct 2005 05:03:39 +0000 (05:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 5 Oct 2005 05:03:39 +0000 (05:03 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1471 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_faiHook.inc
plugins/admin/fai/class_faiHookEntry.inc
plugins/admin/fai/class_faiPartitionTable.inc
plugins/admin/fai/class_faiScript.inc
plugins/admin/fai/class_faiScriptEntry.inc
plugins/admin/fai/class_faiTemplate.inc
plugins/admin/fai/class_faiVariable.inc
plugins/admin/fai/faiHookEntry.tpl

index 6d8e21a346a28a552221eb8caf79e1cd5bff7ccd..83551a24ad6e2fde95211b4ba1b000eec043cfda 100644 (file)
@@ -270,6 +270,13 @@ class faiHook extends plugin
       $tmp['objectClass'] = $this->subClasses;
 
       $sub_dn = "cn=".$obj['cn'].",".$this->dn;
+
+      if($obj['status']=="new"){
+        $ldap->cat($sub_dn);
+        if($ldap->count()){
+          $obj['status']="modify";
+        }
+      }
  
       if($obj['status'] == "delete"){
         $ldap->cd($sub_dn);
index 3621552b0f9648d3eb09ec710e4f89f6197cf6e9..5dd08ab682531b8668f298f82871cbdfc38ad789 100644 (file)
@@ -35,6 +35,34 @@ class faiHookEntry extends plugin
       $this->Object_status = "new";
       $this->orig_cn       = false;
     }
+
+    if(isset($this->Object_FAIscript)){
+      $ds= ldap_connect($this->config->current['SERVER']);
+      ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
+      if(function_exists("ldap_set_rebind_proc") && isset($this->config->current['RECURSIVE']) && $this->config->current['RECURSIVE'] == "true") {
+        ldap_set_option($this->cid, LDAP_OPT_REFERRALS, 1);
+        ldap_set_rebind_proc($ds, array(&$this, "rebind"));
+      }
+
+      if(isset($this->config->current['TLS']) && $this->config->current['TLS'] == "true"){
+        ldap_start_tls($ds);
+      }
+
+      $r = ldap_bind($ds);
+      $sr= @ldap_read($ds, $this->dn, "FAIscript=*", array("FAIscript"));
+      if ($sr) {
+        $ei=ldap_first_entry($ds, $sr);
+        if ($ei) {
+          if ($info = ldap_get_values_len($ds, $ei, "FAIscript")){
+            $this->Object_FAIscript = base64_decode($info[0]);
+          }
+        }
+      }
+
+      /* close conncetion */
+      ldap_unbind($ds);
+    }
+
   }
 
   function execute()
@@ -42,6 +70,18 @@ class faiHookEntry extends plugin
     /* Fill templating stuff */
     $smarty     = get_smarty();
     $display = "";
+        
+    if(isset($_POST['ImportUpload'])){
+      if(($_FILES['ImportFile']['error']!=0)){
+        print_red(_("Please select a valid file."));
+      }else
+      if(($_FILES['ImportFile']['size']==0)){
+        print_red(_("Selected file is empty."));
+      }else{
+        $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
+        $this->Object_FAIscript = $str;
+      }
+    }
 
     foreach($this->attributes as $attrs){
       $smarty->assign($attrs,stripslashes($this->$attrs));
index e00bacd6e133f24d90a3f74bc94067a4b1140c15..8cedb0f1604e56be1b08225d8a8bea023510bf0c 100644 (file)
@@ -313,6 +313,13 @@ class faiPartitionTable extends plugin
       $disk_attrs['cn']           =  $disk['cn'];
       $disk_attrs['description']  =  $disk['description']; 
       $disk_attrs['objectClass']  =  array("top","FAIclass","FAIpartitionDisk");
+
+      if($disk['status']=="new"){
+        $ldap->cat($disk_dn);
+        if($ldap->count()){
+          $disk['status']="edited";
+        }
+      }
  
       if($disk['status'] == "delete"){
         $ldap->cd($disk_dn);
@@ -355,7 +362,15 @@ class faiPartitionTable extends plugin
         
         unset($partition_attrs['status']);
         unset($partition_attrs['old_cn']);
-      
+
+        if($partition['status']=="new"){
+          $ldap->cat($partition_dn);
+          if($ldap->count()){
+            $partition['status']="edited";
+          }
+        }
+
+
         if(($partition['status'] == "delete")&&($disk['status']!="new")){
           $ldap->cd($partition_dn);
           $ldap->rmdir_recursive($partition_dn);
index e3ee13884290e442b9094a2fcdab36c4212efe2d..9b4b1781567cb230a5bd626723feb0ffa382abf4 100644 (file)
@@ -260,6 +260,13 @@ class faiScript extends plugin
       $tmp['objectClass'] = $this->subClasses;
 
       $sub_dn = "cn=".$obj['cn'].",".$this->dn;
+
+      if($obj['status']=="new"){
+        $ldap->cat($sub_dn);
+        if($ldap->count()){
+          $obj['status']="modify";
+        }
+      }
  
       if($obj['status'] == "delete"){
         $ldap->cd($sub_dn);
index ebaf792f41f74a5d3b5c7e6cc233e2f2d2781b1f..4d337ca4b3990adf3ac956de5590032cd571208b 100644 (file)
@@ -50,7 +50,7 @@ class faiScriptEntry extends plugin
       if(($_FILES['ImportFile']['size']==0)){
         print_red(_("Selected file is empty."));
       }else{
-        $str = file_get_contents($_FILES['ImportFile']['tmp_name']);
+        $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
         $this->Object_FAIscript = $str;
       }
     }
index 6792e36a265b76785cf6c2d3af4d05d2746070eb..b33788bd56a559db4cf8a22710b97fa706e30bb7 100644 (file)
@@ -159,7 +159,11 @@ class faiTemplate extends plugin
     $a_return=array();
     foreach($this->SubObjects as $obj){
       if($obj['status'] != "delete"){
-        $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]";
+        if((isset($obj['description']))&&(!empty($obj['description']))){
+          $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]";
+        }else{
+          $a_return[$obj['cn']]= $obj['cn'];
+        }
       }
     }
     return($a_return);
@@ -240,6 +244,7 @@ class faiTemplate extends plugin
     }
 
     foreach($Objects as $name => $obj){
+
       foreach($this->sub64coded as $codeIt){
         $obj[$codeIt]=base64_encode($obj[$codeIt]);
       }
@@ -255,6 +260,13 @@ class faiTemplate extends plugin
 
       $sub_dn = "cn=".$obj['cn'].",".$this->dn;
 
+      if($obj['status']=="new"){
+        $ldap->cat($sub_dn);
+        if($ldap->count()){
+          $obj['status']="modify";
+        }
+      }
+
       if($obj['status'] == "delete"){
         $ldap->cd($sub_dn);
         $ldap->rmdir_recursive($sub_dn);
index e90e7e9b285c50af39b682dbbe92735117e93141..ae7d76f634fb23c828cfb6c34ba878859c0a067f 100644 (file)
@@ -160,7 +160,7 @@ class faiVariable extends plugin
     foreach($this->SubObjects as $obj){
       if($obj['status'] != "delete"){
 
-        if((isset($obj['description']))&&(!empty($obj['description']))){
+        if((isset($obj['description']))&&(!empty($obj['description']))&&(!preg_match("/\[\*\]/",$obj['description']))){
           if (preg_match("/\[\*\]/", $obj['description'])){
             $a_return[$obj['cn']]= $obj['cn']." [".preg_replace("/\s*\[\*\]\s*/", "", $obj['description'])."]";
           } else {
@@ -269,6 +269,13 @@ class faiVariable extends plugin
       $tmp['objectClass'] = $this->subClasses;
 
       $sub_dn = "cn=".$obj['cn'].",".$this->dn;
+
+      if($obj['status']=="new"){
+        $ldap->cat($sub_dn);
+        if($ldap->count()){
+          $obj['status']="modify";
+        }
+      }
  
       if($obj['status'] == "delete"){
         $ldap->cd($sub_dn);
index d2a4f0ea00c3ef07c0077a4d883c6bf87b4c35b7..78fe9d3694c23716b68ab0e8e9f40174e6682030 100644 (file)
                <td>
                                <h2><img alt="" src="images/fai_hook.png" align="middle" title="{t}Hook attributes{/t}">&nbsp;{t}Hook attributes{/t}</h2>
                                <table width="100%">
-                                       <tr>
-                                               <td>
-                                                       <LABEL for="Object_FAIscript">
-                                                       {t}Script{/t}{$must}&nbsp;
-                                                       </LABEL>
-                                               </td>
-                                               <td>
-                                                       <input type="text" name="Object_FAIscript" value="{$Object_FAIscript}" id="Object_FAIscript" style="width:280px;">
-                                               </td>
-                                       </tr>
                                        <tr>
                                                <td>
                                                        <LABEL for="Object_FAItask">
                </td>
        </tr>
 </table>
+
+
+<p class="seperator">&nbsp;</p>
+<h2><img alt="" src="images/fai_hook.png" align="middle" title="{t}Hook attributes{/t}">&nbsp;
+    <LABEL for="Object_FAIscript">
+        {t}Script{/t}
+    </LABEL>
+    </h2>
+<table width="99%">
+    <tr>
+        <td>
+            <textarea name="Object_FAIscript" style="width:100%;height:300px;" id="Object_FAIscript">{$Object_FAIscript}</textarea>
+        </td>
+    </tr>
+</table>
+<br>
+<div>
+    <input type="file" name="ImportFile">&nbsp;
+    <input type="submit" name="ImportUpload" value="{t}Import script{/t}">
+</div>
+
 <p class="seperator">&nbsp;</p>
 <br>
 <div style="align:right;" align="right">