<?php
	require_once( $GLOBALS["site_root"]."/includes/widgets/Widget.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/MyProfileMenu.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendAdminSubmit.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/FrontendSubmit.inc.php" );

	require_once( $GLOBALS["site_root"]."/includes/models/User.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/models/AdminUser.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/models/DirtyObject.inc.php" );

	class MemberWidget extends Widget {
		// csak pane lehet, NEM LEHET SUBPANE (MemberWidget in MemberWidget)
		protected $bLoggedIn = false;
		protected $iUserId = 0;
		protected $iMemberId = 0;
		protected $user_model;
		protected $my_user_model;
		protected $my_member_model;
		protected $member_model;

		protected $oMyProfileMenu;

		protected $oSubmit = null;
		protected $oAdminSubmit = null;
		protected $sPageName = "";

		public function __construct( $id , $parent = null ) {
			parent::__construct( $id , $parent );
			$this->user_model = new UserModel();
			$this->my_member_model = $this->my_user_model = new MyMemberModel();
			$this->member_model = new MemberModel();
			$this->dirty_model = new DirtyObjectModel();
			$this->bLoggedIn = $this->my_user_model->isUserLoggedIn();
			$this->iUserId = $this->my_user_model->getLoggedInUserId();
			$this->iMemberId = $this->my_user_model->getLoggedInMemberId();
			if (!$this->bLoggedIn) return;

			$this->oMyProfileMenu = new MyProfileMenu( "MyProfileMenu" , $this );
		}

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->setParam( "bLoggedIn" , $this->bLoggedIn );
			return parent::render();
		}

		protected function clearDirtyObjectAdmin( $object ) {
			$this->dirty_model->unsetDirtyObject( $this->iUserId , $object );
			if ($this->dirty_model->isDirtyObject( $this->iUserId )) return;
			$this->user_model->adminAcknowledgeUser( $this->iUserId );
		}

		protected function generateMemberWidgetNormalSubmit( $object = "" ) {
			$this->oSubmit = new FrontendSubmit( "smb_modify" , $this );
			$this->oSubmit->setValue( __("Save","attr") );

			if (empty( $object )) return;
			if ($this->dirty_model->isDirtyObject( $this->iUserId , $object ) && AdminUserModel::isAdminLoggedIn() ) {
				$this->oAdminSubmit = new FrontendAdminSubmit( "smb_admin_modify" , $this );
				$this->oAdminSubmit->setValue( __("Admin_save","attr") );
			}
		}

	}



?>
