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

	class MyProfileMenu extends Widget {
		protected $bIsMember;
		protected $sCurrent = "basic_datas";
		protected $iCurrentIndex = 0;
		protected $aMenu = array();
		protected $my_member_model = null;

		public function setCurrentMenuItem( $v ) { $this->sCurrent = $v; }

		protected function prepareMenu() {
			$this->aMenu = $this->my_member_model->getMenu();
			$this->iCurrentIndex = 0;
			foreach ($this->aMenu as $menuitem) {
				if ($menuitem["name"]==$this->sCurrent) break;
				$this->iCurrentIndex++;
			}
			// get current menu
			$this->iNumofitems = count( $this->aMenu );
			$prev_num = ($this->iCurrentIndex + $this->iNumofitems-1)%$this->iNumofitems;
			$next_num = ($this->iCurrentIndex + 1)%$this->iNumofitems;
			$this->setParam( "url_prev", $this->aMenu[$prev_num]["url"] );
			$this->setParam( "url_next", $this->aMenu[$next_num]["url"] );
			$this->setParam( "numofitems" , count( $this->aMenu ) );
			$this->setParam( "menuindex" , $this->iCurrentIndex );
			$this->setParam( "menuitem" , $this->aMenu[ $this->iCurrentIndex ] );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->my_member_model = new MyMemberModel();
			$this->bIsMember = $this->my_member_model->isMemberLoggedin();
			if ($this->bIsMember) {
				$mm = new MemberModel();
				$member = $mm->getMemberFromMemberId( $this->my_member_model->getLoggedInMemberId() );
				$murl = new MemberURL();
				$this->setParam( "url_public_profile" , $murl->renderURLFromMember( $member ) );
			}
			fo3_use_global_css( "jquery-ui.css" );

			$this->setParam( "bIsMember" , $this->bIsMember );
			if (!$this->bIsMember) return parent::render();
			FNTHPage::addUniquePageFullInit(
				sprintf( "InitMyProfileMenu('%s');\n",$this->getId() ) );
			$this->prepareMenu();
			return parent::render();
		}

	}

?>
