source: trunk/news_admin/inc/class.sonews.inc.php @ 2

Revision 2, 5.9 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare - News                                                        *
4        * http://www.egroupware.org                                                *
5        * --------------------------------------------                             *
6        *  This program is free software; you can redistribute it and/or modify it *
7        *  under the terms of the GNU General Public License as published by the   *
8        *  Free Software Foundation; either version 2 of the License, or (at your  *
9        *  option) any later version.                                              *
10        * --------------------------------------------                             *
11        * This program was sponsered by Golden Glair productions                   *
12        * http://www.goldenglair.com                                               *
13        \**************************************************************************/
14
15
16        class sonews
17        {
18                var $db;
19
20                function sonews()
21                {
22                        copyobj($GLOBALS['phpgw']->db,$this->db);
23                }
24
25                function get_newslist($cat_id, $start, $order,$sort,$limit=0,$activeonly,&$total)
26                {
27                        if(!empty($order))
28                        {
29                                $ordermethod = ' ORDER BY ' . $this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
30                        }
31                        else
32                        {
33                                $ordermethod = ' ORDER BY news_date DESC';
34                        }
35
36                        if(is_array($cat_id))
37                        {
38                                $filter = 'IN (' . implode(',',$cat_id) . ')';
39                        }
40                        else
41                        {
42                                $filter = '=' . (int)$cat_id;
43                        }
44
45                        $sql = 'SELECT * FROM phpgw_news WHERE news_cat ' . $filter;
46                        if($activeonly)
47                        {
48                                $now = time();
49                                $sql .= " AND news_begin<=$now AND news_end>=$now";
50                        }
51                        $sql .= $ordermethod;
52
53                        $this->db->query($sql,__LINE__,__FILE__);
54                        $total = $this->db->num_rows();
55                        $this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
56
57                        $news = array();
58
59                        while($this->db->next_record())
60                        {
61                                $news[$this->db->f('news_id')] = array(
62                                        'subject' => @htmlspecialchars($this->db->f('news_subject', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()),
63                                        'submittedby' => $this->db->f('news_submittedby'),
64                                        'date'    => $this->db->f('news_date'),
65                                        'id'      => $this->db->f('news_id'),
66                                        'begin'   => $this->db->f('news_begin'),
67                                        'end'     => $this->db->f('news_end'),
68                                        'teaser'  => @htmlspecialchars($this->db->f('news_teaser', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()),
69                                        'content' => $this->db->f('news_content',True),
70                                        'is_html' => ($this->db->f('is_html') ? True : False),
71                                );
72                        }
73                        return $news;
74                }
75
76                function get_all_public_news($limit=5)
77                {
78                        $now = time();
79                        $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);
80
81                        $news = array();
82
83                        while ($this->db->next_record())
84                        {
85                                $news[$this->db->f('news_id')] = array(
86                                        'subject' => $this->db->f('news_subject', True),
87                                        'submittedby' => $this->db->f('news_submittedby'),
88                                        'date'    => $this->db->f('news_date'),
89                                        'id'      => $this->db->f('news_id'),
90                                        'teaser'  => $this->db->f('news_teaser', True),
91                                        'content' => $this->db->f('news_content', True),
92                                        'is_html' => ($this->db->f('is_html') ? True : False),
93                                );
94                        }
95                        return $news;
96                }
97
98                function add($news)
99                {
100                        $add_array = array(
101                                'news_date'                     => (int)$news['date'],
102                                'news_submittedby'      => $GLOBALS['phpgw_info']['user']['account_id'],
103                                'news_content'          => $news['content'],
104                                'news_subject'          => $news['subject'],
105                                'news_begin'            => (int)$news['begin'],
106                                'news_end'                      => (int)$news['end'],
107                                'news_teaser'           => $news['teaser'],
108                                'news_cat'                      => (int)$news['category'],
109                                'is_html'                       => (int)!!$news['is_html'],
110                        );
111                        $this->db->insert('phpgw_news', $add_array, '', __LINE__, __FILE__);
112
113                        return $this->db->get_last_insert_id('phpgw_news', 'news_id');
114                }
115
116                function edit($news)
117                {
118                        $update_array = array(
119                                'news_content'  => $news['content'],
120                                'news_subject'  => $news['subject'],
121                                'news_teaser'   => $news['teaser'],
122                                'news_begin'    => $news['begin'],
123                                'news_end'              => $news['end'],
124                                'news_cat'              => $news['category'],
125                                'is_html'               => $news['is_html'] ? 1 : 0,
126                        );
127                        $this->db->update('phpgw_news', $update_array, array('news_id' => (int)$news['id']), __LINE__, __FILE__);
128                }
129
130                function delete($news_id)
131                {
132                        $this->db->query('DELETE FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__);
133                }
134
135                function get_news($news_id)
136                {
137                        $this->db->query('SELECT * FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__);
138                        $this->db->next_record();
139
140                        $item = array(
141                                'id'       => $this->db->f('news_id'),
142                                'date'     => $this->db->f('news_date'),
143                                'subject'  => $this->db->f('news_subject', True),
144                                'submittedby' => $this->db->f('news_submittedby'),
145                                'teaser'   => $this->db->f('news_teaser', True),
146                                'content'  => $this->db->f('news_content', True),
147                                'begin'    => $this->db->f('news_begin'),
148                                'end'      => $this->db->f('news_end'),
149                                'category' => $this->db->f('news_cat'),
150                                'is_html'  => ($this->db->f('is_html') ? True : False),
151                        );
152                        return $item;
153                }
154
155//              function getlist($order,$sort,$cat_id)
156//              {
157//                      if ($order)
158//                      {
159//                              $ordermethod = ' ORDER BY ' . $this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
160//                      }
161//                      else
162//                      {
163//                              $ordermethod = ' ORDER BY news_date DESC';
164//                      }
165
166//                      $this->db->query('SELECT * FROM phpgw_news WHERE news_cat=' . (int)$cat_id . $ordermethod,__LINE__,__FILE__);
167//                      while ($this->db->next_record())
168//                      {
169//                              $items[] = array(
170//                                      'id'          => $this->db->f('news_id'),
171//                                      'date'        => $this->db->f('news_date'),
172//                                      'subject'     => $this->db->f('news_subject'),
173//                                      'submittedby' => $this->db->f('news_submittedby'),
174//                                      'content'     => $this->db->f('news_content'),
175//                                      'status'      => $this->db->f('news_status'),
176//                                      'cat'         => $this->db->f('news_cat')
177//                              );
178//                      }
179//                      return $items;
180//              }
181        }
Note: See TracBrowser for help on using the repository browser.