Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.7KB

  1. <?php
  2. /**
  3. *
  4. * This file is part of HESK - PHP Help Desk Software.
  5. *
  6. * (c) Copyright Klemen Stirn. All rights reserved.
  7. * http://www.hesk.com
  8. *
  9. * For the full copyright and license agreement information visit
  10. * http://www.hesk.com/eula.php
  11. *
  12. */
  13. /* Check if this is a valid include */
  14. if (!defined('IN_SCRIPT')) {die('Invalid attempt');}
  15. function hesk_initOnline($user_id)
  16. {
  17. global $hesk_settings, $hesklang;
  18. /* Set user to online */
  19. hesk_setOnline($user_id);
  20. /* Can this user view online staff? */
  21. if (hesk_checkPermission('can_view_online',0))
  22. {
  23. $hesk_settings['users_online'] = hesk_listOnline();
  24. define('SHOW_ONLINE',1);
  25. }
  26. return true;
  27. } // END hesk_initOnline()
  28. function hesk_printOnline() {
  29. global $hesk_settings, $hesklang;
  30. ?>
  31. <li class="dropdown messages-menu">
  32. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  33. <i class="fa fa-users"></i>
  34. <span class="label label-danger"><?php echo count($hesk_settings['users_online']); ?></span>
  35. </a>
  36. <ul class="dropdown-menu">
  37. <li class="header"><?php echo $hesklang['onlinep']; ?></li>
  38. <li>
  39. <ul class="menu">
  40. <?php foreach ($hesk_settings['users_online'] as $tmp): ?>
  41. <li>
  42. <?php $link = ($tmp['id'] == $_SESSION['id']) ? '' : ' href="mail.php?a=new&id='.$tmp['id'].'"'; ?>
  43. <a<?php echo $link; ?>>
  44. <div class="pull-left">
  45. <i class="fa fa-user fa-2x black"></i>
  46. </div>
  47. <h4><?php echo $tmp['name']; ?></h4>
  48. <?php
  49. if ($tmp['isadmin']): ?>
  50. <p>
  51. <span class="label label-default">
  52. <?php echo $hesklang['administrator']; ?>
  53. </span>
  54. </p>
  55. <?php elseif ($tmp['id'] == $_SESSION['id']): ?>
  56. <!--<span class="badge badge-default">You</span>-->
  57. <?php endif; ?>
  58. </a>
  59. </li>
  60. <?php endforeach; ?>
  61. </ul>
  62. </li>
  63. </ul>
  64. </li>
  65. <?php
  66. } // END hesk_printOnline()
  67. function hesk_listOnline($list_names=1)
  68. {
  69. global $hesk_settings, $hesklang, $hesk_db_link;
  70. $users_online = array();
  71. /* Clean expired entries */
  72. hesk_cleanOnline();
  73. /* Get a list of online users */
  74. /* --> With names */
  75. if ($list_names)
  76. {
  77. $res = hesk_dbQuery("SELECT `t1`.`user_id` , `t2`.`name` , `t2`.`isadmin` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."online` AS `t1` INNER JOIN `".hesk_dbEscape($hesk_settings['db_pfix'])."users` AS `t2` ON `t1`.`user_id` = `t2`.`id`");
  78. while ($tmp = hesk_dbFetchAssoc($res))
  79. {
  80. $users_online[$tmp['user_id']] = array(
  81. 'id' => $tmp['user_id'],
  82. 'name' => $tmp['name'],
  83. 'isadmin' => $tmp['isadmin']
  84. );
  85. }
  86. }
  87. /* --> Without names */
  88. else
  89. {
  90. $res = hesk_dbQuery("SELECT `user_id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."online`");
  91. while ($tmp = hesk_dbFetchAssoc($res))
  92. {
  93. $users_online[] = $tmp['user_id'];
  94. }
  95. }
  96. return $users_online;
  97. } // END hesk_listOnline()
  98. function hesk_setOnline($user_id)
  99. {
  100. global $hesk_settings, $hesklang, $hesk_db_link;
  101. /* If already online just update... */
  102. hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."online` SET `tmp` = `tmp` + 1 WHERE `user_id` = '".intval($user_id)."'");
  103. /* ... else insert a new entry */
  104. if ( ! hesk_dbAffectedRows() )
  105. {
  106. hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."online` (`user_id`) VALUES (".intval($user_id).") ");
  107. }
  108. return true;
  109. } // END hesk_setOnline()
  110. function hesk_setOffline($user_id)
  111. {
  112. global $hesk_settings, $hesklang, $hesk_db_link;
  113. /* If already online just update... */
  114. hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."online` WHERE `user_id` = '".intval($user_id)."'");
  115. return true;
  116. } // END hesk_setOffline()
  117. function hesk_cleanOnline()
  118. {
  119. global $hesk_settings, $hesklang, $hesk_db_link;
  120. /* Delete old rows from the database */
  121. hesk_dbQuery("DELETE FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."online` WHERE `dt` < ( NOW() - INTERVAL ".intval($hesk_settings['online_min'])." MINUTE) ");
  122. return true;
  123. } // END hesk_cleanOnline()