[admin] profile can be uploaded

This commit is contained in:
Tóth Richárd
2018-06-07 23:32:06 +02:00
parent a88c0df0d2
commit f98f1fe6e2
10 changed files with 918 additions and 2 deletions

295
_class/class_milestone.php Normal file
View 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;
}
}
?>

View File

@@ -0,0 +1,118 @@
<?php
/**
* MILESTONE COMPETITION
*/
class milestone_camp
{
private $msca_id;
private $msca_date;
private $msca_place;
private $msca_month;
public function set_msca_data_by_id($_msca_id) {
global $sql;
$cat_assoc_array = $sql->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;
}
}
?>

View File

@@ -0,0 +1,206 @@
<?php
/**
* MILESTONE COMPETITION
*/
class milestone_competition
{
private $msc_id;
private $msc_date;
private $msc_name;
private $msc_category;
private $msc_place;
private $msc_location;
private $msc_month;
private $msc_matches = null;
public function set_msc_data_by_id($_msc_id) {
global $sql;
$cat_assoc_array = $sql->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;
}
}
?>

View File

@@ -0,0 +1,140 @@
<?php
/**
* MILESTONE TRAINING
*/
class milestone_training
{
private $mst_id;
private $mst_date;
private $mst_count;
private $mst_month;
private $mst_trainings = null;
public function set_mst_data_by_id($_mst_id) {
global $sql;
$cat_assoc_array = $sql->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;
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* MILESTONE TYPE
*/
class milestone_type
{
private $mt_id;
private $mt_name;
private $mt_short_name;
public function set_mt_data_by_id($_mt_id) {
global $sql;
$cat_assoc_array = $sql->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;
}
}
?>

View File

@@ -231,6 +231,10 @@ class page {
# csoportok # csoportok
include('include_user_groups.php'); include('include_user_groups.php');
break; break;
case 'milestones':
# csoportok
include('include_milestones.php');
break;
case 'delete_training_type': case 'delete_training_type':
# EDZÉS TÍPUS TÖRLÉS # EDZÉS TÍPUS TÖRLÉS
include('include_delete_training_type.php'); include('include_delete_training_type.php');

View File

@@ -0,0 +1,32 @@
<?php
# HA VAN ID, AKKOR PROFIL FELTÖLTÉS
if ($this->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');
?>

View File

@@ -556,6 +556,15 @@ if (isset($_POST['action'])) {
log::register('update_user_group', $_POST['ug_id']); log::register('update_user_group', $_POST['ug_id']);
header('Location: /admin/user_groups/'.$_POST['ug_id']); header('Location: /admin/user_groups/'.$_POST['ug_id']);
break; 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: default:
# code... # code...
break; break;

View File

@@ -0,0 +1,25 @@
<div class="form_wrapper">
{if isset($error)}
<p class="error_msg">
{$error}
</p>
{/if}
{if !isset($success)}
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="upload_milestone">
<div>
<label for="fileToUpload">Fájl:</label>
<div><input type="file" name="fileToUpload" id="fileToUpload"></div>
</div>
<div>
<div style="float: left;">
<input class="button black" type="submit" value="Feltöltés">
</div>
</div>
</form>
{else}
<p class="success_msg">{$success}</p>
<a href="/admin/milestones">Vissza</a>
{/if}
</div>

View File

@@ -6,6 +6,7 @@
<a href="/admin/schools" class="addbutton add-big">Iskolák</a> <a href="/admin/schools" class="addbutton add-big">Iskolák</a>
<a href="/admin/regions" class="addbutton add-big">Diákolimpia körzetek</a> <a href="/admin/regions" class="addbutton add-big">Diákolimpia körzetek</a>
<a href="/admin/user_groups" class="addbutton add-big">Csoportok</a> <a href="/admin/user_groups" class="addbutton add-big">Csoportok</a>
<a href="/admin/milestones" class="addbutton add-big">Játékos profil feltöltése</a>
</div> </div>