Beispiel #1
1
 private static function runQueryWithView($query, $fields, $printArray)
 {
     $_SESSION['tableData'] = array();
     $exec_time_row = array();
     $records = '';
     try {
         // turn on query profiling
         Flight::get('db')->query('SET profiling = 1;');
         $stmt = Flight::get('db')->query($query);
         // find out time above query was ran for
         $exec_time_result = Flight::get('db')->query('SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;');
         $exec_time_row = $exec_time_result->fetchAll(PDO::FETCH_NUM);
         // run query and fetch array
         $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
         // store table fields/columns + data rows in session for exporting later
         $_SESSION['tableData'] = array_merge($fields, $data);
         $records = Presenter::listTableData($data);
     } catch (PDOException $e) {
         setFlashMessage('Error: ' . $e->getMessage());
     }
     Flight::render('table', array('title' => Flight::get('lastSegment'), 'icon' => self::$icon, 'table_data' => $records, 'fields' => getOptions($fields), 'query' => SqlFormatter::format($query), 'printArray' => $printArray, 'timetaken' => $exec_time_row[0][1]));
 }
Beispiel #2
0
 /**
  * Attempt to login user based on credentials specified in config file.
  */
 public function loginuser()
 {
     $username_ok = false;
     $password_ok = false;
     $username = $_POST['username'];
     $password = $_POST['password'];
     // get user login details from config file
     $config = Flight::get('config');
     // go through array and match username and password
     foreach ($config as $key => $value) {
         if ($key === 'username') {
             if (is_array($value)) {
                 foreach ($value as $value2) {
                     if ($username === $value2) {
                         $username_ok = true;
                     }
                 }
             } else {
                 if ($username === $value) {
                     $username_ok = true;
                 }
             }
         } elseif ($key === 'password') {
             if (is_array($value)) {
                 foreach ($value as $value2) {
                     if ($password === $value2) {
                         $password_ok = true;
                     }
                 }
             } else {
                 if ($password === $value) {
                     $password_ok = true;
                 }
             }
         }
     }
     if ($username_ok && $password_ok) {
         $_SESSION['logged'] = true;
         Flight::redirect('./home');
     } else {
         setFlashMessage('Error: Invalid username or password!');
         Flight::redirect('./login');
     }
 }
Beispiel #3
0
<?php

use App\Battleships\Exceptions\Exception;
// Default home route
$app->get('/', function () use($app) {
    $fleet = getFleet();
    // flag to backdoor cheats
    $debug = isset($_GET['debug']) ? true : false;
    $flash_messages = getFlashMessage();
    $app->view->setData('fleet', $fleet);
    $app->render('layout.php', ['grid' => $fleet->getGridCoordinates(), 'hits' => $fleet->getShotCoordinates(), 'debug' => $debug, 'hit' => 'X', 'miss' => '--', 'no_shot' => '.', 'flash_messages' => $flash_messages]);
});
// Handle post request
$app->post('/', function () use($app) {
    if (empty($_POST['co-ordinates'])) {
        $app->redirect('/');
    }
    $coordinates = $_POST['co-ordinates'];
    $row = strtolower(substr($coordinates, 0, 1));
    $column = intval(substr($coordinates, 1));
    $fleet = getFleet();
    try {
        $status = $fleet->fire($row, $column);
        $status ? setFlashMessage('hit') : setFlashMessage('miss');
        updateFleet($fleet);
    } catch (Exception $e) {
        setFlashMessage($e->getMessage());
    }
    $app->redirect('/');
});
return $app;
Beispiel #4
0
function flashRedirect($page, $message)
{
    setFlashMessage($message);
    Flight::redirect($page);
    exit;
}
Beispiel #5
0
 /**
  *
  * Login service 
  *
  **/
 function do_login($parameters)
 {
     $creds = array();
     $creds['user_login'] = $parameters['user'];
     $creds['user_password'] = $parameters['password'];
     $creds['remember'] = true;
     $user = wp_signon($creds, false);
     if (is_wp_error($user)) {
         setFlashMessage('error', $user->get_error_message());
         wp_redirect(home_url() . '/home/login');
         exit;
     } else {
         wp_redirect(home_url() . '/dashboard/');
         exit;
     }
 }
Beispiel #6
0
     if ($record['akce'] == 'lite') {
         $record = mainEditLite($record);
         $dataBox = $record['lite'];
     }
     break;
     //==============================================================================
 //==============================================================================
 case 'save':
     //==============================================================================
     if (canAction('w') === FALSE) {
         require PHPINC_DIR . '/templates/403.php';
     }
     $redirectUrl = mainSave($_POST);
     if (is_array($redirectUrl) === TRUE) {
         if (isset($redirectUrl['report']) === TRUE) {
             setFlashMessage($redirectUrl['report'], $type = 'error');
         }
         unsetEditValue2Session();
         $redirectUrl = getUrlSearchFromSession();
     }
     require PHPPRG_DIR . '/redirect.php';
     break;
     //==============================================================================
 //==============================================================================
 case 'delete':
     //==============================================================================
     $redirectUrl = mainDelete($_GET);
     require PHPPRG_DIR . '/redirect.php';
     break;
     //==============================================================================
 //==============================================================================
Beispiel #7
0
 *
 * @link       http://www.bnhelp.cz
 * @package    Micka
 * @category   Metadata
 * @version    20130403
 */
require PHPPRG_DIR . '/micka_lib_auth.php';
require AUTHLIB_FILE;
// login
if (isset($_REQUEST['user'])) {
    if (prihlaseni($_REQUEST['user'], isset($_REQUEST['pwd']) ? $_REQUEST['pwd'] : '') === FALSE) {
        Debugger::log('[micka_auth.php] ' . 'LOGIN error, ' . $_REQUEST['user'] . ' invalid username or password', 'INFO');
        if ($_SESSION['hs_lang'] == 'cze') {
            setFlashMessage('Chybné přihlášení: Neznámé uživatelské jméno ' . $_REQUEST['user'] . ' nebo špatné heslo.', 'error');
        } else {
            setFlashMessage('Login error: Invalid username ' . $_REQUEST['user'] . ' or password.', 'error');
        }
        if (!prihlaseni('guest', '')) {
            if (isset($hlaska) && $hlaska != '') {
                Debugger::log('[micka_auth.php] ' . "hlaska: {$hlaska}", 'INFO');
            }
            Debugger::log('[micka_auth.php] ' . 'Not available for guest.', 'INFO');
            require PHPINC_DIR . '/templates/403.php';
        }
        require PHPPRG_DIR . '/redirect.php';
    }
    getProj();
    require PHPPRG_DIR . '/redirect.php';
} else {
    if (isset($_SESSION["u"]) === FALSE || empty($_SESSION['ms_groups'])) {
        // guest
Beispiel #8
0
 /**
  * Fire the fleet with given co-ordinates
  *
  * @param string $row    row from A to J
  * @param int    $column column number from 1 to 10
  * @return bool
  * @throws Exception
  */
 public function fire($row, $column)
 {
     // If the firing is outside the board
     // we will throw an exception
     if ($column < 1 || $column > 10 || $row > 'j') {
         throw new Exception('You are hitting outside the board. Your hit landed on ' . strtoupper($row) . $column . '.');
     }
     //check if the co-ordinate is already hit
     if (!$this->targetAlreadyHit($row, $column)) {
         $status = '';
         // find out if it is a hit or miss
         if (empty($this->gridCoordinates[$row][$column])) {
             $status = 'miss';
         } else {
             $status = 'hit';
             // Hit the ship
             $ship = $this->ships[$this->gridCoordinates[$row][$column]];
             $ship->hit();
             //check if the ship has sunk
             if ($ship->getStatus() == 'sunk') {
                 setFlashMessage($ship->getType() . ' sunk');
             }
             // Update Fleet status
             $this->updateFleetStatus();
         }
         // Record Hit or Miss
         $this->shotCoordinates[$row][$column] = $status;
         //update the record count
         $this->totalHits++;
         return $status == 'hit' ? true : false;
     }
     return false;
 }
Beispiel #9
0
function destroy_post_controller($id)
{
    __is_guest();
    $id = (int) $id;
    if ($id == 0) {
        throw new RuntimeException('418');
    }
    destroy_model($id, 'posts');
    setFlashMessage(trans('success_deleted_post', 'post'));
    redirect('dashboard');
}
 /**
  *
  * Deal with new requests 
  *
  **/
 public function process_newbox_form()
 {
     if ($_POST['more_box']) {
         if (isset($_POST['more_box']['address'])) {
             //send email to enclothed and mark the db as ordered again
             global $current_user;
             $profile = $this->main->profiles_model->getFullProfile($current_user->user_email);
             $data = array();
             if ($_POST['more_box']['address'] == 'delivery') {
                 $address = $profile->delivery_add_1 . " " . $profile->delivery_add_2 . ", " . $profile->delivery_town . " " . $profile->delivery_post_code;
             } else {
                 $address = $profile->bill_add_1 . " " . $profile->bill_add_2 . ", " . $profile->bill_town . " " . $profile->bill_post_code;
             }
             $data['username'] = $current_user->user_email;
             $data['user_reference'] = $profile->customer_id;
             $data['address'] = $_POST['more_box']['address'];
             $data['address_reason'] = $_POST['more_box']['address_reason'];
             $this->main->sendmail(get_bloginfo('admin_email'), 'New box requested!', Emails_model::TEMPLATE_NEW_BOX, $data);
             $data = array();
             $data['email'] = $current_user->user_email;
             $data['name'] = strtoupper($profile->first_name . ' ' . $profile->last_name);
             $this->main->sendmail($data['email'], 'New box requested!', Emails_model::TEMPLATE_NEW_BOX_USER, $data);
             setFlashMessage('success', 'Your box has been ordered. We shall be in touch soon.');
         }
     }
 }