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

Revision 2, 19.0 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 uinews
17        {
18                var $start = 0;
19                var $query = '';
20                var $sort  = '';
21                var $order = '';
22                var $cat_id;
23                var $template;
24                var $bo;
25                var $news_data;
26                var $news_id;
27                var $sbox;
28                var $public_functions = array(
29                        'write_news'  => True,
30                        'add'         => True,
31                        'edit'        => True,
32                        'delete'      => True,
33                        'delete_item' => True,
34                        'read_news'      => True,
35                        'show_news_home' => True
36                );
37
38                function uinews()
39                {
40                        $this->nextmatchs = createobject('phpgwapi.nextmatchs');
41                        $this->template = $GLOBALS['phpgw']->template;
42                        $this->bo   = CreateObject('news_admin.bonews',True);
43                        $this->sbox = createObject('phpgwapi.sbox');
44                        $this->start = $this->bo->start;
45                        $this->query = $this->bo->query;
46                        $this->order = $this->bo->order;
47                        $this->sort = $this->bo->sort;
48                        $this->cat_id = $this->bo->cat_id;
49                }
50
51                //with $default, we are called from the news form
52                function selectlist($type,$default=false)
53                {
54                        $link_data['menuaction'] = ($type == 'read') ? 'news_admin.uinews.read_news' : 'news_admin.uinews.write_news';
55                        $link_data['start'] = 0;
56                        $right = ($type == 'read') ? PHPGW_ACL_READ : PHPGW_ACL_ADD;
57                        $selectlist = ($default === false) ? ('<option>' . lang($type . ' news') . '</option>') : '';
58                        foreach($this->bo->cats as $cat)
59                        {
60                                if($this->bo->acl->is_permitted($cat['id'],$right))
61                                {
62                                        $cat_id = (int)$cat['id'];
63                                        $link_data['cat_id'] = $cat_id;
64                                        $selectlist .= '<option value="';
65                                        $selectlist .= $default !== False ? $cat_id : $GLOBALS['phpgw']->link('/index.php',$link_data);
66                                        $selectlist .= '"';
67                                        $selectlist .= ($default === $cat_id) ? ' selected="selected"' : '';
68                                        $selectlist .= '>' . $cat['name'] . '</option>' . "\n";
69                                }
70                        }
71
72                        if (!$default)
73                        {
74                                if($type=='read' || $this->bo->acl->is_permitted('all',$right))
75                                {
76                                        $link_data['cat_id'] = 'all';
77                                        $selectlist .= '<option style="font-weight:bold" value="' . $GLOBALS['phpgw']->link('/index.php',$link_data) 
78                                                . '">' . lang('All news') . '</option>'  . "\n";
79                                }
80                        }
81                        return $selectlist;
82                }
83
84                function read_news()
85                {
86                        $limit = ($GLOBALS['phpgw_info']['common']['maxmatchs'] ? $GLOBALS['phpgw_info']['common']['maxmatchs'] : 5);
87
88                        $news_id = get_var('news_id',Array('GET'));
89
90                        $news = $news_id ? array($news_id => $this->bo->get_news($news_id)) : 
91                                $this->bo->get_newslist($this->cat_id,$this->start,'','',$limit,True);
92
93                        $this->template->set_file(array(
94                                'main' => 'read.tpl'
95                        ));
96                        $this->template->set_block('main','news_form');
97                        $this->template->set_block('main','row');
98                        $this->template->set_block('main','row_empty');
99
100                        $GLOBALS['phpgw']->common->phpgw_header();
101                        echo parse_navbar();
102                        $this->template->set_block('main','category');
103                        $var['lang_read'] = lang('Read');
104                        $var['lang_write'] = lang('Write');
105                        $var['readable'] = $this->selectlist('read');
106                        $var['maintainlink'] = (($this->cat_id != 'all') && $this->bo->acl->is_permitted($this->cat_id,PHPGW_ACL_ADD)) ?
107                                ('<a href="' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news&start=0&cat_id='.$this->cat_id)
108                                . '">' . lang('Maintain') . '</a>') : '';
109                        $var['cat_name'] = ($this->cat_id != 'all') ? $this->bo->catbo->id2name($this->cat_id) : lang('All news');
110                        $this->template->set_var($var);
111                        $this->template->parse('_category','category');
112
113                        $this->template->set_var('icon',$GLOBALS['phpgw']->common->image('news_admin','news-corner.gif'));
114
115                        foreach($news as $newsitem)
116                        {
117                                $var = Array(
118                                        'subject' => $newsitem['subject'],
119                                        'submitedby' => 'Submitted by ' . $GLOBALS['phpgw']->common->grab_owner_name($newsitem['submittedby']) . ' on ' . $GLOBALS['phpgw']->common->show_date($newsitem['date']),
120                                        'content' => $newsitem['content'],
121                                );
122
123                                $this->template->set_var($var);
124                                $this->template->parse('rows','row',True);
125                        }
126                        if ($this->start)
127                        {
128                                $link_data['menuaction'] = 'news_admin.uinews.read_news';
129                                $link_data['start'] = $this->start - $limit;
130                                $link_data['cat_id'] = $this->cat_id;
131                                $this->template->set_var('lesslink',
132                                        '<a href="' . $GLOBALS['phpgw']->link('/index.php',$link_data) . '">&lt;&lt;&lt;</a>'
133                                );
134                        }
135                        if ($this->bo->total > $this->start + $limit)
136                        {
137                                $link_data['menuaction'] = 'news_admin.uinews.read_news';
138                                $link_data['start'] = $this->start + $limit;
139                                $link_data['cat_id'] = $this->cat_id;
140                                $this->template->set_var('morelink',
141                                        '<a href="' . $GLOBALS['phpgw']->link('/index.php',$link_data) . '">' . lang('More news') . '</a>'
142                                );
143                        }
144                        if (! $this->bo->total)
145                        {
146                                $this->template->set_var('row_message',lang('No entries found'));
147                                $this->template->parse('rows','row_empty',True);
148                        }
149
150                        $this->template->pfp('_out','news_form');
151                }
152
153                //this is currently broken
154                function show_news_home()
155                {
156                        $title = '<font color="#FFFFFF">'.lang('News Admin').'</font>';
157                        $portalbox = CreateObject('phpgwapi.listbox',array(
158                                'title'     => $title,
159                                'primary'   => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
160                                'secondary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
161                                'tertiary'  => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
162                                'width'     => '100%',
163                                'outerborderwidth' => '0',
164                                'header_background_image' => $GLOBALS['phpgw']->common->image('phpgwapi/templates/default','bg_filler')
165                        ));
166
167                        $app_id = $GLOBALS['phpgw']->applications->name2id('news_admin');
168                        $GLOBALS['portal_order'][] = $app_id;
169
170                        $var = Array(
171                                'up'       => Array('url' => '/set_box.php', 'app' => $app_id),
172                                'down'     => Array('url' => '/set_box.php', 'app' => $app_id),
173                                'close'    => Array('url' => '/set_box.php', 'app' => $app_id),
174                                'question' => Array('url' => '/set_box.php', 'app' => $app_id),
175                                'edit'     => Array('url' => '/set_box.php', 'app' => $app_id)
176                        );
177
178                        while(list($key,$value) = each($var))
179                        {
180                                $portalbox->set_controls($key,$value);
181                        }
182
183                        $newslist = $this->bo->get_newslist($cat_id);
184
185                        $image_path = $GLOBALS['phpgw']->common->get_image_path('news_admin');
186
187                        if(is_array($newslist))
188                        {
189                        foreach($newslist as $newsitem)
190                        {
191                                $portalbox->data[] = array(
192                                        'text' => $newsitem['subject'] . ' - ' . lang('Submitted by') . ' ' . $GLOBALS['phpgw']->common->grab_owner_name($newsitem['submittedby']) . ' ' . lang('on') . ' ' . $GLOBALS['phpgw']->common->show_date($newsitem['date']),
193                                        'link' => $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.show_news&news_id=' . $newsitem['id'])
194                                );
195                        }
196                        }
197                        else
198                        {
199                                $portalbox->data[] = array('text' => lang('no news'));
200                        }
201
202                        $tmp = "\r\n"
203                                . '<!-- start News Admin -->' . "\r\n"
204                                . $portalbox->draw()
205                                . '<!-- end News Admin -->'. "\r\n";
206                        $this->template->set_var('phpgw_body',$tmp,True);
207                }
208
209                //the following function is unmaintained
210                function show_news_website($section='mid')
211                {
212                        $cat_id = $_GET['cat_id'];
213                        $start = $_GET['start'];
214                        $oldnews = $_GET['oldnews'];
215                        $news_id = $_GET['news_id'];
216
217                        if (! $cat_id)
218                        {
219                                $cat_id = 0;
220                        }
221
222                        $this->template->set_file(array(
223                                '_news' => 'news_' . $section . '.tpl'
224                        ));
225                        $this->template->set_block('_news','news_form');
226                        $this->template->set_block('_news','row');
227                        $this->template->set_block('_news','category');
228
229
230                        if($news_id)
231                        {
232                                $news = array($news_id => $this->bo->get_news($news_id));
233                        }
234                        else
235                        {
236                                $news = $this->bo->get_NewsList($cat_id,$oldnews,$start,$total);
237                        }
238
239                        $var = Array();
240
241                        $this->template->set_var('icon',$GLOBALS['phpgw']->common->image('news_admin','news-corner.gif'));
242
243                        foreach($news as $newsitem)
244                        {
245                                $var = Array(
246                                        'subject'=> $newsitem['subject'],
247                                        'submitedby' => 'Submitted by ' . $GLOBALS['phpgw']->common->grab_owner_name($newsitem['submittedby']) . ' on ' . $GLOBALS['phpgw']->common->show_date($newsitem['date']),
248                                        'content'    => nl2br($newsitem['content'])
249                                );
250
251                                $this->template->set_var($var);
252                                $this->template->parse('rows','row',True);
253                        }
254
255                        $out = $this->template->fp('out','news_form');
256
257                        if ($this->bo->total > 5 && ! $oldnews)
258                        {
259                                $link_values = array(
260                                        'menuaction'    => 'news_admin.uinews.show_news',
261                                        'oldnews'       => 'True',
262                                        'cat_id'        => $cat_id,
263                                        'category_list' => 'True'
264                                );
265
266                                $out .= '<center><a href="' . $GLOBALS['phpgw']->link('/index.php',$link_values) . '">View news archives</a></center>';
267                        }
268                        return $out;
269                }
270
271                function add()
272                {
273                        if($_POST['cancel'])
274                        {
275                                Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
276                                return;
277                        }
278                        if($_POST['submitit'])
279                        {
280                                $this->news_data = $_POST['news'];
281                                if(!$this->news_data['subject'])
282                                {
283                                        $errors[] = lang('The subject is missing');
284                                }
285                                if(!$this->news_data['content'])
286                                {
287                                        $errors[] = lang('The news content is missing');
288                                }
289                                if(!is_array($errors))
290                                {
291                                        $this->news_data['date'] = time();
292                                        $this->news_data['content'] = @htmlentities($this->news_data['content']);
293                                        $this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
294                                        $this->news_id = $this->bo->add($this->news_data);
295                                        if(!$this->news_id)
296                                        {
297                                                $this->message = lang('failed to add message');
298                                        }
299                                        else
300                                        {
301                                                $this->message = lang('Message has been added');
302                                                //after having added, we must switch to edit mode instead of stay in add
303                                                $this->modify('edit');
304                                                return;
305                                        }
306                                }
307                                else
308                                {
309                                        $this->message = $errors;
310                                }
311                        }
312                        else
313                        {
314                                $this->news_data['category'] = $this->cat_id;
315                        }
316                        $this->modify('add');
317                }
318
319                function delete()
320                {
321                        $news_id = $_POST['news_id'] ? $_POST['news_id'] : $_GET['news_id'];
322
323                        $GLOBALS['phpgw']->common->phpgw_header();
324                        echo parse_navbar();
325                        $this->template->set_file(array(
326                                'form' => 'admin_delete.tpl'
327                        ));
328                        $this->template->set_var('lang_message',lang('Are you sure you want to delete this entry ?'));
329                        $this->template->set_var('lang_yes',lang('Yes'));
330                        $this->template->set_var('lang_no',lang('No'));
331
332                        $this->template->set_var('link_yes',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.delete_item&news_id=' . $news_id));
333                        $this->template->set_var('link_no',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
334
335                        $this->template->pfp('_out','form');
336                }
337
338                function delete_item()
339                {
340                        $item = (int)get_var('news_id',array('GET','POST'));
341                        if($item)
342                        {
343                                $this->bo->delete($item);
344                                $msg = lang('Item has been deleted');
345                        }
346                        else
347                        {
348                                $msg = lang('Item not found');
349                        }
350                        $this->write_news($msg);
351                }
352
353                function edit()
354                {
355                        $this->news_data = $_POST['news'];
356                        $this->news_id   = (isset($_GET['news_id']) ? $_GET['news_id'] : $_POST['news']['id']);
357
358                        if($_POST['cancel'])
359                        {
360                          if(isset($this->news_data['category']))
361                          {
362                              Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news&cat_id='.$this->news_data['category']));
363                              return;
364                          }
365                          else
366                          {
367                              Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
368                              return;
369                          }
370                        }
371
372                        if(is_array($this->news_data))
373                        {
374                                if(!$this->news_data['subject'])
375                                {
376                                        $errors[] = lang('The subject is missing');
377                                }
378                                if(!$this->news_data['content'])
379                                {
380                                        $errors[] = lang('The news content is missing');
381                                }
382
383                                if(!is_array($errors))
384                                {
385                                        $this->news_data['content'] = @htmlentities($this->news_data['content']);
386                                        $this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
387                                        $this->bo->edit($this->news_data);
388                                        $this->message = lang('News item has been updated');
389                                }
390                                else
391                                {
392                                        $this->message = $errors;
393                                }
394                        }
395                        else
396                        {
397                                $this->news_data = $this->bo->get_news($this->news_id,True);
398                                $this->news_data['date_d'] = date('j',$this->news_data['begin']);
399                                $this->news_data['date_m'] = date('n',$this->news_data['begin']);
400                                $this->news_data['date_y'] = date('Y',$this->news_data['begin']);
401                        }
402                        $this->modify();
403                }
404
405                function modify($type = 'edit')
406                {
407                        $options = $this->bo->get_options($this->news_data);
408                        $GLOBALS['phpgw']->common->phpgw_header();
409                        echo parse_navbar();
410
411                        $this->template->set_file(array(
412                                'form' => 'admin_form.tpl'
413                        ));
414
415                        if(is_array($this->message))
416                        {
417                                $this->template->set_var('errors',$GLOBALS['phpgw']->common->error_list($this->message));
418                        }
419                        elseif($this->message)
420                        {
421                                $this->template->set_var('errors',$this->message);
422                        }
423
424                        $category_list = $this->selectlist('write', (int)$this->news_data['category']);
425
426                        $this->template->set_var('lang_header',lang($type . ' news item'));
427                        $this->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php',
428                                array('menuaction'      => 'news_admin.uinews.'.$type,
429                                                'news_id'       => $this->news_id
430                                        )
431                                )
432                        );
433                        $this->template->set_var(array(
434                                'form_button' => '<input type="submit" name="submitit" value="' . lang('save') . '">',
435                                'value_id' => $this->news_id,
436                                'done_button' => '<input type="submit" name="cancel" value="' . lang('Done') . '">',
437                                'label_subject' => lang('subject') . ':',
438                                'value_subject' => '<input name="news[subject]" size="60" value="' . @htmlspecialchars($this->news_data['subject'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()) . '">',
439                                'label_teaser' => lang('teaser') . ':',
440                                'value_teaser' => '<input name="news[teaser]" size="60" value="' . @htmlspecialchars($this->news_data['teaser'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()) . '" maxLength="100">',
441                                'label_content' => lang('Content') . ':',
442                                'value_content' => '<textarea cols="60" rows="6" name="news[content]" wrap="virtual">' . $this->news_data['content'] . '</textarea>',
443                                'label_category' => lang('Category') . ':',
444                                'value_category' => '<select name="news[category]">' . $this->selectlist('write', (int)$this->news_data['category']) . '</select>',
445                                'label_visible' => lang('Visible') . ':',
446                                'value_begin_d' =>  $this->sbox->getDays('news[begin_d]',date('j',$this->news_data['begin'])),
447                                'value_begin_m' =>  $this->sbox->getMonthText('news[begin_m]',date('n',$this->news_data['begin'])),
448                                'value_begin_y' =>  $this->sbox->getYears('news[begin_y]',date('Y',$this->news_data['begin']),date('Y')),
449                                'select_from' => $options['from'],
450                                'select_until' => $options['until'],
451                                'value_end_d' =>  $this->sbox->getDays('news[end_d]',date('j',$this->news_data['end'])) ,
452                                'value_end_m' =>  $this->sbox->getMonthText('news[end_m]',date('n',$this->news_data['end'])),
453                                'value_end_y' =>  $this->sbox->getYears('news[end_y]',date('Y',$this->news_data['end']),date('Y')),
454                                'label_is_html' => lang('Contains HTML'),
455                                'value_is_html' => '<input type="checkbox" value="1" name="news[is_html]"' . ($this->news_data['is_html'] ? ' checked="1"' : '') .'>',
456                        ));
457                       
458                        $this->template->pfp('out','form');
459                }
460               
461                function write_news($message = '')
462                {
463                        $this->template->set_file(array(
464                                'main' => 'write.tpl'
465                        ));
466                        $this->template->set_block('main','list');
467                        $this->template->set_block('main','row');
468                        $this->template->set_block('main','row_empty');
469
470                        $GLOBALS['phpgw']->common->phpgw_header();
471                        echo parse_navbar();
472                        $this->template->set_block('main','category');
473                        $var['lang_read'] = lang('Read');
474                        $var['lang_write'] = lang('Write');
475                        $var['readable'] = $this->selectlist('read');
476                        $var['cat_name'] = $this->cat_id ? $this->bo->catbo->id2name($this->cat_id) : lang('Global news');
477
478                        $this->template->set_var($var);
479                        $this->template->parse('_category','category');
480
481                        if ($message)
482                        {
483                                $this->template->set_var('message',$message);
484                        }
485
486                        $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'));
487                        $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'));
488                        $this->template->set_var('header_status',lang('Visible'));
489                        $this->template->set_var('header_edit',lang('Edit'));
490                        $this->template->set_var('header_delete',lang('Delete'));
491                        $this->template->set_var('header_view',lang('View'));
492
493                        $items      = $this->bo->get_newslist($this->cat_id,$this->start,$this->order,$this->sort);
494
495                        $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');
496                        $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');
497                       
498                        $this->template->set_var(array(
499                                'left' => $left,
500                                'right' => $right,
501                                'lang_showing' => $this->nextmatchs->show_hits($this->bo->total,$this->start),
502                        ));
503
504                        foreach($items as $item)
505                        {
506                                $this->nextmatchs->template_alternate_row_color($this->template);
507                                $this->template->set_var('row_date',$GLOBALS['phpgw']->common->show_date($item['date']));
508                                if(strlen($item['news_subject']) > 40)
509                                {
510                                        $subject = $GLOBALS['phpgw']->strip_html(substr($item['subject'],40,strlen($item['subject'])));
511                                }
512                                else
513                                {
514                                        $subject = $GLOBALS['phpgw']->strip_html($item['subject']);
515                                }
516                                $this->template->set_var('row_subject',$subject);
517                                $this->template->set_var('row_status',$this->bo->get_visibility($item));
518
519                                $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>');
520                                $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>');
521                                $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>');
522
523                                $this->template->parse('rows','row',True);
524                        }
525
526                        if(!$this->bo->total)
527                        {
528                                $this->nextmatchs->template_alternate_row_color($this->template);
529                                $this->template->set_var('row_message',lang('No entries found'));
530                                $this->template->parse('rows','row_empty',True);
531                        }
532
533                        $this->template->set_var('link_add',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.add'));
534                        $this->template->set_var('lang_add',lang('Add new news'));
535
536                        $this->template->pfp('out','list');
537                }
538        }
539?>
Note: See TracBrowser for help on using the repository browser.