Skip to content

Commit

Permalink
#8 - Gameaccounts can be active automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schulz committed Dec 18, 2018
1 parent 007127b commit 156481f
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 50 deletions.
83 changes: 54 additions & 29 deletions admin/games.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,32 @@

$status = FALSE;

$name = getinput($_POST[ "name" ]);
$short = getinput($_POST[ "short" ]);
$tag = getinput($_POST[ "tag" ]);
$name = getinput($_POST[ "name" ]);
$short = getinput($_POST[ "short" ]);
$tag = getinput($_POST[ "tag" ]);

$cup_auto_active = (isset($_POST[ "cup_auto_active" ]) && ($_POST[ "cup_auto_active" ] == '1')) ?
1 : 0;

if (!checkforempty(array('name', 'short', 'tag'))) {
throw new \Exception($_language->module['fill_correctly']);
}

if(isset($_POST[ 'save' ])) {
if (isset($_POST[ 'save' ])) {

$saveQuery = mysqli_query(
$_database,
"INSERT INTO `" . PREFIX . "games`
(
name,
short,
tag
`name`,
`short`,
`tag`,
`cup_auto_active`
) VALUES (
'" . $name . "',
'" . $short . "',
'" . $tag ."'
'" . $tag ."',
" . $cup_auto_active . "
)"
);

Expand All @@ -61,9 +66,10 @@
$saveQuery = mysqli_query(
$_database,
"UPDATE `" . PREFIX . "games`
SET `name` = '" . $name . "',
SET `name` = '" . $name . "',
`tag` = '" . $tag ."',
`short` = '" . $short . "'
`short` = '" . $short . "',
`cup_auto_active` = " . $cup_auto_active . "
WHERE `gameID` = " . $game_id
);

Expand Down Expand Up @@ -140,26 +146,38 @@
$ds = mysqli_fetch_array(
mysqli_query(
$_database,
"SELECT
`name`,
`tag`
FROM `" . PREFIX . "games`
"SELECT
`name`,
`tag`
FROM `" . PREFIX . "games`
WHERE `gameID` = " . $game_id
)
);

$saveQuery = mysqli_query(
$game_tag = $ds['tag'];

$deleteQuery = mysqli_query(
$_database,
"DELETE FROM " . PREFIX . "games
"DELETE FROM `" . PREFIX . "games`
WHERE `gameID` = " . $game_id
);

if (file_exists($filepath.$ds['tag'].".gif")) {
unlink($filepath.$ds['tag'].".gif");
if (file_exists($filepath . $game_tag . ".gif")) {
unlink($filepath . $game_tag . ".gif");
}

if (!$saveQuery) {
throw new \Exception($_language->module['query_delete_failed']);
if (!$deleteQuery) {
throw new \Exception($_language->module['query_delete_failed'] . ' (`games`)');
}

$deleteQuery = mysqli_query(
$_database,
"DELETE FROM `" . PREFIX . "cups_gameaccounts`
WHERE `category` = '" . $game_tag . "'"
);

if (!$deleteQuery) {
throw new \Exception($_language->module['query_delete_failed'] . ' (`cups_gameaccounts`)');
}

header("Location: admincenter.php?site=games");
Expand All @@ -173,8 +191,8 @@
$ds = mysqli_fetch_array(
mysqli_query(
$_database,
"SELECT * FROM " . PREFIX . "games
WHERE gameID='" . $game_id . "'"
"SELECT * FROM `" . PREFIX . "games`
WHERE gameID = " . $game_id
)
);

Expand All @@ -184,17 +202,18 @@
$data_array['$name'] = getinput($ds['name']);
$data_array['$short'] = getinput($ds['short']);
$data_array['$tag'] = getinput($ds['tag']);
$data_array['$cup_auto_active'] = $ds['cup_auto_active'];
$data_array['$icon'] = $pic;
$data_array['$game_id'] = $game_id;
$data_array['$postName'] = 'saveedit';
$game_edit = $GLOBALS["_template"]->replaceTemplate("game_add", $data_array);
$game_edit = $GLOBALS["_template"]->replaceTemplate("game_action", $data_array);
echo $game_edit;

} else {

$ergebnis = mysqli_query(
$_database,
"SELECT * FROM `" . PREFIX . "games`
"SELECT * FROM `" . PREFIX . "games`
ORDER BY `active` DESC, `name` ASC"
);

Expand All @@ -216,6 +235,12 @@
$active_txt = ($ds['active']) ?
$_language->module[ 'active' ] : $_language->module[ 'inactive' ];

$auto_active_class = ($ds['cup_auto_active']) ?
'btn btn-success btn-xs' : 'btn btn-danger btn-xs';

$auto_active_txt = ($ds['cup_auto_active']) ?
$_language->module[ 'yes' ] : $_language->module[ 'no' ];

$edit_url = 'admincenter.php?site=games&action=edit&id=' . $game_id;
$delete_url = 'admincenter.php?site=games&delete=true&id=' . $game_id;

Expand All @@ -227,6 +252,8 @@
$data_array['$tag'] = $game_tag;
$data_array['$active_class'] = $active_class;
$data_array['$active_txt'] = $active_txt;
$data_array['$auto_active_class'] = $auto_active_class;
$data_array['$auto_active_txt'] = $auto_active_txt;
$data_array['$edit_url'] = $edit_url;
$data_array['$delete_url'] = $delete_url;

Expand All @@ -240,7 +267,7 @@

}

$no_entries = '<tr><td colspan="5">' . $_language->module[ 'no_entries' ] . '</td></tr>';
$no_entries = '<tr><td colspan="8">' . $_language->module[ 'no_entries' ] . '</td></tr>';

if (empty($active_games)) {
$active_games = $no_entries;
Expand All @@ -254,13 +281,11 @@
$data_array['$name'] = '';
$data_array['$short'] = '';
$data_array['$tag'] = '';
$data_array['$cup_auto_active'] = '';
$data_array['$game_id'] = 0;
$data_array['$icon'] = '';
$data_array['$image'] = '';
$data_array['$ts_tab'] = '';
$data_array['$ts_bg'] = '';
$data_array['$postName'] = 'save';
$add_game = $GLOBALS["_template"]->replaceTemplate("game_add", $data_array);
$add_game = $GLOBALS["_template"]->replaceTemplate("game_action", $data_array);

$data_array = array();
$data_array['$active_games'] = $active_games;
Expand Down
15 changes: 9 additions & 6 deletions cup/ajax/admin/admin_games.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,35 @@
throw new \Exception($_language->module['unknown_action']);
}

$game_id = (isset($_GET['game_id']) && validate_int($_GET['game_id'])) ?
$game_id = (isset($_GET['game_id']) && validate_int($_GET['game_id'], true)) ?
(int)$_GET['game_id'] : 0;

if ($game_id < 1) {
throw new \Exception($_language->module['unknown_game']);
}

if ($getAction == 'setActiveMode') {
if ($getAction == 'setActiveMode' || $getAction == 'setAutoActiveMode') {

$activeColumn = ($getAction == 'setActiveMode') ?
'active' : 'cup_auto_active';

$get = mysqli_fetch_array(
mysqli_query(
$_database,
"SELECT
`active`
`" . $activeColumn . "`
FROM `" . PREFIX . "games`
WHERE `gameID` = " . $game_id
)
);

$new_value = (!empty($get['active']) && ($get['active'] == 1)) ?
$new_value = (!empty($get[$activeColumn]) && ($get[$activeColumn] == 1)) ?
0 : 1;

$query = mysqli_query(
$_database,
"UPDATE `".PREFIX."games`
SET active = " . $new_value . "
"UPDATE `" . PREFIX . "games`
SET " . $activeColumn . " = " . $new_value . "
WHERE gameID = " . $game_id
);

Expand Down
8 changes: 8 additions & 0 deletions cup/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,11 @@ body {
background: rgba(19, 19, 19, 0.2);
border: 1px rgba(19, 19, 19, 0.5) solid;
}

/**
* Custom Bootstrap
*/
.input-group > span.form-control {
height: 39px;
line-height: 25px;
}
7 changes: 7 additions & 0 deletions cup/dist/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,13 @@ body {
border: 1px rgba(19, 19, 19, 0.5) solid;
}

/**
* Custom Bootstrap
*/
.input-group > span.form-control {
height: 39px;
line-height: 25px;
}
/* MAIN */
body,
html,
Expand Down
2 changes: 1 addition & 1 deletion cup/dist/css/styles.min.css

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion install-cup-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,18 @@
) ENGINE=MyISAM;"
);

$alterTabelQuery = mysqli_query(
$alterTableQuery = mysqli_query(
$_database,
"ALTER TABLE `" . PREFIX . "cups_settings`
ADD UNIQUE KEY `cup_id` (`cup_id`,`round`);"
);

$alterTableQuery = mysqli_query(
$_database,
"ALTER TABLE `" . PREFIX . "games`
ADD `cup_auto_active` INT(1) NOT NULL DEFAULT '0' AFTER `short`;"
);

echo "Delete this file!";

$sendmail = \webspell\Email::sendEmail(
Expand Down
1 change: 1 addition & 0 deletions languages/de/admin/games.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$language_array = Array(

'active_games'=>'aktive Spiele',
'cup_auto_active'=>'Cup Gameaccounts automatisch aktiviert?',
'game_short'=>'Abk&uuml;rzung',
'inactive_games'=>'inaktive Spiele',
'unknown_game'=>'unbekanntes Spiel',
Expand Down
1 change: 1 addition & 0 deletions languages/en/admin/games.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$language_array = Array(

'active_games'=>'active games',
'cup_auto_active'=>'Cup gameaccounts are active automatically?',
'game_short'=>'Shortcut',
'inactive_games'=>'inactive games',
'unknown_game'=>'unknown games',
Expand Down
59 changes: 49 additions & 10 deletions src/classes/gameaccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function checkGameaccount() {

global $_database, $userID;

if(is_null($this->game_tag)) {
if (is_null($this->game_tag)) {
throw new \Exception($this->lang->module['error_gameaccount_game_tag']);
}

Expand Down Expand Up @@ -628,6 +628,47 @@ public function deleteGameaccount() {

}

private function getActivateStateByGame() {

global $userID;

if (isanyadmin($userID)) {
$this->isActive = 1;
return;
}

if (is_null($this->game_tag)) {
return;
}

global $_database;

$getGame = mysqli_query(
$_database,
"SELECT
`cup_auto_active`
FROM `" . PREFIX . "games`
WHERE `tag` = '" . $this->game_tag . "'"
);

if (!$getGame) {
return;
}

$get = mysqli_fetch_array($getGame);

if (empty($get['cup_auto_active'])) {
return;
}

if ($get['cup_auto_active'] != 1) {
return;
}

$this->isActive = 1;

}

public function saveGameaccount($gameaccount_id = null, $redirect = TRUE) {

if (is_null($this->game_id) || !validate_int($this->game_id)) {
Expand Down Expand Up @@ -663,10 +704,8 @@ public function saveGameaccount($gameaccount_id = null, $redirect = TRUE) {
global $_database, $userID;

//
// Gameaccount aktiv?
if(isanyadmin($userID)) {
$this->isActive = 1;
}
// Gameaccount automatisch aktiv?
$this->getActivateStateByGame();

//
// Neuer Gameaccount
Expand All @@ -682,11 +721,11 @@ public function saveGameaccount($gameaccount_id = null, $redirect = TRUE) {
)
VALUES
(
".$userID.",
".time().",
'".$this->game_tag."',
'".$this->value."',
".$this->isActive."
" . $userID . ",
" . time() . ",
'" . $this->game_tag . "',
'" . $this->value . "',
" . $this->isActive . "
)"
);

Expand Down
9 changes: 9 additions & 0 deletions templates/game_add.html → templates/game_action.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
maxlength="3" />
</div>
</div>
<div class="col-sm-12">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" name="cup_auto_active"
value="1" />
</span>
<span class="form-control">%cup_auto_active%</span>
</div>
</div>
</div>
<hr />
<div class="row">
Expand Down
Loading

0 comments on commit 156481f

Please sign in to comment.