Example #1
0
 public static function update_profile(stdClass $profile, $profile_password)
 {
     hd_print("API: method 'update_profile'");
     return HD::make_json_rpc_request('update_profile', array('macaddr' => ZTVApi::get_mac_addr(), 'profile_id' => $profile->id, 'profile_password' => $profile_password));
 }
Example #2
0
 public static function get_epg($media_id, $limit, $start, $stop)
 {
     hd_print("API: method 'get_epg'");
     return HD::make_json_rpc_request('get_epg', array('media_id' => $media_id, 'limit' => $limit, 'start' => SWRNApi::format_timestamp($start), 'stop' => SWRNApi::format_timestamp($stop)));
 }
 public function handle_user_input(&$user_input, &$plugin_cookies)
 {
     if (!isset($user_input->control_id)) {
         if ($plugin_cookies->require_restart) {
             ZTVDaemonController::restart($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array());
             $plugin_cookies->require_restart = false;
         }
         if (!ZTVTerminal::login()) {
             return ActionFactory::show_dialog('Введите регистрационные данные', $this->do_registration_form_defs($plugin_cookies), true);
         }
         $result = $this->load_profiles();
         if ($result) {
             if ($this->profile->require_password) {
                 return ActionFactory::show_dialog('Введите пароль профиля ' . $this->profile->title, $this->do_profile_form_defs($plugin_cookies, false), true);
             }
             return ActionFactory::open_folder();
         }
         return;
     } else {
         if ($user_input->action_type == 'confirm' || $user_input->action_type == 'apply') {
             switch ($user_input->control_id) {
                 case 'use_proxy':
                     $plugin_cookies->use_proxy = $user_input->use_proxy;
                     $plugin_cookies->proxy_ip = isset($plugin_cookies->proxy_ip) ? $plugin_cookies->proxy_ip : '192.168.0.1';
                     $plugin_cookies->proxy_port = isset($plugin_cookies->proxy_port) ? $plugin_cookies->proxy_port : '8080';
                     $plugin_cookies->require_restart = true;
                     break;
                 case 'proxy_ip':
                     $plugin_cookies->proxy_ip = $user_input->proxy_ip;
                     $plugin_cookies->require_restart = true;
                     break;
                 case 'proxy_port':
                     $plugin_cookies->proxy_port = $user_input->proxy_port;
                     $plugin_cookies->require_restart = true;
                     break;
                 case 'daemon_start_button':
                     ZTVDaemonController::start($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array());
                     break;
                 case 'daemon_restart_button':
                     ZTVDaemonController::restart($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array());
                     break;
                 case 'daemon_stop_button':
                     ZTVDaemonController::stop();
                     break;
                 case 'register_button':
                     return ActionFactory::show_dialog('Введите регистрационные данные', $this->do_registration_form_defs($plugin_cookies), true);
                     break;
                 case 'register_terminal':
                     if (is_null($user_input->username) || trim($user_input->username) === '') {
                         return ActionFactory::show_error(false, 'Ошибка', array('Идентификатор не может быть пустым.'));
                     } else {
                         if (is_null($user_input->password) || trim($user_input->password) === '') {
                             return ActionFactory::show_error(false, 'Ошибка', array('PIN-код не может быть пустым.'));
                         }
                     }
                     if (!ZTVTerminal::register($user_input->username, $user_input->password)) {
                         return ActionFactory::show_error(false, 'Ошибка', array('Неверный идентификатор или PIN-код.'));
                     }
                     $plugin_cookies->username = $user_input->username;
                     $plugin_cookies->password = $user_input->password;
                     if ($user_input->selected_media_url == 'setup') {
                         return ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('Вход выполнен.'));
                     }
                     return ActionFactory::close_dialog_and_run(ActionFactory::open_folder());
                     break;
                 case 'deregister_terminal':
                     if (ZTVTerminal::deregister() && $user_input->selected_media_url == 'setup') {
                         return ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('Выход выполнен.'));
                     }
                     return ActionFactory::show_error(false, 'Ошибка', array('Не удалось выполненить выход.'));
                     break;
                 case 'register_cancel':
                     if (ZTVTerminal::login() && $user_input->selected_media_url != 'setup') {
                         return ActionFactory::close_dialog_and_run(ActionFactory::open_folder());
                     }
                     return ActionFactory::reset_controls($this->do_registration_form_defs($plugin_cookies));
                     break;
                 case 'profile':
                     $this->profile = $this->profiles[$user_input->profile];
                     if ($this->profile->require_password) {
                         return ActionFactory::show_dialog('Введите пароль профиля ' . $this->profile->title, $this->do_profile_form_defs($plugin_cookies, $this->profile->require_password && !$this->profile->password), true);
                     }
                     if ($this->tv->set_profile($this->profile->id)) {
                         return ActionFactory::show_title_dialog('Профиль успешно установлен');
                     }
                     break;
                 case 'set_profile_password':
                     if (!$user_input->profile_password) {
                         return ActionFactory::show_error(false, 'Ошибка', array('Пароль не задан.'));
                     }
                     if ($user_input->profile_password != $user_input->profile_password_repeat) {
                         return ActionFactory::show_error(false, 'Ошибка', array('Введенные пароли не совпадают.'));
                     }
                     $result = $this->tv->api_call(array(HD::make_json_rpc_request('set_terminal_params', array('macaddr' => HD::get_mac_addr_dashed(), 'profile_id' => $this->profile->id)), HD::make_json_rpc_request('update_profile', array('macaddr' => HD::get_mac_addr_dashed(), 'profile_id' => $this->profile->id, 'profile_password' => $user_input->profile_password))));
                     if (count($result) == 2 && $result[0]->result && $result[1]->result) {
                         return ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('Профиль успешно установлен'));
                     }
                     return;
                     break;
                 case 'verify_profile_password':
                     if ($user_input->profile_password != $this->profile->password) {
                         return ActionFactory::show_error(false, 'Ошибка', array('Неверный пароль.'));
                     }
                     if ($user_input->selected_media_url != 'setup') {
                         return ActionFactory::close_dialog_and_run(ActionFactory::open_folder());
                     }
                     $result = $this->tv->set_profile($this->profile->id);
                     if ($result) {
                         return ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('Профиль успешно установлен'));
                     }
                     return;
                     break;
                 case 'profile_cancel':
                     $result = $this->tv->set_profile(1);
                     if (!$result) {
                         return;
                     }
                     if ($user_input->selected_media_url != 'setup') {
                         return ActionFactory::close_dialog_and_run(ActionFactory::open_folder());
                     }
                     $this->profile = $this->profiles[1];
                     return ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('Установлен профиль по умолчанию(' . $this->profile->title . ')'));
                     break;
             }
         }
     }
     return ActionFactory::reset_controls($this->do_get_control_defs($plugin_cookies));
 }