<?php
	defined( "_VALID_PAGE_MONITOR" ) or die ("No direct access");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<link href="templates/krzysp/css/main.css" rel="stylesheet" type="text/css" />
</style>
<style type="text/css" title="text/css">
/* <![CDATA[ */
	table{
		border: none;
		width: 100%;
		padding-left: 30px;
	}
	td.grayed{
		background: lightGray;
	}
	td.grayed span{
		font-size: 80%;
	}
	td.grayed span.ok{
		color: green;
	}
	td.grayed span.error{
		color: red;
	}	
/* ]]> */
</style>
</head>
<body>

PageMonitor installation.<br/><br/>

<?php
	$error = false;
	
	if( !$_POST["lang"] )
		include( 'install/language.php' );
	else if( !$_POST["stage2"] ){
		echo '<p>'._INSTALLWELCOME.'</p>';
		?>
		
		<form action="index.php" method="post">
		<input type="hidden" value="true" name="stage2"/>
		<b><?=_PAGEMONITOR_TEXT_A?></b><br/><br/>
		<table style="width:100%">
		<tbody>
		<tr>
		<td class="grayed">
			<b><?=_ABSOLUTE_FTP_FOLDER?></b><br/>
			<span><?=_ABSOLUTE_FTP_FOLDER2?></span>
		</td>
		<td>
			<input type="text" name="ftp_folder" size="20"/>
		</td>
		</tr>
		
		<tr>
		<td class="grayed">
			<b><?=ftp_folder2http_folder?></b><br/>
			<span><?=ftp_folder2http_folder2?></span>
		</td>
		<td>
			<input type="text" name="ftp_folder2http_folder" size="20"/>
		</td>
		</tr>
		
		<tr>
		<td class="grayed">
			<b><?=http_location?></b><br/>
			<span><?=http_location2?></span>
		</td>
		<td>
			<input type="text" name="http_location" size="20" value="PageMonitorPHP"/>
		</td>
		</tr>
		
		<tr>
		<td class="grayed">
			<b><?=date_format?></b><br/>
			<span><?=date_format2?></span>
		</td>
		<td>
			<input type="text" name="date_format" size="20" value="Y-m-d H:i:s"/>
		</td>
		</tr>
		
		<tr>
		<td class="grayed">
			<b><?=show_tooltips_for_pages?></b><br/>
			<span><?=show_tooltips_for_pages2?></span>
		</td>
		<td>
			<select name="show_tooltips_for_pages">
				<option selected value="true"><?=_YES?></option>
				<option value="false"><?=_NO?></option>				
			</select>
		</td>
		</tr>
		
		<tr>
		<td class="grayed">
			<b><?=desired_language?></b><br/>
			<span><?=desired_language2?></span>
		</td>
		<td>
			<select name="lang">
			<?php
				foreach( $langs as $language ){
					?>
						<option value="<?=$language['lang_code']?>"><?=$language['lang name']?></option>
					<?php
				}
			?>
			</select>
		</td>
		</tr>
		
		</tbody>
		</table>
		
		<br/><b><?=_PAGEMONITOR_TEXT_B?></b><br/><br/>
		<table>
			<tbody>
			<tr>
			<td class="grayed">
				<b><?=_XMLFILENAME?></b><br/>
				<span><?=_XMLFILENAME2?></span>
			</td>
			<td>
				<input type="text" name="xmlfile" size="20" value="PageMonitor.xml"/>
			</td>
			</tr>
			
			<tr>
			<td class="grayed">
				<b><?=_FTPACCESS?></b><br/>
				<span><?=_FTPACCESS2?></span>
			</td>
			<td>
				<input type="text" name="ftpaccess" size="20"/>
			</td>
			</tr>
			
			</tbody>
		</table>
		
		<br/><b><?=_PAGEMONITOR_TEXT_C?></b><br/><br/>
		<table>
			<tbody>
			<tr>
			<td class="grayed">
				</br>
			</td>
			<td>
				<input type="submit" value="Install"/>
			</td>
			</tr>
		
			</tbody>
		</table>
		
		</form>
		
		
		<?php
	}else if( $_POST["stage2"] ){
		$ftp_folder = $_POST["ftp_folder"];
		$ftp_folder2http_folder = $_POST["ftp_folder2http_folder"];
		$http_location = $_POST["http_location"];
		$date_format = $_POST["date_format"];
		$show_tooltips_for_pages = $_POST["show_tooltips_for_pages"];
		$desired_language = $_POST["lang"];
		
		$ftpaccess = $_POST["ftpaccess"];
		$xmlfilename = $_POST["xmlfile"];
		
		$out = "";
		$out .= "<?php" . chr(10);
		$out .= "/* No direct access */" . chr(10) . "defined( '_VALID_PAGE_MONITOR' ) or die( 'Restricted access' );" . chr(10).chr(10);
		$out .= "/* Configuration switches */" . chr(10) . "\tglobal $" . "pm_config;" . chr(10);
		
		$out .= "\t$" . 'pm_config["ftp_folder"] = "'. $ftp_folder . '";' .chr(10);
		$out .= "\t$" . 'pm_config["ftp_folder2http_folder"] = "' . $ftp_folder2http_folder .'";' .chr(10);
		$out .= "\t$" . 'pm_config["http_location"] = "/'. $http_location . '";' . chr(10);
		$out .= "\t$" . 'pm_config["template"] = "' . 'krzysp' . '";' .chr(10);
		$out .= "\t$" . 'pm_config["date_format"] = "' . $date_format . '";' .chr(10);
		$out .= "\t$" . 'pm_config["show_tooltips_for_pages"] = ' . $show_tooltips_for_pages . ';' .chr(10);
		$out .= "/* Debug and testing */" .chr(10);
		$out .= "\t$" . 'pm_config["show_elapsed_time"] = true;' . chr(10);
		
		$out .= "/* To GLOBALS */" .chr(10);
		$out .= "\t$" . 'GLOBALS["pm_config"] = $pm_config;' .chr(10);
		
		$out .= "/* Language */" . chr(10);
		$out .= "\tDEFINE('_LANGUAGE','" . $desired_language ."');" .chr(10);
		
		$out .= "?>" .chr(10);
		
		?>
		<table>
		<tbody>
		<tr>
		<td class="grayed"><b>Writting PageMonitorConfiguration.php</b></td>
		<td class="grayed">
		
		<?php
		
		/*
		<form>
			<textarea rows="10" cols="50"><?=$out?></textarea>
		</form>*/
		$wrote = false;		
		$fh = fopen("PageMonitorConfiguration.php", "w" );
		if( $fh ){
			$wrote = fwrite( $fh, $out );
			if( $wrote )
				fclose( $fh );
		}
		if( $wrote )
			echo '<span class="ok">OK</span>';
		else{
			echo '<span class="error">ERROR</span>';
		}
		?>
		</td>
		</tr>
		<?php
			if( !$wrote ){
			?>
			<tr>
				<td>
					<?=_COULDNOTWRITECONFIGFILE?><br/>
					<form>
						<textarea rows="10" cols="50"><?=$out?></textarea>
					</form>
				</td>
				<td>
					<br/>
				</td>
			</tr>
			
			<?php
			}
		?>
		
		<tr>
		<td class="grayed"><b>Writting InDesign plugin xml config file</b></td>
		<td class="grayed">
		<?php
			$out2 = "";
			$out2 .= '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
			$out2 .= '<XML>' . chr(10);
			$out2 .= '<GRABURL>' . base64_encode($ftpaccess) . '</GRABURL>' . chr(10);
			
			$out2_tmp = '<AUTOGRABSAVE VALUE="1"/>
	<LOGFILE VALUE="1"/>
	<PRODUCTIONFLIPFLOP VALUE="1"/>
	<USEDOCPATH VALUE="0"/>
	<AUTOGRABPRINT VALUE="0"/>
	<HIDEINVISIBLES VALUE="1"/>

	<POSTPATH VALUE="1"/>
	<PRODUCTIONPATH CASE="UPPER" VALUE="LAYOUTY OK" CODE="1"/>

	<PREVIEWSCALE VALUE="125"/>

	<CASESENSE VALUE="UPPER"/>

	<TRANSLATE ENABLE="1">KBU,XKBU|S,XS|M,XM|OW,XOW|A,XA|K,XK|RO,XRO|RW,XRW|D,XD|FMW,XFMW|FFM,XFFM|MA,XMA</TRANSLATE>


	<NONPRODUTIONNAME>([0-9]+_[0-9]+_[0-9]+_[A-Z]{2,3}_[0-9]+).+(LAY|LAy|Lay|LaY|lay|lAY|laY|lAy)</NONPRODUTIONNAME>

	<PROOFPRINTER TEXT="Korrektur Drucken..." VALUE="1" NAME="Druckauftrag">
		<OVERFLOW VALUE="1"/>
		<WHITEOVERPRINT VALUE="1"/>
		<REDLINE VALUE="1" SETTING="0 mm"/>
	</PROOFPRINTER>
	
	<WHITEOVERPRINT TEXT="Check text set to overprint" VALUE="1"/>
	<UNUSEDCOLORS TEXT="Check for unused colors" VALUE="1"/>
	<PAGINATIONINFO TEXT="Fill out pagination" VALUE="1"/>
	<PICTURESCALE TEXT="Check picture scaling" VALUE="1" LO="70" HI="140"/>

	<SEARCHPICTUREPATH TEXT="Layout-Scans pruefen" BACKGROUND="1" VALUE="1">
		<OPTION>  Layout_Scans</OPTION>
	</SEARCHPICTUREPATH>
	
	<PRINTACTION>
		<SEARCHOLDPICTURE VALUE="1"/>
	</PRINTACTION>
	
	<!-- krzysp; dodane przeze mnie -->
	<!-- 
		kSSJPEGLowQuality 				=> 1
		kSSJPEGGoodQuality				=> 2
		kSSJPEGExcellentQuality		=> 3
		kSSJPEGGreatQuality				=> 4
		-->
	<PREVQUALITY XSCALE=".2" YSCALE=".2" DPI="72.0" JPEGQUALITY="1" STRING="-low"/>
<!--<PREVQUALITY XSCALE=".5" YSCALE=".5" DPI="72.0" JPEGQUALITY="2" STRING="-med"/>-->
	<PREVQUALITY XSCALE="1" YSCALE="1" DPI="72.0" JPEGQUALITY="3" STRING="-high"/>	

	<DOCNAME>
		<REGEX>([0-9]+_[0-9]+_(PS1|PS2)_([0-9]{6})+).+</REGEX>
		<DAY>[0-9]+_[0-9]+_[A-Z,0-9]{3}_([0-9]{2})</DAY>
		<MONTH>[0-9]+_[0-9]+_[A-Z,0-9]{3}_[0-9]{2}([0-9]{2})</MONTH>
		<MINIYEAR>[0-9]+_[0-9]+_[A-Z,0-9]{3}_[0-9]{4}([0-9]{2})</MINIYEAR>
		<OBJECT>[0-9]+_[0-9]+_([A-Z,0-9]{3})</OBJECT>
		<PAGE>([0-9]+)</PAGE>
		<!-- jeżeli nie ma XPAGE będzie podgląd tylko jednej strony! -->
		<XPAGE>[0-9]+_([0-9]+)</XPAGE>
	</DOCNAME>

	<DOCNAME>
		<REGEX>([0-9]+_(PS1|PS2)_([0-9]{6})+).+</REGEX>
		<DAY>[0-9]+_[A-Z,0-9]{3}_([0-9]{2})</DAY>
		<MONTH>[0-9]+_[A-Z,0-9]{3}_[0-9]{2}([0-9]{2})</MONTH>
		<MINIYEAR>[0-9]+_[A-Z,0-9]{3}_[0-9]{4}([0-9]{2})</MINIYEAR>
		<OBJECT>[0-9]+_([A-Z,0-9]{3})</OBJECT>
		<PAGE>([0-9]+)</PAGE>
		<XPAGE>[0-9]+_([0-9]+)</XPAGE>
	</DOCNAME>


	<DOCNAME>
		<REGEX>([0-9]+_[0-9]+_(PBS1|PKG1|PZZ1|PWW1|PSL1|PTR1|PWR1|TMPO|SKLP|SKF1|EURO)_([0-9]{6})+).+</REGEX>
		<DAY>[0-9]+_[0-9]+_[A-Z,0-9]{4}_([0-9]{2})</DAY>
		<MONTH>[0-9]+_[0-9]+_[A-Z,0-9]{4}_[0-9]{2}([0-9]{2})</MONTH>
		<MINIYEAR>[0-9]+_[0-9]+_[OAA-Z,0-9]{4}_[0-9]{4}([0-9]{2})</MINIYEAR>
		<OBJECT>[0-9]+_[0-9]+_([A-Z,0-9]{4})</OBJECT>
		<PAGE>([0-9]+)</PAGE>
		<PAGE>[0-9]+_([0-9]+)</PAGE>
	</DOCNAME>

	<DOCNAME>
		<REGEX>([0-9]+_(PBS1|PKG1|PZZ1|PWW1|PSL1|PTR1|PWR1|TMPO|SKLP|SKF1|EURO)_([0-9]{6})+).+</REGEX>
		<DAY>[0-9]+_[A-Z,0-9]{4}_([0-9]{2})</DAY>
		<MONTH>[0-9]+_[A-Z,0-9]{4}_[0-9]{2}([0-9]{2})</MONTH>
		<MINIYEAR>[0-9]+_[A-Z,0-9]{4}_[0-9]{4}([0-9]{2})</MINIYEAR>
		<OBJECT>[0-9]+_([A-Z,0-9]{4})</OBJECT>
		<PAGE>([0-9]+)</PAGE>
		<XPAGE>[0-9]+_([0-9]+)</XPAGE>
	</DOCNAME>
';
		$out2 .= $out2_tmp;
		
		$out2 .= '</XML>' . chr(10);
		
		$wrote = false;		
		$fh = fopen($xmlfilename, "w" );
		if( $fh ){
			$wrote = fwrite( $fh, $out2 );
			if( $wrote )
				fclose( $fh );
		}
		if( $wrote )
			echo '<span class="ok">OK</span>';
		else{
			echo '<span class="error">ERROR</span>';
		}
		
		?>
		</td>
		</tr>
		
		<?php
		if( !$wrote ){
		?>
			<tr>
			<td><?php printf(_COULDNOTWRITECONFIGFILEXML, $xmlfilename);?><br/>
			<form>
						<textarea rows="10" cols="50"><?=$out2?></textarea>
			</form>
			</td>
			<td><br/></td>
			</tr>
		<?php
		}
		?>

		</tbody>
		</table>
		
		<p>
		<?=_INSTALLATIONCOMPLETE?>
		</p>
		<?php
	}
	
	
	
?>

</body>
</html>
