set('id', $id);
$vars->set('actionId', $actionId);
$vars->set('category', $category);
$form = &Horde_Form::singleton('PDataForm', &$vars);
if ($form->validate($vars)) {
$vals = array(
'title' => $vars->get('title'),
'info' => $vars->get('info'),
'category' => $vars->get('category'),
'attributes' => serialize(array()),
);
if ($actionId == 'edit') {
$vals['time_modified'] = time();
$result = $pdata->update($id, $vals);
} else {
$vals['time_created'] = time();
$result = $pdata->add($vals);
}
if (is_a($result, 'PEAR_Error')) {
$notification->push(_("There was a problem saving the entry: ") .
$result->getMessage(), 'horde.error');
} else {
$notification->push(_("Success!"), 'horde.success');
$goodEntry = false;
}
} elseif ($actionId == 'edit') {
$entry = $pdata->getById($id);
if (is_a($entry, 'PEAR_Error')) {
$goodEntry = false;
$notification->push(_("There was a problem fetching the data: ") .
$entry->getMessage(), 'horde.error');
} else {
$vars->set('time_created', $entry['time_created']);
$vars->set('category', $entry['category']);
$vars->set('title', $entry['title']);
$vars->set('info', $entry['info']);
}
}
break;
case 'show':
// base url for generation later
$baseUrl = Util::addParameter(Horde::selfUrl(), 'actionId', 'show');
$appUrl = Horde::selfUrl();
// get the maximum journal id
$maxJournalId = $pdata->getMaxJournalId();
$minJournalId = $pdata->getMinJournalId();
// if no direction has been specified, then you want this id, fetch it
if (is_null($direction)) {
$entry = $pdata->getById($id);
} elseif ($direction) {
$entry = $pdata->getJournalById($id, '>', 'ASC');
} else {
$entry = $pdata->getJournalById($id, '<', 'DESC');
}
// check the fetched entry
if (is_a($entry, 'PEAR_Error')) {
$goodEntry = false;
$notification->push("There was a problem getting the journal entry: " .
$entry->getMessage(), 'horde.error');
}
break;
default:
if ($direction) {
$direction = 'ASC';
} else {
$direction = 'DESC';
}
$entries = $pdata->getByCategory('Journal', $order, $direction);
if (is_a($entries, 'PEAR_Error')) {
$goodEntry = false;
$notification->push("There was a problem getting the information: " .
$entries->getMessage(), 'horde.error');
}
break;
}
require PENGUINCODER_TEMPLATES . '/common-header.inc';
require PENGUINCODER_TEMPLATES . '/menu/menu.inc';
switch ($actionId) {
case 'post':
case 'edit':
if (!is_null($form)) {
$renderer = &new Horde_Form_Renderer();
if ($goodEntry) {
$form->renderActive($renderer, $vars, Horde::selfUrl(), 'post');
} else {
$form->renderInactive($renderer, $vars, Horde::selfUrl(), 'post');
}
}
break;
case 'show':
$commentcount = $registry->call('forums/numMessages', array(
$entry['id'], 'penguincoder'));
if (is_a($commentcount, 'PEAR_Error')) {
$commentcount = 0;
}
if (!is_a($entry, 'PEAR_Error')) {
require PENGUINCODER_TEMPLATES . '/data/header.inc';
require PENGUINCODER_TEMPLATES . '/actions/header.inc';
require PENGUINCODER_TEMPLATES . '/actions/main.inc';
require PENGUINCODER_TEMPLATES . '/actions/nav.inc';
require PENGUINCODER_TEMPLATES . '/actions/admin.inc';
require PENGUINCODER_TEMPLATES . '/actions/footer.inc';
require PENGUINCODER_TEMPLATES . '/data/data.inc';
require PENGUINCODER_TEMPLATES . '/data/footer.inc';
}
$comments = $registry->call('forums/postMessage', array(
'penguincoder', $entry['id'], 'commentCallback'
));
$threads = $registry->call('forums/renderThreads', array(
$entry['id'], true, 'penguincoder'));
if (is_a($threads, 'PEAR_Error')) {
$threads = $threads->getMessage();
}
if (is_a($comments, 'PEAR_Error')) {
$comments = $comments->getMessage();
}
if (!empty($threads)) {
echo '
' . $threads;
}
if (!empty($comments)) {
echo '
' . $comments;
}
break;
default:
if (!is_a($entries, 'PEAR_Error') && count($entries)) {
if ($direction == 'DESC') {
$direction = 0;
} else {
$direction = 1;
}
require PENGUINCODER_TEMPLATES . '/journal/listheader.inc';
$style = 'item0';
$counter = 0;
foreach ($entries as $entry) {
if ($style === 'item1') {$style = 'item0';}
else {$style = 'item1';}
include PENGUINCODER_TEMPLATES . '/journal/listentry.inc';
$counter++;
}
include PENGUINCODER_TEMPLATES . '/journal/listfooter.inc';
}
break;
}
echo '
'; require $registry->get('templates', 'horde') . '/common-footer.inc';