<?php
include_once ("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."config.php");
include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");
include_once(PATH_TO_ROOT."CRM/class/class.checkString.php");
include_once (PATH_TO_ROOT.'CRM/class/class.logger.php');
$LangPack = new LanguagePack($db, $aLanguage);
$table = "_customerActivities";

$id = StringChecker::Check(intval($_GET['a']));
if(empty($id))
    exit;
$sql = "SELECT a.*, b.description as activity 
		FROM ".WARPIT_CRM.".".$table." as a 
		LEFT JOIN ".WARPIT_CRM."._activitiesSpecification as b
		ON a.activityId = b.id
		WHERE a.customerId = ".$id." 
		AND a.deleted = 0 
		ORDER BY inputDate DESC";
$res = $db->SQLexecute($sql);


?>
<table cellpadding="0" border="1" cellspacing="0" width="90%" align="center">
	<tr>
		<th>
			<?php echo $LangPack->GetLabel("preview_activities_window", "activity_title","Aktivnost");?>
		</th>
		<th>
			<?php echo $LangPack->GetLabel("preview_activities_window", "inputDate_title","Datum");?>
		</th>
		<th>
			<?php echo $LangPack->GetLabel("preview_activities_window", "file_title","Datoteka");?>
		</th>
		<th>
			<?php echo $LangPack->GetLabel("preview_activities_window", "comment_title","Komentar");?>
		</th>
		<th>
			<?php echo $LangPack->GetLabel("preview_activities_window", "filename_title","Ime datoteke");?>
		</th>
	</tr>
<?php
while($row = $db->fetchAssoc($res)){
	echo "<tr>";
		echo "<td>";
			echo $row['activity'];
		echo "</td>";
		echo "<td>";
			echo date_format(new DateTime($row['addedDate']),"d.m.Y H:i:s");
		echo "</td>";
		echo "<td width=300 height=300>";
            $file = str_replace("../", "",$row['fileLocation']);
            $ext = pathinfo($file, PATHINFO_EXTENSION);
            if($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "bmp" || $ext == "gif")
    			echo "<img width=300 height=300 src='".ACTIVITE_UPLOAD_WWW_PATH.str_replace("../", "",$row['fileLocation'])."' alt= '".str_replace("../", "",$row['fileLocation'])."'>";
            else
                echo "<a href='".ACTIVITE_UPLOAD_WWW_PATH.$file."' target='_blank'>".basename($row['fileLocation'])."</a>";
		echo "</td>";
		echo "<td>";
			echo $row['comment'] != null ? $row['comment'] : "&nbsp;";
		echo "</td>";
		echo "<td>";
			echo basename($row['fileLocation']);
		echo "</td>";
	echo "</tr>";
}	
?>
</table>