Code

Added exporter
[gosa.git] / gosa-core / include / functions.inc
index ae3ccfc8e0b3a4fe1a1b04a85e1c527d2d2a70c2..d5338a003c203fb266ec38686f8a28cbbc940e1c 100644 (file)
@@ -88,6 +88,7 @@ define ("DEBUG_CONFIG", 64);
 define ("DEBUG_ACL",    128);
 define ("DEBUG_SI",     256);
 define ("DEBUG_MAIL",   512); // mailAccounts, imap, sieve etc.
+define ("DEBUG_FAI",   1024); // FAI (incomplete)
 
 /* Rewrite german 'umlauts' and spanish 'accents'
    to get better results */
@@ -164,7 +165,7 @@ function make_seed() {
 /* Debug level action */
 function DEBUG($level, $line, $function, $file, $data, $info="")
 {
-  if (session::get('DEBUGLEVEL') & $level){
+  if (session::global_get('DEBUGLEVEL') & $level){
     $output= "DEBUG[$level] ";
     if ($function != ""){
       $output.= "($file:$function():$line) - $info: ";
@@ -219,10 +220,10 @@ function get_browser_language()
 /* Rewrite ui object to another dn */
 function change_ui_dn($dn, $newdn)
 {
-  $ui= session::get('ui');
+  $ui= session::global_get('ui');
   if ($ui->dn == $dn){
     $ui->dn= $newdn;
-    session::set('ui',$ui);
+    session::global_set('ui',$ui);
   }
 }
 
@@ -247,7 +248,7 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
   /* Return plugin dir or root directory? */
   if ($plugin){
     if ($path == ""){
-      $nf= preg_replace("!^".$BASE_DIR."/!", "", session::get('plugin_dir'));
+      $nf= preg_replace("!^".$BASE_DIR."/!", "", session::global_get('plugin_dir'));
     } else {
       $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
     }
@@ -258,7 +259,7 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
       return ("$BASE_DIR/ihtml/themes/default/$nf/$filename");
     }
     if ($path == ""){
-      return (session::get('plugin_dir')."/$filename");
+      return (session::global_get('plugin_dir')."/$filename");
     } else {
       return ($path."/$filename");
     }
@@ -411,7 +412,7 @@ function ldap_login_user_htaccess ($username)
   $ui->loadACL();
 
   /* TODO: check java script for htaccess authentication */
-  session::set('js',true);
+  session::global_set('js',true);
 
   return ($ui);
 }
@@ -603,10 +604,10 @@ function add_lock($object, $user)
   /* Remember which entries were opened as read only, because we 
       don't need to remove any locks for them later.
    */
-  if(!session::is_set("LOCK_CACHE")){
-    session::set("LOCK_CACHE",array(""));
+  if(!session::global_is_set("LOCK_CACHE")){
+    session::global_set("LOCK_CACHE",array(""));
   }
-  $cache = &session::get("LOCK_CACHE");
+  $cache = &session::global_get("LOCK_CACHE");
   if(isset($_POST['open_readonly'])){
     $cache['READ_ONLY'][$object] = TRUE;
     return;
@@ -675,8 +676,8 @@ function del_lock ($object)
   /* If this object was opened in read only mode then 
       skip removing the lock entry, there wasn't any lock created.
     */
-  if(session::is_set("LOCK_CACHE")){
-    $cache = &session::get("LOCK_CACHE");
+  if(session::global_is_set("LOCK_CACHE")){
+    $cache = &session::global_get("LOCK_CACHE");
     if(isset($cache['READ_ONLY'][$object])){
       unset($cache['READ_ONLY'][$object]);
       return;
@@ -1025,7 +1026,7 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
 function check_sizelimit()
 {
   /* Ignore dialog? */
-  if (session::is_set('size_ignore') && session::get('size_ignore')){
+  if (session::global_is_set('size_ignore') && session::global_get('size_ignore')){
     return ("");
   }
 
@@ -1033,8 +1034,8 @@ function check_sizelimit()
   if (session::is_set('limit_exceeded') && session::get('limit_exceeded')){
     $smarty= get_smarty();
     $smarty->assign('warning', sprintf(_("The size limit of %d entries is exceed!"),
-          session::get('size_limit')));
-    $smarty->assign('limit_message', sprintf(_("Set the new size limit to %s and show me this message if the limit still exceeds"), '<input type="text" name="new_limit" maxlength="10" size="5" value="'.(session::get('size_limit') +100).'">'));
+          session::global_get('size_limit')));
+    $smarty->assign('limit_message', sprintf(_("Set the new size limit to %s and show me this message if the limit still exceeds"), '<input type="text" name="new_limit" maxlength="10" size="5" value="'.(session::global_get('size_limit') +100).'">'));
     return($smarty->fetch(get_template_path('sizelimit.tpl')));
   }
 
@@ -1044,7 +1045,7 @@ function check_sizelimit()
 
 function print_sizelimit_warning()
 {
-  if (session::is_set('size_limit') && session::get('size_limit') >= 10000000 ||
+  if (session::global_is_set('size_limit') && session::global_get('size_limit') >= 10000000 ||
       (session::is_set('limit_exceeded') && session::get('limit_exceeded'))){
     $config= "<input type='submit' name='edit_sizelimit' value="._("Configure").">";
   } else {
@@ -1065,25 +1066,25 @@ function eval_sizelimit()
     if (tests::is_id($_POST['new_limit']) &&
         isset($_POST['action']) && $_POST['action']=="newlimit"){
 
-      session::set('size_limit', validate($_POST['new_limit']));
+      session::global_set('size_limit', validate($_POST['new_limit']));
       session::set('size_ignore', FALSE);
     }
 
     /* User wants no limits? */
     if (isset($_POST['action']) && $_POST['action']=="ignore"){
-      session::set('size_limit', 0);
-      session::set('size_ignore', TRUE);
+      session::global_set('size_limit', 0);
+      session::global_set('size_ignore', TRUE);
     }
 
     /* User wants incomplete results */
     if (isset($_POST['action']) && $_POST['action']=="limited"){
-      session::set('size_ignore', TRUE);
+      session::global_set('size_ignore', TRUE);
     }
   }
   getMenuCache();
   /* Allow fallback to dialog */
   if (isset($_POST['edit_sizelimit'])){
-    session::set('size_ignore',FALSE);
+    session::global_set('size_ignore',FALSE);
   }
 }
 
@@ -1164,6 +1165,7 @@ function get_ou($name)
   global $config;
 
   $map = array( 
+                "roleRDN"      => "ou=roles,",
                 "ogroupRDN"      => "ou=groups,",
                 "applicationRDN" => "ou=apps,",
                 "systemRDN"     => "ou=systems,",
@@ -1749,7 +1751,8 @@ function gen_uids($rule, $attributes)
 
     /* Don't assign used ones */
     if (!in_array($uid, $used)){
-      $ret[]= $uid;
+      /* Add uid, but remove {} first. These are invalid anyway. */
+      $ret[]= preg_replace('/[{}]/', '', $uid);
     }
   }
 
@@ -1980,40 +1983,7 @@ function compare_revision($revision_file, $revision)
 
 function progressbar($percentage,$width=100,$height=15,$showvalue=false)
 {
-  $str = ""; // Our return value will be saved in this var
-
-  $color  = dechex($percentage+150);
-  $color2 = dechex(150 - $percentage);
-  $bgcolor= $showvalue?"FFFFFF":"DDDDDD";
-
-  $progress = (int)(($percentage /100)*$width);
-
-  /* If theres a better solution for this, use it... */
-  $str = "\n   <div style=\" width:".($width)."px; ";
-  $str.= "\n       height:".($height)."px; ";
-  $str.= "\n       background-color:#000000; ";
-  $str.= "\n       padding:1px;\" > ";
-
-  $str.= "\n     <div style=\" width:".($width)."px; ";
-  $str.= "\n         background-color:#$bgcolor; ";
-  $str.= "\n         height:".($height)."px;\" > ";
-
-  if(($height >10)&&($showvalue)){
-    $str.= "\n   <font style=\"font-size:".($height-2)."px; ";
-    $str.= "\n     color:#FF0000; align:middle; ";
-    $str.= "\n     padding-left:".((int)(($width*0.4)))."px; \"> ";
-    $str.= "\n     <b>".$percentage."%</b> ";
-    $str.= "\n   </font> ";
-  }
-
-  $str.= "\n       <div style=\" width:".$progress."px; ";
-  $str.= "\n         height:".$height."px; ";
-  $str.= "\n         background-color:#".$color2.$color2.$color."; \" >";
-  $str.= "\n       </div>";
-  $str.= "\n     </div>";
-  $str.= "\n   </div>";
-
-  return($str);
+  return("<img src='progress.php?x=$width&amp;y=$height&amp;p=$percentage'>");
 }
 
 
@@ -2574,6 +2544,11 @@ function generate_smb_nt_hash($password)
     } else {
       $hash= "";
     }
+
+    if ($hash == "") {
+      msg_dialog::display(_("Configuration error"), _("Cannot generate samba hash!"), ERROR_DIALOG);
+      return ("");
+    }
   } else {
          $tmp= $config->get_cfg_value('sambaHashHook')." ".escapeshellarg($password);
          @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
@@ -2582,11 +2557,11 @@ function generate_smb_nt_hash($password)
          flush();
          reset($ar);
          $hash= current($ar);
-  }
 
-  if ($hash == "") {
-         msg_dialog::display(_("Configuration error"), _("Cannot generate samba hash!"), ERROR_DIALOG);
-         return ("");
+    if ($hash == "") {
+      msg_dialog::display(_("Configuration error"), sprintf(_("Cannot generate samba hash: running '%s' failed, check the 'sambaHashHook'!"),$config->get_cfg_value('sambaHashHook')), ERROR_DIALOG);
+      return ("");
+    }
   }
 
   list($lm,$nt)= split (":", trim($hash));
@@ -2808,6 +2783,16 @@ function cred_decrypt($input,$password) {
   return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $input), MCRYPT_MODE_ECB, $iv);
 }
 
+function get_object_info()
+{
+  return(session::get('objectinfo'));
+}
+
+function set_object_info($str = "")
+{
+  session::set('objectinfo',$str);
+}
+
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>