Users: Revamp and consolidate code, integrate ORM.

This commit is contained in:
reliberate
2016-10-05 10:29:30 -06:00
parent d98bac68a6
commit d20a495548
32 changed files with 2613 additions and 2342 deletions
+241
View File
@@ -0,0 +1,241 @@
<?php
//application details
$apps[$x]['name'] = "Group Manager";
$apps[$x]['uuid'] = "2caf27b0-540a-43d5-bb9b-c9871a1e4f84";
$apps[$x]['category'] = "Core";
$apps[$x]['subcategory'] = "";
$apps[$x]['version'] = "";
$apps[$x]['license'] = "Mozilla Public License 1.1";
$apps[$x]['url'] = "http://www.fusionpbx.com";
$apps[$x]['description']['en-us'] = "Manage user groups and permissions.";
$apps[$x]['description']['es-cl'] = "Administrar grupos de usuarios y permisos.";
$apps[$x]['description']['de-de'] = "";
$apps[$x]['description']['de-ch'] = "";
$apps[$x]['description']['de-at'] = "";
$apps[$x]['description']['fr-fr'] = "Gérer les groupes d'utilisateurs et des autorisations.";
$apps[$x]['description']['fr-ca'] = "";
$apps[$x]['description']['fr-ch'] = "";
$apps[$x]['description']['pt-pt'] = "Gerenciar grupos de usuários e permissões.";
$apps[$x]['description']['pt-br'] = "Gerenciar grupos de usuários e permissões.";
//permission details
$y = 0;
$apps[$x]['permissions'][$y]['name'] = "group_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "3b4acc6d-827b-f537-bf21-0093d94ffec7";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_add";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_delete";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = 'group_domain';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'group_all';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_member_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "3b4acc6d-827b-f537-bf21-0093d94ffec7";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_member_add";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_member_delete";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_permissions";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_user_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "3b4acc6d-827b-f537-bf21-0093d94ffec7";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_user_add";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_user_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_user_delete";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_permission_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "3b4acc6d-827b-f537-bf21-0093d94ffec7";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_permission_add";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_permission_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "group_permission_delete";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
//schema details
$y = 0; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = "v_groups";
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "primary";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "id";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "serial";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "integer";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "INT NOT NULL AUTO_INCREMENT";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_domains";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "v_id";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "group_name";
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "groupid";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_protected";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "group_description";
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "groupdesc";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$y = 1; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = "v_group_users";
$apps[$x]['db'][$y]['fields'][$z]['name'] = "id";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "serial";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "integer";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "INT NOT NULL AUTO_INCREMENT";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_user_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "primary";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_domains";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "v_id";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "group_name";
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "groupid";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_groups";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "group_uuid";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "username";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "user_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$y = 2; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = "v_group_permissions";
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_permission_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "primary";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "id";
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "group_permission_name";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "serial";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "integer";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "INT NOT NULL AUTO_INCREMENT";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_domains";
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "domain_uuid";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "v_id";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = "true";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = "permission_name";
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = "permission_id";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_name";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "group_uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
?>
+65
View File
@@ -0,0 +1,65 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2012
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
$sql = "select * from v_group_users ";
$sql .= "where group_uuid is null; ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$db->beginTransaction();
foreach($result as $row) {
if (strlen($row['group_name']) > 0) {
//get the group_uuid
$sql = "select group_uuid from v_groups ";
$sql .= "where group_name = '".$row['group_name']."' ";
$prep_statement_sub = $db->prepare($sql);
$prep_statement_sub->execute();
$sub_result = $prep_statement_sub->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement_sub);
$group_uuid = $sub_result['group_uuid'];
//set the group_uuid
$sql = "update v_group_users set ";
$sql .= "group_uuid = '".$group_uuid."' ";
$sql .= "where group_user_uuid = '".$row['group_user_uuid']."'; ";
$db->exec($sql);
unset($sql);
}
}
$db->commit();
unset ($prep_statement);
}
}
?>
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
<?php
$apps[$x]['menu'][3]['title']['en-us'] = "Group Manager";
$apps[$x]['menu'][3]['title']['es-cl'] = "Administración de Grupos";
$apps[$x]['menu'][3]['title']['fr-fr'] = "Gestion des groupes";
$apps[$x]['menu'][3]['title']['pt-pt'] = "'Gestão de Grupos";
$apps[$x]['menu'][3]['title']['pt-br'] = "Gerenciar grupos";
$apps[$x]['menu'][3]['title']['pl'] = "Menedżer grup";
$apps[$x]['menu'][3]['title']['uk'] = "Групи";
$apps[$x]['menu'][3]['title']['sv-se'] = "Grupp Inställningar";
$apps[$x]['menu'][3]['title']['de-at'] = "Gruppenverwaltung";
$apps[$x]['menu'][3]['title']['he'] = "מנהל קבוצה";
$apps[$x]['menu'][3]['uuid'] = "3b4acc6d-827b-f537-bf21-0093d94ffec7";
$apps[$x]['menu'][3]['parent_uuid'] = "594d99c5-6128-9c88-ca35-4b33392cec0f";
$apps[$x]['menu'][3]['category'] = "internal";
$apps[$x]['menu'][3]['path'] = "/core/groups/groups.php";
$apps[$x]['menu'][3]['groups'][] = "superadmin";
?>
+490
View File
@@ -0,0 +1,490 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permisions
if (permission_exists('group_permissions') || if_group("superadmin")) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//include the header
$document['title'] = $text['title-group_permissions'];
require_once "resources/header.php";
//include paging
require_once "resources/paging.php";
//get the list of installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$x=0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
//if there are no permissions listed in v_group_permissions then set the default permissions
$sql = "select count(*) as count from v_group_permissions ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$group_permission_count = $row["count"];
break; //limit to 1 row
}
unset ($prep_statement);
if ($group_permission_count == 0) {
//no permissions found add the defaults
foreach($apps as $app) {
foreach ($app['permissions'] as $row) {
foreach ($row['groups'] as $group) {
//add the record
$sql = "insert into v_group_permissions ";
$sql .= "(";
$sql .= "group_permission_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$row['name']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
//get the group uuid, lookup domain uuid (if any) and name
$group_uuid = check_str($_REQUEST['group_uuid']);
$sql = "select domain_uuid, group_name from v_groups ";
$sql .= "where group_uuid = '".$group_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$group_name = $row["group_name"];
break; //limit to 1 row
}
unset ($prep_statement);
//get the permissions assigned to this group
$sql = " select * from v_group_permissions ";
$sql .= "where group_name = '$group_name' ";
$sql .= "and domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ");
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$permission_name = $row["permission_name"];
$permissions_db[$permission_name] = "true";
}
//show the db checklist
//echo "<pre>";
//print_r($permissions_db);
//echo "</pre>";
//list all the permissions in the database
foreach($apps as $app) {
if (isset($app['permissions'])) foreach ($app['permissions'] as $row) {
if ($permissions_db[$row['name']] == "true") {
$permissions_db_checklist[$row['name']] = "true";
}
else {
$permissions_db_checklist[$row['name']] = "false";
}
}
}
//show the db checklist
//echo "<pre>";
//print_r($permissions_db_checklist);
//echo "</pre>";
//process the http post
if (count($_POST)>0) {
foreach($_POST['permissions_form'] as $permission) {
$permissions_form[$permission] = "true";
}
//list all the permissions
foreach($apps as $app) {
foreach ($app['permissions'] as $row) {
if ($permissions_form[$row['name']] == "true") {
$permissions_form_checklist[$row['name']] = "true";
}
else {
$permissions_form_checklist[$row['name']] = "false";
}
}
}
//show the form db checklist
//echo "<pre>";
//print_r($permissions_form_checklist);
//echo "</pre>";
//list all the permissions
foreach($apps as $app) {
foreach ($app['permissions'] as $row) {
$permission = $row['name'];
if ($permissions_db_checklist[$permission] == "true" && $permissions_form_checklist[$permission] == "true") {
//matched do nothing
}
if ($permissions_db_checklist[$permission] == "false" && $permissions_form_checklist[$permission] == "false") {
//matched do nothing
}
if ($permissions_db_checklist[$permission] == "true" && $permissions_form_checklist[$permission] == "false") {
//delete the record
$sql = "delete from v_group_permissions ";
$sql .= "where group_name = '$group_name' ";
$sql .= "and permission_name = '$permission' ";
$db->exec(check_sql($sql));
unset($sql);
foreach($apps as $app) {
foreach ($app['permissions'] as $row) {
if ($row['name'] == $permission) {
$sql = "delete from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '".$row['menu']['uuid']."' ";
$sql .= "and group_name = '$group_name' ";
$sql .= "and menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$db->exec(check_sql($sql));
unset($sql);
$sql = " select menu_item_parent_uuid from v_menu_items ";
$sql .= "where menu_item_uuid = '".$row['menu']['uuid']."' ";
$sql .= "and menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$menu_item_parent_uuid = $row["menu_item_parent_uuid"];
}
unset ($prep_statement);
$sql = " select * from v_menu_items as i, v_menu_item_groups as g ";
$sql .= "where i.menu_item_uuid = g.menu_item_uuid ";
$sql .= "and i.menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$sql .= "and i.menu_item_parent_uuid = '$menu_item_parent_uuid' ";
$sql .= "and g.group_name = '$group_name' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
if ($result_count == 0) {
$sql = "delete from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '$menu_item_parent_uuid' ";
$sql .= "and group_name = '$group_name' ";
$sql .= "and menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
}
}
}
//set the permission to false in the permissions_db_checklist
$permissions_db_checklist[$permission] = "false";
}
if ($permissions_db_checklist[$permission] == "false" && $permissions_form_checklist[$permission] == "true") {
//add the record
$sql = "insert into v_group_permissions ";
$sql .= "(";
$sql .= "group_permission_uuid, ";
if ($domain_uuid != '') {
$sql .= "domain_uuid, ";
}
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
if ($domain_uuid != '') {
$sql .= "'".$domain_uuid."', ";
}
$sql .= "'$permission', ";
$sql .= "'$group_name' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
foreach($apps as $app) {
foreach ($app['permissions'] as $row) {
if ($row['name'] == $permission) {
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'b4750c3f-2a86-b00d-b7d0-345c14eca286', ";
$sql .= "'".$row['menu']['uuid']."', ";
$sql .= "'$group_name' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
$sql = " select menu_item_parent_uuid from v_menu_items ";
$sql .= "where menu_item_uuid = '".$row['menu']['uuid']."' ";
$sql .= "and menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$menu_item_parent_uuid = $row["menu_item_parent_uuid"];
}
unset ($prep_statement);
$sql = " select * from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '$menu_item_parent_uuid' ";
$sql .= "and group_name = '$group_name' ";
$sql .= "and menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
if ($result_count == 0) {
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'b4750c3f-2a86-b00d-b7d0-345c14eca286', ";
$sql .= "'$menu_item_parent_uuid', ";
$sql .= "'$group_name' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
}
}
}
//set the permission to true in the permissions_db_checklist
$permissions_db_checklist[$permission] = "true";
}
}
}
$_SESSION["message"] = $text['message-update'];
header("Location: groups.php");
return;
}
//copy group javascript
echo "<script language='javascript' type='text/javascript'>\n";
echo " function copy_group() {\n";
echo " var new_group_name;\n";
echo " var new_group_desc;\n";
echo " new_group_name = prompt('".$text['message-new_group_name']."');\n";
echo " if (new_group_name != null) {\n";
echo " new_group_desc = prompt('".$text['message-new_group_description']."');\n";
echo " if (new_group_desc != null) {\n";
echo " window.location = 'permissions_copy.php?group_name=".$group_name."&new_group_name=' + new_group_name + '&new_group_desc=' + new_group_desc;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "\n";
echo " $( document ).ready(function() {\n";
echo " $('#group_permission_search').focus();\n";
echo " });\n";
echo "</script>\n";
//prevent enter key submit on search field
echo "<script language='javascript' type='text/javascript'>\n";
echo " $(document).ready(function() {\n";
echo " $('#group_permission_search').keydown(function(event){\n";
echo " if (event.keyCode == 13) {\n";
echo " event.preventDefault();\n";
echo " return false;\n";
echo " }\n";
echo " });\n";
echo " });\n";
echo "</script>\n";
//show the content
echo "<form method='post' name='frm' action=''>\n";
echo "<input type='hidden' name='domain_uuid' value='".$domain_uuid."'>\n";
echo "<table cellpadding='0' cellspacing='0' width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align=\"left\" nowrap=\"nowrap\" valign='top'>";
echo " <b>".$text['header-group_permissions'].$group_name."</b>";
echo " <br><br>";
echo " </td>\n";
echo " <td width='50%' align=\"right\" valign='top'>\n";
echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='groups.php'\" value='".$text['button-back']."'> ";
echo " <input type='text' id='group_permission_search' class='formfld' style='min-width: 150px; width:150px; max-width: 150px;' placeholder=\"".$text['label-search']."\" onkeyup='permission_search();'>\n";
echo " <input type='button' class='btn' alt='".$text['button-copy']."' onclick='copy_group();' value='".$text['button-copy']."'>";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align=\"left\" colspan='2'>\n";
echo " ".$text['description-group_permissions']."\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br /><br />\n";
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//list all the permissions
foreach($apps as $app_index => $app) {
//hide apps for which there are no permissions
if (!is_array($app['permissions']) || sizeof($app['permissions']) == 0) { continue; }
$app_name = $app['name'];
$description = $app['description']['en-us'];
//used to hide apps, even if permissions don't exist
$array_apps_unique[] = str_replace(' ','_',strtolower($app['name']));
echo "<div id='app_".str_replace(' ','_',strtolower($app['name']))."'>";
echo "<b>".$app_name."</b><br />\n";
if ($description != '') { echo $description."<br />\n"; }
echo "<br>";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <th style='text-align: center; padding: 0 7px;'><input type='checkbox' id='check_toggle_".$app_index."' onclick=\"check_toggle('".$app_index."', this.checked);\"></th>\n";
echo " <th width='30%'>".$text['label-permission_permissions']."</th>\n";
echo " <th width='70%'>".$text['label-permission_description']."</th>\n";
echo " <tr>\n";
foreach ($app['permissions'] as $permission_index => $row) {
$checked = ($permissions_db_checklist[$row['name']] == "true") ? "checked='checked'" : null;
echo "<tr id='permission_".$row['name']."'>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: center; padding: 3px 0px 0px 0px;'><input type='checkbox' name='permissions_form[]' id='perm_".$app_index."_".$permission_index."' ".$checked." value='".$row['name']."'></td>\n";
echo " <td valign='top' nowrap='nowrap' class='".$row_style[$c]."' onclick=\"(document.getElementById('perm_".$app_index."_".$permission_index."').checked) ? document.getElementById('perm_".$app_index."_".$permission_index."').checked = false : document.getElementById('perm_".$app_index."_".$permission_index."').checked = true;\">".$row['name']."</td>\n";
echo " <td valign='top' class='row_stylebg' onclick=\"(document.getElementById('perm_".$app_index."_".$permission_index."').checked) ? document.getElementById('perm_".$app_index."_".$permission_index."').checked = false : document.getElementById('perm_".$app_index."_".$permission_index."').checked = true;\">".$row['description']."&nbsp;</td>\n";
echo "</tr>\n";
$c = ($c == 0) ? 1 : 0;
//populate search/filter arrays
$array_apps[] = str_replace(' ','_',strtolower($app['name']));
$array_apps_original[] = $app['name'];
$array_permissions[] = $row['name'];
$array_descriptions[] = str_replace('"','\"',$row['description']);
$app_permissions[$app_index][] = "perm_".$app_index."_".$permission_index;
}
echo " <tr>\n";
echo " <td colspan='3' align='right' style='padding-top: 15px;'><input type='submit' name='submit' class='btn' value='".$text['button-save']."'></td>\n";
echo " </tr>\n";
echo "</table>";
echo "</div>\n\n";
} //end foreach
echo "<br>";
unset($sql, $result, $row_count);
echo "</form>\n";
//check or uncheck all category checkboxes
echo "<script>\n";
echo "function check_toggle(app_index, toggle_state) {\n";
echo " switch (app_index) {\n";
foreach ($app_permissions as $app_index => $app_permission_ids) {
echo " case '".$app_index."':\n";
foreach ($app_permission_ids as $app_permission_id) {
echo " document.getElementById('".$app_permission_id."').checked = toggle_state;\n";
}
echo " break;\n";
}
echo " }\n";
echo "}\n";
echo "</script>\n";
//setting search script
echo "<script>\n";
echo " var apps_unique = new Array(\"".implode('","', $array_apps_unique)."\");\n";
echo " var apps = new Array(\"".implode('","', $array_apps)."\");\n";
echo " var apps_original = new Array(\"".implode('","', $array_apps_original)."\");\n";
echo " var permissions = new Array(\"".implode('","', $array_permissions)."\");\n";
echo " var descriptions = new Array(\"".implode('","', $array_descriptions)."\");\n";
echo "\n";
echo " function permission_search() {\n";
echo " var criteria = $('#group_permission_search').val();\n";
echo " if (criteria.length >= 2) {\n";
echo " for (var x = 0; x < apps_unique.length; x++) {\n";
echo " document.getElementById('app_'+apps_unique[x]).style.display = 'none';\n";
echo " }\n";
echo " for (var x = 0; x < permissions.length; x++) {\n";
echo " if (\n";
echo " apps_original[x].toLowerCase().match(criteria.toLowerCase()) ||\n";
echo " permissions[x].toLowerCase().match(criteria.toLowerCase()) ||\n";
echo " descriptions[x].toLowerCase().match(criteria.toLowerCase())\n";
echo " ) {\n";
echo " document.getElementById('app_'+apps[x]).style.display = '';\n";
echo " document.getElementById('permission_'+permissions[x]).style.display = '';\n";
echo " }\n";
echo " else {\n";
echo " document.getElementById('permission_'+permissions[x]).style.display = 'none';\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " else {\n";
echo " for (var x = 0; x < permissions.length; x++) {\n";
echo " document.getElementById('app_'+apps[x]).style.display = '';\n";
echo " document.getElementById('permission_'+permissions[x]).style.display = '';\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "\n";
echo "</script>\n";
//show the footer
require_once "resources/footer.php";
?>
+184
View File
@@ -0,0 +1,184 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2014
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_add')) {
//access allowed
}
else {
echo "access denied";
return;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the http values and set them as variables
if (count($_POST) > 0) {
//set the variables
$group_name = check_str($_POST["group_name"]);
if (permission_exists('group_domain')) {
$domain_uuid = check_str($_POST["domain_uuid"]);
}
else {
$domain_uuid = $_SESSION['domain_uuid'];
}
$group_description = check_str($_POST["group_description"]);
//check for global/domain duplicates
$sql = "select count(*) as num_rows from v_groups where ";
$sql .= "group_name = '".$group_name."' ";
$sql .= "and domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ");
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$group_exists = ($row['num_rows'] > 0) ? true : false;
}
else {
$group_exists = false;
}
unset($sql, $prep_statement, $row);
//insert group
if (!$group_exists) {
$sql = "insert into v_groups ";
$sql .= "(";
$sql .= "group_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "group_name, ";
$sql .= "group_description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= (($domain_uuid != '') ? "'".$domain_uuid."'" : "null").", ";
$sql .= "'".$group_name."', ";
$sql .= "'".$group_description."' ";
$sql .= ")";
if (!$db->exec($sql)) {
//echo $db->errorCode() . "<br>";
$info = $db->errorInfo();
echo "<pre>".print_r($info, true)."</pre>";
exit;
// $info[0] == $db->errorCode() unified error code
// $info[1] is the driver specific error code
// $info[2] is the driver specific error string
}
$_SESSION["message"] = $text['message-add'];
header("Location: groups.php");
}
else {
$_SESSION['message_mood'] = 'negative';
$_SESSION["message"] = $text['message-group_exists'];
header("Location: groupadd.php");
}
//redirect the user
return;
}
//include the header
include "resources/header.php";
$document['title'] = $text['title-group_add'];
//show the content
echo "<form name='login' method='post' action=''>\n";
echo "<table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td align='left' valign='top'>\n";
echo " <b>".$text['header-group_add']."</b>\n";
echo " <br><br>\n";
echo " ".$text['description-group_add']."\n";
echo " </td>\n";
echo " <td align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='back' onclick=\"window.location='groups.php'\" value='".$text['button-back']."'> ";
echo " <input type='submit' class='btn' value=\"".$text['button-save']."\">\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br>";
echo "<table width='100%' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncellreq'>\n";
echo $text['label-group_name']."\n";
echo "</td>\n";
echo "<td width='70%' align='left' class='vtable'>\n";
echo " <input type='text' class='formfld' name='group_name'>\n";
echo "</td>\n";
echo "</tr>\n";
if (permission_exists('group_domain')) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-domain']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='domain_uuid'>\n";
echo " <option value='' ".((strlen($domain_uuid) == 0) ? "selected='selected'" : null).">".$text['option-global']."</option>\n";
foreach ($_SESSION['domains'] as $row) {
echo " <option value='".$row['domain_uuid']."' ".(($row['domain_uuid'] == $domain_uuid) ? "selected='selected'" : null).">".$row['domain_name']."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-domain_name']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncell'>\n";
echo $text['label-group_description']."\n";
echo "</td>\n";
echo "<td align='left' class='vtable'>\n";
echo "<textarea name='group_description' class='formfld' style='width: 250px; height: 50px;'></textarea>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan='2' align='right'>\n";
echo " <br />";
echo " <input type='submit' class='btn' value=\"".$text['button-save']."\">\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>";
echo "</form>";
//include the footer
include "resources/footer.php";
?>
+98
View File
@@ -0,0 +1,98 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2015
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_delete') || if_group("superadmin")) {
//access allowed
}
else {
echo "access denied";
return;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the http value and set as a variable
$group_uuid = check_str($_GET["id"]);
//validate the uuid
if (is_uuid($group_uuid)) {
//get the group from v_groups
$sql = "select domain_uuid, group_name from v_groups ";
$sql .= "where group_uuid = '".$group_uuid."' ";
if (!permission_exists('group_domain')) {
$sql .= "and (domain_uuid = '".$_SESSION['domain_uuid']."' or domain_uuid is null); ";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$group_name = $row["group_name"];
}
unset ($prep_statement);
//delete the group users
$sql = "delete from v_group_users ";
$sql .= "where group_uuid = '".$group_uuid."' ";
if (!$db->exec($sql)) {
$error = $db->errorInfo();
print_r($error);
}
//delete the group permissions
if (strlen($group_name) > 0) {
$sql = "delete from v_group_permissions ";
$sql .= "where group_name = '".$group_name."' ";
$sql .= "and domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ");
if (!$db->exec($sql)) {
$error = $db->errorInfo();
print_r($error);
}
}
//delete the group
$sql = "delete from v_groups ";
$sql .= "where group_uuid = '".$group_uuid."' ";
$sql .= "and domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ");
if (!$db->exec($sql)) {
$error = $db->errorInfo();
print_r($error);
}
}
//redirect the user
$_SESSION["message"] = $text['message-delete'];
header("Location: groups.php");
?>
+314
View File
@@ -0,0 +1,314 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2014
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_edit')) {
//access allowed
}
else {
echo "access denied";
return;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//process update
if (count($_POST) > 0) {
//set the variables
$group_uuid = check_str($_POST['group_uuid']);
$group_name = check_str($_POST['group_name']);
$group_name_previous = check_str($_POST['group_name_previous']);
$domain_uuid = check_str($_POST["domain_uuid"]);
$domain_uuid_previous = check_str($_POST["domain_uuid_previous"]);
$group_description = check_str($_POST["group_description"]);
//check for global/domain duplicates
$sql = "select count(*) as num_rows from v_groups where ";
$sql .= "group_name = '".$group_name."' ";
$sql .= "and group_uuid <> '".$group_uuid."' ";
$sql .= "and domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ");
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$group_exists = ($row['num_rows'] > 0) ? true : false;
}
else {
$group_exists = false;
}
unset($sql, $prep_statement, $row);
//update group
if (!$group_exists) {
$sql = "update v_groups ";
$sql .= "set ";
$sql .= "group_name = '".$group_name."', ";
$sql .= "domain_uuid = ".(($domain_uuid != '') ? "'".$domain_uuid."'" : "null").", ";
$sql .= "group_description = '".$group_description."' ";
$sql .= "where group_uuid = '".$group_uuid."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
echo "<pre>".print_r($error, true)."</pre>";
exit;
}
//group changed from global to domain-specific
if ($domain_uuid_previous == '' && $domain_uuid != '') {
//remove any users assigned to the group from the old domain
$sql = "delete from v_group_users where group_uuid = '".$group_uuid."' and domain_uuid <> '".$domain_uuid."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//update permissions to use new domain uuid
$sql = "update v_group_permissions set domain_uuid = '".$domain_uuid."' where group_name = '".$group_name_previous."' and domain_uuid is null ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name
if ($group_name != $group_name_previous && $group_name != '') {
//change group name in group users
$sql = "update v_group_users set group_name = '".$group_name."' where group_uuid = '".$group_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name in permissions
$sql = "update v_group_permissions set group_name = '".$group_name."' where domain_uuid = '".$domain_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
}
}
//group changed from one domain to another
else if ($domain_uuid_previous != '' && $domain_uuid != '' && $domain_uuid_previous != $domain_uuid) {
//remove any users assigned to the group from the old domain
$sql = "delete from v_group_users where group_uuid = '".$group_uuid."' and domain_uuid = '".$domain_uuid_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//update permissions to use new domain uuid
$sql = "update v_group_permissions set domain_uuid = '".$domain_uuid."' where group_name = '".$group_name_previous."' and domain_uuid = '".$domain_uuid_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name
if ($group_name != $group_name_previous && $group_name != '') {
//change group name in group users
$sql = "update v_group_users set group_name = '".$group_name."' where group_uuid = '".$group_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name in permissions
$sql = "update v_group_permissions set group_name = '".$group_name."' where domain_uuid = '".$domain_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
}
}
//group changed from domain-specific to global
else if ($domain_uuid_previous != '' && $domain_uuid == '') {
//change group name
if ($group_name != $group_name_previous && $group_name != '') {
//change group name in group users
$sql = "update v_group_users set group_name = '".$group_name."' where group_uuid = '".$group_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name in permissions
$sql = "update v_group_permissions set group_name = '".$group_name."' where domain_uuid = '".$domain_uuid_previous."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
}
//update permissions to not use a domain uuid
$sql = "update v_group_permissions set domain_uuid = null where group_name = '".$group_name."' and domain_uuid = '".$domain_uuid_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
}
//domain didn't change, but name may still
else {
//change group name
if ($group_name != $group_name_previous && $group_name != '') {
//change group name in group users
$sql = "update v_group_users set group_name = '".$group_name."' where group_uuid = '".$group_uuid."' and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
//change group name in permissions
$sql = "update v_group_permissions set group_name = '".$group_name."' where domain_uuid ".(($domain_uuid != '') ? " = '".$domain_uuid."' " : " is null ")." and group_name = '".$group_name_previous."' ";
if (!$db->exec(check_sql($sql))) {
$error = $db->errorInfo();
//echo "<pre>".print_r($error, true)."</pre>"; exit;
}
}
}
$_SESSION["message"] = $text['message-update'];
header("Location: groups.php");
}
else {
$_SESSION['message_mood'] = 'negative';
$_SESSION["message"] = $text['message-group_exists'];
header("Location: groupedit.php?id=".$group_uuid);
}
//redirect the user
return;
}
//pre-populate the form
$group_uuid = check_str($_REQUEST['id']);
if ($group_uuid != '') {
$sql = "select * from v_groups where ";
$sql .= "group_uuid = '".$group_uuid."' ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$group_name = $row['group_name'];
$domain_uuid = $row['domain_uuid'];
$group_description = $row['group_description'];
}
}
//include the header
include "resources/header.php";
$document['title'] = $text['title-group_edit'];
//copy group javascript
echo "<script language='javascript' type='text/javascript'>\n";
echo " function copy_group() {\n";
echo " var new_group_name;\n";
echo " var new_group_desc;\n";
echo " new_group_name = prompt('".$text['message-new_group_name']."');\n";
echo " if (new_group_name != null) {\n";
echo " new_group_desc = prompt('".$text['message-new_group_description']."');\n";
echo " if (new_group_desc != null) {\n";
echo " window.location = 'permissions_copy.php?group_name=".$group_name."&new_group_name=' + new_group_name + '&new_group_desc=' + new_group_desc;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//show the content
echo "<form name='login' method='post' action=''>\n";
echo "<input type='hidden' name='group_uuid' value='".$group_uuid."'>\n";
echo "<table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td align='left' valign='top'>\n";
echo " <b>".$text['header-group_edit']."</b>\n";
echo " <br><br>\n";
echo " ".$text['description-group_edit']."\n";
echo " </td>\n";
echo " <td align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='back' onclick=\"window.location='groups.php'\" value='".$text['button-back']."'> ";
echo " <input type='button' class='btn' alt='".$text['button-copy']."' onclick='copy_group();' value='".$text['button-copy']."'>";
echo " <input type='submit' class='btn' value=\"".$text['button-save']."\">\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br>";
echo "<table width='100%' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncellreq' valign='top'>\n";
echo $text['label-group_name']."\n";
echo "</td>\n";
echo "<td width='70%' align='left' class='vtable'>\n";
echo " <input type='hidden' name='group_name_previous' value=\"".$group_name."\">\n";
echo " <input type='text' class='formfld' name='group_name' value=\"".$group_name."\">\n";
echo "</td>\n";
echo "</tr>\n";
if (permission_exists('group_domain')) {
echo "<tr>\n";
echo "<td class='vncell' valign='top'>\n";
echo " ".$text['label-domain']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input type='hidden' name='domain_uuid_previous' value='".$domain_uuid."'>\n";
echo " <select class='formfld' name='domain_uuid'>\n";
echo " <option value='' ".((strlen($domain_uuid) == 0) ? "selected='selected'" : null).">".$text['option-global']."</option>\n";
foreach ($_SESSION['domains'] as $row) {
echo "<option value='".$row['domain_uuid']."' ".(($row['domain_uuid'] == $domain_uuid) ? "selected='selected'" : null).">".$row['domain_name']."</option>\n";
}
echo " </select>\n";
echo " <br />\n";
echo $text['description-domain_name']."\n";
echo "</td>\n";
echo "</tr>\n";
}
else {
echo "<input type='hidden' name='domain_uuid' value='".$domain_uuid."'>";
}
echo "<tr>\n";
echo "<td class='vncell' valign='top'>\n";
echo $text['label-group_description']."\n";
echo "</td>\n";
echo "<td align='left' class='vtable' valign='top'>\n";
echo " <textarea name='group_description' class='formfld' style='width: 250px; height: 50px;'>".$group_description."</textarea>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan='2' align='right'>\n";
echo " <br />";
echo " <input type='submit' class='btn' value=\"".$text['button-save']."\">\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>";
echo "</form>";
//include the footer
include "resources/footer.php";
?>
+87
View File
@@ -0,0 +1,87 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_member_add') || if_group("superadmin")) {
//access allowed
}
else {
echo "access denied";
return;
}
//requires a superadmin to add a user to the superadmin group
if (!if_group("superadmin") && $_GET["group_name"] == "superadmin") {
echo "access denied";
return;
}
//get the http values and set them as variables
$domain_uuid = check_str($_POST["domain_uuid"]);
$group_uuid = check_str($_POST["group_uuid"]);
$group_name = check_str($_POST["group_name"]);
$user_uuid = check_str($_POST["user_uuid"]);
//add the user to the group
if (is_uuid($user_uuid) && is_uuid($group_uuid) && strlen($group_name) > 0) {
$sql = "insert into v_group_users ";
$sql .= "(";
$sql .= "group_user_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "group_uuid, ";
$sql .= "group_name, ";
$sql .= "user_uuid ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$domain_uuid."', ";
$sql .= "'".$group_uuid."', ";
$sql .= "'".$group_name."', ";
$sql .= "'".$user_uuid."' ";
$sql .= ")";
if (!$db->exec($sql)) {
$info = $db->errorInfo();
echo "<pre>".print_r($info, true)."</pre>";
exit;
}
else {
//log the success
//$log_type = 'group'; $log_status='add'; $log_add_user=$_SESSION["username"]; $log_desc= "username: ".$username." added to group: ".$group_name;
//log_add($db, $log_type, $log_status, $log_desc, $log_add_user, $_SERVER["REMOTE_ADDR"]);
}
}
//redirect the user
$_SESSION["message"] = $text['message-update'];
header("Location: groupmembers.php?group_uuid=".$group_uuid."&group_name=".$group_name);
?>
+70
View File
@@ -0,0 +1,70 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_member_delete') || if_group("superadmin")) {
//access allowed
}
else {
echo "access denied";
return;
}
//requires a superadmin to delete superadmin group
if (!if_group("superadmin") && $_GET["group_name"] == "superadmin") {
echo "access denied";
return;
}
//get the http values and set them as variables
$group_name = check_str($_GET["group_name"]);
$user_uuid = check_str($_GET["user_uuid"]);
$group_uuid = check_str($_GET["group_uuid"]);
//delete the group membership
$sql_delete = "delete from v_group_users ";
$sql_delete .= "where user_uuid = '".$user_uuid."' ";
$sql_delete .= "and group_uuid = '".$group_uuid."' ";
if (!$db->exec($sql_delete)) {
$info = $db->errorInfo();
echo "<pre>".print_r($info, true)."</pre>";
exit;
}
else {
//$log_type = 'group'; $log_status='remove'; $log_add_user=$_SESSION["username"]; $log_desc= "username: ".$username." removed from group: ".$group_name;
//log_add($db, $log_type, $log_status, $log_desc, $log_add_user, $_SERVER["REMOTE_ADDR"]);
}
//redirect the user
$_SESSION["message"] = $text['message-delete'];
header("Location: groupmembers.php?group_uuid=".$group_uuid."&group_name=".$group_name);
?>
+191
View File
@@ -0,0 +1,191 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('group_members_view') || if_group("superadmin")) {
//access allowed
}
else {
echo "access denied";
return;
}
//requires a superadmin to view members of the superadmin group
if (!if_group("superadmin") && $_GET["group_name"] == "superadmin") {
echo "access denied";
return;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get the group uuid, lookup domain uuid (if any) and name
$group_uuid = check_str($_REQUEST['group_uuid']);
$sql = "select domain_uuid, group_name from v_groups ";
$sql .= "where group_uuid = '".$group_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$group_name = $row["group_name"];
break; //limit to 1 row
}
unset ($prep_statement);
//define the if group members function
function is_group_member($group_uuid, $user_uuid) {
global $db, $domain_uuid;
$sql = "select * from v_group_users ";
$sql .= "where user_uuid = '".$user_uuid."' ";
$sql .= "and group_uuid = '".$group_uuid."' ";
$sql .= "and domain_uuid = '".(($domain_uuid != '') ? $domain_uuid : $_SESSION['domain_uuid'])."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
if (count($prep_statement->fetchAll(PDO::FETCH_NAMED)) == 0) { return true; } else { return false; }
unset ($sql, $prep_statement);
}
//$exampledatareturned = example("apples", 1);
//get the the users array
if (permission_exists('group_member_add')) {
$sql = "select * from v_users where ";
if ($domain_uuid != '') {
$sql .= "domain_uuid = '".$domain_uuid."' ";
}
else {
$sql .= "domain_uuid = '".$_SESSION['domain_uuid']."' ";
}
$sql .= "order by username ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
}
//get the groups users
$sql = "select u.user_uuid, u.username, gu.group_user_uuid, gu.domain_uuid, gu.group_uuid ";
$sql .= "from v_group_users as gu, v_users as u, v_domains as d ";
$sql .= "where gu.user_uuid = u.user_uuid ";
$sql .= "and gu.domain_uuid = d.domain_uuid ";
if ($domain_uuid != '') {
$sql .= "and gu.domain_uuid = '".$domain_uuid."' ";
}
if (!permission_exists('user_all')) {
$sql .= "and u.domain_uuid = '".$_SESSION['domain_uuid']."' ";
}
$sql .= "and gu.group_uuid = '".$group_uuid."' ";
$sql .= "order by d.domain_name asc, u.username asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
//include the header
require_once "resources/header.php";
$document['title'] = $text['title-group_members'];
//show the content
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo " <tr>\n";
echo " <td width='100%' align='left' valign='top'>\n";
echo " <b>".$text['header-group_members'].$group_name."</b>\n";
echo " </td>\n";
echo " <td align='right' nowrap='nowrap' valign='middle'>\n";
echo " <input type='button' class='btn' style='margin-right: 15px;' alt='".$text['button-back']."' onclick=\"window.location='groups.php'\" value='".$text['button-back']."'>";
echo " </td>";
if (permission_exists('group_member_add')) {
echo " <td align='right' nowrap='nowrap' valign='top'>\n";
echo " <form method='post' action='groupmemberadd.php'>";
echo " <select name='user_uuid' style='width: 200px;' class='formfld'>\n";
echo " <option value=''></option>\n";
foreach($users as $field) {
if (is_group_member($group_uuid, $field['user_uuid'])) {
echo " <option value='".$field['user_uuid']."'>".$field['username']."</option>\n";
}
}
unset($sql, $users);
echo " </select>";
echo " <input type='hidden' name='domain_uuid' value='".(($domain_uuid != '') ? $domain_uuid : $_SESSION['domain_uuid'])."'>";
echo " <input type='hidden' name='group_uuid' value='".$group_uuid."'>";
echo " <input type='hidden' name='group_name' value='".$group_name."'>";
echo " <input type='submit' class='btn' value='".$text['button-add_member']."'>";
echo " </form>";
echo " </td>\n";
}
echo " </tr>\n";
echo "</table>\n";
echo "<br>";
$echo = "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
$echo .= "<tr>\n";
if (permission_exists('user_all')) {
$echo .= "<th width='30%' align='left' nowrap>".$text['label-domain']."</th>\n";
}
$echo .= " <th align='left' nowrap>".$text['label-username']."</th>\n";
$echo .= " <td width='25' align='right' nowrap>&nbsp;</td>\n";
$echo .= "</tr>\n";
$count = 0;
foreach ($result as &$row) {
$group_user_uuid = $row["group_user_uuid"];
$username = $row["username"];
$user_uuid = $row["user_uuid"];
$domain_uuid = $row["domain_uuid"];
$group_uuid = $row["group_uuid"];
$echo .= "<tr>";
if (permission_exists('user_all')) {
$echo .= "<td align='left' class='".$row_style[$c]."' nowrap>".$_SESSION['domains'][$domain_uuid]['domain_name']."</td>\n";
}
$echo .= "<td align='left' class='".$row_style[$c]."' nowrap>".$username."</td>\n";
$echo .= "<td class='list_control_icons' style='width: 25px;'>";
if (permission_exists('group_member_delete')) {
$echo .= "<a href='groupmemberdelete.php?user_uuid=".$user_uuid."&group_name=".$group_name."&group_uuid=".$group_uuid."' onclick=\"return confirm('".$text['confirm-delete']."')\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
}
$echo .= "</td>\n";
$echo .= "</tr>\n";
$c = ($c) ? 0 : 1;
$group_users[] = $row["user_uuid"];
$count++;
}
$echo .= "</table>\n";
$echo .= "<br /><br />";
echo $echo;
//include the footer
require_once "resources/footer.php";
?>
+234
View File
@@ -0,0 +1,234 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2014
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check the permissions
if (if_group("admin") || if_group("superadmin")) {
//access allowed
}
else {
echo "access denied";
return;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//show the header
require_once "resources/header.php";
$document['title'] = $text['title-group_manager'];
if (isset($_REQUEST["change"])) {
//get the values from the HTTP POST and save them as PHP variables
$change = check_str($_REQUEST["change"]);
$group_uuid = check_str($_REQUEST["group_uuid"]);
$group_name = check_str($_REQUEST["group_name"]);
$sql = "update v_groups set group_protected = '".$change."' ";
$sql .= "where group_uuid = '".$group_uuid."' ";
if (!permission_exists('group_domain')) {
$sql .= "and (";
$sql .= " domain_uuid = '".$domain_uuid."' ";
$sql .= " or domain_uuid is null ";
$sql .= ") ";
}
$db->exec(check_sql($sql));
unset($sql);
$_SESSION["message"] = $text['message-update'];
}
//get the groups
$sql = "select * from v_groups ";
if (!(permission_exists('group_all') && $_GET['showall'] == 'true')) {
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "or domain_uuid is null ";
}
$sql .= "order by domain_uuid desc, group_name asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$groups = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset($sql, $prep_statement);
//$system_groups = array('superadmin','admin','user','public','agent');
$system_groups = array();
//get group counts
$sql = "select group_uuid, count(user_uuid) as group_count from v_group_users ";
if (!permission_exists('user_all')) {
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
}
$sql .= "group by group_uuid ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as $row) {
$group_counts[$row['group_uuid']] = $row['group_count'];
}
unset($sql, $prep_statement, $result, $row);
//show the content
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
echo "<tr>";
echo "<td width='50%' valign='top'>";
echo " <b>".$text['header-group_manager']."</b>";
echo " <br><br>";
echo "</td>";
echo "<td width='50%' align='right' valign='top'>";
if (permission_exists('group_all')) {
if ($_GET['showall'] != 'true') {
echo "<input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='groups.php?showall=true';\">\n";
}
}
if (permission_exists('user_view')) {
echo " <input type='button' class='btn' onclick=\"window.location='index.php'\" value='".$text['header-user_manager']."'>";
}
if (permission_exists('group_edit')) {
echo " <input type='button' class='btn' alt='".$text['button-restore']."' onclick=\"window.location='permissions_default.php'\" value='".$text['button-restore']."'>";
}
echo "</td>\n";
echo "</tr>";
echo "</table>";
echo "<br>";
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
$echo = "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
$echo .= "<tr>\n";
if (permission_exists('group_all') && $_GET['showall'] == 'true') {
$echo .= " <th nowrap>".$text['label-domain']."</th>\n";
}
$echo .= " <th nowrap>".$text['label-group_name']."</th>\n";
$echo .= " <th nowrap>".$text['label-group_tools']."</th>\n";
$echo .= " <th style='text-align: center;' nowrap>".$text['label-group_protected']."</th>\n";
$echo .= " <th nowrap>".$text['label-group_description']."</th>\n";
$echo .= " <td class='list_control_icons' style='width: 25px;'>";
if (permission_exists('group_add')) {
$echo .= "<a href='groupadd.php' alt='".$text['button-add']."'>".$v_link_label_add."</a>";
}
$echo .= " </td>\n";
$echo .= "</tr>\n";
$count = 0;
foreach ($groups as &$row) {
$domain_uuid = $row['domain_uuid'];
$group_uuid = $row["group_uuid"];
$group_name = $row["group_name"];
$group_protected = $row["group_protected"];
$group_description = $row["group_description"];
if (strlen($group_name) == 0) { $group_name = "&nbsp;"; }
if (strlen($group_description) == 0) { $group_description = "&nbsp;"; }
$group_description = wordwrap($group_description, 50, "<br />\n");
if (!if_group("superadmin") && $group_name == "superadmin") {
//hide the superadmin group from non superadmin's
}
else {
if (permission_exists('group_edit') && !($domain_uuid == '' && in_array($group_name, $system_groups))) {
$tr_link = (permission_exists('group_edit')) ? "href='groupedit.php?id=".$group_uuid."'" : null;
}
else {
unset($tr_link);
}
$echo .= "<tr ".$tr_link.">\n";
if (permission_exists('group_all') && $_GET['showall'] == 'true') {
$echo .= "<td class='".$row_style[$c]."' nowrap>";
$echo .= ($domain_uuid != '') ? $_SESSION['domains'][$domain_uuid]['domain_name'] : "<i>".$text['label-global']."</i>";
$echo .= "</td>\n";
}
$echo .= "<td class='".$row_style[$c]."' nowrap>";
if (permission_exists('group_edit') && !($domain_uuid == '' && in_array($group_name, $system_groups))) {
$echo .= "<a href='groupedit.php?id=".$group_uuid."'>".(($domain_uuid == '' && $_GET['showall'] != 'true') ? "<i>".$group_name."</i>" : $group_name)."</a>";
}
else {
$echo .= ($domain_uuid == '' && $_GET['showall'] != 'true') ? "<i>".$group_name."</i>" : $group_name;
}
$echo .= "</td>\n";
$echo .= "<td class='".$row_style[$c]." tr_link_void' nowrap>\n";
if (permission_exists('group_add') || if_group("superadmin")) {
$echo .= "<a class='' href='group_permissions.php?group_uuid=".$group_uuid."' title='".$text['label-group_permissions']."'>".$text['label-group_permissions']."</a>&nbsp;&nbsp;&nbsp;";
}
if (permission_exists('group_member_view') || if_group("superadmin")) {
$echo .= "<a class='' href='groupmembers.php?group_uuid=".$group_uuid."&group_name=".$group_name."' title='".$text['label-group_members']."'>".$text['label-group_members']."</a>";
if (sizeof($group_counts) > 0 && $group_counts[$group_uuid] > 0) {
$echo .= " <span style='font-size: 80%;'>(".$group_counts[$group_uuid].")</span>";
}
}
$echo .= "</td>\n";
$echo .= "<td class='".$row_style[$c]." tr_link_void' style='padding: 0px; text-align: center;' align='center' nowrap>\n";
$echo .= " <input type='checkbox' name='group_protected' ".(($group_protected == "true") ? "checked='checked'" : null)." value='".(($group_protected == "true") ? 'false' : 'true')."' onchange=\"window.location='".PROJECT_PATH."/core/users/groups.php?change=".(($group_protected == "true") ? 'false' : 'true')."&group_uuid=".$group_uuid."&group_name=".$group_name.(($_GET['showall'] == 'true') ? "&showall=true" : null)."';\">\n";
$echo .= "</td>\n";
$echo .= "<td class='row_stylebg' nowrap>".$group_description."</td>\n";
$echo .= "<td class='list_control_icons' style='width: 25px;'>";
if (permission_exists('group_edit')) {
if (!($domain_uuid == '' && in_array($group_name, $system_groups))) {
$echo .= "<a href='groupedit.php?id=".$group_uuid."' alt='".$text['button-edit']."'>".$v_link_label_edit."</a>";
}
else {
$echo .= "<span onclick=\"alert('".$text['message-default_system_group']."');\" alt='".$text['button-edit']."'>".str_replace("list_control_icon", "list_control_icon_disabled", $v_link_label_edit)."</span>";
}
}
if (permission_exists('group_delete')) {
if (!($domain_uuid == '' && in_array($group_name, $system_groups))) {
$echo .= "<a href='groupdelete.php?id=".$group_uuid."' onclick=\"return confirm('".$text['confirm-delete']."')\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
}
else {
$echo .= "<span onclick=\"alert('".$text['message-default_system_group']."');\" alt='".$text['button-delete']."'>".str_replace("list_control_icon", "list_control_icon_disabled", $v_link_label_delete)."</span>";
}
}
$echo .= "</td>\n";
$echo .= "</tr>\n";
}
$c = ($c) ? 0 : 1;
$count++;
}
$echo .= "<tr>\n";
$echo .= "<td colspan='".((permission_exists('group_all') && $_GET['showall'] == 'true') ? 5 : 4)."'>&nbsp;</td>";
$echo .= "<td class='list_control_icons' style='width: 25px;'>";
if (permission_exists('group_add')) {
$echo .= "<a href='groupadd.php' alt='".$text['button-add']."'>".$v_link_label_add."</a>";
}
$echo .= "</td>\n";
$echo .= "</tr>\n";
$echo .= "</table>\n";
$echo .= "<br>";
if ($count > 0) {
echo $echo;
}
//show the footer
require_once "resources/footer.php";
?>
+124
View File
@@ -0,0 +1,124 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Sérgio Reis <uc@wavecom.pt>
*/
//includes
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('extension_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//include paging
require_once "resources/paging.php";
//set the http get/post variable(s) to a php variable
if (isset($_REQUEST["group_name"]) && isset($_REQUEST["new_group_name"])) {
//get HTTP values and set as variables
$group_name = check_str($_REQUEST["group_name"]);
$new_group_name = check_str($_REQUEST["new_group_name"]);
$new_group_desc = check_str($_REQUEST["new_group_desc"]);
//get the groups data
$sql = "select * from v_groups ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "or domain_uuid is null ";
$sql .= "and group_name = '".$group_name."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$group_name = $row["group_name"];
}
unset ($prep_statement);
//create new group
$group_uuid = uuid();
$sql = "insert into v_groups ";
$sql .= "( ";
$sql .= "group_uuid, ";
$sql .= "group_name, ";
$sql .= "group_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$group_uuid."', ";
$sql .= "'".$new_group_name."', ";
$sql .= "'".$new_group_desc."' ";
$sql .= ") ";
$db->exec(check_sql($sql));
unset($sql);
//get the group permissions data
$sql = "select * from v_group_permissions ";
$sql .= "where group_name = '".$group_name."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$permission_name = $row["permission_name"];
$group_name = $row["group_name"];
//copy the group permissions
$group_permission_uuid = uuid();
$sql = "insert into v_group_permissions ";
$sql .= "( ";
$sql .= "group_permission_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$group_permission_uuid."', ";
$sql .= "'".$permission_name."', ";
$sql .= "'".$new_group_name."' ";
$sql .= ") ";
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
//redirect the user
$_SESSION["message"] = $text['message-copy'];
}
//redirect
header("Location: groups.php");
?>
+59
View File
@@ -0,0 +1,59 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2014
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//check permisions
if (!$included) {
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('group_edit')) {
//access granted
}
else {
echo "access denied";
return;
}
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//permission restore default
require_once "core/groups/resources/classes/permission.php";
$permission = new permission;
$permission->db = $db;
$permission->restore();
//redirect the users
if (!$included) {
//show a message to the user
$_SESSION["message"] = $text['message-restore'];
header("Location: groups.php");
return;
}
?>
@@ -0,0 +1,133 @@
<?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>
Copyright (C) 2013
All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//define the permission class
class permission {
//delete the permissions
function delete() {
//set the variables
$db = $this->db;
//get unprotected groups and their domain uuids (if any)
$sql = "select group_name, domain_uuid from v_groups where group_protected <> 'true' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
if ($result_count > 0) {
foreach($result as $row) {
$unprotected_groups[$row['group_name']] = $row['domain_uuid'];
}
}
unset ($prep_statement, $sql, $result, $result_count);
//delete unprotected group permissions
if (is_array($unprotected_groups) && sizeof($unprotected_groups) > 0) {
foreach ($unprotected_groups as $unprotected_group_name => $unprotected_domain_uuid) {
$sql = "delete from v_group_permissions where ";
$sql .= "group_name = '".$unprotected_group_name."' ";
$sql .= "and domain_uuid ".(($unprotected_domain_uuid != '') ? " = '".$unprotected_domain_uuid."' " : " is null ");
if (false === $db->exec($sql)) {
//echo $db->errorCode() . "<br>";
$info = $db->errorInfo();
print_r($info);
// $info[0] == $db->errorCode() unified error code
// $info[1] is the driver specific error code
// $info[2] is the driver specific error string
}
}
}
}
//restore the permissions
function restore() {
//set the variables
$db = $this->db;
//delete the group permisisons
$this->delete();
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$x=0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
//restore default permissions
foreach($apps as $row) {
foreach ($row['permissions'] as $permission) {
//set the variables
if ($permission['groups']) {
foreach ($permission['groups'] as $group) {
//check group protection
$sql = "select * from v_groups ";
$sql .= "where group_name = '".$group."' ";
$sql .= "and group_protected = 'true'";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($prep_statement);
if (count($result) == 0) {
//if the item uuid is not currently in the db then add it
$sql = "select * from v_group_permissions ";
$sql .= "where permission_name = '".$permission['name']."' ";
$sql .= "and group_name = '$group' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($prep_statement);
if (count($result) == 0) {
//insert the default permissions into the database
$sql = "insert into v_group_permissions ";
$sql .= "(";
$sql .= "group_permission_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$permission['name']."', ";
$sql .= "'".$group."' ";
$sql .= ");";
$db->exec(check_sql($sql));
unset($sql);
} // if count
} // if prepared statement
} // if count
} // if prepared statement
} // foreach group permission
} // if permission
} // foreach permission
} // foreach app
} // function
} // class
?>
+90
View File
@@ -0,0 +1,90 @@
<?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>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
// make sure the PATH_SEPARATOR is defined
umask(2);
if (!defined("PATH_SEPARATOR")) {
if (strpos($_ENV["OS"], "Win") !== false) {
define("PATH_SEPARATOR", ";");
} else {
define("PATH_SEPARATOR", ":");
}
}
if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html';
// make sure the document_root is set
$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]);
if(PHP_SAPI == 'cli'){
chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME));
$script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]);
$dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME));
if (file_exists('/project_root.php')) {
$path = '/';
} else {
$i = 1;
$path = '';
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
}
$_SERVER["DOCUMENT_ROOT"] = $path;
}else{
$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
}
$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
// try to detect if a project path is being used
if (!defined('PROJECT_PATH')) {
if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) {
define('PROJECT_PATH', '/fusionpbx');
} elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) {
define('PROJECT_PATH', '');
} else {
$dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)));
$i = 1;
$path = $_SERVER["DOCUMENT_ROOT"];
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
if(!file_exists($path. '/project_root.php')){
die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance");
}
$project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
define('PROJECT_PATH', $project_path);
}
$_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH);
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]);
}
?>