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

	class MemberAttachments extends GeneralAttachments {
		protected $mmm;
		protected $mm;

		public function __construct( $id = "MemberAttachments" , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->mmm = new MyMemberModel();
			$this->mm = new MemberModel();

		}

		public function loadAttachments() {
			$member_id = $this->mmm->getLoggedinMemberId();
			$attachments = $this->mm->getMemberAttachments( $member_id );

			$i = array();
		
			foreach ($attachments as $attachment) {
				$f = array();
				$f["id"]=$attachment["member_attachment_id"];
				$f["mime_type"]=$attachment["attachment_mimetype"];
				$f["filename"]=$attachment["attachment_original_filename"];	
				$f["real_path"]=$GLOBALS["site_root"].$attachment["attachment_path"].$attachment["attachment_filename"];
				$f["www_path"]=MemberURL::renderMemberAttachmentURL( $attachment["member_attachment_id"] );
				$f["comment"]=$attachment["attachment_title"];
				$f["original"]=true;
				$this->addAttachment( $f );
			}
		}

		public function deleteAttachment( $id ) {
			$this->mm->deleteMemberAttachment( $id ,
				$this->mmm->getLoggedinMemberId() );
		}

		public function saveAttachments() {
			if (empty( $this->aAttachments )) return;
			/*
			if (AdminIpModel::isAdminIp( fo3_get_remote_ipaddress() )) {
				FNTH_da( $this->aAttachments );
			}
			*/
			foreach ($this->aAttachments as $attachment) {
				$this->mm->addMemberAttachment(
					$this->mmm->getLoggedinMemberId(),
					$attachment );
			}
		}
	}

?>
