| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | if (!defined('DEBUG_MODE')) { die(); } |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class Hm_Handler_idle_time_check extends Hm_Handler_Module { |
| 15: | public function process() { |
| 16: | $logout = false; |
| 17: | if ($this->session->loaded) { |
| 18: | $this->session->set('idletime_start', time()); |
| 19: | } |
| 20: | $start = $this->session->get('idletime_start', 0); |
| 21: | if (!$start) { |
| 22: | $logout = true; |
| 23: | } |
| 24: | else { |
| 25: | $max = $this->user_config->get('idle_time', 0)*60*60; |
| 26: | if ($max && (time() - $start) > $max) { |
| 27: | $logout = true; |
| 28: | } |
| 29: | } |
| 30: | if ($logout) { |
| 31: | Hm_Debug::add('IDLETIMER: timer exceeded, logged out', 'warning'); |
| 32: | $this->session->destroy($this->request); |
| 33: | } |
| 34: | else { |
| 35: | $this->session->set('idletime_start', time()); |
| 36: | } |
| 37: | } |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | class Hm_Handler_process_idle_time extends Hm_Handler_Module { |
| 44: | public function process() { |
| 45: | $idle_time = 0; |
| 46: | if (array_key_exists('idle_time', $this->request->post)) { |
| 47: | $idle_time = $this->request->post['idle_time']/60; |
| 48: | } |
| 49: | $max = $this->user_config->get('idle_time', 1)*60; |
| 50: | if ($max && $idle_time >= $max) { |
| 51: | Hm_Debug::add('IDLETIMER: Logged out after idle period', 'warning'); |
| 52: | $this->session->destroy($this->request); |
| 53: | } |
| 54: | } |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | class Hm_Handler_process_idle_time_setting extends Hm_Handler_Module { |
| 61: | public function process() { |
| 62: | list($success, $form) = $this->process_form(array('save_settings', 'idle_time')); |
| 63: | $new_settings = $this->get('new_user_settings', array()); |
| 64: | $settings = $this->get('user_settings', array()); |
| 65: | |
| 66: | if ($success) { |
| 67: | if (in_array($form['idle_time'], array(0, 1, 2, 3, 24), true)) { |
| 68: | $new_settings['idle_time'] = $form['idle_time']; |
| 69: | } |
| 70: | else { |
| 71: | $settings['idle_time'] = $this->user_config->get('idle_time', false); |
| 72: | } |
| 73: | } |
| 74: | else { |
| 75: | $settings['idle_time'] = $this->user_config->get('idle_time', false); |
| 76: | } |
| 77: | $this->out('new_user_settings', $new_settings, false); |
| 78: | $this->out('user_settings', $settings, false); |
| 79: | } |
| 80: | } |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | class Hm_Output_idle_time_setting extends Hm_Output_Module { |
| 86: | protected function output() { |
| 87: | $options = array( |
| 88: | 1 => '1 Hour', |
| 89: | 2 => '2 Hours', |
| 90: | 3 => '3 Hours', |
| 91: | 24 => '1 Day', |
| 92: | 0 => 'Forever' |
| 93: | ); |
| 94: | $settings = $this->get('user_settings', array()); |
| 95: | $reset = ''; |
| 96: | |
| 97: | if (array_key_exists('idle_time', $settings)) { |
| 98: | $idle_time = $settings['idle_time']; |
| 99: | } |
| 100: | else { |
| 101: | $idle_time = 1; |
| 102: | } |
| 103: | $res = '<tr class="general_setting"><td><label for="idle_time">'.$this->trans('Allowed idle time until logout').'</label></td>'. |
| 104: | '<td><select class="form-select form-select-sm w-auto" id="idle_time" name="idle_time">'; |
| 105: | foreach ($options as $val => $label) { |
| 106: | $res .= '<option '; |
| 107: | if ($idle_time == $val) { |
| 108: | $res .= 'selected="selected" '; |
| 109: | if ($idle_time != '0') { |
| 110: | $reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-counterclockwise refresh_list reset_default_value_select"></i></span>'; |
| 111: | } |
| 112: | } |
| 113: | $res .= 'value="'.$val.'">'.$this->trans($label).'</option>'; |
| 114: | } |
| 115: | $res .= '</select>'.$reset.'</td></tr>'; |
| 116: | return $res; |
| 117: | } |
| 118: | } |
| 119: | |