phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] news_admin/inc hook_website_mid.inc.php, 1.3 class.bo


From: skwashd
Subject: [Phpgroupware-cvs] news_admin/inc hook_website_mid.inc.php, 1.3 class.bo.inc.php, 1.2 class.so.inc.php, 1.2 class.ui.inc.php, 1.3 hook_sidebox_menu.inc.php, 1.2 class.uinews.inc.php, 1.27 class.sonews.inc.php, 1.4 class.bonews.inc.php, 1.4
Date: Sun, 15 May 2005 14:25:00 +0200

Update of news_admin/inc

Removed Files:
     Branch: MAIN
            hook_website_mid.inc.php
            class.bo.inc.php
            class.so.inc.php
            class.ui.inc.php
Added Files:
     Branch: MAIN
            hook_sidebox_menu.inc.php lines: +31 -0
            class.uinews.inc.php lines: +419 -103
            class.sonews.inc.php lines: +137 -37
            class.bonews.inc.php lines: +275 -7

Log Message:
merged from 16

====================================================
Index: hook_sidebox_menu.inc.php
<?php
/**
* TODO Add Header
* Code is GPL
* Written Dave Hall
* (c) 2004 FSF
*/

        $file[] = array('text'  => 'show all news',
                        'url'   => $GLOBALS['phpgw']->link('/index.php',
                                array('menuaction'      => 
'news_admin.uinews.read_news',
                                        'start'         => 0,
                                        'cat_id'        => 'all'
                                )
                        )
                );

        if(intval($_GET['cat_id'])
                && ExecMethod('news_admin.boacl.is_writeable', $_GET['cat_id']))
        {
                $file[] = array('text'  => 'add news item to this category',
                                'url'   => $GLOBALS['phpgw']->link('/index.php',
                                        array('menuaction'      => 
'news_admin.uinews.add',
                                                'cat_id'        => 
$_GET['cat_id']
                                        )
                                )
                        );
        }

        display_sidebox('news_admin',lang('news_admin'),$file);
?>

====================================================
Index: class.uinews.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare - News                                                   
   *
        * http://www.phpgroupware.org                                           
   *
        * --------------------------------------------                          
   *
        *  This program is free software; you can redistribute it and/or modify 
it *
        *  under the terms of the GNU General Public License as published by 
the   *
        *  Free Software Foundation; either version 2 of the License, or (at 
your  *
        *  option) any later version.                                           
   *
        * --------------------------------------------                          
   *
        * This program was sponsered by Golden Glair productions                
   *
        * http://www.goldenglair.com                                            
   *
        
\**************************************************************************/

        /* $Id: class.uinews.inc.php,v 1.27 2005/05/15 12:25:42 skwashd Exp $ */

        class uinews
        {
                var $start = 0;
                var $query = '';
                var $sort  = '';
                var $order = '';
                var $cat_id;
                var $template;
                var $bo;
                var $news_data;
                var $news_id;
                var $sbox;
                var $public_functions = array(
                        'write_news'    => True,
                        'add'           => True,
                        'edit'          => True,
                        'delete'        => True,
                        'delete_item'   => True,
                        'read_news'      => True,
                        'show_news_home' => True
                );

                function uinews()
                {
                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
                        $this->template = $GLOBALS['phpgw']->template;
                        $this->bo   = CreateObject('news_admin.bonews',True);
                        $this->sbox = createObject('phpgwapi.sbox');
                        $this->start = $this->bo->start;
                        $this->query = $this->bo->query;
                        $this->order = $this->bo->order;
                        $this->sort = $this->bo->sort;
                        $this->cat_id = $this->bo->cat_id;
                }

                //with $default, we are called from the news form
                function selectlist($type,$default=false)
                {
                        $link_data['menuaction'] = ($type == 'read') ? 
'news_admin.uinews.read_news' : 'news_admin.uinews.write_news';
                        $link_data['start'] = 0;
                        $right = ($type == 'read') ? PHPGW_ACL_READ : 
PHPGW_ACL_ADD;
                        $selectlist = ($default === false) ? ('<option>' . 
lang($type . ' news') . '</option>') : '';
                        $cats = is_array($this->bo->cats) ? $this->bo->cats : 
array();
                        foreach($cats as $cat)
                        {
                                
if($this->bo->acl->is_permitted($cat['id'],$right))
                                {
                                        $cat_id = (int) $cat['id'];
                                        $link_data['cat_id'] = $cat_id;
                                        $selectlist .= '<option value="';
                                        $selectlist .= $default !== False ? 
$cat_id : $GLOBALS['phpgw']->link('/index.php',$link_data);
                                        $selectlist .= '"';
                                        $selectlist .= ($default === $cat_id) ? 
' selected="selected"' : '';
                                        $selectlist .= '>' . $cat['name'] . 
'</option>' . "\n";
                                }
                        }
                        if (!$default)
                        {
                                $link_data['cat_id'] = 'all';
                                $selectlist .= '<option 
style="font-weight:bold" value="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data)
                                        . '">' . lang('All news') . '</option>' 
 . "\n";
                        }
                        return $selectlist;
                }

                function read_news()
                {
                        $limit = ($GLOBALS['phpgw_info']['common']['maxmatchs']
                                 ? 
$GLOBALS['phpgw_info']['common']['maxmatchs'] : 5);

                        $news_id = get_var('news_id',Array('GET'));

                        $news = $news_id ? array($news_id => 
$this->bo->get_news($news_id)) :
                                
$this->bo->get_newslist($this->cat_id,$this->start,'','',$limit,True);

                        $this->template->set_file(array(
                                'main' => 'read.tpl'
                        ));
                        $this->template->set_block('main','news_form');
                        $this->template->set_block('main','row');
                        $this->template->set_block('main','row_empty');

                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();
                        $this->template->set_block('main','category');
                        $var['lang_read'] = lang('Read');
                        $var['lang_write'] = lang('Write');
                        $var['readable'] = $this->selectlist('read');
                        $var['maintainlink'] = (($this->cat_id != 'all') && 
$this->bo->acl->is_permitted($this->cat_id,PHPGW_ACL_ADD)) ?
                                ('<a href="' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news&start=0&cat_id='.$this->cat_id)
 .
                                        '">' . lang('Maintain') . '</a>') :
                                '';
                        $var['cat_name'] = ($this->cat_id != 'all') ? 
$this->bo->catbo->id2name($this->cat_id) : lang('All news');
                        $this->template->set_var($var);
                        $this->template->parse('_category','category');

                        
$this->template->set_var('icon',$GLOBALS['phpgw']->common->image('news_admin','news-corner.gif'));

                        foreach($news as $newsitem)
                        {
                                $var = Array(
                                        'subject'       => $newsitem['subject'],
                                        'submitedby'    => 'Submitted by ' . 
$GLOBALS['phpgw']->accounts->id2name($newsitem['submittedby']) . ' on ' . 
$GLOBALS['phpgw']->common->show_date($newsitem['date']),
                                        'content'       => 
($newsitem['is_html'] ? $newsitem['content'] : nl2br($newsitem['content'])),
                                );

                                $this->template->set_var($var);
                                $this->template->parse('rows','row',True);
                        }
                        if ($this->start)
                        {
                                $link_data['menuaction'] = 
'news_admin.uinews.read_news';
                                $link_data['start'] = $this->start - $limit;
                                $this->template->set_var('lesslink',
                                        '<a href="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '">&lt;&lt;&lt;</a>'
                                );
                        }
                        if ($this->bo->total > $this->start + $limit)
                        {
                                $link_data['menuaction'] = 
'news_admin.uinews.read_news';
                                $link_data['start'] = $this->start + $limit;
                                $this->template->set_var('morelink',
                                        '<a href="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '">' . lang('More news') . 
'</a>'
                                );
                        }
                        if (! $this->bo->total)
                        {
                                $this->template->set_var('row_message',lang('No 
entries found'));
                                $this->template->parse('rows','row_empty',True);
                        }

                        $this->template->pfp('_out','news_form');
                }

                //this is currently broken
                function show_news_home()
                {
                        $title = '<font color="#FFFFFF">'.lang('News 
Admin').'</font>';
                        $portalbox = CreateObject('phpgwapi.listbox',array(
                                'title'     => $title,
                                'primary'   => 
$GLOBALS['phpgw_info']['theme']['navbar_bg'],
                                'secondary' => 
$GLOBALS['phpgw_info']['theme']['navbar_bg'],
                                'tertiary'  => 
$GLOBALS['phpgw_info']['theme']['navbar_bg'],
                                'width'     => '100%',
                                'outerborderwidth' => '0',
                                'header_background_image' => 
$GLOBALS['phpgw']->common->image('phpgwapi','bg_filler', 'png', False)
                        ));

                        $app_id = 
$GLOBALS['phpgw']->applications->name2id('news_admin');
                        $GLOBALS['portal_order'][] = $app_id;

                        $var = Array(
                                'up'       => Array('url' => '/set_box.php', 
'app' => $app_id),
                                'down'     => Array('url' => '/set_box.php', 
'app' => $app_id),
                                'close'    => Array('url' => '/set_box.php', 
'app' => $app_id),
                                'question' => Array('url' => '/set_box.php', 
'app' => $app_id),
                                'edit'     => Array('url' => '/set_box.php', 
'app' => $app_id)
                        );

                        while(list($key,$value) = each($var))
                        {
                                $portalbox->set_controls($key,$value);
                        }

                        $newslist = 
$this->bo->get_newslist($this->cat_id,0,'','',5,True);

                        $image_path = 
$GLOBALS['phpgw']->common->get_image_path('news_admin');

                        if(is_array($newslist))
                        {
                                foreach($newslist as $newsitem)
                                {
                                        $portalbox->data[] = array(
                                                'text' => $newsitem['subject'] 
. ' - ' . lang('Submitted by') . ' ' . 
$GLOBALS['phpgw']->accounts->id2name($newsitem['submittedby']) . ' ' . 
lang('on') . ' ' . $GLOBALS['phpgw']->common->show_date($newsitem['date']),
                                                'link' => 
$GLOBALS['phpgw']->link('/index.php',
                                                                
array('menuaction'      => 'news_admin.uinews.show_news',
                                                                        
'news_id'       =>  $newsitem['id'],
                                                                )
                                                        )
                                        );
                                }
                        }
                        else
                        {
                                $portalbox->data[] = array('text' => lang('no 
news'));
                        }

                        $tmp = "\r\n"
                                . '<!-- start News Admin -->' . "\r\n"
                                . $portalbox->draw()
                                . '<!-- end News Admin -->'. "\r\n";
                        $this->template->set_var('phpgw_body',$tmp,True);
                        $this->template->pfp('out', 'phpgw_body');
                }

                //the following function is unmaintained
                function show_news_website($section='mid')
                {
                        $cat_id = $_GET['cat_id'];
                        $start = $_GET['start'];
                        $oldnews = $_GET['oldnews'];
                        $news_id = $_GET['news_id'];

                        if (! $cat_id)
                        {
                                $cat_id = 0;
                        }

                        $this->template->set_file(array(
                                '_news' => 'news_' . $section . '.tpl'
                        ));
                        $this->template->set_block('_news','news_form');
                        $this->template->set_block('_news','row');
                        $this->template->set_block('_news','category');


                        if($news_id)
                        {
                                $news = array($news_id => 
$this->bo->get_news($news_id));
                        }
                        else
                        {
                                $news = 
$this->bo->get_NewsList($cat_id,$oldnews,$start,$total);
                        }

                        $var = Array();

                        
$this->template->set_var('icon',$GLOBALS['phpgw']->common->image('news_admin','news-corner.gif'));

                        foreach($news as $newsitem)
                        {
                                $var = Array(
                                        'subject'=> $newsitem['subject'],
                                        'submitedby' => 'Submitted by ' . 
$GLOBALS['phpgw']->accounts->id2name($newsitem['submittedby']) . ' on ' . 
$GLOBALS['phpgw']->common->show_date($newsitem['date']),
                                        'content'    => 
nl2br($newsitem['content'])
                                );

                                $this->template->set_var($var);
                                $this->template->parse('rows','row',True);
                        }

                        $out = $this->template->fp('out','news_form');

                        if ($this->bo->total > 5 && ! $oldnews)
                        {
                                $link_values = array(
                                        'menuaction'    => 
'news_admin.uinews.show_news',
                                        'oldnews'       => 'True',
                                        'cat_id'        => $cat_id,
                                        'category_list' => 'True'
                                );

                                $out .= '<center><a href="' . 
$GLOBALS['phpgw']->link('/index.php',$link_values) . '">View news 
archives</a></center>';
                        }
                        return $out;
                }

                function add()
                {
                        if($_POST['cancel'])
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
                                return;
                        }
                        if($_POST['submitit'])
                        {
                                $this->news_data = $_POST['news'];
                                if (! $this->news_data['subject'])
                                {
                                        $errors[] = lang('The subject is 
missing');
                                }
                                if (! $this->news_data['content'])
                                {
                                        $errors[] = lang('The news content is 
missing');
                                }
                                if (!is_array($errors))
                                {
                                        $this->news_data['date'] = time();
                                        
$this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
                                        $this->news_id = 
$this->bo->add($this->news_data);
                                        $this->message = lang('Message has been 
added');
                                        //after having added, we must switch to 
edit mode instead of stay in add
                                        $this->news_data = 
$this->bo->get_news($this->news_id,True);
                                        $this->modify('edit');
                                        return;
                                }
                                else
                                {
                                        $this->message = $errors;
                                }
                        }
                        else
                        {
                                $this->news_data['category'] = $this->cat_id;
                        }
                        $this->modify('add');
                }

                function delete()
                {
                        $news_id = $_POST['news_id'] ? $_POST['news_id'] : 
$_GET['news_id'];

                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();
                        $this->template->set_file(array(
                                'form' => 'admin_delete.tpl'
                        ));
                        $this->template->set_var('lang_message',lang('Are you 
sure you want to delete this entry ?'));
                        $this->template->set_var('lang_yes',lang('Yes'));
                        $this->template->set_var('lang_no',lang('No'));

                        
$this->template->set_var('link_yes',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.delete_item&news_id='
 . $news_id));
                        
$this->template->set_var('link_no',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));

                        $this->template->pfp('_out','form');
                }

                function delete_item()
                {
                        $item = intval(get_var('news_id'));
                        if($item)
                        {
                                $this->bo->delete($item);
                                $msg = lang('Item has been deleted');
                        }
                        else
                        {
                                $msg = lang('Item not found');
                        }
                        $this->write_news($msg);
                }

                function edit()
                {
                        $this->news_data        = $_POST['news'];
                        $this->news_id          = (isset($_GET['news_id']) ? 
$_GET['news_id']
                                                                                
: $_POST['news']['id']);

                        if($_POST['cancel'])
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
                                return;
                        }
                        if(is_array($this->news_data))
                        {
                                if(! $this->news_data['subject'])
                                {
                                        $errors[] = lang('The subject is 
missing');
                                }
                                if(! $this->news_data['content'])
                                {
                                        $errors[] = lang('The news content is 
missing');
                                }

                                if(!is_array($errors))
                                {
                                        
$this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
                                        $this->bo->edit($this->news_data);
                                        $this->message = lang('News item has 
been updated');
                                }
                                else
                                {
                                        $this->message = $errors;
                                }
                        }
                        /*else
                        {*/
                                $this->news_data = 
$this->bo->get_news($this->news_id,True);
                                $this->news_data['date_d'] = 
date('j',$this->news_data['begin']);
                                $this->news_data['date_m'] = 
date('n',$this->news_data['begin']);
                                $this->news_data['date_y'] = 
date('Y',$this->news_data['begin']);
                        /*}*/
                        $this->modify();
                }

                function modify($type = 'edit')
                {
                        $options = $this->bo->get_options($this->news_data);
                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();

                        $this->template->set_file(array(
                                'form' => 'admin_form.tpl'
                        ));

                        if (is_array($this->message))
                        {
                                
$this->template->set_var('errors',$GLOBALS['phpgw']->common->error_list($this->message));
                        }
                        elseif($this->message)
                        {
                                
$this->template->set_var('errors',$this->message);
                        }

                        $this->template->set_var('lang_header',lang($type . ' 
news item'));
                        
$this->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php',
                                array('menuaction'      => 
'news_admin.uinews.'.$type,
                                                'news_id'       => 
$this->news_id
                                        )
                                )
                        );

                        //echo '<br />UI:<br /><pre>'; 
print_r($this->news_data); echo '</pre>';

                        $this->template->set_var(array(
                                'form_button' => '<input type="submit" 
name="submitit" value="' . lang('save') . '">',
                                'value_id' => $this->news_id,
                                'done_button' => '<input type="submit" 
name="cancel" value="' . lang('Done') . '">',
                                'label_subject' => lang('subject') . ':',
                                'value_subject' => '<input name="news[subject]" 
size="60" value="' . htmlentities($this->news_data['subject']) . '">',
                                'label_teaser' => lang('teaser') . ':',
                                'value_teaser' => '<input name="news[teaser]" 
size="60" value="' . htmlentities($this->news_data['teaser']) . '" 
maxLength=100>',
                                'label_content' => lang('Content') . ':',
                                'value_content' => '<textarea cols="60" 
rows="6" name="news[content]" wrap="virtual">' . $this->news_data['content'] . 
'</textarea>',
                                'label_category' => lang('Category') . ':',
                                'value_category' => '<select 
name="news[category]">' . $this->selectlist('write', 
intval($this->news_data['category'])) . '</select>',
                                'label_visible' => lang('Visible') . ':',
                                'value_begin_d' =>  
$this->sbox->getDays('news[begin_d]',date('j',$this->news_data['begin'])),
                                'value_begin_m' =>  
$this->sbox->getMonthText('news[begin_m]',date('n',$this->news_data['begin'])),
                                'value_begin_y' =>  
$this->sbox->getYears('news[begin_y]',date('Y',$this->news_data['begin']),date('Y')),
                                'select_from' => $options['from'],
                                'select_until' => $options['until'],
                                'value_end_d' =>  
$this->sbox->getDays('news[end_d]',date('j',$this->news_data['end'])) ,
                                'value_end_m' =>  
$this->sbox->getMonthText('news[end_m]',date('n',$this->news_data['end'])),
                                'value_end_y' =>  
$this->sbox->getYears('news[end_y]',date('Y',$this->news_data['end']),date('Y')),
                                'label_is_html' => lang('Contains HTML'),
                                'value_is_html' => '<input type="checkbox" 
name="news[is_html]" value="1" ' . ($this->news_data['is_html'] ? ' CHECKED' : 
'') .'>',
                        ));

                        $this->template->pfp('out','form');
                }

                function write_news($message = '')
                {
                        $this->template->set_file(array(
                                'main' => 'write.tpl'
                        ));
                        $this->template->set_block('main','list');
                        $this->template->set_block('main','row');
                        $this->template->set_block('main','row_empty');

                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();
                        $this->template->set_block('main','category');
                        $var['lang_read'] = lang('Read');
                        $var['lang_write'] = lang('Write');
                        $var['readable'] = $this->selectlist('read');
                        $var['cat_name'] = $this->cat_id ? 
$this->bo->catbo->id2name($this->cat_id) : lang('Global news');

                        $this->template->set_var($var);
                        $this->template->parse('_category','category');

                        if ($message)
                        {
                                $this->template->set_var('message',$message);
                        }

                        
$this->template->set_var('header_date',$this->nextmatchs->show_sort_order($this->sort,'news_date',$this->order,'/index.php',lang('Date'),'&menuaction=news_admin.uinews.write_news'));
                        
$this->template->set_var('header_subject',$this->nextmatchs->show_sort_order($this->sort,'news_subject',$this->order,'/index.php',lang('Subject'),'&menuaction=news_admin.uinews.write_news'));
                        
$this->template->set_var('header_status',lang('Visible'));
                        $this->template->set_var('header_edit','edit');
                        $this->template->set_var('header_delete','delete');
                        $this->template->set_var('header_view','view');

                        $items      = 
$this->bo->get_newslist($this->cat_id,$this->start,$this->order,$this->sort);

                        $left  = 
$this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');
                        $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');

                        $this->template->set_var(array(
                                'left' => $left,
                                'right' => $right,
                                'lang_showing' => 
$this->nextmatchs->show_hits($this->bo->total,$this->start),
                        ));

                        foreach($items as $item)
                        {
                                
$this->nextmatchs->template_alternate_row_color(&$this->template);
                                
$this->template->set_var('row_date',$GLOBALS['phpgw']->common->show_date($item['date']));
                                if (strlen($item['news_subject']) > 40)
                                {
                                        $subject = 
$GLOBALS['phpgw']->strip_html(substr($item['subject'],40,strlen($item['subject'])));
                                }
                                else
                                {
                                        $subject = 
$GLOBALS['phpgw']->strip_html($item['subject']);
                                }
                                
$this->template->set_var('row_subject',$subject);
                                
$this->template->set_var('row_status',$this->bo->get_visibility($item));

                                $this->template->set_var('row_view','<a href="' 
. 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.read_news&news_id='
 . $item['id']) . '">' . lang('view') . '</a>');
                                $this->template->set_var('row_edit','<a href="' 
. 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.edit&news_id='
 . $item['id']) . '">' . lang('edit') . '</a>');
                                $this->template->set_var('row_delete','<a 
href="' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.delete&news_id='
 . $item['id']) . '">' . lang('Delete') . '</a>');

                                $this->template->parse('rows','row',True);
                        }

                        if (! $this->bo->total)
                        {
                                
$this->nextmatchs->template_alternate_row_color(&$this->template);
                                $this->template->set_var('row_message',lang('No 
entries found'));
                                $this->template->parse('rows','row_empty',True);
                        }

                        
$this->template->set_var('link_add',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.add'));
                        $this->template->set_var('lang_add',lang('Add new 
news'));

                        $this->template->pfp('out','list');
                }
        }
?>

====================================================
Index: class.sonews.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare - News                                                   
   *
        * http://www.phpgroupware.org                                           
   *
        * --------------------------------------------                          
   *
        *  This program is free software; you can redistribute it and/or modify 
it *
        *  under the terms of the GNU General Public License as published by 
the   *
        *  Free Software Foundation; either version 2 of the License, or (at 
your  *
        *  option) any later version.                                           
   *
        * --------------------------------------------                          
   *
        * This program was sponsered by Golden Glair productions                
   *
        * http://www.goldenglair.com                                            
   *
        
\**************************************************************************/

        /* $Id: class.sonews.inc.php,v 1.4 2005/05/15 12:25:42 skwashd Exp $ */

        class sonews
        {
                var $db;

                function sonews()
                {
                        $this->db       = $GLOBALS['phpgw']->db;
                }


                function get_newslist($cat_id, $start, 
$order,$sort,$limit=0,$activeonly,&$total)
                {
                        if ($order)
                        {
                                $ordermethod = ' ORDER BY ' . 
$this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
                        }
                        else
                        {
                                $ordermethod = ' ORDER BY news_date DESC';
                        }

                        if (is_array($cat_id))
                        {
                                $filter = "IN (" . implode(',',$cat_id) . ')';
                        }
                        else
                        {
                                $filter = "=" . intval($cat_id);
                        }

                        $sql = 'SELECT * FROM phpgw_news WHERE news_cat ' . 
$filter;
                        if ($activeonly)
                        {
                                $now = time();
                                $sql .= " AND news_begin<=$now AND 
news_end>=$now";
                        }
                        $sql .= $ordermethod;

                        $this->db->query($sql,__LINE__,__FILE__);
                        $total = $this->db->num_rows();
                        
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);

                        $news = array();

                        while ($this->db->next_record())
                        {
                                $news[$this->db->f('news_id')] = array(
                                        'subject'       => 
htmlentities($this->db->f('news_subject', True)),
                                        'submittedby'   => 
$this->db->f('news_submittedby'),
                                        'date'          => 
$this->db->f('news_date'),
                                        'id'            => 
$this->db->f('news_id'),
                                        'begin'         => 
$this->db->f('news_begin'),
                                        'end'           => 
$this->db->f('news_end'),
                                        'teaser'        => 
htmlentities($this->db->f('news_teaser', True)),
                                        'content'       => 
$this->db->f('news_content',True),
                                        'is_html'       => 
($this->db->f('is_html') ? True : False),
                                );
                        }
                        return $news;
                }

                function get_all_public_news($limit=5)
                {
                        $now = time();
                        $this->db->limit_query("SELECT * FROM phpgw_news WHERE 
news_begin<=$now AND news_end>=$now ORDER BY news_date 
DESC",0,__LINE__,__FILE__,$limit);

                        $news = array();

                        while ($this->db->next_record())
                        {
                                $news[$this->db->f('news_id')] = array(
                                        'subject'       => 
$this->db->f('news_subject', True),
                                        'submittedby'   => 
$this->db->f('news_submittedby'),
                                        'date'          => 
$this->db->f('news_date'),
                                        'id'            => 
$this->db->f('news_id'),
                                        'teaser'        => 
$this->db->f('news_teaser', True),
                                        'content'       => 
$this->db->f('news_content', True),
                                        'is_html'       => 
($this->db->f('is_html') ? True : False),
                                );
                        }
                        return $news;
                }

                function add($news)
                {
                        $sql  = 'INSERT INTO phpgw_news '
                                . ' (news_date, news_submittedby, news_content, 
news_subject, news_begin,'
                                . ' news_end,news_teaser,news_cat,is_html) '
                                . 'VALUES (' . intval($news['date'])  . ','
                                . $GLOBALS['phpgw_info']['user']['account_id'] 
. ','
                                . "'" . 
$this->db->db_addslashes($news['content']) ."',"
                                . "'" . 
$this->db->db_addslashes($news['subject']) ."',"
                                . intval($news['begin']) . ','
                                . intval($news['end']) . ','
                                . "'" . 
$this->db->db_addslashes($news['teaser']) . "',"
                                . intval($news['category']) . ',' . 
intval($news['is_html']) .')';

                        $this->db->query($sql, __LINE__, __FILE__);

                        return $this->db->get_last_insert_id('phpgw_news', 
'news_id');
                }

                function edit($news)
                {
                        //echo '<br />SO-save:<pre>'; print_r($news); echo 
'</pre>';
                        $this->db->query("UPDATE phpgw_news SET "
                                . "news_content='" . 
$this->db->db_addslashes($news['content']) . "',"
                                . "news_subject='" . 
$this->db->db_addslashes($news['subject']) . "', "
                                . "news_teaser='" . 
$this->db->db_addslashes($news['teaser']) . "', "
                                . 'news_begin=' . intval($news['begin']) . ', '
                                . 'news_end=' . intval($news['end']) . ', '
                                . 'news_cat=' . intval($news['category']) . ', '
                                . 'is_html=' . ($news['is_html'] ? 1 : 0) .' '
                                . 'WHERE news_id=' . 
intval($news['id']),__LINE__,__FILE__);
                }

                function delete($news_id)
                {
                        $this->db->query('DELETE FROM phpgw_news WHERE 
news_id=' . intval($news_id) ,__LINE__,__FILE__);
                }

                function get_news($news_id)
                {
                        $this->db->query('SELECT * FROM phpgw_news WHERE 
news_id=' . intval($news_id),__LINE__,__FILE__);
                        $this->db->next_record();

                        $item = array(
                                'id'            => $this->db->f('news_id'),
                                'date'          => $this->db->f('news_date'),
                                'subject'       => $this->db->f('news_subject', 
True),
                                'submittedby'   => 
$this->db->f('news_submittedby'),
                                'teaser'        => $this->db->f('news_teaser', 
True),
                                'content'       => $this->db->f('news_content', 
True),
                                'begin'         => $this->db->f('news_begin'),
                                'end'           => $this->db->f('news_end'),
                                'category'      => $this->db->f('news_cat'),
                                'is_html'       => ($this->db->f('is_html') ? 
True : False),
                        );
                        //echo '<pre>'; print_r($item); echo '</pre>';
                        return $item;
                }

//              function getlist($order,$sort,$cat_id)
//              {
//                      if ($order)
//                      {
//                              $ordermethod = ' ORDER BY ' . 
$this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
//                      }
//                      else
//                      {
//                              $ordermethod = ' ORDER BY news_date DESC';
//                      }

//                      $this->db->query('SELECT * FROM phpgw_news WHERE 
news_cat=' . intval($cat_id) . $ordermethod,__LINE__,__FILE__);
//                      while ($this->db->next_record())
//                      {
//                              $items[] = array(
//                                      'id'          => 
$this->db->f('news_id'),
//                                      'date'        => 
$this->db->f('news_date'),
//                                      'subject'     => 
$this->db->f('news_subject'),
//                                      'submittedby' => 
$this->db->f('news_submittedby'),
//                                      'content'     => 
$this->db->f('news_content'),
//                                      'status'      => 
$this->db->f('news_status'),
//                                      'cat'         => 
$this->db->f('news_cat')
//                              );
//                      }
//                      return $items;
//              }

        }

====================================================
Index: class.bonews.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare - News                                                   
   *
        * http://www.phpgroupware.org                                           
   *
        * --------------------------------------------                          
   *
        *  This program is free software; you can redistribute it and/or modify 
it *
        *  under the terms of the GNU General Public License as published by 
the   *
        *  Free Software Foundation; either version 2 of the License, or (at 
your  *
        *  option) any later version.                                           
   *
        * --------------------------------------------                          
   *
        * This program was sponsered by Golden Glair productions                
   *
        * http://www.goldenglair.com                                            
   *
        
\**************************************************************************/

        /* $Id: class.bonews.inc.php,v 1.4 2005/05/15 12:25:42 skwashd Exp $ */

        class bonews
        {
                var $sonews;
                var $acl;
                var $start = 0;
                var $query = '';
                var $sort  = '';
                var $cat_id;
                var $total = 0;
                var $debug;
                var $use_session = False;
                var $unixtimestampmax;
                var $dateformat;

                function bonews($session=False)
                {
                        $this->acl = CreateObject('news_admin.boacl');
                        $this->sonews = CreateObject('news_admin.sonews');
                        $this->accounts = 
$GLOBALS['phpgw']->accounts->get_list();
                        $this->debug = False;
                        if($session)
                        {
                                $this->read_sessiondata();
                                $this->use_session = True;
                                
foreach(array('start','query','sort','order','cat_id') as $var)
                                {
                                        $this->$var = get_var($var, 
array('POST', 'GET'), '');
                                }

                                $this->cat_id = $this->cat_id ? $this->cat_id : 
'all';
                                $this->save_sessiondata();
                        }
                        $this->catbo = 
createobject('phpgwapi.categories','','news_admin');
                        $this->cats = 
$this->catbo->return_array('all',0,False,'','','cat_name',True);
                        //change this around 19 Jan 2038 03:14:07 GMT
                        $this->unixtimestampmax = 2147483647;
                        $this->dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
                }

                function save_sessiondata()
                {
                        $data = array(
                                'start' => $this->start,
                                'query' => $this->query,
                                'sort'  => $this->sort,
                                'order' => $this->order,
                                'cat_id' => $this->cat_id,
                        );
                        if($this->debug) { echo '<br>Save:'; 
_debug_array($data); }
                        
$GLOBALS['phpgw']->session->appsession('session_data','news_admin',$data);
                }

                function read_sessiondata()
                {
                        $data = 
$GLOBALS['phpgw']->session->appsession('session_data','news_admin');
                        if($this->debug) { echo '<br>Read:'; 
_debug_array($data); }

                        $this->start  = $data['start'];
                        $this->query  = $data['query'];
                        $this->sort   = $data['sort'];
                        $this->order  = $data['order'];
                        $this->cat_id = $data['cat_id'];
                }

                function get_newslist($cat_id, $start=0, 
$order='',$sort='',$limit=0,$activeonly=False)
                {
                        $cats = False;
                        if ($cat_id == 'all')
                        {
                                if(! ($this->cats && is_array($this->cats)) )
                                {
                                        $this->cats = array();
                                }
                                foreach($this->cats as $cat)
                                {
                                        if ($this->acl->is_readable($cat['id']))
                                        {
                                                $cats[] = $cat['id'];
                                        }
                                }
                        }
                        elseif($this->acl->is_readable($cat_id))
                        {
                                $cats = $cat_id;
                        }

                        if($cats)
                        {
                                $news = $this->sonews->get_newslist($cats, 
$start,$order,$sort,$limit,$activeonly,$this->total);
                                foreach($news as $id => $item)
                                {
                                        $news[$id]['content'] = 
($item['is_html'] ? $item['content'] : nl2br(htmlentities($item['content'])));
                                }
                                return $news;
                        }
                        else
                        {
                                return array();
                        }
                }

                function get_all_public_news($limit = 5)
                {
                        $news = $this->sonews->get_all_public_news($limit);
                        foreach($news as $id => $item)
                        {
                                $news[$id]['content'] = ($item['is_html'] ? 
$item['content'] : nl2br(htmlentities($item['content'])));
                        }
                        return $news;
                }

                function delete($news_id)
                {
                        $this->sonews->delete($news_id);
                }

                function add($news)
                {
                        return $this->acl->is_writeable($news['category']) ?
                                $this->sonews->add($news) :
                                false;
                }

                function edit($news)
                {
                        $oldnews = $this->sonews->get_news($news['id']);
                        return ($this->acl->is_writeable($oldnews['category']) 
&&
                                        
$this->acl->is_writeable($news['category'])) ?
                                $this->sonews->edit($news) :
                                False;
                }

                function get_visibility(&$news)
                {
                        $now = time();

                        if ($news['end'] < $now)
                        {
                                return lang('Never');
                        }
                        else
                        {
                                if ($news['begin'] < $now)
                                {
                                        if ($news['end'] == 
$this->unixtimestampmax)
                                        {
                                                return lang('Always');
                                        }
                                        else
                                        {
                                                return lang('until') . 
date($this->dateformat,$news['end']);
                                        }
                                }
                                else
                                {
                                        if ($news['end'] == 
$this->unixtimestampmax)
                                        {
                                                return lang('from') . 
date($this->dateformat,$news['begin']);

                                        }
                                        else
                                        {
                                                return lang('from') . ' ' . 
date($this->dateformat,$news['begin']) . ' ' .
                                                        lang('until') . ' ' . 
date($this->dateformat,$news['end']);
                                        }
                                }
                        }
                }

                //return the selectboxes with calculated defaults, and change 
begin and end by sideaffect
                function get_options(&$news)
                {
                        $now = time();
                        //always is default
                        if (!isset($news['begin']))
                        {
                                //these are only displayed values not 
necessarily the ones that will get stored
                                $news['begin'] = $now;
                                $news['end'] = $now;
                                $from = 1;
                                $until = 1;
                        }
                        //if enddate is in the past set option to never
                        elseif ($news['end'] < $now)
                        {
                                $news['begin'] = $now;
                                $news['end'] = $now;
                                $from = 0;
                                $until = 1;
                        }
                        else
                        {
                                if ($news['begin'] < $now)
                                {
                                        $news['begin'] = $now;
                                        if ($news['end'] == 
$this->unixtimestampmax)
                                        {
                                                $news['end'] = $now;
                                                $from = 1;
                                                $until = 1;
                                        }
                                        else
                                        {
                                                $from = 0.5;
                                                $until = 0.5;
                                        }
                                }
                                else
                                {
                                        if ($news['end'] == 
$this->unixtimestampmax)
                                        {
                                                $news['end'] = $now;
                                                $from = 0.5;
                                                $until = 1;
                                        }
                                        else
                                        {
                                                $from = 0.5;
                                                $until = 0.5;
                                        }
                                }
                        }
                        $options['from'] = '<option value="1"' . (($from == 1) 
? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
                        $options['from'] .= '<option value="0"' . (($from == 0) 
? ' selected="selected"' : '') . '>' . lang('Never') . '</option>';
                        $options['from'] .= '<option value="0.5"' . (($from == 
0.5) ? ' selected="selected"' : '') . '>' . lang('From') . '</option>';
                        $options['until'] = '<option value="1"' . (($until == 
1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
                        $options['until'] .= '<option value="0.5"' . (($until 
== 0.5) ? ' selected="selected"' : '') . '>' . lang('until') . '</option>';
                        return $options;
                }

                //set the begin and end dates
                function set_dates($from,$until,&$news)
                {
                        switch($from)
                        {
                                //always
                                case 1:
                                        $news['begin'] = $news['date'];
                                        $news['end'] = $this->unixtimestampmax;
                                        break;
                                //never
                                case 0:
                                        $news['begin'] = 0;
                                        $news['end'] = 0;
                                        break;
                                default:
                                        $news['begin'] = 
mktime(0,0,0,intval($news['begin_m']), intval($news['begin_d']), 
intval($news['begin_y']));
                                        switch($until)
                                        {
                                                case 1:
                                                        $news['end'] = 
$this->unixtimestampmax;
                                                        break;
                                                default:
                                                        $news['end'] = 
mktime(0,0,0,intval($news['end_m']), intval($news['end_d']), 
intval($news['end_y']));
                                        }
                        }
                }

//              function format_fields($fields)
//              {
//                      $cat = createobject('phpgwapi.categories','news_admin');

//                      $item = array(
//                              'id'          => $fields['id'],
//                              'date'        => 
$GLOBALS['phpgw']->common->show_date($fields['date']),
//                              'subject'     => 
$GLOBALS['phpgw']->strip_html($fields['subject']),
//                              'submittedby' => $fields['submittedby'],
//                              'content'     => $fields['content'],
//                              'status'      => lang($fields['status']),
//                              'cat'         => $cat->id2name($fields['cat'])
//                      );
//                      return $item;
//              }

                function get_news($news_id)
                {
                        $news = $this->sonews->get_news($news_id);
                        //echo '<br />BO:<br />'; print_r($news); echo '</pre>';
                        if ($this->acl->is_readable($news['category']))
                        {
                                $this->total = 1;
                                $news['content'] = ($news['is_html'] ? 
$news['content']: htmlentities($news['content']));
                                //echo '<br />BO2:<br />'; print_r($news); echo 
'</pre>';
                                return $news;
                        }
                        else
                        {
                                 return False;
                        }
                }
        }
?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]