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 | $sql_count = 'SELECT count(*) as total FROM phpgw_news WHERE news_cat ' . $filter; |
---|
47 | if($activeonly) |
---|
48 | { |
---|
49 | $now = time(); |
---|
50 | $filter_plus = " AND news_begin<=$now AND news_end>=$now"; |
---|
51 | $sql .= $filter_plus; |
---|
52 | $sql_count.= $filter_plus; |
---|
53 | } |
---|
54 | $sql .= $ordermethod; |
---|
55 | |
---|
56 | $this->db->query($sql_count,__LINE__,__FILE__); |
---|
57 | if($this->db->next_record()) |
---|
58 | $total = $this->db->f('total'); |
---|
59 | else |
---|
60 | $total=0; |
---|
61 | $this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit); |
---|
62 | |
---|
63 | $news = array(); |
---|
64 | |
---|
65 | while($this->db->next_record()) |
---|
66 | { |
---|
67 | $news[$this->db->f('news_id')] = array( |
---|
68 | 'subject' => @htmlspecialchars($this->db->f('news_subject', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()), |
---|
69 | 'submittedby' => $this->db->f('news_submittedby'), |
---|
70 | 'date' => $this->db->f('news_date'), |
---|
71 | 'id' => $this->db->f('news_id'), |
---|
72 | 'begin' => $this->db->f('news_begin'), |
---|
73 | 'end' => $this->db->f('news_end'), |
---|
74 | 'teaser' => @htmlspecialchars($this->db->f('news_teaser', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()), |
---|
75 | 'content' => $this->db->f('news_content',True), |
---|
76 | 'is_html' => ($this->db->f('is_html') ? True : False), |
---|
77 | ); |
---|
78 | } |
---|
79 | return $news; |
---|
80 | } |
---|
81 | |
---|
82 | function get_all_public_news($limit=5) |
---|
83 | { |
---|
84 | $now = time(); |
---|
85 | $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); |
---|
86 | |
---|
87 | $news = array(); |
---|
88 | |
---|
89 | while ($this->db->next_record()) |
---|
90 | { |
---|
91 | $news[$this->db->f('news_id')] = array( |
---|
92 | 'subject' => $this->db->f('news_subject', True), |
---|
93 | 'submittedby' => $this->db->f('news_submittedby'), |
---|
94 | 'date' => $this->db->f('news_date'), |
---|
95 | 'id' => $this->db->f('news_id'), |
---|
96 | 'teaser' => $this->db->f('news_teaser', True), |
---|
97 | 'content' => $this->db->f('news_content', True), |
---|
98 | 'is_html' => ($this->db->f('is_html') ? True : False), |
---|
99 | ); |
---|
100 | } |
---|
101 | return $news; |
---|
102 | } |
---|
103 | |
---|
104 | function add($news) |
---|
105 | { |
---|
106 | $add_array = array( |
---|
107 | 'news_date' => (int)$news['date'], |
---|
108 | 'news_submittedby' => $GLOBALS['phpgw_info']['user']['account_id'], |
---|
109 | 'news_content' => $news['content'], |
---|
110 | 'news_subject' => $news['subject'], |
---|
111 | 'news_begin' => (int)$news['begin'], |
---|
112 | 'news_end' => (int)$news['end'], |
---|
113 | 'news_teaser' => $news['teaser'], |
---|
114 | 'news_cat' => (int)$news['category'], |
---|
115 | 'is_html' => (int)!!$news['is_html'], |
---|
116 | ); |
---|
117 | $this->db->insert('phpgw_news', $add_array, '', __LINE__, __FILE__); |
---|
118 | |
---|
119 | return $this->db->get_last_insert_id('phpgw_news', 'news_id'); |
---|
120 | } |
---|
121 | |
---|
122 | function edit($news) |
---|
123 | { |
---|
124 | $update_array = array( |
---|
125 | 'news_content' => $news['content'], |
---|
126 | 'news_subject' => $news['subject'], |
---|
127 | 'news_teaser' => $news['teaser'], |
---|
128 | 'news_begin' => $news['begin'], |
---|
129 | 'news_end' => $news['end'], |
---|
130 | 'news_cat' => $news['category'], |
---|
131 | 'is_html' => $news['is_html'] ? 1 : 0, |
---|
132 | ); |
---|
133 | $this->db->update('phpgw_news', $update_array, array('news_id' => (int)$news['id']), __LINE__, __FILE__); |
---|
134 | } |
---|
135 | |
---|
136 | function delete($news_id) |
---|
137 | { |
---|
138 | $this->db->query('DELETE FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__); |
---|
139 | } |
---|
140 | |
---|
141 | function get_news($news_id) |
---|
142 | { |
---|
143 | $this->db->query('SELECT * FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__); |
---|
144 | $this->db->next_record(); |
---|
145 | |
---|
146 | $item = array( |
---|
147 | 'id' => $this->db->f('news_id'), |
---|
148 | 'date' => $this->db->f('news_date'), |
---|
149 | 'subject' => $this->db->f('news_subject', True), |
---|
150 | 'submittedby' => $this->db->f('news_submittedby'), |
---|
151 | 'teaser' => $this->db->f('news_teaser', True), |
---|
152 | 'content' => $this->db->f('news_content', True), |
---|
153 | 'begin' => $this->db->f('news_begin'), |
---|
154 | 'end' => $this->db->f('news_end'), |
---|
155 | 'category' => $this->db->f('news_cat'), |
---|
156 | 'is_html' => ($this->db->f('is_html') ? True : False), |
---|
157 | ); |
---|
158 | return $item; |
---|
159 | } |
---|
160 | |
---|
161 | // function getlist($order,$sort,$cat_id) |
---|
162 | // { |
---|
163 | // if ($order) |
---|
164 | // { |
---|
165 | // $ordermethod = ' ORDER BY ' . $this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort); |
---|
166 | // } |
---|
167 | // else |
---|
168 | // { |
---|
169 | // $ordermethod = ' ORDER BY news_date DESC'; |
---|
170 | // } |
---|
171 | |
---|
172 | // $this->db->query('SELECT * FROM phpgw_news WHERE news_cat=' . (int)$cat_id . $ordermethod,__LINE__,__FILE__); |
---|
173 | // while ($this->db->next_record()) |
---|
174 | // { |
---|
175 | // $items[] = array( |
---|
176 | // 'id' => $this->db->f('news_id'), |
---|
177 | // 'date' => $this->db->f('news_date'), |
---|
178 | // 'subject' => $this->db->f('news_subject'), |
---|
179 | // 'submittedby' => $this->db->f('news_submittedby'), |
---|
180 | // 'content' => $this->db->f('news_content'), |
---|
181 | // 'status' => $this->db->f('news_status'), |
---|
182 | // 'cat' => $this->db->f('news_cat') |
---|
183 | // ); |
---|
184 | // } |
---|
185 | // return $items; |
---|
186 | // } |
---|
187 | } |
---|