442 lines
12 KiB
PHP
442 lines
12 KiB
PHP
<?php
|
|
|
|
/**
|
|
* MILESTONE
|
|
*/
|
|
class milestone
|
|
{
|
|
private $ms_id;
|
|
private $ms_type_mt_id;
|
|
private $ms_training_mst_id = null;
|
|
private $ms_competition_msc_id = null;
|
|
private $ms_camp_msca_id = null;
|
|
private $ms_ranking_msr_id = null;
|
|
private $ms_user_kid_uk_id;
|
|
private $ms_sums; //text
|
|
|
|
private $season;
|
|
|
|
public function set_ms_data_by_id($_ms_id) {
|
|
global $sql;
|
|
$cat_assoc_array = $sql->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);
|
|
|
|
if ($field == 'ms_type_mt_id' && $value != null) {
|
|
$new_mt = new milestone_type();
|
|
$new_mt->set_mt_data_by_id($value);
|
|
$this->set_ms_type_mt_id($new_mt);
|
|
}
|
|
|
|
if ($field == 'ms_training_mst_id' && $value != null) {
|
|
$new_mst = new milestone_training();
|
|
$new_mst->set_mst_data_by_id($value);
|
|
$this->set_ms_training_mst_id($new_mst);
|
|
}
|
|
|
|
if ($field == 'ms_competition_msc_id' && $value != null) {
|
|
$new_msc = new milestone_competition();
|
|
$new_msc->set_msc_data_by_id($value);
|
|
$this->set_ms_competition_msc_id($new_msc);
|
|
}
|
|
|
|
if ($field == 'ms_camp_msca_id' && $value != null) {
|
|
$new_msca = new milestone_camp();
|
|
$new_msca->set_msca_data_by_id($value);
|
|
$this->set_ms_camp_msca_id($new_msca);
|
|
}
|
|
|
|
if ($field == 'ms_ranking_msr_id' && $value != null) {
|
|
$new_msr = new milestone_ranking();
|
|
$new_msr->set_msr_data_by_id($value);
|
|
$this->set_ms_ranking_msr_id($new_msr);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function create_ms($_mt, $_season, $_uk, $_mst = null, $_msc = null, $_msca = null, $_msr = null, $_sums = 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_ranking_msr_id' => $_msr,
|
|
'ms_camp_msca_id' => $_msca,
|
|
'ms_user_kid_uk_id' => $_uk,
|
|
'ms_season' => $_season,
|
|
'ms_sums' => $_sums,
|
|
), false);
|
|
}
|
|
|
|
public function get_ms_month() {
|
|
if (null !== $this->ms_competition_msc_id) {
|
|
return $this->ms_competition_msc_id->get_msc_month();
|
|
}
|
|
elseif (null !== $this->ms_training_mst_id) {
|
|
return $this->ms_training_mst_id->get_mst_month();
|
|
}
|
|
elseif (null !== $this->ms_camp_msca_id) {
|
|
return $this->ms_camp_msca_id->get_msca_month();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @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_season()
|
|
{
|
|
return $this->ms_season;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $ms_season
|
|
*
|
|
* @return self
|
|
*/
|
|
public function set_ms_season($ms_season)
|
|
{
|
|
$this->ms_season = $ms_season;
|
|
|
|
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_ranking_msr_id()
|
|
{
|
|
return $this->ms_ranking_msr_id;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $ms_ranking_msr_id
|
|
*
|
|
* @return self
|
|
*/
|
|
public function set_ms_ranking_msr_id($ms_ranking_msr_id)
|
|
{
|
|
$this->ms_ranking_msr_id = $ms_ranking_msr_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;
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function get_ms_sums()
|
|
{
|
|
return $this->ms_sums;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $ms_sums
|
|
*
|
|
* @return self
|
|
*/
|
|
public function set_ms_sums($ms_sums)
|
|
{
|
|
$this->ms_sums = $ms_sums;
|
|
|
|
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);
|
|
$sql->execute_query('DELETE milestone_ranking FROM milestone_ranking JOIN milestone ON ms_ranking_msr_id= msr_id WHERE ms_user_kid_uk_id = ' . $kid);
|
|
|
|
$content = file($_FILES['fileToUpload']['tmp_name']); //makes array
|
|
|
|
|
|
for ($i=0; $i < count($content); $i++) {
|
|
$line = $content[$i];
|
|
//var_dump($line);
|
|
if ($i === 0 || empty(trim($line))) { //ha üres sor volt
|
|
if (empty(trim($line))) {
|
|
++$i;
|
|
}
|
|
if (empty(trim($content[$i]))) {
|
|
//a következő sor is üres, átugroható
|
|
continue;
|
|
}
|
|
$firstLineParts = explode(' ', trim($content[$i]));
|
|
|
|
$typeLetter = $firstLineParts[0];
|
|
//$month = $firstLineParts[1] . '-01';
|
|
|
|
//$ms = new milestone();
|
|
$mst_id = 'null';
|
|
$msc_id = 'null';
|
|
$msca_id = 'null';
|
|
$msr_id = 'null';
|
|
$actual_season = 'null';
|
|
|
|
if ('s' == $typeLetter) {
|
|
$season = $firstLineParts[1];
|
|
$sums = "";
|
|
$j = $i + 1;
|
|
while(isset($content[$j]) && !empty(trim($content[$j]))) {
|
|
$sums .= trim($content[$j]) . '\n';
|
|
++$i;
|
|
$j = $i + 1;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
$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, $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]) . '\n';
|
|
++$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, $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);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
# ranking
|
|
|
|
//get season after 'r'
|
|
$msr_season = trim(substr($content[$i], 2));
|
|
|
|
++$i;
|
|
$msr_date = trim($content[$i]);
|
|
|
|
++$i;
|
|
$rankings = '';
|
|
do {
|
|
$rankings .= trim($content[$i]) . '\n';
|
|
++$i;
|
|
} while (isset($content[$i]) && !empty(trim($content[$i])));
|
|
|
|
$msr_id = milestone_ranking::create_msr($msr_date, $rankings, $msr_season);
|
|
|
|
break;
|
|
|
|
default:
|
|
# code...
|
|
break;
|
|
}
|
|
|
|
if (null !== $type) {
|
|
self::create_ms($type, $season, $kid, $mst_id, $msc_id, $msca_id, $msr_id, $sums);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
?>
|