Skip to content

Commit 1e76587

Browse files
committed
Module/UCP: Implement Recent Activity Account
1 parent d3e1abf commit 1e76587

File tree

13 files changed

+181
-8
lines changed

13 files changed

+181
-8
lines changed

application/libraries/Dblogger.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public function __construct()
3939
* @param string|null $type
4040
* @param int $offset
4141
* @param int $limit
42+
* @param int $accountId
43+
* @param string|array|null $event
4244
* @return mixed
4345
*/
44-
public function getLogs(?string $type = "", int $offset = 0, int $limit = 0): mixed
46+
public function getLogs(?string $type = "", int $offset = 0, int $limit = 0, int $accountId = 0, string|null|array $event = ""): mixed
4547
{
46-
return $this->CI->logger_model->getLogsDb($type, $offset, $limit);
48+
return $this->CI->logger_model->getLogsDb($type, $offset, $limit, $accountId);
4749
}
4850

4951
/**

application/models/Logger_model.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,36 @@
1010

1111
class Logger_model extends CI_Model
1212
{
13-
public function getLogsDb(string $logType = "", int $offset = 0, int $limit = 0): ?array
13+
public function getLogsDb($logType = "", int $offset = 0, int $limit = 0, int $accountId = 0, $event = ''): ?array
1414
{
15-
if (($logType != "" && !is_string($logType)) || !is_numeric($limit) || !is_numeric($offset)) {
15+
if (($logType != "" && !is_string($logType)) || (!is_string($event) && !is_array($event)) || !is_numeric($limit) || !is_numeric($offset) || !is_numeric($accountId)) {
1616
return null;
1717
}
1818

1919
$builder = $this->db->table('logs')->select('*');
20+
2021
if ($logType != "") {
2122
$builder->where('type', $logType);
2223
}
23-
$builder->orderBy('time', 'DESC');
24-
if ($limit > 0 && $offset == 0) {
25-
$builder->limit($limit);
24+
25+
if (!empty($event)) {
26+
if (is_array($event)) {
27+
$builder->whereIn('event', $event);
28+
} else {
29+
$builder->where('event', $event);
30+
}
2631
}
27-
if ($limit > 0 && $offset > 0) {
32+
33+
if ($accountId > 0) {
34+
$builder->where('user_id', $accountId);
35+
}
36+
37+
$builder->orderBy('time', 'DESC');
38+
39+
if ($limit > 0) {
2840
$builder->limit($limit, $offset);
2941
}
42+
3043
$query = $builder->get();
3144

3245
// Get the results

application/modules/donate/controllers/Donate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public function checkPaypal($id)
138138

139139
Events::trigger('onSuccessDonate', $this->user->getId(), $specify_donate);
140140

141+
$this->dblogger->createLog("user", "donate", $specify_donate['price'].$this->config->item('donation_currency_sign'), $specify_donate['points'], Dblogger::STATUS_SUCCEED, $this->user->getId());
142+
141143
redirect(base_url('/donate/success'));
142144
}
143145
} catch (Exception $e) {

application/modules/levelup/controllers/Levelup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public function submit()
130130
$this->user->setDp($this->user->getDp() - $price);
131131
}
132132

133+
$this->dblogger->createLog("user", "service", "Level Up", $CharacterName, Dblogger::STATUS_SUCCEED, $this->user->getId());
134+
133135
//Successful
134136
die(lang("successfully", "levelup"));
135137

application/modules/teleport/controllers/Teleport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public function submit()
126126
//MAKE SURE THAT THE CHARACTER EXISTS AND THAT HE IS OFFLINE, ALSO MAKE SURE WE CAN AFFORD IT
127127
$character_exists = $this->teleport_model->characterExists($characterGuid, $realmConnection->getConnection());
128128

129+
//Get the character name
130+
$CharacterName = $realmConnection->getNameByGuid($characterGuid);
131+
129132
if ($character_exists) {
130133
if ($this->canPay($this->user->getVp(), $this->user->getDp(), $realmConnection->getGold($this->user->getId(), $characterGuid), $teleport_exists['vpCost'], $teleport_exists['dpCost'], $teleport_exists['goldCost'])) {
131134
//Update the vp, dp and gold.
@@ -138,6 +141,8 @@ public function submit()
138141

139142
Events::trigger('onTeleport', $this->user->getId(), $characterGuid, $teleport_exists['vpCost'], $teleport_exists['dpCost'], $teleport_exists['goldCost'], $location['x'], $location['y'], $location['z'], $location['orientation'], $location['mapId']);
140143

144+
$this->dblogger->createLog("user", "service", "Teleport", $CharacterName, Dblogger::STATUS_SUCCEED, $this->user->getId());
145+
141146
die("1");
142147
} else {
143148
die(lang("cant_afford", "teleport"));

application/modules/ucp/controllers/Ucp.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct()
1717
$this->load->config('links');
1818

1919
$this->load->model("ucp_model");
20+
$this->load->library("dblogger");
2021
}
2122

2223
public function index()
@@ -47,6 +48,60 @@ public function index()
4748
$groupedMenus[$menu['group']][] = $menu;
4849
}
4950

51+
$recent_activity = $this->dblogger->getLogs('user', 0, 5, $this->user->getId(), ['login', 'logout', 'recovery', 'service']);
52+
53+
$recent_activities = [];
54+
foreach ($recent_activity as $activityLog) {
55+
$time = date("H:i", $activityLog['time']);
56+
$date = date("Y-m-d", $activityLog['time']);
57+
$today = date("Y-m-d");
58+
$yesterday = date("Y-m-d", strtotime("-1 day"));
59+
60+
if ($date == $today) {
61+
$date_label = lang('today', 'ucp');
62+
} elseif ($date == $yesterday) {
63+
$date_label = lang('yesterday', 'ucp');
64+
} else {
65+
$date_label = date("F j, Y", $activityLog['time']);
66+
}
67+
68+
$activity_time = "{$date_label}, {$time}" . lang('ip', 'ucp') . ": {$activityLog['ip']}";
69+
$title = '';
70+
$icon = '';
71+
72+
switch ($activityLog['event']) {
73+
case 'login':
74+
$title = lang('account_login', 'ucp');
75+
$icon = 'fa-sign-in-alt';
76+
break;
77+
case 'logout':
78+
$title = lang('account_logout', 'ucp');
79+
$icon = 'fa-sign-out-alt';
80+
break;
81+
case 'recovery':
82+
$title = lang('account_recovery', 'ucp');
83+
$icon = 'fa-clock-rotate-left';
84+
break;
85+
case 'donate':
86+
$title = lang('donate', 'main') . ": {$activityLog['message']} | " . lang('donation_points', 'main') . ": {$activityLog['custom']}";
87+
$icon = 'fa-circle-dollar-to-slot';
88+
break;
89+
case 'service':
90+
$title = "{$activityLog['message']} | " . lang('character', 'ucp') . ": {$activityLog['custom']}";
91+
$icon = ' fa-users-gear';
92+
break;
93+
default:
94+
break;
95+
}
96+
97+
$recent_activities[] = [
98+
'icon' => $icon,
99+
'title' => $title,
100+
'event' => strtolower($activityLog['event']),
101+
'activity_time' => $activity_time,
102+
];
103+
}
104+
50105
$data = [
51106
"username" => $this->user->getUsername(),
52107
"nickname" => $this->user->getNickname(),
@@ -75,6 +130,7 @@ public function index()
75130
"realms" => $this->realms->getRealms(),
76131
"realmObj" => $this->realms,
77132
"menus" => $groupedMenus,
133+
"recent_activity" => $recent_activities,
78134
];
79135

80136
$data['email'] = false;

application/modules/ucp/language/english/ucp.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@
7979
$lang['six_digit_auth_code'] = "6 digit Authenticator code";
8080
$lang['six_digit_not_empty'] = "6 digit Authenticator code cannot be empty";
8181
$lang['six_digit_not_true'] = "Authenticator code is not true";
82+
83+
// Recent Activity
84+
$lang['recent_activity'] = 'Recent Activity';
85+
$lang['account_login'] = 'Account Login';
86+
$lang['account_logout'] = 'Account Logout';
87+
$lang['account_recovery'] = 'Account Recovery';
88+
$lang['service'] = 'Service';
89+
$lang['character'] = 'Character';
90+
$lang['amount'] = 'Amount';
91+
$lang['ip'] = 'IP';
92+
$lang['today'] = 'Today';
93+
$lang['yesterday'] = 'Yesterday';

application/modules/ucp/language/france/ucp.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@
7979
$lang['six_digit_auth_code'] = "Code Authenticator à 6 chiffres";
8080
$lang['six_digit_not_empty'] = "Le code Authenticator à 6 chiffres ne peut pas être vide";
8181
$lang['six_digit_not_true'] = "Le code Authenticator est incorrect";
82+
83+
// Recent Activity
84+
$lang['recent_activity'] = 'Activité récente';
85+
$lang['account_login'] = 'Connexion au compte';
86+
$lang['account_logout'] = 'Déconnexion du compte';
87+
$lang['account_recovery'] = 'Récupération du compte';
88+
$lang['service'] = 'Service';
89+
$lang['character'] = 'Personnage';
90+
$lang['amount'] = 'Montant';
91+
$lang['ip'] = 'IP';
92+
$lang['today'] = 'Aujourd\'hui';
93+
$lang['yesterday'] = 'Hier';

application/modules/ucp/language/persian/ucp.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@
7979
$lang['six_digit_auth_code'] = "کد 6 رقمی احراز ورود";
8080
$lang['six_digit_not_empty'] = "کد احراز ورود 6 رقمی نمی تواند خالی باشد";
8181
$lang['six_digit_not_true'] = "کد احراز صحیح نیست";
82+
83+
// Recent Activity
84+
$lang['recent_activity'] = 'فعالیت‌های اخیر';
85+
$lang['account_login'] = 'ورود به حساب';
86+
$lang['account_logout'] = 'خروج از حساب';
87+
$lang['account_recovery'] = 'بازیابی حساب';
88+
$lang['service'] = 'سرویس';
89+
$lang['character'] = 'شخصیت';
90+
$lang['amount'] = 'مقدار';
91+
$lang['ip'] = 'آی‌پی';
92+
$lang['today'] = 'امروز';
93+
$lang['yesterday'] = 'دیروز';

application/modules/ucp/language/portuguese-brazilian/ucp.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@
8484
$lang['six_digit_auth_code'] = "Código de Autenticador de 6 dígitos";
8585
$lang['six_digit_not_empty'] = "O código de Autenticador de 6 dígitos não pode estar vazio";
8686
$lang['six_digit_not_true'] = "O código de Autenticador não é válido";
87+
88+
// Recent Activity
89+
$lang['recent_activity'] = 'Atividade recente';
90+
$lang['account_login'] = 'Login da conta';
91+
$lang['account_logout'] = 'Logout da conta';
92+
$lang['account_recovery'] = 'Recuperação da conta';
93+
$lang['service'] = 'Serviço';
94+
$lang['character'] = 'Personagem';
95+
$lang['amount'] = 'Quantidade';
96+
$lang['ip'] = 'IP';
97+
$lang['today'] = 'Hoje';
98+
$lang['yesterday'] = 'Ontem';

application/modules/ucp/language/spanish/ucp.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,32 @@
6363
$lang['invalid_language'] = "Idioma inválido";
6464

6565
$lang['change_information'] = "Cambiar información";
66+
67+
// Security
68+
$lang['account_security'] = "Seguridad de la cuenta";
69+
$lang['save_changes'] = "Guardar cambios";
70+
$lang['two_factor'] = "AUTENTICACIÓN DE DOS FACTORES";
71+
$lang['two_factor_description'] = "La autenticación de dos factores ayuda a proteger tu cuenta contra accesos no autorizados añadiendo una capa adicional de seguridad.";
72+
$lang['two_factor_help'] = "Descarga la aplicación Google Authenticator desde Google Play o App Store. Abre la aplicación y usa la cámara de tu teléfono para escanear el código de barras inferior. Ingresa el código de verificación de 6 dígitos generado por la aplicación Authenticator.";
73+
$lang['qr_code'] = "Código QR";
74+
$lang['qr_code_help_1'] = "¿No puedes escanear el código QR? También puedes ingresar la";
75+
$lang['qr_code_help_2'] = "clave manualmente.";
76+
$lang['select_authentication'] = "Seleccionar método de autenticación";
77+
$lang['disabled'] = "Desactivado";
78+
$lang['google_authenticator'] = "Google Authenticator";
79+
$lang['six_digit_auth_code'] = "Código de autenticación de 6 dígitos";
80+
$lang['six_digit_not_empty'] = "El código de autenticación de 6 dígitos no puede estar vacío";
81+
$lang['six_digit_not_true'] = "El código de autenticación no es correcto";
82+
83+
// Recent Activity
84+
$lang['recent_activity'] = 'Actividad reciente';
85+
$lang['account_login'] = 'Inicio de sesión';
86+
$lang['account_logout'] = 'Cierre de sesión';
87+
$lang['account_recovery'] = 'Recuperación de cuenta';
88+
$lang['service'] = 'Servicio';
89+
$lang['character'] = 'Personaje';
90+
$lang['amount'] = 'Cantidad';
91+
$lang['ip'] = 'IP';
92+
$lang['today'] = 'Hoy';
93+
$lang['yesterday'] = 'Ayer';
94+

application/modules/ucp/views/ucp.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@
111111
{/foreach}
112112
</div>
113113
{/if}
114+
115+
<div class="section-header">{lang("recent_activity", "ucp")}</div>
116+
<div class="section-body">
117+
{foreach from=$recent_activity item=activity}
118+
<div class="table-responsive text-nowrap">
119+
<table class="nice_table mb-3">
120+
<tr>
121+
<td> <i class="fas {$activity.icon}"></i> {$activity.title}</td>
122+
<td class="col-3">{$activity.activity_time nofilter}</td>
123+
</tr>
124+
</table>
125+
</div>
126+
{/foreach}
127+
</div>
114128
</div>
115129
</div>
116130
</div>

application/modules/unstuck/controllers/Unstuck.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public function submit()
163163
$this->user->setVp($this->user->getVp() - $price);
164164
}
165165

166+
$this->dblogger->createLog("user", "service", "Unstuck", $characterName, Dblogger::STATUS_SUCCEED, $this->user->getId());
167+
166168
//Successful
167169
$data = [
168170
'status' => true,

0 commit comments

Comments
 (0)