Add users and groups php class.

This commit is contained in:
markjcrane
2016-04-03 11:47:06 -06:00
parent df9d78a11f
commit 4292386b6c
3 changed files with 257 additions and 1 deletions

View File

@@ -156,7 +156,7 @@ if ($domains_processed == 1) {
unset ($prep_statement); unset ($prep_statement);
} }
//if there are no permissions listed in v_group_permissions then set the default permissions //if user_enabled is null then set to enabled true
$sql = "select count(*) as count from v_users "; $sql = "select count(*) as count from v_users ";
$sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and user_enabled is null "; $sql .= "and user_enabled is null ";

View File

@@ -0,0 +1,180 @@
<?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) 2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
/**
* groups class provides methods for add, delete groups, and add default groups
*
* @method string add
* @method boolean delete
* @method boolean defaults
*/
class groups {
/**
* Called when the object is created
*/
public function __construct() {
//place holder
}
/**
* Called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* add a group
*/
public function add() {
$id = uuid();
//return $id;
return false;
}
/**
* delete a group
*/
public function delete($id) {
return false;
}
/**
* add defaults groups
*/
public function defaults() {
//get the global database connection
global $db;
//if the are no groups add the default groups
$sql = "SELECT * FROM v_groups ";
$sql .= "WHERE domain_uuid is null ";
$result = $db->query($sql)->fetch();
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
if (count($result) == 0) {
$x = 0;
$tmp[$x]['group_name'] = 'superadmin';
$tmp[$x]['group_description'] = 'Super Administrator Group';
$tmp[$x]['group_protected'] = 'false';
$x++;
$tmp[$x]['group_name'] = 'admin';
$tmp[$x]['group_description'] = 'Administrator Group';
$tmp[$x]['group_protected'] = 'false';
$x++;
$tmp[$x]['group_name'] = 'user';
$tmp[$x]['group_description'] = 'User Group';
$tmp[$x]['group_protected'] = 'false';
$x++;
$tmp[$x]['group_name'] = 'public';
$tmp[$x]['group_description'] = 'Public Group';
$tmp[$x]['group_protected'] = 'false';
$x++;
$tmp[$x]['group_name'] = 'agent';
$tmp[$x]['group_description'] = 'Call Center Agent Group';
$tmp[$x]['group_protected'] = 'false';
$db->beginTransaction();
foreach($tmp as $row) {
if (strlen($row['group_name']) > 0) {
$sql = "insert into v_groups ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "group_uuid, ";
$sql .= "group_name, ";
$sql .= "group_description, ";
$sql .= "group_protected ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "null, ";
$sql .= "'".uuid()."', ";
$sql .= "'".$row['group_name']."', ";
$sql .= "'".$row['group_description']."', ";
$sql .= "'".$row['group_protected']."' ";
$sql .= ")";
$db->exec($sql);
unset($sql);
}
}
$db->commit();
}
unset($prep_statement, $result);
}
//if there are no permissions listed in v_group_permissions then set the default permissions
$sql = "select count(*) as count from v_group_permissions ";
$sql .= "where domain_uuid is null ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$result = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement);
if ($result['count'] == 0) {
//no permissions found add the defaults
$db->beginTransaction();
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 .= "domain_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "null, ";
$sql .= "'".$row['name']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec($sql);
unset($sql);
}
}
}
$db->commit();
}
}
} //end scripts class
/*
//example use
$group = new groups;
$group->defaults();
*/
?>

View File

@@ -0,0 +1,76 @@
<?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) 2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
/**
* users class provides methods for adding and removing users
*
* @method string add
* @method boolean delete
*/
class users {
/**
* Called when the object is created
*/
public function __construct() {
//place holder
}
/**
* Called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* add a user
*/
public function add($username, $password) {
$id = uuid();
//return $id;
return false;
}
/**
* delete a user
*/
public function delete($id) {
return false;
}
} //end scripts class
/*
//example use
$user = new users;
$user->add($username, $password);
*/
?>