Code

list base image migration for gosa-plugins
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiTemplate.inc
index 9015ba8789f9e1f853ef3ff95c591cd0a0a77501..7ea9a836befe4cb641f8e529647b32c37aa6c773 100644 (file)
@@ -82,6 +82,10 @@ class faiTemplate extends plugin
         $this->SubObjects[$objects['cn']] = $objects;
       }
     }
+    $this->is_new = FALSE;
+    if($this->dn == "new"){
+      $this->is_new =TRUE;
+    }
     $this->ui = get_userinfo();
   }
 
@@ -102,13 +106,12 @@ 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)){
           $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
         }
-
-        $var = stripslashes($var);
   
         $object[$attrs] = $var;
       }
@@ -301,7 +304,7 @@ class faiTemplate extends plugin
       }else{
         $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
         if(preg_match("/d/",$acl)){
-          $act .="<input type='image' src='images/edittrash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+          $act .="<input type='image' src='images/lists/trash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
         }
       }
 
@@ -431,6 +434,21 @@ class faiTemplate extends plugin
     /* Call common method to give check the hook */
     $message= plugin::check();
 
+    /* Ensure that we do not overwrite an allready existing entry 
+     */
+    if($this->is_new){
+      $new_dn= 'cn='.$this->cn.",".get_ou('faitemplateou').get_ou('faiou').session::get('CurrentMainBase');
+      $faifilter = session::get('faifilter');
+      if($faifilter['branch']!="main"){
+        $new_dn ='cn='.$this->cn.",".get_ou('faitemplateou').$faifilter['branch'];
+      }
+
+      $res = faiManagement::check_class_name("FAItemplate",$this->cn,$new_dn);
+      if(isset($res[$this->cn])){
+        $message[] = msgPool::duplicated(_("Name"));
+      }
+    }
+
     return ($message);
   }
 
@@ -443,9 +461,6 @@ class faiTemplate extends plugin
     $ldap = $this->config->get_ldap_link();
 
     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
-    if (!$ldap->success()){
-      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
-    }
 
     if($this->initially_was_account){
       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
@@ -569,6 +584,34 @@ class faiTemplate extends plugin
             "description"       => _("Description"))
           ));
   }
+
+
+  /*! \brief  Used for copy & paste.
+    Returns a HTML input mask, which allows to change the cn of this entry.
+    @param  Array   Array containing current status && a HTML template.
+   */
+  function getCopyDialog()
+  {
+    $vars = array("cn");
+    $smarty = get_smarty();
+    $smarty->assign("cn", htmlentities($this->cn));
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+
+  /*! \brief  Used for copy & paste.
+    Some entries must be renamed to avaoid duplicate entries.
+   */
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = get_post('cn');
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: