Code

Made faiScript w3c conform
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiScript.inc
index fe28af277f9940572a0ab65e8f1a0687cddb5a26..17cd0734488bedbef6dd95be8b76c0051bbcdc44 100644 (file)
@@ -55,7 +55,7 @@ class faiScript extends plugin
       foreach($res as $obj){
 
         /* Skip not relevant objects */
-        if(!preg_match("/".normalizePreg($this->dn)."$/i",$obj['dn'])) continue;
+        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
 
         $objects = array();
         $objects['status']      = "FreshLoaded";
@@ -88,7 +88,7 @@ class faiScript extends plugin
 
         /* Check if we must decode some attributes */
         if(in_array_ics($attrs,$this->sub64coded)){
-          $var = base64_decode($var);
+          $var = postDecode($var);
         }
 
         /*  check if this is a binary entry */
@@ -108,9 +108,9 @@ class faiScript extends plugin
   /* Return a valid dn to fetch acls. Because 'new' will not work. */
   function acl_base_for_current_object($dn)
   {
-    if($dn == "new"){
+    if($dn == "new" || $dn == ""){
       if($this->dn == "new"){
-        $dn= "cn=dummy,".session::get('CurrentMainBase');
+        $dn= $this->parent->parent->acl_base;
       }else{
         $dn = $this->dn;
       }
@@ -144,27 +144,26 @@ class faiScript extends plugin
     }
 
     if($this->dn != "new"){
-      session::set('objectinfo',$this->dn);
+      set_object_info($this->dn);
     }
 
-    /* File download requested */
-    if(isset($_GET['getFAIscript'])){
-      if(isset($this->SubObjects[base64_decode($_GET['getFAIscript'])])){
-        $obj = $this->SubObjects[base64_decode($_GET['getFAIscript'])];
-        $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
-        send_binary_content(stripslashes($obj['FAIscript']),$obj['cn'].".FAIscript"); 
-      }
-    }
-    
     /* Handle posts */
     $s_action = $s_entry = "";
     foreach($_POST as $name => $value){
 
+      if(preg_match("/^download_/",$name)){
+        $s_entry = postDecode(preg_replace("/^download_/","",$name));
+        $obj = $this->SubObjects[$s_entry];
+        $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
+        send_binary_content(stripslashes($obj['FAIscript']),$obj['cn'].".FAIscript"); 
+        break;
+      }
+
       /* Edit script posted */
       if(preg_match("/^editscript_/",$name)){
         $s_action = "edit";
         $s_entry = preg_replace("/^editscript_/","",$name);
-        $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+        $s_entry = postDecode(preg_replace("/_.*/","",$s_entry));
         break;
       }
 
@@ -172,13 +171,13 @@ class faiScript extends plugin
       if(preg_match("/^deletescript_/",$name) && !preg_match("/freeze/i",$this->FAIstate)){
         $s_action = "remove";
         $s_entry = preg_replace("/^deletescript_/","",$name);
-        $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
+        $s_entry = postDecode(preg_replace("/_.*/","",$s_entry));
         break;
       }
     }
 
     if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
-      $s_entry = base64_decode($_GET['id']);
+      $s_entry = postDecode($_GET['id']);
       if(isset($this->SubObjects[$s_entry])){
         $s_action = "edit";
       }
@@ -199,7 +198,7 @@ class faiScript extends plugin
       $this->dialog->set_acl_category("fai");
 
       /* Assign some additional dialog informations like headline and parent  */
-      session::set('objectinfo',$obj['dn']);
+      set_object_info($obj['dn']);
       $this->dialog->parent = &$this;
       $this->is_dialog=true;
     }
@@ -311,9 +310,9 @@ class faiScript extends plugin
     $plug = $_GET['plug'];
    
     if($this->sort_order == "up"){
-      $dir = "<img src='images/lists/sort-up.png' title='"._("Sort direction")."' alt='\/' border=0>";
+      $dir = image('images/lists/sort-up.png');
     }else{
-      $dir = "<img src='images/lists/sort-down.png' title='"._("Sort direction")."' alt='/\' border=0>";
+      $dir = image('images/lists/sort-down.png');
     }
  
     if($this->sort_by == "name"){
@@ -324,7 +323,7 @@ class faiScript extends plugin
       $sort_prio = $dir;
     }
 
-    $divlist->SetHeader(array(  array("string"=>"<a href='?plug=".$plug."&amp;sort=name'>"._("Name").$sort_name."</a>"),
+    $divlist->SetHeader(array(  array("string"=>"<a href='?plug=".$plug."&amp;sort=name'>"._("Name")."</a>".$sort_name),
                                 array("string"=>"<a href='?plug=".$plug."&amp;sort=priority'>".$sort_prio._("Priority")."</a>",
                                       "attach"=>"style='width:100px;'"),
                                 array("string"=>_("Download"),
@@ -341,11 +340,11 @@ class faiScript extends plugin
       
       /* Hide delete icon if this object is freezed */
       if(preg_match("/freeze/", $this->FAIstate)){
-        $act .= "<input type='image' src='images/lists/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        $act .= image('images/lists/edit.png', 'editscript_%s',msgPool::editButton());
       }else{
-        $act .= "<input type='image' src='images/lists/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        $act .= image('images/lists/edit.png', 'editscript_%s',msgPool::editButton());
         if(preg_match("/d/",$acl)){
-          $act .="<input type='image' src='images/lists/trash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+          $act .= image('images/lists/trash.png', 'deletescript_%s',msgPool::delButton());
         }
       }
 
@@ -354,18 +353,16 @@ class faiScript extends plugin
       if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
         $down = "";
       }else{
-        $down = "<a href='?plug=".$_GET['plug']."&getFAIscript=".base64_encode($key)."'>
-          <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0>
-          </a>"; 
+        $down = image('images/save.png', 'download_'.postEncode($key));
       } 
 
       /* Check if we are allowed to view this object */
       $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn")  ;
       if(preg_match("/r/",$s_acl)){
-        $divlist->AddEntry(array( array("string"=>"<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".base64_encode($key)."'>".$name['name']."</a>"),
+        $divlist->AddEntry(array( array("string"=>"<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".postEncode($key)."'>".$name['name']."</a>"),
               array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"),
               array("string"=>$down , "attach" => "style='width:100px;'"),
-              array("string"=>str_replace("%s",base64_encode($key),$act),
+              array("string"=>str_replace("%s",postEncode($key),$act),
                 "attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
       }
     }
@@ -432,12 +429,12 @@ class faiScript extends plugin
       $ldap = $this->config->get_ldap_link();
       $ldap->cd ($this->dn);
       $release = $this->parent->parent->fai_release;
-      $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $this->dn);
+      $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
       new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
       FAI::prepare_to_save_FAI_object($use_dn,array(),true);
  
       foreach($this->SubObjects as $name => $obj){
-        $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $obj['dn']);
+        $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $obj['dn']);
         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
       }
       $this->handle_post_events("remove");
@@ -451,11 +448,6 @@ class faiScript extends plugin
   {
     if((isset($_POST['FAIscript_posted'])) && !preg_match("/freeze/", $this->FAIstate)){
       plugin::save_object();
-      foreach($this->attributes as $attrs){
-        if(isset($_POST[$attrs])){
-          $this->$attrs = $_POST[$attrs];
-        }
-      }
     }
     
     /* Get sort order */
@@ -482,7 +474,7 @@ class faiScript extends plugin
      */
     if($this->is_new){
       $release = $this->parent->parent->fai_release;
-      $new_dn= 'cn='.$this->cn.",".get_ou('faiscriptou').get_ou('faiou').$release;
+      $new_dn= 'cn='.$this->cn.",".get_ou('faiScriptRDN').get_ou('faiBaseRDN').$release;
       $res = faiManagement::check_class_name("FAIscript",$this->cn,$new_dn);
       if(isset($res[$this->cn])){
         $message[] = msgPool::duplicated(_("Name"));
@@ -536,13 +528,13 @@ class faiScript extends plugin
     foreach($Objects as $name => $obj){
 
       foreach($this->sub64coded as $codeIt){
-        $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt]));
+        $obj[$codeIt]=postEncode(stripslashes($obj[$codeIt]));
       }
 
       $tmp = array();
       $attributes = array_merge($this->sub_Load_Later,$this->subAttributes);
       foreach($attributes as $attrs){
-
+        if(!isset($obj[$attrs])) continue; 
         if($obj[$attrs] == ""){
           $obj[$attrs] = array();
         }
@@ -595,7 +587,7 @@ class faiScript extends plugin
     foreach($res as $obj){
 
       /* Skip not relevant objects */
-      if(!preg_match("/".normalizePreg($source['dn'])."$/i",$obj['dn'])) continue;
+      if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
 
       $objects = array();
       $objects['status']      = "edited";