@@ -23,70 +23,105 @@ class Model extends Plugin
23
23
'altemail ' => '' ,
24
24
];
25
25
26
- protected function create (): string
26
+ public function create (): array
27
27
{
28
28
Util::elog (__METHOD__ );
29
29
30
- if (Util::is_adm ()) return parent ::create ();
31
- Util::log ('You are not authorized to perform this action, please contact your administrator. ' );
32
- Util::relist ();
33
- return '' ;
30
+ if (!Util::is_adm ())
31
+ {
32
+ return [
33
+ 'status ' => 'error ' ,
34
+ 'message ' => 'You are not authorized to perform this action, please contact your administrator. '
35
+ ];
36
+ }
37
+
38
+ return parent ::create ();
34
39
}
35
40
36
- protected function read (): string
41
+ public function read (): array
37
42
{
38
43
Util::elog (__METHOD__ );
39
44
40
- $ usr = Db::read ('* ' , 'id ' , $ this ->g ->input ['i ' ], '' , 'one ' );
45
+ $ usr = Db::read ('* ' , 'id ' , $ this ->controller ->input ['i ' ], '' , 'one ' );
41
46
if (!$ usr )
42
47
{
43
- Util::log ('User not found. ' );
44
- Util::relist ();
45
- return '' ;
48
+ return [
49
+ 'status ' => 'error ' ,
50
+ 'message ' => 'User not found. '
51
+ ];
46
52
}
47
53
48
54
if (Util::is_acl (0 ))
49
55
{
50
- // superadmin
56
+ // superadmin - allow access
57
+ return [
58
+ 'status ' => 'success ' ,
59
+ 'message ' => $ usr
60
+ ];
51
61
}
52
62
elseif (Util::is_acl (1 ))
53
- { // normal admin
63
+ {
64
+ // normal admin
54
65
if ((int )$ _SESSION ['usr ' ]['grp ' ] !== (int )$ usr ['grp ' ])
55
66
{
56
- Util::log ('You are not authorized to perform this action. ' );
57
- Util::relist ();
58
- return '' ;
67
+ return [
68
+ 'status ' => 'error ' ,
69
+ 'message ' => 'You are not authorized to perform this action. '
70
+ ];
59
71
}
60
72
}
61
73
else
62
- { // Other users
74
+ {
75
+ // Other users
63
76
if ((int )$ _SESSION ['usr ' ]['id ' ] !== (int )$ usr ['id ' ])
64
77
{
65
- Util::log ('You are not authorized to perform this action. ' );
66
- Util::relist ();
67
- return '' ;
78
+ return [
79
+ 'status ' => 'error ' ,
80
+ 'message ' => 'You are not authorized to perform this action. '
81
+ ];
68
82
}
69
83
}
70
- return $ this ->g ->t ->read ($ usr );
84
+
85
+ return [
86
+ 'status ' => 'success ' ,
87
+ 'message ' => $ usr
88
+ ];
89
+ }
90
+
91
+ public function update (): array
92
+ {
93
+ Util::elog (__METHOD__ );
94
+ // Add your update logic here
95
+ return [
96
+ 'status ' => 'success ' ,
97
+ 'message ' => 'Update operation '
98
+ ];
71
99
}
72
100
73
- protected function delete (): string
101
+ public function delete (): array
74
102
{
75
103
Util::elog (__METHOD__ );
76
104
77
105
if (Util::is_post ())
78
106
{
79
107
parent ::delete ();
80
- return '' ;
108
+ return [
109
+ 'status ' => 'success ' ,
110
+ 'message ' => 'Delete operation completed '
111
+ ];
81
112
}
82
- return $ this ->g ->t ->delete ();
113
+
114
+ return [
115
+ 'status ' => 'success ' ,
116
+ 'message ' => 'Confirm deletion '
117
+ ];
83
118
}
84
119
85
- protected function list (): string
120
+ public function list (): array
86
121
{
87
122
Util::elog (__METHOD__ );
88
123
89
- if ($ this ->g ->input ['f ' ] === 'json ' )
124
+ if ($ this ->controller ->input ['f ' ] === 'json ' )
90
125
{
91
126
$ columns = [
92
127
['dt ' => null , 'db ' => 'id ' ],
@@ -99,34 +134,47 @@ protected function list(): string
99
134
['dt ' => 3 , 'db ' => 'altemail ' ],
100
135
['dt ' => 4 , 'db ' => 'acl ' , 'formatter ' => function ($ d ): string
101
136
{
102
- return $ this -> g -> acl [ is_string ($ d ) ? (int )$ d : $ d] ;
137
+ return is_string ($ d ) ? (int )$ d : $ d ;
103
138
}],
104
139
['dt ' => 5 , 'db ' => 'grp ' ],
105
140
];
106
- $ this ->g ->out ['json ' ] = Db::simple ($ _GET , 'accounts ' , 'id ' , $ columns );
107
- return '' ;
141
+ return [
142
+ 'status ' => 'success ' ,
143
+ 'message ' => Db::simple ($ _GET , 'accounts ' , 'id ' , $ columns )
144
+ ];
108
145
}
109
- return $ this ->g ->t ->list ($ this ->in );
146
+
147
+ return [
148
+ 'status ' => 'success ' ,
149
+ 'message ' => Db::read ('* ' , '' , '' , 'ORDER BY `updated` DESC ' )
150
+ ];
110
151
}
111
152
112
- protected function switch_user (): string
153
+ public function switch_user (): array
113
154
{
114
155
Util::elog (__METHOD__ );
115
156
116
- if (Util::is_adm () && ! is_null ($ this ->g ->input ['i ' ]))
157
+ if (! Util::is_adm () || is_null ($ this ->controller ->input ['i ' ]))
117
158
{
118
- $ usr = Db::read ('id,acl,grp,login,fname,lname,webpw,cookie ' , 'id ' , $ this ->g ->input ['i ' ], '' , 'one ' );
119
- if ($ usr )
120
- {
121
- $ _SESSION ['usr ' ] = $ usr ;
122
- Util::log ('Switch to user: ' . $ usr ['login ' ], 'success ' );
123
- }
159
+ return [
160
+ 'status ' => 'error ' ,
161
+ 'message ' => 'Not authorized to switch users '
162
+ ];
124
163
}
125
- else
164
+
165
+ $ usr = Db::read ('id,acl,grp,login,fname,lname,webpw,cookie ' , 'id ' , $ this ->controller ->input ['i ' ], '' , 'one ' );
166
+ if ($ usr )
126
167
{
127
- Util::log ('Not authorized to switch users ' );
168
+ $ _SESSION ['usr ' ] = $ usr ;
169
+ return [
170
+ 'status ' => 'success ' ,
171
+ 'message ' => 'Switch to user: ' . $ usr ['login ' ]
172
+ ];
128
173
}
129
- Util::relist ();
130
- return '' ;
174
+
175
+ return [
176
+ 'status ' => 'error ' ,
177
+ 'message ' => 'User not found '
178
+ ];
131
179
}
132
180
}
0 commit comments