<?PHP
/******************************************************************************
 @Author: 	Björn Brockmann, Paul Eppner (paul@twomoons.de)
			Sven Bräutigam, Jürgen Brändle
 @Homepage  http://www.der-dirigent.de
******************************************************************************/

/******************************************************************************
 1. Benötigte Funktionen und Klassen includieren
******************************************************************************/

/******************************************************************************
 2. Eventuelle Actions/ Funktionen abarbeiten
******************************************************************************/
$perm->check('area_upl');
if ($idclient != 0 && $idclient != (int) $client || !isset($idclient)) $idclient = (int) $client;

/******************************************************************************
 3. Eventuelle Dateien zur Darstellung includieren
******************************************************************************/

/******************************************************************************
 4. Bildschirmausgabe aufbereiten und ausgeben
******************************************************************************/

$url         = 'main.php?area=scan&action=10&iddirectory=' . $iddirectory . '&viewtype=' . $viewtype;
$url2        = 'main.php?area=upl&idexpand=' . $idexpand . '&viewtype=' . $viewtype;
$progressbar = 'tpl/' . $cfg_dedi['skin'] . '/img/blue.gif';
?>
<html>
	<meta http-equiv="content-type" content="text/html; charset=<?PHP echo $lang_charset ?>">
	<title>der dirigent 1.0 - <?PHP echo $dedi_lang['scan_title']; ?></title>
	<script language="JavaScript1.2">
		var intActive       = 0
		var intDirs         = 0
		var intFiles        = 0
		var intThumbs       = 0
		var intDirsDone     = -1
		var intFilesDone    = 0
		var intThumbsDone   = 0
		var intDirsOpen     = 0
		var intFilesOpen    = 0
		var intThumbsOpen   = 0
		var intTotalProzent = 0
		var strError        = ""
		var arrErrorFiles   = [];
		var dtmStart        = new Date();
		var intDuration     = 0
		var dtmEnde         = '';
		
		function updateprogressbar() {
			var strText
			strText  = "<html>"
			strText += "<style>"
			strText += "body  { font-family: Verdana,Arial,Helvetica; font-size: 11px; }"
			strText += "table { width: 100%; }"
			strText += "th    { font-family: Verdana,Arial,Helvetica; font-size: 11px; text-align: left; }"
			strText += "td    { font-family: Verdana,Arial,Helvetica; font-size: 11px; text-align: center; }"
			strText += "caption { font-family: Verdana,Arial,Helvetica; font-size: 11px; font-weight: bold; text-align: left; color: #800000; }"
			strText += "</style>"
			strText += "<body>";
			if (intTotalProzent > 0) {
				strText += "<p><img src=\"<?PHP echo $progressbar; ?>\" height=\"20\" hspace=\"5\" vspace=\"5\" width=\"" + parseInt(370*intTotalProzent/100) + "\" alt=\"<?PHP echo $dedi_lang['scan_done_start']; ?>" + intTotalProzent + "<?PHP echo $dedi_lang['scan_done_end']; ?>\"></p>"
			} else {
				strText += "<p><img src=\"<?PHP echo $progressbar; ?>\" height=\"20\" hspace=\"5\" vspace=\"5\" width=\"0\" alt=\"<?PHP echo $dedi_lang['scan_done_start']; ?>" + intTotalProzent + "<?PHP echo $dedi_lang['scan_done_end']; ?>\"></p>"
			}
			strText += "<p align=\"center\">" + intTotalProzent + "<?PHP echo $dedi_lang['scan_done_end']; ?></p>"
			strText += (strError != "") ? "<p><?PHP echo $dedi_lang['scan_error']; ?>" + strError + "</p>": "";
			strText += "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"1\">"
			strText += "<caption><?PHP echo $dedi_lang['scan_status']; ?>" + ((intActive == 3) ? "<?PHP echo $dedi_lang['scan_status_done_start']; ?>" + intDuration + "<?PHP echo $dedi_lang['scan_status_done_end']; ?>": "<?PHP echo $dedi_lang['scan_status_active']; ?>") + "</caption>"
			strText += "<tr>"
			strText += "<th>&nbsp;</th><th><?PHP echo $dedi_lang['scan_status_total']; ?></th><th><?PHP echo $dedi_lang['scan_status_processed']; ?></th><th><?PHP echo $dedi_lang['scan_status_todo']; ?></th>"
			strText += "</tr>"
			strText += (intActive == 0) ? "<tr bgcolor=\"#A8BADE\">": "<tr>";
			strText += "<th><?PHP echo $dedi_lang['scan_directroies']; ?></th><td>" + intDirs + "</td><td>" + intDirsDone + "</td><td>" + intDirsOpen + "</td>"
			strText += "</tr>"
			strText += (intActive == 1) ? "<tr bgcolor=\"#A8BADE\">": "<tr>";
			strText += "<th><?PHP echo $dedi_lang['scan_files']; ?></th><td>" + intFiles + "</td><td>" + intFilesDone + "</td><td>" + intFilesOpen + "</td>"
			strText += "</tr>"
			strText += (intActive == 2) ? "<tr bgcolor=\"#A8BADE\">": "<tr>";
			strText += "<th><?PHP echo $dedi_lang['scan_thumbs']; ?></th><td>" + intThumbs + "</td><td>" + intThumbsDone + "</td><td>" + intThumbsOpen + "</td>"
			strText += "</tr>"
			strText += "<tr>"
			strText += "<td colspan=\"4\" style=\"text-align: left;\">"
			strText += "<br><p><?PHP echo $dedi_lang['scan_errors']; ?><br>"
			strText += (arrErrorFiles.length > 0) ? arrErrorFiles.join("<br>"): "<?PHP echo $dedi_lang['scan_errors_none']; ?>";
			strText += "</p>"
			if (intActive == 3) {
				strText += "<p align=\"center\"><?PHP echo $dedi_lang['scan_closing_time']; ?><br><a href=\"javascript:top.close()\"><?PHP echo $dedi_lang['scan_close_now']; ?></a></p>"
				if (window.opener) window.opener.location.href = "<?PHP echo $sess->url($url2); ?>";
			}
			strText += "</td>"
			strText += "</tr>"
			strText += "</table>"
			strText += "</body></html>"
			var preview = window.frames["progress"].document
			preview.open();
			preview.write(strText);
  			preview.close();
		}
		function setDirValues() {
			intDirs     += arguments[0];
			intDirsDone += arguments[1];
			intDirsOpen  = intDirs - intDirsDone;
		}
		function setFileValues() {
			intFiles     += arguments[0];
			intFilesDone += arguments[1];
			intFilesOpen  = intFiles - intFilesDone;
		}
		function setThumbValues() {
			if (arguments[0] > intThumbs) intThumbs = arguments[0];
			intThumbsDone += arguments[1];
			intThumbsOpen  = intThumbs - intThumbsDone;
		}
		function setMiscValues() {
			if (arguments.length >= 1) arrErrorFiles = arrErrorFiles.concat(arguments[0]);
			if (arguments.length >= 2) strError     = arguments[1];
			if (arguments.length >= 3) intActive    = arguments[2];
			
			switch (intActive) {
				case 0:
					intTotalProzent  = (intDirs > 0)   ? 33.33*(intDirsDone/intDirs)    : 0.00;
					break;
				case 1:
					intTotalProzent  = 33.33
					intTotalProzent += (intFiles > 0)  ? 33.33*(intFilesDone/intFiles)  : ((intFilesDone >= intFiles) ? 33.33 : 0.00);
					break;
				case 2:
					intTotalProzent  = 66.66
					intTotalProzent += (intThumbs > 0) ? 33.34*(intThumbsDone/intThumbs): ((intThumbsDone >= intThumbs && intThumbs > 0) ? 33.34 : 0.00);
					break;
				default:
					dtmEnde = new Date();
					intDuration = dtmEnde.getTime() - dtmStart.getTime()
					intDuration /= 1000;
					intTotalProzent = 100.00;
					break;
			}
			intTotalProzent = Math.round(intTotalProzent)
			updateprogressbar();
		}
	</script>
	<style>
		body { margin: 0px; padding: 0px; }
		iframe { margin: 0px; padding: 0px; }
	</style>
	<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
		<iframe src="<?PHP echo $sess->url($url); ?>" name="progress" id="progress" width="100%" height="100%" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="yes" frameborder="0"></iframe>
		<iframe src="about:blank" name="progresscontrol" id="progresscontrol" width="100%" height="1" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="no" frameborder="0"></iframe>
	</body>
</html>