2012-06-04 16:58:40 +02:00
< ? php
/*
FusionPBX
Version : MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 ( the " License " ); you may not use this file except in compliance with
the License . You may obtain a copy of the License at
http :// www . mozilla . org / MPL /
Software distributed under the License is distributed on an " AS IS " basis ,
WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
for the specific language governing rights and limitations under the
License .
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane < markjcrane @ fusionpbx . com >
2013-08-16 08:27:06 +02:00
Portions created by the Initial Developer are Copyright ( C ) 2008 - 2013
2012-06-04 16:58:40 +02:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
2014-12-21 07:12:21 +01:00
Luis Daniel Lucio Quiroz < dlucio @ okay . com . mx >
2012-06-04 16:58:40 +02:00
*/
include " root.php " ;
2013-07-06 08:03:27 +02:00
require_once " resources/require.php " ;
2013-07-06 07:50:55 +02:00
require_once " resources/check_auth.php " ;
2012-06-04 16:58:40 +02:00
if ( permission_exists ( " user_add " ) ||
2013-06-09 06:32:24 +02:00
permission_exists ( " user_edit " ) ||
2012-06-04 16:58:40 +02:00
permission_exists ( " user_delete " ) ||
if_group ( " superadmin " )) {
//access allowed
}
else {
echo " access denied " ;
return ;
}
2013-06-09 06:32:24 +02:00
//add multi-lingual support
2015-01-18 10:22:07 +01:00
$language = new text ;
$text = $language -> get ();
2013-06-09 06:32:24 +02:00
2012-06-04 16:58:40 +02:00
//get data from the db
2014-06-21 00:21:39 +02:00
if ( strlen ( $_REQUEST [ " id " ]) > 0 ) {
2012-06-04 16:58:40 +02:00
$user_uuid = $_REQUEST [ " id " ];
}
//required to be a superadmin to update an account that is a member of the superadmin group
2013-08-16 08:27:06 +02:00
$superadmins = superadmin_list ( $db );
if ( if_superadmin ( $superadmins , $user_uuid )) {
2013-06-09 06:32:24 +02:00
if ( ! if_group ( " superadmin " )) {
2012-06-04 16:58:40 +02:00
echo " access denied " ;
2013-08-16 08:27:06 +02:00
exit ;
2012-06-04 16:58:40 +02:00
}
}
//delete the group from the user
if ( $_GET [ " a " ] == " delete " && permission_exists ( " user_delete " )) {
//set the variables
2014-10-18 05:17:13 +02:00
$group_uuid = check_str ( $_GET [ " group_uuid " ]);
2012-06-04 16:58:40 +02:00
//delete the group from the users
2015-03-31 02:54:24 +02:00
$sql = " delete from v_group_users where 1 = 1 " ;
2014-10-18 05:17:13 +02:00
$sql .= " and group_uuid = ' " . $group_uuid . " ' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
2012-06-04 16:58:40 +02:00
$db -> exec ( check_sql ( $sql ));
//redirect the user
2014-02-23 10:39:12 +01:00
$_SESSION [ " message " ] = $text [ 'message-update' ];
header ( " Location: usersupdate.php?id= " . $user_uuid );
2012-06-04 16:58:40 +02:00
return ;
}
//get the user settings
$sql = " select * from v_user_settings " ;
2013-05-14 18:38:26 +02:00
$sql .= " where user_uuid = ' " . $user_uuid . " ' " ;
2012-06-04 16:58:40 +02:00
$sql .= " and user_setting_enabled = 'true' " ;
$prep_statement = $db -> prepare ( $sql );
if ( $prep_statement ) {
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
foreach ( $result as $row ) {
$name = $row [ 'user_setting_name' ];
$category = $row [ 'user_setting_category' ];
$subcategory = $row [ 'user_setting_subcategory' ];
if ( strlen ( $subcategory ) == 0 ) {
//$$category[$name] = $row['domain_setting_value'];
$user_settings [ $category ][ $name ] = $row [ 'user_setting_value' ];
}
else {
$user_settings [ $category ][ $subcategory ][ $name ] = $row [ 'user_setting_value' ];
}
}
}
2013-08-16 08:27:06 +02:00
if ( count ( $_POST ) > 0 && $_POST [ " persistform " ] != " 1 " ) {
2014-05-13 07:41:44 +02:00
//get the HTTP values and set as variables
$user_uuid = $_REQUEST [ " id " ];
2015-03-31 23:47:31 +02:00
$domain_uuid = check_str ( $_POST [ " domain_uuid " ]);
2014-06-21 00:21:39 +02:00
$username_old = check_str ( $_POST [ " username_old " ]);
$username = check_str ( $_POST [ " username " ]);
2014-05-13 07:41:44 +02:00
$password = check_str ( $_POST [ " password " ]);
$confirm_password = check_str ( $_POST [ " confirm_password " ]);
$user_status = check_str ( $_POST [ " user_status " ]);
$user_language = check_str ( $_POST [ " user_language " ]);
$user_time_zone = check_str ( $_POST [ " user_time_zone " ]);
$contact_uuid = check_str ( $_POST [ " contact_uuid " ]);
$group_member = check_str ( $_POST [ " group_member " ]);
$user_enabled = check_str ( $_POST [ " user_enabled " ]);
$api_key = check_str ( $_POST [ " api_key " ]);
2014-06-21 00:21:39 +02:00
//check required values
if ( $username != $username_old ) {
$sql = " select count(*) as num_rows from v_users where domain_uuid = ' " . $domain_uuid . " ' and username = ' " . $username . " ' " ;
$prep_statement = $db -> prepare ( check_sql ( $sql ));
if ( $prep_statement ) {
$prep_statement -> execute ();
$row = $prep_statement -> fetch ( PDO :: FETCH_ASSOC );
if ( 0 < $row [ 'num_rows' ]) {
$msg_error = $text [ 'message-username_exists' ];
}
}
unset ( $sql );
}
if ( $password != $confirm_password ) { $msg_error = $text [ 'message-password_mismatch' ]; }
2014-05-13 07:41:44 +02:00
if ( $msg_error ) {
2014-06-21 00:21:39 +02:00
$_SESSION [ " message " ] = $msg_error ;
2014-08-02 09:02:31 +02:00
$_SESSION [ " message_mood " ] = 'negative' ;
2014-06-21 00:21:39 +02:00
header ( " Location: usersupdate.php?id= " . $user_uuid );
exit ;
2014-05-13 07:41:44 +02:00
}
//check to see if user language is set
$sql = " select count(*) as num_rows from v_user_settings " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'language' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$prep_statement = $db -> prepare ( check_sql ( $sql ));
if ( $prep_statement ) {
$prep_statement -> execute ();
$row = $prep_statement -> fetch ( PDO :: FETCH_ASSOC );
if ( $row [ 'num_rows' ] == 0 ) {
$user_setting_uuid = uuid ();
$sql = " insert into v_user_settings " ;
$sql .= " ( " ;
$sql .= " domain_uuid, " ;
$sql .= " user_setting_uuid, " ;
$sql .= " user_setting_category, " ;
$sql .= " user_setting_subcategory, " ;
$sql .= " user_setting_name, " ;
$sql .= " user_setting_value, " ;
$sql .= " user_setting_enabled, " ;
$sql .= " user_uuid " ;
$sql .= " ) " ;
$sql .= " values " ;
$sql .= " ( " ;
2015-03-31 02:54:24 +02:00
$sql .= " ' " . $domain_uuid . " ', " ;
2014-05-13 07:41:44 +02:00
$sql .= " ' " . $user_setting_uuid . " ', " ;
$sql .= " 'domain', " ;
$sql .= " 'language', " ;
$sql .= " 'code', " ;
$sql .= " ' " . $user_language . " ', " ;
$sql .= " 'true', " ;
$sql .= " ' " . $user_uuid . " ' " ;
$sql .= " ) " ;
$db -> exec ( check_sql ( $sql ));
}
else {
if ( strlen ( $user_language ) == 0 ) {
$sql = " delete from v_user_settings " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'language' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
unset ( $sql );
}
else {
$sql = " update v_user_settings set " ;
$sql .= " user_setting_value = ' " . $user_language . " ', " ;
$sql .= " user_setting_enabled = 'true' " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'language' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
}
}
}
2012-06-04 16:58:40 +02:00
2013-06-09 06:32:24 +02:00
//get the number of rows in v_user_settings
2012-06-04 16:58:40 +02:00
$sql = " select count(*) as num_rows from v_user_settings " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'time_zone' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$prep_statement = $db -> prepare ( check_sql ( $sql ));
if ( $prep_statement ) {
$prep_statement -> execute ();
$row = $prep_statement -> fetch ( PDO :: FETCH_ASSOC );
if ( $row [ 'num_rows' ] == 0 ) {
$user_setting_uuid = uuid ();
$sql = " insert into v_user_settings " ;
$sql .= " ( " ;
2012-10-19 21:25:26 +02:00
$sql .= " domain_uuid, " ;
2012-06-04 16:58:40 +02:00
$sql .= " user_setting_uuid, " ;
$sql .= " user_setting_category, " ;
$sql .= " user_setting_subcategory, " ;
$sql .= " user_setting_name, " ;
$sql .= " user_setting_value, " ;
$sql .= " user_setting_enabled, " ;
$sql .= " user_uuid " ;
$sql .= " ) " ;
$sql .= " values " ;
$sql .= " ( " ;
2015-03-31 02:54:24 +02:00
$sql .= " ' " . $domain_uuid . " ', " ;
2012-06-04 16:58:40 +02:00
$sql .= " ' " . $user_setting_uuid . " ', " ;
$sql .= " 'domain', " ;
$sql .= " 'time_zone', " ;
$sql .= " 'name', " ;
$sql .= " ' " . $user_time_zone . " ', " ;
$sql .= " 'true', " ;
$sql .= " ' " . $user_uuid . " ' " ;
$sql .= " ) " ;
$db -> exec ( check_sql ( $sql ));
2014-06-21 00:21:39 +02:00
unset ( $sql );
2012-06-04 16:58:40 +02:00
}
else {
if ( strlen ( $user_time_zone ) == 0 ) {
$sql = " delete from v_user_settings " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'time_zone' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
unset ( $sql );
}
else {
$sql = " update v_user_settings set " ;
$sql .= " user_setting_value = ' " . $user_time_zone . " ', " ;
$sql .= " user_setting_enabled = 'true' " ;
$sql .= " where user_setting_category = 'domain' " ;
$sql .= " and user_setting_subcategory = 'time_zone' " ;
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
2014-06-21 00:21:39 +02:00
unset ( $sql );
2012-06-04 16:58:40 +02:00
}
}
}
//assign the user to the group
2014-10-18 05:17:13 +02:00
if ( strlen ( $_REQUEST [ " group_uuid_name " ]) > 0 ) {
$group_data = explode ( '|' , $_REQUEST [ " group_uuid_name " ]);
$group_uuid = $group_data [ 0 ];
$group_name = $group_data [ 1 ];
2012-06-04 16:58:40 +02:00
$sql_insert = " insert into v_group_users " ;
$sql_insert .= " ( " ;
$sql_insert .= " group_user_uuid, " ;
$sql_insert .= " domain_uuid, " ;
$sql_insert .= " group_name, " ;
2014-10-18 05:17:13 +02:00
$sql_insert .= " group_uuid, " ;
2012-06-04 16:58:40 +02:00
$sql_insert .= " user_uuid " ;
2014-10-18 05:17:13 +02:00
$sql_insert .= " ) " ;
2012-06-04 16:58:40 +02:00
$sql_insert .= " values " ;
2014-10-18 05:17:13 +02:00
$sql_insert .= " ( " ;
2012-06-04 16:58:40 +02:00
$sql_insert .= " ' " . uuid () . " ', " ;
2014-10-18 05:17:13 +02:00
$sql_insert .= " ' " . $domain_uuid . " ', " ;
$sql_insert .= " ' " . $group_name . " ', " ;
$sql_insert .= " ' " . $group_uuid . " ', " ;
$sql_insert .= " ' " . $user_uuid . " ' " ;
2012-06-04 16:58:40 +02:00
$sql_insert .= " ) " ;
2014-10-18 05:17:13 +02:00
//only a superadmin can add other superadmins or admins, admins can only add other admins
switch ( $group_name ) {
case " superadmin " :
if ( ! if_group ( " superadmin " )) { break ; }
case " admin " :
if ( ! if_group ( " superadmin " ) && ! if_group ( " admin " )) { break ; }
default :
2012-06-04 16:58:40 +02:00
$db -> exec ( $sql_insert );
}
}
2015-03-31 02:54:24 +02:00
//change domain_uuid in group users and user settings tables
if ( permission_exists ( 'user_domain' )) {
$sql = " update v_group_users set " ;
$sql .= " domain_uuid = ' " . $domain_uuid . " ' " ;
$sql .= " where user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
$sql = " update v_user_settings set " ;
$sql .= " domain_uuid = ' " . $domain_uuid . " ' " ;
$sql .= " where user_uuid = ' " . $user_uuid . " ' " ;
$db -> exec ( check_sql ( $sql ));
}
2012-06-04 16:58:40 +02:00
//sql update
$sql = " update v_users set " ;
2015-03-31 02:54:24 +02:00
if ( permission_exists ( 'user_domain' )) {
$sql .= " domain_uuid = ' " . $domain_uuid . " ', " ;
}
2014-06-21 00:21:39 +02:00
if ( strlen ( $username ) > 0 && $username != $username_old ) {
2015-03-31 02:54:24 +02:00
$sql .= " username = ' " . $username . " ', " ;
2012-06-04 16:58:40 +02:00
}
if ( strlen ( $password ) > 0 && $confirm_password == $password ) {
//salt used with the password to create a one way hash
2015-02-10 21:54:03 +01:00
$salt = uuid ();
2012-06-04 16:58:40 +02:00
//set the password
$sql .= " password = ' " . md5 ( $salt . $password ) . " ', " ;
$sql .= " salt = ' " . $salt . " ', " ;
}
2013-09-21 06:38:26 +02:00
if ( strlen ( $api_key ) > 0 ) {
2015-03-31 02:54:24 +02:00
$sql .= " api_key = ' " . $api_key . " ', " ;
2013-09-21 06:38:26 +02:00
}
else {
$sql .= " api_key = null, " ;
}
2015-03-31 02:54:24 +02:00
$sql .= " user_status = ' " . $user_status . " ', " ;
$sql .= " user_enabled = ' " . $user_enabled . " ', " ;
2012-06-04 16:58:40 +02:00
if ( strlen ( $contact_uuid ) == 0 ) {
$sql .= " contact_uuid = null " ;
}
else {
2015-03-31 02:54:24 +02:00
$sql .= " contact_uuid = ' " . $contact_uuid . " ' " ;
}
$sql .= " where 1 = 1 " ;
if ( ! permission_exists ( 'user_domain' )) {
$sql .= " and domain_uuid = ' " . $domain_uuid . " ' " ;
2012-06-04 16:58:40 +02:00
}
2015-03-31 02:54:24 +02:00
$sql .= " and user_uuid = ' " . $user_uuid . " ' " ;
2012-06-04 16:58:40 +02:00
$db -> exec ( check_sql ( $sql ));
2014-06-21 00:21:39 +02:00
// if call center installed
if ( file_exists ( $_SERVER [ 'DOCUMENT_ROOT' ] . PROJECT_PATH . " /app/call_center/app_config.php " )) {
// update agent and tiers tables
$sql = " update v_call_center_agents set agent_name = ' " . $username . " ' where domain_uuid = ' " . $domain_uuid . " ' and agent_name = ' " . $username_old . " ' " ;
$db -> exec ( check_sql ( $sql ));
unset ( $sql );
$sql = " update v_call_center_tiers set agent_name = ' " . $username . " ' where domain_uuid = ' " . $domain_uuid . " ' and agent_name = ' " . $username_old . " ' " ;
$db -> exec ( check_sql ( $sql ));
unset ( $sql );
//syncrhonize the configuration
save_call_center_xml ();
//update the user_status
$fp = event_socket_create ( $_SESSION [ 'event_socket_ip_address' ], $_SESSION [ 'event_socket_port' ], $_SESSION [ 'event_socket_password' ]);
2015-03-31 02:54:24 +02:00
$switch_cmd .= " callcenter_config agent set status " . $username . " @ " . $_SESSION [ 'domains' ][ $domain_uuid ][ 'domain_name' ] . " ' " . $user_status . " ' " ;
2014-06-21 00:21:39 +02:00
$switch_result = event_socket_request ( $fp , 'api ' . $switch_cmd );
2012-06-04 16:58:40 +02:00
2014-06-21 00:21:39 +02:00
//update the user state
2015-03-31 02:54:24 +02:00
$cmd = " api callcenter_config agent set state " . $username . " @ " . $_SESSION [ 'domains' ][ $domain_uuid ][ 'domain_name' ] . " Waiting " ;
2014-06-21 00:21:39 +02:00
$response = event_socket_request ( $fp , $cmd );
}
2012-06-04 16:58:40 +02:00
//redirect the browser
2014-02-23 10:39:12 +01:00
$_SESSION [ " message " ] = $text [ 'message-update' ];
2014-10-18 05:17:13 +02:00
if ( $_REQUEST [ 'submit' ] == $text [ 'button-add' ]) {
header ( " Location: usersupdate.php?id= " . $user_uuid );
}
else {
header ( " Location: index.php " );
}
2012-06-04 16:58:40 +02:00
return ;
2014-06-21 00:21:39 +02:00
2012-06-04 16:58:40 +02:00
}
2014-06-21 00:21:39 +02:00
2015-03-31 23:47:31 +02:00
//pre-populate the form
$sql = " select * from v_users " ;
$sql .= " where user_uuid = ' " . $user_uuid . " ' " ;
if ( ! permission_exists ( 'user_all' )) {
$sql .= " and domain_uuid = ' " . $domain_uuid . " ' " ;
}
2012-06-04 16:58:40 +02:00
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
foreach ( $result as & $row ) {
2015-03-31 23:47:31 +02:00
$domain_uuid = $row [ " domain_uuid " ];
2012-06-04 16:58:40 +02:00
$user_uuid = $row [ " user_uuid " ];
2014-06-21 00:21:39 +02:00
$username = $row [ " username " ];
2012-06-04 16:58:40 +02:00
$password = $row [ " password " ];
2013-09-21 06:38:26 +02:00
$api_key = $row [ " api_key " ];
2013-09-20 21:24:43 +02:00
$user_enabled = $row [ " user_enabled " ];
2012-06-04 16:58:40 +02:00
$contact_uuid = $row [ " contact_uuid " ];
$user_status = $row [ " user_status " ];
}
//get the groups the user is a member of
//group_members function defined in config.php
$group_members = group_members ( $db , $user_uuid );
2014-06-21 00:21:39 +02:00
2012-06-04 16:58:40 +02:00
//include the header
2013-07-06 08:29:50 +02:00
require_once " resources/header.php " ;
2014-07-10 02:32:50 +02:00
$document [ 'title' ] = $text [ 'title-user_edit' ];
2012-06-04 16:58:40 +02:00
//show the content
$table_width = 'width="100%"' ;
2014-07-07 18:34:43 +02:00
echo " <script> " ;
echo " function compare_passwords() { " ;
2014-07-07 21:04:28 +02:00
echo " if (document.getElementById('password') === document.activeElement || document.getElementById('confirmpassword') === document.activeElement) { " ;
echo " if (document.getElementById('password').value != '' || document.getElementById('confirmpassword').value != '') { " ;
echo " if (document.getElementById('password').value != document.getElementById('confirmpassword').value) { " ;
echo " $ ('#password').removeClass('formfld_highlight_good'); " ;
echo " $ ('#confirmpassword').removeClass('formfld_highlight_good'); " ;
echo " $ ('#password').addClass('formfld_highlight_bad'); " ;
echo " $ ('#confirmpassword').addClass('formfld_highlight_bad'); " ;
echo " } " ;
echo " else { " ;
echo " $ ('#password').removeClass('formfld_highlight_bad'); " ;
echo " $ ('#confirmpassword').removeClass('formfld_highlight_bad'); " ;
echo " $ ('#password').addClass('formfld_highlight_good'); " ;
echo " $ ('#confirmpassword').addClass('formfld_highlight_good'); " ;
echo " } " ;
echo " } " ;
2014-07-07 18:34:43 +02:00
echo " } " ;
echo " else { " ;
2014-07-07 21:04:28 +02:00
echo " if (document.getElementById('password').value == document.getElementById('confirmpassword').value) { " ;
echo " $ ('#password').removeClass('formfld_highlight_bad'); " ;
echo " $ ('#confirmpassword').removeClass('formfld_highlight_bad'); " ;
echo " $ ('#password').removeClass('formfld_highlight_good'); " ;
echo " $ ('#confirmpassword').removeClass('formfld_highlight_good'); " ;
echo " } " ;
2014-07-07 18:34:43 +02:00
echo " } " ;
echo " } " ;
echo " </script> " ;
2012-06-04 16:58:40 +02:00
echo " <form method='post' action=''> " ;
2014-10-18 10:18:03 +02:00
echo " <table $table_width cellpadding='0' cellspacing='0' border='0'> " ;
2013-06-09 06:32:24 +02:00
echo " <td align='left' width='90%' nowrap><b> " . $text [ 'header-user_edit' ] . " </b></td> \n " ;
2014-10-18 10:18:03 +02:00
echo " <td align='right' nowrap> \n " ;
2013-06-09 06:32:24 +02:00
echo " <input type='button' class='btn' onclick= \" window.location='index.php' \" value=' " . $text [ 'button-back' ] . " '> " ;
2014-04-27 00:50:52 +02:00
echo " <input type='submit' name='submit' class='btn' value=' " . $text [ 'button-save' ] . " '> " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td align='left' colspan='2'> \n " ;
2013-06-09 06:32:24 +02:00
echo " " . $text [ 'description-user_edit' ] . " \n " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
echo " <br /> \n " ;
2014-10-18 10:18:03 +02:00
echo " <table $table_width cellpadding='0' cellspacing='0' border='0'> " ;
2012-06-04 16:58:40 +02:00
echo " <tr> \n " ;
2013-06-09 06:32:24 +02:00
echo " <th class='th' colspan='2' align='left'> " . $text [ 'label-user_info' ] . " </th> \n " ;
2012-06-04 16:58:40 +02:00
echo " </tr> \n " ;
echo " <tr> " ;
2015-03-18 09:57:18 +01:00
echo " <td width='30%' class='vncellreq' valign='top'> " . $text [ 'label-username' ] . " </td> " ;
2014-06-21 00:21:39 +02:00
echo " <td width='70%' class='vtable'> " ;
if ( if_group ( " admin " ) || if_group ( " superadmin " )) {
2014-12-21 07:12:21 +01:00
echo " <input type='txt' autocomplete='off' class='formfld' name='username' value=' " . $username . " ' required='required'> " ;
2014-06-21 00:21:39 +02:00
}
else {
echo " " . $username ;
}
echo " </td> " ;
2012-06-04 16:58:40 +02:00
echo " </tr> " ;
echo " <tr> " ;
2015-03-18 09:57:18 +01:00
echo " <td class='vncell' valign='top'> " . $text [ 'label-password' ] . " </td> " ;
2014-07-07 21:04:28 +02:00
echo " <td class='vtable'><input type='password' autocomplete='off' class='formfld' name='password' id='password' value='' onfocus='compare_passwords();' onkeyup='compare_passwords();' onblur='compare_passwords();'></td> " ;
2012-06-04 16:58:40 +02:00
echo " </tr> " ;
echo " <tr> " ;
2015-03-18 09:57:18 +01:00
echo " <td class='vncell' valign='top'> " . $text [ 'label-confirm_password' ] . " </td> " ;
2014-07-07 21:04:28 +02:00
echo " <td class='vtable'><input type='password' autocomplete='off' class='formfld' name='confirm_password' id='confirmpassword' value='' onfocus='compare_passwords();' onkeyup='compare_passwords();' onblur='compare_passwords();'></td> " ;
2012-06-04 16:58:40 +02:00
echo " </tr> " ;
2015-03-31 02:54:24 +02:00
if ( permission_exists ( 'user_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 " ;
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 " ;
}
2015-03-31 23:47:31 +02:00
else {
echo " <input type='hidden' name='domain_uuid' value=' " . $domain_uuid . " '> " ;
}
2015-03-31 02:54:24 +02:00
2012-06-04 16:58:40 +02:00
echo " <tr> " ;
2015-02-15 07:50:00 +01:00
echo " <td class='vncellreq' valign='top'> " . $text [ 'label-groups' ] . " </td> " ;
2012-06-04 16:58:40 +02:00
echo " <td class='vtable'> " ;
$sql = " SELECT * FROM v_group_users " ;
$sql .= " where domain_uuid=:domain_uuid " ;
$sql .= " and user_uuid=:user_uuid " ;
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> bindParam ( ':domain_uuid' , $domain_uuid );
$prep_statement -> bindParam ( ':user_uuid' , $user_uuid );
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
$result_count = count ( $result );
2014-10-18 05:17:13 +02:00
if ( $result_count > 0 ) {
echo " <table width='30%'> \n " ;
foreach ( $result as $field ) {
if ( strlen ( $field [ 'group_name' ]) > 0 ) {
echo " <tr> \n " ;
echo " <td class='vtable'> " . $field [ 'group_name' ] . " </td> \n " ;
2014-10-18 10:18:03 +02:00
if ( $result_count > 1 ) {
echo " <td> \n " ;
if ( permission_exists ( 'group_member_delete' ) || if_group ( " superadmin " )) {
echo " <a href='usersupdate.php?id= " . $user_uuid . " &domain_uuid= " . $domain_uuid . " &group_uuid= " . $field [ 'group_uuid' ] . " &a=delete' alt=' " . $text [ 'button-delete' ] . " ' onclick= \" return confirm(' " . $text [ 'confirm-delete' ] . " ') \" > $v_link_label_delete </a> \n " ;
}
echo " </td> \n " ;
2014-10-18 05:17:13 +02:00
}
echo " </tr> \n " ;
$assigned_groups [] = $field [ 'group_uuid' ];
2012-06-04 16:58:40 +02:00
}
}
2014-10-18 05:17:13 +02:00
echo " </table> \n " ;
2012-06-04 16:58:40 +02:00
}
2014-10-18 05:17:13 +02:00
unset ( $sql , $prep_statement , $result , $result_count );
2012-06-04 16:58:40 +02:00
$sql = " SELECT * FROM v_groups " ;
$sql .= " where domain_uuid = ' " . $domain_uuid . " ' " ;
2015-01-08 10:54:24 +01:00
$sql .= " or domain_uuid is null " ;
2014-10-18 05:17:13 +02:00
if ( sizeof ( $assigned_groups ) > 0 ) {
$sql .= " and group_uuid not in (' " . implode ( " ',' " , $assigned_groups ) . " ') " ;
}
2014-06-21 21:40:16 +02:00
$sql .= " order by group_name asc " ;
2012-06-04 16:58:40 +02:00
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
2014-10-18 05:17:13 +02:00
$result_count = count ( $result );
if ( $result_count > 0 ) {
echo " <br /> \n " ;
echo " <select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;'> \n " ;
echo " <option value=''></option> \n " ;
foreach ( $result as $field ) {
if ( $field [ 'group_name' ] == " superadmin " && ! if_group ( " superadmin " )) { continue ; } //only show the superadmin group to other superadmins
if ( $field [ 'group_name' ] == " admin " && ( ! if_group ( " superadmin " ) && ! if_group ( " admin " ) )) { continue ; } //only show the admin group to other admins
if ( ! in_array ( $field [ " group_uuid " ], $assigned_groups )) {
echo " <option value=' " . $field [ 'group_uuid' ] . " | " . $field [ 'group_name' ] . " '> " . $field [ 'group_name' ] . " </option> \n " ;
}
2012-06-04 16:58:40 +02:00
}
2014-10-18 05:17:13 +02:00
echo " </select> " ;
echo " <input type='submit' name='submit' class='btn' value= \" " . $text [ 'button-add' ] . " \" > \n " ;
2012-06-04 16:58:40 +02:00
}
2014-10-18 05:17:13 +02:00
unset ( $sql , $prep_statement , $result );
2012-06-04 16:58:40 +02:00
echo " </td> " ;
echo " </tr> " ;
echo " </table> " ;
echo " <br> " ;
echo " <br> " ;
2015-02-15 08:59:02 +01:00
echo " <table $table_width cellpadding='0' cellspacing='0'> " ;
2012-06-04 16:58:40 +02:00
echo " <tr> \n " ;
2013-06-09 06:32:24 +02:00
echo " <th class='th' colspan='2' align='left'> " . $text [ 'label-additional_info' ] . " </th> \n " ;
2012-06-04 16:58:40 +02:00
echo " </tr> \n " ;
echo " <tr> " ;
2015-03-18 09:57:18 +01:00
echo " <td width='30%' class='vncell' valign='top'> " . $text [ 'label-contact' ] . " </td> " ;
2012-06-04 16:58:40 +02:00
echo " <td width='70%' class='vtable'> \n " ;
$sql = " select contact_uuid, contact_organization, contact_name_given, contact_name_family from v_contacts " ;
2015-03-31 02:54:24 +02:00
$sql .= " where domain_uuid = ' " . $domain_uuid . " ' " ;
2015-03-26 20:51:53 +01:00
$sql .= " order by contact_organization desc, contact_name_family asc, contact_name_given asc " ;
2012-06-04 16:58:40 +02:00
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
unset ( $prep_statement , $sql );
echo " <select name= \" contact_uuid \" id= \" contact_uuid \" class= \" formfld \" > \n " ;
echo " <option value= \" \" ></option> \n " ;
foreach ( $result as $row ) {
$contact_name = '' ;
if ( strlen ( $row [ 'contact_organization' ]) > 0 ) {
$contact_name = $row [ 'contact_organization' ];
}
if ( strlen ( $row [ 'contact_name_family' ]) > 0 ) {
if ( strlen ( $contact_name ) > 0 ) { $contact_name .= " , " ; }
$contact_name .= $row [ 'contact_name_family' ];
}
if ( strlen ( $row [ 'contact_name_given' ]) > 0 ) {
if ( strlen ( $contact_name ) > 0 ) { $contact_name .= " , " ; }
$contact_name .= $row [ 'contact_name_given' ];
}
if ( $row [ 'contact_uuid' ] == $contact_uuid ) {
echo " <option value= \" " . $row [ 'contact_uuid' ] . " \" selected= \" selected \" > " . $contact_name . " </option> \n " ;
}
else {
echo " <option value= \" " . $row [ 'contact_uuid' ] . " \" > " . $contact_name . " </option> \n " ;
}
}
unset ( $sql , $result , $row_count );
echo " </select> \n " ;
echo " <br /> \n " ;
2013-06-09 06:32:24 +02:00
echo $text [ 'description-contact' ] . " \n " ;
2012-06-04 16:58:40 +02:00
if ( strlen ( $contact_uuid ) > 0 ) {
2014-07-08 04:39:59 +02:00
echo " <a href= \" " . PROJECT_PATH . " /app/contacts/contact_edit.php?id= $contact_uuid\ " > " . $text['description-contact_view'] . " </ a > \n " ;
2012-06-04 16:58:40 +02:00
}
echo " </td> " ;
echo " </tr> " ;
if ( $_SESSION [ 'user_status_display' ] == " false " ) {
//hide the user_status when it is set to false
}
else {
echo " <tr> \n " ;
2015-03-18 09:57:18 +01:00
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
2015-02-15 07:50:00 +01:00
echo " " . $text [ 'label-status' ] . " \n " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " <td class= \" vtable \" > \n " ;
2015-03-31 02:54:24 +02:00
$cmd = " ' " . PROJECT_PATH . " /app/calls_active/v_calls_exec.php?cmd=callcenter_config+agent+set+status+ " . $username . " @ " . $_SESSION [ 'domains' ][ $domain_uuid ][ 'domain_name' ] . " +'+this.value " ;
2012-06-04 16:58:40 +02:00
echo " <select id='user_status' name='user_status' class='formfld' style='' onchange= \" send_cmd( $cmd ); \" > \n " ;
2015-03-31 02:54:24 +02: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 " ;
2012-06-04 16:58:40 +02:00
echo " </select> \n " ;
echo " <br /> \n " ;
2013-06-09 06:32:24 +02:00
echo " " . $text [ 'description-status' ] . " <br /> \n " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
}
2014-05-13 07:41:44 +02:00
echo " <tr> \n " ;
2015-03-18 09:57:18 +01:00
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
2015-02-15 07:50:00 +01:00
echo " " . $text [ 'label-user_language' ] . " \n " ;
2014-05-13 07:41:44 +02:00
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 " ;
2015-03-18 09:57:18 +01:00
//get all language codes from database
$sql = " select * from v_languages order by language asc " ;
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
foreach ( $result as & $row ) {
$language_codes [ $row [ " code " ]] = $row [ " language " ];
}
unset ( $prep_statement , $result , $row );
foreach ( $_SESSION [ 'app' ][ 'languages' ] as $code ) {
$selected = ( $code == $user_settings [ 'domain' ][ 'language' ][ 'code' ]) ? " selected='selected' " : null ;
echo " <option value=' " . $code . " ' " . $selected . " > " . $language_codes [ $code ] . " [ " . $code . " ]</option> \n " ;
2014-05-13 07:41:44 +02:00
}
echo " </select> \n " ;
echo " <br /> \n " ;
echo " " . $text [ 'description-user_language' ] . " <br /> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
2012-06-04 16:58:40 +02:00
echo " <tr> \n " ;
2015-03-18 09:57:18 +01:00
echo " <td width='20%' class= \" vncell \" valign='top'> \n " ;
2015-02-15 07:50:00 +01:00
echo " " . $text [ 'label-time_zone' ] . " \n " ;
2012-06-04 16:58:40 +02:00
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();
$time_zone_identifiers = DateTimeZone :: listIdentifiers ();
$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 " ;
}
if ( $row == $user_settings [ 'domain' ][ 'time_zone' ][ 'name' ]) {
echo " <option value=' " . $row . " ' selected='selected'> " . $row . " </option> \n " ;
}
else {
echo " <option value=' " . $row . " '> " . $row . " </option> \n " ;
}
$previous_category = $category ;
$x ++ ;
}
echo " </select> \n " ;
echo " <br /> \n " ;
2013-06-09 06:32:24 +02:00
echo " " . $text [ 'description-time_zone' ] . " <br /> \n " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
2013-09-21 06:38:26 +02:00
if ( file_exists ( $_SERVER [ " DOCUMENT_ROOT " ] . PROJECT_PATH . '/app/api/app_config.php' )) {
echo " <tr> " ;
2015-03-18 09:57:18 +01:00
echo " <td class='vncell' valign='top'> " . $text [ 'label-api_key' ] . " </td> " ;
2013-09-21 06:38:26 +02:00
echo " <td class='vtable'> \n " ;
2014-08-15 09:04:52 +02:00
echo " <input type= \" text \" class='formfld' name= \" api_key \" id='api_key' value= \" " . $api_key . " \" > " ;
echo " <input type='button' class='btn' value=' " . $text [ 'button-generate' ] . " ' onclick= \" getElementById('api_key').value=' " . uuid () . " '; \" > " ;
2013-09-21 06:38:26 +02:00
if ( strlen ( $text [ 'description-api_key' ]) > 0 ) {
echo " <br /> " . $text [ 'description-api_key' ] . " <br /> \n " ;
}
echo " </td> " ;
echo " </tr> " ;
}
2012-08-10 17:53:02 +02:00
echo " <tr> \n " ;
echo " <td class='vncell' valign='top' align='left' nowrap='nowrap'> \n " ;
2015-03-31 02:54:24 +02:00
echo " " . $text [ 'label-enabled' ] . " \n " ;
2012-08-10 17:53:02 +02:00
echo " </td> \n " ;
echo " <td class='vtable' align='left'> \n " ;
2015-03-31 02:54:24 +02:00
echo " <select class='formfld' name='user_enabled'> \n " ;
echo " <option value='true'> " . $text [ 'option-true' ] . " </option> \n " ;
echo " <option value='false' " . (( $user_enabled == " false " ) ? " selected='selected' " : null ) . " > " . $text [ 'option-false' ] . " </option> \n " ;
echo " </select> \n " ;
2012-08-10 17:53:02 +02:00
echo " <br /> \n " ;
2013-06-09 06:32:24 +02:00
echo $text [ 'description-enabled' ] . " \n " ;
2012-08-10 17:53:02 +02:00
echo " </td> \n " ;
2013-06-09 06:32:24 +02:00
echo " </tr> \n " ;
2012-08-10 17:53:02 +02:00
2012-06-04 16:58:40 +02:00
echo " <tr> " ;
2015-02-15 10:39:23 +01:00
echo " <td colspan='2' align='right'> " ;
2012-06-04 16:58:40 +02:00
echo " <input type='hidden' name='id' value= \" $user_uuid\ " > " ;
2014-06-21 00:21:39 +02:00
echo " <input type='hidden' name='username_old' value= \" $username\ " > " ;
2015-02-15 10:20:19 +01:00
echo " <br> " ;
2013-06-09 06:32:24 +02:00
echo " <input type='submit' name='submit' class='btn' value=' " . $text [ 'button-save' ] . " '> " ;
2012-06-04 16:58:40 +02:00
echo " </td> " ;
echo " </tr> " ;
echo " </table> " ;
2015-02-15 08:59:02 +01:00
echo " <br><br> " ;
2012-06-04 16:58:40 +02:00
echo " </form> " ;
//include the footer
2013-07-06 08:29:50 +02:00
require_once " resources/footer.php " ;
2012-06-04 16:58:40 +02:00
2014-07-08 04:39:59 +02:00
?>