Example #1
0
 public static final function showError($error)
 {
     $view = View::setFile('error');
     $view->setValue('L_message', $error);
     $view->setValue('U_ok', '?');
     return self::setBody($view);
 }
Example #2
0
 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('Not In');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $view = View::setFile('map', View::HTML_FILE);
     /**
      * Links
      */
     $result = F::i(_DBMS_SYS)->query('SELECT cou1.cou_name AS cou1, cou2.cou_name AS cou2 FROM !prefix_adjacent a, !prefix_countries cou1, !prefix_countries cou2 WHERE a.cou_id1 = cou1.cou_id AND a.cou_id2 = cou2.cou_id');
     while (($obj = $result->getObject()) != NULL) {
         $view->setGroupValues('adjacents', array('from' => $obj->cou1, 'to' => $obj->cou2));
     }
     $view->setValue('game', $game->g_id);
     $view->setValue('mode', isset($params['mode']) ? $params['mode'] : 'owner');
     $view->setValue('confirmed', $game->getPlayer(F::i('Session')->getMid())->p_ready);
     $view->setValue('step', $game->g_step);
     $view->setValue('m_id', F::i('Session')->getMid());
     return parent::setBody($view, '', TRUE);
 }
Example #3
0
 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if ($game->g_step > 0) {
             throw new Exception('Game already launched');
         }
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('You are not in this game');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust ! : ' . $e);
     }
     if ($synchrone) {
         $view = View::setFile('wait_game', View::HTML_FILE);
         $view->setValue('u_js', '?action=wait_game&game=' . $game->g_id);
         $view->setValue('u_leave', '?action=leave_game&game=' . $game->g_id);
         $view->setValue('game', stripslashes($game->g_name));
         if ($game->m_id == F::i('Session')->getMid()) {
             $view->setSwitch('creator', TRUE);
             $view->setValue('u_launch', '?action=launch_game&game=' . $game->g_id);
         }
         return parent::setBody($view, F::i('Lang')->getKey('title_wait_game'));
     } else {
         $view = View::setFile('wait_game', View::JSON_FILE);
         $players = $game->getPlayers();
         for ($i = 0; $i < count($players); $i++) {
             $view->setGroupValues('players', array('name' => $players[$i]->m_login, 'color' => $players[$i]->col_code, 'col_name' => $players[$i]->col_name));
         }
         return $view->getContent();
     }
 }
Example #4
0
 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     $title = '';
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         $access_key = isset($params['access_key']) && !empty($params['access_key']) ? Tools::saltHash($params['access_key']) : 'NULL';
         // Create Game
         $game = Game::create(F::i('Session')->getMid(), $params['name'], $access_key);
         Tools::redirect('?action=wait_game&game=' . $game->g_id);
     } else {
         // Generate form
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('Create'), '#', 'POST', 'tabbed_form'));
         $title = F::i('Lang')->getKey('title_new_game');
     }
     return parent::setBody($view, $title);
 }
Example #5
0
 public function getView($params, $synchrone)
 {
     $form = new Form(self::getFields(), $params);
     $view = View::setFile('chatbox', View::JSON_FILE);
     $fields = Chatbox::getFields();
     if (F::i('Session')->isConnected()) {
         $fields['name']['disabled'] = TRUE;
     }
     $errors = $form->getErrors();
     if (!Tools::isEmpty($errors)) {
         foreach ($errors as $field => $msg) {
             $view->setGroupValues('error', array('field' => $field, 'errmsg' => $msg));
         }
     }
     // If Submitting
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // TODO Sauvegarde du pseudo en cookie
         // Enregistrement des données
         if (F::i('Session')->isConnected()) {
             $m_name = '';
         } else {
             $m_name = $params['name'];
             self::setNickname($m_name);
         }
         F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_chatbox_messages (m_id, m_name, mes_content) VALUES (?, ?, ?)', array(F::i('Session')->getMid(), $m_name, $params['content']));
         // Et sortie
         return;
     }
     // Recuperation des derniers messages
     $sql = 'SELECT mes.m_name, m.m_login, mes.m_id, mes_content, UNIX_TIMESTAMP(mes_date) AS mes_date FROM !prefix_chatbox_messages mes, !prefix_members m WHERE m.m_id = mes.m_id';
     $array = array();
     // si une date est donnée, tous les messages depuis cette date
     if (isset($params['since'])) {
         $sql .= ' AND mes_date > FROM_UNIXTIME(?)';
         $array[] = $params['since'];
     }
     // sinon, limiter à _LIMIT_LAST_CHATBOX messages
     $sql .= ' ORDER BY mes_date DESC';
     if (!isset($params['since'])) {
         $sql .= ' LIMIT ?';
         $array[] = _LIMIT_LAST_CHATBOX;
     }
     // Generation d'un pseudo si non connecté et pseudo non fourni
     // Si connecté, verouiller le pseudo
     $result = F::i(_DBMS_SYS)->query($sql, $array);
     // Recover messages and switch the order to get the last _LIMIT_LAST_CHATBOX messages but the last at the end.
     $messages = array();
     for ($i = 0; $i < $result->getNumRows(); $i++) {
         $obj = $result->getObject();
         $messages[] = array('author_mid' => $obj->m_id, 'author_name' => $obj->m_id == _ID_VISITOR ? $obj->m_name : $obj->m_login, 'content' => htmlentities($obj->mes_content, ENT_QUOTES, 'UTF-8', TRUE), 'date' => $obj->mes_date);
     }
     $messages = array_reverse($messages);
     for ($i = 0; $i < count($messages); $i++) {
         $view->setGroupValues('message', $messages[$i]);
     }
     return $view->getContent();
 }
Example #6
0
 public function getView($params, $synchrone)
 {
     try {
         if (!isset($params['game'])) {
             throw new Exception('No Game given');
         }
         $game = new Game($params['game']);
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $params['mode'] = isset($params['mode']) ? $params['mode'] : '';
     switch ($params['mode']) {
         case 'continents':
             $mode = 'continents';
             break;
         case 'owner':
         default:
             $mode = 'owner';
     }
     $view = View::setFile('map', View::SVG_FILE);
     /**
      * Territories
      */
     $result = F::i(_DBMS_SYS)->query('SELECT cou.cou_name, cou.cou_troops_x, cou.cou_troops_y, cou.cou_d, con.con_name, l.m_id, l.l_strength FROM !prefix_continents con, !prefix_countries cou, !prefix_lands l WHERE l.g_id = ? AND l.cou_id = cou.cou_id AND cou.con_id = con.con_id', array($game->g_id));
     while (($obj = $result->getObject()) != NULL) {
         $view->setGroupValues('territories', array('cou_name' => $obj->cou_name, 'con_name' => $obj->con_name, 'cou_d' => $obj->cou_d, 'm_id' => $obj->m_id, 'troops' => $obj->l_strength, 'troops_x' => $obj->cou_troops_x, 'troops_y' => $obj->cou_troops_y));
     }
     /**
      * Display Mode
      */
     if ($mode == 'owner') {
         $result = F::i(_DBMS_SYS)->query('SELECT p.m_id, m.m_login, col.col_code FROM !prefix_players p, !prefix_members m, !prefix_colors col WHERE p.m_id = m.m_id AND p.col_id = col.col_id AND p.g_id = ?', array($game->g_id));
         while (($obj = $result->getObject()) != NULL) {
             $view->setGroupValues('styles', array('style_name' => 'g.player_' . $obj->m_id, 'style_code' => 'fill: #' . $obj->col_code));
             /**
              * Legend
              */
             $view->setGroupValues('legend', array('id' => 'legend_player_' . $obj->m_id, 'text' => $obj->m_login, 'col_code' => $obj->col_code));
         }
     } else {
         if ($mode == 'continents') {
             // con_id = col_id... Just to have a color but normaly, no link lol
             $result = F::i(_DBMS_SYS)->query('SELECT con.con_name, con.con_id, col.col_code FROM !prefix_continents con, !prefix_colors col WHERE con.con_id = col.col_id');
             while (($obj = $result->getObject()) != NULL) {
                 $view->setGroupValues('styles', array('style_name' => '.' . $obj->con_name, 'style_code' => 'fill: #' . $obj->col_code));
                 /**
                  * Legend
                  */
                 $view->setGroupValues('legend', array('class' => 'legend_continent_' . $obj->con_id, 'text' => $obj->con_name, 'col_code' => $obj->col_code));
             }
         }
     }
     return $view->getContent();
 }
Example #7
0
 public function getView($params, $synchrone)
 {
     include_once _MODEL_DIR . '/chatbox.php';
     $chatbox = new Form(Chatbox::getFields(), array('name' => Chatbox::getNickname()));
     $login = F::i('Session')->getUsername();
     // Display Index page...
     $view = View::setFile('index', View::HTML_FILE);
     $view->setValue('u_chatbox', '?action=chatbox');
     $view->setValue('chatbox_form', $chatbox->getHTML('', '?action=chatbox', 'ajax', 'chatbox_form', 'cron.socket', 'clear_chatbox'));
     $view->setValue('login', $login);
     return parent::setBody($view, F::i('Lang')->getKey('title_index'));
 }
Example #8
0
 public function getView($params, $synchrone)
 {
     try {
         if (!isset($params['game'])) {
             throw new Exception('No Game given');
         }
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('Not In');
         }
         if (!isset($params['step']) || empty($params['step'])) {
             throw new Exception('Need step');
         }
         $view = View::setFile('confirm', View::JSON_FILE);
         if ($params['step'] == $game->g_step + 1) {
             // If all players ready
             $result = F::i(_DBMS_SYS)->query('SELECT m_id FROM !prefix_players WHERE g_id=? AND p_ready=0', array($game->g_id));
             if ($result->getNumRows() == 0) {
                 // If somebody is solving the game
                 // Dangerous Part so ask the database to have the LAST info
                 $result = F::i(_DBMS_SYS)->query('SELECT g_resolving FROM !prefix_games WHERE g_id=?', array($game->g_id));
                 if ($result->getObject()->g_resolving == 0) {
                     // Let's Solve !
                     F::i(_DBMS_SYS)->mexec(array(array('UPDATE !prefix_games SET g_resolving=1 WHERE g_id=?', array($game->g_id)), array('CALL PROC_SOLVE_ATTACKS(?)', array($game->g_id)), array('UPDATE !prefix_players SET p_ready=0 WHERE g_id=?', array($game->g_id)), array('UPDATE !prefix_games SET g_step=g_step+1 WHERE g_id=?', array($game->g_id)), array('UPDATE !prefix_games SET g_resolving=0 WHERE g_id=?', array($game->g_id))));
                 }
                 $view->setValue('confirm', 1);
             } else {
                 $view->setValue('confirm', 0);
             }
         } else {
             if ($params['step'] == $game->g_step) {
                 $view->setValue('confirm', 1);
             } else {
                 throw new Exception('Not a valid step');
             }
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust ! : ' . $e->getMessage());
     }
     return $view->getContent();
 }
 /**
  * Handles search queries.
  *
  * @param string $_GET['q']
  */
 public function search()
 {
     // no query
     if (!isset($_GET['q']) || empty($_GET['q'])) {
         $v = new View("search_index");
         $v->content = "You must enter a query.";
         return $v->render();
     }
     // process their query
     $query = filter_var($_GET['q'], FILTER_SANITIZE_STRING);
     $m = new AnimalModel();
     $v = new View("animal_index");
     $v->title = "Search Results for &#8220;{$query}&#8221;";
     $v->animals = $m->find($query);
     if (empty($v->animals)) {
         $v->setFile("search_index");
         $v->content = "Sorry, no results were found for &#8220;{$query}&#8221;.";
     }
     $v->render();
 }
Example #10
0
 public function getView($params, $synchrone)
 {
     // Get all the games of the player
     $result = F::i(_DBMS_SYS)->query('SELECT g.g_id, g_name, g_step, COUNT(*) AS g_total_players, TIMESTAMPDIFF(HOUR, g_start, NOW()) AS lifetime, m_login AS g_owner FROM !prefix_members m, !prefix_players AS p, !prefix_games AS g, !prefix_players AS p2 WHERE p.m_id = ? AND g.m_id = m.m_id AND p.g_id = g.g_id AND g.g_id = p2.g_id GROUP BY g.g_id', array(F::i('Session')->getMid()));
     $view = View::setFile('list_games', View::HTML_FILE);
     $view->setValue('form', '');
     if ($result->getNumRows() == 0) {
         $view->setSwitch('no_games', TRUE);
     }
     for ($i = 0; $i < $result->getNumRows(); $i++) {
         $obj = $result->getObject();
         if ($obj->g_step == 0) {
             $link = '?action=wait_game&game=' . $obj->g_id;
             $name = '<span style="font-style: italic;">' . $obj->g_name . '</span>';
         } else {
             $link = '?action=play&game=' . $obj->g_id;
             $name = '<span style="font-weight: bold;">' . $obj->g_name . '</span>';
         }
         $view->setGroupValues('games', array('link' => $link, 'name' => $name, 'total_players' => $obj->g_total_players, 'owner' => $obj->g_owner, 'lifetime' => $obj->lifetime));
     }
     return parent::setBody($view, F::i('Lang')->getKey('title_current_games'));
 }
Example #11
0
 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // Register
         $salt = Tools::generateSalt();
         $password = Tools::saltHash($params['password'], $salt);
         $error = FALSE;
         try {
             F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_members (m_login, m_password, m_email, m_salt, m_auth) VALUES (?, ?, ?, ?, ?)', array($params['login'], $password, $params['email'], $salt, _AUTH_MEMBER));
         } catch (DBMSError $e) {
             // Login already given
             $error = TRUE;
         }
         if (!$error) {
             $view = View::setFile('info', View::HTML_FILE);
             $view->setValue('L_message', F::i('Lang')->getKey('register_successful'));
             $view->setValue('U_ok', '?');
             F::i('Session')->connect($params['login'], $params['password']);
         } else {
             $view = View::setFile('error', View::HTML_FILE);
             $view->setValue('l_message', F::i('Lang')->getKey('login_taken'));
             $view->setValue('u_ok', '?');
         }
     } else {
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('register'), '#', 'POST', 'tabbed_form'));
     }
     return parent::setBody($view);
 }
Example #12
0
    public function getView($params, $synchrone)
    {
        $search_form = new Form($this->search_fields, $params);
        $access_form = new Form($this->access_fields, $params);
        $title = '';
        $insert = TRUE;
        try {
            if (!isset($params['game'])) {
                throw new Exception('No Game given');
            }
            $game = new Game($params['game']);
            if ($game->isIn(F::i('Session')->getMid())) {
                throw new Exception('Already In');
            }
        } catch (Exception $e) {
            $insert = FALSE;
        }
        if ($insert) {
            if ($game->g_access_key == 'NULL' || $access_form->isSubmitting() && Tools::isEmpty($access_form->getErrors()) && $game->g_access_key == Tools::saltHash($params['access_key'])) {
                $game->insert(F::i('Session')->getMid());
                Tools::redirect('?action=wait_game&game=' . $game->g_id);
            } else {
                // CHECK
                if ($access_form->isSubmitting()) {
                    // Error
                    die('bad access key');
                } else {
                    $view = View::setFile('formular', View::HTML_FILE);
                    $errors = $access_form->getErrors();
                    // Errors in the filling
                    if (!empty($errors)) {
                        $view->setSwitch('form_errors', TRUE);
                        foreach ($errors as $field => $error) {
                            $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
                        }
                    }
                    $view->setValue('form', $access_form->getHTML(F::i('Lang')->getKey('access_key'), '#', 'POST', 'tabbed_form'));
                }
            }
        } else {
            $sql = 'SELECT g.g_id, g_name, TIMESTAMPDIFF(HOUR, g_start, NOW()) AS lifetime, COUNT(*) AS g_total_players, m_login AS g_owner 
					FROM !prefix_members m, !prefix_games AS g, !prefix_players AS p 
					WHERE g.m_id = m.m_id 
						AND p.g_id = g.g_id 
						AND g.g_id NOT IN (
							SELECT g_id FROM !prefix_players WHERE m_id = ?
						)';
            $array = array(F::i('Session')->getMid());
            // If search is defined, add condition
            if (isset($params['search'])) {
                $sql .= ' AND g_name LIKE ?';
                $array[] = '%' . $params['search'] . '%';
            }
            $sql .= ' GROUP BY g.g_id ORDER BY g_start DESC';
            // Get all the games
            $result = F::i(_DBMS_SYS)->query($sql, $array);
            $view = View::setFile('list_games', View::HTML_FILE);
            $view->setValue('form', $search_form->getHTML('', '#', 'POST', 'inline'));
            if ($result->getNumRows() == 0) {
                $view->setSwitch('no_games', TRUE);
            }
            for ($i = 0; $i < $result->getNumRows(); $i++) {
                $obj = $result->getObject();
                $view->setGroupValues('games', array('link' => '?action=join_game&game=' . $obj->g_id, 'name' => stripslashes($obj->g_name), 'total_players' => $obj->g_total_players, 'owner' => $obj->g_owner, 'lifetime' => $obj->lifetime));
            }
            $title = F::i('Lang')->getKey('title_join_game');
        }
        return parent::setBody($view);
    }