<?php
include("../../Config/config.php");
$Config =& new Config();

mysql_connect($Config->DB_HOST, $Config->DB_USER, $Config->DB_PASS) or die(mysql_error());
mysql_select_db($Config->DB_DATABASE) or die(mysql_error());

if ((int)ini_get('magic_quotes_runtime')) set_magic_quotes_runtime(0);

function redirectTo($newUrl){
 $newUrl = trim($newUrl);

 echo("<head><meta http-equiv=\"Refresh\" content=\"0;URL=" . $newUrl . "\"></head><body></body></html>");
 exit();
}

function debug($value) {
        $counter = 0;
        echo "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" style=\"border: solid 1px #000000; background: #EEEEEE; width: 95%; margin: 20px;\" align=\"center\">\n";
        echo "<tr>\n<td colspan=\"3\" style=\"font-family: Arial; font-size: 13pt; font-weight: bold; text-align: center;\">Debugging Information</td>\n</tr>\n";
        if ( is_array($value) ) {
                echo "<tr>\n<td>&nbsp;</td>\n<td><b>Array Key</b></td>\n<td><b>Array Value</b></td>\n</tr>\n";
                foreach($value as $key=>$val) {
                        if (is_array($val)) {
                                debug($val);
                        }
                        else {
                                echo "<tr>\n<td>$counter</td>\n<td>&nbsp;" . $key . "&nbsp;</td>\n<td>&nbsp;" . $val . "&nbsp;</td>\n</tr>\n";
                        }
                        $counter++;
                }
        }
        else {
                echo "<tr>\n<td colspan=\"3\">" . $value . "</td>\n</tr>\n";
        }
        echo "</table>\n";
}

function blogger_checkFaultString($bloggerResult) {
        if (isset($bloggerResult["faultString"])) {
                return $bloggerResult["faultString"];
        }
        else if (strpos(isset($bloggerResult), "java.lang.Exception") !== false) {
                return $bloggerResult;
        }
        else {
                return true;
        }
}

function display_select($name, $options, $value = 0, $misc = "unset") {
        $select = "<select";
        if (strlen($name)) {
                $select .= " name=\"" . $name . "\"";
        }
        if (is_array($misc)) {
                while (list($id, $val) = each($misc)) {
                        $select .= " " . $id . "=\"" . $val . "\"";
                }
        }
        $select .= ">";
        if (is_array($options)) {
                while (list($id, $val) = each($options)) {
                        $select .= "\n<option";
                        $select .= " value=\"" . $id . "\"";
                        if (strcmp($id, $value))
                                $select .= ">";
                        else
                                $select .= " selected>";
                        $select .= htmlspecialchars($val) . "</option>";
                }
        }
        $select .= "\n</select>\n";
        return $select;
}

function filelist ($startdir="../tmp/", $searchSubdirs=1, $directoriesonly=0, $maxlevel="all", $level=1){
   //list the directory/file names that you want to ignore
   $ignoredDirectory[] = ".";
   $ignoredDirectory[] = "..";
   $ignoredDirectory[] = "_vti_cnf";
   $ignoredDirectory[] = ".htaccess";
   $ignoredDirectory[] = "index.htm";
   $ignoredDirectory[] = "index.html";
   $ignoredDirectory[] = "index.php";
   global $directorylist;    //initialize global array

   if (is_dir($startdir)) {
       if ($dh = opendir($startdir)) {
           while (($file = readdir($dh)) !== false) {
               if (!(array_search($file,$ignoredDirectory) > -1)) {
                 if (filetype($startdir . $file) == "dir") {
                       //build your directory array however you choose;
                       //add other file details that you want.
                       $directorylist[$startdir . $file]['level'] = $level;
                       $directorylist[$startdir . $file]['dir'] = 1;
                       $directorylist[$startdir . $file]['name'] = $file;
                       $directorylist[$startdir . $file]['path'] = $startdir;
                       if ($searchSubdirs) {
                           if ((($maxlevel) == "all") or ($maxlevel > $level)) {
                               filelist($startdir . $file . "/", $searchSubdirs, $directoriesonly, $maxlevel, $level + 1);
                           }
                       }
                   } else {
                       if (!$directoriesonly) {
                           //if you want to include files; build your file array
                           //however you choose; add other file details that you want.
                         $directorylist[$startdir . $file]['level'] = $level;
                         $directorylist[$startdir . $file]['dir'] = 0;
                         $directorylist[$startdir . $file]['name'] = $file;
                         $directorylist[$startdir . $file]['path'] = $startdir;
     					}
     				}
     			}
     		}
           closedir($dh);
		}

	}
	return($directorylist);
}

function delete_files($target, $exceptions, $output=true){
   $sourcedir = opendir($target);
   while(false !== ($filename = readdir($sourcedir)))
   {
       if(!in_array($filename, $exceptions))
       {
           if($output)
           { echo "Processing: ".$target."/".$filename."<br>"; }
           if(is_dir($target."/".$filename))
           {
               // recurse subdirectory; call of function recursive
               delete_files($target."/".$filename, $exceptions);
           }
           else if(is_file($target."/".$filename))
           {
               // unlink file
               unlink($target."/".$filename);
           }
       }
   }
   closedir($sourcedir);
   if(rmdir($target))
   { return true; }
   else
   { return false; }
}
?>
