This repository has been archived on 2020-06-13. You can view files and clone it, but cannot push or open issues/pull-requests.
penguincoder.org-horde/admin.php

152 lines
4.9 KiB
PHP

<?php
@define('PENGUINCODER_BASE', dirname(__FILE__));
require_once PENGUINCODER_BASE . '/lib/base.php';
if (!Auth::isAdmin("penguincoder:admin")) {
Horde::authenticationFailureRedirect();
}
require_once 'Horde/Variables.php';
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
require_once 'Horde/UI/Tabs.php';
class DataForm extends Horde_Form
{
function DataForm(&$vars)
{
parent::Horde_Form($vars);
$this->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 '<table style="margin-left: 15%;" width="75%"><tr><td>';
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 '</td></tr></table>';
require $registry->get('templates', 'horde') . '/common-footer.inc';