<?php
	require_once( $GLOBALS["site_root"]."/includes/pages/BackendPopup.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminTextbox.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminTextarea.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminSubmit.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminTimestamp.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminCheckbox.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminNumeric.inc.php" );
	require_once( $GLOBALS["site_root"]."/includes/widgets/AdminUserLogTable.inc.php" );

	require_once( $GLOBALS["site_root"]."/includes/models/Blueboard.inc.php" );

	class AdminFeedbackEditPage extends BackendPopup {
		protected $reg_tstamp;
		protected $user_name;
		protected $email;
		protected $pwd;
		protected $contact_phone;
		protected $is_acknowledged;
		protected $is_admin_acknowledged;
		protected $is_instant_sender;

		protected $npublic_comment;

		protected $feedback_submit;

		protected $user_log;

		public function __construct( $id = "AdminFeedbackEditPage" , $parent = null ) {
			parent::__construct( $id , $parent );
			if (!AdminUserModel::isAdminLoggedIn()) return;

			$this->user_comment = new AdminTextarea( "user_comment" , $this );
			$this->score = new AdminNumeric( "score" , $this );
			$this->feedback_submit = new AdminSubmit( "feedback_submit" , $this );
		}

		protected function initializeWidgets() {
			$this->user_comment->setTitle( __("blueboardpage_Comment" ) );
			$this->user_comment->setShowTitle( true );
			$this->user_comment->setWidth( 760 );
			
			$this->score->setTitle( __("blueboardpage_Score" ) );
			$this->score->setWidth( 50 );
			$this->score->setShowTitle( true );
			
			switch ($this->aG["mode"]) {
			case "modify":
				$this->feedback_submit->setValue( __( "Modify","attr" ) );
				$this->setParam( "title" , __("users_Modify_user" ) );
				break;
			case "delete":
				$this->feedback_submit->setValue( __( "Delete","attr" ) );
				$this->setParam( "title" , __("users_Delete_user" ) );
				break;
			}
			FNTHPage::setPageTitle( $this->getParam( "title" ) );
			switch ($this->aG["mode"]) {
			case "modify":
			case "delete":
				$this->loadDatas( $this->aG["uid"] );
			}
		}

		protected function loadDatas( $uid ) {
			$bbm = new BlueboardModel();
			$row = $bbm->getUserCommentDetail( $uid );
			$this->user_comment->setValue( $row["user_comment_detail"] );
			$this->score->setValue( $row["score"] );
		}

		protected function saveDatas( $uid ) {
			$this->refreshChildValuesFromArray();
			$p = array();
			$p["user_comment_detail"]=$this->user_comment->getValue();
			if (strlen( $this->score->getValue() ))
				$p["score"]=$this->score->getValue();

			if (!$uid) return;
			$bbm = new BlueboardModel();
			$bbm->updateUserCommentDetail( $uid , $p );
		}
		
		public function handleEvents() {
			if (!$this->isLoggedIn()) return parent::handleEvents();
			if (!isset( $this->aP[$this->feedback_submit->getId()] )) return parent::handleEvents();
			switch ($this->aG["mode"]) {
			case "new":$this->saveDatas( 0 );break;
			case "modify":$this->saveDatas( $this->aG["uid"] );break;
			case "delete":$this->deleteDatas( $this->aG["uid"] );break;
			}
			$this->closeAndRefreshParent();
		}

		public function render() {
			if (!$this->isLoggedIn()) return parent::render();
			$this->initializeWidgets();
			if (isset( $this->aG["uid"] ))
				$this->setParam( "user_id" , $this->aG["uid"] );
			return parent::render();
		}


	}

?>
