function display($args) { $show = array_get_default($args, 'show', 'home'); $page = null; foreach ($this->pages as $page) { if ($page['name'] == $show) { break; } } if (!$page) { $show = 'home'; $main_show = 'home'; } else { $main_show = array_key_exists('parent', $page) ? $page['parent'] : $show; } $args['show'] = $show; $menu = $this->display_menu($main_show); $this->append(ax_ul_items($menu, array('id' => 'tablist'))); foreach ($this->pages as $page) { if ($page['name'] == $show) { // show header first $this->append(ax_h2($page['descr'])); // then submenu $submenu = $this->display_menu($show, $main_show); $this->append(ax_ul_items($submenu, array('id' => 'subtablist'))); // and finally the page $display = new $page['class']($this, $args, $this->pages); $display->show(); } } }
function display($args) { $show = array_get_default($args, 'show', 'home'); $page = null; foreach ($this->pages as $page) { if ($page['name'] == $show) { break; } } if (!$page) { $show = 'home'; $main_show = 'home'; } else { $main_show = array_key_exists('parent', $page) ? $page['parent'] : $show; } $args['show'] = $show; // Go to monitor if no id is specified $id = array_get_default($args, 'id', ''); if ($id == '') { header('Location: ../?' . http_build_query($args)); exit; } // Display menu $menu = $this->display_menu($main_show); $this->append(ax_ul_items($menu, array('id' => 'tablist'))); foreach ($this->forms as $form) { if ($form['name'] == $show) { break; } } if (!$form or $form['name'] != $show) { return; } $title = $form['descr']; $form = new $form['class']($args); if ($form->get_data($id)) { // Editing existing entity $title .= " {$id}"; } else { // Adding new entity $form->set_control_value('id', ''); $id = ""; unset($args['id']); $title .= " (new)"; } if (Request::is_post()) { $form->fill($_POST); $msg = $form->save_data(); $id = $form->get_control_value('id'); $form->get_data($id); if ($msg != "") { $this->append(ax_p($msg)); } } $fr = new AnewtFormRendererDefault(); $fr->set_form($form); $this->append(ax_h2($title)); $this->append($fr); }
/** * Create an AnewtXHTMLHeader element for the specified header level. * \param $level The header level (1, 2, 3, 4, 5, or 6) * \param $content The content for this element * \param $attributes Additional element attributes (optional) */ function ax_h($level, $content, $attributes = null) { assert('is_int($level);'); $level = max(min($level, 6), 1); switch ($level) { case 1: return ax_h1($content, $attributes); case 2: return ax_h2($content, $attributes); case 3: return ax_h3($content, $attributes); case 4: return ax_h4($content, $attributes); case 5: return ax_h5($content, $attributes); case 6: return ax_h6($content, $attributes); } }
$fragment->append_child(new AnewtXHTMLHeader2('Forms')); $form = new AnewtXHTMLForm(null, array('method' => 'GET')); $input_fragment = new AnewtXHTMLFragment(); $input_fragment->append_child(new AnewtXHTMLLabel('Label: ', array('for' => 'test'))); $input_fragment->append_child(new AnewtXHTMLInput(null, array('name' => 'test', 'id' => 'test', 'type' => 'text'))); $form->append_child(new AnewtXHTMLParagraph($input_fragment)); $select = new AnewtXHTMLSelect(null, array('name' => 'select')); $select->append_child(new AnewtXHTMLOption('First', array('value' => 'first'))); $select->append_child(new AnewtXHTMLOption('Second', array('value' => 'second'))); $select->append_child(new AnewtXHTMLOption('Third', array('value' => 'third'))); $form->append_child(new AnewtXHTMLParagraph($select)); $fragment->append_child($form); $form->append_child(new AnewtXHTMLParagraph(new AnewtXHTMLInput(null, array('type' => 'submit')))); /* Convenience API */ $r = array(); $r[] = ax_h2('Convenience API'); $r[] = ax_p('Test with some <& special characters.', array('style' => 'color: #ccc;')); $r[] = ax_p_class(ax_raw('This is <strong>strong</strong>'), 'someclass'); $r[] = ax_p(ax_abbr('ICE', 'InterCity Express')); $r[] = ax_p(array('Test', ax_br(), 'after the break')); $p = ax_p(array('testje', array('1', '2'), ax_strong('blablabla'))); $p->set_attribute('id', 'paragraph-id'); $p->set_class('foo bar baz'); $p->remove_class('bar'); $p->add_class('quux'); $p->append_child(ax_a_href('name', '/url/')); $r[] = $p; $r[] = ax_p(ax_sprintf('%s & %s', ax_span_class('Sugar', 'sweet'), 'Spice')); $fragment->append_child(ax_fragment($r, ax_p('final paragraph'))); /* Final output */ echo to_string($fragment), NL;
$page = new AnewtPage(); $page->set('title', 'Anewt form test page'); $page->add_stylesheet(ax_stylesheet($css)); $page->append(ax_h1('Test form')); $form = new TestForm(); assert('$form->get_control_value("text5") === "7"'); $form->set_control_value('text5', '8'); if ($form->autofill()) { if ($form->process()) { $page->append(ax_p('Form succesfully processed!')); } else { $page->append(ax_p('Error while processing form!')); } } else { $page->append(ax_p('Form not processed.')); } $fr = new AnewtFormRendererDefault(); $fr->set_form($form); $page->append(ax_h2('The form')); $page->append($fr); if (AnewtRequest::is_post()) { $values = $form->get_control_values(); ob_start(); var_dump($values); $values = ob_get_clean(); $page->append(ax_h2('Form output')); $page->append(ax_pre($values)); $page->append(ax_h2('$_POST values')); $page->append(ax_pre(print_r($_POST, true))); } $page->flush();