511 lines
19 KiB
PHP
511 lines
19 KiB
PHP
<?php
|
|
/*
|
|
USER_KID osztály
|
|
GYEREKEK osztálya, a USER_PARENT osztályból öröklődik
|
|
*/
|
|
class user_kid extends user_parent {
|
|
private $user_id;
|
|
private $user_name;
|
|
private $user_is_active;
|
|
private $user_balance;
|
|
private $user_last_name;
|
|
private $user_first_name;
|
|
private $user_password;
|
|
private $user_email;
|
|
private $user_last_login;
|
|
private $user_gender;
|
|
private $user_address_scc_id; //SCC ID
|
|
private $user_address; //SCC OBJ
|
|
private $user_birth_date;
|
|
private $user_birth_year;
|
|
private $user_first_training;
|
|
private $user_beforehand;
|
|
private $user_hand;
|
|
private $user_last_modified;
|
|
private $logged_in;
|
|
private $user_type;
|
|
private $user_shirt_size;
|
|
private $user_shirt_note;
|
|
private $user_school_sc_id; //SCHOOL ID
|
|
private $user_school; //SCHOOL OBJ
|
|
private $user_parent_1;
|
|
private $user_parent_2;
|
|
private $user_phone;
|
|
private $user_facebook;
|
|
private $user_region;
|
|
private $user_ago_category;
|
|
private $user_contact;
|
|
private $user_other;
|
|
private $user_deleted;
|
|
|
|
public function set_uk_id($_uid) {
|
|
$this->user_id = $_uid;
|
|
}
|
|
public function set_uk_name($_uname) {
|
|
$this->user_name = $_uname;
|
|
}
|
|
public function set_uk_is_active($_active) {
|
|
$this->user_is_active = $_active;
|
|
}
|
|
public function set_uk_password($_u_pass) {
|
|
$this->user_password = $_u_pass;
|
|
}
|
|
public function set_uk_email($_u_email) {
|
|
$this->user_email = $_u_email;
|
|
}
|
|
public function set_uk_phone($_u_phone) {
|
|
$this->user_phone = $_u_phone;
|
|
}
|
|
public function set_uk_facebook($_facebook) {
|
|
$this->user_facebook = $_facebook;
|
|
}
|
|
public function set_uk_last_login($_u_last_login) {
|
|
$this->user_last_login = $_u_last_login;
|
|
}
|
|
public function set_uk_shirt_size_ss_id($_shirt_size) {
|
|
$this->user_shirt_size = $_shirt_size;
|
|
}
|
|
public function set_uk_shirt_note($_shirt_note) {
|
|
$this->user_shirt_note = $_shirt_note;
|
|
}
|
|
public function set_uk_school_sc_id($_school) {
|
|
$this->user_school_sc_id = $_school;
|
|
}
|
|
public function set_uk_parent_1($_uk_parent_1) {
|
|
$this->user_parent_1 = $_uk_parent_1;
|
|
}
|
|
public function set_uk_parent_2($_uk_parent_2) {
|
|
$this->user_parent_2 = $_uk_parent_2;
|
|
}
|
|
public function set_uk_region_reg_id($_uk_region) {
|
|
$this->user_region = $_uk_region;
|
|
}
|
|
public function set_uk_contact($_uk_contact) {
|
|
$this->user_contact = $_uk_contact;
|
|
}
|
|
public function set_uk_other($_uk_other) {
|
|
$this->user_other = $_uk_other;
|
|
}
|
|
public function set_uk_deleted($_uk_deleted) {
|
|
$this->user_deleted = $_uk_deleted;
|
|
}
|
|
|
|
public function get_uk_id() {
|
|
return $this->user_id;
|
|
}
|
|
public function get_uk_name() {
|
|
return $this->user_name;
|
|
}
|
|
public function get_uk_last_name() {
|
|
return $this->user_last_name;
|
|
}
|
|
public function get_uk_first_name() {
|
|
return $this->user_first_name;
|
|
}
|
|
public function get_uk_password() {
|
|
return $this->user_password;
|
|
}
|
|
public function get_uk_email() {
|
|
return $this->user_email;
|
|
}
|
|
public function get_uk_phone() {
|
|
return $this->user_phone;
|
|
}
|
|
public function get_uk_facebook() {
|
|
return $this->user_facebook;
|
|
}
|
|
public function get_uk_shirt_size() {
|
|
return $this->user_shirt_size;
|
|
}
|
|
public function get_uk_shirt_size_name() {
|
|
global $sql;
|
|
if ($this->user_shirt_size) return $sql->single_variable("select shirt_name from shirt where shirt_id = " . $this->user_shirt_size);
|
|
else return null;
|
|
}
|
|
|
|
public function get_uk_shirt_note() {
|
|
return $this->user_shirt_note;
|
|
}
|
|
public function get_uk_school_sc_id() {
|
|
return $this->user_school_sc_id;
|
|
}
|
|
public function get_uk_school_name() {
|
|
global $sql;
|
|
if ($this->user_school_sc_id) return $sql->single_variable('select sc_name from school where sc_id = ' . $this->user_school_sc_id);
|
|
else return null;
|
|
}
|
|
public function get_uk_school_city() {
|
|
global $sql;
|
|
if ($this->user_school_city_scc_id) return $sql->single_variable('select scc_city from school_city where scc_id = ' . $this->user_school_city_scc_id);
|
|
else return null;
|
|
}
|
|
public function get_uk_parent_1() {
|
|
return $this->user_parent_1;
|
|
}
|
|
public function get_uk_parent_2() {
|
|
return $this->user_parent_2;
|
|
}
|
|
public function get_uk_region_reg_id() {
|
|
return $this->user_region;
|
|
}
|
|
public function get_uk_region_name() {
|
|
global $sql;
|
|
if ($this->user_region) return $sql->single_variable('select reg_name from region where reg_id = ' . $this->user_region);
|
|
else return null;
|
|
}
|
|
public function get_uk_contact() {
|
|
return $this->user_contact;
|
|
}
|
|
public function get_uk_other() {
|
|
return $this->user_other;
|
|
}
|
|
public function get_uk_deleted() {
|
|
return $this->user_deleted;
|
|
}
|
|
|
|
|
|
public function get_uk_presence($_training_id) {
|
|
global $sql;
|
|
return $sql->num_of_rows('select * from presence where pr_user_kid_uk_id = ' . $this->get_uk_id() . ' AND pr_training_tr_id = ' . $_training_id);
|
|
}
|
|
|
|
public function get_uk_presence_on_previous_trainings($_trainigs) {
|
|
//az előző edzések ID-ját kapja paraméterül
|
|
//megadja, hogy hányszor volt a gyerek
|
|
global $sql;
|
|
|
|
return $sql->single_variable("SELECT count(*) FROM presence WHERE pr_training_tr_id IN (" . implode(',', $_trainigs) . ") AND pr_user_kid_uk_id = " . $this->get_uk_id() . ";");
|
|
}
|
|
|
|
public function set_uk_gender($_gender) {
|
|
$this->user_gender = $_gender;
|
|
}
|
|
public function get_uk_gender() {
|
|
return $this->user_gender;
|
|
}
|
|
public function set_uk_birth_date($_birth_date) {
|
|
$this->user_birth_date = $_birth_date;
|
|
}
|
|
public function get_uk_birth_date() {
|
|
return $this->user_birth_date;
|
|
}
|
|
public function set_uk_birth_year($_birth_year) {
|
|
$this->user_birth_year = $_birth_year;
|
|
}
|
|
public function get_uk_birth_year() {
|
|
return $this->user_birth_year;
|
|
}
|
|
public function set_uk_first_training($_first_training) {
|
|
$this->user_first_training = $_first_training;
|
|
}
|
|
public function get_uk_first_training() {
|
|
return $this->user_first_training;
|
|
}
|
|
public function set_uk_hand($_hand) {
|
|
$this->user_hand = $_hand;
|
|
}
|
|
public function get_uk_hand() {
|
|
return $this->user_hand;
|
|
}
|
|
public function set_uk_last_modified($_last_modified) {
|
|
$this->user_last_modified = $_last_modified;
|
|
}
|
|
public function get_uk_last_modified() {
|
|
return $this->user_last_modified;
|
|
}
|
|
public function set_uk_address_scc_id($_address) {
|
|
$this->user_address_scc_id = $_address;
|
|
}
|
|
public function get_uk_address_scc_id() {
|
|
return $this->user_address_scc_id;
|
|
}
|
|
public function set_uk_address($_address) {
|
|
$this->user_address = $_address;
|
|
}
|
|
public function get_uk_address() {
|
|
return $this->user_address;
|
|
}
|
|
public function set_uk_beforehand($_beforehand) {
|
|
$this->user_beforehand = $_beforehand;
|
|
}
|
|
public function get_uk_beforehand() {
|
|
return $this->user_beforehand;
|
|
}
|
|
public function set_uk_age_category($_age_category) {
|
|
$this->user_age_category = $_age_category;
|
|
}
|
|
public function get_uk_age_category() {
|
|
return $this->user_age_category;
|
|
}
|
|
public function set_uk_school($_school) {
|
|
$this->user_school = $_school;
|
|
}
|
|
public function get_uk_school() {
|
|
return $this->user_school;
|
|
}
|
|
public function set_uk_balance($_balance) {
|
|
$this->user_balance = $_balance;
|
|
}
|
|
public function get_uk_balance() {
|
|
return $this->user_balance;
|
|
}
|
|
public function is_logged_in() {
|
|
//leellenőrzi cookie alapján h be vagyunk-e jelentkezve
|
|
//JAVÍTVA: adja vissza az adattag igazságértékét
|
|
return $this->logged_in;
|
|
}
|
|
public function set_login($_login) {
|
|
//bool-t kap paraméterül
|
|
$this->logged_in = $_login;
|
|
}
|
|
|
|
public function get_training_number_in_month($_year, $_month) {
|
|
//évet és hónapot kap paraméterül, az edzések számát adja vissza
|
|
global $sql;
|
|
//var_dump($_date);
|
|
return $sql->single_variable(
|
|
"SELECT count( DISTINCT pr_id )
|
|
FROM `presence`
|
|
JOIN `training` ON `tr_id` = `pr_training_tr_id`
|
|
WHERE `pr_user_kid_uk_id` = ". $this->get_uk_id()."
|
|
AND `tr_date` LIKE '".$_year."-".$_month."%'
|
|
AND tr_deleted = 0
|
|
;"
|
|
);
|
|
}
|
|
|
|
public function update_login_time($_uk_id = null) {
|
|
global $sql;
|
|
//az adott user_id-n updateli a login_time-ot
|
|
$sql->update_table('user_kid', array('uk_last_login' => date('Y-m-d')), array('uk_id' => (empty($_uk_id)?$this->get_uk_id():$_uk_id)));
|
|
}
|
|
|
|
public function set_user_data_by_id($_uk_id) {
|
|
global $sql, $user;
|
|
$user_data_assoc_array = $sql->assoc_array("select * from user_kid where uk_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
|
|
if ($field == 'uk_school_sc_id' && !empty($value)) {
|
|
$school = new school();
|
|
$school->set_school_data_by_id($value);
|
|
$this->set_uk_school($school);
|
|
}
|
|
if ($field == 'uk_address_scc_id' && !empty($value)) {
|
|
$city = new school_city();
|
|
$city->set_school_city_data_by_id($value);
|
|
$this->set_uk_address($city);
|
|
}
|
|
//$this->set_ua_type(2); //kid típus beállítása
|
|
}
|
|
$this->set_login(true);
|
|
}
|
|
public static function add_new_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 create_user($_user_value_array) {
|
|
global $sql;
|
|
//SCHOOL_HANDLER
|
|
if (isset($_user_value_array['add_school']) && $_user_value_array['add_school'] != "") {
|
|
//megnézzük adott-e az iskolához települést, ha nem, akkor null-ra állítjuk
|
|
//if (isset($_user_value_array['uk_school_city_scc_id']) && $_user_value_array['uk_school_city_scc_id'] == '') $_user_value_array['uk_school_city_scc_id'] = 'null';
|
|
//$new_school_id = $sql->insert_into('school', array('sc_name' => $_user_value_array['add_school'], 'sc_school_city_scc_id' => $_user_value_array['uk_school_city_scc_id']));
|
|
$new_school_id = school::create_school($_user_value_array['add_school'], $_user_value_array['uk_school_city_scc_id']);
|
|
log::register('new_school', $new_school_id);
|
|
$_user_value_array['uk_school_sc_id'] = $new_school_id;
|
|
}
|
|
unset($_user_value_array['add_school']);
|
|
unset($_user_value_array['uk_school_city_scc_id']);
|
|
//PARENT_1 HANDLER
|
|
if (isset($_user_value_array['add_parent_1']) && $_user_value_array['add_parent_1'] != "") {
|
|
//lehet, hogy csak a neve van megadva, ezért meg kell vizsgálni, hogy a többi létezik-e; ha nem => null
|
|
//var_dump($_user_value_array);
|
|
//die("hiba");
|
|
$_user_value_array['uk_parent_1'] = self::add_new_parent(
|
|
$_user_value_array['add_parent_1'],
|
|
$_user_value_array['parent_1_email'],
|
|
$_user_value_array['parent_1_facebook'], $_user_value_array['parent_1_phone']);
|
|
log::register('new_parent', $_user_value_array['uk_parent_1']);
|
|
}
|
|
if (isset($_user_value_array['add_parent_1'])) unset($_user_value_array['add_parent_1']);
|
|
if (isset($_user_value_array['parent_1_email'])) unset($_user_value_array['parent_1_email']);
|
|
if (isset($_user_value_array['parent_1_facebook'])) unset($_user_value_array['parent_1_facebook']);
|
|
if (isset($_user_value_array['parent_1_phone'])) unset($_user_value_array['parent_1_phone']);
|
|
//PARENT_2 HANDLER
|
|
if (isset($_user_value_array['add_parent_2']) && $_user_value_array['add_parent_2'] != "") {
|
|
$_user_value_array['uk_parent_2'] = self::add_new_parent(
|
|
$_user_value_array['add_parent_2'],
|
|
$_user_value_array['parent_2_email'], $_user_value_array['parent_2_facebook'],
|
|
$_user_value_array['parent_2_phone']);
|
|
log::register('new_parent', $_user_value_array['uk_parent_2']);
|
|
}
|
|
if (isset($_user_value_array['add_parent_2'])) unset($_user_value_array['add_parent_2']);
|
|
if (isset($_user_value_array['parent_2_email'])) unset($_user_value_array['parent_2_email']);
|
|
if (isset($_user_value_array['parent_2_facebook'])) unset($_user_value_array['parent_2_facebook']);
|
|
if (isset($_user_value_array['parent_2_phone'])) unset($_user_value_array['parent_2_phone']);
|
|
|
|
//date handler
|
|
if (!isset($_user_value_array['uk_first_training']) || $_user_value_array['uk_first_training'] == "") {
|
|
$_user_value_array['uk_first_training'] = 'null';
|
|
}
|
|
if (!isset($_user_value_array['uk_birth_date']) || $_user_value_array['uk_birth_date'] == "") {
|
|
$_user_value_array['uk_birth_date'] = 'null';
|
|
}
|
|
if (!isset($_user_value_array['uk_birth_year']) || $_user_value_array['uk_birth_year'] == "") {
|
|
$_user_value_array['uk_birth_year'] = 'null';
|
|
}
|
|
|
|
foreach ($_user_value_array as $index => $value) {
|
|
if ($value == "") $_user_value_array[$index] = 'null';
|
|
}
|
|
|
|
return $sql->insert_into('user_kid', $_user_value_array);
|
|
}
|
|
public static function update_user($_user_value_array, $_user_id) {
|
|
global $sql;
|
|
//a módosítás dátumát updateljük
|
|
$_user_value_array['uk_last_modified'] = date("Y-m-d");
|
|
//PARENT_1 HANDLER
|
|
if (isset($_user_value_array['add_parent_1']) && $_user_value_array['add_parent_1'] != "") {
|
|
$_user_value_array['uk_parent_1'] = self::add_new_parent(
|
|
$_user_value_array['add_parent_1'],
|
|
$_user_value_array['parent_1_email'],
|
|
$_user_value_array['parent_1_facebook'], $_user_value_array['parent_1_phone']);
|
|
log::register('new_parent', $_user_value_array['uk_parent_1']);
|
|
}
|
|
else {
|
|
//meglévő szülő updatelése
|
|
user_parent::update_parent(array(
|
|
'up_email' => $_user_value_array['parent_1_email'],
|
|
'up_facebook' => $_user_value_array['parent_1_facebook'],
|
|
'up_phone' => $_user_value_array['parent_1_phone']), $_user_value_array['uk_parent_1']);
|
|
|
|
}
|
|
if (isset($_user_value_array['add_parent_1'])) unset($_user_value_array['add_parent_1']);
|
|
if (isset($_user_value_array['parent_1_email'])) unset($_user_value_array['parent_1_email']);
|
|
if (isset($_user_value_array['parent_1_facebook'])) unset($_user_value_array['parent_1_facebook']);
|
|
if (isset($_user_value_array['parent_1_phone'])) unset($_user_value_array['parent_1_phone']);
|
|
//PARENT_2 HANDLER
|
|
if (isset($_user_value_array['add_parent_2']) && $_user_value_array['add_parent_2'] != "") {
|
|
$_user_value_array['uk_parent_2'] = self::add_new_parent(
|
|
$_user_value_array['add_parent_2'],
|
|
$_user_value_array['parent_2_email'], $_user_value_array['parent_2_facebook'],
|
|
$_user_value_array['parent_2_phone']);
|
|
log::register('new_parent', $_user_value_array['uk_parent_2']);
|
|
}
|
|
else {
|
|
//meglévő szülő updatelése
|
|
//var_dump($_user_value_array['uk_parent_2']);
|
|
user_parent::update_parent(array(
|
|
'up_email' => $_user_value_array['parent_2_email'],
|
|
'up_facebook' => $_user_value_array['parent_2_facebook'],
|
|
'up_phone' => $_user_value_array['parent_2_phone']), $_user_value_array['uk_parent_2']);
|
|
|
|
}
|
|
if (isset($_user_value_array['add_parent_2'])) unset($_user_value_array['add_parent_2']);
|
|
if (isset($_user_value_array['parent_2_email'])) unset($_user_value_array['parent_2_email']);
|
|
if (isset($_user_value_array['parent_2_facebook'])) unset($_user_value_array['parent_2_facebook']);
|
|
if (isset($_user_value_array['parent_2_phone'])) unset($_user_value_array['parent_2_phone']);
|
|
|
|
//SCHOOL HANDLER
|
|
if (isset($_user_value_array['add_school']) && $_user_value_array['add_school'] != "") {
|
|
//$new_school_id = $sql->insert_into('school', array('sc_name' => $_user_value_array['add_school'], 'sc_school_city_scc_id' => $_user_value_array['uk_school_city_scc_id']));
|
|
$new_school_id = school::create_school($_user_value_array['add_school'], $_user_value_array['uk_school_city_scc_id']);
|
|
log::register('new_school', $new_school_id);
|
|
$_user_value_array['uk_school_sc_id'] = $new_school_id;
|
|
}
|
|
|
|
unset($_user_value_array['add_school']);
|
|
unset($_user_value_array['uk_school_city_scc_id']);
|
|
|
|
//date handler
|
|
if (!isset($_user_value_array['uk_first_training']) || $_user_value_array['uk_first_training'] == "") {
|
|
$_user_value_array['uk_first_training'] = 'null';
|
|
}
|
|
if (!isset($_user_value_array['uk_birth_date']) || $_user_value_array['uk_birth_date'] == "") {
|
|
$_user_value_array['uk_birth_date'] = 'null';
|
|
}
|
|
if (!isset($_user_value_array['uk_birth_year']) || $_user_value_array['uk_birth_year'] == "") {
|
|
$_user_value_array['uk_birth_year'] = 'null';
|
|
}
|
|
|
|
foreach ($_user_value_array as $index => $value) {
|
|
if ($value == "") $_user_value_array[$index] = 'null';
|
|
}
|
|
|
|
//ha nincs bejelölve h aktív akkor nem kapja meg ezt az értéket, manuálisan kell beállítani
|
|
if (!isset($_user_value_array['uk_is_active'])) $_user_value_array['uk_is_active'] = 0;
|
|
$sql->update_table('user_kid', $_user_value_array, array('uk_id' => $_user_id));
|
|
}
|
|
|
|
public function calculate_balance(&$_de_obj_array, $_user_obj = null) {
|
|
//kiszámolja az egyenleget a diary entry-k alapján, amik tömbben érkeznek
|
|
//a tömbben feltölti a pénzmozgást, és minden lépésben befrissíti az egyenleget
|
|
//az update-elt tömböt adja vissza
|
|
//ha user_obj null, akkor az aktuális usernél állítja be
|
|
global $sql;
|
|
|
|
//kezdetben 0
|
|
$balance = 0;
|
|
foreach ($_de_obj_array as $i => $_de) {
|
|
//minden lépésben az balance-t be kell állítani az előző lépésben updatelt balance-ra
|
|
if (isset($_de_obj_array[$i-1])) {
|
|
$_de->set_de_balance($_de_obj_array[$i-1]->get_de_balance());
|
|
}
|
|
if ($_de->get_de_type() == 'training') {
|
|
//ha edzés, akkor -1000 levonás, kivéve, ha kedvezményes:
|
|
//1-nél több edzés / nap
|
|
//8-nál több edzés / hónap
|
|
//első két alkalom egyike
|
|
//var_dump($_de);
|
|
//echo $_de->get_de_first_two() . '<br>';
|
|
//echo $_de->get_de_training_per_month() . '<br>';
|
|
//echo $_de->get_de_training_per_day() . '<br><br><br>';
|
|
if ($_de->get_de_first_two() > 0 || $_de->get_de_training_per_month() > 8 || $_de->get_de_training_per_day() > 1) {
|
|
//do nothing
|
|
$_de->set_de_transaction(0);
|
|
$_de->set_de_has_discount(true);
|
|
//TODO: ha van már havi 8+ akk ne nézze a duplázót!
|
|
if ($_de->get_de_first_two() > 0) $_de->set_de_discount_id(1);
|
|
if ($_de->get_de_training_per_day() > 1) $_de->set_de_discount_id(3);
|
|
if ($_de->get_de_training_per_month() > 8) $_de->set_de_discount_id(2);
|
|
}
|
|
else {
|
|
//$balance -= 1000;
|
|
$_de->set_de_transaction(-1000); //beállítjuk, mennyivel csökken az egyenleg
|
|
$_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction()); //beállítjuk az új egyenleget
|
|
//echo $_de->get_de_date() . " minusz 1000<br><br>";
|
|
}
|
|
}
|
|
elseif ($_de->get_de_type() == 'money_deposit') {
|
|
$_de->set_de_transaction($_de->get_de_money_deposit()->get_mod_sum());
|
|
$_de->set_de_balance($_de->get_de_balance()+$_de->get_de_transaction());
|
|
//$balance += $_de->get_de_money_deposit()->get_mod_sum();
|
|
//echo $_de->get_de_date() . " plussz " . $_de->get_de_money_deposit()->get_mod_sum() . "<br><br>";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sql->update_table('user_kid', (array('uk_balance' => $_de->get_de_balance())), array('uk_id' => (is_object($_user_obj)?$_user_obj->get_uk_id():$this->get_uk_id())), false);
|
|
|
|
return $_de_obj_array;
|
|
}
|
|
}
|
|
?>
|