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 bonews |
---|
17 | { |
---|
18 | var $sonews; |
---|
19 | var $acl; |
---|
20 | var $start = 0; |
---|
21 | var $query = ''; |
---|
22 | var $sort = ''; |
---|
23 | var $cat_id; |
---|
24 | var $total = 0; |
---|
25 | var $debug; |
---|
26 | var $use_session = False; |
---|
27 | var $unixtimestampmax; |
---|
28 | var $dateformat; |
---|
29 | var $cats = array(); |
---|
30 | |
---|
31 | function bonews($session=False) |
---|
32 | { |
---|
33 | $this->acl = CreateObject('news_admin.boacl'); |
---|
34 | $this->sonews = CreateObject('news_admin.sonews'); |
---|
35 | $this->accounts = $GLOBALS['phpgw']->accounts->get_list('groups'); |
---|
36 | $this->debug = False; |
---|
37 | if($session) |
---|
38 | { |
---|
39 | $this->read_sessiondata(); |
---|
40 | $this->use_session = True; |
---|
41 | foreach(array('start','query','sort','order','cat_id') as $var) |
---|
42 | { |
---|
43 | $this->$var = get_var($var, array('POST', 'GET'), ''); |
---|
44 | } |
---|
45 | |
---|
46 | $this->cat_id = $this->cat_id ? $this->cat_id : 'all'; |
---|
47 | $this->save_sessiondata(); |
---|
48 | } |
---|
49 | $this->catbo = createobject('phpgwapi.categories','','news_admin'); |
---|
50 | $this->cats = $this->catbo->return_array('all',0,False,'','','cat_name',True); |
---|
51 | settype($this->cats,'array'); |
---|
52 | //change this around 19 Jan 2038 03:14:07 GMT |
---|
53 | $this->unixtimestampmax = 2147483647; |
---|
54 | $this->dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; |
---|
55 | } |
---|
56 | |
---|
57 | function save_sessiondata() |
---|
58 | { |
---|
59 | $data = array( |
---|
60 | 'start' => $this->start, |
---|
61 | 'query' => $this->query, |
---|
62 | 'sort' => $this->sort, |
---|
63 | 'order' => $this->order, |
---|
64 | 'cat_id' => $this->cat_id, |
---|
65 | ); |
---|
66 | if($this->debug) { echo '<br>Save:'; _debug_array($data); } |
---|
67 | $GLOBALS['phpgw']->session->appsession('session_data','news_admin',$data); |
---|
68 | } |
---|
69 | |
---|
70 | function read_sessiondata() |
---|
71 | { |
---|
72 | $data = $GLOBALS['phpgw']->session->appsession('session_data','news_admin'); |
---|
73 | if($this->debug) { echo '<br>Read:'; _debug_array($data); } |
---|
74 | |
---|
75 | $this->start = $data['start']; |
---|
76 | $this->query = $data['query']; |
---|
77 | $this->sort = $data['sort']; |
---|
78 | $this->order = $data['order']; |
---|
79 | $this->cat_id = $data['cat_id']; |
---|
80 | } |
---|
81 | |
---|
82 | function get_newslist($cat_id, $start=0, $order='',$sort='',$limit=0,$activeonly=False) |
---|
83 | { |
---|
84 | $charset = $GLOBALS['phpgw']->translation->charset(); |
---|
85 | |
---|
86 | $cats = False; |
---|
87 | if ($cat_id == 'all') |
---|
88 | { |
---|
89 | foreach($this->cats as $cat) |
---|
90 | { |
---|
91 | if ($this->acl->is_readable($cat['id'])) |
---|
92 | { |
---|
93 | $cats[] = $cat['id']; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | elseif($this->acl->is_readable($cat_id)) |
---|
98 | { |
---|
99 | $cats = $cat_id; |
---|
100 | } |
---|
101 | |
---|
102 | if($cats) |
---|
103 | { |
---|
104 | $news = $this->sonews->get_newslist($cats, $start,$order,$sort,$limit,$activeonly,$this->total); |
---|
105 | foreach($news as $id => $item) |
---|
106 | { |
---|
107 | $news[$id]['content'] = ($item['is_html'] ? |
---|
108 | $item['content'] : |
---|
109 | nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset) |
---|
110 | )); |
---|
111 | } |
---|
112 | return $news; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | return array(); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | function get_all_public_news($limit = 5) |
---|
121 | { |
---|
122 | $charset = $GLOBALS['phpgw']->translation->charset(); |
---|
123 | |
---|
124 | $news = $this->sonews->get_all_public_news($limit); |
---|
125 | foreach($news as $id => $item) |
---|
126 | { |
---|
127 | $news[$id]['content'] = ($item['is_html'] ? |
---|
128 | $item['content'] : |
---|
129 | nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset) |
---|
130 | )); |
---|
131 | } |
---|
132 | return $news; |
---|
133 | } |
---|
134 | |
---|
135 | function delete($news_id) |
---|
136 | { |
---|
137 | $this->sonews->delete($news_id); |
---|
138 | } |
---|
139 | |
---|
140 | function add($news) |
---|
141 | { |
---|
142 | return $this->acl->is_writeable($news['category']) ? |
---|
143 | $this->sonews->add($news) : |
---|
144 | false; |
---|
145 | } |
---|
146 | |
---|
147 | function edit($news) |
---|
148 | { |
---|
149 | $oldnews = $this->sonews->get_news($news['id']); |
---|
150 | return ($this->acl->is_writeable($oldnews['category']) && |
---|
151 | $this->acl->is_writeable($news['category'])) ? |
---|
152 | $this->sonews->edit($news) : |
---|
153 | False; |
---|
154 | } |
---|
155 | |
---|
156 | function get_visibility(&$news) |
---|
157 | { |
---|
158 | $now = time(); |
---|
159 | |
---|
160 | if ($news['end'] < $now) |
---|
161 | { |
---|
162 | return lang('Never'); |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | if ($news['begin'] < $now) |
---|
167 | { |
---|
168 | if ($news['end'] == $this->unixtimestampmax) |
---|
169 | { |
---|
170 | return lang('Always'); |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | return lang('until') . date($this->dateformat,$news['end']); |
---|
175 | } |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | if ($news['end'] == $this->unixtimestampmax) |
---|
180 | { |
---|
181 | return lang('from') . date($this->dateformat,$news['begin']); |
---|
182 | |
---|
183 | } |
---|
184 | else |
---|
185 | { |
---|
186 | return lang('from') . ' ' . date($this->dateformat,$news['begin']) . ' ' . |
---|
187 | lang('until') . ' ' . date($this->dateformat,$news['end']); |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | //return the selectboxes with calculated defaults, and change begin and end by sideaffect |
---|
194 | function get_options(&$news) |
---|
195 | { |
---|
196 | $now = time(); |
---|
197 | //always is default |
---|
198 | if (!isset($news['begin'])) |
---|
199 | { |
---|
200 | //these are only displayed values not necessarily the ones that will get stored |
---|
201 | $news['begin'] = $now; |
---|
202 | $news['end'] = $now; |
---|
203 | $from = 1; |
---|
204 | $until = 1; |
---|
205 | } |
---|
206 | //if enddate is in the past set option to never |
---|
207 | elseif ($news['end'] < $now) |
---|
208 | { |
---|
209 | $news['begin'] = $now; |
---|
210 | $news['end'] = $now; |
---|
211 | $from = 0; |
---|
212 | $until = 1; |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | if ($news['begin'] < $now) |
---|
217 | { |
---|
218 | $news['begin'] = $now; |
---|
219 | if ($news['end'] == $this->unixtimestampmax) |
---|
220 | { |
---|
221 | $news['end'] = $now; |
---|
222 | $from = 1; |
---|
223 | $until = 1; |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | $from = 0.5; |
---|
228 | $until = 0.5; |
---|
229 | } |
---|
230 | } |
---|
231 | else |
---|
232 | { |
---|
233 | if ($news['end'] == $this->unixtimestampmax) |
---|
234 | { |
---|
235 | $news['end'] = $now; |
---|
236 | $from = 0.5; |
---|
237 | $until = 1; |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | $from = 0.5; |
---|
242 | $until = 0.5; |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | $options['from'] = '<option value="1"' . (($from == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>'; |
---|
247 | $options['from'] .= '<option value="0"' . (($from == 0) ? ' selected="selected"' : '') . '>' . lang('Never') . '</option>'; |
---|
248 | $options['from'] .= '<option value="0.5"' . (($from == 0.5) ? ' selected="selected"' : '') . '>' . lang('From') . '</option>'; |
---|
249 | $options['until'] = '<option value="1"' . (($until == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>'; |
---|
250 | $options['until'] .= '<option value="0.5"' . (($until == 0.5) ? ' selected="selected"' : '') . '>' . lang('until') . '</option>'; |
---|
251 | return $options; |
---|
252 | } |
---|
253 | |
---|
254 | //set the begin and end dates |
---|
255 | function set_dates($from,$until,&$news) |
---|
256 | { |
---|
257 | switch($from) |
---|
258 | { |
---|
259 | //always |
---|
260 | case 1: |
---|
261 | $news['begin'] = $news['date']; |
---|
262 | $news['end'] = $this->unixtimestampmax; |
---|
263 | break; |
---|
264 | //never |
---|
265 | case 0: |
---|
266 | $news['begin'] = 0; |
---|
267 | $news['end'] = 0; |
---|
268 | break; |
---|
269 | default: |
---|
270 | $news['begin'] = mktime(0,0,0,(int)$news['begin_m'], (int)$news['begin_d'], (int)$news['begin_y']); |
---|
271 | switch($until) |
---|
272 | { |
---|
273 | case 1: |
---|
274 | $news['end'] = $this->unixtimestampmax; |
---|
275 | break; |
---|
276 | default: |
---|
277 | $news['end'] = mktime(0,0,0,(int)$news['end_m'], (int)$news['end_d'], (int)$news['end_y']); |
---|
278 | } |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | // function format_fields($fields) |
---|
283 | // { |
---|
284 | // $cat = createobject('phpgwapi.categories','news_admin'); |
---|
285 | |
---|
286 | // $item = array( |
---|
287 | // 'id' => $fields['id'], |
---|
288 | // 'date' => $GLOBALS['phpgw']->common->show_date($fields['date']), |
---|
289 | // 'subject' => $GLOBALS['phpgw']->strip_html($fields['subject']), |
---|
290 | // 'submittedby' => $fields['submittedby'], |
---|
291 | // 'content' => $fields['content'], |
---|
292 | // 'status' => lang($fields['status']), |
---|
293 | // 'cat' => $cat->id2name($fields['cat']) |
---|
294 | // ); |
---|
295 | // return $item; |
---|
296 | // } |
---|
297 | |
---|
298 | function get_news($news_id) |
---|
299 | { |
---|
300 | $news = $this->sonews->get_news($news_id); |
---|
301 | |
---|
302 | if ($this->acl->is_readable($news['category'])) |
---|
303 | { |
---|
304 | $this->total = 1; |
---|
305 | $news['content'] = ($news['is_html'] ? |
---|
306 | $news['content']: |
---|
307 | nl2br(htmlspecialchars($news['content'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()) |
---|
308 | )); |
---|
309 | return $news; |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | return False; |
---|
314 | } |
---|
315 | } |
---|
316 | } |
---|
317 | ?> |
---|