Ejemplo n.º 1
0
 protected function _load()
 {
     $id = $this->get->id;
     $viewSource = $this->get->textVal('view-source');
     $examples = Raxan::importCSV('data/examples.csv');
     foreach ($examples as $example) {
         if ($example['id'] == $id) {
             // set page title and tip
             $title = htmlspecialchars($example['title']);
             $tip = $example['tip'] ? $example['tip'] : $example['desc'];
             $this->title($title);
             $this->title->html($title);
             $this->tips->text($tip);
             // load php file
             $file = $example['filename'] ? $example['filename'] : $example['id'] . '.php';
             $frame = $this->frame1;
             $frame->attr('src', $file);
             // get source
             $src = htmlspecialchars(file_get_contents($file));
             $src = str_replace('../raxan', 'raxan', $src);
             $this->phpsource->html($src);
             // get plugin source
             if ($example['plugin']) {
                 $this->pluginfile->text(' (' . $example['plugin'] . ')');
                 $this->pluginsource->html(htmlspecialchars(file_get_contents($example['plugin'])));
                 $this->pluginpanel->show();
             }
             // get html source
             if ($example['html']) {
                 $this->htmlfile->text(' (' . $example['html'] . ')');
                 $this->htmlsource->html(htmlspecialchars(file_get_contents($example['html'])));
                 $this->htmlpanel->show();
                 if (substr($example['html'], -3) == '.js') {
                     // show Javascript code
                     $this->htmlpanel->find('code')->attr('class', 'javascript');
                 }
             }
             // get data source
             if ($example['data']) {
                 $this->datafile->text(' (' . $example['data'] . ')');
                 $this->datasource->html(htmlspecialchars(file_get_contents($example['data'])));
                 $this->datapanel->show();
             }
         }
     }
     // only view source code
     if ($viewSource == 'on') {
         $this->frame1->remove();
     } else {
         if ($viewSource == 'off') {
             $this->sourceCode->remove();
         }
     }
 }
Ejemplo n.º 2
0
 function testLog()
 {
     $msg = 'Base Class test log';
     $t = date('Y-m-d H:i:s', time());
     $file = dirname(__FILE__) . '/logfile.txt';
     file_put_contents($file, '');
     Raxan::config('log.enable', true);
     Raxan::config('log.file', $file);
     // log
     $base = new BaseClass();
     $base->log($msg);
     $c = file_get_contents($file);
     $this->compare("INFO \t" . $t . " \t \t" . $msg, trim($c), 'Log file content');
     // log with params
     file_put_contents($file, '');
     $base->log($msg, 'ERROR', 'Label');
     $t = date('Y-m-d H:i:s', time());
     $c = file_get_contents($file);
     $this->compare("ERROR \t" . $t . " \t [Label] \t" . $msg, trim($c), 'Log with label params');
 }
Ejemplo n.º 3
0
<?php

require_once '../raxan/pdi/gateway.php';
Raxan::sendError('File not found', 404);
Ejemplo n.º 4
0
/**
 * Creates an instance of a page class
 * @param string $page The name of a RaxanWebPage sub-class
 * @param string $content
 */
function raxan_auto_create($page, $content = null)
{
    // initialize page class
    if ($page) {
        try {
            if (!$content) {
                $content = '';
            }
            $type = substr($content, 0, 5) == '<?xml' ? 'xml' : null;
            $o = new $page($content, null, $type);
            $o->reply();
        } catch (Exception $e) {
            // raise system error event
            $rt = Raxan::triggerSysEvent('system_error', $e);
            if (!$rt) {
                $err = $e->getMessage() . '  Line ' . $e->getLine() . ' in ' . $e->getFile() . "\n" . $e->getTraceAsString() . "\n";
                if (ini_get('display_errors') == 1) {
                    echo "Uncaught Error: " . nl2br($err);
                }
                Raxan::log($err, 'ERROR', 'Uncaught Error');
            }
        }
    }
}
Ejemplo n.º 5
0
<?php

require_once '../raxan/pdi/gateway.php';
Raxan::sendError('Unauthorized  access', 401);
Ejemplo n.º 6
0
 function testThrowCallbackException()
 {
     try {
         // this should raise an error
         Raxan::throwCallbackException('back_callback');
         $ok = true;
     } catch (Exception $e) {
         $ok = false;
     }
     $this->okFalse($ok, 'Callback Error');
 }
Ejemplo n.º 7
0
 /**
  * Converts input value/key to a valid timestamp
  * @return int Returns timestamp if value is a valid datetime string or null if there was an error
  */
 public function timestampVal($key)
 {
     if (!isset($this->_date)) {
         $this->_date = Raxan::CDate();
     }
     $v = $this->value($key);
     if (!is_array($v)) {
         try {
             $v = $v ? $this->_date->getTimestamp($v) : null;
         } catch (Exception $e) {
             $v = null;
         }
     } else {
         foreach ($v as $k => $b) {
             try {
                 $b = $b ? $this->_date->getTimestamp($b) : null;
             } catch (Exception $e) {
                 $b = null;
             }
             $v[$k] = $b;
         }
     }
     return $v;
 }
Ejemplo n.º 8
0
 protected function _init()
 {
     if (!session_id()) {
         // no current session exists so let's create one
         if ($this->id) {
             session_id($this->id);
         }
         session_name($name = Raxan::config('session.name'));
         $timeout = intval(Raxan::config('session.timeout')) * 60;
         if ($timeout) {
             session_set_cookie_params($timeout);
         }
         //set timeout
         session_start();
         if (!$this->id) {
             $this->id = session_id();
         }
         // reset cookie timeout on page load/refesh
         if (isset($_COOKIE[$name])) {
             setcookie($name, $_COOKIE[$name], time() + $timeout, '/');
         }
     }
     $this->store =& $_SESSION;
     // use current session object
 }
Ejemplo n.º 9
0
 /**
  * Parses a date string and returns an array containing the date parts otherwise false
  * It's works great with date values returned from MSSQL, MySQL and others.
  * @return Array Returns an array that contains the date parts: year, month, mday, minutes,hours and seconds
  * @param $str String Supported Date/Time string format
  */
 public function parse($str)
 {
     $delim = '';
     $dpart = array('minutes' => '', 'hour' => '', 'seconds' => '');
     $dt = preg_replace('/(\\s)+/', ' ', $str);
     // remove extra white spaces
     if (strpos($dt, '-') > 0) {
         $delim = '-';
     }
     if (strpos($dt, '/') > 0) {
         $delim = '/';
     }
     if (!$delim && ($d = strpos($dt, '.')) > 0) {
         $c = strpos($dt, ':');
         if (!$c || $c > $d) {
             $delim = '.';
         }
     }
     if ($delim == '-' || $delim == '/' || $delim == '.') {
         @(list($date, $time) = explode(' ', $dt));
         $date = explode($delim, $date);
         $date[] = $time;
     } else {
         $date = explode(' ', $dt, 4);
     }
     foreach ($date as $i => $v) {
         $date[$i] = trim(trim($v, ','));
     }
     @(list($d1, $d2, $d3, $time) = $date);
     if (!self::$months) {
         self::$months = Raxan::locale('months.short');
     }
     $months = self::$months;
     // get year
     if ($d1 > 1000) {
         $dpart['year'] = $d1;
         unset($date[0]);
     }
     if ($d3 > 1000) {
         $dpart['year'] = $d3;
         unset($date[2]);
     }
     if (!isset($dpart['year'])) {
         $dpart['year'] = date('Y');
     }
     // get month - defaults to mm-dd-yyyy
     if (!is_numeric($d1)) {
         for ($i = 0; $i < 12; $i++) {
             // mmm dd yyyy
             if (stristr($d1, $months[$i]) != false) {
                 $dpart['mon'] = $i + 1;
                 unset($date[0]);
                 break;
             }
         }
     } else {
         if (!is_numeric($d2)) {
             for ($i = 0; $i < 12; $i++) {
                 if (stristr($d2, $months[$i]) != false) {
                     $dpart['mon'] = $i + 1;
                     unset($date[1]);
                     break;
                 }
             }
         } else {
             if ($d2 <= 12 && $d1 >= 1500) {
                 $dpart['mon'] = $d2;
                 unset($date[1]);
             }
             // yyyy-mm-dd
             if ($d1 <= 12 && $d3 >= 1500) {
                 $dpart['mon'] = $d1;
                 unset($date[0]);
             } else {
                 if ($d1 > 12 && $d3 >= 1500) {
                     $dpart['mon'] = $d2;
                     unset($date[1]);
                 }
             }
             // dd-mm-yyyy
         }
     }
     // get day
     unset($date[3]);
     $dpart['mday'] = implode('', $date);
     if (!is_numeric($dpart['mday']) || $dpart['mday'] > 31) {
         return false;
     }
     // get time info. use 1 jan 2008 as a starting date
     $t = strtotime('1-jan-2008 ' . $time);
     if ($t) {
         $t = getdate($t);
         $dpart['hours'] = $t['hours'];
         $dpart['minutes'] = $t['minutes'];
         $dpart['seconds'] = $t['seconds'];
     }
     return $dpart;
 }
Ejemplo n.º 10
0
 /**
  * Returned encoded javascript value 
  */
 public static function encodeVar($v)
 {
     if (!is_numeric($v) && is_string($v)) {
         $v = '"' . Raxan::escapeText($v) . '"';
     } else {
         if ($v instanceof RaxanClientExtension || $v instanceof RaxanClientVariable) {
             // pass chain as value
             $v = $v . '';
         } else {
             if ($v === true) {
                 $v = 'true';
             } else {
                 if ($v === false) {
                     $v = 'false';
                 } else {
                     if (!is_scalar($v)) {
                         // encode arrays and objects
                         $v = Raxan::JSON('encode', $v);
                         // replace _pointer hash array with variable name due to json encoding.
                         // See RaxanClientVariable->_pointer
                         if (strpos($v, ':{"_pointer":"_v')) {
                             $v = preg_replace('/:\\{"_pointer"\\:"(_v[0-9]+)"\\}/', ':\\1', $v);
                         }
                         if (!$v) {
                             $v = '{}';
                         }
                     }
                 }
             }
         }
     }
     return $v;
 }
Ejemplo n.º 11
0
<?php

require_once '../raxan/pdi/gateway.php';
Raxan::sendError('Forbidden access', 403);
Ejemplo n.º 12
0
 /**
  * Adds a custom method to the RaxanElement Class. Use addMethod($object) to add multiple methods from an object
  */
 public static function addMethod($name, $callback = null)
 {
     if (!self::$callMethods) {
         self::$callMethods = array();
     }
     if ($callback === null && is_object($name)) {
         // add methods from an object
         $obj = $name;
         $names = get_class_methods($obj);
         foreach ($names as $name) {
             if ($name[0] != '_') {
                 self::$callMethods[$name] = array($obj, $name);
             }
         }
         // don't add names that begins with '_'
     } else {
         if (!is_callable($callback)) {
             Raxan::throwCallbackException($callback);
         }
         self::$callMethods[$name] = $callback;
     }
 }
Ejemplo n.º 13
0
<?php

/**
 * Raxan Gateway file
 * Copyright (c) 2011 Raymond Irving (http://raxanpdi.com)
 * License: GPL, MIT
 * @package Raxan
 */
// replace \ in path
$__raxanGTWPth = str_replace('\\', '/', dirname(__FILE__)) . '/';
// include main files
include_once $__raxanGTWPth . 'shared/raxan.php';
include_once $__raxanGTWPth . 'shared/raxan.element.php';
// element
include_once $__raxanGTWPth . 'shared/raxan.webpage.php';
// web page
include_once $__raxanGTWPth . 'shared/raxan.ui.php';
// set pdi base path
Raxan::setBasePath($__raxanGTWPth);
Ejemplo n.º 14
0
<?php

require_once "../raxan/pdi/autostart.php";
// add custom phone and money validators
$san = Raxan::dataSanitizer();
$san->addDataValidator('Phone', '/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/');
// using regex
$san->addDataValidator('ZipCode', 'validate_ZipCode');
// using callback
function validate_ZipCode($value)
{
    // validate zip code
    return preg_match('/^(\\d{5}-\\d{4})|(\\d{5})$/', $value);
}
class CustomValidatorPage extends RaxanWebPage
{
    protected $frm;
    protected function _config()
    {
        $this->preserveFormContent = true;
    }
    protected function _init()
    {
        $this->source('views/custom-validators.html');
    }
    protected function formSubmit($e)
    {
        // event callback
        $msg = array();
        // validate user input
        if (!$this->post->isPhone('phone')) {
Ejemplo n.º 15
0
<?php

require_once '../raxan/pdi/gateway.php';
Raxan::sendError('Bad syntax', 400);
Ejemplo n.º 16
0
<?php

require_once '../raxan/pdi/autostart.php';
// system configuration
Raxan::loadConfig('config.php');
// load external config file
Raxan::config('site.timezone', 'America/Toronto');
// set timezone
class SearchBoxPage extends RaxanWebPage
{
    protected $db;
    protected $infoTpl, $searchTpl;
    protected function _init()
    {
        $this->source('views/searchbox.html');
        try {
            // see config.php for connection info
            // For employee sample data visit http://dev.mysql.com/doc/
            $this->db = $this->Raxan->connect('employees');
            // connect to db
        } catch (Exception $e) {
            $this->db = null;
            $msg = $this->getView('connection-failed.html');
            $this->flashmsg($msg, 'bounce', 'rax-box error');
        }
    }
    protected function _load()
    {
        // event to handle employee click
        $this->results->delegate('a', '#click', '.employeeClick');
        // event to handle auto-complete search
Ejemplo n.º 17
0
<?php

require_once "../raxan/pdi/autostart.php";
// set timezone - needed when using E_STRICT
Raxan::config('site.timezone', 'America/Jamaica');
class DateEntry extends RaxanWebPage
{
    protected function _config()
    {
        $this->preserveFormContent = true;
    }
    protected function buttonClick($e)
    {
        $f = $this->post->textVal('format');
        $dt = $this->post->dateVal('date', $f);
        if (!$dt) {
            $dt = 'Invalid date';
        }
        $this->msg->text($dt);
    }
}
?>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Date Entry</title>
    <link href="../raxan/ui/css/master.css" type="text/css" rel="stylesheet" />
    <!--[if lt IE 8]><link rel="stylesheet" href="../raxan/ui/css/master.ie.css" type="text/css"><![endif]-->
Ejemplo n.º 18
0
<?php

require_once '../raxan/pdi/autostart.php';
Raxan::loadPlugin('plugins/showdate.php', true);
class NewPage extends RaxanWebPage
{
    protected function _config()
    {
        $this->masterTemplate = 'views/master.homepage.html';
    }
}
?>

<h3>Date/Time Plugin test page</h3>
<p>
    Lorem ipsum cu nam impedit efficiantur, ei aperiri dissentiet eos, mea dico error saperet in.
    Vidisse pertinax deterruisset id vel, dicunt audire labitur his eu. Pro magna propriae at,
    augue choro quodsi est eu. Tota cotidieque reformidans ei qui, ad dicit impetus persequeris pri,
    harum accommodare id per. Mediocrem quaerendum cu has, habeo inermis nominati eu sed.
</p>
<form name="form1" action="" method="post">
    <input type="submit" name="submit1" id="submit1" value="Reload page" class="button" />
</form>
Ejemplo n.º 19
0
 /**
  * Return DOMNodeList query dom based on XPath
  * @param string $pth CSS selector
  * @param DOMNode $context Optional context node
  * @return DOMNodeList
  */
 public function xQuery($pth, DOMNode $context = null)
 {
     if (!$this->init) {
         $this->initDOMDocument();
     }
     // init dom on first query
     if (!$context) {
         $dl = $this->xPath->query($pth);
     } else {
         if (substr($pth, 0, 1) == '/') {
             $pth = '.' . $pth;
         }
         $dl = $this->xPath->query($pth, $context);
     }
     if (Raxan::$isDebug) {
         if (!$dl) {
             Raxan::debug('xQuery Error: Invalid XPath Expression: ' . $pth);
         } else {
             Raxan::debug("XPath: \t Found " . $dl->length . " \t {$pth} ");
         }
     }
     if (!$dl) {
         libxml_clear_errors();
     }
     // clear libxml error
     return $dl;
 }