+++ /dev/null
-<?php
-/**
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Joel Vandal <joel@scopserv.com>
- * @package Babel
- */
-
-class Translate_Display {
-
- function header($msg, $msg2 = '') {
- global $cnt_i, $registry;
- $select_img = Horde::img('alerts/message.png');
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="header">%s</td><td align="right" class="header">%s</td><td class="header" width="20">%s</td></tr></table>', $msg, $msg2, $select_img);
- flush();
- }
-
- function warning($msg, $bold = true) {
- global $cnt_i, $registry;
- $item = ($cnt_i++ % 2);
- $select_img = Horde::img('alerts/warning.png');
- if ($bold) {
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="item%d" style="color: #ff0000">%s</td><td class="item%1$d" width="20">%s</td></tr></table>', $item, $msg, $select_img);
- } else {
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="item%d small" style="color: #ff0000">%s</td><td class="item%1$d" width="20">%s</td></tr></table>', $item, $msg, $select_img);
- }
- flush();
- }
-
- function error($msg) {
- global $cnt_i, $registry;
- $item = ($cnt_i++ % 2);
- $select_img = Horde::img('alerts/error.png');
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="item%d" style="color: #ff0000"><b>%s</b></td><td class="item%1$d" width="20">%s</td></tr></table>', $item, $msg, $select_img);
- flush();
- }
-
- function info($msg = "", $bold = true) {
-
- global $cnt_i, $registry;
-
- if (empty($msg)) {
- echo "<br />";
- } else {
-
- $item = ($cnt_i++ % 2);
-
- $select_img = Horde::img('alerts/select.png');
- if ($bold) {
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="item%d"><b>%s</b></td><td class="item%1$d" width="20">%s</td></tr></table>', $item, $msg, $select_img);
- } else {
- print sprintf('<table cellspacing=0 cellpadding=0 width=100%%><tr><td class="item%d small">%s</td><td class="item%1$d" width="20">%s</td></tr></table>', $item, $msg, '');
- }
- flush();
- }
- }
-
- function parseCharset($headers)
- {
- if (preg_match('/charset=(.*)/i', $headers, $m)) {
- return $m[1];
- }
- return 'UTF-8';
- }
-
- function convert_string($msg) {
- global $po;
-
- $f = array('/</', '/>/');
- $t = array('<', '>');
- $msg = preg_replace($f, $t, $msg);
- return Horde_String::convertCharset(html_entity_decode($msg), 'UTF-8', Translate_Display::parseCharset($po->meta['Content-Type']));
- }
-
- function display_string($msg) {
- global $po;
-
- $f = array('/</', '/>/');
- $t = array('<', '>');
- $msg = preg_replace($f, $t, $msg);
- return Horde_String::convertCharset($msg, Translate_Display::parseCharset($po->meta['Content-Type']), 'UTF-8');
- }
-
- function get_percent($used, $total) {
- if ($total > 0) {
- $percent = sprintf("%2.2f", (($used * 100) / $total));
- } else {
- $percent = 0;
- }
-
- return $percent;
- }
-
- function create_bargraph ($used, $total, $text = true, $reverse = false, $small = false) {
- if ($total > 0) {
- $percent = round(($used * 100) / $total);
- } else {
- $percent = 0;
- }
-
- $html = '<table border="0" cellpadding="0" cellspacing="0"><tr><td nowrap="nowrap">';
- $html .= '<table border="0" width="100" cellpadding="0" cellspacing="0">';
- $html .= '<tr height="10">';
-
- if ($percent > 0) {
- $html .= '<td nowrap="nowrap" width="' . ($percent) . '" bgcolor="#00FF00"></td>';
- }
-
- if ($percent != 100) {
- $html .= '<td nowrap="nowrap" width="' . (100 - $percent) . '" ';
- if ($reverse) {
- $html .= ' bgcolor="#FFFFFF"></td>';
- } else {
- $html .= ' bgcolor="#006699"></td>';
- }
- }
-
- $html .= '</tr></table></td>';
-
- if ($text) {
- if ($small) {
- $html .= '<td class="small"> ' . $percent .'% </td>';
- } else {
- $html .= '<td> ' . $percent .'% </td>';
- }
- }
-
- $html .= '</tr></table>';
-
- return $html;
- }
-
-}
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<?php
-
-$page_title = $GLOBALS['registry']->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-?>
-<title><?php echo $page_title ?></title>
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<!-- Skeleton: Copyright 2004-2010 The Horde Project. Skeleton is under a Horde license. -->
-<!-- Horde Project: http://www.horde.org/ | Skeleton: http://www.horde.org/horde/ -->
-<!-- Horde Licenses: http://www.horde.org/licenses/ -->
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<?php
-
-$page_title = $registry->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-?>
-<title><?php echo htmlspecialchars($page_title) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-/**
- * $Id: block.php 219 2008-01-11 09:45:33Z duck $
- *
- * Copyright Obala d.o.o. (www.obala.si)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- * @package Folks
- */
-define('HORDE_BASE', dirname(__FILE__) . '/..');
-require_once HORDE_BASE . '/lib/base.php';
-require_once 'Horde/Loader.php';
-
-// Block to load
-$block_id = Horde_Util::getFormData('block');
-list($app, $name) = explode(':', $block_id);
-
-$block_data = array();
-$block = Horde_Block_Collection::getBlock($app, $name, Horde_Util::getFormData('defaults'));
-if ($block instanceof PEAR_Error) {
- $block_data['title'] = $block->getMessage();
- $block_data['content'] = $block->getDebugInfo();
-} else {
- $block_data['title'] = @$block->getTitle();
- if ($block_data['title'] instanceof PEAR_Error) {
- $block_data['title'] = $block_data['title']->getMessage();
- }
- $block_data['content'] = @$block->getContent();
- if ($block_data['content'] instanceof PEAR_Error) {
- $block_data['content'] = $block_data['content']->getDebugInfo();
- }
-}
-
-echo Horde_Serialize::serialize($block_data, Horde_Serialize::JSON);
+++ /dev/null
-<?php
-/**
- * The Horde_Block_Layout_View class represents the user defined portal layout.
- *
- * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Duck <duck@obala.net>
- * @package Horde_Block
- */
-class Horde_Block_Layout_View_Js extends Horde_Block_Layout_View {
-
- /**
- * Render the current layout as HTML.
- *
- * @return string HTML layout.
- */
- function toHtml()
- {
- $html = '<div id="page">';
- $js = '<script type="text/javascript">' . "\n";
- $js .= 'var confirm_remove = "' . _("Are sure to remove this block?") . '";' . "\n";
- $js .= 'var edit_url = "' . Horde::url('dragdrop/params.php') . '";' . "\n";
- $js .= 'var load_url = "' . Horde::url('dragdrop/block.php') . '";' . "\n";
- $js .= 'var list_url = "' . Horde::url('dragdrop/select.php') . '";' . "\n";
- $js .= 'var save_url = "' . Horde::url('dragdrop/save.php') . '";' . "\n";
-
- $js_init = '<script type="text/javascript">'
- . ' function init() {'
- . ' portal = new Xilinus.Portal("#page div", {onOverWidget: onOverWidget, onOutWidget: onOutWidget});';
-
- $js_id = 0;
- $widget_col = 0;
- $columns = 0;
- foreach ($this->_layout as $row_num => $row) {
- foreach ($row as $col_num => $item) {
- if ($col_num > $columns) {
- $columns = $col_num;
- }
- if (is_array($item)) {
- $js .= $this->_serializeBlock($js_id, $item['app'], $item['params']['type'],
- $item['params']['params'], $js_init, $col_num);
- $js_id++;
- }
- }
- }
-
- $columns = max($columns, 2); // FOR TESTING ADD AT KEAST 3 COLUMNS
- for ($col_num = 0; $col_num <= $columns; $col_num++) {
- $html .= '<div id="widget_col_' . $col_num . '"></div>';
- }
-
- $js .= '</script>';
-
- $js_init .= 'portal.addWidgetControls("control_buttons");'
- . '}'
- . 'document.observe("dom:loaded", init);
-'
- . '</script>';
-
- $html .= '</div>' . "\n" . $js . "\n" . $js_init;
-
- // Strip any CSS <link> tags out of the returned content so
- // they can be handled seperately.
- if (preg_match_all('/<link .*?rel="stylesheet".*?\/>/', $html, $links)) {
- $html = str_replace($links[0], '', $html);
- $this->_linkTags = $links[0];
- }
-
- return $html;
- }
-
- function _serializeBlock($js_id, $app, $name, $params, &$js_init, $col_num)
- {
- $block = Horde_Block_Collection::getBlock($app, $name, $params);
- if ($block instanceof PEAR_Error) {
- $title = $block->getMessage();
- $content = $block->getDebugInfo();
- $params = array();
- } else {
- $content = @$block->getContent();
- if ($content instanceof PEAR_Error) {
- $content = $content->getDebugInfo();
- }
- $title = @$block->getTitle();
- if ($title instanceof PEAR_Error) {
- $title = $title->getMessage();
- } else {
- $title = strip_tags($title);
- }
- }
-
- $content = Horde_Serialize::serialize($content, Horde_Serialize::JSON);
- $title = Horde_Serialize::serialize($title, Horde_Serialize::JSON);
- $params = Horde_Serialize::serialize($params, Horde_Serialize::JSON);
-
- $js_init .= 'portal.add(new Xilinus.Widget().'
- . 'setTitle(title_' . $js_id .').'
- . ' setContent(content_' . $js_id .'), ' . $col_num . ');'
- . '_widgets_blocks[' . $js_id . '] = "' . $app . ':' . $name . '";'
- . '_layout_params[' . $js_id . '] = \'' . $params . '\'.evalJSON();'
- . 'delete title_' . $js_id .';'
- . 'delete content_' . $js_id .';' . "\n";
-
- return 'var content_' . $js_id . ' = ' . $content . ';' . "\n"
- . 'var title_' . $js_id . ' = ' . $title . ';' . "\n";
- }
-}
+++ /dev/null
-<?php
-/**
- * Copyright 2008 Thomas Trethan <thomas@trethan.net>
- *
- * See the enclosed file LICENSE for license information (ASL). If you
- * did not receive this file, see http://www.horde.org/licenses/asl.php.
- */
-
-function _cleanupData()
-{
- $GLOBALS['import_step'] = 1;
- return Horde_Data::IMPORT_FILE;
-}
-
-@define('FIMA_BASE', dirname(__FILE__));
-require_once FIMA_BASE . '/lib/base.php';
-
-$ledger = Fima::getActiveLedger();
-
-/* Importable file types. */
-$file_types = array('csv' => _("CSV"),
- 'tsv' => _("TSV"));
-
-/* Templates for the different import steps. */
-$templates = array(
- Horde_Data::IMPORT_CSV => array($registry->get('templates', 'horde') . '/data/csvinfo.inc'),
- Horde_Data::IMPORT_TSV => array($registry->get('templates', 'horde') . '/data/tsvinfo.inc'),
- Horde_Data::IMPORT_MAPPED => array($registry->get('templates', 'horde') . '/data/csvmap.inc'),
- Horde_Data::IMPORT_DATETIME => array($registry->get('templates', 'horde') . '/data/datemap.inc'),
- Horde_Data::IMPORT_FILE => array(FIMA_TEMPLATES . '/data/import.inc', FIMA_TEMPLATES . '/data/export.inc'),
-);
-
-/* Field/clear name mapping. */
-$app_fields = array('date' => _("Date"),
- 'asset' => _("Asset Account"),
- 'account' => _("Account"),
- 'desc' => _("Description"),
- 'amount' => _("Amount"),
- 'eo' => _("e.o."));
-
-/* Date/time fields. */
-$time_fields = array('date' => 'date');
-
-/* Initial values. */
-$param = array('time_fields' => $time_fields,
- 'file_types' => $file_types);
-$import_format = Horde_Util::getFormData('import_format', '');
-$import_step = Horde_Util::getFormData('import_step', 0) + 1;
-$next_step = Horde_Data::IMPORT_FILE;
-$actionID = Horde_Util::getFormData('actionID');
-$error = false;
-
-/* Loop through the action handlers. */
-switch ($actionID) {
-case 'export':
- $data = array();
-
- /* Create a Fima storage instance. */
- $storage = &Fima_Driver::singleton($ledger);
- if (is_a($storage, 'PEAR_Error')) {
- $notification->push(sprintf(_("Failed to access the ledger: %s"), $storage->getMessage()), 'horde.error');
- $error = true;
- break;
- }
- $params = $storage->getParams();
-
- $filters = array(array('type', $prefs->getValue('active_postingtype')));
-
- /* Get accounts and postings. */
- $accounts = Fima::listAccounts();
- $postings = Fima::listPostings($filters);
-
- foreach ($postings as $postingId => $posting) {
- $row = array();
- foreach ($posting as $key => $value) {
- switch ($key) {
- case 'date':
- $row[$key] = strftime(Fima::convertDateFormat($prefs->getValue('date_format')), $value);
- break;
- case 'asset':
- case 'account':
- $row[$key] = isset($accounts[$value]) ? $accounts[$value]['number'] : '';
- break;
- case 'amount':
- $row[$key] = Fima::convertValueToAmount($value);
- break;
- case 'eo':
- case 'desc':
- $row[$key] = Horde_String::convertCharset($value, 'UTF-8', $params['charset']);
- break;
- default:
- break;
- }
- }
- $data[] = $row;
- }
-
- if (!count($data)) {
- $notification->push(_("There were no postings to export."), 'horde.message');
- $error = true;
- break;
- }
-
- switch (Horde_Util::getFormData('exportID')) {
- case EXPORT_CSV:
- $injector->getInstance('Horde_Data')->getData('Csv', array('cleanup' => '_cleanupData'))->exportFile(_("postings.csv"), $data, true);
- exit;
-
- case EXPORT_TSV:
- $injector->getInstance('Horde_Data')->getData('Tsv', array('cleanup' => '_cleanupData'))->exportFile(_("postings.tsv"), $data, true);
- exit;
- }
- break;
-
-case Horde_Data::IMPORT_FILE:
- $storage = &Fima_Driver::singleton($ledger);
- if (is_a($storage, 'PEAR_Error')) {
- $notification->push(sprintf(_("Failed to access the ledger: %s"), $storage->getMessage()), 'horde.error');
- $error = true;
- break;
- }
-
- $_SESSION['import_data']['target'] = $ledger;
- $_SESSION['import_data']['purge'] = Horde_Util::getFormData('purge');
- break;
-}
-
-if (!$error) {
- try {
- $data = $injector->getInstance('Horde_Data')->getData($import_format, array('cleanup' => '_cleanupData'));
- $next_step = $data->nextStep($actionID, $param);
- } catch (Horde_Data_Exception $e) {
- if ($data) {
- $notification->push($e, 'horde.error');
- $next_step = $data->cleanup();
- } else {
- $notification->push(_("This file format is not supported."), 'horde.error');
- $next_step = Horde_Data::IMPORT_FILE;
- }
- }
-}
-
-/* We have a final result set. */
-if (is_array($next_step)) {
- /* Create a Fima storage instance. */
- $storage = &Fima_Driver::singleton($ledger);
- if (is_a($storage, 'PEAR_Error')) {
- $notification->push(sprintf(_("Failed to access the ledger: %s"), $storage->getMessage()), 'horde.error');
- }
-
- $params = $storage->getParams();
-
- /* Purge old postings if requested. */
- if ($_SESSION['import_data']['purge']) {
- $result = $storage->deleteAll(false, $prefs->getValue('active_postingtype'));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("The postings could not be purged: %s"), $result->getMessage()), 'horde.error');
- } else {
- $notification->push(_("Postings successfully purged."), 'horde.success');
- }
- }
-
- /* Get accounts and postings. */
- $accounts = Fima::listAccounts();
- $accounts_indices = array();
- foreach ($accounts as $account) {
- $accounts_indices[$account['number']] = $account['account_id'];
- }
-
- foreach ($next_step as $row) {
- $row['type'] = $prefs->getValue('active_postingtype');
- $row['asset'] = sprintf('%\'04d', $row['asset']);
- $row['asset'] = isset($accounts_indices[$row['asset']]) ? $accounts_indices[$row['asset']] : null;
- $row['account'] = sprintf('%\'04d', $row['account']);
- $row['account'] = isset($accounts_indices[$row['account']]) ? $accounts_indices[$row['account']] : null;
- $row['date'] = Fima::convertDateToStamp($row['date'], Fima::convertDateFormat($prefs->getValue('date_format')));
- $row['amount'] = Fima::convertAmountToValue($row['amount']);
- if ($prefs->getValue('expenses_sign') == 0) {
- if ($row['account'] !== null) {
- if ($accounts[$row['account']]['type'] == FIMA_ACCOUNTTYPE_EXPENSE) {
- $row['amount'] *= -1;
- }
- } else {
- $row['amount'] *= -1;
- }
- }
- $row['desc'] = isset($row['desc']) ? trim($row['desc']) : '';
- $row['eo'] = isset($row['eo']) ? (bool)trim($row['eo']) : false;
- $result = $storage->addPosting($row['type'], $row['date'], $row['asset'], $row['account'], $row['eo'], $row['amount'], $row['desc']);
- if (is_a($result, 'PEAR_Error')) {
- break;
- }
- }
-
- if (!count($next_step)) {
- $notification->push(sprintf(_("The %s file didn't contain any postings."),
- $file_types[$_SESSION['import_data']['format']]), 'horde.error');
- } else {
- $notification->push(sprintf(_("%s successfully imported"),
- $file_types[$_SESSION['import_data']['format']]), 'horde.success');
- }
- $next_step = $data->cleanup();
-}
-
-$title = _("Import/Export Postings");
-require FIMA_TEMPLATES . '/common-header.inc';
-require FIMA_TEMPLATES . '/menu.inc';
-
-if ($next_step == Horde_Data::IMPORT_FILE) {
- /* Build the charset options. */
- $charsets = $registry->nlsconfig['encodings'];
- asort($charsets);
- $all_charsets = $registry->nlsconfig['charsets'];
- natcasesort($all_charsets);
- foreach ($all_charsets as $charset) {
- if (!isset($charsets[$charset])) {
- $charsets[$charset] = $charset;
- }
- }
- $my_charset = $GLOBALS['registry']->getLanguageCharset();
-}
-
-foreach ($templates[$next_step] as $template) {
- require $template;
- echo '<br />';
-}
-require $registry->get('templates', 'horde') . '/common-footer.inc';
+++ /dev/null
-<?php
-/**
- * Fima storage implementation for PHP's PEAR database abstraction layer.
- *
- * Required values for $params:<pre>
- * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.).
- * 'table' The name of the foo table in 'database'.
- * 'charset' The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- * 'database' The name of the database.
- * 'hostspec' The hostname of the database server.
- * 'protocol' The communication protocol ('tcp', 'unix', etc.).
- * 'username' The username with which to connect to the database.
- * 'password' The password associated with 'username'.
- * 'options' Additional options to pass to the database.
- * 'tty' The TTY on which to connect to the database.
- * 'port' The port on which to connect to the database.</pre>
- *
- * The table structure can be created by the scripts/sql/fima.sql
- * script.
- *
- * Copyright 2007-2008 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Thomas Trethan <thomas@trethan.net>
- * @package Fima
- */
-class Fima_Driver_sql extends Fima_Driver {
-
- /**
- * Handle for the current database connection.
- *
- * @var DB
- */
- var $_db;
-
- /**
- * Constructs a new SQL storage object.
- *
- * @param string $ledger The ledger to load.
- * @param array $params A hash containing connection parameters.
- */
- function Fima_Driver_sql($ledger, $params = array())
- {
- $this->_ledger = $ledger;
- $this->_params = $params;
- }
-
- /**
- * Retrieves accounts from the database.
- *
- * @param array $filters Any filters for restricting the retrieved accounts.
- *
- * @return mixed True on success, PEAR_Error on failure.
- */
- function retrieveAccounts($filters = array())
- {
- /* Build the SQL query. */
- $query = sprintf('SELECT * FROM %s WHERE account_owner = ?', $this->_params['table_accounts']);
- $values = array($this->_ledger);
-
- /* Add filters. */
- $this->_addFilters($filters, $query, $values, 'account_');
-
- /* Sorting. */
- $query .= ' ORDER BY account_number ASC';
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::retrieveAccounts(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $this->_accounts = array();
- $result = $this->_db->query($query, $values);
-
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
-
- /* Store the retrieved values in the accounts variable. */
- $this->_accounts = array();
- while ($row && !is_a($row, 'PEAR_Error')) {
- /* Add this new account to the $_account list. */
- $this->_accounts[$row['account_id']] = $this->_buildAccount($row);
-
- /* Advance to the new row in the result set. */
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- }
- $result->free();
- } else {
- return $result;
- }
-
- return true;
- }
-
- /**
- * Retrieves one account from the database.
- *
- * @param string $accountId The ID of the account to retrieve.
- *
- * @return array The array of account attributes.
- */
- function getAccount($accountId)
- {
- /* Build the SQL query. */
- $query = sprintf('SELECT * FROM %s WHERE account_owner = ? AND account_id = ?',
- $this->_params['table_accounts']);
- $values = array($this->_ledger, $accountId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::getAccount(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
- if ($row === null) {
- return PEAR::raiseError(_("Not found"));
- }
-
- /* Decode and return the account. */
- return $this->_buildAccount($row);
- }
-
- /**
- * Retrieves one account from the database by number.
- *
- * @param string $number The number of the account to retrieve.
- *
- * @return array The array of account attributes.
- */
- function getAccountByNumber($number)
- {
- /* Build the SQL query. */
- $query = sprintf('SELECT * FROM %s WHERE account_owner = ? AND account_number = ?',
- $this->_params['table_accounts']);
- $values = array($this->_ledger, sprintf('%\'04s', $number));
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::getAccountByNumber(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
- if ($row === null) {
- return PEAR::raiseError(_("Not found"));
- }
-
- /* Decode and return the account. */
- return $this->_buildAccount($row);
- }
-
- /**
- * Retrieves postings from the database.
- *
- * @param array $filters Any filters for restricting the retrieved postings.
- * @param array $sorting Sort order of retrieved postings.
- * @param array $limit Limit of the retrieved postings, array(page, postings/page).
- *
- * @return mixed True on success, PEAR_Error on failure.
- */
- function retrievePostings($filters = array(), $sorting = array(), $limit = array())
- {
- /* Build the SQL query filter. */
- $queryfilter = ' WHERE posting_owner = ?';
- $values = array($this->_ledger);
-
- /* Add filters. */
- $this->_addFilters($filters, $queryfilter, $values, 'posting_');
-
- $query = sprintf('SELECT count(p.posting_id) posting_count, SUM(p.posting_amount) posting_result FROM %s p',
- $this->_params['table_postings']);
- $query .= $queryfilter;
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
- $this->_postingsCount = (int)$row['posting_count'];
- $this->_postingsResult = $row['posting_result'];
- $result->free();
-
- // correct result when account is an asset account too
- if ($this->_postingsCount > 0) {
- $query = sprintf('SELECT SUM(p.posting_amount) posting_result ' .
- 'FROM %s p JOIN %s a ON a.account_id = p.posting_account ' .
- $queryfilter . ' AND a.account_type = ?',
- $this->_params['table_postings'], $this->_params['table_accounts']);
- $values2 = $values;
- $values2[] = FIMA_ACCOUNTTYPE_ASSET;
- $result = $this->_db->query($query, $values2);
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
- }
- $this->_postingsResult -= $row['posting_result'];
- $result->free();
- }
- } else {
- return $result;
- }
-
- /* Fetch the postings if necessary. */
- $this->_postings = array();
- if ($this->_postingsCount == 0) {
- return true;
- }
-
- $query = sprintf('SELECT p.*, asset.account_number posting_asset_number, account.account_number posting_account_number ' .
- 'FROM %s p LEFT OUTER JOIN %s asset ON p.posting_asset = asset.account_id LEFT OUTER JOIN %s account ON p.posting_account = account.account_id',
- $this->_params['table_postings'], $this->_params['table_accounts'], $this->_params['table_accounts']);
- $query .= $queryfilter;
-
- /* Sorting. */
- if (!is_array($sorting)) {
- $sorting = array($sorting);
- }
- if (count($sorting) == 0) {
- $sorting = array('posting_date ASC');
- }
- $query .= ' ORDER BY ' . implode(', ', $sorting);
-
- /* Limit. */
- if (count($limit) > 0) {
- if ($limit[0] < 0) {
- $limit[0] += ceil($this->_postingsCount / $limit[1]) + 1;
- }
- $limit[0] = ($limit[0] - 1) * $limit[1];
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings() limitQuery: %s', $query), 'DEBUG');
- $result = $this->_db->queryLimit($query, $limit[0], $limit[1], $values);
- } else {
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings(): %s', $query), 'DEBUG');
- $result = $this->_db->query($query, $values);
- }
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
-
- /* Store the retrieved values in the accounts variable. */
- while ($row && !is_a($row, 'PEAR_Error')) {
- /* Add this new posting to the $_posting list. */
- $this->_postings[$row['posting_id']] = $this->_buildPosting($row);
-
- /* Advance to the new row in the result set. */
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- }
- $result->free();
- } else {
- return $result;
- }
-
- return true;
- }
-
- /**
- * Retrieves one posting from the database.
- *
- * @param string $postingId The ID of the posting to retrieve.
- *
- * @return array The array of posting attributes.
- */
- function getPosting($postingId)
- {
- /* Build the SQL query. */
- $query = sprintf('SELECT * FROM %s WHERE posting_owner = ? AND posting_id = ?',
- $this->_params['table_postings']);
- $values = array($this->_ledger, $postingId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::getPosting(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
-
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
- if ($row === null) {
- return PEAR::raiseError(_("Not found"));
- }
-
- /* Decode and return the posting. */
- return $this->_buildPosting($row);
- }
-
- /**
- * Get grouped results.
- *
- * @param array $groups Fields to group.
- * @param boolean $filters Filters for postings.
- *
- * @return array A matrix of the grouped results.
- */
- function getResults($groups, $filters = array()) {
- $matrix = array();
-
- /* Fix grouping. */
- if (!is_array($groups)) {
- $groups = array($groups);
- }
- if (!isset($groups[1])) {
- $groups[1] = 'owner';
- }
- foreach ($groups as $groupId => $group) {
- switch($group) {
- case 'date_month': $groups[$groupId] = 'FROM_UNIXTIME(posting_date, \'%Y%m\')'; break;
- case 'date_year': $groups[$groupId] = 'FROM_UNIXTIME(posting_date, \'%Y\')'; break;
- case 'asset_number': $groups[$groupId] = 'asset.account_number'; break;
- case 'asset_parent': $groups[$groupId] = 'CONCAT(LEFT(asset.account_number, 2), \'00\')'; break;
- case 'asset_type': $groups[$groupId] = 'asset.account_type'; break;
- case 'account_number': $groups[$groupId] = 'account.account_number'; break;
- case 'account_parent': $groups[$groupId] = 'CONCAT(LEFT(account.account_number, 2), \'00\')'; break;
- case 'account_type': $groups[$groupId] = 'account.account_type'; break;
- default: $groups[$groupId] = 'posting_'.$group; break;
- }
- }
-
- /* Build the SQL query filter. */
- $query = sprintf('SELECT %s x, %s y, sum(posting_amount) result ' .
- 'FROM %s p LEFT OUTER JOIN %s asset ON p.posting_asset = asset.account_id AND p.posting_owner = asset.account_owner LEFT OUTER JOIN %s account ON p.posting_account = account.account_id AND p.posting_owner = account.account_owner ' .
- 'WHERE posting_owner = ?',
- $groups[0], $groups[1], $this->_params['table_postings'], $this->_params['table_accounts'], $this->_params['table_accounts']);
- $values = array($this->_ledger);
-
- /* Add filters. */
- foreach ($filters as $filterId => $filter) {
- switch($filter[0]) {
- case 'date_month': $filters[$filterId][0] = 'FROM_UNIXTIME(posting_date, \'%Y%m\')'; break;
- case 'date_year': $filters[$filterId][0] = 'FROM_UNIXTIME(posting_date, \'%Y%m\')'; break;
- case 'asset_number': $filters[$filterId][0] = 'asset.account_number'; break;
- case 'asset_parent': $filters[$filterId][0] = 'LEFT(asset.account_number, 2)'; break;
- case 'asset_type': $filters[$filterId][0] = 'asset.account_type'; break;
- case 'account_number': $filters[$filterId][0] = 'account.account_number'; break;
- case 'account_parent': $filters[$filterId][0] = 'LEFT(account.account_number, 2)'; break;
- case 'account_type': $filters[$filterId][0] = 'account.account_type'; break;
- default: $filters[$filterId][0] = 'posting_'.$filter[0]; break;
- }
- }
- $this->_addFilters($filters, $query, $values);
-
- /* Add grouping. */
- $query .= ' GROUP BY ' . implode(', ', $groups);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::getResults(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $result = $this->_db->query($query, $values);
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
-
- /* Store the retrieved values in the accounts variable. */
- while ($row && !is_a($row, 'PEAR_Error')) {
- /* Add this new posting to the $_posting list. */
- if (!isset($matrix[$row['y']])) {
- $matrix[$row['y']] = array();
- }
- $matrix[$row['y']][$row['x']] = $row['result'];
-
- /* Advance to the new row in the result set. */
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- }
- $result->free();
- }
-
- return $matrix;
- }
-
- /**
- * Get the results of all asset accounts.
- *
- * @param string $postingtype Type of postings.
- * @param boolean $perdate Date of asset results.
- *
- * @return array Array of asset accounts and results
- */
- function getAssetResults($postingtype, $perdate = null)
- {
- $perdate = ($perdate === null) ? mktime() : (int)$perdate;
-
- /* Build the SQL query. */
- $query = sprintf('SELECT account_id, SUM(account_result) account_result FROM ( ' .
- ' SELECT a1.account_id, SUM(p1.posting_amount) account_result ' .
- ' FROM %s a1 LEFT OUTER JOIN %s p1 ON a1.account_id = p1.posting_asset AND p1.posting_owner = ? AND p1.posting_type = ? ' .
- ' WHERE a1.account_owner = ? AND a1.account_type = ? and p1.posting_date <= ?' .
- ' GROUP BY a1.account_id ' .
- ' UNION ' .
- ' SELECT a2.account_id, SUM(p2.posting_amount) * -1 account_result ' .
- ' FROM %s a2 LEFT OUTER JOIN %s p2 ON a2.account_id = p2.posting_account AND p2.posting_owner = ? AND p2.posting_type = ? ' .
- ' WHERE a2.account_owner = ? AND a2.account_type = ? and p2.posting_date <= ?' .
- ' GROUP BY a2.account_id ' .
- ') x ' .
- 'GROUP BY account_id ',
- $this->_params['table_accounts'], $this->_params['table_postings'],
- $this->_params['table_accounts'], $this->_params['table_postings']);
- $values = array($this->_ledger, $postingtype, $this->_ledger, FIMA_ACCOUNTTYPE_ASSET, $perdate,
- $this->_ledger, $postingtype, $this->_ledger, FIMA_ACCOUNTTYPE_ASSET, $perdate);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::getAssetResults(): %s', $query), 'DEBUG');
-
- /* Execute the query. */
- $assetresults = array();
- $result = $this->_db->query($query, $values);
- if (isset($result) && !is_a($result, 'PEAR_Error')) {
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- if (is_a($row, 'PEAR_Error')) {
- return $row;
- }
-
- /* Store the retrieved values in the accounts variable. */
- while ($row && !is_a($row, 'PEAR_Error')) {
- /* Add this new posting to the $_posting list. */
- $assetresults[] = $row;
-
- /* Advance to the new row in the result set. */
- $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
- }
- $result->free();
- } else {
- return $result;
- }
-
- return $assetresults;
- }
-
- /**
- * Build an account.
- *
- * @param array $row Datasbase row holding account attributes.
- * @param boolean $getparent Also get parent account.
- *
- * @return array The array of account attributes.
- */
- function _buildAccount($row, $getparent = true)
- {
- $parent = null;
- if ($getparent) {
- if (($parent_number = Fima::getAccountParent($row['account_number'])) !== null) {
- if (isset($this->_accounts[$parent_number])) {
- $parent = $this->_accounts[$parent_number];
- } else {
- $parent = $this->getAccountByNumber($parent_number);
- if (is_a($parent, 'PEAR_Error')) {
- $parent = null;
- }
- }
- }
- }
-
- /* Create a new account based on $row's values. */
- return array('account_id' => $row['account_id'],
- 'owner' => $row['account_owner'],
- 'number' => sprintf('%\'04d', $row['account_number']),
- 'type' => $row['account_type'],
- 'name' => Horde_String::convertCharset($row['account_name'], $this->_params['charset'], 'UTF-8'),
- 'eo' => $row['account_eo'],
- 'desc' => Horde_String::convertCharset($row['account_desc'], $this->_params['charset'], 'UTF-8'),
- 'closed' => $row['account_closed'],
- 'label' => trim($row['account_number'] . ' ' .
- (($parent === null) ? '' : $parent['name'] . ' - ') .
- Horde_String::convertCharset($row['account_name'], $this->_params['charset'], 'UTF-8')),
- 'parent_id' => ($parent === null) ? null : $parent['account_id'],
- 'parent_number' => ($parent === null) ? '' : $parent['number'],
- 'parent_name' => ($parent === null) ? '' : $parent['name']);
- }
-
- /**
- * Adds an account to the backend storage.
- *
- * @param string $number The number of the account.
- * @param string $type The type of the account.
- * @param string $name The name (short) of the account.
- * @param boolean $eo Extraordinary account.
- * @param string $desc The description (long) of the account.
- * @param boolean $closed Close account.
- *
- * @return mixed ID of the new account or PEAR_Error
- */
- function _addAccount($number, $type, $name, $eo, $desc, $closed)
- {
- $accountId = strval(new Horde_Support_Uuid());
-
- $query = sprintf(
- 'INSERT INTO %s (account_id, account_owner, account_number, account_type, ' .
- 'account_name, account_eo, account_desc, account_closed) ' .
- 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
- $this->_params['table_accounts']);
- $values = array($accountId,
- $this->_ledger,
- sprintf('%\'04d', $number),
- $type,
- Horde_String::convertCharset($name, 'UTF-8', $this->_params['charset']),
- (int)(bool)$eo,
- Horde_String::convertCharset($desc, 'UTF-8', $this->_params['charset']),
- (int)(bool)$closed);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_addAccount(): %s', $query), 'DEBUG');
-
- /* Attempt the insertion query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return $accountId;
- }
-
- /**
- * Modifies an existing account.
- *
- * @param string $accountId The account to modify.
- * @param string $number The number of the account.
- * @param string $type The type of the account.
- * @param string $name The name (short) of the account.
- * @param boolean $eo Extraordinary account.
- * @param string $desc The description (long) of the account.
- * @param boolean $closed Close account.
- *
- * @return mixed True or PEAR_Error
- */
- function _modifyAccount($accountId, $number, $type, $name, $eo, $desc, $closed)
- {
- $query = sprintf('UPDATE %s SET' .
- ' account_number = ?, ' .
- ' account_type = ?, ' .
- ' account_name = ?, ' .
- ' account_eo = ?, ' .
- ' account_desc = ?, ' .
- ' account_closed = ? ' .
- 'WHERE account_owner = ? AND account_id = ?',
- $this->_params['table_accounts']);
- $values = array(sprintf('%\'04d', $number),
- $type,
- Horde_String::convertCharset($name, 'UTF-8', $this->_params['charset']),
- (int)(bool)$eo,
- Horde_String::convertCharset($desc, 'UTF-8', $this->_params['charset']),
- (int)(bool)$closed,
- $this->_ledger,
- $accountId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_modifyAccount(): %s', $query), 'DEBUG');
-
- /* Attempt the update query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return true;
- }
-
- /**
- * Deletes an account from the backend.
- *
- * @param string $accountId The account to delete.
- * @param mixed $dsSubaccounts True/false when deleting subaccounts,
- * accountId when shifting subaccounts
- * @param mixed $dsPostings True/false when deleting postings,
- * accountId when shifting postings
- *
- * @return mixed True or PEAR_Error
- */
- function _deleteAccount($accountId, $dsSubaccounts = false, $dsPostings = true)
- {
- /* Get the account's details for use later. */
- $account = $this->getAccount($accountId);
-
- /* Handle subaccounts. */
- if ($dsSubaccounts !== false) {
- /* Delete subaccounts. */
- $parent = (int)($account['number'] / 100) . '%';
- $this->retrieveAccounts(array(array('number', $parent, 'LIKE'),
- array('number', (string)$account['number'], '!=')));
-
- foreach ($this->_accounts as $subaccountId => $subaccount) {
- $delete = $this->_deleteAccount($subaccountId, false, $dsSubaccounts);
- if (is_a($delete, 'PEAR_Error')) {
- return $delete;
- }
- }
- }
-
- /* Handle postings. */
- if ($dsPostings !== false) {
- if ($dsPostings === true) {
- /* Delete account postings. */
- $query = sprintf('DELETE FROM %s WHERE posting_owner = ? AND (posting_asset = ? OR posting_account = ?)',
- $this->_params['table_postings']);
- $values = array($this->_ledger, $accountId, $accountId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_deleteAccount(): %s', $query), 'DEBUG');
-
- /* Attempt the delete query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
- } else {
- /* Shift account postings. */
- $shift = $this->_shiftPostings($accountId, $dsPostings);
- if (is_a($shift, 'PEAR_Error')) {
- return $shift;
- }
- }
- }
-
- /* Delete account. */
- $query = sprintf('DELETE FROM %s WHERE account_owner = ? AND account_id = ?',
- $this->_params['table_accounts']);
- $values = array($this->_ledger, $accountId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_deleteAccount(): %s', $query), 'DEBUG');
-
- /* Attempt the delete query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return true;
- }
-
- /**
- * Build a posting.
- *
- * @param array $row Datasbase row holding posting attributes;
- *
- * @return array The array of posting attributes.
- */
- function _buildPosting($row)
- {
- /* Create a new account based on $row's values. */
- return array('posting_id' => $row['posting_id'],
- 'owner' => $row['posting_owner'],
- 'type' => $row['posting_type'],
- 'date' => $row['posting_date'],
- 'asset' => $row['posting_asset'],
- 'account' => $row['posting_account'],
- 'desc' => Horde_String::convertCharset($row['posting_desc'], $this->_params['charset'], 'UTF-8'),
- 'amount' => $row['posting_amount'],
- 'eo' => (int)(bool)$row['posting_eo']);
- }
-
- /**
- * Adds a posting to the backend storage.
- *
- * @param string $type The posting type.
- * @param integer $date The posting date.
- * @param string $asset The ID of the asset account.
- * @param string $account The ID of the account.
- * @param boolean $eo Extraordinary posting.
- * @param float $amount The posting amount.
- * @param string $desc The posting description.
- *
- * @return mixed ID of the new posting or PEAR_Error
- */
- function _addPosting($type, $date, $asset, $account, $eo, $amount, $desc)
- {
- $postingId = strval(new Horde_Support_Uuid());
-
- $query = sprintf(
- 'INSERT INTO %s (posting_id, posting_owner, posting_type, posting_date, ' .
- 'posting_asset, posting_account, posting_eo, posting_amount, posting_desc) ' .
- 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
- $this->_params['table_postings']);
- $values = array($postingId,
- $this->_ledger,
- $type,
- (int)$date,
- $asset,
- $account,
- (int)(bool)$eo,
- (float)$amount,
- Horde_String::convertCharset($desc, 'UTF-8', $this->_params['charset']));
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_addPosting(): %s', $query), 'DEBUG');
-
- /* Attempt the insertion query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return $postingId;
- }
-
- /**
- * Modifies an existing posting.
- *
- * @param string $postingId The posting to modify.
- * @param string $type The posting type.
- * @param integer $date The posting date.
- * @param string $asset The ID of the asset account.
- * @param string $account The ID of the account.
- * @param boolean $eo Extraordinary posting.
- * @param float $amount The posting amount.
- * @param string $desc The posting description.
- *
- * @return mixed True or PEAR_Error
- */
- function _modifyPosting($postingId, $type, $date, $asset, $account, $eo, $amount, $desc)
- {
- $query = sprintf('UPDATE %s SET' .
- ' posting_type = ?, ' .
- ' posting_date = ?, ' .
- ' posting_asset = ?, ' .
- ' posting_account = ?, ' .
- ' posting_eo = ?, ' .
- ' posting_amount = ?, ' .
- ' posting_desc = ? ' .
- 'WHERE posting_owner = ? AND posting_id = ?',
- $this->_params['table_postings']);
- $values = array($type,
- (int)$date,
- $asset,
- $account,
- (int)(bool)$eo,
- (float)$amount,
- Horde_String::convertCharset($desc, 'UTF-8', $this->_params['charset']),
- $this->_ledger,
- $postingId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_modifyPosting(): %s', $query), 'DEBUG');
-
- /* Attempt the update query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return true;
- }
-
- /**
- * Deletes a posting from the backend.
- *
- * @param string $postingId The posting to delete.
- *
- * @return mixed True or PEAR_Error
- */
- function _deletePosting($postingId)
- {
- /* Get the task's details for use later. */
- $posting = $this->getPosting($postingId);
-
- $query = sprintf('DELETE FROM %s WHERE posting_owner = ? AND posting_id = ?',
- $this->_params['table_postings']);
- $values = array($this->_ledger, $postingId);
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_deletePosting(): %s', $query), 'DEBUG');
-
- /* Attempt the delete query. */
- $result = $this->_db->query($query, $values);
-
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return true;
- }
-
- /**
- * Shift an existing posting.
- *
- * @param string $postingId The posting to shift.
- * @param string $type The posting type shifting to.
- * @param string $asset The ID of the asset account.
- * @param string $account The ID of the account.
- *
- * @return mixed True or PEAR_Error
- */
- function _shiftPosting($postingId, $type, $asset, $account)
- {
- if (!$type && !$asset && !$account) {
- return true;
- }
-
- $query = sprintf('UPDATE %s SET' .
- ($type ? ' posting_type = ?, ' : '') .
- ($asset ? ' posting_asset = ?, ' : '') .
- ($account ? ' posting_account = ?, ' : '').
- ' posting_eo = posting_eo ' .
- 'WHERE posting_owner = ? AND posting_id = ?',
- $this->_params['table_postings']);
- $values = array();
- if ($type) { $values[] = $type; }
- if ($asset) { $values[] = $asset; }
- if ($account) { $values[] = $account; }
- $values[] = $this->_ledger;
- $values[] = $postingId;
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_shiftPosting(): %s', $query), 'DEBUG');
-
- /* Attempt the update query. */
- $result = $this->_db->query($query, $values);
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
-
- return true;
- }
-
- /**
- * Shift postings in the backend.
- *
- * @param mixed $accountIdFrom The account(s) to shift postings from.
- * @param string $accountIdTo The account to shift postings to.
- *
- * @return mixed True or PEAR_Error
- */
- function _shiftPostings($accountIdFrom, $accountIdTo)
- {
- if (!is_array($accountIdFrom)) {
- $accountIdFrom = array($accountIdFrom);
- }
-
- foreach ($accountIdFrom as $key => $value) {
- $accountIdFrom[$key] = $this->_db->quoteSmart($value);
- }
-
- $fields = array('posting_asset', 'posting_account');
- foreach ($fields as $field) {
- $query = sprintf('UPDATE %s SET' .
- ' %s = ? ' .
- 'WHERE posting_owner = ? AND %s IN (!)',
- $this->_params['table_postings'], $field, $field);
- $values = array($accountIdTo, $this->_ledger, implode(',', $accountIdFrom));
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_shiftPostings(): %s', $query), 'DEBUG');
-
- /* Attempt the update query. */
- $result = $this->_db->query($query, $values);
-
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
- }
-
- return true;
- }
-
- /**
- * Deletes all postings and accounts.
- *
- * @param mixed $accounts boolean or account_type
- * @param mixed $accounts boolean or posting_type.
- *
- * @return mixed True or PEAR_Error
- */
- function _deleteAll($accounts, $postings)
- {
- /* Delete postings. */
- if ($postings) {
- $query = sprintf('DELETE FROM %s WHERE posting_owner = ?',
- $this->_params['table_postings']);
- $values = array($this->_ledger);
-
- /* Filter. */
- if ($postings !== true) {
- $query .= ' AND posting_type = ?';
- $values[] = $postings;
- }
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_deleteAll(): %s', $query), 'DEBUG');
-
- /* Attempt the delete query. */
- $result = $this->_db->query($query, $values);
-
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
- } else {
- /* If postings aren't deleted, don't delete accounts. */
- return false;
- }
-
- /* Delete Accounts */
- if ($accounts) {
- $query = sprintf('DELETE FROM %s WHERE account_owner = ?',
- $this->_params['table_accounts']);
- $values = array($this->_ledger);
-
- /* Filter. */
- if ($accounts !== true) {
- $query .= ' AND account_type = ?';
- $values[] = $accounts;
- }
-
- /* Log the query at a DEBUG log level. */
- Horde::logMessage(sprintf('Fima_Driver_sql::_deleteAll(): %s', $query), 'DEBUG');
-
- /* Attempt the delete query. */
- $result = $this->_db->query($query, $values);
-
- if (is_a($result, 'PEAR_Error')) {
- Horde::logMessage($result, 'ERR');
- return $result;
- }
- }
-
- return true;
- }
-
-
- /**
- * Build the where clause for a query using the passed filters
- * Attention: does not include the WHERE keyword, add WHERE 1=1 manually in the query
- *
- * @param array $filters Array of filters, syntax: array(field, value [, operator = '=' [, andor = 'AND']])
- * @param array $prefix optional prefix for fields
- *
- * @return integer number of added filters
- */
- function _addFilters($filters, &$query, &$values, $prefix = '')
- {
- $filtercnt = 0;
-
- foreach ($filters as $filter) {
- // and/or
- if (!isset($filter[3])) {
- $filter[3] = 'AND';
- } else {
- $filter[3] = strtoupper($filter[3]);
- if (!in_array($filter[3], array('AND', 'OR'))) {
- $filter[3] = 'AND';
- }
- }
-
- // subfilter
- if (is_array($filter[0])) {
- $query .= ' ' . $filter[3] . ' (1=1';
- $filtercnt += $this->_addFilters($filter[0], $query, $values, $prefix);
- $query .= ')';
- continue;
- }
-
- // fix operator
- if (!isset($filter[2])) {
- $filter[2] = '=';
- } else {
- $filter[2] = strtoupper($filter[2]);
- if (!in_array($filter[2], array('<', '>', '<=', '>=', '=', '<>', '!=', 'IN', 'NOT IN', 'IS', 'IS NOT', 'LIKE', 'NOT LIKE'))) {
- $filter[2] = '=';
- }
- }
-
- // fix operator for null values
- if ($filter[1] === null) {
- if (!in_array($filter[2], array('IS', 'IS NOT'))) {
- $filter[2] = in_array($filter[2], array('=', 'IN', 'LIKE')) ? 'IS' : 'IS NOT';
- }
- } elseif (in_array($filter[2], array('IS', 'IS NOT'))) {
- $filter[2] = ($filter[2] == 'IS') ? '=' : '!=';
- }
-
- // fix operator for array value + prepare values
- if (is_array($filter[1])) {
- if (!in_array($filter[2], array('IN', 'NOT IN'))) {
- $filter[2] = in_array($filter[2], array('=', 'IS', 'LIKE')) ? 'IN' : 'NOT IN';
- }
- $filterph = '(!)';
- foreach ($filter[1] as $key => $value) {
- $filter[1][$key] = $this->_db->quoteSmart($value);
- }
- $filter[1] = implode(',', $filter[1]);
- } else {
- if (in_array($filter[2], array('IN', 'NOT IN'))) {
- $filter[2] = ($filter[2] == 'IN') ? '=' : '!=';
- }
- $filterph = '?';
- }
-
- // fix != operator
- if ($filter[2] == '!=') {
- $filter[2] = '<>';
- }
-
- $query .= sprintf(' ' . $filter[3] . ' ' . $prefix . '%s %s %s', $filter[0], $filter[2], $filterph);
- $values[] = $filter[1];
- $filtercnt++;
- }
-
- return $filtercnt;
- }
-
- /**
- * Attempts to open a connection to the SQL server.
- *
- * @return boolean True on success; PEAR_Error on failure.
- */
- function initialize()
- {
- try {
- $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'fima', 'storage');
- } catch (Horde_Exception $e) {
- return PEAR::raiseError($e->getMessage());
- }
-
- return true;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Copyright 2008 Thomas Trethan <thomas@trethan.net>
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Thomas Trethan <thomas@trethan.net>
- */
-
-@define('FIMA_BASE', dirname(__FILE__));
-require_once FIMA_BASE . '/lib/base.php';
-
-$vars = Horde_Variables::getDefaultVariables();
-
-/* Get the current action ID. */
-$actionID = Horde_Util::getFormData('actionID');
-
-/* Change posting type. */
-if (($postingtype = Horde_Util::getFormData('postingtype')) !== null) {
- $postingtypeold = $prefs->getValue('active_postingtype');
- $prefs->setValue('active_postingtype', $postingtype);
-}
-
-/* Get closed period. */
-$closedperiod = (int)$prefs->getValue('closed_period');
-
-/* Create page array. */
-$pageOb = array();
-$pageOb['url'] = Horde::url('postings.php');
-if (($pageOb['page'] = Horde_Util::getFormData('page')) === null) {
- $pageOb['page'] = $prefs->getValue('startpage');
-}
-$pageOb['mode'] = 'list';
-
-$title = _("My Postings");
-$ledger = Fima::getActiveLedger();
-$filters = array();
-
-switch ($actionID) {
-case 'change_sort':
- /* Sort out the sorting values. */
- if (($sortby = Horde_Util::getFormData('sortby')) !== null) {
- $prefs->setValue('sortby', $sortby);
- }
- if (($sortdir = Horde_Util::getFormData('sortdir')) !== null) {
- $prefs->setValue('sortdir', $sortdir);
- }
- break;
-
-case 'search_postings':
- /* If we're searching, only list those postings that match the search result. */
- $_SESSION['fima_search'] = array('type' => Horde_Util::getFormData('search_type'),
- 'date_start' => Horde_Util::getFormData('search_date_start'),
- 'date_end' => Horde_Util::getFormData('search_date_end'),
- 'asset' => Horde_Util::getFormData('search_asset'),
- 'account' => Horde_Util::getFormData('search_account'),
- 'desc' => Horde_Util::getFormData('search_desc'),
- 'amount_start' => Horde_Util::getFormData('search_amount_start'),
- 'amount_end' => Horde_Util::getFormData('search_amount_end'),
- 'eo' => Horde_Util::getFormData('search_eo'));
-
- /* Build filters. */
- if ($_SESSION['fima_search']['type'] !== null) {
- $prefs->setValue('active_postingtype', $_SESSION['fima_search']['type']);
- }
- if ($_SESSION['fima_search']['date_start'] !== null) {
- if (is_array($_SESSION['fima_search']['date_start'])) {
- $_SESSION['fima_search']['date_start'] = mktime(0, 0, 0, $_SESSION['fima_search']['date_start']['month'],
- $_SESSION['fima_search']['date_start']['day'],
- $_SESSION['fima_search']['date_start']['year']);
- } else {
- $_SESSION['fima_search']['date_start'] = (int)$_SESSION['fima_search']['date_start'];
- }
- }
- if ($_SESSION['fima_search']['date_end'] !== null) {
- if (is_array($_SESSION['fima_search']['date_end'])) {
- $_SESSION['fima_search']['date_end'] = mktime(0, 0, 0, $_SESSION['fima_search']['date_end']['month'],
- $_SESSION['fima_search']['date_end']['day'],
- $_SESSION['fima_search']['date_end']['year']);
- } else {
- $_SESSION['fima_search']['date_end'] = (int)$_SESSION['fima_search']['date_end'];
- }
- }
- if ($_SESSION['fima_search']['asset'] !== null) {
- if (count($_SESSION['fima_search']['asset']) == 0) {
- unset($_SESSION['fima_search']['asset']);
- }
- }
- if ($_SESSION['fima_search']['account'] !== null) {
- if (count($_SESSION['fima_search']['account']) == 0) {
- unset($_SESSION['fima_search']['account']);
- }
- }
- if ($_SESSION['fima_search']['desc'] !== null) {
- if ($_SESSION['fima_search']['desc'] === '') {
- unset($_SESSION['fima_search']['desc']);
- }
- }
- if ($_SESSION['fima_search']['amount_start'] !== null) {
- if ($_SESSION['fima_search']['amount_start'] === '') {
- unset($_SESSION['fima_search']['amount_start']);
- }
- }
- if ($_SESSION['fima_search']['amount_end'] !== null) {
- if ($_SESSION['fima_search']['amount_end'] === '') {
- unset($_SESSION['fima_search']['amount_end']);
- }
- }
- if (isset($_SESSION['fima_search']['amount_start']) && isset($_SESSION['fima_search']['amount_end'])) {
- if ((double)$_SESSION['fima_search']['amount_start'] > (double)$_SESSION['fima_search']['amount_end']) {
- $tmp = $_SESSION['fima_search']['amount_start'];
- $_SESSION['fima_search']['amount_start'] = $_SESSION['fima_search']['amount_end'];
- $_SESSION['fima_search']['amount_end'] = $tmp;
- }
- }
- if ($_SESSION['fima_search']['eo'] !== null) {
- if ($_SESSION['fima_search']['eo'] == -1) {
- unset($_SESSION['fima_search']['eo']);
- }
- }
-
- break;
-
-case 'clear_search':
- unset($_SESSION['fima_search']);
- break;
-
-case 'add_postings':
- $pageOb['mode'] = 'edit';
- $pageOb['url'] = Horde_Util::addParameter($pageOb['url'], 'actionID', 'add_postings');
- $actionID = 'save_postings';
- $postings = array();
- $title = _("Add Postings");
- break;
-
-case 'edit_postings':
- $postingset = Horde_Util::getFormData('indices');
- if ($postingset !== null) {
- $pageOb['mode'] = 'edit';
- $pageOb['url'] = Horde_Util::addParameter($pageOb['url'], 'actionID', 'add_postings');
- $actionID = 'save_postings';
- $filters[] = array('id', $postingset);
- $title = _("Edit Postings");
- }
- break;
-
-case 'shift_postings':
- $postingset = Horde_Util::getFormData('indices');
- if ($postingset !== null) {
- $pageOb['mode'] = 'shift';
- $actionID = 'update_postings';
- $filters[] = array('id', $postingset);
- $title = _("Shift Postings");
- }
- break;
-
-case 'transfer_postings':
- $pageOb['mode'] = 'transfer';
- $actionID = 'copymove_postings';
- $postings = array();
- $title = _("Transfer Postings");
- break;
-
-case 'save_postings':
- /* Get the form values. */
- $postingset = Horde_Util::getFormData('posting_id');
-
- $share = &$GLOBALS['fima_shares']->getShare($ledger);
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
- $notification->push(sprintf(_("Access denied saving postings to %s."), $share->get('name')), 'horde.error');
- Horde::url('postings.php', true)->redirect();
- }
- if ($postingset !== null) {
- $pageOb['mode'] = 'edit';
- $title = _("Edit Postings");
- $posting_owner = $ledger;
- $posting_type = $prefs->getValue('active_postingtype');
-
- $posting_dates = Horde_Util::getFormData('date');
- $posting_assets = Horde_Util::getFormData('asset');
- $posting_accounts = Horde_Util::getFormData('account');
- $posting_eos = Horde_Util::getFormData('eo');
- $posting_amounts = Horde_Util::getFormData('amount');
- $posting_descs = Horde_Util::getFormData('desc');
-
- $postings = array();
- $savecount = 0;
-
- $storage = &Fima_Driver::singleton($ledger);
- foreach($postingset as $index => $posting_id) {
- $posting_valid = true;
-
- if ($posting_dates[$index] !== '' || $posting_assets[$index] !== '' || $posting_accounts[$index] !== '' ||
- $posting_amounts[$index] !== '' || $posting_descs[$index] !== '') {
-
- $posting_date = Fima::convertDateToStamp($posting_dates[$index], Fima::convertDateFormat($prefs->getValue('date_format')));
- $posting_asset = $posting_assets[$index];
- $posting_account = $posting_accounts[$index];
- $posting_eo = (int)(bool)$posting_eos[$index];
- $posting_amount = Fima::convertAmountToValue($posting_amounts[$index]);
- $posting_desc = $posting_descs[$index];
-
- /* Check posting date. */
- if ($posting_date === false) {
- $posting_valid = false;
- } elseif ($posting_date <= $closedperiod) {
- $posting_valid = false;
- }
-
- /* Check asset account and account. */
- if ($posting_asset === '' || $posting_account === '') {
- $posting_valid = false;
- } elseif ($posting_asset === $posting_account) {
- continue;
- }
-
- /* Fix amount sign. */
- if ($prefs->getValue('expenses_sign') == 0) {
- $account = Fima::getAccount($posting_account);
- if (!is_a($account, 'PEAR_Error') && $account !== null) {
- if ($account['type'] == FIMA_ACCOUNTTYPE_EXPENSE) {
- $posting_amount *= -1;
- }
- }
- }
-
- /* If $posting_id is set, we're modifying an existing account. Otherwise,
- * we're adding a new posting with the provided attributes. */
- if ($posting_valid) {
- if ($posting_id != null) {
- $result = $storage->modifyPosting($posting_id, $posting_type, $posting_date, $posting_asset,
- $posting_account, $posting_eo, $posting_amount, $posting_desc);
- } else {
- $result = $storage->addPosting($posting_type, $posting_date, $posting_asset, $posting_account,
- $posting_eo, $posting_amount, $posting_desc);
- }
-
- // Check our results.
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem saving the posting: %s."), $result->getMessage()), 'horde.error');
- $posting_valid = false;
- } else {
- $savecount++;
- }
- }
-
- /* Reload invalid or unsaved postings. */
- if (!$posting_valid) {
- $postings[] = array('posting_id' => $posting_id,
- 'owner' => $ledger,
- 'type' => $posting_type,
- 'date' => $posting_date,
- 'asset' => $posting_asset,
- 'account' => $posting_account,
- 'eo' => $posting_eo,
- 'amount' => $posting_amount,
- 'desc' => $posting_desc);
- }
- }
- }
-
- if ($savecount > 0) {
- $notification->push(sprintf(_("Saved %d postings."), $savecount), 'horde.success');
- }
- if (count($postings) > 0) {
- $notification->push(sprintf(_("%d postings not saved."), count($postings)), 'horde.error');
- } else {
- /* Return to the posting list. */
- Horde::url('postings.php', true)->redirect();
- }
- } else {
- /* Return to the posting list. */
- Horde::url('postings.php', true)->redirect();
- }
- break;
-
-case 'delete_postings':
- /* Delete postings if we're provided with valid account IDs. */
- $postingset = Horde_Util::getFormData('indices');
-
- $share = &$GLOBALS['fima_shares']->getShare($ledger);
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
- $notification->push(sprintf(_("Access denied deleting postings from %s."), $share->get('name')), 'horde.error');
- Horde::url('postings.php', true)->redirect();
- }
- if ($postingset !== null) {
- $storage = &Fima_Driver::singleton($ledger);
- $delcount = 0;
- foreach($postingset as $index => $posting_id) {
- $result = $storage->deletePosting($posting_id);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem deleting posting #%d: %s"),
- $index, $result->getMessage()), 'horde.error');
- } else {
- $delcount++;
- }
- }
- if ($delcount > 0) {
- $notification->push(sprintf(_("Deleted %d postings."), $delcount), 'horde.success');
- }
- }
-
- /* Return to the posting list. */
- Horde::url('postings.php', true)->redirect();
-
-case 'update_postings':
- /* Get the form values. */
- $postingset = Horde_Util::getFormData('posting_id');
-
- $share = &$GLOBALS['fima_shares']->getShare($ledger);
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
- $notification->push(sprintf(_("Access denied shifting postings in %s."), $share->get('name')), 'horde.error');
- Horde::url('postings.php', true)->redirect();
- }
- if ($postingset !== null) {
- $posting_type = Horde_Util::getFormData('type');
- $posting_asset = Horde_Util::getFormData('asset');
- $posting_account = Horde_Util::getFormData('account');
-
- if ($posting_type || $posting_asset || $posting_account) {
- $storage = &Fima_Driver::singleton($ledger);
- $shiftcount = 0;
-
- foreach($postingset as $index => $posting_id) {
- $result = $storage->ShiftPosting($posting_id, $posting_type, $posting_asset, $posting_account);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem shifting posting #%d: %s"),
- $index, $result->getMessage()), 'horde.error');
- } else {
- $shiftcount++;
- }
- }
- if ($shiftcount > 0) {
- $notification->push(sprintf(_("Shifted %d postings."), $shiftcount), 'horde.success');
- }
- }
- }
-
- /* Return to the posting list. */
- Horde::url('postings.php', true)->redirect();
-
-case 'copymove_postings':
- $share = &$GLOBALS['fima_shares']->getShare($ledger);
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
- $notification->push(sprintf(_("Access denied transfering postings in %s."), $share->get('name')), 'horde.error');
- Horde::url('postings.php', true)->redirect();
- }
- if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE) && (!Horde_Util::getFormData('keep') || Horde_Util::getFormData('delete'))) {
- $notification->push(sprintf(_("Access denied transfering postings in %s."), $share->get('name')), 'horde.error');
- Horde::url('postings.php', true)->redirect();
- }
- $type_from = Horde_Util::getFormData('type_from');
- $period_from = Horde_Util::getFormData('period_from');
- $keep = Horde_Util::getFormData('keep');
- $summarize = Horde_Util::getFormData('summarize');
- $summarize_account = Horde_Util::getFormData('summarize_post_account');
- $type_to = Horde_Util::getFormData('type_to');
- $period_to = Horde_Util::getFormData('period_to');
- $delete = Horde_Util::getFormData('delete');
-
- $period_from_start = mktime(0, 0, 0, ($period_from['month'] === '') ? 1 : $period_from['month'], 1, (int)$period_from['year']);
- $period_from_end = mktime(0, 0, 0, ($period_from['month'] === '') ? 12 : $period_from['month'] + 1, ($period_from['month'] === '') ? 31 : 0, (int)$period_from['year']);
- $period_to_start = mktime(0, 0, 0, ($period_to['month'] === '') ? 1 : $period_to['month'], 1, (int)$period_to['year']);
- $period_to_end = mktime(0, 0, 0, ($period_to['month'] === '') ? 12 : $period_to['month'] + 1, ($period_to['month'] === '') ? 31 : 0, (int)$period_to['year']);
-
- $storage = &Fima_Driver::singleton($ledger);
-
- /* Delete existing. */
- if ($delete) {
- $transferfilters = array(array('type', $type_to),
- array('date', $period_to_start, '>='),
- array('date', $period_to_end, '<='));
- $postings = Fima::listPostings($transferfilters);
- $delcount = 0;
- foreach ($postings as $postingId => $posting) {
- $result = $storage->deletePosting($postingId);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem deleting an existing posting: %s"),
- $result->getMessage()), 'horde.error');
- } else {
- $delcount++;
- }
- }
- if ($delcount > 0) {
- $notification->push(sprintf(_("Deleted %d existing postings."), $delcount), 'horde.success');
- }
- }
-
- /* Copy postings. */
- $transferfilters = array(array('type', $type_from),
- array('date', $period_from_start, '>='),
- array('date', $period_from_end, '<='));
- $postings = Fima::listPostings($transferfilters);
-
- if ($summarize != 'none') {
- $accounts = Fima::listAccounts();
- $postingscopy = array();
-
- foreach ($postings as $postingId => $posting) {
- $asset = (isset($accounts[$posting['asset']]))
- ? (($accounts[$posting['asset']]['parent_id'] !== null) ? $accounts[$posting['asset']]['parent_id'] : $accounts[$posting['asset']]['account_id'])
- : $posting['asset'];
- $account = (isset($accounts[$posting['account']]))
- ? (($accounts[$posting['account']]['parent_id'] !== null) ? $accounts[$posting['account']]['parent_id'] : $accounts[$posting['account']]['account_id'])
- : $posting['account'];
-
- if ($summarize == 'combine') {
- $copyId = $asset . '_' . $account . '_' . strftime('%Y%m', $posting['date']);
-
- if (isset($postingscopy[$copyId])) {
- $postingscopy[$copyId]['amount'] += $posting['amount'];
- } else {
- $postingscopy[$copyId] = $posting;
- $postingscopy[$copyId]['date'] = mktime(0, 0, 0, ($period_to['month'] === '') ? strftime('%m', $posting['date']) : $period_to['month'], 1, (int)$period_to['year']);
- $postingscopy[$copyId]['asset'] = $asset;
- $postingscopy[$copyId]['account'] = $account;
- $postingscopy[$copyId]['eo'] = 0;
- $postingscopy[$copyId]['desc'] = _("Summarized");
- }
- } elseif ($summarize == 'post') {
- $copyIdAsset = $asset . '_' . strftime('%Y%m', $posting['date']);
- $copyIdAccount = $account . '_' . strftime('%Y%m', $posting['date']);
-
- if (isset($postingscopy[$copyIdAsset])) {
- $postingscopy[$copyIdAsset]['amount'] += $posting['amount'];
- } else {
- $postingscopy[$copyIdAsset] = $posting;
- $postingscopy[$copyIdAsset]['date'] = mktime(0, 0, 0, ($period_to['month'] === '') ? strftime('%m', $posting['date']) : $period_to['month'], 1, (int)$period_to['year']);
- $postingscopy[$copyIdAsset]['asset'] = $asset;
- $postingscopy[$copyIdAsset]['account'] = $summarize_account;
- $postingscopy[$copyIdAsset]['eo'] = 0;
- $postingscopy[$copyIdAsset]['desc'] = _("Summarized");
- }
-
- if (isset($postingscopy[$copyIdAccount])) {
- $postingscopy[$copyIdAccount]['amount'] += $posting['amount'];
- } else {
- $postingscopy[$copyIdAccount] = $posting;
- $postingscopy[$copyIdAccount]['date'] = mktime(0, 0, 0, ($period_to['month'] === '') ? strftime('%m', $posting['date']) : $period_to['month'], 1, (int)$period_to['year']);
- $postingscopy[$copyIdAccount]['asset'] = $summarize_account;
- $postingscopy[$copyIdAccount]['account'] = $account;
- $postingscopy[$copyIdAccount]['eo'] = 0;
- $postingscopy[$copyIdAccount]['desc'] = _("Summarized");
- }
- }
- }
- } else {
- $postingscopy = &$postings;
- foreach ($postingscopy as $postingId => $posting) {
- $postingscopy[$postingId]['date'] = mktime(0, 0, 0, ($period_to['month'] === '') ? strftime('%m', $posting['date']) : $period_to['month'], strftime('%d', $posting['date']), (int)$period_to['year']);
- }
- }
-
- $addcount = 0;
- foreach ($postingscopy as $postingId => $posting) {
- $result = $storage->addPosting($type_to, $posting['date'], $posting['asset'], $posting['account'],
- $posting['eo'], $posting['amount'], $posting['desc']);
-
- // Check our results.
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem saving the posting: %s."), $result->getMessage()), 'horde.error');
- } else {
- $addcount++;
- }
- }
- if ($addcount > 0) {
- $notification->push(sprintf($summarize ? _("Summarized %d postings.") : _("Transfered %d postings."), $addcount), 'horde.success');
- }
-
- /* Delete original postings. */
- if (!$keep) {
- $delcount = 0;
- foreach ($postings as $postingId => $posting) {
- $result = $storage->deletePosting($postingId);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("There was a problem deleting an original posting: %s"),
- $result->getMessage()), 'horde.error');
- } else {
- $delcount++;
- }
- }
- if ($delcount > 0) {
- $notification->push(sprintf(_("Deleted %d original postings."), $delcount), 'horde.success');
- }
- }
-
- /* Return to the posting list. */
- Horde::url('postings.php', true)->redirect();
-
-default:
- break;
-}
-
-/* Print. */
-$print_view = (bool)Horde_Util::getFormData('print');
-if (!$print_view && $pageOb['mode'] == 'list') {
- $print_link = Horde_Util::addParameter(Horde::url('postings.php'), array('print' => 1));
-}
-
-/* Filters. */
-$postingtype = $prefs->getValue('active_postingtype');
-$filters[] = array('type', $postingtype);
-if (isset($_SESSION['fima_search'])) {
- $title = _("Search Results");
- foreach ($_SESSION['fima_search'] as $searchId => $search) {
- if ($search === null) {
- continue;
- }
- switch ($searchId) {
- case 'date_start': $filters[] = array('date', $search, '>='); break;
- case 'date_end': $filters[] = array('date', $search, '<='); break;
- case 'asset': $filters[] = array(array(array('asset', $search), array('account', $search, '=', 'OR'))); break;
- case 'account': $filters[] = array('account', $search); break;
- case 'desc': $filters[] = array('desc', Fima::convertWildcards($search), 'LIKE'); break;
- case 'amount_start': $filters[] = array('amount', Fima::convertAmountToValue($search), '>='); break;
- case 'amount_end': $filters[] = array('amount', Fima::convertAmountToValue($search), '<='); break;
- case 'eo': $filters[] = array('eo', (int)(bool)$search);
- default: break;
- }
- }
-}
-
-/* Retrieve accounts, accounttypes and postings (if not set before). */
-$accounts = Fima::listAccounts();
-$accounttypes = Fima::getAccountTypes();
-if (!isset($postings)) {
- $postings = Fima::listPostings($filters, ($pageOb['mode'] != 'list' || $print_view) ? null : $pageOb['page']);
-}
-
-$pageOb['postings_perpage'] = $prefs->getValue('max_postings');
-$pageOb['postings_total'] = Fima::getPostingsCount();
-
-if ($pageOb['mode'] == 'edit') {
- /* Fix amount sign. */
- if ($prefs->getValue('expenses_sign') == 0) {
- foreach ($postings as $postingId => $posting) {
- if ($accounts[$posting['account']]['type'] == FIMA_ACCOUNTTYPE_EXPENSE) {
- $postings[$postingId]['amount'] *= -1;
- }
- }
- }
- /* Add blank postings. */
- for ($i = count($postings); $i < max($pageOb['postings_perpage'], 12); $i++) {
- $postings[] = array('posting_id' => null,
- 'owner' => $ledger,
- 'type' => $postingtype,
- 'date' => null,
- 'asset' => null,
- 'account' => null,
- 'eo' => null,
- 'amount' => null,
- 'desc' => null);
- }
-}
-
-/* Add account information to postings and create flags list. */
-if ($pageOb['mode'] == 'list') {
- $flags = array();
- foreach ($postings as $postingId => $posting) {
- $postings[$postingId]['desc'] = htmlspecialchars($posting['desc']);
-
- if (isset($accounts[$posting['asset']])) {
- $postings[$postingId]['asset_label'] = htmlspecialchars($accounts[$posting['asset']]['label']);
- $postings[$postingId]['asset_closed'] = $accounts[$posting['asset']]['closed'];
- } else {
- $postings[$postingId]['asset_label'] = _("Unknown");
- $postings[$postingId]['asset_closed'] = false;
- }
- if (isset($accounts[$posting['account']])) {
- $postings[$postingId]['account_label'] = htmlspecialchars($accounts[$posting['account']]['label']);
- $postings[$postingId]['account_type'] = $accounts[$posting['account']]['type'];
- $postings[$postingId]['account_type_eo'] = sprintf($posting['eo'] ? _("e.o. %s") : _("%s") , $accounttypes[$accounts[$posting['account']]['type']]);
- $postings[$postingId]['account_closed'] = $accounts[$posting['account']]['closed'];
- } else {
- $postings[$postingId]['account_label'] = _("Unknown");
- $postings[$postingId]['account_type'] = '';
- $postings[$postingId]['account_type_eo'] = '';
- $postings[$postingId]['account_closed'] = false;
- }
-
- $flag = 0;
- $flagpos = 0;
- foreach ($accounttypes as $typeId => $typeLabel) {
- if ($postings[$postingId]['account_type'] == $typeId) {
- $flag |= pow(2, $flagpos);
- }
- $flagpos++;
- }
- $flags[] = $flag;
- }
-}
-
-/* Set up page information. */
-$pageOb['page_count'] = ceil($pageOb['postings_total'] / $pageOb['postings_perpage']);
-if ($pageOb['page'] < 0) {
- $pageOb['page'] += $pageOb['page_count'] + 1;
-}
-if ($pageOb['mode'] == 'list') {
- if ($pageOb['postings_total'] == 0) {
- $pageOb['postings_count'] = _("No Postings");
- } else {
- $pageOb['postings_count'] = sprintf(_("%s to %s of %s Postings"),
- ($pageOb['page'] - 1) * $pageOb['postings_perpage'] + 1,
- min($pageOb['page'] * $pageOb['postings_perpage'], $pageOb['postings_total']),
- $pageOb['postings_total']);
- }
-}
-
-/* Get sorting. */
-if ($pageOb['mode'] == 'list' || $pageOb['mode'] == 'edit') {
- $sortby = $prefs->getValue('sortby');
- $sortdir = $prefs->getValue('sortdir');
- $sorturl = Horde_Util::addParameter($pageOb['url'], 'sortdir', ($sortdir) ? 0 : 1);
-}
-
-/* Generate page links. */
-if ($pageOb['mode'] == 'list') {
- $graphicsdir = Horde_Themes::img(null, 'horde');
- if ($pageOb['page'] == 1) {
- $pageOb['pages_first'] = Horde::img('nav/first-grey.png', null, null, $graphicsdir);
- $pageOb['pages_prev'] = Horde::img('nav/left-grey.png', null, null, $graphicsdir);
- } else {
- $first_url = Horde_Util::addParameter($pageOb['url'], 'page', 1);
- $pageOb['pages_first'] = Horde::link($first_url, _("First Page")) . Horde::img('nav/first.png', '<<', null, $graphicsdir) . '</a>';
- $prev_url = Horde_Util::addParameter($pageOb['url'], 'page', $pageOb['page'] - 1);
- $pageOb['pages_prev'] = Horde::link($prev_url, _("Previous Page"), '', '', '', '', '', array('id' => 'prev')) . Horde::img('nav/left.png', '<', null, $graphicsdir) . '</a>';
- }
- if ($pageOb['page'] == $pageOb['page_count']) {
- $pageOb['pages_last'] = Horde::img('nav/last-grey.png', null, null, $graphicsdir);
- $pageOb['pages_next'] = Horde::img('nav/right-grey.png', null, null, $graphicsdir);
- } else {
- $next_url = Horde_Util::addParameter($pageOb['url'], 'page', $pageOb['page'] + 1);
- $pageOb['pages_next'] = Horde::link($next_url, _("Next Page"), '', '', '', '', '', array('id' => 'next')) . Horde::img('nav/right.png', '>', null, $graphicsdir) . '</a>';
- $last_url = Horde_Util::addParameter($pageOb['url'], 'page', $pageOb['page_count']);
- $pageOb['pages_last'] = Horde::link($last_url, _("Last Page")) . Horde::img('nav/last.png', '>>', null, $graphicsdir) . '</a>';
- }
-}
-
-/* Some browsers have trouble with hidden overflow in table cells but not in divs. */
-if ($GLOBALS['browser']->hasQuirk('no_hidden_overflow_tables')) {
- $overflow_begin = '<div class="ohide">';
- $overflow_end = '</div>';
-} else {
- $overflow_begin = '';
- $overflow_end = '';
-}
-
-/* Set up row Ids. */
-$rowId = 0;
-
-/* Get date and amount format. */
-$datefmt = $prefs->getValue('date_format');
-$amountfmt = $prefs->getValue('amount_format');
-
-$js_onload = array();
-
-if ($pageOb['mode'] == 'edit') {
- /* Fix date format. */
- $datefmt = Fima::convertDateFormat($datefmt);
-
- /* Add current date in first field if no postings. */
- foreach ($postings as $key => $value) {
- if ($value['date'] == '') {
- $js_onload[] = '$("date1").setValue(' . Horde_Serialize::serialize(strftime($datefmt), Horde_Serialize::JSON) . ')';
- }
- break;
- }
-
- /* Select first date field. */
- $js_onload[] = 'updateResult()';
- $js_onload[] = 'updateAssetResult(_getall("asset[]")[0])';
- $js_onload[] = '$("date1").focus().select()';
-}
-
-Horde::addInlineScript($js_onload, 'dom');
-
-require FIMA_TEMPLATES . '/common-header.inc';
-if ($print_view) {
- require_once $registry->get('templates', 'horde') . '/javascript/print.js';
-} else {
- require FIMA_TEMPLATES . '/menu.inc';
-}
-if ($browser->hasFeature('javascript')) {
- require FIMA_TEMPLATES . '/postings/javascript_' . $pageOb['mode'] . '.inc';
-}
-
-/* Get current asset results. */
-if ($pageOb['mode'] == 'edit') {
- $assetresults = Fima::getAssetResults($prefs->getValue('active_postingtype'));
-}
-
-/* Generate tabs. */
-if ($pageOb['mode'] != 'transfer' && !$print_view) {
- $tabs = new Horde_Core_Ui_Tabs('postingtype', $vars);
- $postingtypes = Fima::getPostingTypes();
- foreach ($postingtypes as $typeValue => $typeLabel) {
- $tabs->addTab($typeLabel, $pageOb['url'], $typeValue);
- }
- echo $tabs->render($prefs->getValue('active_postingtype'));
-}
-
-/* Generate list. */
-if (!$print_view) {
- require FIMA_TEMPLATES . '/postings/header.inc';
-}
-
-if ($pageOb['mode'] == 'list' && $pageOb['page_count'] == 0) {
- require FIMA_TEMPLATES . '/postings/empty.inc';
-} else {
- $form = 1;
- if (!$print_view) {
- require FIMA_TEMPLATES . '/postings/navbar.inc';
- require FIMA_TEMPLATES . '/postings/actions.inc';
- }
-
- require FIMA_TEMPLATES . '/postings/posting_headers.inc';
- require FIMA_TEMPLATES . '/postings/' . $pageOb['mode'] . '.inc';
- require FIMA_TEMPLATES . '/postings/posting_footers.inc';
-
- /* If there are 20 postings or less, don't show the actions/navbar again. */
- if ((count($postings) > 20 || $pageOb['mode'] != 'list') && !$print_view) {
- $form = 2;
- require FIMA_TEMPLATES . '/postings/actions.inc';
- require FIMA_TEMPLATES . '/postings/navbar.inc';
- } else {
- /* TODO */
- echo '<tr><td class="control" colspan="6"></td></tr>';
- }
-}
-require FIMA_TEMPLATES . '/postings/footer.inc';
-
-require $registry->get('templates', 'horde') . '/common-footer.inc';
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<!-- Fima: Copyright 2007-2008 The Horde Project. Fima is under the GPL. -->
-<!-- Horde Project: http://www.horde.org/ | Fima: http://www.horde.org/fima/ -->
-<!-- Horde Licenses: http://www.horde.org/licenses/ -->
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<?php
-
-$page_title = $registry->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-?>
-<title><?php echo htmlspecialchars($page_title) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<title><?php echo htmlspecialchars($registry->get('name')) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<!-- Kastalia: Copyright 2009 Andre Pawlowski -->
-<!-- Horde Project: http://www.horde.org/ | Kastalia: http://h4des.org/index.php?inhalt=kastalia -->
-<!-- Horde Licenses: http://www.horde.org/licenses/ -->
-<?php echo !empty($language) ? '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . strtr($language, '_', '-') . '" lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-
-
-<head>
-
-<?php
-
-$page_title = $registry->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-?>
-<title><?php echo htmlspecialchars($page_title) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-/**
- * News
- *
- * $Id: mail.php 1174 2009-01-19 15:11:03Z duck $
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- * @package News
- */
-
-require_once dirname(__FILE__) . '/lib/base.php';
-
-$id = Horde_Util::getFormData('id');
-$row = $news->get($id);
-if ($row instanceof PEAR_Error) {
- $notification->push($row);
- Horde::url('browse.php')->redirect();
-}
-
-/* Error handler */
-function _error($msg)
-{
- $GLOBALS['notification']->push($msg, 'horde.error');
- News::getUrlFor('news', $GLOBALS['id'])->redirect();
-}
-
-if (!$registry->isAuthenticated()) {
- _error(_("Only authenticated users can send mails."));
-}
-
-$to = Horde_Util::getFormData('email');
-if (empty($to)) {
- _error(_("No mail entered."));
- exit;
-}
-
-$from = $prefs->getValue('from_addr');
-if (empty($from)) {
- _error(_("You have no email set."));
- exit;
-}
-
-$body = sprintf(_("%s would you like to invite you to read the news\n Title: %s\n\n Published: %s \nLink: %s"),
- $GLOBALS['registry']->getAuth(),
- $row['title'],
- $row['publish'],
- News::getUrlFor('news', $id, true, -1));
-
-$mail = new Horde_Mime_Mail(array('subject' => $row['title'], 'body' => $body, 'to' => $to, 'from' => $from, 'charset' => 'UTF-8'));
-try {
- $mail->send($injector->getInstance('Horde_Mail'));
- $notification->push(sprintf(_("News succesfully send to %s"), $to), 'horde.success');
-} catch (Horde_Mime_Exception $e) {
- $notification->push($e);
-}
-
-News::getUrlFor('news', $id)->redirect();
+++ /dev/null
-<?php
-/**
- * News
- *
- * $Id: pdf.php 1191 2009-01-21 16:45:21Z duck $
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- * @package News
- */
-
-$no_compress = true;
-require_once dirname(__FILE__) . '/lib/base.php';
-
-$id = Horde_Util::getFormData('id');
-$row = $news->get($id);
-
-// Check if the news exists
-if ($row instanceof PEAR_Error) {
- $notification->push($row);
- Horde::url('browse.php')->redirect();
-}
-
-// Set up the PDF object.
-$pdf = new Horde_Pdf_Writer();
-
-$pdf->setInfo('title', $row['title']);
-$pdf->setInfo('author', $row['user']);
-$pdf->setInfo('CreationDate', 'D:' . date('Ymdhis'));
-
-$pdf->open();
-$pdf->addPage();
-$pdf->setAutoPageBreak(true);
-$pdf->setFont('Arial', '', 12);
-
-if ($row['picture']) {
- $file = $conf['vfs']['params']['vfsroot'] . '/'
- . News::VFS_PATH . '/images/news/big/'
- . $id . '.' . $conf['images']['image_type'];
- try {
- $pdf->image($file, 120, 20);
- } catch (Horde_Pdf_Exception $e) {
- Horde::logMessage($e, 'INFO');
- }
-}
-
-$pdf->setFillColor('rgb', 200/255, 220/255, 255/255);
-$pdf->cell(0, 6, $row['title'], 0, 1, 'L', 1);
-$pdf->newLine(4);
-
-$pdf->write(12, _("On") . ': ' . News::dateFormat($row['publish']) . "\n");
-$pdf->write(12, _("Link") . ': ' . News::getUrlFor('news', $id, true) . "\n\n", News::getUrlFor('news', $id, true));
-$pdf->multiCell(0, 12, strip_tags($row['content']));
-
-$browser->downloadHeaders($id . '.pdf', 'application/pdf');
-echo $pdf->getOutput();
+++ /dev/null
-<?php
-/**
- * $Id: comments.php 1263 2009-02-01 23:25:56Z duck $
- *
- * Copyright 2007 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- */
-
-$news_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
-
-$cache_key = 'news_rss_comments';
-$rss = $cache->get($cache_key, $conf['cache']['default_lifetime']);
-if (!$rss) {
- $list = News::getLastComments(50);
- $title = _("Last comments");
-
- $rss = '<?xml version="1.0" encoding="UTF-8" ?>
-<rss version="2.0">
-<channel>
- <title>' . htmlspecialchars($title) . '</title>
- <language>' . str_replace('_', '-', strtolower($registry->preferredLang())) . '</language>
- <lastBuildDate>' . date('r') . '</lastBuildDate>
- <description>' . htmlspecialchars($title) . '</description>
- <link>' . Horde::url('index.php', true, -1) . '</link>
- <generator>' . htmlspecialchars($registry->get('name')) . '</generator>';
-
- foreach ($list as $comment) {
- $rss .= '
- <item>
- <title>' . htmlspecialchars($comment['message_subject']) . ' </title>
- <link>' . $comment['read_url'] . '</link>
- <guid isPermaLink="true">' . $comment['read_url'] . '</guid>
- <pubDate>' . date('r', strtotime($comment['message_date'])) . '</pubDate>
- <description><![CDATA[' . $comment['message_author'] . ': ' . strip_tags($comment['body']) . ']]></description>
- </item>';
- }
-
- $rss .= '
-</channel>
-</rss>';
-
- $cache->set($cache_key, $rss);
-}
-
-header('Content-type: text/xml; charset=UTF-8');
-echo $rss;
+++ /dev/null
-<?php
-/**
- * $Id: index.php 183 2008-01-06 17:39:50Z duck $
- *
- * Copyright 2007 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- */
-
-$news_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
-
-// Show a specific user?
-$cache_key = 'news_rss_index';
-
-$rss = $cache->get($cache_key, $conf['cache']['default_lifetime']);
-if (!$rss) {
-
- $title = $registry->get('name', 'horde');
-
- $read_url = Horde::url('read.php', true, -1);
- $rss = '<?xml version="1.0" encoding="UTF-8" ?>
- <rss version="2.0">
- <channel>
- <title>' . htmlspecialchars($title) . '</title>
- <language>' . str_replace('_', '-', strtolower($registry->preferredLang())) . '</language>
- <lastBuildDate>' . date('r') . '</lastBuildDate>
- <description>' . htmlspecialchars($title) . '</description>
- <link>' . Horde::url('index.php', true, -1) . '</link>
- <generator>' . htmlspecialchars($registry->get('name')) . '</generator>';
-
- $rss .= '
- <item>
- <title>' . _("Last news") . ' </title>
- <link>' . Horde::url('rss/news.php', true, -1) . '</link>
- </item>';
-
- $rss .= '
- <item>
- <title>' . _("Last comments") . ' </title>
- <link>' . Horde::url('rss/comments.php', true, -1) . '</link>
- </item>';
-
- $rss .= '
- </channel>
- </rss>';
-
- $cache->set($cache_key, $rss);
-}
-
-header('Content-type: text/xml');
-echo $rss;
+++ /dev/null
-<?php
-/**
- * $Id: news.php 1263 2009-02-01 23:25:56Z duck $
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Duck <duck@obala.net>
- * @author McLion <mclion@obala.net>
- */
-
-$news_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
-
-$cache_key = 'news_rss_news';
-$rss = $cache->get($cache_key, $conf['cache']['default_lifetime']);
-if (empty($rss)) {
-
- /* query preparation */
- $query = 'SELECT n.id, publish, n.user, n.source, n.sourcelink, ' .
- 'n.category1, n.category2, n.comments, n.picture, n.chars, nl.content, ' .
- 'nl.title, nl.abbreviation ' .
- 'FROM ' . $news->prefix . ' AS n, ' . $news->prefix . '_body AS nl ' .
- 'WHERE n.status="' . News::CONFIRMED . '" AND n.publish<=NOW() ' .
- 'AND nl.lang="' . $registry->preferredLang() . '" AND n.id=nl.id ORDER BY publish DESC';
- $rssbody = '';
- $query = $news->db->modifyLimitQuery($query, 0, 10);
- $list = $news->db->getAssoc($query, true, array(), DB_FETCHMODE_ASSOC);
- $categories = $news_cat->getCategories(false);
- $title = sprintf(_("Last news"), $registry->get('name', 'horde'));
-
- $lastnewstime = 0;
- foreach ($list as $news_id => $news) {
- $news_link = News::getUrlFor('news', $news_id, true);
- $rssbody .= '
- <item>
- <enclosure url="http://' . $_SERVER['SERVER_NAME'] . News::getImageUrl($news_id) . '" type="image/jpg" />
- <title>' . htmlspecialchars($news['title']) . ' </title>
- <dc:creator>' . htmlspecialchars($news['user']). '</dc:creator>
- <link>' . $news_link . '</link>
- <guid isPermaLink="true">' . $news_link . '</guid>
- <comments>' . $news_link . '#comments</comments>
- <description><![CDATA[' . trim(substr(htmlspecialchars(strip_tags($news['content'])), 0, 512)) . ']]></description>
- <pubDate>' . date('r', strtotime($news['publish'])) . '</pubDate>
- <category><![CDATA[' . $categories[$news['category1']]['category_name'] . ']]></category>
- </item>';
-
- if (strtotime($news['publish']) > $lastnewstime) {
- $lastnewstime = strtotime($news['publish']);
- }
- }
-
- // Wee need the last published news time
- $rssheader = '<?xml version="1.0" encoding="UTF-8" ?>
-<rss version="2.0"
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
- xmlns:dc="http://purl.org/dc/elements/1.1/" >
-<channel>
- <title>' . htmlspecialchars($title) . '</title>
- <language>' . str_replace('_', '-', strtolower($registry->preferredLang())) . '</language>
- <lastBuildDate>' . date('r', $lastnewstime) . '</lastBuildDate>
- <description>' . htmlspecialchars($title) . '</description>
- <link>' . Horde::url('index.php', true, -1) . '</link>
- <generator>' . htmlspecialchars($registry->get('name')) . '</generator>';
-
- $rssfooter = '
-</channel>
-</rss>';
-
- // build rss
- $rss = $rssheader . $rssbody . $rssfooter;
-
- $cache->set($cache_key, $rss);
-}
-
-header('Content-type: text/xml; charset=utf-8');
-echo $rss;
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<!-- news: Copyright 2004-2010 The Horde Project. news is under a Horde license. -->
-<!-- Horde Project: http://www.horde.org/ | news: http://www.horde.org/horde/ -->
-<!-- Horde Licenses: http://www.horde.org/licenses/ -->
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<?php
-
-$page_title = $registry->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-?>
-<title><?php echo htmlspecialchars($page_title) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<link rel="alternate" title="<?php echo _("Last news") ?>" href="<?php echo Horde::url('rss/news.php', true, -1) ?>" type="application/rss+xml" />
-<link rel="alternate" title="<?php echo _("Last comments") ?>" href="<?php echo Horde::url('rss/comments.php', true, -1) ?>" type="application/rss+xml" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-</head>
-
-<body>
+++ /dev/null
-<?php
-if (isset($language)) {
- header('Content-type: text/html; charset=UTF-8');
- header('Vary: Accept-Language');
-}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
-<!-- Skoli: Copyright 2004-2008 The Horde Project. Skoli is under a Horde license. -->
-<!-- Horde Project: http://www.horde.org/ | Skoli: http://www.horde.org/horde/ -->
-<!-- Horde Licenses: http://www.horde.org/licenses/ -->
-<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
-<head>
-<?php
-
-$page_title = $registry->get('name');
-if (!empty($title)) {
- $page_title .= ' :: ' . $title;
-}
-
-Horde::outputMetaTags();
-Horde::includeScriptFiles();
-
-$bc = $prefs->getValue('show_panel')
- ? 'rightPanel'
- : '';
-
-?>
-<title><?php echo htmlspecialchars($page_title) ?></title>
-<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
-<?php Horde_Themes::includeStylesheetFiles() ?>
-<link href="<?php echo Horde::url('themes/categoryCSS.php') ?>" rel="stylesheet" type="text/css" />
-</head>
-
-<body<?php if ($bc) echo ' class="' . $bc . '"' ?>>