Example #1
0
 private function send_page($page)
 {
     if (is_ajax()) {
         /* AJAX request: We only need to send html parts and commands generated for this page. */
         require_once dirname(__FILE__) . '/pages/' . $page . '.php';
         $args = func_get_args();
         /* Call page object with arguments ($esxman, $database, [, $arg[, ...]]). */
         $args[0] = $this->database;
         array_unshift($args, $this);
         $reflector = new ReflectionClass('page_' . $page);
         $object = $reflector->newInstanceArgs($args);
         $result = $object->html;
         $result['commands'] = $object->commands;
         /* Set inactivity timer and inventory change timer. */
         if (!preg_match('/^(login|console)$/', $page)) {
             if (request('reason') != 'inventory') {
                 $result['commands'][] = 'start_inactivity_timer(' . $this->config['timeout'] . ');';
             }
             $result['commands'][] = 'get_inventory_changes();';
         }
         echo json_encode($result);
     } else {
         /* Non-AJAX request: We need to initialize objects and timers and stuff. */
         $tpl = new Template($page == 'console' ? 'console.html' : 'main.html');
         $commands = array();
         /* Fetch content for div elements, except main content. */
         $vars = $tpl->getVars();
         foreach ($vars as $var) {
             if (preg_match('/div$/', $var) && $var != 'contentdiv' && !isset($object->html[preg_replace('/div$/', '', $var)])) {
                 require_once dirname(__FILE__) . '/blocks/' . preg_replace('/div$/', '', $var) . '.php';
                 $blockobjectname = 'block_' . preg_replace('/div$/', '', $var);
                 $blockobject = new $blockobjectname($this->username, $this->database);
                 $tpl->setVar($var, $blockobject->html, true);
                 $commands = array_merge($commands, $blockobject->commands);
             }
         }
         /* Add javascript commands. */
         $commands[] = "\$('#wrapper').css('display', 'block');";
         $commands[] = "var label_bummer = '" . _('Bummer') . "';";
         $commands[] = "var label_waitdotdotdot = '" . _('Wait...') . "';";
         $commands[] = "var label_pleasewait = '" . _('Please wait...') . "';";
         $commands[] = "var inactivity_timer = null;";
         $commands[] = "var inventory_timer = null;";
         $commands[] = "get(document.URL.replace(/.*(#\\/|\\?)/, ''));";
         $tpl->setVar('commands', implode("\n", $commands));
         echo $tpl->get();
     }
     exit;
 }