-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathListmembersController.php
More file actions
137 lines (116 loc) · 4.85 KB
/
ListmembersController.php
File metadata and controls
137 lines (116 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
class ListmembersController extends AppController {
public function redirectMembers(){
$this->redirect('/list/members');
$this->autoRender = false;
}
public function index(){
$this->set('title_for_layout', $this->Lang->get('LISTMEMBERS__TITLE'));
$this->loadModel('Users');
$this->loadModel('ListMembers.Perm');
$permGetMailEtat = $this->Perm->getListMembersByPerm('mail_perm', 'etat');
$users = $this->Users->find('all', ['order' => 'id ASC']);
//RÉCUPÉRATION DES RANKS CUSTOMS
$this->loadModel('Rank');
$custom_ranks = $this->Rank->find('all');
foreach ($custom_ranks as $key => $value) {
$available_ranks[$value['Rank']['rank_id']] = $value['Rank']['name'];
}
$this->set(compact("users", "permGetMailEtat", "available_ranks"));
}
public function profil(){
//EXTRAIRE LE PARAMETRE ID USER
$id = $this->request->query['id'];
//CHARGEMENT DU MODEL USER POUR LA BDD
$this->loadModel('User');
//ISOLEMENT DES INFORMATIONS DE L'UTILISATEUR PORTANT L'ID USER SORTIS EN PARAMETRE + REQUETE SQL
$conditions = array("User.id" => array($id));
$userFound = $this->User->find('first', array('conditions' => $conditions));
//RÉCUPÉRATION DU NOMBRE DE VOTES DU MEMBRE
if ($this->EyPlugin->isInstalled('eywek.vote')) {
$this->loadModel("Vote.Vote");
$voteCount = count($this->Vote->find('all', ['conditions' => ['user_id' => $userFound["User"]["id"]]]));
}
//RÉCUPÉRATION DES RANKS CUSTOMS
$this->loadModel('Rank');
$custom_ranks = $this->Rank->find('all');
foreach ($custom_ranks as $key => $value) {
$available_ranks[$value['Rank']['rank_id']] = $value['Rank']['name'];
}
//SORTIE DE LA VARIABLE POUR LE VIEW
$this->set(compact("userFound", "voteCount", "available_ranks"));
//CREATION DE LA VARIABLE TITLE POUR LE TITRE DE L'ONGLET
$this->set('title_for_layout', $this->Lang->get('LISTMEMBERS__PROFILE').' '.$userFound['User']['pseudo']);
}
function admin_add_perm(){
$this->loadModel('ListMembers.Perm');
$permMail = $this->Perm->getListMembersByPerm('mail_perm', 'perm');
if(!isset($permMail)){
$this->Perm->set(array(
'perm' => 'mail_perm'
));
$this->Perm->save();
}
}
function admin_update_perm(){
$this->loadModel('ListMembers.Perm');
$this->layout = 'admin';
$this->autoRender = false;
if($this->isConnected && $this->User->isAdmin()){
if($this->request->is('post')) {
$perm_name = $this->request->data['mail_perm_name'];
$perm_check = $this->request->data['mail_perm_check'];
$permGetId = $this->Perm->getListMembersByPerm($perm_name, 'id');
if($perm_check == '0'){
$this->Perm->read(null, $permGetId);
$this->Perm->set(array(
'etat' => '0'
));
$this->Perm->save();
}else{
$this->Perm->read(null, $permGetId);
$this->Perm->set(array(
'etat' => '1'
));
$this->Perm->save();
}
if($perm_check == '0'){
$this->response->body(json_encode(array('statut' => true, 'msg' => $this->Lang->get('LISTMEMBERS__DISABLED_PERM_MAIL'))));
}else{
$this->response->body(json_encode(array('statut' => true, 'msg' => $this->Lang->get('LISTMEMBERS__ENABLED_PERM_MAIL'))));
}
return;
}
}
else
throw new ForbiddenException();
}
function admin_index(){
if($this->isConnected AND $this->User->isAdmin()){
$this->set('title_for_layout', $this->Lang->get('LISTMEMBERS__ADMIN_TITLE'));
$this->layout = 'admin';
$this->admin_add_perm();
$permGetMail = $this->Perm->getListMembersByPerm('mail_perm', 'etat');
//VERIF_VERSION_INSTALL
$plugins = $this->EyPlugin->pluginsLoaded;
$version_install = $plugins->{'empiredev.listmembers.24'}->{'version'};
//VERIF_VERSION_MARKET
$version_up = null;
$json = file_get_contents('http://api.mineweb.org/api/v2/plugin/all');
$json = json_decode($json, true);
foreach($json as $pl){
if($pl['id'] == "24"){
$version_up = $pl['version'];
}
}
$isUpdateAvaible = false;
if($version_install != $version_up){
$isUpdateAvaible = true;
}
$this->set(compact('isUpdateAvaible'));
$this->set('isActiveMail', $permGetMail);
}
else
throw new ForbiddenException();
}
}