55 if (in_array($row->id,
$arr)) {
59 return $w ? min($w) : 0;
73 if (in_array($row->id,
$arr)) {
77 return $w ? max($w) : 0;
92 if (in_array($row->id,
$arr) && $row->weight > $weight) {
93 $weight = $row->weight;
110 $arr = json_decode($json_groups,
true);
112 if (self::is_users(
$arr)) {
113 return 'Все авторизованные';
116 if (self::is_not_system(
$arr)) {
120 $arr_keys = array_intersect(array_keys(self::$group_names),
$arr);
122 $text = implode(
', ', array_map(
function ($key) {
126 return $text ?:
'Нет групп';
138 if (count(
$arr) > 1) {
139 foreach (
$arr as $key => $row) {
142 uasort(
$arr,
function ($a, $b) {
143 if ($a->weight < $b->weight) {
145 }
else if ($a->weight > $b->weight) {
148 if ($a->act < $b->act) {
150 }
else if ($a->act > $b->act) {
153 if (self::row($a->owner_group)->weight > self::row($b->owner_group)->weight) {
180 return (
bool) ((array_intersect(
$user->groups, json_decode($row->groups,
true)) && $row->act) || (
$user->id && in_array($row->owner_group,
$user->groups)));
188 $dbh = Connect::getInstance()->dbh;
197 foreach (
$dbh->query(
"SELECT * FROM `groups` ORDER BY `id` ASC")->fetchAll() as $row) {
200 self::$groups_active = array_filter(
self::$groups,
function ($row) {
203 self::$groups_not_system = array_filter(
self::$groups,
function ($row) {
204 return $row->id != 1;
206 self::$groups_owners = array_filter(
self::$groups,
function ($row) {
207 return $row->id != 0;
209 self::$groups_users = array_filter(
self::$groups,
function ($row) {
210 return !in_array($row->id, [0, 1]);
212 self::$group_names = array_column(
self::$groups,
'name',
'id');
224 return in_array($id, array_column(self::$groups_active,
'id'));
233 public static function text($id)
235 return (array_column(
self::$groups,
'name',
'id')[$id] ?:
'В процессе удаления') .
' [' . $id .
']';
245 public static function row($id)
248 if ($row->id == $id) {
263 if (count(
$arr) == count(self::$groups_users) && !array_diff(array_column(self::$groups_users,
'id'),
$arr)) {
277 if (count(
$arr) == count(self::$groups_not_system) && !array_diff(array_column(self::$groups_not_system,
'id'),
$arr)) {
294 $dbh = Connect::getInstance()->dbh;
295 $sth =
$dbh->prepare(
"UPDATE {$table_name} SET `groups` = :groups WHERE `id` = :id");
296 $sth->bindValue(
':groups', json_encode(
$arr));
297 $sth->bindValue(
':id', $id);
299 return $sth->rowCount();
313 $dbh = Connect::getInstance()->dbh;
314 $sth =
$dbh->prepare(
"UPDATE {$table_name} SET `owner_group` = :owner_group WHERE `id` = :id");
316 $sth->bindValue(
':id', $id);
318 return $sth->rowCount();
329 $tables = [
'actions',
'modals',
'selects',
'templates',
'pages',
'users',
'groups',
'crontabs'];
333 $headers = [
'Cookie: ' . session_name() .
'=' . session_id()];
335 foreach ($tables as
$table) {
336 foreach (Controller::all($id,
'owner_group',
$table) as $row) {
337 $data = http_build_query([
'table' =>
$table,
'id' => $row->id,
'CSRF' => Env::$e->CSRF]);
338 session_write_close();
354 $tables = [
'actions',
'modals',
'selects',
'templates',
'pages',
'users',
'groups',
'crontabs'];
356 foreach ($tables as
$table) {
357 $count += Controller::count($id,
'owner_group',
$table, ($is_active ?
'AND `act` = 1' :
''));
371 $dbh = Connect::getInstance()->dbh;
372 $tables = [
'actions',
'modals',
'selects',
'templates',
'pages',
'users'];
374 foreach ($tables as
$table) {
375 foreach (
$dbh->query(
"SELECT * FROM $table WHERE `owner_group` = $id OR `groups` LIKE '%$id%'") as $row) {
376 $count += (int) ($row->owner_group == $id || in_array($id, json_decode($row->groups)));
379 $count += Groups::count($id,
'owner_group');
392 $dbh = Connect::getInstance()->dbh;
393 $tables = [
'actions',
'modals',
'selects',
'templates',
'pages'];
395 foreach ($tables as
$table) {
396 $owners[] =
$dbh->query(
"SELECT `owner_group` FROM `$table` WHERE `file` = '$file' LIMIT 1")->fetchColumn();
398 $owners = array_unique(array_filter($owners));
399 return count($owners) > 1 ? false :
true;
if(!($row=Wrong\Models\Crontabs::find($_POST['id']))) if(! $user->access() ->write($row)) $sth
if($_POST['code']==file_get_contents($_SERVER['DOCUMENT_ROOT'] . $row->file)) $file
if(!in_array($_POST['table'], Wrong\Database\Controller::$tables)) $table
User отвечает за работу с данными пользователя
API отвечает за http запросы к серверу
Connect создает подключение к базе данных
Controller контроллер для запросов к БД
Groups контроллер управления моделями групп пользователей, расширяет Controller.
Group класс, содержащий статические методы, используемые для управления группами пользователей.
static max_weight_group($arr)
static is_not_system($arr)
static count_all_available_models($id)
static $groups_not_system
static set_groups($id, $arr, $table_name)
static set_owner($id, $owner_group, $table_name)
static is_one_owner_file($file)
static delete_all_owner_models($id)
static is_available_group($row, $id=null)
static groupNamesText($json_groups)
static count_all_owner_models($id, $is_active=false)
Env класс управляющий, добавляющий или записывающий переменные среды
if(!($row=Wrong\Database\Controller::find($_GET['id'], 'id', $_GET['table']))) $groups
if(preg_match('#//#', $request)) if($request !='/' &&preg_match('#/$#', $request)) if(preg_match('#index\.(php|html)$#', $request)) if(Wrong\Start\Env::$e->SYSTEM_CLOSED && $user->main_group_id !=1) if(preg_match('#^/api/(modal|action|select)/[a-z0-9\-]+#', $request, $matches)) if(isset($_GET['FROM_UID'])) if($request=='/' &&Wrong\Start\Env::$e->RETURN_TO_REQUEST && $user->id && $request !=$user->request && $user->request &&!isset($_GET['main'])) if(preg_match('#^/remind/([0-9]+)/([a-z0-9]+)#i', $request, $matches) &&Wrong\Auth\User::is_remind($matches[1], $matches[2])) if(preg_match('#^/email-confirm/([0-9]+)/([a-z0-9]+)#i', $request, $matches) &&Wrong\Auth\User::is_confirm($matches[1], $matches[2]) &&! $user->email_confirmed) if(Wrong\Start\Env::$e->EMAIL_CONFIRMATION && $user->id &&! $user->email_confirmed) if( $arr=Wrong\Models\Pages::all( $request, 'request'))