Code

Updated department handling.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Jun 2008 07:22:46 +0000 (07:22 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Jun 2008 07:22:46 +0000 (07:22 +0000)
-Centralized all department types, this makes it more easy to add/disable/enable new types

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11431 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/departments/class_departmentGeneric.inc
gosa-core/plugins/admin/departments/class_departmentManagement.inc
gosa-core/plugins/admin/departments/class_divListDepartment.inc

index 5026fd9ab74d08a23977fe976270c7cbd0221949..09509b9c6f70425a98fc3ffbdabadcea565748a5 100644 (file)
@@ -172,17 +172,20 @@ class department extends plugin
     }
 
     $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";
+    $dep_types = departmentManagement::get_support_departments();
+    $tpl ="";
+    foreach($dep_types as $key => $data){
+      if($data['ATTR'] == $this->type){
+        $tpl = $data['TPL'];
+        break;
+      }
+    }
+    if($tpl == "") {
+      trigger_error("No template specified for container type '".$this->type."', please update epartmentManagement::get_support_departments().");
+      $tpl = "generic.tpl";
     }
-
                return($smarty->fetch (get_template_path($tpl, TRUE)));
        }
 
index 2de4cf2b7f7ba8defda52ea728b515eef0b872af..0ef47749bc0fab56c5fef825a38bd0b86609e61b 100644 (file)
@@ -113,18 +113,18 @@ class departmentManagement extends plugin
     if ($s_action=="new"){
       $this->dn= "new";
 
-      $objects['c'] ['ACL'] = "country";
-      $objects['c'] ['TAB'] = "COUNTRY_TABS";
-      $objects['ou']['ACL'] = "department";
-      $objects['ou']['TAB'] = "DEPTABS";
-      $objects['l'] ['ACL'] = "locatity";
-      $objects['l'] ['TAB'] = "LOCALITY_TABS";
-      $objects['o'] ['ACL'] = "organization";
-      $objects['o'] ['TAB'] = "ORGANIZATION_TABS";
-
-      if(isset($objects[$s_entry])){
-        $tab = $objects[$s_entry]['TAB'];
-        $acl = $objects[$s_entry]['ACL'];
+      $types = $this->get_support_departments();
+      $type = "";
+      foreach($types as $key => $data){
+        if($data['ATTR'] == $s_entry){
+          $type = $key;
+          break;
+        }
+      }
+
+      if(isset($types[$type])){
+        $tab = $types[$type]['TAB'];
+        $acl = $types[$type]['ACL'];
         $this->deptabs= new deptabs($this->config,$this->config->data['TABS'][$tab], $this->dn,$acl);
         $this->deptabs->set_acl_base($this->DivListDepartment->selectedBase);
       }else{
@@ -142,15 +142,7 @@ class departmentManagement extends plugin
      */
     if (( $s_action=="edit") && (!isset($this->deptabs->config))){
 
-      /* Possible department types
-       */
-      $types['dcObject']           = array("ACL" => "",             "TAB" => "");
-      $types['country']            = array("ACL" => "country",      "TAB" => "COUNTRY_TABS");
-      $types['locality']           = array("ACL" => "locality",     "TAB" => "LOCALITY_TABS");
-      $types['organizationalUnit'] = array("ACL" => "department",   "TAB" => "DEPTABS");
-      $types['organization']       = array("ACL" => "organization", "TAB" => "ORGANIZATION_TABS");
-      $types['Alias??']            = array("ACL" => "alias"     ,   "TAB" => "");
-      $types['Referal??']          = array("ACL" => "referal",      "TAB" => "");
+      $types = $this->get_support_departments();
 
       $this->dn= $this->departments[trim($s_entry)]['dn'];
       $entry   = $this->departments[trim($s_entry)];
@@ -456,45 +448,21 @@ class departmentManagement extends plugin
     $config = session::get('config');
     $tmp = $config->idepartments;
 
-    /* Possible department types 
-     */ 
-    $types['dcObject']  = array("ACL" => "department",      "ATTR" => "dc",
-        "CLS" => "(objectClass=dcObject)",
-        "IMG"  => "plugins/departments/images/department.png");
-
-    $types['country']            = array("ACL" => "country",      "ATTR" => "c",
-        "CLS" => "(objectClass=country)",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "c");
-    $types['locality']           = array("ACL" => "locality",     "ATTR" => "l",
-        "CLS" => "(objectClass=locality)",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "l");
-    $types['organizationalUnit'] = array("ACL" => "department",   "ATTR" => "ou",
-        "CLS" => "(&(objectClass=gosaDepartment)(objectClass=organizationalUnit))",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "ou");
-    $types['organization']       = array("ACL" => "organization", "ATTR" => "o",
-        "CLS" => "(objectClass=organization)",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "o");
-    $types['Alias??']            = array("ACL" => "alias"     ,    "ATTR" => "alias?",
-        "CLS" => "(objectClass=alias??)",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "alias");
-    $types['Referal??']          = array("ACL" => "referal",       "ATTR" => "referal?",
-        "CLS" => "(objectClass=referal??)",
-        "IMG" => "plugins/departments/images/country.png", "ABBR" => "referal");
+    $types = $this->get_support_departments();
 
-
     /* Create search filter for each department type
      */
     $res = array();
     if($this->DivListDepartment->SubSearch){
       foreach($types as $oc => $data){
-        $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$data['CLS'].")",
+        $oc_f = "(&(objectClass=".$data['OC'].")(objectClass=gosaDepartment))";
+        $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$oc_f.")",
             "department", $base, array($data['ATTR'],"objectClass", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
       }
     }else{
       foreach($types as $oc => $data){
-        $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$data['CLS'].")",
+        $oc_f = "(&(objectClass=".$data['OC'].")(objectClass=gosaDepartment))";
+        $res= array_merge($res,get_list("(&(|(".$data['ATTR']."=$Regex)(description=$Regex))".$oc_f.")",
             "department", $base, array($data['ATTR'], "objectClass","description"), GL_SIZELIMIT ));
       }
     }
@@ -514,14 +482,13 @@ class departmentManagement extends plugin
        */
       $found =FALSE;
       foreach($types as $oc => $data){
-        if(in_array($oc,$attr['objectClass'])){
+        if(in_array($data['OC'],$attr['objectClass']) && isset($attr[$data['ATTR']][0])){
           $name = $attr[$data['ATTR']][0]."-".$attr['dn'];
           $deps[$name] = $attr;
           $found =TRUE;
           break;
         }
       }
-      if(!$found ) trigger_error("Not found!");
     }
     uksort($deps, 'strnatcasecmp');
 
@@ -603,6 +570,99 @@ class departmentManagement extends plugin
     $this->DivListDepartment->save_object();
   }
 
+
+  /*! \brief  Returns information about all container types that GOsa con handle.
+    @return Array   Informations about departments supported by GOsa.
+   */
+  public static function get_support_departments()
+  {
+    /* Domain component 
+     */
+    $types = array();
+    $types['dcObject']['ACL']     = "dcObject";
+    $types['dcObject']['CLASS']   = "dcObject";
+    $types['dcObject']['ATTR']    = "dc";
+    $types['dcObject']['TAB']     = "DCOBJECT_TABS";
+    $types['dcObject']['OC']      = "dcObject";
+    $types['dcObject']['IMG']     = "plugins/departments/images/dcObject.png";
+    $types['dcObject']['IMG_FULL']= "plugins/departments/images/dcObject.png";
+    $types['dcObject']['TITLE']   = _("Domain Component");
+    $types['dcObject']['TPL']     = "dcObject.tpl";
+
+    /* Country object
+     */
+    $types['country']['ACL']     = "country";
+    $types['country']['CLASS']   = "country";
+    $types['country']['TAB']     = "COUNTRY_TABS";
+    $types['country']['ATTR']    = "c";
+    $types['country']['OC']      = "country";
+    $types['country']['IMG']     = "plugins/departments/images/country.png";
+    $types['country']['IMG_FULL']= "plugins/departments/images/country.png";
+    $types['country']['TITLE']   = _("Country");
+    $types['country']['TPL']     = "country.tpl";
+
+    /* Locality object
+     */
+    $types['locality']['ACL']     = "locality";
+    $types['locality']['CLASS']   = "locality";
+    $types['locality']['TAB']     = "LOCALITY_TABS";
+    $types['locality']['ATTR']    = "l";
+    $types['locality']['OC']      = "locality";
+    $types['locality']['IMG']     = "plugins/departments/images/locality.png";
+    $types['locality']['IMG_FULL']= "plugins/departments/images/locality.png";
+    $types['locality']['TITLE']   = _("Locality");
+    $types['locality']['TPL']     = "locality.tpl";
+
+    /* Organization
+     */
+    $types['organization']['ACL']     = "organization";
+    $types['organization']['CLASS']   = "organization";
+    $types['organization']['TAB']     = "ORGANIZATION_TABS";
+    $types['organization']['ATTR']    = "o";
+    $types['organization']['OC']      = "organization";
+    $types['organization']['IMG']     = "plugins/departments/images/organization.png";
+    $types['organization']['IMG_FULL']= "plugins/departments/images/organization.png";
+    $types['organization']['TITLE']   = _("Organization");
+    $types['organization']['TPL']     = "organization.tpl";
+
+    /* Organization
+     */
+    $types['organizationalUnit']['ACL']     = "department";
+    $types['organizationalUnit']['CLASS']   = "department";
+    $types['organizationalUnit']['TAB']     = "DEPTABS";
+    $types['organizationalUnit']['ATTR']    = "ou";
+    $types['organizationalUnit']['OC']      = "organizationalUnit";
+    $types['organizationalUnit']['IMG']     = "plugins/departments/images/department.png";
+    $types['organizationalUnit']['IMG_FULL']= "plugins/departments/images/department.png";
+    $types['organizationalUnit']['TITLE']   = _("Department");
+    $types['organizationalUnit']['TPL']     = "generic.tpl";
+
+    /* Alias
+     */
+    $types['alias']['ACL']     = "alias";
+    $types['alias']['CLASS']   = "alias";
+    $types['alias']['TAB']     = "ALIASTABS";
+    $types['alias']['ATTR']    = "???";
+    $types['alias']['OC']      = "???";
+    $types['alias']['IMG']     = "plugins/departments/images/alias.png";
+    $types['alias']['IMG_FULL']= "plugins/departments/images/alias.png";
+    $types['alias']['TITLE']   = _("Alias");
+    $types['alias']['TPL']     = "alias.tpl";
+
+    /* Referal
+     */
+    $types['referal']['ACL']     = "referal";
+    $types['referal']['CLASS']   = "referal";
+    $types['referal']['TAB']     = "REFERALTABS";
+    $types['referal']['ATTR']    = "???";
+    $types['referal']['OC']      = "???";
+    $types['referal']['IMG']     = "plugins/departments/images/referal.png";
+    $types['referal']['IMG_FULL']= "plugins/departments/images/referal.png";
+    $types['referal']['TITLE']   = _("Referal");
+    $types['referal']['TPL']     = "referal.tpl";
+
+    return($types);
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 87011c32273473a1c0491eb4cdcc37f5f721f4ac..8a8a868a21fcdeb7f2d8ae6131c5e6ffbbc13629 100644 (file)
@@ -207,37 +207,7 @@ class divListDepartment extends MultiSelectWindow
   {
     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
 
-    /* Possible department types
-     */
-   $types['dcObject']  = array("ACL" => "department",      "ATTR" => "dc",
-       "TITLE"     => _("Domain Component"),
-       "IMG_FULL"  => "plugins/departments/images/department.png", 
-       "IMG"       => "plugins/departments/images/department.png", "ABBR" => "dc");
-
-    $types['country']            = array("ACL" => "country",      "ATTR" => "c",
-        "TITLE"     => _("Country"),
-        "IMG_FULL"  => "plugins/departments/images/country.png", 
-        "IMG"       => "plugins/departments/images/country.png", "ABBR" => "c");
-    $types['locality']           = array("ACL" => "locality",     "ATTR" => "l",
-        "TITLE"     => _("Locality"),
-        "IMG_FULL"  => "plugins/departments/images/locality.png", 
-        "IMG"       => "plugins/departments/images/locality.png", "ABBR" => "l");
-    $types['organizationalUnit'] = array("ACL" => "department",   "ATTR" => "ou",
-        "TITLE"     => _("Department"),
-        "IMG_FULL"  => "images/lists/folder-full.png", 
-        "IMG"       => "images/lists/folder.png", "ABBR" => "ou");
-    $types['organization']       = array("ACL" => "organization", "ATTR" => "o",
-        "TITLE"     => _("Organization"),
-        "IMG_FULL"  => "plugins/departments/images/organization.png", 
-        "IMG"       => "plugins/departments/images/organization.png", "ABBR" => "o");
-    $types['Alias??']            = array("ACL" => "alias"     ,    "ATTR" => "alias?",
-        "TITLE"     => _("Alias"),
-        "IMG_FULL"  => "plugins/departments/images/department_alias.png", 
-        "IMG"       => "plugins/departments/images/department_alias.png", "ABBR" => "alias");
-    $types['Referal??']          = array("ACL" => "referal",       "ATTR" => "referal?",
-        "TITLE"     => _("Referal"),
-        "IMG_FULL"  => "plugins/departments/images/department_referal.png", 
-        "IMG"       => "plugins/departments/images/department_referal.png", "ABBR" => "referal");
+    $types = $this->parent->get_support_departments();
 
     $this->departments = $list;