<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/Widget.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/Member.inc.php" );

	class MemberAttachmentPane extends Widget {
		public function __construct( $id = "MemberPane" , $parent = null ) {
			parent::__construct( $id , $parent );
		}

		public function handleEvents() {
			if (!isset( $this->aG["member_attachment_id"] )) {
				return parent::handleEvents();
			}
			$jm = new MemberModel();
			$member_attachment_id = $this->aG["member_attachment_id"];
			$member_attachment = $jm->getMemberAttachment( $member_attachment_id );
			// TODO : jogosultsag van-e raja :D
			header( "Content-Type: " . $member_attachment["attachment_mimetype"] );
			header( sprintf( "Content-Disposition: attachment; filename=\"%s\"",$member_attachment["attachment_original_filename"] ) );
			$filename = $GLOBALS["site_root"].$member_attachment["attachment_path"]."/".$member_attachment["attachment_filename"];
			header( "Content-length: ".$member_attachment["attachment_filesize"] );
			echo file_get_contents( $filename );
			exit();

			// ez viszi ki az okossagot
			return parent::handleEvents();
		}
	}

?>
