';
return ($apply);
}
@@ -1371,27 +1547,27 @@ function gen_uids($rule, $attributes)
}
}
- if(preg_match('/\{id#\d+}/',$uid)){
- $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
+ if(preg_match('/\{id#\d+}/',$uid)){
+ $size= preg_replace('/^.*{id#(\d+)}.*$/', '\\1', $uid);
- while (true){
- mt_srand((double) microtime()*1000000);
- $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
- $res= preg_replace('/{id#(\d+)}/', $number, $uid);
- if (!in_array($res, $used)){
- $uid= $res;
- break;
- }
+ while (true){
+ mt_srand((double) microtime()*1000000);
+ $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1));
+ $res= preg_replace('/{id#(\d+)}/', $number, $uid);
+ if (!in_array($res, $used)){
+ $uid= $res;
+ break;
}
}
-
- /* Don't assign used ones */
- if (!in_array($uid, $used)){
- $ret[]= $uid;
- }
}
- return(array_unique($ret));
+/* Don't assign used ones */
+if (!in_array($uid, $used)){
+ $ret[]= $uid;
+}
+}
+
+return(array_unique($ret));
}
@@ -1445,6 +1621,10 @@ function to_byte($value) {
function in_array_ics($value, $items)
{
+ if (!is_array($items)){
+ return (FALSE);
+ }
+
foreach ($items as $item){
if (strtolower($item) == strtolower($value)) {
return (TRUE);
@@ -1493,9 +1673,7 @@ function validate($string)
function get_gosa_version()
{
- /* Variables filled in by subversion */
- $svn_path = '$HeadURL$';
- $svn_revision = '$Revision$';
+ global $svn_revision, $svn_path;
/* Extract informations */
$revision= preg_replace('/^[^0-9]*([0-9]+)[^0-9]*$/', '\1', $svn_revision);
@@ -1509,80 +1687,291 @@ function get_gosa_version()
}
}
-function gosaRaiseError($errno, $errstr, $errfile, $errline)
+
+function rmdirRecursive($path, $followLinks=false) {
+ $dir= opendir($path);
+ while($entry= readdir($dir)) {
+ if(is_file($path."/".$entry) || ((!$followLinks) && is_link($path."/".$entry))) {
+ unlink($path."/".$entry);
+ } elseif (is_dir($path."/".$entry) && $entry!='.' && $entry!='..') {
+ rmdirRecursive($path."/".$entry);
+ }
+ }
+ closedir($dir);
+ return rmdir($path);
+}
+
+function scan_directory($path,$sort_desc=false)
{
- global $error_collector;
+ $ret = false;
- /* FIXME: workaround for buggy imap_open */
- if (preg_match('/imap_open/', $errstr)){
- return;
+ /* is this a dir ? */
+ if(is_dir($path)) {
+
+ /* is this path a readable one */
+ if(is_readable($path)){
+
+ /* Get contents and write it into an array */
+ $ret = array();
+
+ $dir = opendir($path);
+
+ /* Is this a correct result ?*/
+ if($dir){
+ while($fp = readdir($dir))
+ $ret[]= $fp;
+ }
+ }
}
+ /* Sort array ascending , like scandir */
+ sort($ret);
- /* FIXME: workaround for PHP5 */
- if (preg_match('/var: Deprecated./', $errstr)){
- return;
+ /* Sort descending if parameter is sort_desc is set */
+ if($sort_desc) {
+ $ret = array_reverse($ret);
}
- /* Create header as needed */
- if ($error_collector == ""){
- if ($_SESSION['js']==FALSE){
- $error_collector= "
";
+ return($ret);
+}
+
+function clean_smarty_compile_dir($directory)
+{
+ global $svn_revision;
+
+ if(is_dir($directory) && is_readable($directory)) {
+ // Set revision filename to REVISION
+ $revision_file= $directory."/REVISION";
+
+ /* Is there a stamp containing the current revision? */
+ if(!file_exists($revision_file)) {
+ // create revision file
+ create_revision($revision_file, $svn_revision);
} else {
- $error_collector= "
"._("Generating this page caused the PHP interpreter to rise some errors!")."
";
+# check for "$config->...['CONFIG']/revision" and the
+# contents should match the revision number
+ if(!compare_revision($revision_file, $svn_revision)){
+ // If revision differs, clean compile directory
+ foreach(scan_directory($directory) as $file) {
+ if(($file==".")||($file=="..")) continue;
+ if( is_file($directory."/".$file) &&
+ is_writable($directory."/".$file)) {
+ // delete file
+ if(!unlink($directory."/".$file)) {
+ print_red("File ".$directory."/".$file." could not be deleted.");
+ // This should never be reached
+ }
+ } elseif(is_dir($directory."/".$file) &&
+ is_writable($directory."/".$file)) {
+ // Just recursively delete it
+ rmdirRecursive($directory."/".$file);
+ }
+ }
+ // We should now create a fresh revision file
+ clean_smarty_compile_dir($directory);
+ } else {
+ // Revision matches, nothing to do
+ }
}
+ } else {
+ // Smarty compile dir is not accessible
+ // (Smarty will warn about this)
}
-
- /* Extract traceback data */
- $trace= debug_backtrace();
-
- /* Create error header */
- $error_collector.= "
"._("PHP error")." \"$errstr\"
";
-
- /* Generate trace history */
- for ($index= 1; $index":
- $type= _("method");
- break;
+ fclose($fh);
+ } else {
+ print_red("Can not write to revision file");
+ }
+
+ return $result;
+}
+
+function compare_revision($revision_file, $revision)
+{
+ // false means revision differs
+ $result= false;
+
+ if(file_exists($revision_file) && is_readable($revision_file)) {
+ // Open file
+ if($fh= fopen($revision_file, "r")) {
+ // Compare File contents with current revision
+ if($revision == fread($fh, filesize($revision_file))) {
+ $result= true;
}
} else {
- $type= "-";
+ print_red("Can not open revision file");
+ }
+ // Close file
+ fclose($fh);
+ }
+
+ return $result;
+}
+
+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);
+
+ /* Abort printing out percentage, if divs are to small */
+
+
+ /* If theres a better solution for this, use it... */
+ $str = "
+