2016-10-05 10:29:30 -06: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>
2024-09-12 09:41:01 -06:00
Portions created by the Initial Developer are Copyright (C) 2008-2024
2016-10-05 10:29:30 -06:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
2022-10-10 16:35:14 -06:00
//includes files
2023-06-15 14:28:23 -03:00
require_once dirname ( __DIR__ , 2 ) . "/resources/require.php" ;
2016-10-05 10:29:30 -06:00
require_once "resources/check_auth.php" ;
//add multi-lingual support
$language = new text ;
$text = $language -> get ();
2024-04-02 14:55:32 -03:00
//create a single database object
$database = new database ;
$database -> app_name = 'users' ;
$database -> app_uuid = '112124b3-95c2-5352-7e9d-d14c0b88f207' ;
2016-10-05 10:29:30 -06:00
//get user uuid
2023-05-17 05:10:15 +00:00
if ( ! empty ( $_REQUEST [ "id" ]) && (( is_uuid ( $_REQUEST [ "id" ]) && permission_exists ( 'user_edit' )) || ( is_uuid ( $_REQUEST [ "id" ]) && $_REQUEST [ "id" ] == $_SESSION [ 'user_uuid' ]))) {
2019-06-08 20:08:29 -06:00
$user_uuid = $_REQUEST [ "id" ];
2016-10-05 10:29:30 -06:00
$action = 'edit' ;
}
2019-08-16 13:46:40 -06:00
elseif ( permission_exists ( 'user_add' ) && ! isset ( $_REQUEST [ "id" ])) {
2016-10-05 10:29:30 -06:00
$user_uuid = uuid ();
$action = 'add' ;
}
else {
// load users own account
2019-08-23 21:38:17 -06:00
header ( "Location: user_edit.php?id=" . urlencode ( $_SESSION [ 'user_uuid' ]));
2018-11-08 00:58:16 -07:00
exit ;
2016-10-05 10:29:30 -06:00
}
//get total user count from the database, check limit, if defined
2023-05-24 17:42:37 -06:00
if ( permission_exists ( 'user_add' ) && $action == 'add' && ! empty ( $_SESSION [ 'limit' ][ 'users' ][ 'numeric' ])) {
2019-07-19 15:05:18 -06:00
$sql = "select count(*) " ;
$sql .= "from v_users " ;
$sql .= "where domain_uuid = :domain_uuid " ;
2019-06-08 20:08:29 -06:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
2019-07-19 15:05:18 -06:00
$num_rows = $database -> select ( $sql , $parameters , 'column' );
unset ( $sql , $parameters );
2019-06-08 20:08:29 -06:00
2019-07-19 15:05:18 -06:00
if ( $num_rows >= $_SESSION [ 'limit' ][ 'users' ][ 'numeric' ]) {
2018-08-31 03:09:01 +00:00
message :: add ( $text [ 'message-maximum_users' ] . ' ' . $_SESSION [ 'limit' ][ 'users' ][ 'numeric' ], 'negative' );
2016-10-05 10:29:30 -06:00
header ( 'Location: users.php' );
exit ;
}
}
//required to be a superadmin to update an account that is a member of the superadmin group
if ( permission_exists ( 'user_edit' ) && $action == 'edit' ) {
2019-08-28 17:53:34 -06:00
$superadmins = superadmin_list ();
2016-10-05 10:29:30 -06:00
if ( if_superadmin ( $superadmins , $user_uuid )) {
if ( ! if_group ( "superadmin" )) {
echo "access denied" ;
exit ;
}
}
}
//delete the group from the user
2023-05-13 04:55:04 +00:00
if ( ! empty ( $_GET [ "a" ]) && $_GET [ "a" ] == "delete" && is_uuid ( $_GET [ "group_uuid" ]) && is_uuid ( $user_uuid ) && permission_exists ( "user_delete" )) {
2016-10-05 10:29:30 -06:00
//set the variables
2019-02-10 10:16:56 -07:00
$group_uuid = $_GET [ "group_uuid" ];
2016-10-05 10:29:30 -06:00
//delete the group from the users
2019-07-19 15:05:18 -06:00
$array [ 'user_groups' ][ 0 ][ 'group_uuid' ] = $group_uuid ;
$array [ 'user_groups' ][ 0 ][ 'user_uuid' ] = $user_uuid ;
$p = new permissions ;
$p -> add ( 'user_group_delete' , 'temp' );
$database -> delete ( $array );
unset ( $array );
$p -> delete ( 'user_group_delete' , 'temp' );
2016-10-05 10:29:30 -06:00
//redirect the user
2018-08-31 03:09:01 +00:00
message :: add ( $text [ 'message-update' ]);
2019-09-11 02:34:25 -06:00
header ( "Location: user_edit.php?id=" . urlencode ( $user_uuid ));
2019-07-19 15:05:18 -06:00
exit ;
2016-10-05 10:29:30 -06:00
}
2019-04-10 19:35:34 -06:00
//retrieve password requirements
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' )) {
$required [ 'length' ] = $_SESSION [ 'users' ][ 'password_length' ][ 'numeric' ];
$required [ 'number' ] = ( $_SESSION [ 'users' ][ 'password_number' ][ 'boolean' ] == 'true' ) ? true : false ;
$required [ 'lowercase' ] = ( $_SESSION [ 'users' ][ 'password_lowercase' ][ 'boolean' ] == 'true' ) ? true : false ;
$required [ 'uppercase' ] = ( $_SESSION [ 'users' ][ 'password_uppercase' ][ 'boolean' ] == 'true' ) ? true : false ;
$required [ 'special' ] = ( $_SESSION [ 'users' ][ 'password_special' ][ 'boolean' ] == 'true' ) ? true : false ;
}
2019-04-10 19:35:34 -06:00
2018-11-08 00:58:16 -07:00
//prepare the data
2023-05-17 04:05:52 +00:00
if ( ! empty ( $_POST )) {
2023-05-17 04:43:23 +00:00
2018-11-08 00:58:16 -07:00
//get the HTTP values and set as variables
if ( permission_exists ( 'user_edit' ) && $action == 'edit' ) {
$user_uuid = $_REQUEST [ "id" ];
2019-06-08 20:08:29 -06:00
$username_old = $_POST [ "username_old" ];
}
$domain_uuid = $_POST [ "domain_uuid" ];
2019-11-23 22:15:30 -07:00
$username = $_POST [ "username" ];
$password = $_POST [ "password" ];
$password_confirm = $_POST [ "password_confirm" ];
$user_email = $_POST [ "user_email" ];
2023-05-24 10:13:49 -06:00
$user_status = $_POST [ "user_status" ] ?? '' ;
2019-06-08 20:08:29 -06:00
$user_language = $_POST [ "user_language" ];
$user_time_zone = $_POST [ "user_time_zone" ];
2023-05-24 10:13:49 -06:00
2020-02-26 19:16:05 -05:00
if ( permission_exists ( 'contact_edit' ) && $action == 'edit' ) {
2019-06-08 20:08:29 -06:00
$contact_uuid = $_POST [ "contact_uuid" ];
2018-11-08 00:58:16 -07:00
}
2020-02-18 22:19:21 -07:00
else if ( permission_exists ( 'contact_add' ) && $action == 'add' ) {
2019-11-23 22:15:30 -07:00
$contact_organization = $_POST [ "contact_organization" ];
$contact_name_given = $_POST [ "contact_name_given" ];
$contact_name_family = $_POST [ "contact_name_family" ];
2019-06-08 20:08:29 -06:00
}
$group_uuid_name = $_POST [ "group_uuid_name" ];
2023-07-13 17:22:52 -06:00
$user_type = $_POST [ "user_type" ];
2023-06-06 22:05:05 +00:00
$user_enabled = $_POST [ "user_enabled" ] ?? 'false' ;
2021-01-07 08:43:58 -05:00
if ( permission_exists ( 'api_key' )) {
$api_key = $_POST [ "api_key" ];
}
2020-04-17 16:59:38 -06:00
if ( permission_exists ( 'message_key' )) {
2019-11-23 22:15:30 -07:00
$message_key = $_POST [ "message_key" ];
2018-11-08 00:58:16 -07:00
}
2023-05-24 17:42:37 -06:00
if ( ! empty ( $_SESSION [ 'authentication' ][ 'methods' ]) && in_array ( 'totp' , $_SESSION [ 'authentication' ][ 'methods' ])) {
2023-04-23 01:26:51 -06:00
$user_totp_secret = strtoupper ( $_POST [ "user_totp_secret" ]);
}
2016-10-05 10:29:30 -06:00
2019-09-19 08:14:14 -06:00
//validate the token
$token = new token ;
if ( ! $token -> validate ( $_SERVER [ 'PHP_SELF' ])) {
message :: add ( $text [ 'message-invalid_token' ], 'negative' );
header ( 'Location: users.php' );
exit ;
}
2024-04-02 11:01:43 -06:00
//validate the user status
switch ( $user_status ) {
case "Available" :
break ;
case "Available (On Demand)" :
break ;
case "On Break" :
break ;
case "Do Not Disturb" :
break ;
case "Logged Out" :
break ;
default :
$user_status = '' ;
}
2018-11-08 00:58:16 -07:00
//check required values
2023-05-24 10:13:49 -06:00
if ( empty ( $username )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-username' ];
2018-11-08 00:58:16 -07:00
}
2023-05-24 10:13:49 -06:00
//require a username format: any, email, no_email
2023-05-24 17:42:37 -06:00
if ( ! empty ( $_SESSION [ 'users' ][ 'username_format' ][ 'text' ]) && $_SESSION [ 'users' ][ 'username_format' ][ 'text' ] != 'any' ) {
2020-10-16 11:48:07 -06:00
if (
( $_SESSION [ 'users' ][ 'username_format' ][ 'text' ] == 'email' && ! valid_email ( $username )) ||
( $_SESSION [ 'users' ][ 'username_format' ][ 'text' ] == 'no_email' && valid_email ( $username ))
) {
message :: add ( $text [ 'message-username_format_invalid' ], 'negative' , 7500 );
}
}
2023-05-24 10:13:49 -06:00
//require unique globally or per domain
2023-05-24 17:42:37 -06:00
if (( permission_exists ( 'user_edit' ) && $action == 'edit' && $username != $username_old && ! empty ( $username )) ||
( permission_exists ( 'user_add' ) && $action == 'add' && ! empty ( $username ))) {
2023-05-24 10:13:49 -06:00
$sql = "select count(*) from v_users " ;
if ( isset ( $_SESSION [ "users" ][ "unique" ][ "text" ]) && $_SESSION [ "users" ][ "unique" ][ "text" ] == "global" ) {
$sql .= "where username = :username " ;
}
else {
$sql .= "where username = :username " ;
2019-09-10 19:23:14 -06:00
$sql .= "and domain_uuid = :domain_uuid " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
}
$parameters [ 'username' ] = $username ;
$num_rows = $database -> select ( $sql , $parameters , 'column' );
if ( $num_rows > 0 ) {
message :: add ( $text [ 'message-username_exists' ], 'negative' , 7500 );
2016-10-05 10:29:30 -06:00
}
2023-05-17 04:05:52 +00:00
unset ( $sql , $parameters );
2016-10-05 10:29:30 -06:00
}
2023-05-24 10:13:49 -06:00
//require the passwords to match
2023-05-24 17:42:37 -06:00
if ( ! empty ( $password ) && $password != $password_confirm ) {
2019-03-08 14:17:59 -07:00
message :: add ( $text [ 'message-password_mismatch' ], 'negative' , 7500 );
2016-10-05 10:29:30 -06:00
}
2023-05-24 10:13:49 -06:00
//require passwords not allowed to be empty
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' ) && permission_exists ( 'user_add' ) && $action == 'add' ) {
2023-05-24 17:42:37 -06:00
if ( empty ( $password )) {
2019-03-08 14:17:59 -07:00
message :: add ( $text [ 'message-password_blank' ], 'negative' , 7500 );
2018-11-08 00:58:16 -07:00
}
2023-05-24 17:42:37 -06:00
if ( empty ( $group_uuid_name )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-group' ];
2018-11-08 00:58:16 -07:00
}
2016-10-05 10:29:30 -06:00
}
2023-05-24 10:13:49 -06:00
//require a value a valid email address format
2020-03-27 18:09:04 -06:00
if ( ! valid_email ( $user_email )) {
$invalid [] = $text [ 'label-email' ];
}
2016-10-05 10:29:30 -06:00
2023-05-24 10:13:49 -06:00
//require passwords with the defined required attributes: length, number, lower case, upper case, and special characters
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' ) && ! empty ( $password )) {
2023-05-24 17:42:37 -06:00
if ( ! empty ( $required [ 'length' ]) && is_numeric ( $required [ 'length' ]) && $required [ 'length' ] != 0 ) {
2018-11-08 00:58:16 -07:00
if ( strlen ( $password ) < $required [ 'length' ]) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-characters' ];
2018-11-08 00:58:16 -07:00
}
}
if ( $required [ 'number' ]) {
if ( ! preg_match ( '/(?=.*[\d])/' , $password )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-numbers' ];
2018-11-08 00:58:16 -07:00
}
}
if ( $required [ 'lowercase' ]) {
if ( ! preg_match ( '/(?=.*[a-z])/' , $password )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-lowercase_letters' ];
2018-11-08 00:58:16 -07:00
}
}
if ( $required [ 'uppercase' ]) {
if ( ! preg_match ( '/(?=.*[A-Z])/' , $password )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-uppercase_letters' ];
2018-11-08 00:58:16 -07:00
}
}
if ( $required [ 'special' ]) {
if ( ! preg_match ( '/(?=.*[\W])/' , $password )) {
2020-03-27 18:09:04 -06:00
$invalid [] = $text [ 'label-special_characters' ];
2018-11-08 00:58:16 -07:00
}
}
2016-10-05 10:29:30 -06:00
}
2019-03-08 14:17:59 -07:00
//return if error
2023-05-13 04:55:04 +00:00
if ( message :: count () != 0 || ! empty ( $invalid )) {
2020-03-27 18:09:04 -06:00
if ( $invalid ) { message :: add ( $text [ 'message-required' ] . implode ( ', ' , $invalid ), 'negative' , 7500 ); }
persistent_form_values ( 'store' , $_POST );
2019-08-23 21:38:17 -06:00
header ( "Location: user_edit.php" . ( permission_exists ( 'user_edit' ) && $action != 'add' ? "?id=" . urlencode ( $user_uuid ) : null ));
2019-03-08 14:17:59 -07:00
exit ;
}
2020-03-27 18:09:04 -06:00
else {
persistent_form_values ( 'clear' );
}
2019-03-08 14:17:59 -07:00
//save the data
$i = $n = $x = $c = 0 ; //set initial array indexes
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//check to see if user language is set
$sql = "select user_setting_uuid, user_setting_value from v_user_settings " ;
$sql .= "where user_setting_category = 'domain' " ;
$sql .= "and user_setting_subcategory = 'language' " ;
2019-06-08 20:08:29 -06:00
$sql .= "and user_uuid = :user_uuid " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$row = $database -> select ( $sql , $parameters , 'row' );
2023-05-17 04:05:52 +00:00
if ( ! empty ( $user_language ) && ( empty ( $row ) || ( ! empty ( $row [ 'user_setting_uuid' ]) && ! is_uuid ( $row [ 'user_setting_uuid' ])))) {
2019-06-08 20:08:29 -06:00
//add user setting to array for insert
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = uuid ();
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'domain' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'language' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'code' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $user_language ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
}
else {
2023-05-17 04:05:52 +00:00
if ( empty ( $row [ 'user_setting_value' ]) || empty ( $user_language )) {
2019-07-19 15:05:18 -06:00
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_category' ] = 'domain' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_subcategory' ] = 'language' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_uuid' ] = $user_uuid ;
$p = new permissions ;
$p -> add ( 'user_setting_delete' , 'temp' );
$database -> delete ( $array_delete );
unset ( $array_delete );
$p -> delete ( 'user_setting_delete' , 'temp' );
2016-10-05 10:29:30 -06:00
}
2023-05-17 04:05:52 +00:00
if ( ! empty ( $user_language )) {
2019-06-08 20:08:29 -06:00
//add user setting to array for update
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = $row [ 'user_setting_uuid' ];
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'domain' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'language' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'code' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $user_language ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
2016-10-05 10:29:30 -06:00
}
}
2019-06-08 20:08:29 -06:00
unset ( $sql , $parameters , $row );
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//check to see if user time zone is set
2018-08-30 10:11:23 -06:00
$sql = "select user_setting_uuid, user_setting_value from v_user_settings " ;
2018-11-08 00:58:16 -07:00
$sql .= "where user_setting_category = 'domain' " ;
$sql .= "and user_setting_subcategory = 'time_zone' " ;
2019-06-08 20:08:29 -06:00
$sql .= "and user_uuid = :user_uuid " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$row = $database -> select ( $sql , $parameters , 'row' );
2023-05-17 04:05:52 +00:00
if ( ! empty ( $user_time_zone ) && ( empty ( $row ) || ( ! empty ( $row [ 'user_setting_uuid' ]) && ! is_uuid ( $row [ 'user_setting_uuid' ])))) {
2019-06-08 20:08:29 -06:00
//add user setting to array for insert
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = uuid ();
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'domain' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'time_zone' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'name' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $user_time_zone ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
}
else {
2023-05-17 04:05:52 +00:00
if ( empty ( $row [ 'user_setting_value' ]) || empty ( $user_time_zone )) {
2019-07-19 15:05:18 -06:00
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_category' ] = 'domain' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_subcategory' ] = 'time_zone' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_uuid' ] = $user_uuid ;
$p = new permissions ;
$p -> add ( 'user_setting_delete' , 'temp' );
$database -> delete ( $array_delete );
unset ( $array_delete );
$p -> delete ( 'user_setting_delete' , 'temp' );
2018-08-30 10:11:23 -06:00
}
2023-05-17 04:05:52 +00:00
if ( ! empty ( $user_time_zone )) {
2019-06-08 20:08:29 -06:00
//add user setting to array for update
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = $row [ 'user_setting_uuid' ];
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'domain' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'time_zone' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'name' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $user_time_zone ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
2018-08-30 10:11:23 -06:00
}
}
2019-06-08 20:08:29 -06:00
unset ( $sql , $parameters , $row );
2018-08-30 10:11:23 -06:00
2018-11-08 00:58:16 -07:00
//check to see if message key is set
2020-04-17 16:59:38 -06:00
if ( permission_exists ( 'message_key' )) {
2018-11-08 00:58:16 -07:00
$sql = "select user_setting_uuid, user_setting_value from v_user_settings " ;
$sql .= "where user_setting_category = 'message' " ;
$sql .= "and user_setting_subcategory = 'key' " ;
2019-06-08 20:08:29 -06:00
$sql .= "and user_uuid = :user_uuid " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$row = $database -> select ( $sql , $parameters , 'row' );
2023-05-17 04:05:52 +00:00
if ( ! empty ( $message_key ) && ( empty ( $row ) || ( ! empty ( $row [ 'user_setting_uuid' ]) && ! is_uuid ( $row [ 'user_setting_uuid' ])))) {
2019-06-08 20:08:29 -06:00
//add user setting to array for insert
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = uuid ();
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'message' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'key' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'text' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $message_key ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
}
else {
2023-05-17 04:05:52 +00:00
if ( empty ( $row [ 'user_setting_value' ]) || empty ( $message_key )) {
2019-07-19 15:05:18 -06:00
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_category' ] = 'message' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_setting_subcategory' ] = 'key' ;
$array_delete [ 'user_settings' ][ 0 ][ 'user_uuid' ] = $user_uuid ;
$p = new permissions ;
$p -> add ( 'user_setting_delete' , 'temp' );
$database -> delete ( $array_delete );
unset ( $array_delete );
$p -> delete ( 'user_setting_delete' , 'temp' );
2016-10-05 10:29:30 -06:00
}
2023-05-17 04:05:52 +00:00
if ( ! empty ( $message_key )) {
2019-06-08 20:08:29 -06:00
//add user setting to array for update
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = $row [ 'user_setting_uuid' ];
$array [ 'user_settings' ][ $i ][ 'user_uuid' ] = $user_uuid ;
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_settings' ][ $i ][ 'user_setting_category' ] = 'message' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_subcategory' ] = 'key' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_name' ] = 'text' ;
$array [ 'user_settings' ][ $i ][ 'user_setting_value' ] = $message_key ;
$array [ 'user_settings' ][ $i ][ 'user_setting_enabled' ] = 'true' ;
$i ++ ;
2018-11-08 00:58:16 -07:00
}
2016-10-05 10:29:30 -06:00
}
}
2023-05-17 04:05:52 +00:00
unset ( $sql , $parameters , $row );
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//assign the user to the group
2023-05-24 17:42:37 -06:00
if (( permission_exists ( 'user_add' ) || permission_exists ( 'user_edit' )) && ! empty ( $_REQUEST [ "group_uuid_name" ])) {
2018-11-08 00:58:16 -07:00
$group_data = explode ( '|' , $group_uuid_name );
$group_uuid = $group_data [ 0 ];
$group_name = $group_data [ 1 ];
2019-07-26 01:09:58 -06:00
//compare the group level to only add groups at the same level or lower than the user
$sql = "select * from v_groups " ;
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) " ;
$sql .= "and group_uuid = :group_uuid " ;
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$parameters [ 'group_uuid' ] = $group_uuid ;
$row = $database -> select ( $sql , $parameters , 'row' );
if ( $row [ 'group_level' ] <= $_SESSION [ 'user' ][ 'group_level' ]) {
$array [ 'user_groups' ][ $n ][ 'user_group_uuid' ] = uuid ();
$array [ 'user_groups' ][ $n ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'user_groups' ][ $n ][ 'group_name' ] = $group_name ;
$array [ 'user_groups' ][ $n ][ 'group_uuid' ] = $group_uuid ;
$array [ 'user_groups' ][ $n ][ 'user_uuid' ] = $user_uuid ;
$n ++ ;
2019-02-10 10:16:56 -07:00
}
2019-07-26 01:09:58 -06:00
unset ( $parameters );
2016-10-05 10:29:30 -06:00
}
2018-11-08 00:58:16 -07:00
//update domain, if changed
if (( permission_exists ( 'user_add' ) || permission_exists ( 'user_edit' )) && permission_exists ( 'user_domain' )) {
//adjust group user records
2019-02-09 08:10:21 -07:00
$sql = "select user_group_uuid from v_user_groups " ;
2019-06-08 20:08:29 -06:00
$sql .= "where user_uuid = :user_uuid " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$result = $database -> select ( $sql , $parameters , 'all' );
if ( is_array ( $result )) {
2018-11-08 00:58:16 -07:00
foreach ( $result as $row ) {
//add group user to array for update
2019-06-08 20:08:29 -06:00
$array [ 'user_groups' ][ $n ][ 'user_group_uuid' ] = $row [ 'user_group_uuid' ];
$array [ 'user_groups' ][ $n ][ 'domain_uuid' ] = $domain_uuid ;
$n ++ ;
2018-11-08 00:58:16 -07:00
}
}
2019-06-08 20:08:29 -06:00
unset ( $sql , $parameters );
2018-11-08 00:58:16 -07:00
//adjust user setting records
$sql = "select user_setting_uuid from v_user_settings " ;
2019-06-08 20:08:29 -06:00
$sql .= "where user_uuid = :user_uuid " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$result = $database -> select ( $sql , $parameters );
if ( is_array ( $result )) {
2018-11-08 00:58:16 -07:00
foreach ( $result as $row ) {
//add user setting to array for update
2019-06-08 20:08:29 -06:00
$array [ 'user_settings' ][ $i ][ 'user_setting_uuid' ] = $row [ 'user_setting_uuid' ];
$array [ 'user_settings' ][ $i ][ 'domain_uuid' ] = $domain_uuid ;
$i ++ ;
2018-11-08 00:58:16 -07:00
}
}
2019-06-08 20:08:29 -06:00
unset ( $sql , $parameters );
2018-11-08 00:58:16 -07:00
//unassign any foreign domain groups
2019-06-08 20:08:29 -06:00
$sql = "delete from v_user_groups " ;
$sql .= "where domain_uuid = :domain_uuid " ;
$sql .= "and user_uuid = :user_uuid " ;
2018-11-08 00:58:16 -07:00
$sql .= "and group_uuid not in (" ;
2019-06-08 20:08:29 -06:00
$sql .= " select group_uuid from v_groups where domain_uuid = :domain_uuid or domain_uuid is null " ;
2018-11-08 00:58:16 -07:00
$sql .= ") " ;
2019-06-08 20:08:29 -06:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$parameters [ 'user_uuid' ] = $user_uuid ;
$database -> execute ( $sql , $parameters );
unset ( $sql , $parameters );
2018-11-08 00:58:16 -07:00
}
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//add contact to array for insert
if ( $action == 'add' && permission_exists ( 'user_add' ) && permission_exists ( 'contact_add' )) {
$contact_uuid = uuid ();
$array [ 'contacts' ][ $c ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'contacts' ][ $c ][ 'contact_uuid' ] = $contact_uuid ;
$array [ 'contacts' ][ $c ][ 'contact_type' ] = 'user' ;
$array [ 'contacts' ][ $c ][ 'contact_organization' ] = $contact_organization ;
$array [ 'contacts' ][ $c ][ 'contact_name_given' ] = $contact_name_given ;
$array [ 'contacts' ][ $c ][ 'contact_name_family' ] = $contact_name_family ;
$array [ 'contacts' ][ $c ][ 'contact_nickname' ] = $username ;
$c ++ ;
if ( permission_exists ( 'contact_email_add' )) {
$contact_email_uuid = uuid ();
$array [ 'contact_emails' ][ $c ][ 'contact_email_uuid' ] = $contact_email_uuid ;
$array [ 'contact_emails' ][ $c ][ 'domain_uuid' ] = $domain_uuid ;
$array [ 'contact_emails' ][ $c ][ 'contact_uuid' ] = $contact_uuid ;
$array [ 'contact_emails' ][ $c ][ 'email_address' ] = $user_email ;
$array [ 'contact_emails' ][ $c ][ 'email_primary' ] = '1' ;
$c ++ ;
2018-04-25 22:15:03 -06:00
}
2018-11-08 00:58:16 -07:00
}
2016-10-05 10:29:30 -06:00
2020-03-06 19:37:36 -07:00
//set the password hash cost
$options = array ( 'cost' => 10 );
2018-11-08 00:58:16 -07:00
//add user setting to array for update
$array [ 'users' ][ $x ][ 'user_uuid' ] = $user_uuid ;
$array [ 'users' ][ $x ][ 'domain_uuid' ] = $domain_uuid ;
2023-05-24 17:42:37 -06:00
if ( ! empty ( $username ) && ( empty ( $username_old ) || $username != $username_old )) {
2018-11-08 00:58:16 -07:00
$array [ 'users' ][ $x ][ 'username' ] = $username ;
}
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' ) && ! empty ( $password ) && $password == $password_confirm ) {
2024-10-27 18:04:35 -06:00
//remove the session id files
$sql = "select session_id from v_user_logs " ;
$sql .= "where user_uuid = :user_uuid " ;
$sql .= "and timestamp > NOW() - INTERVAL '4 hours' " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$user_logs = $database -> select ( $sql , $parameters , 'all' );
foreach ( $user_logs as $row ) {
if ( preg_match ( '/^[a-zA-Z0-9,-]+$/' , $row [ 'session_id' ]) && file_exists ( session_save_path () . "/sess_" . $row [ 'session_id' ])) {
unlink ( session_save_path () . "/sess_" . $row [ 'session_id' ]);
}
}
//create a one way hash for the user password
2020-03-06 19:37:36 -07:00
$array [ 'users' ][ $x ][ 'password' ] = password_hash ( $password , PASSWORD_DEFAULT , $options );
$array [ 'users' ][ $x ][ 'salt' ] = null ;
2018-11-08 00:58:16 -07:00
}
2019-08-16 13:15:52 -06:00
$array [ 'users' ][ $x ][ 'user_email' ] = $user_email ;
2018-11-08 00:58:16 -07:00
$array [ 'users' ][ $x ][ 'user_status' ] = $user_status ;
if ( permission_exists ( 'user_add' ) || permission_exists ( 'user_edit' )) {
2021-01-07 08:43:58 -05:00
if ( permission_exists ( 'api_key' )) {
2023-05-24 17:42:37 -06:00
$array [ 'users' ][ $x ][ 'api_key' ] = ( ! empty ( $api_key )) ? $api_key : null ;
2021-01-07 08:43:58 -05:00
}
2023-05-24 17:42:37 -06:00
if ( ! empty ( $_SESSION [ 'authentication' ][ 'methods' ]) && in_array ( 'totp' , $_SESSION [ 'authentication' ][ 'methods' ])) {
2023-04-23 01:26:51 -06:00
$array [ 'users' ][ $x ][ 'user_totp_secret' ] = $user_totp_secret ;
}
2023-07-13 17:22:52 -06:00
$array [ 'users' ][ $x ][ 'user_type' ] = $user_type ;
2018-11-08 00:58:16 -07:00
$array [ 'users' ][ $x ][ 'user_enabled' ] = $user_enabled ;
2020-02-18 22:19:21 -07:00
if ( permission_exists ( 'contact_add' )) {
2023-05-24 17:42:37 -06:00
$array [ 'users' ][ $x ][ 'contact_uuid' ] = ( ! empty ( $contact_uuid )) ? $contact_uuid : null ;
2020-02-18 22:19:21 -07:00
}
2018-11-08 00:58:16 -07:00
if ( $action == 'add' ) {
$array [ 'users' ][ $x ][ 'add_user' ] = $_SESSION [ "user" ][ "username" ];
$array [ 'users' ][ $x ][ 'add_date' ] = date ( "Y-m-d H:i:s.uO" );
2018-04-25 22:15:03 -06:00
}
2018-11-08 00:58:16 -07:00
}
$x ++ ;
//add the user_edit permission
$p = new permissions ;
$p -> add ( "user_setting_add" , "temp" );
$p -> add ( "user_setting_edit" , "temp" );
$p -> add ( "user_edit" , "temp" );
2019-07-26 01:24:57 -06:00
$p -> add ( 'user_group_add' , 'temp' );
2020-04-13 13:57:31 -06:00
2018-11-08 00:58:16 -07:00
//save the data
$database -> save ( $array );
//$message = $database->message;
//remove the temporary permission
$p -> delete ( "user_setting_add" , "temp" );
$p -> delete ( "user_setting_edit" , "temp" );
$p -> delete ( "user_edit" , "temp" );
2019-07-26 01:24:57 -06:00
$p -> delete ( 'user_group_add' , 'temp' );
2018-11-08 00:58:16 -07:00
//if call center installed
if ( $action == 'edit' && permission_exists ( 'user_edit' ) && file_exists ( $_SERVER [ "PROJECT_ROOT" ] . "/app/call_centers/app_config.php" )) {
//get the call center agent uuid
$sql = "select call_center_agent_uuid from v_call_center_agents " ;
2019-06-08 20:08:29 -06:00
$sql .= "where domain_uuid = :domain_uuid " ;
$sql .= "and user_uuid = :user_uuid " ;
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$parameters [ 'user_uuid' ] = $user_uuid ;
$call_center_agent_uuid = $database -> select ( $sql , $parameters , 'column' );
unset ( $sql , $parameters );
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//update the user_status
2023-05-24 10:13:49 -06:00
if ( isset ( $call_center_agent_uuid ) && is_uuid ( $call_center_agent_uuid ) && ! empty ( $user_status )) {
2023-12-02 20:16:18 -04:00
$esl = event_socket :: create ();
2023-06-12 23:06:55 +00:00
$switch_cmd = "callcenter_config agent set status " . $call_center_agent_uuid . " '" . $user_status . "'" ;
2023-12-02 20:16:18 -04:00
$switch_result = event_socket :: api ( $switch_cmd );
2018-11-08 00:58:16 -07:00
}
2016-10-05 10:29:30 -06:00
2018-11-08 00:58:16 -07:00
//update the user state
2019-06-08 20:08:29 -06:00
if ( isset ( $call_center_agent_uuid ) && is_uuid ( $call_center_agent_uuid )) {
2023-12-02 20:16:18 -04:00
$esl = event_socket :: create ();
$cmd = "callcenter_config agent set state " . $call_center_agent_uuid . " Waiting" ;
$response = event_socket :: api ( $cmd );
2018-11-08 00:58:16 -07:00
}
}
2016-10-05 10:29:30 -06:00
2019-03-08 14:17:59 -07:00
//response message
if ( $action == 'edit' ) {
message :: add ( $text [ 'message-update' ], 'positive' );
2016-10-05 10:29:30 -06:00
}
else {
2019-03-08 14:17:59 -07:00
message :: add ( $text [ 'message-add' ], 'positive' );
2016-10-05 10:29:30 -06:00
}
2020-04-13 13:57:31 -06:00
header ( "Location: user_edit.php?id=" . urlencode ( $user_uuid ));
2019-09-11 02:34:25 -06:00
exit ;
2020-03-27 18:09:04 -06:00
}
2019-03-08 14:17:59 -07:00
2020-03-27 18:09:04 -06:00
//populate form
if ( persistent_form_values ( 'exists' )) {
//populate the form with values from session variable
persistent_form_values ( 'load' );
//clear, set $unsaved flag
persistent_form_values ( 'clear' );
}
else {
//populate the form with values from db
if ( $action == 'edit' ) {
2023-04-23 01:26:51 -06:00
$sql = "select domain_uuid, user_uuid, username, user_email, api_key, user_totp_secret, " ;
2023-07-13 17:22:52 -06:00
$sql .= "user_type, user_enabled, contact_uuid, cast(user_enabled as text), user_status " ;
2020-07-05 20:07:42 -06:00
$sql .= "from v_users " ;
$sql .= "where user_uuid = :user_uuid " ;
2020-03-27 18:09:04 -06:00
if ( ! permission_exists ( 'user_all' )) {
$sql .= "and domain_uuid = :domain_uuid " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
}
$parameters [ 'user_uuid' ] = $user_uuid ;
$row = $database -> select ( $sql , $parameters , 'row' );
if ( is_array ( $row ) && sizeof ( $row ) > 0 ) {
$domain_uuid = $row [ "domain_uuid" ];
$user_uuid = $row [ "user_uuid" ];
$username = $row [ "username" ];
$user_email = $row [ "user_email" ];
$api_key = $row [ "api_key" ];
2023-04-23 01:26:51 -06:00
$user_totp_secret = $row [ "user_totp_secret" ];
2023-07-13 17:22:52 -06:00
$user_type = $row [ "user_type" ];
2020-03-27 18:09:04 -06:00
$user_enabled = $row [ "user_enabled" ];
if ( permission_exists ( 'contact_view' )) {
$contact_uuid = $row [ "contact_uuid" ];
}
$user_status = $row [ "user_status" ];
2019-09-11 02:34:25 -06:00
}
else {
2020-03-27 18:09:04 -06:00
message :: add ( $text [ 'message-invalid_user' ], 'negative' , 7500 );
header ( "Location: user_edit.php?id=" . $_SESSION [ 'user_uuid' ]);
exit ;
2016-10-05 10:29:30 -06:00
}
2020-03-27 18:09:04 -06:00
unset ( $sql , $parameters , $row );
//get user settings
$sql = "select * from v_user_settings " ;
$sql .= "where user_uuid = :user_uuid " ;
$sql .= "and user_setting_enabled = 'true' " ;
$parameters [ 'user_uuid' ] = $user_uuid ;
$result = $database -> select ( $sql , $parameters , 'all' );
if ( is_array ( $result )) {
foreach ( $result as $row ) {
$name = $row [ 'user_setting_name' ];
$category = $row [ 'user_setting_category' ];
$subcategory = $row [ 'user_setting_subcategory' ];
2023-05-05 13:46:37 -03:00
if ( empty ( $subcategory )) {
2020-03-27 18:09:04 -06:00
//$$category[$name] = $row['domain_setting_value'];
$user_settings [ $category ][ $name ] = $row [ 'user_setting_value' ];
}
else {
$user_settings [ $category ][ $subcategory ][ $name ] = $row [ 'user_setting_value' ];
}
}
}
unset ( $sql , $parameters , $result , $row );
2019-04-10 19:35:34 -06:00
}
2016-10-05 10:29:30 -06:00
}
2023-02-17 14:21:41 -07:00
//set the defaults
2023-05-05 13:46:37 -03:00
if ( empty ( $user_enabled )) { $user_enabled = "true" ; }
2023-07-24 14:14:48 -06:00
if ( empty ( $user_totp_secret )) { $user_totp_secret = "" ; }
2023-02-17 14:21:41 -07:00
2019-09-19 08:14:14 -06:00
//create token
$object = new token ;
$token = $object -> create ( $_SERVER [ 'PHP_SELF' ]);
2016-10-05 10:29:30 -06:00
//include the header
require_once "resources/header.php" ;
$document [ 'title' ] = $text [ 'title-user_edit' ];
//show the content
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' )) {
echo "<script> \n " ;
echo " function compare_passwords() { \n " ;
echo " if (document.getElementById('password') === document.activeElement || document.getElementById('password_confirm') === document.activeElement) { \n " ;
echo " if ($('#password').val() != '' || $('#password_confirm').val() != '') { \n " ;
echo " if ($('#password').val() != $('#password_confirm').val()) { \n " ;
echo " $('#password').removeClass('formfld_highlight_good'); \n " ;
echo " $('#password_confirm').removeClass('formfld_highlight_good'); \n " ;
echo " $('#password').addClass('formfld_highlight_bad'); \n " ;
echo " $('#password_confirm').addClass('formfld_highlight_bad'); \n " ;
echo " } \n " ;
echo " else { \n " ;
echo " $('#password').removeClass('formfld_highlight_bad'); \n " ;
echo " $('#password_confirm').removeClass('formfld_highlight_bad'); \n " ;
echo " $('#password').addClass('formfld_highlight_good'); \n " ;
echo " $('#password_confirm').addClass('formfld_highlight_good'); \n " ;
echo " } \n " ;
echo " } \n " ;
echo " } \n " ;
echo " else { \n " ;
echo " $('#password').removeClass('formfld_highlight_bad'); \n " ;
echo " $('#password_confirm').removeClass('formfld_highlight_bad'); \n " ;
echo " $('#password').removeClass('formfld_highlight_good'); \n " ;
echo " $('#password_confirm').removeClass('formfld_highlight_good'); \n " ;
echo " } \n " ;
echo " } \n " ;
echo " function show_strength_meter() { \n " ;
echo " $('#pwstrength_progress').slideDown(); \n " ;
echo " } \n " ;
echo "</script> \n " ;
}
2016-10-05 10:29:30 -06:00
echo "<form name='frm' id='frm' method='post'> \n " ;
2020-01-07 11:11:50 -07:00
echo "<div class='action_bar' id='action_bar'> \n " ;
echo " <div class='heading'><b>" . $text [ 'header-user_edit' ] . "</b></div> \n " ;
echo " <div class='actions'> \n " ;
2023-05-13 04:55:04 +00:00
if ( ! empty ( $unsaved )) {
2020-03-27 18:09:04 -06:00
echo "<div class='unsaved'>" . $text [ 'message-unsaved_changes' ] . " <i class='fas fa-exclamation-triangle'></i></div>" ;
2019-03-08 14:17:59 -07:00
}
2016-10-05 10:29:30 -06:00
if ( permission_exists ( 'user_add' ) || permission_exists ( 'user_edit' )) {
2020-04-18 14:09:51 -06:00
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-back' ], 'icon' => $_SESSION [ 'theme' ][ 'button_icon_back' ], 'id' => 'btn_back' , 'link' => 'users.php' ]);
2016-10-05 10:29:30 -06:00
}
2020-04-18 14:09:51 -06:00
$button_margin = 'margin-left: 15px;' ;
2019-08-04 01:34:50 -06:00
if ( permission_exists ( 'ticket_add' ) || permission_exists ( 'ticket_edit' )) {
2020-04-18 14:09:51 -06:00
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-tickets' ], 'icon' => 'tags' , 'style' => $button_margin , 'link' => PROJECT_PATH . '/app/tickets/tickets.php?user_uuid=' . urlencode ( $user_uuid )]);
unset ( $button_margin );
2019-08-04 01:34:50 -06:00
}
2020-04-18 14:09:51 -06:00
if ( permission_exists ( 'user_permissions' ) && file_exists ( '../../app/user_permissions/user_permissions.php' )) {
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-permissions' ], 'icon' => 'key' , 'style' => $button_margin , 'link' => PROJECT_PATH . '/app/user_permissions/user_permissions.php?id=' . urlencode ( $user_uuid )]);
unset ( $button_margin );
}
2024-09-12 09:41:01 -06:00
if ( permission_exists ( 'user_setting_view' )) {
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-settings' ], 'icon' => $_SESSION [ 'theme' ][ 'button_icon_settings' ], 'id' => 'btn_settings' , 'style' => '' , 'link' => PROJECT_PATH . '/core/user_settings/user_settings.php?id=' . urlencode ( $user_uuid )]);
}
2020-04-18 14:09:51 -06:00
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-save' ], 'icon' => $_SESSION [ 'theme' ][ 'button_icon_save' ], 'id' => 'btn_save' , 'style' => 'margin-left: 15px;' , 'onclick' => 'submit_form();' ]);
2020-01-07 11:11:50 -07:00
echo " </div> \n " ;
echo " <div style='clear: both;'></div> \n " ;
2019-03-08 14:17:59 -07:00
echo "</div> \n " ;
2020-01-07 11:11:50 -07:00
echo $text [ 'description-user_edit' ] . " \n " ;
echo "<br /><br /> \n " ;
2016-10-05 10:29:30 -06:00
2024-09-05 23:37:34 -06:00
echo "<div class='card'> \n " ;
2016-10-05 10:29:30 -06:00
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>" ;
echo " <tr>" ;
echo " <td width='30%' class='vncellreq' valign='top'>" . $text [ 'label-username' ] . "</td>" ;
echo " <td width='70%' class='vtable'>" ;
if ( permission_exists ( "user_edit" )) {
2023-05-17 05:10:15 +00:00
echo " <input type='text' class='formfld' name='username' id='username' autocomplete='new-password' value='" . escape ( $username ?? '' ) . "' required='required'> \n " ;
2019-04-12 10:18:03 -06:00
echo " <input type='text' style='display: none;' disabled='disabled'> \n " ; //help defeat browser auto-fill
2016-10-05 10:29:30 -06:00
}
else {
2018-06-08 13:42:42 -06:00
echo " " . escape ( $username ) . " \n " ;
2023-05-17 05:10:15 +00:00
echo " <input type='hidden' name='username' id='username' autocomplete='new-password' value='" . escape ( $username ?? '' ) . "'> \n " ;
2016-10-05 10:29:30 -06:00
}
echo " </td>" ;
echo " </tr>" ;
2024-06-14 14:43:11 -06:00
if ( permission_exists ( 'user_password' )) {
echo " <tr>" ;
echo " <td class='vncell" . (( $action == 'add' ) ? 'req' : null ) . "' valign='top'>" . $text [ 'label-password' ] . "</td>" ;
echo " <td class='vtable'>" ;
echo " <input type='password' style='display: none;' disabled='disabled'>" ; //help defeat browser auto-fill
echo " <input type='password' autocomplete='new-password' class='formfld' name='password' id='password' value= \" " . escape ( $password ?? null ) . " \" " . ( $action == 'add' ? "required='required'" : null ) . " onkeypress='show_strength_meter();' onfocus='compare_passwords();' onkeyup='compare_passwords();' onblur='compare_passwords();'>" ;
echo " <div id='pwstrength_progress' class='pwstrength_progress'></div><br /> \n " ;
if (( ! empty ( $required [ 'length' ]) && is_numeric ( $required [ 'length' ]) && $required [ 'length' ] != 0 ) || $required [ 'number' ] || $required [ 'lowercase' ] || $required [ 'uppercase' ] || $required [ 'special' ]) {
echo $text [ 'label-required' ] . ': ' ;
2019-04-10 19:35:34 -06:00
if ( is_numeric ( $required [ 'length' ]) && $required [ 'length' ] != 0 ) {
2024-06-14 14:43:11 -06:00
echo $required [ 'length' ] . " " . $text [ 'label-characters' ];
if ( $required [ 'number' ] || $required [ 'lowercase' ] || $required [ 'uppercase' ] || $required [ 'special' ]) {
echo " (" ;
}
}
if ( $required [ 'number' ]) {
$required_temp [] = $text [ 'label-number' ];
2019-04-10 19:35:34 -06:00
}
2024-06-14 14:43:11 -06:00
if ( $required [ 'lowercase' ]) {
$required_temp [] = $text [ 'label-lowercase' ];
}
if ( $required [ 'uppercase' ]) {
$required_temp [] = $text [ 'label-uppercase' ];
}
if ( $required [ 'special' ]) {
$required_temp [] = $text [ 'label-special' ];
}
if ( ! empty ( $required_temp )) {
echo implode ( ', ' , $required_temp );
if ( is_numeric ( $required [ 'length' ]) && $required [ 'length' ] != 0 ) {
echo ")" ;
}
}
unset ( $required_temp );
2019-04-10 19:35:34 -06:00
}
2024-06-14 14:43:11 -06:00
echo " </td>" ;
echo " </tr>" ;
echo " <tr>" ;
echo " <td class='vncell" . (( $action == 'add' ) ? 'req' : null ) . "' valign='top'>" . $text [ 'label-confirm_password' ] . "</td>" ;
echo " <td class='vtable'>" ;
echo " <input type='password' autocomplete='new-password' class='formfld' name='password_confirm' id='password_confirm' value= \" " . escape ( $password_confirm ?? null ) . " \" " . ( $action == 'add' ? "required='required'" : null ) . " onfocus='compare_passwords();' onkeyup='compare_passwords();' onblur='compare_passwords();'><br /> \n " ;
echo " " . $text [ 'message-green_border_passwords_match' ] . " \n " ;
echo " </td>" ;
echo " </tr>" ;
2019-04-10 19:35:34 -06:00
}
2016-10-05 10:29:30 -06:00
2019-08-16 13:15:52 -06:00
echo " <tr>" ;
echo " <td class='vncellreq'>" . $text [ 'label-email' ] . "</td>" ;
2023-05-17 05:10:15 +00:00
echo " <td class='vtable'><input type='text' class='formfld' name='user_email' value='" . escape ( $user_email ?? '' ) . "' required='required'></td>" ;
2019-08-16 13:15:52 -06:00
echo " </tr>" ;
2016-10-05 10:29:30 -06:00
echo " <tr> \n " ;
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
echo " " . $text [ 'label-user_language' ] . " \n " ;
echo " </td> \n " ;
echo " <td class= \" vtable \" align='left'> \n " ;
echo " <select id='user_language' name='user_language' class='formfld' style=''> \n " ;
echo " <option value=''></option> \n " ;
//get all language codes from database
2019-06-08 20:08:29 -06:00
$sql = "select * from v_languages order by language asc " ;
2019-07-19 15:05:18 -06:00
$languages = $database -> select ( $sql , null , 'all' );
2023-05-24 17:42:37 -06:00
if ( ! empty ( $languages ) && is_array ( $languages ) && sizeof ( $languages ) != 0 ) {
2019-07-19 15:05:18 -06:00
foreach ( $languages as $row ) {
$language_codes [ $row [ "code" ]] = $row [ "language" ];
}
2016-10-05 10:29:30 -06:00
}
2019-07-19 15:05:18 -06:00
unset ( $sql , $languages , $row );
if ( is_array ( $_SESSION [ 'app' ][ 'languages' ]) && sizeof ( $_SESSION [ 'app' ][ 'languages' ]) != 0 ) {
foreach ( $_SESSION [ 'app' ][ 'languages' ] as $code ) {
2023-05-17 04:05:52 +00:00
$selected = ( isset ( $user_language ) && $code == $user_language ) || ( isset ( $user_settings [ 'domain' ][ 'language' ][ 'code' ]) && $code == $user_settings [ 'domain' ][ 'language' ][ 'code' ]) ? "selected='selected'" : null ;
2023-05-13 04:55:04 +00:00
echo " <option value='" . $code . "' " . $selected . ">" . escape ( $language_codes [ $code ] ?? null ) . " [" . escape ( $code ?? null ) . "]</option> \n " ;
2019-07-19 15:05:18 -06:00
}
2016-10-05 10:29:30 -06:00
}
echo " </select> \n " ;
echo " <br /> \n " ;
echo " " . $text [ 'description-user_language' ] . "<br /> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
echo " " . $text [ 'label-time_zone' ] . " \n " ;
echo " </td> \n " ;
echo " <td class= \" vtable \" align='left'> \n " ;
echo " <select id='user_time_zone' name='user_time_zone' class='formfld' style=''> \n " ;
echo " <option value=''></option> \n " ;
//$list = DateTimeZone::listAbbreviations();
2017-04-27 18:30:52 +01:00
$time_zone_identifiers = DateTimeZone :: listIdentifiers ();
2016-10-05 10:29:30 -06:00
$previous_category = '' ;
$x = 0 ;
foreach ( $time_zone_identifiers as $key => $row ) {
$time_zone = explode ( "/" , $row );
$category = $time_zone [ 0 ];
if ( $category != $previous_category ) {
if ( $x > 0 ) {
echo " </optgroup> \n " ;
}
echo " <optgroup label='" . $category . "'> \n " ;
}
2023-05-13 04:55:04 +00:00
$selected = ( isset ( $user_time_zone ) && $row == $user_time_zone ) || ( ! empty ( $user_settings [ 'domain' ][ 'time_zone' ]) && $row == $user_settings [ 'domain' ][ 'time_zone' ][ 'name' ]) ? "selected='selected'" : null ;
2020-03-27 18:09:04 -06:00
echo " <option value='" . escape ( $row ) . "' " . $selected . ">" . escape ( $row ) . "</option> \n " ;
2016-10-05 10:29:30 -06:00
$previous_category = $category ;
$x ++ ;
}
echo " </select> \n " ;
echo " <br /> \n " ;
echo " " . $text [ 'description-time_zone' ] . "<br /> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
2023-11-15 08:28:49 -07:00
if ( permission_exists ( "user_status" )) {
2016-10-05 10:29:30 -06:00
echo " <tr> \n " ;
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
echo " " . $text [ 'label-status' ] . " \n " ;
echo " </td> \n " ;
echo " <td class= \" vtable \" > \n " ;
2024-04-02 10:52:02 -06:00
echo " <select id='user_status' name='user_status' class='formfld' style=''> \n " ;
2016-10-05 10:29:30 -06:00
echo " <option value=''></option> \n " ;
echo " <option value='Available' " . (( $user_status == "Available" ) ? "selected='selected'" : null ) . ">" . $text [ 'option-available' ] . "</option> \n " ;
echo " <option value='Available (On Demand)' " . (( $user_status == "Available (On Demand)" ) ? "selected='selected'" : null ) . ">" . $text [ 'option-available_on_demand' ] . "</option> \n " ;
echo " <option value='Logged Out' " . (( $user_status == "Logged Out" ) ? "selected='selected'" : null ) . ">" . $text [ 'option-logged_out' ] . "</option> \n " ;
echo " <option value='On Break' " . (( $user_status == "On Break" ) ? "selected='selected'" : null ) . ">" . $text [ 'option-on_break' ] . "</option> \n " ;
echo " <option value='Do Not Disturb' " . (( $user_status == "Do Not Disturb" ) ? "selected='selected'" : null ) . ">" . $text [ 'option-do_not_disturb' ] . "</option> \n " ;
echo " </select> \n " ;
echo " <br /> \n " ;
echo " " . $text [ 'description-status' ] . "<br /> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
}
2020-02-18 22:19:21 -07:00
if ( $action == 'edit' && permission_exists ( "user_edit" ) && permission_exists ( 'contact_edit' )) {
2016-10-05 10:29:30 -06:00
echo " <tr>" ;
echo " <td class='vncell' valign='top'>" . $text [ 'label-contact' ] . "</td>" ;
echo " <td class='vtable'> \n " ;
2019-03-06 20:50:17 -07:00
$sql = "select " ;
$sql .= "c.contact_uuid, " ;
$sql .= "c.contact_organization, " ;
$sql .= "c.contact_name_given, " ;
$sql .= "c.contact_name_family, " ;
$sql .= "c.contact_nickname " ;
$sql .= "from " ;
$sql .= "v_contacts as c " ;
$sql .= "where " ;
2019-06-08 20:08:29 -06:00
$sql .= "c.domain_uuid = :domain_uuid " ;
2019-03-06 20:50:17 -07:00
$sql .= "and not exists ( " ;
$sql .= " select " ;
$sql .= " contact_uuid " ;
$sql .= " from " ;
$sql .= " v_users as u " ;
$sql .= " where " ;
2019-06-08 20:08:29 -06:00
$sql .= " u.domain_uuid = :domain_uuid " ;
2019-03-06 20:50:17 -07:00
if ( is_uuid ( $contact_uuid )) { //don't exclude currently assigned contact
2019-06-08 20:08:29 -06:00
$sql .= "and u.contact_uuid <> :contact_uuid " ;
$parameters [ 'contact_uuid' ] = $contact_uuid ;
2019-03-06 20:50:17 -07:00
}
$sql .= " and u.contact_uuid = c.contact_uuid " ;
2019-03-06 19:54:12 -07:00
$sql .= ") " ;
2019-03-06 20:50:17 -07:00
$sql .= "order by " ;
$sql .= "lower(c.contact_organization) asc, " ;
$sql .= "lower(c.contact_name_family) asc, " ;
$sql .= "lower(c.contact_name_given) asc, " ;
$sql .= "lower(c.contact_nickname) asc " ;
2019-06-08 20:08:29 -06:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$contacts = $database -> select ( $sql , $parameters , 'all' );
unset ( $parameters );
2016-10-05 10:29:30 -06:00
echo "<select name= \" contact_uuid \" id= \" contact_uuid \" class= \" formfld \" > \n " ;
echo "<option value= \"\" ></option> \n " ;
2019-06-08 20:08:29 -06:00
foreach ( $contacts as $row ) {
2018-07-16 22:32:08 -06:00
$contact_name = array ();
2023-05-24 17:42:37 -06:00
if ( ! empty ( $row [ 'contact_organization' ])) { $contact_name [] = $row [ 'contact_organization' ]; }
if ( ! empty ( $row [ 'contact_name_family' ])) { $contact_name [] = $row [ 'contact_name_family' ]; }
if ( ! empty ( $row [ 'contact_name_given' ])) { $contact_name [] = $row [ 'contact_name_given' ]; }
if ( ! empty ( $row [ 'contact_name_family' ]) && empty ( $row [ 'contact_name_family' ]) && ! empty ( $row [ 'contact_nickname' ])) { $contact_name [] = $row [ 'contact_nickname' ]; }
2018-07-16 22:32:08 -06:00
echo "<option value='" . escape ( $row [ 'contact_uuid' ]) . "' " . (( $row [ 'contact_uuid' ] == $contact_uuid ) ? "selected='selected'" : null ) . ">" . escape ( implode ( ', ' , $contact_name )) . "</option> \n " ;
2016-10-05 10:29:30 -06:00
}
2019-06-08 20:08:29 -06:00
unset ( $sql , $row_count );
2016-10-05 10:29:30 -06:00
echo "</select> \n " ;
echo "<br /> \n " ;
echo $text [ 'description-contact' ] . " \n " ;
2023-05-05 13:46:37 -03:00
if ( ! empty ( $contact_uuid )) {
2019-08-23 21:38:17 -06:00
echo " <a href= \" " . PROJECT_PATH . "/app/contacts/contact_edit.php?id=" . urlencode ( $contact_uuid ) . " \" >" . $text [ 'description-contact_view' ] . "</a> \n " ;
2016-10-05 10:29:30 -06:00
}
echo " </td>" ;
echo " </tr>" ;
}
2020-02-18 22:19:21 -07:00
elseif ( $action == 'add' && permission_exists ( "user_add" ) && permission_exists ( 'contact_add' )) {
2016-10-05 10:29:30 -06:00
echo " <tr>" ;
echo " <td class='vncell'>" . $text [ 'label-first_name' ] . "</td>" ;
2023-05-17 05:10:15 +00:00
echo " <td class='vtable'><input type='text' class='formfld' name='contact_name_given' value='" . escape ( $contact_name_given ?? '' ) . "'></td>" ;
2016-10-05 10:29:30 -06:00
echo " </tr>" ;
echo " <tr>" ;
echo " <td class='vncell'>" . $text [ 'label-last_name' ] . "</td>" ;
2023-05-17 05:10:15 +00:00
echo " <td class='vtable'><input type='text' class='formfld' name='contact_name_family' value='" . escape ( $contact_name_family ?? '' ) . "'></td>" ;
2016-10-05 10:29:30 -06:00
echo " </tr>" ;
echo " <tr>" ;
2019-06-10 13:15:04 -06:00
echo " <td class='vncell'>" . $text [ 'label-organization' ] . "</td>" ;
2023-05-17 05:10:15 +00:00
echo " <td class='vtable'><input type='text' class='formfld' name='contact_organization' value='" . escape ( $contact_organization ?? '' ) . "'></td>" ;
2016-10-05 10:29:30 -06:00
echo " </tr>" ;
}
2019-01-29 15:45:38 -07:00
if ( permission_exists ( "user_groups" )) {
2016-10-05 10:29:30 -06:00
echo " <tr>" ;
2019-01-29 15:45:38 -07:00
echo " <td class='vncellreq' valign='top'>" . $text [ 'label-groups' ] . "</td>" ;
2016-10-05 10:29:30 -06:00
echo " <td class='vtable'>" ;
$sql = "select " ;
2019-02-09 08:10:21 -07:00
$sql .= " ug.*, g.domain_uuid as group_domain_uuid " ;
2016-10-05 10:29:30 -06:00
$sql .= "from " ;
2019-02-09 08:10:21 -07:00
$sql .= " v_user_groups as ug, " ;
2016-10-05 10:29:30 -06:00
$sql .= " v_groups as g " ;
$sql .= "where " ;
2019-02-09 08:10:21 -07:00
$sql .= " ug.group_uuid = g.group_uuid " ;
2016-10-05 10:29:30 -06:00
$sql .= " and (" ;
$sql .= " g.domain_uuid = :domain_uuid " ;
$sql .= " or g.domain_uuid is null " ;
$sql .= " ) " ;
2019-02-09 08:10:21 -07:00
$sql .= " and ug.domain_uuid = :domain_uuid " ;
$sql .= " and ug.user_uuid = :user_uuid " ;
2016-10-05 10:29:30 -06:00
$sql .= "order by " ;
$sql .= " g.domain_uuid desc, " ;
$sql .= " g.group_name asc " ;
2020-04-13 13:57:31 -06:00
$parameters [ 'domain_uuid' ] = $domain_uuid ;
2019-06-08 20:08:29 -06:00
$parameters [ 'user_uuid' ] = $user_uuid ;
$user_groups = $database -> select ( $sql , $parameters , 'all' );
if ( is_array ( $user_groups )) {
2016-10-05 10:29:30 -06:00
echo "<table cellpadding='0' cellspacing='0' border='0'> \n " ;
2019-06-08 20:08:29 -06:00
foreach ( $user_groups as $field ) {
2023-05-05 13:46:37 -03:00
if ( ! empty ( $field [ 'group_name' ])) {
2016-10-05 10:29:30 -06:00
echo "<tr> \n " ;
echo " <td class='vtable' style='white-space: nowrap; padding-right: 30px;' nowrap='nowrap'>" ;
2023-05-24 17:42:37 -06:00
echo escape ( $field [ 'group_name' ]) . (( ! empty ( $field [ 'group_domain_uuid' ])) ? "@" . $_SESSION [ 'domains' ][ $field [ 'group_domain_uuid' ]][ 'domain_name' ] : null );
2016-10-05 10:29:30 -06:00
echo " </td> \n " ;
2020-11-03 13:49:43 -07:00
if ( permission_exists ( 'user_group_delete' ) || if_group ( "superadmin" )) {
2019-02-10 10:16:56 -07:00
echo " <td class='list_control_icons' style='width: 25px;'> \n " ;
2019-08-23 21:38:17 -06:00
echo " <a href='user_edit.php?id=" . urlencode ( $user_uuid ) . "&domain_uuid=" . urlencode ( $domain_uuid ) . "&group_uuid=" . urlencode ( $field [ 'group_uuid' ]) . "&a=delete' alt='" . $text [ 'button-delete' ] . "' onclick= \" return confirm('" . $text [ 'confirm-delete' ] . "') \" >" . $v_link_label_delete . "</a> \n " ;
2019-02-10 10:16:56 -07:00
echo " </td> \n " ;
2016-10-05 10:29:30 -06:00
}
echo "</tr> \n " ;
2019-06-08 20:08:29 -06:00
if ( is_uuid ( $field [ 'group_uuid' ])) {
$assigned_groups [] = $field [ 'group_uuid' ];
}
2016-10-05 10:29:30 -06:00
}
}
echo "</table> \n " ;
}
2019-07-19 15:05:18 -06:00
unset ( $sql , $parameters , $user_groups , $field );
2016-10-05 10:29:30 -06:00
$sql = "select * from v_groups " ;
2019-06-08 20:08:29 -06:00
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) " ;
2023-05-17 05:10:15 +00:00
if ( ! empty ( $assigned_groups ) && is_array ( $assigned_groups ) && sizeof ( $assigned_groups ) > 0 ) {
2016-10-05 10:29:30 -06:00
$sql .= "and group_uuid not in ('" . implode ( "','" , $assigned_groups ) . "') " ;
}
$sql .= "order by domain_uuid desc, group_name asc " ;
2020-04-13 13:57:31 -06:00
$parameters [ 'domain_uuid' ] = $domain_uuid ;
2019-06-08 20:08:29 -06:00
$groups = $database -> select ( $sql , $parameters , 'all' );
2018-11-08 00:58:16 -07:00
if ( is_array ( $groups )) {
2016-10-05 10:29:30 -06:00
if ( isset ( $assigned_groups )) { echo "<br /> \n " ; }
2019-04-10 19:35:34 -06:00
echo "<select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;' " . ( $action == 'add' ? "required='required'" : null ) . "> \n " ;
2016-10-05 10:29:30 -06:00
echo " <option value=''></option> \n " ;
2018-11-08 00:58:16 -07:00
foreach ( $groups as $field ) {
2019-07-26 01:09:58 -06:00
if ( $field [ 'group_level' ] <= $_SESSION [ 'user' ][ 'group_level' ]) {
if ( ! isset ( $assigned_groups ) || ( isset ( $assigned_groups ) && ! in_array ( $field [ "group_uuid" ], $assigned_groups ))) {
2023-05-13 04:55:04 +00:00
if ( isset ( $group_uuid_name ) && $group_uuid_name == $field [ 'group_uuid' ] . "|" . $field [ 'group_name' ]) { $selected = "selected='selected'" ; } else { $selected = '' ; }
2023-05-24 17:42:37 -06:00
echo " <option value='" . $field [ 'group_uuid' ] . "|" . $field [ 'group_name' ] . "' $selected >" . $field [ 'group_name' ] . (( ! empty ( $field [ 'domain_uuid' ])) ? "@" . $_SESSION [ 'domains' ][ $field [ 'domain_uuid' ]][ 'domain_name' ] : null ) . "</option> \n " ;
2019-07-26 01:09:58 -06:00
}
2016-10-05 10:29:30 -06:00
}
}
echo "</select>" ;
if ( $action == 'edit' ) {
2020-03-03 19:16:33 -07:00
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-add' ], 'icon' => $_SESSION [ 'theme' ][ 'button_icon_add' ], 'onclick' => 'submit_form();' ]);
2016-10-05 10:29:30 -06:00
}
}
2019-07-19 15:05:18 -06:00
unset ( $sql , $parameters , $groups , $field );
2016-10-05 10:29:30 -06:00
echo " </td>" ;
echo " </tr>" ;
2019-01-29 15:45:38 -07:00
}
2016-10-05 10:29:30 -06:00
2023-07-13 17:22:52 -06:00
if ( permission_exists ( 'user_type' )) {
echo "<tr> \n " ;
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'> \n " ;
echo " " . $text [ 'label-user_type' ] . " \n " ;
echo "</td> \n " ;
echo "<td class='vtable' align='left'> \n " ;
echo " <select class='formfld' name='user_type' id='user_type'> \n " ;
echo " <option value='default' " . (( $user_type == "default" ) ? "selected='selected'" : null ) . ">" . $text [ 'label-default' ] . "</option> \n " ;
echo " <option value='virtual' " . (( $user_type == "virtual" ) ? "selected='selected'" : null ) . ">" . $text [ 'label-virtual' ] . "</option> \n " ;
echo " </select> \n " ;
echo "<br /> \n " ;
echo $text [ 'description-user_type' ] . " \n " ;
echo "</td> \n " ;
echo "</tr> \n " ;
}
2019-01-29 15:45:38 -07:00
if ( permission_exists ( 'user_domain' )) {
2016-10-05 10:29:30 -06:00
echo "<tr> \n " ;
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'> \n " ;
2019-01-29 15:45:38 -07:00
echo " " . $text [ 'label-domain' ] . " \n " ;
2016-10-05 10:29:30 -06:00
echo "</td> \n " ;
echo "<td class='vtable' align='left'> \n " ;
2019-01-29 15:45:38 -07:00
echo " <select class='formfld' name='domain_uuid'> \n " ;
foreach ( $_SESSION [ 'domains' ] as $row ) {
echo " <option value='" . escape ( $row [ 'domain_uuid' ]) . "' " . (( $row [ 'domain_uuid' ] == $domain_uuid ) ? "selected='selected'" : null ) . ">" . escape ( $row [ 'domain_name' ]) . "</option> \n " ;
}
echo " </select> \n " ;
2016-10-05 10:29:30 -06:00
echo "<br /> \n " ;
2019-01-29 15:45:38 -07:00
echo $text [ 'description-domain_name' ] . " \n " ;
2016-10-05 10:29:30 -06:00
echo "</td> \n " ;
echo "</tr> \n " ;
}
else {
2018-06-08 13:42:42 -06:00
echo "<input type='hidden' name='domain_uuid' value='" . escape ( $domain_uuid ) . "'>" ;
2016-10-05 10:29:30 -06:00
}
2019-01-29 15:45:38 -07:00
if ( permission_exists ( 'api_key' )) {
echo " <tr>" ;
echo " <td class='vncell' valign='top'>" . $text [ 'label-api_key' ] . "</td>" ;
echo " <td class='vtable'> \n " ;
2023-05-17 05:10:15 +00:00
echo " <input type='text' class='formfld' style='width: 250px; display: none;' name='api_key' id='api_key' value= \" " . escape ( $api_key ?? '' ) . " \" >" ;
2023-05-05 13:46:37 -03:00
if ( empty ( $api_key )) {
2023-04-23 01:26:51 -06:00
//generate api key
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-generate' ],
'icon' => 'key' ,
2024-09-27 12:43:45 -06:00
'style' => 'margin-top: 1px; margin-bottom: 1px;' ,
2023-04-23 01:26:51 -06:00
'onclick' => "document.getElementById('api_key').value = '" . generate_password ( 32 , 3 ) . "';
document.getElementById('frm').submit();" ]);
}
else {
//view the api key
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-view' ],
'id' => 'button-api_key_view' ,
'icon' => 'key' ,
2024-09-27 12:43:45 -06:00
'style' => 'margin-top: 1px; margin-bottom: 1px;' ,
2023-04-23 01:26:51 -06:00
'onclick' => "document.getElementById ('button-api_key_view').style.display = 'none';
document.getElementById('api_key').style.display = 'inline';
document.getElementById('button-api_key_hide').style.display = 'inline';
document.getElementById('button-api_key_view').style.display = 'none';" ]);
2024-04-02 10:52:02 -06:00
2023-04-23 01:26:51 -06:00
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-hide' ],
'id' => 'button-api_key_hide' ,
'icon' => 'key' ,
'style' => 'display: none;' ,
'onclick' => "document.getElementById('api_key').style.display = 'none';
document.getElementById('button-api_key_hide').style.display = 'none';
document.getElementById('button-api_key_view').style.display = 'inline';" ]);
}
2023-05-05 13:46:37 -03:00
if ( ! empty ( $text [ 'description-api_key' ])) {
2019-01-29 15:45:38 -07:00
echo " <br />" . $text [ 'description-api_key' ] . "<br /> \n " ;
}
echo " </td>" ;
echo " </tr>" ;
}
2023-04-23 01:26:51 -06:00
//user time based one time password secret
2023-05-24 17:42:37 -06:00
if ( ! empty ( $_SESSION [ 'authentication' ][ 'methods' ]) && in_array ( 'totp' , $_SESSION [ 'authentication' ][ 'methods' ])) {
if ( ! empty ( $user_totp_secret ) && ! empty ( $username )) {
2023-04-23 01:26:51 -06:00
$otpauth = "otpauth://totp/" . $username . "?secret=" . $user_totp_secret . "&issuer=" . $_SESSION [ 'domain_name' ];
require_once 'resources/qr_code/QRErrorCorrectLevel.php' ;
require_once 'resources/qr_code/QRCode.php' ;
require_once 'resources/qr_code/QRCodeImage.php' ;
try {
$code = new QRCode ( - 1 , QRErrorCorrectLevel :: H );
$code -> addData ( $otpauth );
$code -> make ();
$img = new QRCodeImage ( $code , $width = 210 , $height = 210 , $quality = 50 );
$img -> draw ();
$image = $img -> getImage ();
$img -> finish ();
}
catch ( Exception $error ) {
echo $error ;
}
2019-01-29 15:45:38 -07:00
}
2023-04-23 01:26:51 -06:00
echo "<tr> \n " ;
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'> \n " ;
echo " " . $text [ 'label-user_totp_secret' ] . " \n " ;
echo "</td> \n " ;
echo "<td class='vtable' align='left' valign='top'> \n " ;
echo " <input type='hidden' class='formfld' style='width: 250px;' name='user_totp_secret' id='user_totp_secret' value= \" " . escape ( $user_totp_secret ) . " \" >" ;
2023-04-27 01:14:06 -06:00
if ( empty ( $user_totp_secret )) {
$base32 = new base2n ( 5 , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' , FALSE , TRUE , TRUE );
$user_totp_secret = $base32 -> encode ( generate_password ( 20 , 3 ));
2023-04-23 01:26:51 -06:00
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-setup' ],
'icon' => 'key' ,
2023-04-27 01:14:06 -06:00
'onclick' => "document.getElementById('user_totp_secret').value = '" . $user_totp_secret . "';
2023-04-23 01:26:51 -06:00
document.getElementById('frm').submit();" ]);
}
else {
echo " <div id='totp_qr' style='display:none;'> \n " ;
echo " " . $user_totp_secret . "<br /> \n " ;
echo " <img src= \" data:image/jpeg;base64," . base64_encode ( $image ) . " \" style='margin-top: 0px; padding: 5px; background: white; max-width: 100%;'><br /> \n " ;
echo " " . $text [ 'description-user_totp_qr_code' ] . "<br /><br /> \n " ;
echo " </div> \n " ;
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-view' ],
'id' => 'button-totp_view' ,
'icon' => 'key' ,
2023-05-17 04:05:52 +00:00
'onclick' => "document.getElementById('totp_qr').style.display = 'inline';
document.getElementById('button-totp_hide').style.display = 'inline';
document.getElementById('button-totp_disable').style.display = 'inline';
document.getElementById('button-totp_view').style.display = 'none';" ]);
2023-04-23 01:26:51 -06:00
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-hide' ],
'id' => 'button-totp_hide' ,
'icon' => 'key' ,
'style' => 'display: none;' ,
2023-05-17 04:05:52 +00:00
'onclick' => "document.getElementById('totp_qr').style.display = 'none';
document.getElementById('button-totp_hide').style.display = 'none';
document.getElementById('button-totp_disable').style.display = 'none';
document.getElementById('button-totp_view').style.display = 'inline';" ]);
2023-04-23 01:26:51 -06:00
echo button :: create ([ 'type' => 'button' ,
'label' => $text [ 'button-disable' ],
'id' => 'button-totp_disable' ,
'icon' => 'trash' ,
'style' => 'display: none;' ,
'onclick' => "document.getElementById('user_totp_secret').value = '';
document.getElementById('frm').submit();" ]);
}
2023-05-05 13:46:37 -03:00
if ( empty ( $user_totp_secret )) {
2023-04-23 01:26:51 -06:00
echo " <br />" . $text [ 'description-user_totp_secret' ] . "<br /> \n " ;
}
else {
echo " <br />" . $text [ 'description-user_totp_view' ] . "<br /> \n " ;
}
echo "</td> \n " ;
echo "</tr> \n " ;
2019-01-29 15:45:38 -07:00
}
2019-03-15 14:17:41 -06:00
echo "<tr " . ( $user_uuid == $_SESSION [ 'user_uuid' ] ? "style='display: none;'" : null ) . "> \n " ;
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'> \n " ;
echo " " . $text [ 'label-enabled' ] . " \n " ;
echo "</td> \n " ;
echo "<td class='vtable' align='left'> \n " ;
2023-02-10 09:20:10 -07:00
if ( substr ( $_SESSION [ 'theme' ][ 'input_toggle_style' ][ 'text' ], 0 , 6 ) == 'switch' ) {
echo " <label class='switch'> \n " ;
echo " <input type='checkbox' id='user_enabled' name='user_enabled' value='true' " . ( $user_enabled == 'true' ? "checked='checked'" : null ) . "> \n " ;
echo " <span class='slider'></span> \n " ;
echo " </label> \n " ;
}
else {
echo " <select class='formfld' id='user_enabled' name='user_enabled'> \n " ;
2023-02-14 11:19:02 -07:00
echo " <option value='true' " . ( $user_enabled == 'true' ? "selected='selected'" : null ) . ">" . $text [ 'option-true' ] . "</option> \n " ;
echo " <option value='false' " . ( $user_enabled == 'false' ? "selected='selected'" : null ) . ">" . $text [ 'option-false' ] . "</option> \n " ;
2023-02-10 09:20:10 -07:00
echo " </select> \n " ;
}
2019-03-15 14:17:41 -06:00
echo "<br /> \n " ;
echo $text [ 'description-enabled' ] . " \n " ;
echo "</td> \n " ;
echo "</tr> \n " ;
2019-01-29 15:45:38 -07:00
2020-02-12 11:58:56 -07:00
echo "</table>" ;
2024-09-05 23:37:34 -06:00
echo "</div> \n " ;
2020-02-12 11:58:56 -07:00
echo "<br /><br />" ;
2016-10-05 10:29:30 -06:00
if ( $action == 'edit' ) {
2020-02-12 11:58:56 -07:00
echo "<input type='hidden' name='id' value= \" " . escape ( $user_uuid ) . " \" >" ;
2016-10-05 10:29:30 -06:00
if ( permission_exists ( "user_edit" )) {
2020-02-12 11:58:56 -07:00
echo "<input type='hidden' name='username_old' value= \" " . escape ( $username ) . " \" >" ;
2016-10-05 10:29:30 -06:00
}
}
2020-02-12 11:58:56 -07:00
echo "<input type='hidden' name='" . $token [ 'name' ] . "' value='" . $token [ 'hash' ] . "'> \n " ;
2016-10-05 10:29:30 -06:00
echo "</form>" ;
2020-03-03 19:16:33 -07:00
//hide password fields before submit
2024-09-12 09:41:01 -06:00
echo "<script> \n " ;
2020-03-03 19:16:33 -07:00
echo " function submit_form() { \n " ;
echo " hide_password_fields(); \n " ;
echo " $('form#frm').submit(); \n " ;
echo " } \n " ;
2020-01-07 11:11:50 -07:00
echo "</script> \n " ;
2016-10-05 10:29:30 -06:00
//include the footer
require_once "resources/footer.php" ;
2023-05-24 19:27:06 -04:00
?>