<?php

/*

Jappix - The instant messaging. Reinvented.
This is the PHP script used to generate a chat log

-------------------------------------------------

Licence : GNU/GPL
Author : Vanaryon
Contact : mailing-list[at]jappix[dot]com
Last revision : 03/03/10

*/

// WE CREATE THE HTML FILE TO BE DOWNLOADED
	if(isset($_POST['originalchat']) && isset($_POST['fromjid'])) {
		// WE DEFINE SOME VARIABLES
			$content_dir = './temp/';
			$original_text = $_POST['originalchat'];
			$from = $_POST['fromjid'];
			$date = date('l jS \of F Y h:i:s A');
			$filename = "chat_log-".crc32($from.$date);
			$filepath = $content_dir.$filename.'.html';
		
		// WE CREATE THE HTML CODE
			$new_text_inter = 
	'<!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" />
			<title>Chat log with '.$from.'</title>
			<style type="text/css">
				html {
					background-color: #ededed;
				}
			
				body {
					margin: 20px 20px 20px 20px;
					padding: 10px 10px 0px 10px;
					border: 1px solid black;
					background-color: #fbf8d8;
					color: #464543;
					font-family : Verdana, Arial, Helvetica, sans-serif;
					font-size: 12pt;
				}
			
				.one-line {
					margin: -12px 0;
				}
				
				.title {
					text-decoration: underline;
					margin: 5px 0 25px 0;
				}
				
				.informations {
					margin-top: 50px;
					padding-top: 10px;
					border-top: 1px black dotted;
				}
			</style>
		</head>
		
		<body>
			<h3 class="title">This is your chat log with '.$from.' on '.$date.'.</h3>
			'.$original_text.'
			<h5 class="informations">Generated by Jappix IM (<a href="http://www.jappix.com/" target="_blank">http://www.jappix.com/</a>) released under the AGPL licence.</h5>
		</body>
	</html>'
			;
			
			$new_text = stripslashes($new_text_inter);
		
		// WE WRITE IT INTO A HTML FILE
			$fileopen = fopen($filepath,"a");
			fwrite($fileopen,$new_text);
			fclose($fileopen);
		
		// WE RETURN TO THE USER THE GENERATED FILE NAME
			echo($filename);
	}
?>
