Code

Added Department templates.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index beda40082a374b1db3b707d3209e355c466fdd80..c8da2b281e438896435e5b869a3bd41f165ff4bc 100644 (file)
@@ -32,11 +32,13 @@ class department extends plugin
        var $businessCategory= "";
        var $telephoneNumber= "";
        var $facsimileTelephoneNumber= "";
-       var $orig_dn= "";
        var $is_administrational_unit= false;
        var $gosaUnitTag= "";
   var $view_logged = FALSE;
 
+  var $type ="ou";
+  var $namingAttr = "ou";
+
        /* Headpage attributes */
        var $last_dep_sorting= "invalid";
        var $departments= array();
@@ -59,7 +61,13 @@ class department extends plugin
                $this->ui= get_userinfo();
                $this->dn= $dn;
                $this->orig_dn= $dn;
-               $this->orig_ou= $this->ou;
+
+    /* Save current naming attribuet 
+     */
+    $nA      = $this->namingAttr;
+    $orig_nA = "orig_".$nA;
+    $this->$orig_nA = $this->$nA;
+
                $this->config= $config;
 
                /* Set base */
@@ -163,7 +171,19 @@ class department extends plugin
       $smarty->assign("unitTag", "");
     }
 
-               return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
+    $smarty->assign("dep_type",$this->type);
+
+    switch($this->type){
+      case 'c'        : $tpl ="country.tpl";break;
+      case 'o'        : $tpl ="organization.tpl";break;
+      case 'l'        : $tpl ="locality.tpl";break;
+      case 'ou'       : $tpl ="generic.tpl";break;
+      case 'alias'    : $tpl ="alias.tpl";break;
+      case 'referal'  : $tpl ="referal.tpl";break;
+      default  : $tpl ="generic.tpl";
+    }
+
+               return($smarty->fetch (get_template_path($tpl, TRUE)));
        }
 
        function clear_fields()
@@ -264,7 +284,15 @@ class department extends plugin
                        $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
                }
 
-               return $message;
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
+    return $message;
        }
 
 
@@ -653,7 +681,47 @@ class department extends plugin
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
       }
     }
+  }
+
+
+  
+  /*! \brief    Returns a list of all available departments for this object.
+                If this object is new, all departments we are allowed to create a new user in are returned.
+                If this is an existing object, return all deps. we are allowed to move tis object too.
+
+      @return   Array [dn] => "..name"  // All deps. we are allowed to act on.
+  */
+  function get_allowed_bases()
+  {
+    $ui = get_userinfo();
+    $deps = array();
+
+    /* Is this a new object ? Or just an edited existing object */
+    if(!$this->initially_was_account && $this->is_account){
+      $new = true;
+    }else{
+      $new = false;
+    }
+
+    $ideps = $this->config->idepartments;
+    if(!isset($ideps[$this->base])){
+      $ideps[$this->base] = ".";
+    }
+    foreach($deps as $dn => $name){
+      if($new && $this->acl_is_createable($dn)){
+        $deps[$dn] = $name;
+      }elseif(!$new && $this->acl_is_moveable($dn)){
+        $deps[$dn] = $name;
+      }
+    }
 
+    /* Add current base */
+    if(isset($this->base) && isset($ideps[$this->base])){
+      $deps[$this->base] = $ideps[$this->base];
+    }else{
+      trigger_error("Cannot return list of departments, no default base found in class ".get_class($this).". ".$this->base);
+    }
+    return($deps);
   }
 
 }