Exemplo n.º 1
0
 public static function getAllForUser($iduser = false)
 {
     if (iduser != false) {
         $db = new DB();
         $sql = "SELECT pt.idtable\n                      FROM poker_tables AS pt\n                INNER JOIN poker_players AS pp ON pp.idtable = pt.idtable AND pp.iduser = " . $iduser;
         $result = $db->query($sql);
         $tables = array();
         if ($result->length() > 0) {
             do {
                 $tables[$result->idtable] = PokerTable::getInstance($result->idtable);
             } while ($result->next());
         }
         return $tables;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * create form for editing / creating a house
  *
  * @return string HTML code
  * @author Elias Müller
  **/
 private function getForm($id = '')
 {
     $path = 'poker_table-' . $this->s->action . ($this->s->element != '' ? '/' . $this->s->element : '');
     if ($id != '') {
         $table = PokerTable::getInstance($id);
     } else {
         $table = new PokerTable();
     }
     $spots = PokerSpot::getAll();
     $tpl = new Template('poker');
     $tpl->assign('path', $path);
     $tpl->assign('spots', $spots);
     $tpl->assign('table', $table);
     return $tpl->fetch('form_table.html');
 }
Exemplo n.º 3
0
 /**
  * Handle form action
  */
 protected function formAction()
 {
     $this->escapeFormVars();
     switch ($this->s->action) {
         case 'send':
             $message = new Message();
             $message->text = $this->vars['text'];
             $message->subject = $this->vars['subject'];
             if ($this->s->params[0] != '') {
                 $message->type = $this->s->params[0];
                 switch ($message->type) {
                     case 'poker':
                         $message->receiver = PokerTable::getInstance($this->s->params[1]);
                         break;
                 }
             } else {
                 if (!is_array($this->vars['user']) || count($this->vars['user']) == 0) {
                     return false;
                 }
                 $message->type = 'user';
                 $rec = array();
                 foreach ($this->vars['user'] as $r) {
                     $rec[] = User::getInstance($r);
                 }
                 $message->receiver = $rec;
             }
             $message->sender = $this->s->user;
             if ($message->save()) {
                 Error::addMessage('Die Nachricht wurde verschickt!');
                 $this->form['reload'] = array('message' => array('sidebar'));
                 return true;
             }
             break;
         case 'update':
             $message = Message::getInstance($this->s->element);
             $message->text = $this->vars['text'];
             $message->subject = $this->vars['subject'];
             if ($message->save()) {
                 Error::addMessage('Die Nachricht wurde geändert!');
                 $this->form['reload'] = array('message' => array('u_message'));
                 return true;
             }
             break;
         case 'reply':
             $r = Message::getInstance($this->s->element);
             $message = new Message();
             $message->text = $this->vars['text'];
             $message->subject = $this->vars['subject'];
             $message->receiver = $r->sender;
             $message->sender = $this->s->user;
             $message->replyto = $this->s->element;
             if ($message->save()) {
                 Error::addMessage('Die Nachricht wurde verschickt!');
                 $this->form['reload'] = array('message' => array('u_message'));
                 return true;
             }
             break;
         case 'mark':
             if ($this->s->element != '') {
                 $m = Message::getInstance($this->s->element);
                 // mark all messages in thread as (un-)read
                 if ($this->vars['messages'] == 'all') {
                     if (is_array($m->replies)) {
                         foreach ($m->replies as $r) {
                             if ($r->receiver == $this->s->user) {
                                 $r->read = $this->vars['option'] == 'read' ? true : false;
                                 if (!$r->save()) {
                                     Error::addError('Interner Fehler: Nachricht konnte nicht gespeichert werden!');
                                     return false;
                                 }
                             }
                         }
                     }
                     $this->form['reload'] = array('message' => array('u_message'));
                 } else {
                     $this->form['reload'] = array('message' => array('sidebar', 'bb_messages'));
                 }
                 // mark current message as (un-)read
                 $m->read = $this->vars['option'] == 'read' ? true : false;
                 if ($m->save()) {
                     return true;
                 } else {
                     Error::addError('Interner Fehler: Nachricht konnte nicht gespeichert werden!');
                     return false;
                 }
             }
             Error::addError('Es konnte keine Nachricht gefunden werden!');
             break;
         case 'delete':
             $m = Message::getInstance($this->s->element);
             if ($m->delete()) {
                 Error::addMessage('Die Nachricht wurde gelöscht!');
                 $this->form['reload'] = array('message' => array('sidebar', 'u_message'));
                 return true;
             }
             break;
         case 'reload':
             switch ($this->s->element) {
                 case 'sidebar':
                     $tpl = new Template('message');
                     $this->s->resetParams();
                     $m = $this->listMessages($this->s->element);
                     $tpl->assign('messages', $m['messages']);
                     $tpl->assign('current', $m['current']);
                     $tpl->assign('read', $m['read']);
                     $tpl->assign('user', $this->s->user);
                     echo $tpl->fetch('message_list.html');
                     break;
                 case 'u_message':
                     $tpl = new Template('message');
                     $this->s->resetParams();
                     $tpl->assign('m', Message::getInstance($this->s->element));
                     $tpl->assign('user', $this->s->user);
                     echo $tpl->fetch('message.html');
                     break;
                 case 'bb_messages':
                     echo $this->blackboardTable();
                 default:
                     echo '';
             }
             return true;
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT pp.idplayer, pp.idtable, pp.stack, pp.c1, pp.c2, pp.position, u.username, pa.idaction, pp.bet, pp.pjoin, pp.pleave, pp.pot, pa.idgame AS pagame, pt.idgame AS ptgame\n                  FROM poker_players AS pp\n            INNER JOIN users AS u ON u.iduser = pp.iduser\n            INNER JOIN poker_tables AS pt ON pt.idtable = pp.idtable \n             LEFT JOIN poker_actions AS pa ON (pa.idplayer = pp.idplayer AND pa.action NOT LIKE 'deal' AND pa.action NOT LIKE 'join' AND pa.action NOT LIKE 'leave')\n                 WHERE pp.idplayer = '{$id}'\n              ORDER BY pa.idaction DESC\n                 LIMIT 1";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         // hand
         $cards = false;
         if ($result->c1 != '') {
             $cards = array(new PokerCard($result->c1), new PokerCard($result->c2));
         }
         // general information
         $table = PokerTable::getInstance($result->idtable);
         $action = PokerAction::getInstance($result->idaction);
         $this->info = array("user" => User::getInstance($result->username), 'table' => $table, 'position' => $result->position, 'stack' => $result->stack, 'bet' => $result->bet, 'cards' => $cards, 'pot' => $result->pot, 'last_action' => $result->pagame === $result->ptgame ? $action : NULL, 'join' => $result->pjoin == 1 ? TRUE : FALSE, 'leave' => $result->pleave == 1 ? TRUE : FALSE);
         $this->id = $id;
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Compose an array with essential game data which represent the current state of a table/game.
  */
 private function getGameInfo($idtable, $player = FALSE, $actions = FALSE)
 {
     // get basic table info
     $table = PokerTable::getInstance($idtable);
     $valid_actions = '';
     $active_player = FALSE;
     // Get all players (seated and waiting)
     $active_players = $table->getActivePlayers(FALSE, FALSE);
     $players = array();
     foreach ($active_players as $p) {
         $players[$p->position] = array('position' => $p->position, 'name' => $p->user->realname, 'stack' => $p->stack, 'bet' => $p->bet, 'waiting' => $p->join, 'leaves' => $p->leave, 'button' => $p->position == $table->positions['dealer'], 'fold' => $p->last_action != NULL ? $p->last_action->action : '');
         // Get valid actions / active player
         $v = $this->validAction($p);
         if (is_object($player) && $player->join == FALSE && $player === $p) {
             $valid_actions = $v;
         }
         if ($v != FALSE && $p->join == FALSE) {
             $active_player = $p->position;
         }
     }
     // detect new game
     $showdown = FALSE;
     if ($actions != FALSE) {
         $a = array_reverse($actions);
         $g = FALSE;
         foreach ($a as $action) {
             if ($g == FALSE && $action->action != 'showdown') {
                 $g = $action->game->id;
             } elseif (($g != $action->game->id || $g == FALSE) && $action->action == 'showdown') {
                 // get showdown data
                 // player cards, winning hand, winning players
                 $showdown = array('winning_hand' => $action->params['winning_hand'], 'player_hands' => $action->params['player_hands'], 'player_cards' => $action->params['player_cards'], 'winner_pots' => $action->params['winners'], 'game' => $action->params['game']);
                 break;
             }
         }
     }
     // Get active game info
     if (is_object($table->game)) {
         $phase = $table->game->getGamePhase();
         $game = array('flop' => $table->game->flop !== FALSE && $phase > 0 ? array($table->game->flop[0]->id, $table->game->flop[1]->id, $table->game->flop[2]->id) : false, 'turn' => $table->game->turn !== FALSE && $phase > 1 ? $table->game->turn->id : false, 'river' => $table->game->river !== FALSE && $phase > 2 ? $table->game->river->id : false, 'pot' => $table->game->pot);
         // Get action log for current game
         if ($actions == FALSE) {
             $actions = $table->game->actions;
         }
         // get current player cards
         if (is_object($player)) {
             $cards = array($player->cards[0]->id, $player->cards[1]->id);
         }
     }
     // Get action log
     $idaction = 0;
     if ($actions !== FALSE) {
         $log = $this->getActionLog($actions);
         $first = current($actions);
         $idaction = $first->id;
     }
     // Send data to client
     // return array (for json object) with: timestamp, past actions, player info, game info, table info
     return array('timestamp' => time(), 'idaction' => $idaction, 'log' => $log, 'table' => array('seats' => $table->seats, 'blind' => $table->blinds['big']), 'game' => $game, 'cards' => $cards, 'self' => is_object($player) ? $player->position : FALSE, 'active' => $active_player, 'players' => $players, 'actions' => $valid_actions, 'showdown' => $showdown);
 }
Exemplo n.º 6
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT m.text, m.subject, m.created, m.read, u1.username AS sender, m.idreply, m.idmessage, m.idrecvr, m.recvr\n\t\t\t\t  FROM messages AS m\n\t\t\t LEFT JOIN users AS u1 ON m.iduser = u1.iduser\n\t\t\t\t WHERE m.idmessage = " . $id . "\n\t\t\t\t\tOR m.idreply = " . $id . "\n\t\t\t  ORDER BY m.created ASC";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         do {
             if ($result->idmessage == $id) {
                 // start message
                 $this->info["subject"] = $result->subject;
                 $this->info["text"] = $result->text;
                 // Systeminfo
                 $this->info["sender"] = User::getInstance($result->sender);
                 $this->info["type"] = $result->recvr;
                 switch ($result->recvr) {
                     case 'user':
                         $this->info["receiver"] = User::getInstanceForId($result->idrecvr);
                         break;
                     case 'poker':
                         $this->info["receiver"] = PokerTable::getInstance($result->idrecvr);
                         break;
                 }
                 $this->info["replyto"] = $result->idreply;
                 if ($result->read != '0000-00-00 00:00:00') {
                     $r = explode(' ', $result->read);
                     $this->info['read']['date'] = new Date($r[0], 'Y-m-d');
                     $this->info['read']['time'] = $r[1];
                 } else {
                     $this->info['read'] = false;
                 }
                 $created = explode(' ', $result->created);
                 $this->info["created"]['date'] = new Date($created[0], 'Y-m-d');
                 $this->info["created"]['time'] = $created[1];
                 $this->id = $result->idmessage;
             } else {
                 // following messages
                 $this->info['replies'][] = Message::getInstance($result->idmessage);
             }
         } while ($result->next());
         return true;
     }
     return false;
 }