Code

Fixed typo
[gosa.git] / gosa-core / include / functions.inc
index 5caf26ea7018b6192af03cdecb4ed4e02c0adbb0..08626e248e47382e578ea438ae417740b2aceaf2 100644 (file)
@@ -22,9 +22,8 @@
 
 /* Configuration file location */
 define ("CONFIG_DIR", "/etc/gosa");
-define ("CONFIG_FILE", "gosa.conf-trunk");
+define ("CONFIG_FILE", "gosa.conf");
 define ("CONFIG_TEMPLATE_DIR", "../contrib/");
-define ("HELP_BASEDIR", "/var/www/doc/");
 
 /* Define get_list flags */
 define("GL_NONE",         0);
@@ -1094,6 +1093,10 @@ function convert_department_dn($dn)
 
   /* Build a sub-directory style list of the tree level
      specified in $dn */
+  global $config;
+  $dn = preg_replace("/".normalizePreg($config->current['BASE'])."$/i","",$dn);
+  if(empty($dn)) return("/");
+
   foreach (split(',', $dn) as $rdn){
 
     /* We're only interested in organizational units... */
@@ -1166,10 +1169,17 @@ function get_ou($name)
  
   if ($ou != ""){
     if (!preg_match('/^[^=]+=[^=]+/', $ou)){
-      return @LDAP::convert("ou=$ou,");
+      $ou = @LDAP::convert("ou=$ou");
     } else {
-      return @LDAP::convert("$ou,");
+      $ou = @LDAP::convert("$ou");
     }
+
+    if(preg_match("/".normalizePreg($config->current['BASE'])."$/",$ou)){
+      return($ou);
+    }else{
+      return("$ou,");
+    }
+  
   } else {
     return "";
   }
@@ -1284,7 +1294,7 @@ function gen_locked_message($user, $dn)
   } else {
     $smarty->assign ("action", _("Edit anyway"));
   }
-  $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries '%s'"), "<b>".$msg."</b>", ""));
+  $smarty->assign ("message", sprintf(_("You're going to edit the LDAP entry/entries %s"), "<b>".$msg."</b>", ""));
 
   return ($smarty->fetch (get_template_path('islocked.tpl')));
 }
@@ -2664,10 +2674,53 @@ function send_binary_content($data,$name,$type = "application/octet-stream")
            HTML output, without breaking quotes.
     @param  The String we want to encode.
     @return The encoded String
-*/
+ */
 function xmlentities($str)
+{ 
+  if(is_string($str)){
+    return(htmlentities($str,ENT_QUOTES));
+  }elseif(is_array($str)){
+    foreach($str as $name => $value){
+      $str[$name] = xmlentities($value);
+    }
+  }
+  return($str);
+}
+
+
+/*! \brief  Updates all accessTo attributes from a given value to a new one.
+            For example if a host is renamed.
+    @param  String  $from The source accessTo name.
+    @param  String  $to   The destination accessTo name.
+*/
+function update_accessTo($from,$to)
 {
-  return (htmlentities($str,ENT_QUOTES));
+  global $config;
+  $ldap = $config->get_ldap_link();
+  $ldap->cd($config->current['BASE']);
+  $ldap->search("(&(objectClass=trustAccount)(accessTo=".$from."))",array("objectClass","accessTo"));
+  while($attrs = $ldap->fetch()){
+    $new_attrs = array("accessTo" => array());
+    $dn = $attrs['dn'];
+    for($i = 0 ; $i < $attrs['objectClass']['count']; $i++){
+      $new_attrs['objectClass'][] =  $attrs['objectClass'][$i];
+    }
+    for($i = 0 ; $i < $attrs['accessTo']['count']; $i++){
+      if($attrs['accessTo'][$i] == $from){
+        if(!empty($to)){
+          $new_attrs['accessTo'][] =  $to;
+        }
+      }else{
+        $new_attrs['accessTo'][] =  $attrs['accessTo'][$i]; 
+      }
+    }
+    $ldap->cd($dn);
+    $ldap->modify($new_attrs);
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, "update_accessTo($from,$to)"));
+    }
+    new log("modify","update_accessTo($from,$to)",$dn,array_keys($new_attrs),$ldap->get_error());
+  }
 }