2014-03-23 16:03:30 -04:00
< ? php
2016-11-16 21:16:25 -05:00
/**
*
* This file is part of HESK - PHP Help Desk Software .
*
* ( c ) Copyright Klemen Stirn . All rights reserved .
* http :// www . hesk . com
*
* For the full copyright and license agreement information visit
* http :// www . hesk . com / eula . php
*
*/
2015-09-12 00:46:46 -04:00
define ( 'IN_SCRIPT' , 1 );
define ( 'HESK_PATH' , '../' );
2015-09-27 14:07:54 -04:00
define ( 'VALIDATOR' , 1 );
2015-10-27 13:45:42 -04:00
define ( 'PAGE_TITLE' , 'ADMIN_USERS' );
2014-03-23 16:03:30 -04:00
/* Get all the required files and functions */
require ( HESK_PATH . 'hesk_settings.inc.php' );
require ( HESK_PATH . 'inc/common.inc.php' );
require ( HESK_PATH . 'inc/admin_functions.inc.php' );
2015-01-18 23:58:14 -05:00
require ( HESK_PATH . 'inc/profile_functions.inc.php' );
2016-08-09 22:17:22 -04:00
require ( HESK_PATH . 'inc/mail_functions.inc.php' );
2014-03-23 16:03:30 -04:00
hesk_load_database_functions ();
hesk_session_start ();
hesk_dbConnect ();
hesk_isLoggedIn ();
/* Check permissions for this feature */
hesk_checkPermission ( 'can_man_users' );
/* Possible user features */
2015-06-13 01:20:06 -04:00
$hesk_settings [ 'features' ] = hesk_getFeatureArray ();
2016-04-25 21:56:52 -04:00
$modsForHesk_settings = mfh_getSettings ();
$calendar_view_array = array (
'month' => 0 ,
'agendaWeek' => 1 ,
'agendaDay' => 2 ,
);
$default_view = $calendar_view_array [ $modsForHesk_settings [ 'default_calendar_view' ]];
2014-03-23 16:03:30 -04:00
/* Set default values */
$default_userdata = array (
2015-01-18 23:58:14 -05:00
// Profile info
2015-09-12 00:46:46 -04:00
'name' => '' ,
'email' => '' ,
2015-01-18 23:58:14 -05:00
'cleanpass' => '' ,
'user' => '' ,
'autoassign' => 'Y' ,
// Signature
2015-09-12 00:46:46 -04:00
'signature' => '' ,
2015-01-18 23:58:14 -05:00
// Permissions
2015-09-12 00:46:46 -04:00
'isadmin' => 1 ,
2014-10-24 22:15:39 -04:00
'active' => 1 ,
2015-09-12 00:46:46 -04:00
'categories' => array ( '1' ),
'features' => array ( 'can_view_tickets' , 'can_reply_tickets' , 'can_change_cat' , 'can_assign_self' , 'can_view_unassigned' , 'can_view_online' ),
2015-01-18 23:58:14 -05:00
// Preferences
'afterreply' => 0 ,
// Defaults
'autostart' => 1 ,
'notify_customer_new' => 1 ,
'notify_customer_reply' => 1 ,
'show_suggested' => 1 ,
2016-10-12 21:25:36 -04:00
'autoreload' => 0 ,
2016-04-25 21:56:52 -04:00
'default_calendar_view' => $default_view ,
2015-01-18 23:58:14 -05:00
// Notifications
'notify_new_unassigned' => 1 ,
'notify_new_my' => 1 ,
'notify_reply_unassigned' => 1 ,
'notify_reply_my' => 1 ,
'notify_assigned' => 1 ,
'notify_note' => 1 ,
'notify_pm' => 1 ,
'notify_note_unassigned' => 1 ,
2016-04-21 22:05:45 -04:00
'notify_overdue_unassigned' => 0 ,
2014-03-23 16:03:30 -04:00
);
/* A list of all categories */
2015-09-03 21:58:05 -04:00
$orderBy = $modsForHesk_settings [ 'category_order_column' ];
2014-03-23 16:03:30 -04:00
$hesk_settings [ 'categories' ] = array ();
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( 'SELECT `id`,`name` FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'categories` ORDER BY `' . $orderBy . '` ASC' );
while ( $row = hesk_dbFetchAssoc ( $res )) {
if ( hesk_okCategory ( $row [ 'id' ], 0 )) {
$hesk_settings [ 'categories' ][ $row [ 'id' ]] = $row [ 'name' ];
2014-03-23 16:03:30 -04:00
}
}
/* Non-admin users may not create users with more permissions than they have */
2015-09-12 00:46:46 -04:00
if ( ! $_SESSION [ 'isadmin' ]) {
/* Can't create admin users */
if ( isset ( $_POST [ 'isadmin' ])) {
2015-01-18 23:58:14 -05:00
unset ( $_POST [ 'isadmin' ]);
}
2014-03-23 16:03:30 -04:00
/* Can only add features he/she has access to */
2015-09-12 00:46:46 -04:00
$hesk_settings [ 'features' ] = array_intersect ( explode ( ',' , $_SESSION [ 'heskprivileges' ]), $hesk_settings [ 'features' ]);
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Can user modify auto-assign setting? */
if ( $hesk_settings [ 'autoassign' ] && ( ! hesk_checkPermission ( 'can_assign_self' , 0 ) || ! hesk_checkPermission ( 'can_assign_others' , 0 ))) {
$hesk_settings [ 'autoassign' ] = 0 ;
2014-03-23 16:03:30 -04:00
}
}
/* Use any set values, default otherwise */
2015-09-12 00:46:46 -04:00
foreach ( $default_userdata as $k => $v ) {
if ( ! isset ( $_SESSION [ 'userdata' ][ $k ])) {
$_SESSION [ 'userdata' ][ $k ] = $v ;
2014-03-23 16:03:30 -04:00
}
}
$_SESSION [ 'userdata' ] = hesk_stripArray ( $_SESSION [ 'userdata' ]);
/* What should we do? */
2015-09-12 00:46:46 -04:00
if ( $action = hesk_REQUEST ( 'a' )) {
if ( $action == 'reset_form' ) {
$_SESSION [ 'edit_userdata' ] = TRUE ;
header ( 'Location: ./manage_users.php' );
} elseif ( $action == 'edit' ) {
edit_user ();
} elseif ( defined ( 'HESK_DEMO' )) {
hesk_process_messages ( $hesklang [ 'ddemo' ], 'manage_users.php' , 'NOTICE' );
} elseif ( $action == 'new' ) {
new_user ();
} elseif ( $action == 'save' ) {
update_user ();
} elseif ( $action == 'remove' ) {
remove ();
} elseif ( $action == 'autoassign' ) {
toggle_autoassign ();
} elseif ( $action == 'active' ) {
toggle_active ();
} else {
hesk_error ( $hesklang [ 'invalid_action' ]);
}
} else {
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* If one came from the Edit page make sure we reset user values */
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( isset ( $_SESSION [ 'save_userdata' ])) {
$_SESSION [ 'userdata' ] = $default_userdata ;
unset ( $_SESSION [ 'save_userdata' ]);
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( isset ( $_SESSION [ 'edit_userdata' ])) {
$_SESSION [ 'userdata' ] = $default_userdata ;
unset ( $_SESSION [ 'edit_userdata' ]);
2014-03-23 16:03:30 -04:00
}
2016-08-09 22:17:22 -04:00
/* Print header */
2016-08-11 13:06:12 -04:00
require_once ( HESK_PATH . 'inc/headerAdmin.inc.php' );
require_once ( HESK_PATH . 'inc/show_admin_nav.inc.php' );
2015-09-12 00:46:46 -04:00
?>
2016-08-09 22:17:22 -04:00
< section class = " content " >
< ? php hesk_handle_messages (); ?>
< script language = " Javascript " type = " text/javascript " ><!--
function confirm_delete () {
if ( confirm ( '<?php echo addslashes($hesklang[' sure_remove_user ']); ?>' )) {
return true ;
}
else {
return false ;
}
}
//-->
</ script >
2016-08-15 15:37:41 -04:00
< div class = " box collapsed-box " >
< div class = " box-header with-border " >
< h1 class = " box-title " >
< ? php echo $hesklang [ 'add_user' ]; ?>
< a href = " javascript:void(0) " onclick = " javascript:alert('<?php echo hesk_makeJsString( $hesklang['users_intro'] ); ?>') " >
< i class = " fa fa-question-circle settingsquestionmark " ></ i >
</ a >
</ h1 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
</ div >
</ div >
< div class = " box-body " >
< ? php echo $hesklang [ 'req_marked_with' ]; ?> <span class="red">*</span>
< form data - toggle = " validator " name = " form1 " method = " post " action = " manage_users.php " class = " form-horizontal " role = " form " >
< ? php hesk_profile_tab ( 'userdata' , false , 'create_user' ); ?>
</ form >
</ div >
</ div >
2016-08-09 22:17:22 -04:00
< div class = " box " >
< div class = " box-header with-border " >
< h1 class = " box-title " >
< ? php echo $hesklang [ 'manage_users' ]; ?>
< a href = " javascript:void(0) " onclick = " javascript:alert('<?php echo hesk_makeJsString( $hesklang['users_intro'] ); ?>') " >
< i class = " fa fa-question-circle settingsquestionmark " ></ i >
</ a >
</ h1 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-minus " ></ i >
</ button >
</ div >
</ div >
< div class = " box-body " >
2015-09-12 00:46:46 -04:00
< table class = " table table-hover " >
< tr >
< th >< b >< i >< ? php echo $hesklang [ 'name' ]; ?> </i></b></th>
< th >< b >< i >< ? php echo $hesklang [ 'email' ]; ?> </i></b></th>
< th >< b >< i >< ? php echo $hesklang [ 'username' ]; ?> </i></b></th>
< th >< b >< i >< ? php echo $hesklang [ 'permission_template' ]; ?> </i></b></th>
< ? php
/* Is user rating enabled? */
if ( $hesk_settings [ 'rating' ]) {
?>
< th >< b >< i >< ? php echo $hesklang [ 'rating' ]; ?> </i></b></th>
< ? php
}
?>
< th >< b >< i >& nbsp ; < ? php echo $hesklang [ 'opt' ]; ?> </i></b></th>
</ tr >
<!-- I can ' t get this block to tab over without breaking , so it will be awkwardly sticking out for now : ( -->
< ? php
$res = hesk_dbQuery ( 'SELECT * FROM `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'users` ORDER BY `name` ASC' );
$i = 1 ;
$cannot_manage = array ();
while ( $myuser = hesk_dbFetchAssoc ( $res )) {
if ( ! compare_user_permissions ( $myuser [ 'id' ], $myuser [ 'isadmin' ], explode ( ',' , $myuser [ 'categories' ]), explode ( ',' , $myuser [ 'heskprivileges' ]))) {
$cannot_manage [ $myuser [ 'id' ]] = array ( 'name' => $myuser [ 'name' ], 'user' => $myuser [ 'user' ], 'email' => $myuser [ 'email' ]);
continue ;
}
if ( isset ( $_SESSION [ 'seluser' ]) && $myuser [ 'id' ] == $_SESSION [ 'seluser' ]) {
$color = 'admin_green' ;
unset ( $_SESSION [ 'seluser' ]);
} else {
$color = $i ? 'admin_white' : 'admin_gray' ;
}
$tmp = $i ? 'White' : 'Blue' ;
$style = 'class="option' . $tmp . 'OFF" onmouseover="this.className=\'option' . $tmp . 'ON\'" onmouseout="this.className=\'option' . $tmp . 'OFF\'"' ;
$i = $i ? 0 : 1 ;
/* User online? */
if ( $hesk_settings [ 'online' ]) {
if ( isset ( $hesk_settings [ 'users_online' ][ $myuser [ 'id' ]])) {
$myuser [ 'name' ] = '<i class="fa fa-circle green" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'online' ] . '"></i> ' . $myuser [ 'name' ];
} else {
$myuser [ 'name' ] = '<i class="fa fa-circle gray" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'offline' ] . '"></i> ' . $myuser [ 'name' ];
}
}
/* To edit yourself go to "Profile" page, not here. */
if ( $myuser [ 'id' ] == $_SESSION [ 'id' ]) {
2016-11-15 12:53:33 -05:00
$edit_code = '<a href="profile.php"><i class="fa fa-pencil icon-link orange" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'edit' ] . '"></i></a>' ;
2015-09-12 00:46:46 -04:00
} elseif ( $myuser [ 'id' ] == 1 ) {
$edit_code = ' <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />' ;
} else {
2016-11-15 12:53:33 -05:00
$edit_code = '<a href="manage_users.php?a=edit&id=' . $myuser [ 'id' ] . '"><i class="fa fa-pencil icon-link orange" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'edit' ] . '"></i></a>' ;
2015-09-12 00:46:46 -04:00
}
if ( $myuser [ 'isadmin' ]) {
$myuser [ 'isadmin' ] = '<font class="open">' . $hesklang [ 'yes' ] . '</font>' ;
} else {
$myuser [ 'isadmin' ] = '<font class="resolved">' . $hesklang [ 'no' ] . '</font>' ;
}
/* Deleting user with ID 1 (default administrator) is not allowed. Also don't allow the logged in user to be deleted or inactivated */
if ( $myuser [ 'id' ] == 1 || $myuser [ 'id' ] == $_SESSION [ 'id' ]) {
$remove_code = ' <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />' ;
} else {
$remove_code = ' <a href="manage_users.php?a=remove&id=' . $myuser [ 'id' ] . '&token=' . hesk_token_echo ( 0 ) . '" onclick="return confirm_delete();"><i class="fa fa-times icon-link red" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'delete' ] . '"></i></a>' ;
}
/* Is auto assign enabled? */
if ( $hesk_settings [ 'autoassign' ]) {
if ( $myuser [ 'autoassign' ]) {
$autoassign_code = '<a href="manage_users.php?a=autoassign&s=0&id=' . $myuser [ 'id' ] . '&token=' . hesk_token_echo ( 0 ) . '"><i class="fa fa-bolt icon-link orange" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'aaon' ] . '"></i></a>' ;
} else {
$autoassign_code = '<a href="manage_users.php?a=autoassign&s=1&id=' . $myuser [ 'id' ] . '&token=' . hesk_token_echo ( 0 ) . '"><i class="fa fa-bolt icon-link gray" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'aaoff' ] . '"></i></a>' ;
}
} else {
$autoassign_code = '' ;
}
$activeMarkup = '' ;
if ( $myuser [ 'id' ] != $_SESSION [ 'id' ] && $myuser [ 'id' ] != 1 ) {
/* Is the user active? */
if ( $myuser [ 'active' ]) {
$activeMarkup = '<a href="manage_users.php?a=active&s=0&id=' . $myuser [ 'id' ] . '&token=' . hesk_token_echo ( 0 ) . '"><i class="fa fa-user icon-link green" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'disable_user' ] . '"></i></a>' ;
} else {
$activeMarkup = '<a href="manage_users.php?a=active&s=1&id=' . $myuser [ 'id' ] . '&token=' . hesk_token_echo ( 0 ) . '"><i class="fa fa-user icon-link gray" data-toggle="tooltip" data-placement="top" title="' . $hesklang [ 'enable_user' ] . '"></i></a>' ;
}
}
$templateName = $hesklang [ 'custom' ];
if ( $myuser [ 'permission_template' ] != - 1 ) {
$result = hesk_dbQuery ( " SELECT `name` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " permission_templates` WHERE `id` = " . intval ( $myuser [ 'permission_template' ]));
$row = hesk_dbFetchAssoc ( $result );
$templateName = $row [ 'name' ];
}
echo <<< EOC
2014-03-23 16:03:30 -04:00
< tr >
< td > $myuser [ name ] </ td >
< td >< a href = " mailto: $myuser[email] " > $myuser [ email ] </ a ></ td >
< td > $myuser [ user ] </ td >
2015-06-16 21:00:44 -04:00
< td > $templateName </ td >
2014-03-23 16:03:30 -04:00
EOC ;
2015-09-12 00:46:46 -04:00
if ( $hesk_settings [ 'rating' ]) {
$alt = $myuser [ 'rating' ] ? sprintf ( $hesklang [ 'rated' ], sprintf ( " %01.1f " , $myuser [ 'rating' ]), ( $myuser [ 'ratingneg' ] + $myuser [ 'ratingpos' ])) : $hesklang [ 'not_rated' ];
echo '<td><img src="../img/star_' . ( hesk_round_to_half ( $myuser [ 'rating' ]) * 10 ) . '.png" width="85" height="16" alt="' . $alt . '" data-toggle="tooltip" data-placement="top" title="' . $alt . '" border="0" style="vertical-align:text-bottom" /> </td>' ;
}
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
echo <<< EOC
2014-10-24 22:15:39 -04:00
< td > $autoassign_code $edit_code $remove_code $activeMarkup </ td >
2014-03-23 16:03:30 -04:00
</ tr >
EOC ;
2015-09-12 00:46:46 -04:00
} // End while
?>
</ table >
< ? php if ( $hesk_settings [ 'online' ]) {
echo ' <i class="fa fa-circle green"></i> ' . $hesklang [ 'online' ] . ' <i class="fa fa-circle gray"></i> ' . $hesklang [ 'offline' ];
} ?>
</ div >
2015-01-18 23:58:14 -05:00
</ div >
2015-09-12 00:46:46 -04:00
< script language = " Javascript " type = " text/javascript " ><!--
hesk_checkPassword ( document . form1 . newpass . value );
//-->
</ script >
2016-08-09 22:17:22 -04:00
</ section >
2014-03-23 16:03:30 -04:00
2016-08-09 22:17:22 -04:00
< ? php
2016-08-15 15:49:31 -04:00
require_once ( HESK_PATH . 'inc/footer.inc.php' );
2016-08-09 22:17:22 -04:00
exit ();
2014-03-23 16:03:30 -04:00
} // End else
/*** START FUNCTIONS ***/
function compare_user_permissions ( $compare_id , $compare_isadmin , $compare_categories , $compare_features )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings ;
2014-03-23 16:03:30 -04:00
/* Comparing myself? */
2015-09-12 00:46:46 -04:00
if ( $compare_id == $_SESSION [ 'id' ]) {
return true ;
2014-03-23 16:03:30 -04:00
}
/* Admins have full access, no need to compare */
2015-09-12 00:46:46 -04:00
if ( $_SESSION [ 'isadmin' ]) {
return true ;
} elseif ( $compare_isadmin ) {
return false ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
/* Compare categories */
foreach ( $compare_categories as $catid ) {
if ( ! array_key_exists ( $catid , $hesk_settings [ 'categories' ])) {
return false ;
2014-03-23 16:03:30 -04:00
}
}
2015-09-12 00:46:46 -04:00
/* Compare features */
foreach ( $compare_features as $feature ) {
if ( ! in_array ( $feature , $hesk_settings [ 'features' ])) {
return false ;
2014-03-23 16:03:30 -04:00
}
}
return true ;
} // END compare_user_permissions()
function edit_user ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang , $default_userdata ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$id = intval ( hesk_GET ( 'id' )) or hesk_error ( " $hesklang[int_error] : $hesklang[no_valid_id] " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* To edit self fore using "Profile" page */
if ( $id == $_SESSION [ 'id' ]) {
hesk_process_messages ( $hesklang [ 'eyou' ], 'profile.php' , 'NOTICE' );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( $id == 1 ) {
hesk_process_messages ( $hesklang [ 'cant_edit_admin' ], './manage_users.php' );
2014-10-26 11:19:01 -04:00
}
2014-03-23 16:03:30 -04:00
$_SESSION [ 'edit_userdata' ] = TRUE ;
2015-09-12 00:46:46 -04:00
if ( ! isset ( $_SESSION [ 'save_userdata' ])) {
$res = hesk_dbQuery ( " SELECT *,`heskprivileges` AS `features`, `active`
FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `id` = '" . intval($id) . "' LIMIT 1 " );
$_SESSION [ 'userdata' ] = hesk_dbFetchAssoc ( $res );
2014-03-23 16:03:30 -04:00
/* Store original username for display until changes are saved successfully */
$_SESSION [ 'original_user' ] = $_SESSION [ 'userdata' ][ 'user' ];
/* A few variables need special attention... */
2015-09-12 00:46:46 -04:00
if ( $_SESSION [ 'userdata' ][ 'isadmin' ]) {
$_SESSION [ 'userdata' ][ 'features' ] = $default_userdata [ 'features' ];
$_SESSION [ 'userdata' ][ 'categories' ] = $default_userdata [ 'categories' ];
} else {
$_SESSION [ 'userdata' ][ 'features' ] = explode ( ',' , $_SESSION [ 'userdata' ][ 'features' ]);
$_SESSION [ 'userdata' ][ 'categories' ] = explode ( ',' , $_SESSION [ 'userdata' ][ 'categories' ]);
2014-03-23 16:03:30 -04:00
}
$_SESSION [ 'userdata' ][ 'cleanpass' ] = '' ;
}
2015-09-12 00:46:46 -04:00
/* Make sure we have permission to edit this user */
if ( ! compare_user_permissions ( $id , $_SESSION [ 'userdata' ][ 'isadmin' ], $_SESSION [ 'userdata' ][ 'categories' ], $_SESSION [ 'userdata' ][ 'features' ])) {
hesk_process_messages ( $hesklang [ 'npea' ], 'manage_users.php' );
}
2014-03-23 16:03:30 -04:00
/* Print header */
2015-09-12 00:46:46 -04:00
require_once ( HESK_PATH . 'inc/headerAdmin.inc.php' );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Print main manage users page */
require_once ( HESK_PATH . 'inc/show_admin_nav.inc.php' );
?>
2014-03-23 16:03:30 -04:00
< ol class = " breadcrumb " >
2015-09-12 00:46:46 -04:00
< li >< a href = " manage_users.php " >< ? php echo $hesklang [ 'manage_users' ]; ?> </a></li>
< li class = " active " >< ? php echo $hesklang [ 'editing_user' ] . ' ' . $_SESSION [ 'original_user' ]; ?> </li>
2014-03-23 16:03:30 -04:00
</ ol >
2015-09-12 00:46:46 -04:00
2016-11-15 12:58:47 -05:00
< section class = " content " >
< div class = " box " >
< div class = " box-header with-border " >
< h1 class = " box-title " >
< ? php echo $hesklang [ 'editing_user' ] . ' <b>' . $_SESSION [ 'original_user' ] . '</b>' ; ?>
</ h1 >
</ div >
< div class = " box-body " >
< ? php
/* This will handle error, success and notice messages */
hesk_handle_messages ();
?>
< h6 >< ? php echo $hesklang [ 'req_marked_with' ]; ?> <span class="important">*</span></h6>
< form role = " form " class = " form-horizontal " name = " form1 " method = " post " action = " manage_users.php " >
< ? php hesk_profile_tab ( 'userdata' , false , 'edit_user' ); ?>
</ form >
< script language = " Javascript " type = " text/javascript " ><!--
hesk_checkPassword ( document . form1 . newpass . value );
//-->
</ script >
</ div >
2014-03-23 16:03:30 -04:00
</ div >
2016-11-15 12:58:47 -05:00
</ section >
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
< ? php
require_once ( HESK_PATH . 'inc/footer.inc.php' );
exit ();
2014-03-23 16:03:30 -04:00
} // End edit_user()
function new_user ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$myuser = hesk_validateUserInfo ();
2014-03-23 16:03:30 -04:00
/* Categories and Features will be stored as a string */
2015-09-12 00:46:46 -04:00
$myuser [ 'categories' ] = implode ( ',' , $myuser [ 'categories' ]);
$myuser [ 'features' ] = implode ( ',' , $myuser [ 'features' ]);
2014-03-23 16:03:30 -04:00
/* Check for duplicate usernames */
2015-09-12 00:46:46 -04:00
$result = hesk_dbQuery ( " SELECT * FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` WHERE `user` = ' " . hesk_dbEscape ( $myuser [ 'user' ]) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $result ) != 0 ) {
hesk_process_messages ( $hesklang [ 'duplicate_user' ], 'manage_users.php' );
}
2014-03-23 16:03:30 -04:00
/* Admins will have access to all features and categories */
2015-09-12 00:46:46 -04:00
if ( $myuser [ 'isadmin' ]) {
$myuser [ 'categories' ] = '' ;
$myuser [ 'features' ] = '' ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " INSERT INTO ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` (
2015-01-18 23:58:14 -05:00
`user` ,
`pass` ,
`isadmin` ,
`name` ,
`email` ,
`signature` ,
`categories` ,
`autoassign` ,
`heskprivileges` ,
`afterreply` ,
`autostart` ,
2016-10-12 21:25:36 -04:00
`autoreload` ,
2015-01-18 23:58:14 -05:00
`notify_customer_new` ,
`notify_customer_reply` ,
`show_suggested` ,
`notify_new_unassigned` ,
`notify_new_my` ,
`notify_reply_unassigned` ,
`notify_reply_my` ,
`notify_assigned` ,
`notify_pm` ,
`notify_note` ,
2015-03-22 20:42:39 -04:00
`notify_note_unassigned` ,
2016-04-21 22:05:45 -04:00
`notify_overdue_unassigned` ,
2016-04-25 21:56:52 -04:00
`permission_template` ,
`default_calendar_view` ) VALUES (
2015-09-12 00:46:46 -04:00
'" . hesk_dbEscape($myuser[' user ']) . "' ,
'" . hesk_dbEscape($myuser[' pass ']) . "' ,
'" . intval($myuser[' isadmin ']) . "' ,
'" . hesk_dbEscape($myuser[' name ']) . "' ,
'" . hesk_dbEscape($myuser[' email ']) . "' ,
'" . hesk_dbEscape($myuser[' signature ']) . "' ,
'" . hesk_dbEscape($myuser[' categories ']) . "' ,
'" . intval($myuser[' autoassign ']) . "' ,
'" . hesk_dbEscape($myuser[' features ']) . "' ,
'" . ($myuser[' afterreply ']) . "' ,
'" . ($myuser[' autostart ']) . "' ,
2016-10-12 21:25:36 -04:00
'" . ($myuser[' autoreload ']) . "' ,
2015-09-12 00:46:46 -04:00
'" . ($myuser[' notify_customer_new ']) . "' ,
'" . ($myuser[' notify_customer_reply ']) . "' ,
'" . ($myuser[' show_suggested ']) . "' ,
'" . ($myuser[' notify_new_unassigned ']) . "' ,
'" . ($myuser[' notify_new_my ']) . "' ,
'" . ($myuser[' notify_reply_unassigned ']) . "' ,
'" . ($myuser[' notify_reply_my ']) . "' ,
'" . ($myuser[' notify_assigned ']) . "' ,
'" . ($myuser[' notify_pm ']) . "' ,
'" . ($myuser[' notify_note ']) . "' ,
'" . ($myuser[' notify_note_unassigned ']) . "' ,
2016-04-21 22:05:45 -04:00
'" . ($myuser[' notify_overdue_unassigned ']) . "' ,
2016-04-25 21:56:52 -04:00
" . intval( $myuser['template'] ) . " ,
" . intval( $myuser['default_calendar_view'] ) . " ) " );
2014-03-23 16:03:30 -04:00
$_SESSION [ 'seluser' ] = hesk_dbInsertID ();
unset ( $_SESSION [ 'userdata' ]);
2015-09-12 00:46:46 -04:00
hesk_process_messages ( sprintf ( $hesklang [ 'user_added_success' ], $myuser [ 'user' ], $myuser [ 'cleanpass' ]), './manage_users.php' , 'SUCCESS' );
2014-03-23 16:03:30 -04:00
} // End new_user()
function update_user ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ( 'POST' );
2014-03-23 16:03:30 -04:00
$_SESSION [ 'save_userdata' ] = TRUE ;
2015-09-12 00:46:46 -04:00
$tmp = intval ( hesk_POST ( 'userid' )) or hesk_error ( " $hesklang[int_error] : $hesklang[no_valid_id] " );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* To edit self fore using "Profile" page */
if ( $tmp == $_SESSION [ 'id' ]) {
hesk_process_messages ( $hesklang [ 'eyou' ], 'profile.php' , 'NOTICE' );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
$_SERVER [ 'PHP_SELF' ] = './manage_users.php?a=edit&id=' . $tmp ;
$myuser = hesk_validateUserInfo ( 0 , $_SERVER [ 'PHP_SELF' ]);
2014-03-23 16:03:30 -04:00
$myuser [ 'id' ] = $tmp ;
2015-04-05 14:22:15 -04:00
/* Only active users can be assigned tickets. Also turn off all notifications */
2015-01-18 23:58:14 -05:00
if ( ! $myuser [ 'active' ]) {
2014-10-24 23:36:27 -04:00
$myuser [ 'autoassign' ] = 0 ;
2015-01-18 23:58:14 -05:00
$myuser [ 'notify_new_unassigned' ] = 0 ;
$myuser [ 'notify_new_my' ] = 0 ;
$myuser [ 'notify_reply_unassigned' ] = 0 ;
$myuser [ 'notify_reply_my' ] = 0 ;
$myuser [ 'notify_assigned' ] = 0 ;
$myuser [ 'notify_pm' ] = 0 ;
$myuser [ 'notify_note' ] = 0 ;
$myuser [ 'notify_note_unassigned' ] = 0 ;
2016-04-21 22:05:45 -04:00
$myuser [ 'notify_overdue_unassigned' ] = 0 ;
2014-10-24 23:36:27 -04:00
}
2014-03-23 16:03:30 -04:00
/* Check for duplicate usernames */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " SELECT `id`,`isadmin`,`categories`,`heskprivileges` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` WHERE `user` = ' " . hesk_dbEscape ( $myuser [ 'user' ]) . " ' LIMIT 1 " );
if ( hesk_dbNumRows ( $res ) == 1 ) {
$tmp = hesk_dbFetchAssoc ( $res );
2014-03-23 16:03:30 -04:00
/* Duplicate? */
2015-09-12 00:46:46 -04:00
if ( $tmp [ 'id' ] != $myuser [ 'id' ]) {
hesk_process_messages ( $hesklang [ 'duplicate_user' ], $_SERVER [ 'PHP_SELF' ]);
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
/* Do we have permission to edit this user? */
if ( ! compare_user_permissions ( $tmp [ 'id' ], $tmp [ 'isadmin' ], explode ( ',' , $tmp [ 'categories' ]), explode ( ',' , $tmp [ 'heskprivileges' ]))) {
hesk_process_messages ( $hesklang [ 'npea' ], 'manage_users.php' );
}
}
2014-03-23 16:03:30 -04:00
/* Admins will have access to all features and categories */
2015-09-12 00:46:46 -04:00
if ( $myuser [ 'isadmin' ]) {
$myuser [ 'categories' ] = '' ;
$myuser [ 'features' ] = '' ;
} /* Not admin */
else {
/* Categories and Features will be stored as a string */
$myuser [ 'categories' ] = implode ( ',' , $myuser [ 'categories' ]);
$myuser [ 'features' ] = implode ( ',' , $myuser [ 'features' ]);
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* Unassign tickets from categories that the user had access before but doesn't anymore */
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `owner`=0 WHERE `owner`=' " . intval ( $myuser [ 'id' ]) . " ' AND `category` NOT IN ( " . $myuser [ 'categories' ] . " ) " );
2014-03-23 16:03:30 -04:00
}
2015-06-07 18:09:25 -04:00
// Find the list of categories they are manager of. If they no longer have access to the category, revoke their manager permission.
if ( $myuser [ 'isadmin' ]) {
// Admins can't be managers
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( 'UPDATE `' . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . 'categories` SET `manager` = 0 WHERE `manager` = ' . intval ( $myuser [ 'id' ]));
2015-06-07 18:09:25 -04:00
} else {
2015-09-12 00:46:46 -04:00
$currentCatRs = hesk_dbQuery ( " SELECT `categories` FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` WHERE `id` = ' " . intval ( $myuser [ 'id' ]) . " ' LIMIT 1 " );
2015-06-07 18:09:25 -04:00
$rowOfCategories = hesk_dbFetchAssoc ( $currentCatRs );
$cats = $rowOfCategories [ 'categories' ];
$currentCategories = explode ( ',' , $cats );
$newCategories = explode ( ',' , $myuser [ 'categories' ]);
// If any any elements are in current but not in new, add them to the revoke array
$revokeCats = array ();
foreach ( $currentCategories as $currentCategory ) {
if ( ! in_array ( $currentCategory , $newCategories ) && $currentCategory != '' ) {
array_push ( $revokeCats , $currentCategory );
}
}
if ( count ( $revokeCats ) > 0 ) {
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` SET `manager` = 0 WHERE `id` IN ( " . implode ( ',' , $revokeCats ) . " ) " );
}
}
2015-09-12 00:46:46 -04:00
hesk_dbQuery (
" UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` SET
`user` = '" . hesk_dbEscape($myuser[' user ']) . "' ,
`name` = '" . hesk_dbEscape($myuser[' name ']) . "' ,
`email` = '" . hesk_dbEscape($myuser[' email ']) . "' ,
`signature` = '" . hesk_dbEscape($myuser[' signature ']) . "' , " . (isset( $myuser['pass'] ) ? " `pass` = '" . hesk_dbEscape($myuser[' pass ']) . "' , " : '') . "
`categories` = '" . hesk_dbEscape($myuser[' categories ']) . "' ,
`isadmin` = '" . intval($myuser[' isadmin ']) . "' ,
`active` = '" . intval($myuser[' active ']) . "' ,
`autoassign` = '" . intval($myuser[' autoassign ']) . "' ,
`heskprivileges` = '" . hesk_dbEscape($myuser[' features ']) . "' ,
`afterreply` = '" . ($myuser[' afterreply ']) . "' ,
`autostart` = '" . ($myuser[' autostart ']) . "' ,
2016-10-12 21:25:36 -04:00
`autoreload` = '" . ($myuser[' autoreload ']) . "' ,
2015-09-12 00:46:46 -04:00
`notify_customer_new` = '" . ($myuser[' notify_customer_new ']) . "' ,
`notify_customer_reply` = '" . ($myuser[' notify_customer_reply ']) . "' ,
`show_suggested` = '" . ($myuser[' show_suggested ']) . "' ,
`notify_new_unassigned` = '" . ($myuser[' notify_new_unassigned ']) . "' ,
`notify_new_my` = '" . ($myuser[' notify_new_my ']) . "' ,
`notify_reply_unassigned` = '" . ($myuser[' notify_reply_unassigned ']) . "' ,
`notify_reply_my` = '" . ($myuser[' notify_reply_my ']) . "' ,
`notify_assigned` = '" . ($myuser[' notify_assigned ']) . "' ,
`notify_pm` = '" . ($myuser[' notify_pm ']) . "' ,
`notify_note` = '" . ($myuser[' notify_note ']) . "' ,
`notify_note_unassigned` = '" . ($myuser[' notify_note_unassigned ']) . "' ,
2016-04-21 22:05:45 -04:00
`notify_overdue_unassigned` = '" . ($myuser[' notify_overdue_unassigned ']) . "' ,
2016-04-25 21:56:52 -04:00
`permission_template` = " . intval( $myuser['template'] ) . " ,
`default_calendar_view` = " . intval( $myuser['default_calendar_view'] ) . "
2016-10-12 21:25:36 -04:00
WHERE `id` = '" . intval($myuser[' id ']) . "' " );
2014-03-23 16:03:30 -04:00
2015-06-07 18:09:25 -04:00
// If they are now inactive, remove any manager rights
if ( ! $myuser [ 'active' ]) {
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` SET `manager` = 0 WHERE `manager` = " . intval ( $myuser [ 'id' ]));
2015-06-07 18:09:25 -04:00
}
2014-03-23 16:03:30 -04:00
unset ( $_SESSION [ 'save_userdata' ]);
unset ( $_SESSION [ 'userdata' ]);
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $hesklang [ 'user_profile_updated_success' ], $_SERVER [ 'PHP_SELF' ], 'SUCCESS' );
2014-03-23 16:03:30 -04:00
} // End update_profile()
function hesk_validateUserInfo ( $pass_required = 1 , $redirect_to = './manage_users.php' )
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
$hesk_error_buffer = '' ;
2015-09-12 00:46:46 -04:00
$myuser [ 'name' ] = hesk_input ( hesk_POST ( 'name' )) or $hesk_error_buffer .= '<li>' . $hesklang [ 'enter_real_name' ] . '</li>' ;
$myuser [ 'email' ] = hesk_validateEmail ( hesk_POST ( 'email' ), 'ERR' , 0 ) or $hesk_error_buffer .= '<li>' . $hesklang [ 'enter_valid_email' ] . '</li>' ;
$myuser [ 'user' ] = hesk_input ( hesk_POST ( 'user' )) or $hesk_error_buffer .= '<li>' . $hesklang [ 'enter_username' ] . '</li>' ;
$myuser [ 'isadmin' ] = hesk_POST ( 'template' ) == '1' ? 1 : 0 ;
$myuser [ 'template' ] = hesk_POST ( 'template' );
$myuser [ 'signature' ] = hesk_input ( hesk_POST ( 'signature' ));
2014-03-23 16:03:30 -04:00
$myuser [ 'autoassign' ] = hesk_POST ( 'autoassign' ) == 'Y' ? 1 : 0 ;
2014-10-24 23:36:27 -04:00
$myuser [ 'active' ] = empty ( $_POST [ 'active' ]) ? 0 : 1 ;
2014-11-24 23:54:57 -05:00
$myuser [ 'can_change_notification_settings' ] = empty ( $_POST [ 'can_change_notification_settings' ]) ? 0 : 1 ;
2014-03-23 16:03:30 -04:00
/* If it's not admin at least one category and fature is required */
2015-09-12 00:46:46 -04:00
$myuser [ 'categories' ] = array ();
$myuser [ 'features' ] = array ();
if ( $myuser [ 'isadmin' ] == 0 ) {
if ( empty ( $_POST [ 'categories' ]) || ! is_array ( $_POST [ 'categories' ])) {
$hesk_error_buffer .= '<li>' . $hesklang [ 'asign_one_cat' ] . '</li>' ;
} else {
foreach ( $_POST [ 'categories' ] as $tmp ) {
if ( is_array ( $tmp )) {
continue ;
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( $tmp = intval ( $tmp )) {
$myuser [ 'categories' ][] = $tmp ;
}
}
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
if ( empty ( $_POST [ 'features' ]) || ! is_array ( $_POST [ 'features' ])) {
$hesk_error_buffer .= '<li>' . $hesklang [ 'asign_one_feat' ] . '</li>' ;
} else {
foreach ( $_POST [ 'features' ] as $tmp ) {
if ( in_array ( $tmp , $hesk_settings [ 'features' ])) {
$myuser [ 'features' ][] = $tmp ;
}
}
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
}
2014-03-23 16:03:30 -04:00
2015-12-23 08:10:22 -05:00
if ( strlen ( $myuser [ 'signature' ]) > 1000 ) {
2015-09-12 00:46:46 -04:00
$hesk_error_buffer .= '<li>' . $hesklang [ 'signature_long' ] . '</li>' ;
2014-03-23 16:03:30 -04:00
}
/* Password */
2015-09-12 00:46:46 -04:00
$myuser [ 'cleanpass' ] = '' ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$newpass = hesk_input ( hesk_POST ( 'newpass' ));
$passlen = strlen ( $newpass );
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
if ( $pass_required || $passlen > 0 ) {
2014-03-23 16:03:30 -04:00
/* At least 5 chars? */
2015-09-12 00:46:46 -04:00
if ( $passlen < 5 ) {
$hesk_error_buffer .= '<li>' . $hesklang [ 'password_not_valid' ] . '</li>' ;
} /* Check password confirmation */
else {
$newpass2 = hesk_input ( hesk_POST ( 'newpass2' ));
if ( $newpass != $newpass2 ) {
$hesk_error_buffer .= '<li>' . $hesklang [ 'passwords_not_same' ] . '</li>' ;
} else {
2014-03-23 16:03:30 -04:00
$myuser [ 'pass' ] = hesk_Pass2Hash ( $newpass );
$myuser [ 'cleanpass' ] = $newpass ;
}
}
2015-09-12 00:46:46 -04:00
}
2014-03-23 16:03:30 -04:00
2015-02-25 11:08:06 -05:00
/* After reply */
2015-09-12 00:46:46 -04:00
$myuser [ 'afterreply' ] = intval ( hesk_POST ( 'afterreply' ));
if ( $myuser [ 'afterreply' ] != 1 && $myuser [ 'afterreply' ] != 2 ) {
$myuser [ 'afterreply' ] = 0 ;
2015-02-25 11:08:06 -05:00
}
2015-01-18 23:58:14 -05:00
// Defaults
2015-09-12 00:46:46 -04:00
$myuser [ 'autostart' ] = isset ( $_POST [ 'autostart' ]) ? 1 : 0 ;
$myuser [ 'notify_customer_new' ] = isset ( $_POST [ 'notify_customer_new' ]) ? 1 : 0 ;
$myuser [ 'notify_customer_reply' ] = isset ( $_POST [ 'notify_customer_reply' ]) ? 1 : 0 ;
$myuser [ 'show_suggested' ] = isset ( $_POST [ 'show_suggested' ]) ? 1 : 0 ;
2016-10-12 21:25:36 -04:00
$myuser [ 'autoreload' ] = isset ( $_POST [ 'autoreload' ]) ? 1 : 0 ;
if ( $myuser [ 'autoreload' ]) {
$myuser [ 'autoreload' ] = intval ( hesk_POST ( 'reload_time' ));
if ( hesk_POST ( 'secmin' ) == 'min' ) {
$myuser [ 'autoreload' ] *= 60 ;
}
if ( $myuser [ 'autoreload' ] < 0 || $myuser [ 'autoreload' ] > 65535 ) {
$myuser [ 'autoreload' ] = 30 ;
}
}
2016-04-25 21:56:52 -04:00
$myuser [ 'default_calendar_view' ] = hesk_POST ( 'default-calendar-view' , 0 );
2015-01-18 23:58:14 -05:00
/* Notifications */
2015-09-12 00:46:46 -04:00
$myuser [ 'notify_new_unassigned' ] = empty ( $_POST [ 'notify_new_unassigned' ]) ? 0 : 1 ;
$myuser [ 'notify_new_my' ] = empty ( $_POST [ 'notify_new_my' ]) ? 0 : 1 ;
$myuser [ 'notify_reply_unassigned' ] = empty ( $_POST [ 'notify_reply_unassigned' ]) ? 0 : 1 ;
$myuser [ 'notify_reply_my' ] = empty ( $_POST [ 'notify_reply_my' ]) ? 0 : 1 ;
$myuser [ 'notify_assigned' ] = empty ( $_POST [ 'notify_assigned' ]) ? 0 : 1 ;
$myuser [ 'notify_note' ] = empty ( $_POST [ 'notify_note' ]) ? 0 : 1 ;
$myuser [ 'notify_pm' ] = empty ( $_POST [ 'notify_pm' ]) ? 0 : 1 ;
$myuser [ 'notify_note_unassigned' ] = empty ( $_POST [ 'notify_note_unassigned' ]) ? 0 : 1 ;
2016-04-21 22:05:45 -04:00
$myuser [ 'notify_overdue_unassigned' ] = empty ( $_POST [ 'notify_overdue_unassigned' ]) ? 0 : 1 ;
2015-01-18 23:58:14 -05:00
2014-03-23 16:03:30 -04:00
/* Save entered info in session so we don't loose it in case of errors */
2015-09-12 00:46:46 -04:00
$_SESSION [ 'userdata' ] = $myuser ;
2014-03-23 16:03:30 -04:00
/* Any errors */
2015-09-12 00:46:46 -04:00
if ( strlen ( $hesk_error_buffer )) {
if ( $myuser [ 'isadmin' ]) {
2015-02-23 22:19:50 -05:00
// Preserve default staff data for the form
global $default_userdata ;
$_SESSION [ 'userdata' ][ 'features' ] = $default_userdata [ 'features' ];
$_SESSION [ 'userdata' ][ 'categories' ] = $default_userdata [ 'categories' ];
}
2015-09-12 00:46:46 -04:00
$hesk_error_buffer = $hesklang [ 'rfm' ] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>' ;
hesk_process_messages ( $hesk_error_buffer , $redirect_to );
2015-02-23 22:19:50 -05:00
}
// "can_unban_emails" feature also enables "can_ban_emails"
2015-09-12 00:46:46 -04:00
if ( in_array ( 'can_unban_emails' , $myuser [ 'features' ]) && ! in_array ( 'can_ban_emails' , $myuser [ 'features' ])) {
2015-02-23 22:19:50 -05:00
$myuser [ 'features' ][] = 'can_ban_emails' ;
2014-03-23 16:03:30 -04:00
}
2015-02-23 22:19:50 -05:00
return $myuser ;
2014-03-23 16:03:30 -04:00
} // End hesk_validateUserInfo()
function remove ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ();
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$myuser = intval ( hesk_GET ( 'id' )) or hesk_error ( $hesklang [ 'no_valid_id' ]);
2014-03-23 16:03:30 -04:00
/* You can't delete the default user */
2015-09-12 00:46:46 -04:00
if ( $myuser == 1 ) {
hesk_process_messages ( $hesklang [ 'cant_del_admin' ], './manage_users.php' );
2014-03-23 16:03:30 -04:00
}
/* You can't delete your own account (the one you are logged in) */
2015-09-12 00:46:46 -04:00
if ( $myuser == $_SESSION [ 'id' ]) {
hesk_process_messages ( $hesklang [ 'cant_del_own' ], './manage_users.php' );
2014-03-23 16:03:30 -04:00
}
2015-06-07 18:09:25 -04:00
// Revoke manager rights
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` SET `manager` = 0 WHERE `manager` = " . intval ( $myuser ));
2015-06-07 18:09:25 -04:00
2014-03-23 16:03:30 -04:00
/* Un-assign all tickets for this user */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " tickets` SET `owner`=0 WHERE `owner`=' " . intval ( $myuser ) . " ' " );
2014-03-23 16:03:30 -04:00
/* Delete user info */
2015-09-12 00:46:46 -04:00
$res = hesk_dbQuery ( " DELETE FROM ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` WHERE `id`=' " . intval ( $myuser ) . " ' " );
if ( hesk_dbAffectedRows () != 1 ) {
hesk_process_messages ( $hesklang [ 'int_error' ] . ': ' . $hesklang [ 'user_not_found' ], './manage_users.php' );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $hesklang [ 'sel_user_removed' ], './manage_users.php' , 'SUCCESS' );
2014-03-23 16:03:30 -04:00
} // End remove()
function toggle_autoassign ()
{
2015-09-12 00:46:46 -04:00
global $hesk_settings , $hesklang ;
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
/* A security check */
hesk_token_check ();
2014-03-23 16:03:30 -04:00
2015-09-12 00:46:46 -04:00
$myuser = intval ( hesk_GET ( 'id' )) or hesk_error ( $hesklang [ 'no_valid_id' ]);
2014-03-23 16:03:30 -04:00
$_SESSION [ 'seluser' ] = $myuser ;
2015-09-12 00:46:46 -04:00
if ( intval ( hesk_GET ( 's' ))) {
$autoassign = 1 ;
2014-03-23 16:03:30 -04:00
$tmp = $hesklang [ 'uaaon' ];
2015-09-12 00:46:46 -04:00
} else {
2014-03-23 16:03:30 -04:00
$autoassign = 0 ;
$tmp = $hesklang [ 'uaaoff' ];
}
2015-09-12 00:46:46 -04:00
/* Update auto-assign settings */
$res = hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` SET `autoassign`=' { $autoassign } ' WHERE `id`=' " . intval ( $myuser ) . " ' " );
if ( hesk_dbAffectedRows () != 1 ) {
hesk_process_messages ( $hesklang [ 'int_error' ] . ': ' . $hesklang [ 'user_not_found' ], './manage_users.php' );
2014-03-23 16:03:30 -04:00
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $tmp , './manage_users.php' , 'SUCCESS' );
2014-03-23 16:03:30 -04:00
} // End toggle_autoassign()
2014-10-24 22:15:39 -04:00
function toggle_active ()
{
global $hesk_settings , $hesklang ;
/* Security check */
hesk_token_check ();
$myuser = intval ( hesk_GET ( 'id' )) or hesk_error ( $hesklang [ 'no_valid_id' ]);
$_SESSION [ 'seluser' ] = $myuser ;
2015-09-12 00:46:46 -04:00
if ( intval ( $myuser ) == $_SESSION [ 'id' ]) {
2014-10-24 23:43:10 -04:00
//-- You can't deactivate yourself!
hesk_process_messages ( $hesklang [ 'self_deactivation' ], './manage_users.php' );
}
2015-09-12 00:46:46 -04:00
if ( intval ( hesk_GET ( 's' ))) {
2014-10-24 22:15:39 -04:00
$active = 1 ;
$tmp = $hesklang [ 'user_activated' ];
2015-04-05 14:22:15 -04:00
$notificationSql = " " ;
2015-09-12 00:46:46 -04:00
} else {
2014-10-24 22:15:39 -04:00
$active = 0 ;
$tmp = $hesklang [ 'user_deactivated' ];
2015-06-07 18:09:25 -04:00
// Revoke any manager rights
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " categories` SET `manager` = 0 WHERE `manager` = " . intval ( $myuser ));
2015-06-07 18:09:25 -04:00
2016-07-24 21:44:44 -04:00
$notificationSql = " , `autoassign` = '0', `notify_new_unassigned` = '0', `notify_new_my` = '0', `notify_reply_unassigned` = '0',
`notify_reply_my` = '0' , `notify_assigned` = '0' , `notify_pm` = '0' , `notify_note` = '0' , `notify_note_unassigned` = '0' , `notify_overdue_unassigned` = '0' " ;
2014-10-24 22:15:39 -04:00
}
2015-06-07 18:09:25 -04:00
2015-09-12 00:46:46 -04:00
hesk_dbQuery ( " UPDATE ` " . hesk_dbEscape ( $hesk_settings [ 'db_pfix' ]) . " users` SET `active` = ' " . $active . " ' " . $notificationSql . " WHERE `id` = ' " . intval ( $myuser ) . " ' " );
2014-10-24 22:15:39 -04:00
if ( hesk_dbAffectedRows () != 1 ) {
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $hesklang [ 'int_error' ] . ': ' . $hesklang [ 'user_not_found' ], './manage_users.php' );
2014-10-24 22:15:39 -04:00
}
2015-09-12 00:46:46 -04:00
hesk_process_messages ( $tmp , './manage_users.php' , 'SUCCESS' );
2014-10-24 22:15:39 -04:00
}
2015-09-12 00:46:46 -04:00
2014-03-23 16:03:30 -04:00
?>