Пример #1
0
 public function handle_request($get, $post, $cookie)
 {
     $env =& $this->server;
     $cfg =& $this->config;
     $sess =& $this->session;
     $action = empty($post['action']) ? empty($get['action']) ? '' : $get['action'] : $post['action'];
     if ($action === 'session-dump') {
         header("Content-Type: text/plain");
         print_r($_SESSION);
         return;
     }
     if ($action === 'logout') {
         foreach ($sess as $k => $v) {
             unset($sess[$k]);
         }
         return $this->redirect('');
     }
     if (empty($sess['user_id']) || !$sess['user_id']) {
         $ok = false;
         if ($action === 'login') {
             $ok = $this->handle_login($get, $post, $cookie);
         }
         if (!$ok) {
             return $this->show_login_form($get, $post, $cookie);
         }
     }
     $is_admin = $_SESSION['roles'][ROLE_ADMINISTRATOR];
     $parts = explode('/', $env['PATH_INFO']);
     if (empty($parts[0])) {
         array_shift($parts);
     }
     $component = array_shift($parts);
     $id = array_shift($parts);
     if (empty($component)) {
         return $this->redirect('client');
     } elseif ($component === 'client') {
         $crud = new ClientForm($is_admin, $this->config, $this);
         if ($id && !empty($parts[0])) {
             $form_id = $parts[0];
             return $crud->handle_form($id, $form_id, $get, $post, $cookie);
         } elseif ($id) {
             return $crud->handle_client($id, $get, $post, $cookie);
         } else {
             return $crud->handle_list($get, $post, $cookie);
         }
     } elseif ($component === 'form') {
         $crud = new FormManager($is_admin, $this->config, $this);
         if (strlen($id)) {
             return $crud->handle_form($id, $parts, $get, $post, $cookie);
         } else {
             return $crud->handle_list($parts, $get, $post, $cookie);
         }
     } elseif ($is_admin) {
         $crud = new CrudForm($component, $this->config, $this);
         return $id ? $crud->handle_item($id, $parts, $get, $post, $cookie) : $crud->handle_index($parts, $get, $post, $cookie);
     } else {
         return $this->error_message('Permission denied. Administrator access required.');
     }
 }