addHidden('', 'actionId', 'text', true); $this->addHidden('', 'data_id', 'int', false); $this->addVariable(_("Title"), 'title', 'text', true); $this->addVariable(_("Type"), 'type', 'text', true); $this->addVariable(_("Info"), 'info', 'longText', true); } } class JournalForm extends Horde_Form { function JournalForm(&$vars) { parent::Horde_Form($vars); $this->addHidden('', 'actionId', 'text', true); $this->addVariable(_("Title"), 'title', 'text', true); $this->addVariable(_("Entry"), 'entry', 'longText', true); } } $title = _("Master Blaster"); $vars = &Variables::getDefaultVariables(); $tabs = &new Horde_UI_Tabs('actionId', $vars); $tabs->addTab(_("List Data"), 'admin.php', 'list'); $tabs->addTab(_("Add Data"), 'admin.php', 'add'); $tabs->addTab(_("Post Journal"), 'admin.php', 'post'); $renderer = &new Horde_Form_Renderer(); global $pdata; global $pjournal; $data_id = Util::getFormData('data_id'); $vars->set('actionId', Util::getFormData('actionId')); switch ($vars->get('actionId')) { case 'post': $form = &Horde_Form::singleton('JournalForm', $vars); $valid = $form->validate($vars); if ($valid) { $result = $pjournal->add($vars->get('title'), $vars->get('entry')); if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf( _("There was a problem saving the post: %s"), $result->getMessage()), 'horde.error'); } else { $notification->push(_("Success"), 'horde.success'); header('Location: ' . Horde::selfUrl()); exit; } } break; case 'add': case 'edit': $form = &Horde_Form::singleton('DataForm', $vars); $valid = $form->validate($vars); if ($valid) { switch ($vars->get('actionId')) { case 'add': $result = $pdata->add($vars->get('title'), $vars->get('type'), $vars->get('info')); break; case 'edit': $result = $pdata->update($vars->get('data_id'), $vars->get('title'), $vars->get('type'), $vars->get('info')); break; } if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf( _("There was a problem with the data persistence: %s"), $result->getMessage()), 'horde.error'); } else { $notification->push(_("Success"), 'horde.success'); header('Location: ' . Horde::selfUrl()); exit; } } if ($vars->get('actionId') == 'edit' && !$valid) { $item = $pdata->retrieveById($data_id); if (is_a($item, 'PEAR_Error')) { $notification->push(sprintf( _("There was a problem with the data persistence: %s"), $item->getMessage()), 'horde.error'); } else { $vars->set('data_id', $data_id); $vars->set('title', $item['title']); $vars->set('type', $item['type']); $vars->set('info', $item['info']); } } break; case 'delete': if (isset($data_id)) { $result = $pdata->delete($data_id); if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf( _("There was a problem with the data persistence: %s"), $result->getMessage()), 'horde.error'); } else { $notification->push(_("Success"), 'horde.success'); } } case 'list': default: $result = $pdata->retrieve(); if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf( _("There was a problem with the data persistence: %s"), $result->getMessage()), 'horde.error'); } $data = $pdata->listData(); break; } require_once PENGUINCODER_TEMPLATES . '/common-header.inc'; require_once PENGUINCODER_TEMPLATES . '/menu/menu.inc'; echo '
'; echo $tabs->render(); if (isset($form)) { $form->renderActive($renderer, $vars, 'admin.php', 'post'); } else { require PENGUINCODER_TEMPLATES . '/admin/header.inc'; $style = 'item1'; foreach ($data as $d) { if ($style == 'item1') {$style = 'item0';} else {$style = 'item1';} include PENGUINCODER_TEMPLATES . '/admin/entry.inc'; } require PENGUINCODER_TEMPLATES . '/admin/footer.inc'; } echo ' |