From: Jan Schneider Date: Sun, 3 Oct 2010 17:54:23 +0000 (+0200) Subject: Fix accidentally re-added files. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=344b0b8d68e8054329c482376e9e362df09b1551;p=horde.git Fix accidentally re-added files. --- diff --git a/babel/lib/Display.php b/babel/lib/Display.php deleted file mode 100644 index e8ba4df19..000000000 --- a/babel/lib/Display.php +++ /dev/null @@ -1,136 +0,0 @@ - - * @package Babel - */ - -class Translate_Display { - - function header($msg, $msg2 = '') { - global $cnt_i, $registry; - $select_img = Horde::img('alerts/message.png'); - print sprintf('
%s%s%s
', $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('
%s%s
', $item, $msg, $select_img); - } else { - print sprintf('
%s%s
', $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('
%s%s
', $item, $msg, $select_img); - flush(); - } - - function info($msg = "", $bold = true) { - - global $cnt_i, $registry; - - if (empty($msg)) { - echo "
"; - } else { - - $item = ($cnt_i++ % 2); - - $select_img = Horde::img('alerts/select.png'); - if ($bold) { - print sprintf('
%s%s
', $item, $msg, $select_img); - } else { - print sprintf('
%s%s
', $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 = ''; - } -} -require FIMA_TEMPLATES . '/postings/footer.inc'; - -require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/fima/templates/common-header.inc b/fima/templates/common-header.inc deleted file mode 100644 index 87fa31c07..000000000 --- a/fima/templates/common-header.inc +++ /dev/null @@ -1,29 +0,0 @@ - - - - - -' : '' ?> - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -?> -<?php echo htmlspecialchars($page_title) ?> - - - - - diff --git a/jeta/templates/common-header.inc b/jeta/templates/common-header.inc deleted file mode 100644 index cab2d7120..000000000 --- a/jeta/templates/common-header.inc +++ /dev/null @@ -1,15 +0,0 @@ - - -' : '' ?> - -<?php echo htmlspecialchars($registry->get('name')) ?> - - - - - diff --git a/kastalia/templates/common-header.inc b/kastalia/templates/common-header.inc deleted file mode 100755 index ea8965e69..000000000 --- a/kastalia/templates/common-header.inc +++ /dev/null @@ -1,32 +0,0 @@ - - - - - -' : '' ?> - - - - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -?> -<?php echo htmlspecialchars($page_title) ?> - - - - - diff --git a/news/mail.php b/news/mail.php deleted file mode 100644 index 292cf6b01..000000000 --- a/news/mail.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @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(); diff --git a/news/pdf.php b/news/pdf.php deleted file mode 100644 index 91e2dc28c..000000000 --- a/news/pdf.php +++ /dev/null @@ -1,60 +0,0 @@ - - * @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(); diff --git a/news/rss/comments.php b/news/rss/comments.php deleted file mode 100644 index 57a65d511..000000000 --- a/news/rss/comments.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ - -$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 = ' - - - ' . htmlspecialchars($title) . ' - ' . str_replace('_', '-', strtolower($registry->preferredLang())) . ' - ' . date('r') . ' - ' . htmlspecialchars($title) . ' - ' . Horde::url('index.php', true, -1) . ' - ' . htmlspecialchars($registry->get('name')) . ''; - - foreach ($list as $comment) { - $rss .= ' - - ' . htmlspecialchars($comment['message_subject']) . ' - ' . $comment['read_url'] . ' - ' . $comment['read_url'] . ' - ' . date('r', strtotime($comment['message_date'])) . ' - - '; - } - - $rss .= ' - -'; - - $cache->set($cache_key, $rss); -} - -header('Content-type: text/xml; charset=UTF-8'); -echo $rss; diff --git a/news/rss/index.php b/news/rss/index.php deleted file mode 100644 index 8d091b529..000000000 --- a/news/rss/index.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ - -$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 = ' - - - ' . htmlspecialchars($title) . ' - ' . str_replace('_', '-', strtolower($registry->preferredLang())) . ' - ' . date('r') . ' - ' . htmlspecialchars($title) . ' - ' . Horde::url('index.php', true, -1) . ' - ' . htmlspecialchars($registry->get('name')) . ''; - - $rss .= ' - - ' . _("Last news") . ' - ' . Horde::url('rss/news.php', true, -1) . ' - '; - - $rss .= ' - - ' . _("Last comments") . ' - ' . Horde::url('rss/comments.php', true, -1) . ' - '; - - $rss .= ' - - '; - - $cache->set($cache_key, $rss); -} - -header('Content-type: text/xml'); -echo $rss; diff --git a/news/rss/news.php b/news/rss/news.php deleted file mode 100755 index 190dbbc75..000000000 --- a/news/rss/news.php +++ /dev/null @@ -1,80 +0,0 @@ - - * @author McLion - */ - -$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 .= ' - - - ' . htmlspecialchars($news['title']) . ' - ' . htmlspecialchars($news['user']). ' - ' . $news_link . ' - ' . $news_link . ' - ' . $news_link . '#comments - - ' . date('r', strtotime($news['publish'])) . ' - - '; - - if (strtotime($news['publish']) > $lastnewstime) { - $lastnewstime = strtotime($news['publish']); - } - } - - // Wee need the last published news time - $rssheader = ' - - - ' . htmlspecialchars($title) . ' - ' . str_replace('_', '-', strtolower($registry->preferredLang())) . ' - ' . date('r', $lastnewstime) . ' - ' . htmlspecialchars($title) . ' - ' . Horde::url('index.php', true, -1) . ' - ' . htmlspecialchars($registry->get('name')) . ''; - - $rssfooter = ' - -'; - - // build rss - $rss = $rssheader . $rssbody . $rssfooter; - - $cache->set($cache_key, $rss); -} - -header('Content-type: text/xml; charset=utf-8'); -echo $rss; diff --git a/news/templates/common-header.inc b/news/templates/common-header.inc deleted file mode 100644 index 7f186be3c..000000000 --- a/news/templates/common-header.inc +++ /dev/null @@ -1,31 +0,0 @@ - - - - - -' : '' ?> - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -?> -<?php echo htmlspecialchars($page_title) ?> - -" href="" type="application/rss+xml" /> -" href="" type="application/rss+xml" /> - - - - diff --git a/skoli/templates/common-header.inc b/skoli/templates/common-header.inc deleted file mode 100644 index ff189124d..000000000 --- a/skoli/templates/common-header.inc +++ /dev/null @@ -1,34 +0,0 @@ - - - - - -' : '' ?> - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -$bc = $prefs->getValue('show_panel') - ? 'rightPanel' - : ''; - -?> -<?php echo htmlspecialchars($page_title) ?> - - - - - ->
'; - $html .= ''; - $html .= ''; - - if ($percent > 0) { - $html .= ''; - } - - if ($percent != 100) { - $html .= ''; - } - } - - $html .= '
'; - } else { - $html .= ' ' . $percent .'%
'; - - return $html; - } - -} diff --git a/babel/templates/common-header.inc b/babel/templates/common-header.inc deleted file mode 100644 index eaa3d5bc4..000000000 --- a/babel/templates/common-header.inc +++ /dev/null @@ -1,25 +0,0 @@ - - -' : '' ?> - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -?> -<?php echo $page_title ?> - - - - diff --git a/crumb/templates/common-header.inc b/crumb/templates/common-header.inc deleted file mode 100644 index 86b9c2aad..000000000 --- a/crumb/templates/common-header.inc +++ /dev/null @@ -1,29 +0,0 @@ - - - - - -' : '' ?> - -get('name'); -if (!empty($title)) { - $page_title .= ' :: ' . $title; -} - -Horde::outputMetaTags(); -Horde::includeScriptFiles(); - -?> -<?php echo htmlspecialchars($page_title) ?> - - - - - diff --git a/drag_n_drop_portal/block.php b/drag_n_drop_portal/block.php deleted file mode 100644 index 71c537bbe..000000000 --- a/drag_n_drop_portal/block.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @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); diff --git a/drag_n_drop_portal/lib/Block/Layout/View/js.php b/drag_n_drop_portal/lib/Block/Layout/View/js.php deleted file mode 100644 index 30caa10f4..000000000 --- a/drag_n_drop_portal/lib/Block/Layout/View/js.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @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 = '
'; - $js = ''; - - $js_init .= 'portal.addWidgetControls("control_buttons");' - . '}' - . 'document.observe("dom:loaded", init); -' - . ''; - - $html .= '
' . "\n" . $js . "\n" . $js_init; - - // Strip any CSS tags out of the returned content so - // they can be handled seperately. - if (preg_match_all('//', $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"; - } -} diff --git a/fima/data.php b/fima/data.php deleted file mode 100644 index e16630cab..000000000 --- a/fima/data.php +++ /dev/null @@ -1,227 +0,0 @@ - - * - * 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 '
'; -} -require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/fima/lib/Driver/sql.php b/fima/lib/Driver/sql.php deleted file mode 100644 index e473c98f6..000000000 --- a/fima/lib/Driver/sql.php +++ /dev/null @@ -1,1064 +0,0 @@ - - * 'phptype' The database type (e.g. 'pgsql', 'mysql', etc.). - * 'table' The name of the foo table in 'database'. - * 'charset' The database's internal charset. - * - * Required by some database implementations:
- *      '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.
- * - * 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 - * @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; - } - -} diff --git a/fima/postings.php b/fima/postings.php deleted file mode 100644 index 3b28ef6e9..000000000 --- a/fima/postings.php +++ /dev/null @@ -1,733 +0,0 @@ - - * - * 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 - */ - -@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) . ''; - $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) . ''; - } - 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) . ''; - $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) . ''; - } -} - -/* Some browsers have trouble with hidden overflow in table cells but not in divs. */ -if ($GLOBALS['browser']->hasQuirk('no_hidden_overflow_tables')) { - $overflow_begin = '
'; - $overflow_end = '
'; -} 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 '