コード例 #1
0
    }
    // end process();
    public function view()
    {
        if ($this->invalid()) {
            $this->tpl->assign('error_msg', 1);
        }
        $this->tpl->parse('test_forms_3.tpl');
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $form = new myForm($opf, 'form1');
    if ($form->execute()) {
        $tpl->assign('username', $opf->validator->username);
        $tpl->assign('email', $opf->validator->email);
        $tpl->assign('age', $opf->validator->age);
        $tpl->assign('content', $opf->validator->content);
        $tpl->parse('report.tpl');
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #2
0
<?php

define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
function optResourceDatabase(optClass $tpl, $title, $compiledTime = NULL)
{
    if (is_null($compiledTime)) {
        $r = mysql_query('SELECT `code` FROM `templates` WHERE `title` = \'' . $title . '\'');
    } else {
        $r = mysql_query('SELECT `code` FROM `templates` WHERE `title` = \'' . $title . '\' AND `lastmod` > \'' . $compiledTime . '\'');
    }
    if ($row = mysql_fetch_row($r)) {
        return $row[0];
    }
    return false;
}
// end optResourceDatabase();
try {
    require 'db_connect.php';
    $tpl = new optClass();
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    $tpl->httpHeaders(OPT_HTML);
    $tpl->registerResource('db', 'Database');
    $tpl->assign('current_date', date('d.m.Y'));
    $tpl->parse('db:example17');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #3
0
<?php

define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    $tpl->httpHeaders(OPT_HTML);
    require 'db_connect.php';
    $r = mysql_query('SELECT id, name FROM categories ORDER BY id');
    $categories = array();
    while ($row = mysql_fetch_assoc($r)) {
        $categories[$row['id']] = array('name' => $row['name']);
    }
    $r = mysql_query('SELECT id, name, description, category FROM products ORDER BY category, id');
    $products = array();
    while ($row = mysql_fetch_assoc($r)) {
        // add the next item
        $products[$row['category']][] = array('id' => $row['id'], 'name' => $row['name'], 'description' => $row['description']);
    }
    $tpl->assign('categories', $categories);
    $tpl->assign('products', $products);
    $tpl->parse('example13.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #4
0
<?php

require './common.php';
require OPT_DIR . 'opt.class.php';
require OPF_DIR . 'opf.class.php';
class myRouter implements iopfRouter
{
    public function createURL($vars)
    {
        return var_export($vars, true);
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $opf->setRouter(new myRouter());
    $tpl->assign('vars', array('somevar' => 'somevalue'));
    $tpl->parse('test_router_1.tpl');
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #5
0
require '../lib/opt.class.php';
require '../lib/opt.components.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    $tpl->httpHeaders(OPT_HTML);
    require 'db_connect.php';
    $selector = new selectComponent();
    $selector->set('name', 'selected');
    $selector->push(0, '---SELECT---');
    $r = mysql_query('SELECT id, name FROM categories ORDER BY id');
    while ($row = mysql_fetch_assoc($r)) {
        // add the next item
        $selector->push($row['id'], $row['name']);
    }
    if (isset($_GET['selected'])) {
        $selector->set('selected', $_GET['selected']);
        if ($_GET['selected'] == 0) {
            $selector->set('message', 'Invalid choice!');
        }
    } else {
        $selector->set('selected', 0);
    }
    $tpl->assign('selector', $selector);
    $tpl->parse('example8.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #6
0
 public function __construct(optClass $tpl, iopfValidator $validator)
 {
     $this->router = NULL;
     $this->design = new opfDesign();
     $this->visit = new opfVisit();
     $this->tpl = $tpl;
     $this->validator = $validator;
     // Object configuration
     $tpl->opf = $this;
     $tpl->control[] = 'opfCall';
     $tpl->control[] = 'opfUrl';
     $tpl->control[] = 'opfForm';
     $tpl->control[] = 'opfJavascript';
     $tpl->components['opfInput'] = 1;
     $tpl->components['opfPassword'] = 1;
     $tpl->components['opfTextarea'] = 1;
     $tpl->components['opfQuestion'] = 1;
     $tpl->components['opfLabel'] = 1;
     $tpl->components['opfSelect'] = 1;
     $tpl->components['opfRadio'] = 1;
     $tpl->components['opfFile'] = 1;
     $tpl->components['opfRetypePassword'] = 1;
     $tpl->components['opfCheckQuestion'] = 1;
     $tpl->instructionFiles[] = OPF_DIR . 'opf.template.php';
     $tpl->registerNamespace('opf');
     $tpl->assign('opfDesign', $this->design);
     $tpl->opf = $this;
     $validator->setOpfInstance($this);
 }
コード例 #7
0
<?php

define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    // Enable XML-style delimiters
    $tpl->xmlsyntaxMode = 1;
    // Enable strict XML syntax for the instructions
    $tpl->strictSyntax = 1;
    $tpl->httpHeaders(OPT_HTML);
    require 'db_connect.php';
    $r = mysql_query('SELECT id, name, description FROM products ORDER BY id');
    $list = array();
    while ($row = mysql_fetch_row($r)) {
        // add the next item
        $list[] = array('id' => $row[0], 'name' => $row[1], 'description' => $row[2]);
    }
    $tpl->assign('products', $list);
    if (rand(0, 10) < 5) {
        $tpl->assign('border', 'border="1"');
    }
    $tpl->parse('example11.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #8
0
        }
        $datasource['monthValues'] = array(0 => '---Choose---', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
        $datasource['yearValues'] = array(0 => '---');
        for ($i = 2006; $i <= 2012; $i++) {
            $datasource['yearValues'][$i] = $i;
        }
        $this->setDatasource($datasource);
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $form = new calendarForm($opf, 'calendarForm');
    $form->display();
    if (checkdate($opf->validator->month, $opf->validator->day, $opf->validator->year)) {
        $tpl->assign('date', 1);
        $tpl->assign('day', $opf->validator->day);
        $tpl->assign('month', $opf->validator->month);
        $tpl->assign('year', $opf->validator->year);
    }
    $tpl->parse('test_opt_forms_1.tpl');
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #9
0
<?php

define('OPT_DIR', '../lib/');
require OPT_DIR . 'opt.class.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->charset = 'iso-8859-2';
    $tpl->debugConsole = true;
    $tpl->alwaysRebuild = true;
    $tpl->httpHeaders(OPT_HTML);
    $tpl->assign('mytree', array(0 => array('title' => 'Main category 1', 'depth' => 0), array('title' => 'Main category 2', 'depth' => 0), array('title' => 'Subcategory 2.1', 'depth' => 1), array('title' => 'Main category 3', 'depth' => 0), array('title' => 'Subcategory 3.1', 'depth' => 1), array('title' => 'Item 3.1.1', 'depth' => 2), array('title' => 'Item 3.1.2', 'depth' => 2), array('title' => 'Item 3.1.3', 'depth' => 2), array('title' => 'Subcategory 3.2', 'depth' => 1), array('title' => 'Subcategory 3.3', 'depth' => 1), array('title' => 'Item 3.3.1', 'depth' => 2), array('title' => 'Main category 4', 'depth' => 0), array('title' => 'Subcategory 4.1', 'depth' => 1), array('title' => 'Item 4.1.1', 'depth' => 2)));
    $tpl->parse('example18.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #10
0
<?php

define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    $tpl->httpHeaders(OPT_HTML);
    require 'db_connect.php';
    $r = mysql_query('SELECT id, name, description FROM products ORDER BY id');
    $list = array();
    while ($row = mysql_fetch_row($r)) {
        // add the next item
        $list[] = array('id' => $row[0], 'name' => $row[1], 'description' => $row[2]);
    }
    $tpl->assign('products', $list);
    $tpl->parse('example2.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #11
0
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    require 'db_connect.php';
    $tpl->httpHeaders(OPT_HTML);
    if (isset($_POST['yes'])) {
        die('Thank you for your submission, ' . $_POST['username'] . '!');
    } else {
        if (isset($_POST['ok'])) {
            $username = new textLabelComponent();
            $username->set('name', 'username');
            $username->set('value', $_POST['username']);
            $username->set('message', 'Is this correct?');
            $actions = array(0 => array('name' => 'yes', 'value' => 'Yes', 'type' => 'submit'), array('name' => 'no', 'value' => 'No', 'type' => 'submit'));
        } else {
            $username = new textInputComponent();
            $username->set('name', 'username');
            if (isset($_POST['username'])) {
                $username->set('value', $_POST['username']);
            }
            $actions = array(0 => array('name' => 'ok', 'value' => 'OK', 'type' => 'submit'));
        }
    }
    $tpl->assign('name', $username);
    $tpl->assign('actions', $actions);
    $tpl->parse('example12.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #12
0
define('OPT_DIR', '../lib/');
require OPT_DIR . 'opt.class.php';
require './pagesystem.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->charset = 'iso-8859-2';
    $tpl->debugConsole = true;
    $tpl->alwaysRebuild = true;
    $tpl->httpHeaders(OPT_HTML);
    $data = array();
    // Create data array
    for ($i = 1; $i <= ITEM_NUM; $i++) {
        $data[] = 'Item ' . $i;
    }
    $ps = new pagesystem(ITEM_NUM, PAGE_SIZE, 'example19.php');
    $rows = array();
    for ($i = $ps->startPos(); $i <= $ps->endPos(); $i++) {
        if (isset($data[$i])) {
            $rows[] = array('item' => $data[$i]);
        } else {
            break;
        }
    }
    $tpl->assign('list', $rows);
    $tpl->assign('ps', $ps);
    $tpl->parse('example19.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #13
0
<?php

define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->cache = './cache/';
    $tpl->gzipCompression = 1;
    $tpl->httpHeaders(OPT_HTML);
    $tpl->assign('current_date', date('d.m.Y, H:i:s'));
    // cache this template result for 30 seconds
    $tpl->cacheStatus(true, 30);
    $tpl->parse('example9.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #14
0
        }
        $this->setError('username', 'opf', 'invaliduser');
        return false;
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $form = new myForm($opf, 'form1');
    if ($form->execute()) {
        $tpl->assign('username', $validator->username);
        $tpl->assign('email', $validator->email);
        $tpl->assign('age', $validator->age);
        $tpl->assign('content', $validator->content);
        $tpl->parse('report.tpl');
    } else {
        if ($form->invalid()) {
            $tpl->assign('error_msg', 1);
        }
        $tpl->parse('test_forms_1.tpl');
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #15
0
define('OPT_DIR', '../lib/');
require '../lib/opt.class.php';
require '../lib/opt.components.php';
try {
    $tpl = new optClass();
    $tpl->root = './templates/';
    $tpl->compile = './templates_c/';
    $tpl->gzipCompression = 1;
    $tpl->compileCacheDisabled = 1;
    $tpl->httpHeaders(OPT_HTML);
    require 'db_connect.php';
    $r = mysql_query('SELECT id, name FROM categories ORDER BY id');
    $list = array(0 => array('value' => 0, 'desc' => '---SELECT---', 'selected' => false));
    while ($row = mysql_fetch_assoc($r)) {
        // add the next item
        $list[] = array('value' => $row['id'], 'desc' => $row['name'], 'selected' => false);
    }
    if (isset($_GET['selected'])) {
        $tpl->assign('selected', $_GET['selected']);
        if ($_GET['selected'] == 0) {
            $tpl->assign('message', 'Invalid choice!');
        }
    } else {
        $tpl->assign('selected', 0);
    }
    $tpl->assign('list', $list);
    $tpl->parse('example7.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #16
0
<?php

require './common.php';
require OPT_DIR . 'opt.class.php';
require OPF_DIR . 'opf.class.php';
try {
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $tpl->httpHeaders(OPT_HTML);
    $tpl->assign('ip', $opf->visit->ip);
    $tpl->assign('address', $opf->visit->currentAddress);
    $tpl->assign('ssl', $opf->visit->secure ? 'Yes' : 'No');
    $tpl->assign('browser', $opf->visit->friendly('browser'));
    $tpl->assign('os', $opf->visit->friendly('os'));
    $tpl->assign('languages', $opf->visit->languages);
    $tpl->assign('settings', $opf->visit->settings);
    $tpl->parse('test_visit_1.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
} catch (opfException $exception) {
    opfErrorHandler($exception);
}
コード例 #17
0
        }
        // The displaying command should be located in the last processed form
        $this->tpl->parse('test_multiple_1_1.tpl');
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $form1 = new form1($opf, 'form1');
    if ($form1->execute()) {
        $tpl->assign('fill_form1', 1);
        $tpl->assign('text', $opf->validator->someText);
        $tpl->parse('test_multiple_1_2.tpl');
    } else {
        $form2 = new form2($opf, 'form2');
        if ($form2->execute()) {
            $tpl->assign('fill_form2', 1);
            $tpl->assign('text', $opf->validator->someText);
            $tpl->parse('test_multiple_1_2.tpl');
        }
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #18
0
    }
}
try {
    require './include.php';
    $tpl = new optClass();
    $tpl->loadConfig('./config.php');
    $tpl->setMasterPage('master.tpl');
    $validator = new opfValidator();
    $opf = new opfClass($tpl, $validator->defaultParams());
    $opf->createI18n('./');
    $itemList = new itemList();
    $typeList = new typeList();
    $form1 = new myForm1($opf, 'form');
    $form2 = new myForm2($opf, 'form');
    $form1->nextStep($form2);
    if ($form1->execute()) {
        $tpl->assign('type', $typeList->getType($opf->validator->type));
        switch ($opf->validator->type) {
            case 1:
                $tpl->assign('value', $opf->validator->value);
                break;
            case 2:
                $tpl->assign('value', $itemList->getItem($opf->validator->value));
        }
        $tpl->parse('test_forms_4_3.tpl');
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}