diff --git a/_class/class_milestone.php b/_class/class_milestone.php new file mode 100644 index 0000000..0e7ac02 --- /dev/null +++ b/_class/class_milestone.php @@ -0,0 +1,295 @@ +assoc_array("select * from milestone where ms_id = " . $_ms_id); + $cat_array = $cat_assoc_array[0]; + //alapadatok + foreach ($cat_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + + //todo: egyéb objektumok + } + + public static function create_ms($_mt, $_uk, $_mst = null, $_msc = null, $_msca = null) + { + global $sql; + return $sql->insert_into('milestone', array( + 'ms_type_mt_id' => $_mt, + 'ms_training_mst_id' => $_mst, + 'ms_competition_msc_id' => $_msc, + 'ms_camp_msca_id' => $_msca, + 'ms_user_kid_uk_id' => $_uk, + ), false); + } + + + + /** + * @return mixed + */ + public function get_ms_id() + { + return $this->ms_id; + } + + /** + * @param mixed $ms_id + * + * @return self + */ + public function set_ms_id($ms_id) + { + $this->ms_id = $ms_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_ms_type_mt_id() + { + return $this->ms_type_mt_id; + } + + /** + * @param mixed $ms_type_mt_id + * + * @return self + */ + public function set_ms_type_mt_id($ms_type_mt_id) + { + $this->ms_type_mt_id = $ms_type_mt_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_ms_training_mst_id() + { + return $this->ms_training_mst_id; + } + + /** + * @param mixed $ms_training_mst_id + * + * @return self + */ + public function set_ms_training_mst_id($ms_training_mst_id) + { + $this->ms_training_mst_id = $ms_training_mst_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_ms_competition_msc_id() + { + return $this->ms_competition_msc_id; + } + + /** + * @param mixed $ms_competition_msc_id + * + * @return self + */ + public function set_ms_competition_msc_id($ms_competition_msc_id) + { + $this->ms_competition_msc_id = $ms_competition_msc_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_ms_camp_msca_id() + { + return $this->ms_camp_msca_id; + } + + /** + * @param mixed $ms_camp_msca_id + * + * @return self + */ + public function set_ms_camp_msca_id($ms_camp_msca_id) + { + $this->ms_camp_msca_id = $ms_camp_msca_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_ms_user_kid_uk_id() + { + return $this->ms_user_kid_uk_id; + } + + /** + * @param mixed $ms_user_kid_uk_id + * + * @return self + */ + public function set_ms_user_kid_uk_id($ms_user_kid_uk_id) + { + $this->ms_user_kid_uk_id = $ms_user_kid_uk_id; + + return $this; + } + + public static function upload_file($file) + { + global $sql; + + + $nameToSearch = trim(substr($_FILES['fileToUpload']['name'],0,-4)); + + $kid = $sql->single_variable('SELECT uk_id FROM user_kid WHERE uk_name = "' . $nameToSearch . '";'); + + if (!$kid) { + return 1; //nem talalhato gyerek + } + + $sql->execute_query('DELETE milestone_training FROM milestone_training JOIN milestone ON ms_training_mst_id = mst_id WHERE ms_user_kid_uk_id = ' . $kid); + $sql->execute_query('DELETE milestone_competition FROM milestone_competition JOIN milestone ON ms_competition_msc_id = msc_id WHERE ms_user_kid_uk_id = ' . $kid); + $sql->execute_query('DELETE milestone_camp FROM milestone_camp JOIN milestone ON ms_camp_msca_id= msca_id WHERE ms_user_kid_uk_id = ' . $kid); + + $content = file($_FILES['fileToUpload']['tmp_name']); //makes array + //var_dump($content); + + for ($i=0; $i < count($content); $i++) { + $line = $content[$i]; + + if (empty(trim($line))) { //ha üres sor volt + if (empty(trim($content[$i+1]))) { + //a következő sor is üres, átugroható + continue; + } + $firstLineParts = explode(' ', trim($content[$i+1])); + $typeLetter = $firstLineParts[0]; + $month = $firstLineParts[1] . '-01'; + ++$i; + + //$ms = new milestone(); + $mst_id = 'null'; + $msc_id = 'null'; + $msca_id = 'null'; + $type = $sql->single_variable('SELECT mt_id FROM milestone_type WHERE mt_short_name = "' . $typeLetter . '";'); + + if (null === $type) { + //érvénytelen típus + return 2; + } + + switch ($typeLetter) { + case 'e': + # training + ++$i; + $mst_date = trim($content[$i]); + + ++$i; + $mst_count = trim($content[$i]); + + $j = $i + 1; + $mst_trainings = ""; + while(isset($content[$j]) && !empty(trim($content[$j]))) { + $mst_trainings .= trim($content[$j]) . '\n'; + ++$i; + $j = $i + 1; + } + + $mst_id = milestone_training::create_mst($mst_date, $mst_count, $month, $mst_trainings); + //var_dump($mst_trainings); + + break; + case 'v': + # competition + ++$i; + $msc_date = trim($content[$i]); + + ++$i; + $msc_name = trim($content[$i]); + + ++$i; + $msc_location = trim($content[$i]); + + ++$i; + $msc_category = trim($content[$i]); + + + ++$i; + $msc_place = trim($content[$i]); + + ++$i; + if (isset($content[$i]) && !empty(trim($content[$i]))) { + ++$i; //mérkőzések szöveg + $matches = ''; + do { + $matches .= trim($content[$i]); + ++$i; + } while (isset($content[$i]) && !empty(trim($content[$i]))); + } + else { + $matches = 'null'; + } + + $msc_id = milestone_competition::create_msc($msc_date, $msc_name, $msc_category, $msc_location, $msc_place, $month, $matches); + + break; + case 't': + # camp + + ++$i; + $msca_date = trim($content[$i]); + + ++$i; + $msca_place = trim($content[$i]); + + $msca_id = milestone_camp::create_msca($msca_date, $msca_place, $month); + + break; + + default: + # code... + break; + } + + if (null !== $type) { + self::create_ms($type, $kid, $mst_id, $msc_id, $msca_id); + } + } + } + + + + + return 0; + + + } +} + + +?> diff --git a/_class/class_milestone_camp.php b/_class/class_milestone_camp.php new file mode 100644 index 0000000..0da2106 --- /dev/null +++ b/_class/class_milestone_camp.php @@ -0,0 +1,118 @@ +assoc_array("select * from milestone_camp where msc_id = " . $_msca_id); + $cat_array = $cat_assoc_array[0]; + //alapadatok + foreach ($cat_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + } + + public static function create_msca($_date, $_place, $_month) + { + global $sql; + return $sql->insert_into('milestone_camp', array( + 'msca_date' => $_date, + 'msca_place' => $_place, + 'msca_month' => $_month, + )); + } + + + /** + * @return mixed + */ + public function get_msca_id() + { + return $this->msca_id; + } + + /** + * @param mixed $msca_id + * + * @return self + */ + public function set_msca_id($msca_id) + { + $this->msca_id = $msca_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_msca_date() + { + return $this->msca_date; + } + + /** + * @param mixed $msca_date + * + * @return self + */ + public function set_msca_date($msca_date) + { + $this->msca_date = $msca_date; + + return $this; + } + + /** + * @return mixed + */ + public function get_msca_place() + { + return $this->msca_place; + } + + /** + * @param mixed $msca_place + * + * @return self + */ + public function set_msca_place($msca_place) + { + $this->msca_place = $msca_place; + + return $this; + } + + /** + * @return mixed + */ + public function get_msca_month() + { + return $this->msca_month; + } + + /** + * @param mixed $msca_month + * + * @return self + */ + public function set_msca_month($msca_month) + { + $this->msca_month = $msca_month; + + return $this; + } +} + + +?> diff --git a/_class/class_milestone_competition.php b/_class/class_milestone_competition.php new file mode 100644 index 0000000..bc3cd91 --- /dev/null +++ b/_class/class_milestone_competition.php @@ -0,0 +1,206 @@ +assoc_array("select * from milestone_competition where msc_id = " . $_msc_id); + $cat_array = $cat_assoc_array[0]; + //alapadatok + foreach ($cat_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + } + + public static function create_msc($_date, $_name, $_category, $_location, $_place, $_month, $_matches = NULL) + { + global $sql; + return $sql->insert_into('milestone_competition', array( + 'msc_date' => $_date, + 'msc_name' => $_name, + 'msc_category' => $_category, + 'msc_location' => $_location, + 'msc_place' => $_place, + 'msc_month' => $_month, + 'msc_matches' => $_matches, + )); + } + + /** + * @return mixed + */ + public function get_msc_id() + { + return $this->msc_id; + } + + /** + * @param mixed $msc_id + * + * @return self + */ + public function set_msc_id($msc_id) + { + $this->msc_id = $msc_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_date() + { + return $this->msc_date; + } + + /** + * @param mixed $msc_date + * + * @return self + */ + public function set_msc_date($msc_date) + { + $this->msc_date = $msc_date; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_name() + { + return $this->msc_name; + } + + /** + * @param mixed $msc_name + * + * @return self + */ + public function set_msc_name($msc_name) + { + $this->msc_name = $msc_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_category() + { + return $this->msc_category; + } + + /** + * @param mixed $msc_category + * + * @return self + */ + public function set_msc_category($msc_category) + { + $this->msc_category = $msc_category; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_place() + { + return $this->msc_place; + } + + /** + * @param mixed $msc_place + * + * @return self + */ + public function set_msc_place($msc_place) + { + $this->msc_place = $msc_place; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_matches() + { + return $this->msc_matches; + } + + /** + * @param mixed $msc_matches + * + * @return self + */ + public function set_msc_matches($msc_matches) + { + $this->msc_matches = $msc_matches; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_month() + { + return $this->msc_month; + } + + /** + * @param mixed $msc_month + * + * @return self + */ + public function set_msc_month($msc_month) + { + $this->msc_month = $msc_month; + + return $this; + } + + /** + * @return mixed + */ + public function get_msc_location() + { + return $this->msc_location; + } + + /** + * @param mixed $msc_location + * + * @return self + */ + public function set_msc_location($msc_location) + { + $this->msc_location = $msc_location; + + return $this; + } +} + + +?> diff --git a/_class/class_milestone_training.php b/_class/class_milestone_training.php new file mode 100644 index 0000000..4bc1573 --- /dev/null +++ b/_class/class_milestone_training.php @@ -0,0 +1,140 @@ +assoc_array("select * from milestone_training where mst_id = " . $_mst_id); + $cat_array = $cat_assoc_array[0]; + //alapadatok + foreach ($cat_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + } + + public static function create_mst($_date, $_count, $_month, $_trainings = NULL) + { + global $sql; + return $sql->insert_into('milestone_training', array( + 'mst_date' => $_date, + 'mst_count' => $_count, + 'mst_month' => $_month, + 'mst_trainings' => $_trainings, + )); + } + + + /** + * @return mixed + */ + public function get_mst_id() + { + return $this->mst_id; + } + + /** + * @param mixed $mst_id + * + * @return self + */ + public function set_mst_id($mst_id) + { + $this->mst_id = $mst_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_mst_date() + { + return $this->mst_date; + } + + /** + * @param mixed $mst_date + * + * @return self + */ + public function set_mst_date($mst_date) + { + $this->mst_date = $mst_date; + + return $this; + } + + /** + * @return mixed + */ + public function get_mst_count() + { + return $this->mst_count; + } + + /** + * @param mixed $mst_count + * + * @return self + */ + public function set_mst_count($mst_count) + { + $this->mst_count = $mst_count; + + return $this; + } + + /** + * @return mixed + */ + public function get_mst_trainings() + { + return $this->mst_trainings; + } + + /** + * @param mixed $mst_trainings + * + * @return self + */ + public function set_mst_trainings($mst_trainings) + { + $this->mst_trainings = $mst_trainings; + + return $this; + } + + /** + * @return mixed + */ + public function get_mst_month() + { + return $this->mst_month; + } + + /** + * @param mixed $mst_month + * + * @return self + */ + public function set_mst_month($mst_month) + { + $this->mst_month = $mst_month; + + return $this; + } +} + + +?> diff --git a/_class/class_milestone_type.php b/_class/class_milestone_type.php new file mode 100644 index 0000000..565b0f0 --- /dev/null +++ b/_class/class_milestone_type.php @@ -0,0 +1,86 @@ +assoc_array("select * from milestone_type where mt_id = " . $_mt_id); + $cat_array = $cat_assoc_array[0]; + //alapadatok + foreach ($cat_array as $field => $value) { + $function_name = "set_" . $field; + $this->$function_name($value); + } + + } + + /** + * @return mixed + */ + public function get_mt_id() + { + return $this->mt_id; + } + + /** + * @param mixed $mt_id + * + * @return self + */ + public function set_mt_id($mt_id) + { + $this->mt_id = $mt_id; + + return $this; + } + + /** + * @return mixed + */ + public function get_mt_name() + { + return $this->mt_name; + } + + /** + * @param mixed $mt_name + * + * @return self + */ + public function set_mt_name($mt_name) + { + $this->mt_name = $mt_name; + + return $this; + } + + /** + * @return mixed + */ + public function get_mt_short_name() + { + return $this->mt_short_name; + } + + /** + * @param mixed $mt_short_name + * + * @return self + */ + public function set_mt_short_name($mt_short_name) + { + $this->mt_short_name = $mt_short_name; + + return $this; + } +} + + +?> diff --git a/_class/class_page.php b/_class/class_page.php index e799ba5..f0148ff 100644 --- a/_class/class_page.php +++ b/_class/class_page.php @@ -231,6 +231,10 @@ class page { # csoportok include('include_user_groups.php'); break; + case 'milestones': + # csoportok + include('include_milestones.php'); + break; case 'delete_training_type': # EDZÉS TÍPUS TÖRLÉS include('include_delete_training_type.php'); diff --git a/_include/include_milestones.php b/_include/include_milestones.php new file mode 100644 index 0000000..47dce3e --- /dev/null +++ b/_include/include_milestones.php @@ -0,0 +1,32 @@ +is_id()) { + switch ($this->get_id()) { + case '1': + $smarty->assign('error', 'Nem található a fájlnévvel egyező gyerek a rendszerben!'); + break; + case '2': + $smarty->assign('error', 'Ismeretlen esemény típus'); + break; + case 'success': + # code... + $smarty->assign('success', 'Sikeres feltöltés!'); + break; + + default: + # code... + break; + } + +} + +else { + # PROFIL FELTÖLTÉS +} + +$smarty->display('upload_milestone.tpl'); + +?> diff --git a/event_handler.php b/event_handler.php index 0959625..9c3adb9 100644 --- a/event_handler.php +++ b/event_handler.php @@ -556,6 +556,15 @@ if (isset($_POST['action'])) { log::register('update_user_group', $_POST['ug_id']); header('Location: /admin/user_groups/'.$_POST['ug_id']); break; + case 'upload_milestone': + $statusCode = milestone::upload_file($_FILES['fileToUpload']); + if (0 !== $statusCode) { + header('Location: /admin/milestones/'.$statusCode); + } + else { + header('Location: /admin/milestones/success'); + } + break; default: # code... break; diff --git a/template/templates/upload_milestone.tpl b/template/templates/upload_milestone.tpl new file mode 100644 index 0000000..a49a20b --- /dev/null +++ b/template/templates/upload_milestone.tpl @@ -0,0 +1,25 @@ +
+ {$error} +
+ {/if} + + {if !isset($success)} + + {else} +{$success}
+ Vissza + {/if} +