Code

Fixed removal of template and profile entries.
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiTemplate.inc
index 3821653247ec78f57fff78d5dbcd452b3a8a6f27..47313ac420467f4357e809df160d771ce8f86a6e 100644 (file)
@@ -66,6 +66,17 @@ class faiTemplate extends plugin
       $this->is_new =TRUE;
     }
     $this->ui = get_userinfo();
+
+    // Prepare lists
+    $this->templateList = new sortableListing();
+    $this->templateList->setInstantDelete(false);
+    $this->templateList->setDeleteable(true);
+    $this->templateList->setEditable(true);
+    $this->templateList->setWidth("100%");
+    $this->templateList->setHeight("220px");
+    $this->templateList->setColspecs(array('*','18px'));
+    $this->templateList->setHeader(array(_("Name"),""));
+    $this->templateList->setDefaultSortColumn(0);
   }
 
 
@@ -85,7 +96,6 @@ class faiTemplate extends plugin
         if(in_array_ics($attrs,$this->sub64coded)){
           $var = base64_decode($var);
         }
-        $var = stripslashes($var);
 
         /*  check if this is a binary entry */
         if(in_array_ics($attrs,$this->subBinary)){
@@ -115,48 +125,44 @@ class faiTemplate extends plugin
 
     /* New Listhandling
      */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if(preg_match("/^editscript_/",$name)&&($once)){
-        $once = false;
-        $entry = preg_replace("/^editscript_/","",$name);
-        $entry = postDecode(preg_replace("/^editscript_/","",$name));
-        $obj  = $this->SubObjects[$entry];
-
+    $this->templateList->save_object();
+    $action = $this->templateList->getAction();
+    if($action['action'] == 'delete'){
+        $id = $this->templateList->getKey($action['targets'][0]);
+        $obj  = $this->SubObjects[$id];
         $acl_dn = $this->acl_base_for_current_object($obj['dn']);
         $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry");
-        if(preg_match("/r/",$acl)){
-          if($obj['status'] == "FreshLoaded"){
-            $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
-          }
-          $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
-          $this->dialog->set_acl_base($this->acl_base);
-          $this->dialog->FAIstate = $this->FAIstate;
-          $this->dialog->set_acl_category("fai");
-
-          set_object_info($obj['dn']);
-          $this->dialog->parent = &$this;
-          $this->is_dialog=true;
+        if(preg_match("/d/",$acl)){
+            $status = $this->SubObjects[$id]['status'];
+            if($status == "edited" || $status == "FreshLoaded"){
+                $this->SubObjects[$id]['status']= "delete";
+            }else{
+                unset($this->SubObjects[$id]);
+            }
         }
-      }
-      if(preg_match("/^deletescript_/",$name)&&($once) && !preg_match("/freeze/",$this->FAIstate)){
-        $once = false;
-        $entry = preg_replace("/^deletescript_/","",$name);
-        $entry = postDecode(preg_replace("/^deletescript_/","",$name));
-        $obj  = $this->SubObjects[$entry];
-
+    }
+    if($action['action'] == 'edit'){
+        $id = $this->templateList->getKey($action['targets'][0]);
+        $obj  = $this->SubObjects[$id];
         $acl_dn = $this->acl_base_for_current_object($obj['dn']);
         $acl = $this->ui->get_permissions($acl_dn,"fai/faiTemplateEntry");
-        if(preg_match("/d/",$acl)){
-          $status = $this->SubObjects[$entry]['status'];
-          if($status == "edited" || $status == "FreshLoaded"){
-            $this->SubObjects[$entry]['status']= "delete";
-          }else{
-            unset($this->SubObjects[$entry]);
-          }
+        if(preg_match("/r/",$acl)){
+            if($obj['status'] == "FreshLoaded"){
+                $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
+            }
+            $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
+            $this->dialog->set_acl_base($this->acl_base);
+            $this->dialog->FAIstate = $this->FAIstate;
+            $this->dialog->set_acl_category("fai");
+
+            set_object_info($obj['dn']);
+            $this->dialog->parent = &$this;
+            $this->is_dialog=true;
         }
-      }
+    }
 
+    $once = true;
+    foreach($_POST as $name => $value){
       if(preg_match("/^download_/",$name)&&($once) && !preg_match("/freeze/",$this->FAIstate)){
         $once = false;
         $entry = postDecode(preg_replace("/^download_/","",$name));
@@ -267,65 +273,43 @@ class faiTemplate extends plugin
       return($display);
     }
 
-     /* Divlist Containing FAItemplates */
-    $divlist = new divSelectBox("FAItemplates");
-    $divlist->setHeight(400);
+     /* list Containing FAItemplates */
+    $dn  = $this->acl_base_for_current_object($this->dn);
+    $acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry")  ;
+    $this->templateList->setAcl($acl,preg_match('/^freeze/', $this->FAIstate));
 
     $tmp = $this->getList(true);
-  
-    /* Create div list with all sub entries listed */
+    $data = $lData = array();
     foreach($this->SubObjects as $key => $name){
 
       /* Skip removed entries */ 
       if($name['status'] == "delete") continue;
 
-      /* Get permissions */
-      $dn  = $this->acl_base_for_current_object($name['dn']);
-      $acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry")  ;
       $act = "";
 
-      /* Hide delete icon if this object is freezed */
-      if(preg_match("/freeze/",$this->FAIstate)){
-        $act .= image('images/lists/edit.png','editscript_%s', msgPool::editButton());
-      }else{
-        $act .= image('images/lists/edit.png','editscript_%s', msgPool::editButton());
-        if(preg_match("/d/",$acl)){
-          $act .= image('images/lists/trash.png','deletescript_%s', msgPool::delButton());
-        }
-      }
-
       /* Check acls for download icon */
+      $dn  = $this->acl_base_for_current_object($name['dn']);
       $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","FAItemplateFile")  ;
-      if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
+      if(($this->SubObjects[$key]['status'] == "new") || 
+              ($this->SubObjects[$key]['dn'] == "new") || 
+              !preg_match("/r/",$s_acl)){
         $down = "";
       }else{
         $down = image('images/save.png','download_'.postEncode($key), _("Download"));
       }
-
-      /* Check if we are allowed to view this object */
-      $s_acl = $this->ui->get_permissions($dn,"fai/faiTemplateEntry","cn")  ;
-      if(preg_match("/r/",$s_acl)){
-
-        $edit_link = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$key."'>".$tmp[$key]."</a>";
-        $divlist->AddEntry(array( array("string"=> $edit_link), 
-              array("string"=>$down , "attach" => "style='width:20px;'"),
-              array("string"=>str_replace("%s",postEncode($key),$act),
-                "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
-      }
+      $data[$key] = $key;
+      $lData[$key] = array('data' => array($name['cn'], $down));
     }
-    $smarty->assign("Entry_divlist",$divlist->DrawList());
-    /* Divlist creation complete
-     */
+
+    $this->templateList->setListData($data,$lData);
+    $this->templateList->update();
+    $smarty->assign("Entry_listing",$this->templateList->render());
 
      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
      * If we post the escaped strings they will be escaped again
      */
     foreach($this->attributes as $attrs){
-      if(get_magic_quotes_gpc()){
-        $smarty->assign($attrs,stripslashes($this->$attrs));
-      }else{
-        $smarty->assign($attrs,($this->$attrs));
-      }
+      $smarty->assign($attrs,set_post($this->$attrs));
     }
 
     $dn = $this->acl_base_for_current_object($this->dn);
@@ -416,7 +400,7 @@ class faiTemplate extends plugin
      */
     if($this->is_new){
       $release = $this->parent->parent->fai_release;
-      $new_dn= 'cn='.$this->cn.",".get_ou('faiTemplateRDN').get_ou('faiBaseRDN').$release;
+      $new_dn= 'cn='.$this->cn.",".get_ou("faiTemplate", "faiTemplateRDN").get_ou("faiManagement", "faiBaseRDN").$release;
       $res = faiManagement::check_class_name("FAItemplate",$this->cn,$new_dn);
       if(isset($res[$this->cn])){
         $message[] = msgPool::duplicated(_("Name"));
@@ -541,8 +525,20 @@ class faiTemplate extends plugin
           "plPriority"    => 24,
           "plSection"     => array("administration"),
           "plCategory"    => array("fai"),
+          "plProperties" =>
+          array(
+              array(
+                  "name"          => "faiTemplateRDN",
+                  "type"          => "rdn",
+                  "default"       => "ou=templates,",
+                  "description"   => _("RDN for FAI template storage."),
+                  "check"         => "gosaProperty::isRdn",
+                  "migrate"       => "migrate_faiTemplateRDN",
+                  "group"         => "plugin",
+                  "mandatory"     => TRUE)),
+
           "plProvidedAcls" => array(
-            "cn"                => _("Name")." ("._("Readonly").")",
+              "cn"                => _("Name")." ("._("Read-only").")",
             "description"       => _("Description"))
           ));
   }
@@ -556,7 +552,7 @@ class faiTemplate extends plugin
   {
     $vars = array("cn");
     $smarty = get_smarty();
-    $smarty->assign("cn", htmlentities($this->cn));
+    $smarty->assign("cn", set_post($this->cn));
     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
     $ret = array();
     $ret['string'] = $str;