<?php

/*
	USER_PARENT osztály
	SZÜLŐK osztálya



*/

class user_parent {

	private $up_id;
	private $up_name;
	private $up_password;
	private $up_last_login;
	private $up_email;
	private $up_phone;
	private $up_facebook;
	private $up_deleted;
	private $logged_in;


	public function set_up_id($_id) {
		$this->up_id = $_id;
	}

	public function set_up_name($_name) {
		$this->up_name = $_name;
	}

	public function set_up_password($_password) {
		$this->up_password = $_password;
	}

	public function set_up_last_login($_last_login) {
		$this->up_last_login = $_last_login;
	}

	public function set_up_email($_email) {
		$this->up_email = $_email;
	}

	public function set_up_phone($_phone) {
		$this->up_phone = $_phone;
	}

	public function set_up_facebook($_facebook) {
		$this->up_facebook = $_facebook;
	}

	public function set_up_deleted($_deleted) {
		$this->up_deleted = $_deleted;
	}

	public function get_up_id() {
		return $this->up_id;
	}

	public function get_up_name() {
		return $this->up_name;
	}

	public function get_up_password() {
		return $this->up_password;
	}

	public function get_up_last_login() {
		return $this->up_last_login;
	}

	public function get_up_email() {
		return $this->up_email;
	}

	public function get_up_phone() {
		return $this->up_phone;
	}

	public function get_up_facebook() {
		return $this->up_facebook;
	}

	public function get_up_deleted() {
		return $this->up_deleted;
	}



	public function set_login($_login) {
		//bool-t kap paraméterül
		$this->logged_in = $_login;
	}

	public function set_user_data_by_id($_uk_id) {
		global $sql, $user;
		$user_data_assoc_array = $sql->assoc_array("select * from user_parent where up_id = " . $_uk_id);
		$user_data_array = $user_data_assoc_array[0];
		foreach ($user_data_array as $field => $value) {
			$function_name = "set_" . $field;
			$this->$function_name($value); //alapadatok beállítása
			$this->set_login(true);
			//$this->set_ua_type(3); //parent típus beállítása
		}

	}

	public static function create_parent($_parent_name, $_email, $_facebook, $_phone) {
		global $sql;
		//beilleszti AB-ba
		//visszaadja az ID-t

		if ($_email == '') $_email = 'null'; 
		if ($_facebook == '') $_facebook = 'null'; 
		if ($_phone == '') $_phone = 'null'; 
		
		return $sql->insert_into('user_parent', 
			array(
				'up_name' => $_parent_name,
				'up_email' => $_email,
				'up_facebook' => $_facebook,
				'up_phone' => $_phone
				)
		);
	}

	public static function update_parent($_parent_value_array, $_up_id) {
		global $sql;
		foreach ($_parent_value_array as $index => $value) {
			if ($value == '') $_parent_value_array[$index] = 'null';
		}
		$sql->update_table('user_parent', $_parent_value_array, array('up_id' => $_up_id));
	}
}


?>