Guest User

Untitled

a guest
Sep 27th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 52.79 KB | None | 0 0
  1. <?php
  2. /*******************************************************************************
  3.  *  Title: Help Desk Software HESK
  4.  *  Version: 2.4.2 from 30th December 2012
  5.  *  Author: Klemen Stirn
  6.  *  Website: http://www.hesk.com
  7.  ********************************************************************************
  8.  *  COPYRIGHT AND TRADEMARK NOTICE
  9.  *  Copyright 2005-2012 Klemen Stirn. All Rights Reserved.
  10.  *  HESK is a registered trademark of Klemen Stirn.
  11.  *  The HESK may be used and modified free of charge by anyone
  12.  *  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
  13.  *  By using this code you agree to indemnify Klemen Stirn from any
  14.  *  liability that might arise from it's use.
  15.  *  Selling the code for this program, in part or full, without prior
  16.  *  written consent is expressly forbidden.
  17.  *  Using this code, in part or full, to create derivate work,
  18.  *  new scripts or products is expressly forbidden. Obtain permission
  19.  *  before redistributing this software over the Internet or in
  20.  *  any other medium. In all cases copyright and header must remain intact.
  21.  *  This Copyright is in full effect in any country that has International
  22.  *  Trade Agreements with the United States of America or
  23.  *  with the European Union.
  24.  *  Removing any of the copyright notices without purchasing a license
  25.  *  is expressly forbidden. To remove HESK copyright notice you must purchase
  26.  *  a license for this script. For more information on how to obtain
  27.  *  a license please visit the page below:
  28.  *  https://www.hesk.com/buy.php
  29.  *******************************************************************************/
  30.  
  31. define('IN_SCRIPT', 1);
  32. define('HESK_PATH', '../');
  33.  
  34. /* Get all the required files and functions */
  35. require(HESK_PATH . 'hesk_settings.inc.php');
  36. require(HESK_PATH . 'inc/common.inc.php');
  37. require(HESK_PATH . 'inc/admin_functions.inc.php');
  38. require(HESK_PATH . 'inc/database.inc.php');
  39.  
  40. hesk_session_start();
  41. hesk_dbConnect();
  42. hesk_isLoggedIn();
  43.  
  44. /* Check permissions for this feature */
  45. hesk_checkPermission('can_man_users');
  46.  
  47. /* Possible user features */
  48. $hesk_settings['features'] = array(
  49.     'can_view_tickets',        /* User can read tickets */
  50.     'can_reply_tickets',    /* User can reply to tickets */
  51.     'can_del_tickets',        /* User can delete tickets */
  52.     'can_edit_tickets',        /* User can edit tickets */
  53.     'can_merge_tickets',    /* User can merge tickets */
  54.     'can_del_notes',        /* User can delete ticket notes posted by other staff members */
  55.     'can_change_cat',        /* User can move ticke to a new category/department */
  56.     'can_man_kb',            /* User can manage knowledgebase articles and categories */
  57.     'can_man_users',        /* User can create and edit staff accounts */
  58.     'can_man_cat',            /* User can manage categories/departments */
  59.     'can_man_canned',        /* User can manage canned responses */
  60.     'can_man_settings',        /* User can manage help desk settings */
  61.     'can_add_archive',        /* User can mark tickets as "Tagged" */
  62.     'can_assign_self',        /* User can assign tickets to himself/herself */
  63.     'can_assign_others',    /* User can assign tickets to other staff members */
  64.     'can_view_unassigned',    /* User can view unassigned tickets */
  65.     'can_view_ass_others',    /* User can view tickets that are assigned to other staff */
  66.     'can_run_reports',        /* User can run reports and see statistics */
  67.     'can_view_online',        /* User can view what staff members are currently online */
  68. );
  69.  
  70. /* Set default values */
  71. $default_userdata = array(
  72.     'name' => '',
  73.     'email' => '',
  74.     'user' => '',
  75.     'signature' => '',
  76.     'isadmin' => 1,
  77.     'categories' => array('1'),
  78.     'features' => array('can_view_tickets', 'can_reply_tickets', 'can_change_cat', 'can_assign_self', 'can_view_unassigned', 'can_view_online'),
  79.     'signature' => '',
  80.     'cleanpass' => '',
  81. );
  82.  
  83. /* A list of all categories */
  84. $hesk_settings['categories'] = array();
  85. $sql = 'SELECT `id`,`name` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'categories` ORDER BY `cat_order` ASC';
  86. $res = hesk_dbQuery($sql);
  87. while ($row = hesk_dbFetchAssoc($res)) {
  88.     if (hesk_okCategory($row['id'], 0)) {
  89.         $hesk_settings['categories'][$row['id']] = $row['name'];
  90.     }
  91. }
  92.  
  93. /* Non-admin users may not create users with more permissions than they have */
  94. if (!$_SESSION['isadmin']) {
  95.     /* Can't create admin users */
  96.     $_POST['isadmin'] = 0;
  97.  
  98.     /* Can only add features he/she has access to */
  99.     $hesk_settings['features'] = array_intersect(explode(',', $_SESSION['heskprivileges']), $hesk_settings['features']);
  100.  
  101.     /* Can user modify auto-assign setting? */
  102.     if ($hesk_settings['autoassign'] && (!hesk_checkPermission('can_assign_self', 0) || !hesk_checkPermission('can_assign_others', 0))) {
  103.         $hesk_settings['autoassign'] = 0;
  104.     }
  105. }
  106.  
  107. /* Use any set values, default otherwise */
  108. foreach ($default_userdata as $k => $v) {
  109.     if (!isset($_SESSION['userdata'][$k])) {
  110.         $_SESSION['userdata'][$k] = $v;
  111.     }
  112. }
  113.  
  114. $_SESSION['userdata'] = hesk_stripArray($_SESSION['userdata']);
  115.  
  116. /* What should we do? */
  117. if ($action = hesk_REQUEST('a'))
  118. {
  119.     if ($action == 'reset_form') {
  120.         $_SESSION['edit_userdata'] = TRUE;
  121.         header('Location: ./manage_users.php');
  122.     } elseif ($action == 'edit') {
  123.         edit_user();
  124.     } elseif (defined('HESK_DEMO')) {
  125.         hesk_process_messages($hesklang['ddemo'], 'manage_users.php', 'NOTICE');
  126.     } elseif ($action == 'new') {
  127.         new_user();
  128.     } elseif ($action == 'save') {
  129.         update_user();
  130.     } elseif ($action == 'remove') {
  131.         remove();
  132.     } elseif ($action == 'autoassign') {
  133.         toggle_autoassign();
  134.     } else {
  135.         hesk_error($hesklang['invalid_action']);
  136.     }
  137. }
  138.  
  139. else
  140. {
  141.  
  142. /* If one came from the Edit page make sure we reset user values */
  143.  
  144. if (isset($_SESSION['save_userdata'])) {
  145.     $_SESSION['userdata'] = $default_userdata;
  146.     unset($_SESSION['save_userdata']);
  147. }
  148. if (isset($_SESSION['edit_userdata'])) {
  149.     $_SESSION['userdata'] = $default_userdata;
  150.     unset($_SESSION['edit_userdata']);
  151. }
  152.  
  153. /* Print header */
  154. require_once(HESK_PATH . 'inc/header.inc.php');
  155.  
  156. /* Print main manage users page */
  157. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  158. ?>
  159.  
  160. </td>
  161. </tr>
  162. <tr>
  163.     <td>
  164.  
  165.         <script language="Javascript" type="text/javascript"><!--
  166.             function confirm_delete() {
  167.                 if (confirm('<?php echo addslashes($hesklang['sure_remove_user']); ?>')) {
  168.                     return true;
  169.                 }
  170.                 else {
  171.                     return false;
  172.                 }
  173.             }
  174.             //-->
  175.         </script>
  176.  
  177.         <?php
  178.         /* This will handle error, success and notice messages */
  179.         hesk_handle_messages();
  180.         ?>
  181.  
  182.         <h3 style="padding-bottom:5px"><?php echo $hesklang['manage_users']; ?> [<a href="javascript:void(0)"
  183.                                                                                     onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['users_intro']); ?>')">?</a>]
  184.         </h3>
  185.  
  186.         &nbsp;<br/>
  187.  
  188.         <div align="center">
  189.             <table border="0" width="100%" cellspacing="1" cellpadding="3" class="white">
  190.                 <tr>
  191.                     <th class="admin_white" style="text-align:left"><b><i><?php echo $hesklang['name']; ?></i></b></th>
  192.                     <th class="admin_white" style="text-align:left"><b><i><?php echo $hesklang['email']; ?></i></b></th>
  193.                     <th class="admin_white" style="text-align:left"><b><i><?php echo $hesklang['username']; ?></i></b>
  194.                     </th>
  195.                     <th class="admin_white" style="text-align:center;white-space:nowrap;width:1px;">
  196.                         <b><i><?php echo $hesklang['administrator']; ?></i></b></th>
  197.                     <?php
  198.                     /* Is user rating enabled? */
  199.                     if ($hesk_settings['rating']) {
  200.                         ?>
  201.                         <th class="admin_white" style="text-align:center;white-space:nowrap;width:1px;">
  202.                             <b><i><?php echo $hesklang['rating']; ?></i></b></th>
  203.                         <?php
  204.                     }
  205.                     ?>
  206.                     <th class="admin_white" style="width:100px"><b><i>&nbsp;<?php echo $hesklang['opt']; ?>
  207.                                 &nbsp;</i></b></th>
  208.                     <th class="admin_white" style="width:100px"><b><i>&nbsp;<?php echo $hesklang['opt']; ?>
  209.                                 &nbsp;</i></b></th>
  210.                 </tr>
  211.  
  212.                 <?php
  213.                 $sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` ORDER BY `id` ASC';
  214.                 $res = hesk_dbQuery($sql);
  215.  
  216.                 $i = 1;
  217.                 $cannot_manage = array();
  218.  
  219.                 while ($myuser = hesk_dbFetchAssoc($res)) {
  220.  
  221.                     if (!compare_user_permissions($myuser['id'], $myuser['isadmin'], explode(',', $myuser['categories']), explode(',', $myuser['heskprivileges']))) {
  222.                         $cannot_manage[$myuser['id']] = array('name' => $myuser['name'], 'user' => $myuser['user'], 'email' => $myuser['email']);
  223.                         continue;
  224.                     }
  225.  
  226.                     if (isset($_SESSION['seluser']) && $myuser['id'] == $_SESSION['seluser']) {
  227.                         $color = 'admin_green';
  228.                         unset($_SESSION['seluser']);
  229.                     } else {
  230.                         $color = $i ? 'admin_white' : 'admin_gray';
  231.                     }
  232.  
  233.                     $tmp = $i ? 'White' : 'Blue';
  234.                     $style = 'class="option' . $tmp . 'OFF" onmouseover="this.className=\'option' . $tmp . 'ON\'" onmouseout="this.className=\'option' . $tmp . 'OFF\'"';
  235.                     $i = $i ? 0 : 1;
  236.  
  237.                     /* User online? */
  238.                     if ($hesk_settings['online']) {
  239.                         if (isset($hesk_settings['users_online'][$myuser['id']])) {
  240.                             $myuser['name'] = '<img src="../img/online_on.png" width="16" height="16" alt="' . $hesklang['online'] . '" title="' . $hesklang['online'] . '" style="vertical-align:text-bottom" /> ' . $myuser['name'];
  241.                         } else {
  242.                             $myuser['name'] = '<img src="../img/online_off.png" width="16" height="16" alt="' . $hesklang['offline'] . '" title="' . $hesklang['offline'] . '" style="vertical-align:text-bottom" /> ' . $myuser['name'];
  243.                         }
  244.                     }
  245.  
  246.                     /* To edit yourself go to "Profile" page, not here. */
  247.                     if ($myuser['id'] == $_SESSION['id']) {
  248.                         $edit_code = '<a href="profile.php"><img src="../img/edit.png" width="16" height="16" alt="' . $hesklang['edit'] . '" title="' . $hesklang['edit'] . '" ' . $style . ' /></a>';
  249.                     } else {
  250.                         $edit_code = '<a href="manage_users.php?a=edit&amp;id=' . $myuser['id'] . '"><img src="../img/edit.png" width="16" height="16" alt="' . $hesklang['edit'] . '" title="' . $hesklang['edit'] . '" ' . $style . ' /></a>';
  251.                     }
  252.  
  253.                     if ($myuser['isadmin']) {
  254.                         $myuser['isadmin'] = '<font class="open">' . $hesklang['yes'] . '</font>';
  255.                     } else {
  256.                         $myuser['isadmin'] = '<font class="resolved">' . $hesklang['no'] . '</font>';
  257.                     }
  258.  
  259.                     /* Deleting user with ID 1 (default administrator) is not allowed */
  260.                     if ($myuser['id'] == 1) {
  261.                         $remove_code = ' <img src="../img/blank.gif" width="16" height="16" alt="" style="padding:3px;border:none;" />';
  262.                     } else {
  263.                         $remove_code = ' <a href="manage_users.php?a=remove&amp;id=' . $myuser['id'] . '&amp;token=' . hesk_token_echo(0) . '" onclick="return confirm_delete();"><img src="../img/delete.png" width="16" height="16" alt="' . $hesklang['remove'] . '" title="' . $hesklang['remove'] . '" ' . $style . ' /></a>';
  264.                     }
  265.  
  266.                     /* Is auto assign enabled? */
  267.                     if ($hesk_settings['autoassign']) {
  268.                         if ($myuser['autoassign']) {
  269.                             $autoassign_code = '<a href="manage_users.php?a=autoassign&amp;s=0&amp;id=' . $myuser['id'] . '&amp;token=' . hesk_token_echo(0) . '"><img src="../img/autoassign_on.png" width="16" height="16" alt="' . $hesklang['aaon'] . '" title="' . $hesklang['aaon'] . '" ' . $style . ' /></a>';
  270.                         } else {
  271.                             $autoassign_code = '<a href="manage_users.php?a=autoassign&amp;s=1&amp;id=' . $myuser['id'] . '&amp;token=' . hesk_token_echo(0) . '"><img src="../img/autoassign_off.png" width="16" height="16" alt="' . $hesklang['aaoff'] . '" title="' . $hesklang['aaoff'] . '" ' . $style . ' /></a>';
  272.                         }
  273.                     } else {
  274.                         $autoassign_code = '';
  275.                     }
  276.  
  277.                     echo <<<EOC
  278. <tr>
  279. <td class="$color">$myuser[name]</td>
  280. <td class="$color"><a href="mailto:$myuser[email]">$myuser[email]</a></td>
  281. <td class="$color">$myuser[user]</td>
  282. <td class="$color">$myuser[isadmin]</td>
  283.  
  284.  
  285.  
  286. EOC;
  287.  
  288.                     if ($hesk_settings['rating']) {
  289.                         $alt = $myuser['rating'] ? sprintf($hesklang['rated'], sprintf("%01.1f", $myuser['rating']), ($myuser['ratingneg'] + $myuser['ratingpos'])) : $hesklang['not_rated'];
  290.                         echo '<td class="' . $color . '" style="text-align:center; white-space:nowrap;"><img src="../img/star_' . (hesk_round_to_half($myuser['rating']) * 10) . '.png" width="85" height="16" alt="' . $alt . '" title="' . $alt . '" border="0" style="vertical-align:text-bottom" />&nbsp;</td>';
  291.                     }
  292.  
  293.                     echo <<<EOC
  294. <td class="$color" style="text-align:center">$autoassign_code $edit_code $remove_code</td>
  295. </tr>
  296.  
  297. EOC;
  298.                 } // End while
  299.                 ?>
  300.             </table>
  301.         </div>
  302.  
  303.         <p>&nbsp;</p>
  304.  
  305.         <p>&nbsp;</p>
  306.  
  307.         <table width="100%" border="0" cellspacing="0" cellpadding="0">
  308.             <tr>
  309.                 <td width="7" height="7"><img src="../img/roundcornerslt.jpg" width="7" height="7" alt=""/></td>
  310.                 <td class="roundcornerstop"></td>
  311.                 <td><img src="../img/roundcornersrt.jpg" width="7" height="7" alt=""/></td>
  312.             </tr>
  313.             <tr>
  314.                 <td class="roundcornersleft">&nbsp;</td>
  315.                 <td>
  316.                     <!-- CONTENT -->
  317.  
  318.                     <h3 align="center"><?php echo $hesklang['add_user']; ?></h3>
  319.  
  320.                     <p align="center"><?php echo $hesklang['req_marked_with']; ?> <font class="important">*</font></p>
  321.  
  322.                     <form name="form1" action="manage_users.php" method="post">
  323.  
  324.                         <!-- Contact info -->
  325.                         <table border="0" width="100%">
  326.                             <tr>
  327.                                 <td width="200" style="text-align:right"><?php echo $hesklang['real_name']; ?>: <font
  328.                                         class="important">*</font></td>
  329.                                 <td align="left"><input type="text" name="name" size="40" maxlength="50"
  330.                                                         value="<?php echo $_SESSION['userdata']['name']; ?>"/></td>
  331.                             </tr>
  332.                             <tr>
  333.                                 <td width="200" style="text-align:right"><?php echo $hesklang['email']; ?>: <font
  334.                                         class="important">*</font></td>
  335.                                 <td align="left"><input type="text" name="email" size="40" maxlength="255"
  336.                                                         value="<?php echo $_SESSION['userdata']['email']; ?>"/></td>
  337.                             </tr>
  338.                             <tr>
  339.                                 <td width="200" style="text-align:right"><?php echo $hesklang['username']; ?>: <font
  340.                                         class="important">*</font></td>
  341.                                 <td><input type="text" name="user" size="40" maxlength="20"
  342.                                            value="<?php echo $_SESSION['userdata']['user']; ?>"/></td>
  343.                             </tr>
  344.                             <tr>
  345.                                 <td width="200" style="text-align:right"><?php echo $hesklang['pass']; ?>: <font
  346.                                         class="important">*</font></td>
  347.                                 <td><input type="password" name="newpass" autocomplete="off" size="40" maxlength="20"
  348.                                            value="<?php echo $_SESSION['userdata']['cleanpass']; ?>"
  349.                                            onkeyup="javascript:hesk_checkPassword(this.value)"/>
  350.                                 </td>
  351.                             </tr>
  352.                             <tr>
  353.                                 <td width="200" style="text-align:right"><?php echo $hesklang['confirm_pass']; ?>: <font
  354.                                         class="important">*</font></td>
  355.                                 <td><input type="password" name="newpass2" autocomplete="off" size="40" maxlength="20"
  356.                                            value="<?php echo $_SESSION['userdata']['cleanpass']; ?>"/>
  357.                                 </td>
  358.                             </tr>
  359.                             <tr>
  360.                                 <td width="200" style="text-align:right"><?php echo $hesklang['pwdst']; ?>:</td>
  361.                                 <td>
  362.                                     <div style="border: 1px solid gray; width: 100px;">
  363.                                         <div id="progressBar"
  364.                                              style="font-size: 1px; height: 14px; width: 0px; border: 1px solid white;">
  365.                                         </div>
  366.                                     </div>
  367.                                 </td>
  368.                             </tr>
  369.                             <tr>
  370.                                 <td valign="top" width="200"
  371.                                     style="text-align:right"><?php echo $hesklang['administrator']; ?>: <font
  372.                                         class="important">*</font></td>
  373.                                 <td valign="top">
  374.  
  375.                                     <?php
  376.                                     /* Only administrators can create new administrator accounts */
  377.                                     if ($_SESSION['isadmin']) {
  378.                                         ?>
  379.                                         <label><input type="radio" name="isadmin" value="1"
  380.                                                       onclick="Javascript:hesk_toggleLayerDisplay('options')" <?php if ($_SESSION['userdata']['isadmin']) echo 'checked="checked"'; ?> /> <?php echo $hesklang['yes'] . ' ' . $hesklang['admin_can']; ?>
  381.                                         </label><br/>
  382.                                         <label><input type="radio" name="isadmin" value="0"
  383.                                                       onclick="Javascript:hesk_toggleLayerDisplay('options')" <?php if (!$_SESSION['userdata']['isadmin']) echo 'checked="checked"'; ?> /> <?php echo $hesklang['no'] . ' ' . $hesklang['staff_can']; ?>
  384.                                         </label>
  385.                                         <?php
  386.                                     } else {
  387.                                         echo $hesklang['no'] . ' ' . $hesklang['staff_can'];
  388.                                     }
  389.                                     ?>
  390.                                     <div id="options"
  391.                                          style="display: <?php echo ($_SESSION['isadmin'] && $_SESSION['userdata']['isadmin']) ? 'none' : 'block'; ?>;">
  392.                                         <table width="100%" border="0">
  393.                                             <tr>
  394.                                                 <td valign="top" width="100"
  395.                                                     style="text-align:right;white-space:nowrap;"><?php echo $hesklang['allowed_cat']; ?>
  396.                                                     : <font class="important">*</font></td>
  397.                                                 <td valign="top">
  398.                                                     <?php
  399.                                                     foreach ($hesk_settings['categories'] as $catid => $catname) {
  400.                                                         echo '<label><input type="checkbox" name="categories[]" value="' . $catid . '" ';
  401.                                                         if (in_array($catid, $_SESSION['userdata']['categories'])) {
  402.                                                             echo ' checked="checked" ';
  403.                                                         }
  404.                                                         echo ' />' . $catname . '</label><br /> ';
  405.                                                     }
  406.                                                     ?>
  407.                                                     &nbsp;
  408.                                                 </td>
  409.                                             </tr>
  410.                                             <tr>
  411.                                                 <td valign="top" width="100"
  412.                                                     style="text-align:right;white-space:nowrap;"><?php echo $hesklang['allow_feat']; ?>
  413.                                                     : <font class="important">*</font></td>
  414.                                                 <td valign="top">
  415.                                                     <?php
  416.                                                     foreach ($hesk_settings['features'] as $k) {
  417.                                                         echo '<label><input type="checkbox" name="features[]" value="' . $k . '" ';
  418.                                                         if (in_array($k, $_SESSION['userdata']['features'])) {
  419.                                                             echo ' checked="checked" ';
  420.                                                         }
  421.                                                         echo ' />' . $hesklang[$k] . '</label><br /> ';
  422.                                                     }
  423.                                                     ?>
  424.                                                     &nbsp;
  425.                                                 </td>
  426.                                             </tr>
  427.                                         </table>
  428.                                     </div>
  429.  
  430.                                 </td>
  431.                             </tr>
  432.                             <?php
  433.                             if ($hesk_settings['autoassign']) {
  434.                                 ?>
  435.                                 <tr>
  436.                                     <td width="200" style="text-align:right"><?php echo $hesklang['opt']; ?>:</td>
  437.                                     <td><label><input type="checkbox" name="autoassign"
  438.                                                       value="Y" <?php if (!isset($_SESSION['userdata']['autoassign']) || $_SESSION['userdata']['autoassign'] == 1) {
  439.                                                 echo 'checked="checked"';
  440.                                             } ?> /> <?php echo $hesklang['user_aa']; ?></label></td>
  441.                                 </tr>
  442.                                 <?php
  443.                             }
  444.                             ?>
  445.                             <tr>
  446.                                 <td valign="top" width="200"
  447.                                     style="text-align:right"><?php echo $hesklang['signature_max']; ?>:
  448.                                 </td>
  449.                                 <td><textarea name="signature" rows="6"
  450.                                               cols="40"><?php echo $_SESSION['userdata']['signature']; ?></textarea><br/>
  451.                                     <?php echo $hesklang['sign_extra']; ?></td>
  452.                             </tr>
  453.                         </table>
  454.  
  455.                         <!-- Submit -->
  456.                         <p align="center"><input type="hidden" name="a" value="new"/>
  457.                             <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
  458.                             <input type="submit" value="<?php echo $hesklang['create_user']; ?>" class="orangebutton"
  459.                                    onmouseover="hesk_btn(this,'orangebuttonover');"
  460.                                    onmouseout="hesk_btn(this,'orangebutton');"/>
  461.                             |
  462.                             <a href="manage_users.php?a=reset_form"><?php echo $hesklang['refi']; ?></a></p>
  463.  
  464.                     </form>
  465.  
  466.                     <script language="Javascript" type="text/javascript"><!--
  467.                         hesk_checkPassword(document.form1.newpass.value);
  468.                         //-->
  469.                     </script>
  470.  
  471.                     <p>&nbsp;</p>
  472.  
  473.                     <!-- END CONTENT -->
  474.                 </td>
  475.                 <td class="roundcornersright">&nbsp;</td>
  476.             </tr>
  477.             <tr>
  478.                 <td><img src="../img/roundcornerslb.jpg" width="7" height="7" alt=""/></td>
  479.                 <td class="roundcornersbottom"></td>
  480.                 <td width="7" height="7"><img src="../img/roundcornersrb.jpg" width="7" height="7" alt=""/></td>
  481.             </tr>
  482.         </table>
  483.  
  484.         <?php
  485.         require_once(HESK_PATH . 'inc/footer.inc.php');
  486.         exit();
  487.  
  488.         } // End else
  489.  
  490.  
  491.         /*** START FUNCTIONS ***/
  492.  
  493.  
  494.         function compare_user_permissions($compare_id, $compare_isadmin, $compare_categories, $compare_features)
  495.         {
  496.             global $hesk_settings;
  497.  
  498.             /* Comparing myself? */
  499.             if ($compare_id == $_SESSION['id']) {
  500.                 return true;
  501.             }
  502.  
  503.             /* Admins have full access, no need to compare */
  504.             if ($_SESSION['isadmin']) {
  505.                 return true;
  506.             } elseif ($compare_isadmin) {
  507.                 return false;
  508.             }
  509.  
  510.             /* Compare categories */
  511.             foreach ($compare_categories as $catid) {
  512.                 if (!array_key_exists($catid, $hesk_settings['categories'])) {
  513.                     return false;
  514.                 }
  515.             }
  516.  
  517.             /* Compare features */
  518.             foreach ($compare_features as $feature) {
  519.                 if (!in_array($feature, $hesk_settings['features'])) {
  520.                     return false;
  521.                 }
  522.             }
  523.  
  524.             return true;
  525.  
  526.         } // END compare_user_permissions()
  527.  
  528.  
  529.         function edit_user()
  530.         {
  531.         global $hesk_settings, $hesklang, $default_userdata;
  532.  
  533.         $id = hesk_isNumber($_GET['id'], "$hesklang[int_error]: $hesklang[no_valid_id]");
  534.  
  535.         /* To edit self fore using "Profile" page */
  536.         if ($id == $_SESSION['id']) {
  537.             hesk_process_messages($hesklang['eyou'], 'profile.php', 'NOTICE');
  538.         }
  539.  
  540.         $_SESSION['edit_userdata'] = TRUE;
  541.  
  542.         if (!isset($_SESSION['save_userdata'])) {
  543.             $sql = 'SELECT `user`,`pass`,`isadmin`,`name`,`email`,`signature`,`categories`,`autoassign`,`heskprivileges` AS `features` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` WHERE `id`=' . hesk_dbEscape($id) . ' LIMIT 1';
  544.             $res = hesk_dbQuery($sql);
  545.             $_SESSION['userdata'] = hesk_dbFetchAssoc($res);
  546.  
  547.             /* Store original username for display until changes are saved successfully */
  548.             $_SESSION['original_user'] = $_SESSION['userdata']['user'];
  549.  
  550.             /* A few variables need special attention... */
  551.             if ($_SESSION['userdata']['isadmin']) {
  552.                 $_SESSION['userdata']['features'] = $default_userdata['features'];
  553.                 $_SESSION['userdata']['categories'] = $default_userdata['categories'];
  554.             } else {
  555.                 $_SESSION['userdata']['features'] = explode(',', $_SESSION['userdata']['features']);
  556.                 $_SESSION['userdata']['categories'] = explode(',', $_SESSION['userdata']['categories']);
  557.             }
  558.             $_SESSION['userdata']['cleanpass'] = '';
  559.         }
  560.  
  561.         /* Make sure we have permission to edit this user */
  562.         if (!compare_user_permissions($id, $_SESSION['userdata']['isadmin'], $_SESSION['userdata']['categories'], $_SESSION['userdata']['features'])) {
  563.             hesk_process_messages($hesklang['npea'], 'manage_users.php');
  564.         }
  565.  
  566.         /* Print header */
  567.         require_once(HESK_PATH . 'inc/header.inc.php');
  568.  
  569.         /* Print main manage users page */
  570.         require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  571.         ?>
  572.  
  573.     </td>
  574. </tr>
  575. <tr>
  576.     <td>
  577.  
  578.         <?php
  579.         /* This will handle error, success and notice messages */
  580.         hesk_handle_messages();
  581.         ?>
  582.  
  583.         <p class="smaller">&nbsp;<a href="manage_users.php" class="smaller"><?php echo $hesklang['manage_users']; ?></a>
  584.             &gt; <?php echo $hesklang['editing_user'] . ' ' . $_SESSION['original_user']; ?></p>
  585.  
  586.         <table width="100%" border="0" cellspacing="0" cellpadding="0">
  587.             <tr>
  588.                 <td width="7" height="7"><img src="../img/roundcornerslt.jpg" width="7" height="7" alt=""/></td>
  589.                 <td class="roundcornerstop"></td>
  590.                 <td><img src="../img/roundcornersrt.jpg" width="7" height="7" alt=""/></td>
  591.             </tr>
  592.             <tr>
  593.                 <td class="roundcornersleft">&nbsp;</td>
  594.                 <td>
  595.  
  596.                     <h3 align="center"><?php echo $hesklang['editing_user'] . ' ' . $_SESSION['original_user']; ?></h3>
  597.  
  598.                     <p align="center"><?php echo $hesklang['req_marked_with']; ?> <font class="important">*</font></p>
  599.  
  600.                     <form name="form1" method="post" action="manage_users.php">
  601.  
  602.                         <!-- Contact info -->
  603.                         <table border="0" width="100%">
  604.                             <tr>
  605.                                 <td width="200" style="text-align:right"><?php echo $hesklang['real_name']; ?>: <font
  606.                                         class="important">*</font></td>
  607.                                 <td align="left"><input type="text" name="name" size="40" maxlength="50"
  608.                                                         value="<?php echo $_SESSION['userdata']['name']; ?>"/></td>
  609.                             </tr>
  610.                             <tr>
  611.                                 <td width="200" style="text-align:right"><?php echo $hesklang['email']; ?>: <font
  612.                                         class="important">*</font></td>
  613.                                 <td align="left"><input type="text" name="email" size="40" maxlength="255"
  614.                                                         value="<?php echo $_SESSION['userdata']['email']; ?>"/></td>
  615.                             </tr>
  616.                             <tr>
  617.                                 <td width="200" style="text-align:right"><?php echo $hesklang['username']; ?>: <font
  618.                                         class="important">*</font></td>
  619.                                 <td><input type="text" name="user" size="40" maxlength="20"
  620.                                            value="<?php echo $_SESSION['userdata']['user']; ?>"/></td>
  621.                             </tr>
  622.                             <tr>
  623.                                 <td width="200" style="text-align:right"><?php echo $hesklang['pass']; ?>:</td>
  624.                                 <td><input type="password" name="newpass" autocomplete="off" size="40" maxlength="20"
  625.                                            value="<?php echo $_SESSION['userdata']['cleanpass']; ?>"
  626.                                            onkeyup="javascript:hesk_checkPassword(this.value)"/></td>
  627.                             </tr>
  628.                             <tr>
  629.                                 <td width="200" style="text-align:right"><?php echo $hesklang['confirm_pass']; ?>:</td>
  630.                                 <td><input type="password" name="newpass2" autocomplete="off" size="40" maxlength="20"
  631.                                            value="<?php echo $_SESSION['userdata']['cleanpass']; ?>"/></td>
  632.                             </tr>
  633.                             <tr>
  634.                                 <td width="200" style="text-align:right"><?php echo $hesklang['pwdst']; ?>:</td>
  635.                                 <td>
  636.                                     <div style="border: 1px solid gray; width: 100px;">
  637.                                         <div id="progressBar"
  638.                                              style="font-size: 1px; height: 14px; width: 0px; border: 1px solid white;">
  639.                                         </div>
  640.                                     </div>
  641.                                 </td>
  642.                             </tr>
  643.                             <tr>
  644.                                 <td valign="top" width="200"
  645.                                     style="text-align:right"><?php echo $hesklang['administrator']; ?>: <font
  646.                                         class="important">*</font></td>
  647.                                 <td valign="top">
  648.  
  649.                                     <?php
  650.                                     /* Only administrators can create new administrator accounts */
  651.                                     if ($_SESSION['isadmin']) {
  652.                                         ?>
  653.                                         <label><input type="radio" name="isadmin" value="1"
  654.                                                       onclick="Javascript:hesk_toggleLayerDisplay('options')" <?php if ($_SESSION['userdata']['isadmin']) echo 'checked="checked"'; ?> /> <?php echo $hesklang['yes'] . ' ' . $hesklang['admin_can']; ?>
  655.                                         </label><br/>
  656.                                         <label><input type="radio" name="isadmin" value="0"
  657.                                                       onclick="Javascript:hesk_toggleLayerDisplay('options')" <?php if (!$_SESSION['userdata']['isadmin']) echo 'checked="checked"'; ?> /> <?php echo $hesklang['no'] . ' ' . $hesklang['staff_can']; ?>
  658.                                         </label>
  659.                                         <?php
  660.                                     } else {
  661.                                         echo $hesklang['no'] . ' ' . $hesklang['staff_can'];
  662.                                     }
  663.                                     ?>
  664.                                     <div id="options"
  665.                                          style="display: <?php echo ($_SESSION['isadmin'] && $_SESSION['userdata']['isadmin']) ? 'none' : 'block'; ?>;">
  666.                                         <table width="100%" border="0">
  667.                                             <tr>
  668.                                                 <td valign="top" width="100"
  669.                                                     style="text-align:right;white-space:nowrap;"><?php echo $hesklang['allowed_cat']; ?>
  670.                                                     : <font class="important">*</font></td>
  671.                                                 <td valign="top">
  672.                                                     <?php
  673.                                                     foreach ($hesk_settings['categories'] as $catid => $catname) {
  674.                                                         echo '<label><input type="checkbox" name="categories[]" value="' . $catid . '" ';
  675.                                                         if (in_array($catid, $_SESSION['userdata']['categories'])) {
  676.                                                             echo ' checked="checked" ';
  677.                                                         }
  678.                                                         echo ' />' . $catname . '</label><br /> ';
  679.                                                     }
  680.                                                     ?>
  681.                                                     &nbsp;
  682.                                                 </td>
  683.                                             </tr>
  684.                                             <tr>
  685.                                                 <td valign="top" width="100"
  686.                                                     style="text-align:right;white-space:nowrap;"><?php echo $hesklang['allow_feat']; ?>
  687.                                                     : <font class="important">*</font></td>
  688.                                                 <td valign="top">
  689.                                                     <?php
  690.                                                     foreach ($hesk_settings['features'] as $k) {
  691.                                                         echo '<label><input type="checkbox" name="features[]" value="' . $k . '" ';
  692.                                                         if (in_array($k, $_SESSION['userdata']['features'])) {
  693.                                                             echo ' checked="checked" ';
  694.                                                         }
  695.                                                         echo ' />' . $hesklang[$k] . '</label><br /> ';
  696.                                                     }
  697.                                                     ?>
  698.                                                     &nbsp;
  699.                                                 </td>
  700.                                             </tr>
  701.                                         </table>
  702.                                     </div>
  703.  
  704.                                 </td>
  705.                             </tr>
  706.                             <?php
  707.                             if ($hesk_settings['autoassign']) {
  708.                                 ?>
  709.                                 <tr>
  710.                                     <td width="200" style="text-align:right"><?php echo $hesklang['opt']; ?>:</td>
  711.                                     <td><label><input type="checkbox" name="autoassign"
  712.                                                       value="Y" <?php if (isset($_SESSION['userdata']['autoassign']) && $_SESSION['userdata']['autoassign'] == 1) {
  713.                                                 echo 'checked="checked"';
  714.                                             } ?> /> <?php echo $hesklang['user_aa']; ?></label></td>
  715.                                 </tr>
  716.                                 <?php
  717.                             }
  718.                             ?>
  719.                             <tr>
  720.                                 <td valign="top" width="200"
  721.                                     style="text-align:right"><?php echo $hesklang['signature_max']; ?>:
  722.                                 </td>
  723.                                 <td><textarea name="signature" rows="6"
  724.                                               cols="40"><?php echo $_SESSION['userdata']['signature']; ?></textarea><br/>
  725.                                     <?php echo $hesklang['sign_extra']; ?></td>
  726.                             </tr>
  727.                         </table>
  728.  
  729.                         <!-- Submit -->
  730.                         <p align="center"><input type="hidden" name="a" value="save"/>
  731.                             <input type="hidden" name="userid" value="<?php echo $id; ?>"/>
  732.                             <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
  733.                             <input type="submit" value="<?php echo $hesklang['save_changes']; ?>" class="orangebutton"
  734.                                    onmouseover="hesk_btn(this,'orangebuttonover');"
  735.                                    onmouseout="hesk_btn(this,'orangebutton');"/>
  736.                             |
  737.                             <a href="manage_users.php"><?php echo $hesklang['dich']; ?></a></p>
  738.  
  739.                     </form>
  740.  
  741.                     <script language="Javascript" type="text/javascript"><!--
  742.                         hesk_checkPassword(document.form1.newpass.value);
  743.                         //-->
  744.                     </script>
  745.  
  746.                 </td>
  747.                 <td class="roundcornersright">&nbsp;</td>
  748.             </tr>
  749.             <tr>
  750.                 <td><img src="../img/roundcornerslb.jpg" width="7" height="7" alt=""/></td>
  751.                 <td class="roundcornersbottom"></td>
  752.                 <td width="7" height="7"><img src="../img/roundcornersrb.jpg" width="7" height="7" alt=""/></td>
  753.             </tr>
  754.         </table>
  755.  
  756.         <?php
  757.         require_once(HESK_PATH . 'inc/footer.inc.php');
  758.         exit();
  759.         } // End edit_user()
  760.  
  761.  
  762.         function new_user()
  763.         {
  764.             global $hesk_settings, $hesklang;
  765.  
  766.             /* A security check */
  767.             hesk_token_check($_POST['token']);
  768.  
  769.             $myuser = hesk_validateUserInfo();
  770.  
  771.             /* Can view unassigned tickets? */
  772.             if (in_array('can_view_unassigned', $myuser['features'])) {
  773.                 $sql_where = '';
  774.                 $sql_what = '';
  775.             } else {
  776.                 $sql_where = ' , `notify_new_unassigned`, `notify_reply_unassigned` ';
  777.                 $sql_what = " , '0', '0' ";
  778.             }
  779.  
  780.             /* Categories and Features will be stored as a string */
  781.             $myuser['categories'] = implode(',', $myuser['categories']);
  782.             $myuser['features'] = implode(',', $myuser['features']);
  783.  
  784.             /* Check for duplicate usernames */
  785.             $sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` WHERE `user` = \'' . hesk_dbEscape($myuser['user']) . '\' LIMIT 1';
  786.             $result = hesk_dbQuery($sql);
  787.             if (hesk_dbNumRows($result) != 0) {
  788.                 hesk_process_messages($hesklang['duplicate_user'], 'manage_users.php');
  789.             }
  790.  
  791.             /* Admins will have access to all features and categories */
  792.             if ($myuser['isadmin']) {
  793.                 $myuser['categories'] = '';
  794.                 $myuser['features'] = '';
  795.             }
  796.  
  797.             $sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` (`user`,`pass`,`isadmin`,`name`,`email`,`signature`,`categories`,`autoassign`,`heskprivileges` $sql_where) VALUES (
  798.     '" . hesk_dbEscape($myuser['user']) . "',
  799.     '" . hesk_dbEscape($myuser['pass']) . "',
  800.     '" . hesk_dbEscape($myuser['isadmin']) . "',
  801.     '" . hesk_dbEscape($myuser['name']) . "',
  802.     '" . hesk_dbEscape($myuser['email']) . "',
  803.     '" . hesk_dbEscape($myuser['signature']) . "',
  804.     '" . hesk_dbEscape($myuser['categories']) . "',
  805.     '" . hesk_dbEscape($myuser['autoassign']) . "',
  806.     '" . hesk_dbEscape($myuser['features']) . "'
  807.     $sql_what )";
  808.  
  809.             $result = hesk_dbQuery($sql);
  810.  
  811.             $_SESSION['seluser'] = hesk_dbInsertID();
  812.  
  813.             unset($_SESSION['userdata']);
  814.  
  815.             hesk_process_messages(sprintf($hesklang['user_added_success'], $myuser['user'], $myuser['cleanpass']), './manage_users.php', 'SUCCESS');
  816.         } // End new_user()
  817.  
  818.  
  819.         function update_user()
  820.         {
  821.             global $hesk_settings, $hesklang;
  822.  
  823.             /* A security check */
  824.             hesk_token_check($_POST['token']);
  825.  
  826.             $_SESSION['save_userdata'] = TRUE;
  827.  
  828.             $tmp = hesk_isNumber($_POST['userid'], "$hesklang[int_error]: $hesklang[no_valid_id]");
  829.  
  830.             /* To edit self fore using "Profile" page */
  831.             if ($tmp == $_SESSION['id']) {
  832.                 hesk_process_messages($hesklang['eyou'], 'profile.php', 'NOTICE');
  833.             }
  834.  
  835.             $_SERVER['PHP_SELF'] = './manage_users.php?a=edit&id=' . $tmp;
  836.             $myuser = hesk_validateUserInfo(0, $_SERVER['PHP_SELF']);
  837.             $myuser['id'] = $tmp;
  838.  
  839.             /* If can't view assigned changes this */
  840.             if (in_array('can_view_unassigned', $myuser['features'])) {
  841.                 $sql_where = "";
  842.             } else {
  843.                 $sql_where = " , `notify_new_unassigned`='0', `notify_reply_unassigned`='0' ";
  844.             }
  845.  
  846.             /* Check for duplicate usernames */
  847.             $sql = 'SELECT `id`,`isadmin`,`categories`,`heskprivileges` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` WHERE `user` = \'' . hesk_dbEscape($myuser['user']) . '\' LIMIT 1';
  848.             $res = hesk_dbQuery($sql);
  849.             if (hesk_dbNumRows($res) == 1) {
  850.                 $tmp = hesk_dbFetchAssoc($res);
  851.  
  852.                 /* Duplicate? */
  853.                 if ($tmp['id'] != $myuser['id']) {
  854.                     hesk_process_messages($hesklang['duplicate_user'], $_SERVER['PHP_SELF']);
  855.                 }
  856.  
  857.                 /* Do we have permission to edit this user? */
  858.                 if (!compare_user_permissions($tmp['id'], $tmp['isadmin'], explode(',', $tmp['categories']), explode(',', $tmp['heskprivileges']))) {
  859.                     hesk_process_messages($hesklang['npea'], 'manage_users.php');
  860.                 }
  861.             }
  862.  
  863.             /* Admins will have access to all features and categories */
  864.             if ($myuser['isadmin']) {
  865.                 $myuser['categories'] = '';
  866.                 $myuser['features'] = '';
  867.             } /* Not admin */
  868.             else {
  869.                 /* Categories and Features will be stored as a string */
  870.                 $myuser['categories'] = implode(',', $myuser['categories']);
  871.                 $myuser['features'] = implode(',', $myuser['features']);
  872.  
  873.                 /* Unassign tickets from categories that the user had access before but doesn't anymore */
  874.                 $sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `owner`=0 WHERE `owner`=" . hesk_dbEscape($myuser['id']) . " AND `category` NOT IN (" . $myuser['categories'] . ")";
  875.                 $res = hesk_dbQuery($sql);
  876.             }
  877.  
  878.             $sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` SET
  879.    `user`='" . hesk_dbEscape($myuser['user']) . "',
  880.    `name`='" . hesk_dbEscape($myuser['name']) . "',
  881.    `email`='" . hesk_dbEscape($myuser['email']) . "',
  882.    `signature`='" . hesk_dbEscape($myuser['signature']) . "',";
  883.             if (isset($myuser['pass'])) {
  884.                 $sql .= "`pass`='" . hesk_dbEscape($myuser['pass']) . "',";
  885.             }
  886.             $sql .= "
  887.    `categories`='" . hesk_dbEscape($myuser['categories']) . "',
  888.    `isadmin`='" . hesk_dbEscape($myuser['isadmin']) . "',
  889.    `autoassign`='" . hesk_dbEscape($myuser['autoassign']) . "',
  890.    `heskprivileges`='" . hesk_dbEscape($myuser['features']) . "'
  891.    $sql_where
  892.    WHERE `id`=" . hesk_dbEscape($myuser['id']) . " LIMIT 1";
  893.             $result = hesk_dbQuery($sql);
  894.  
  895.             unset($_SESSION['save_userdata']);
  896.             unset($_SESSION['userdata']);
  897.  
  898.             hesk_process_messages($hesklang['user_profile_updated_success'], $_SERVER['PHP_SELF'], 'SUCCESS');
  899.         } // End update_profile()
  900.  
  901.  
  902.         function hesk_validateUserInfo($pass_required = 1, $redirect_to = './manage_users.php')
  903.         {
  904.             global $hesk_settings, $hesklang;
  905.  
  906.             $hesk_error_buffer = '';
  907.  
  908.             $myuser['name'] = hesk_input($_POST['name']) or $hesk_error_buffer .= '<li>' . $hesklang['enter_real_name'] . '</li>';
  909.             $myuser['email'] = hesk_validateEmail($_POST['email'], 'ERR', 0) or $hesk_error_buffer .= '<li>' . $hesklang['enter_valid_email'] . '</li>';
  910.             $myuser['user'] = hesk_input($_POST['user']) or $hesk_error_buffer .= '<li>' . $hesklang['enter_username'] . '</li>';
  911.             $myuser['isadmin'] = intval($_POST['isadmin']) ? 1 : 0;
  912.             $myuser['signature'] = hesk_input($_POST['signature']);
  913.             $myuser['autoassign'] = isset($_POST['autoassign']) && $_POST['autoassign'] == 'Y' ? 1 : 0;
  914.  
  915.             /* If it's not admin at least one category and fature is required */
  916.             $myuser['categories'] = array();
  917.             $myuser['features'] = array();
  918.  
  919.             if ($myuser['isadmin'] == 0) {
  920.                 if (empty($_POST['categories'])) {
  921.                     $hesk_error_buffer .= '<li>' . $hesklang['asign_one_cat'] . '</li>';
  922.                 } else {
  923.                     foreach ($_POST['categories'] as $tmp) {
  924.                         if ($tmp = intval($tmp)) {
  925.                             $myuser['categories'][] = $tmp;
  926.                         }
  927.                     }
  928.                 }
  929.  
  930.                 if (empty($_POST['features'])) {
  931.                     $hesk_error_buffer .= '<li>' . $hesklang['asign_one_feat'] . '</li>';
  932.                 } else {
  933.                     foreach ($_POST['features'] as $tmp) {
  934.                         if (in_array($tmp, $hesk_settings['features'])) {
  935.                             $myuser['features'][] = $tmp;
  936.                         }
  937.                     }
  938.                 }
  939.             }
  940.  
  941.             if (strlen($myuser['signature']) > 255) {
  942.                 $hesk_error_buffer .= '<li>' . $hesklang['signature_long'] . '</li>';
  943.             }
  944.  
  945.             /* Password */
  946.             $myuser['cleanpass'] = '';
  947.  
  948.             $newpass = hesk_input($_POST['newpass']);
  949.             $passlen = strlen($newpass);
  950.  
  951.             if ($pass_required || $passlen > 0) {
  952.                 /* At least 5 chars? */
  953.                 if ($passlen < 5) {
  954.                     $hesk_error_buffer .= '<li>' . $hesklang['password_not_valid'] . '</li>';
  955.                 } /* Check password confirmation */
  956.                 else {
  957.                     $newpass2 = hesk_input($_POST['newpass2']);
  958.  
  959.                     if ($newpass != $newpass2) {
  960.                         $hesk_error_buffer .= '<li>' . $hesklang['passwords_not_same'] . '</li>';
  961.                     } else {
  962.                         $myuser['pass'] = hesk_Pass2Hash($newpass);
  963.                         $myuser['cleanpass'] = $newpass;
  964.                     }
  965.                 }
  966.             }
  967.  
  968.             /* Save entered info in session so we don't loose it in case of errors */
  969.             $_SESSION['userdata'] = $myuser;
  970.  
  971.             /* Any errors */
  972.             if (strlen($hesk_error_buffer)) {
  973.                 $hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>';
  974.                 hesk_process_messages($hesk_error_buffer, $redirect_to);
  975.             }
  976.  
  977.             return $myuser;
  978.  
  979.         } // End hesk_validateUserInfo()
  980.  
  981.  
  982.         function remove()
  983.         {
  984.             global $hesk_settings, $hesklang;
  985.  
  986.             /* A security check */
  987.             hesk_token_check($_GET['token']);
  988.  
  989.             $myuser = hesk_isNumber($_GET['id'], $hesklang['no_valid_id']);
  990.  
  991.             /* You can't delete the default user */
  992.             if ($myuser == 1) {
  993.                 hesk_process_messages($hesklang['cant_del_admin'], './manage_users.php');
  994.             }
  995.  
  996.             /* You can't delete your own account (the one you are logged in) */
  997.             if ($myuser == $_SESSION['id']) {
  998.                 hesk_process_messages($hesklang['cant_del_own'], './manage_users.php');
  999.             }
  1000.  
  1001.             /* Un-assign all tickets for this user */
  1002.             $sql = 'UPDATE `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'tickets` SET `owner`=0 WHERE `owner`=' . hesk_dbEscape($myuser) . ' ';
  1003.             $res = hesk_dbQuery($sql);
  1004.  
  1005.             /* Delete user info */
  1006.             $sql = 'DELETE FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` WHERE `id`=' . hesk_dbEscape($myuser) . ' LIMIT 1';
  1007.             $res = hesk_dbQuery($sql);
  1008.             if (hesk_dbAffectedRows() != 1) {
  1009.                 hesk_process_messages($hesklang['int_error'] . ': ' . $hesklang['user_not_found'], './manage_users.php');
  1010.             }
  1011.  
  1012.             hesk_process_messages($hesklang['sel_user_removed'], './manage_users.php', 'SUCCESS');
  1013.         } // End remove()
  1014.  
  1015.  
  1016.         function toggle_autoassign()
  1017.         {
  1018.             global $hesk_settings, $hesklang;
  1019.  
  1020.             /* A security check */
  1021.             hesk_token_check($_GET['token']);
  1022.  
  1023.             $myuser = hesk_isNumber($_GET['id'], $hesklang['no_valid_id']);
  1024.             $_SESSION['seluser'] = $myuser;
  1025.  
  1026.             if (intval($_GET['s'])) {
  1027.                 $autoassign = 1;
  1028.                 $tmp = $hesklang['uaaon'];
  1029.             } else {
  1030.                 $autoassign = 0;
  1031.                 $tmp = $hesklang['uaaoff'];
  1032.             }
  1033.  
  1034.             /* Update auto-assign settings */
  1035.             $sql = 'UPDATE `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'users` SET `autoassign`=\'' . hesk_dbEscape($autoassign) . '\' WHERE `id`=' . hesk_dbEscape($myuser) . ' LIMIT 1';
  1036.             $res = hesk_dbQuery($sql);
  1037.             if (hesk_dbAffectedRows() != 1) {
  1038.                 hesk_process_messages($hesklang['int_error'] . ': ' . $hesklang['user_not_found'], './manage_users.php');
  1039.             }
  1040.  
  1041.             hesk_process_messages($tmp, './manage_users.php', 'SUCCESS');
  1042.         } // End toggle_autoassign()
  1043.         ?>
Add Comment
Please, Sign In to add comment