[admin] profile can be uploaded
This commit is contained in:
295
_class/class_milestone.php
Normal file
295
_class/class_milestone.php
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MILESTONE
|
||||
*/
|
||||
class milestone
|
||||
{
|
||||
private $ms_id;
|
||||
private $ms_type_mt_id;
|
||||
private $ms_training_mst_id;
|
||||
private $ms_competition_msc_id;
|
||||
private $ms_camp_msca_id;
|
||||
private $ms_user_kid_uk_id;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user