fusionpbx/core/groups/app_defaults.php

128 lines
4.1 KiB
PHP
Raw Normal View History

2019-07-25 18:54:55 +02:00
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2019-07-25 17:03:48 +02:00
Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
if ($domains_processed == 1) {
//if the default groups do not exist add them
$group = new groups;
$group->defaults();
//find rows that have a null group_uuid and set the correct group_uuid
2019-02-09 15:55:51 +01:00
$sql = "select * from v_user_groups ";
$sql .= "where group_uuid is null; ";
2019-07-25 17:03:48 +02:00
$result = $database->select($sql, null, 'all');
if (is_array($result)) {
foreach($result as $row) {
if (!empty($row['group_name'])) {
//get the group_uuid
$sql = "select group_uuid from v_groups ";
2019-07-25 17:03:48 +02:00
$sql .= "where group_name = :group_name ";
$parameters['group_name'] = $row['group_name'];
2019-07-25 18:52:49 +02:00
$group_uuid = $database->select($sql, $parameters, 'column');
2019-07-25 17:03:48 +02:00
unset($sql, $parameters);
//set the group_uuid
2019-02-09 15:55:51 +01:00
$sql = "update v_user_groups set ";
2019-07-25 17:03:48 +02:00
$sql .= "group_uuid = :group_uuid ";
$sql .= "where user_group_uuid = :user_group_uuid; ";
$parameters['group_uuid'] = $group_uuid;
$parameters['user_group_uuid'] = $row['user_group_uuid'];
$database->execute($sql, $parameters);
unset($sql, $parameters);
}
}
2019-07-25 17:03:48 +02:00
unset ($result);
}
2019-07-26 08:11:59 +02:00
//set the default group levels
$sql = "select * from v_groups ";
$sql .= "where group_level is null; ";
$result = $database->select($sql, null, 'all');
if (is_array($result) && count($result) > 0) {
$x = 0;
foreach($result as $row) {
$array['groups'][$x]['group_uuid'] = $row['group_uuid'];
switch ($row['group_name']) {
case 'superadmin':
$array['groups'][$x]['group_level'] = 80;
break;
case 'admin':
$array['groups'][$x]['group_level'] = 50;
break;
case 'user':
$array['groups'][$x]['group_level'] = 30;
break;
case 'agent':
$array['groups'][$x]['group_level'] = 20;
break;
case 'public':
$array['groups'][$x]['group_level'] = 10;
break;
default:
$array['groups'][$x]['group_level'] = 10;
}
2019-07-26 08:18:10 +02:00
$x++;
2019-07-26 08:11:59 +02:00
}
$database->app_name = 'groups';
$database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
2021-12-24 20:39:14 +01:00
$database->save($array, false);
2019-07-26 08:11:59 +02:00
unset($array);
}
2020-03-03 00:32:58 +01:00
//update the group_uuid
$sql = "UPDATE v_group_permissions as p ";
$sql .= "SET group_uuid = ( ";
$sql .= " SELECT group_uuid FROM v_groups as g ";
$sql .= " WHERE g.group_name = p.group_name ";
$sql .= ") ";
$sql .= "WHERE group_uuid is null; ";
2020-03-03 00:32:58 +01:00
$parameters = null;
$database->execute($sql, $parameters);
unset($sql, $parameters);
2019-12-08 09:04:16 +01:00
//drop the view_groups
$database->execute("DROP VIEW view_groups;", null);
//add or update the view
$sql = "CREATE VIEW view_groups AS (";
$sql .= " select domain_uuid, group_uuid, group_name, ";
$sql .= " (select domain_name from v_domains where domain_uuid = g.domain_uuid) as domain_name, ";
2019-12-08 09:04:16 +01:00
$sql .= " (select count(*) from v_group_permissions where group_uuid = g.group_uuid) as group_permissions, ";
$sql .= " (select count(*) from v_user_groups where group_uuid = g.group_uuid) as group_members, ";
$sql .= " group_level, group_protected, group_description ";
$sql .= " from v_groups as g ";
$sql .= ");";
$database->execute($sql, null);
unset($sql);
//group permissions
$database->execute("update v_group_permissions set permission_protected = 'false' where permission_protected is null;", null);
$database->execute("update v_group_permissions set permission_assigned = 'true' where permission_assigned is null;", null);
}
2019-02-09 15:55:51 +01:00
?>