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

Revision 49, 19.6 KB checked in by niltonneto, 17 years ago (diff)

Adicionado fckeditor para edição de notícias.

  • 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                                $_POST['news']['is_html'] = '1';
281                                $this->news_data = $_POST['news'];
282                                if(!$this->news_data['subject'])
283                                {
284                                        $errors[] = lang('The subject is missing.');
285                                }
286                                if(!$this->news_data['content'])
287                                {
288                                        $errors[] = lang('The news content is missing.');
289                                }
290                                if(!is_array($errors))
291                                {
292                                        $this->news_data['date'] = time();
293                                       
294                                        $this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
295                                        $this->news_id = $this->bo->add($this->news_data);
296                                        if(!$this->news_id)
297                                        {
298                                                $this->message = lang('failed to add message');
299                                        }
300                                        else
301                                        {
302                                                $this->message = lang('Message has been added');
303                                                //after having added, we must switch to edit mode instead of stay in add
304                                                $this->modify('edit');
305                                                return;
306                                        }
307                                }
308                                else
309                                {
310                                        $this->message = $errors;
311                                }
312                        }
313                        else
314                        {
315                                $this->news_data['category'] = $this->cat_id;
316                        }
317                        $this->modify('add');
318                }
319
320                function delete()
321                {
322                        $news_id = $_POST['news_id'] ? $_POST['news_id'] : $_GET['news_id'];
323
324                        $GLOBALS['phpgw']->common->phpgw_header();
325                        echo parse_navbar();
326                        $this->template->set_file(array(
327                                'form' => 'admin_delete.tpl'
328                        ));
329                        $this->template->set_var('lang_message',lang('Are you sure you want to delete this entry ?'));
330                        $this->template->set_var('lang_yes',lang('Yes'));
331                        $this->template->set_var('lang_no',lang('No'));
332
333                        $this->template->set_var('link_yes',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.delete_item&news_id=' . $news_id));
334                        $this->template->set_var('link_no',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
335
336                        $this->template->pfp('_out','form');
337                }
338
339                function delete_item()
340                {
341                        $item = (int)get_var('news_id',array('GET','POST'));
342                        if($item)
343                        {
344                                $this->bo->delete($item);
345                                $msg = lang('Item has been deleted');
346                        }
347                        else
348                        {
349                                $msg = lang('Item not found');
350                        }
351                        $this->write_news($msg);
352                }
353
354                function edit()
355                {
356                        $this->news_data = $_POST['news'];
357                        $this->news_id   = (isset($_GET['news_id']) ? $_GET['news_id'] : $_POST['news']['id']);
358
359                        if($_POST['cancel'])
360                        {
361                          if(isset($this->news_data['category']))
362                          {
363                              Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news&cat_id='.$this->news_data['category']));
364                              return;
365                          }
366                          else
367                          {
368                              Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.write_news'));
369                              return;
370                          }
371                        }
372
373                        if(is_array($this->news_data))
374                        {
375                                if(!$this->news_data['subject'])
376                                {
377                                        $errors[] = lang('The subject is missing');
378                                }
379                                if(!$this->news_data['content'])
380                                {
381                                        $errors[] = lang('The news content is missing');
382                                }
383
384                                if(!is_array($errors))
385                                {
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                        include_once("fckeditor.php");
408                       
409                        $options = $this->bo->get_options($this->news_data);
410                        $GLOBALS['phpgw']->common->phpgw_header();
411                        echo parse_navbar();
412
413                        $this->template->set_file(array(
414                                'form' => 'admin_form.tpl'
415                        ));
416
417                        if(is_array($this->message))
418                        {
419                                $this->template->set_var('errors',$GLOBALS['phpgw']->common->error_list($this->message));
420                        }
421                        elseif($this->message)
422                        {
423                                $this->template->set_var('errors',$this->message);
424                        }
425
426                        $category_list = $this->selectlist('write', (int)$this->news_data['category']);
427                       
428                        if ($category_list == '')
429                                $this->deny();
430
431                        $this->template->set_var('lang_header',lang($type . ' news item'));
432                        $this->template->set_var('form_action',$GLOBALS['phpgw']->link('/index.php',
433                                array('menuaction'      => 'news_admin.uinews.'.$type,
434                                                'news_id'       => $this->news_id
435                                        )
436                                )
437                        );
438                       
439                        $oFCKeditor = new FCKeditor('news[content]') ;
440                        $oFCKeditor->BasePath = 'news_admin/templates/celepar/fckeditor/';
441                        $oFCKeditor->ToolbarSet = 'ExpressoLivre';
442                        $oFCKeditor->Value = $this->news_data['content'];
443                       
444                        $this->template->set_var(array(
445                                'form_button' => '<input type="submit" name="submitit" value="' . lang('save') . '">',
446                                'value_id' => $this->news_id,
447                                'done_button' => '<input type="submit" name="cancel" value="' . lang('Done') . '">',
448                                'label_subject' => lang('subject') . ':',
449                                'value_subject' => '<input name="news[subject]" autocomplete="off" size="60" value="' . @htmlspecialchars($this->news_data['subject'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()) . '">',
450                                'label_teaser' => lang('teaser') . ':',
451                                'value_teaser' => '<input name="news[teaser]" autocomplete="off" size="60" value="' . @htmlspecialchars($this->news_data['teaser'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()) . '" maxLength="100">',
452                                'label_content' => lang('Content') . ':',
453                                //'value_content' => '<textarea cols="60" rows="6" name="news[content]" wrap="virtual">' . $this->news_data['content'] . '</textarea>',
454                                'value_content' => $oFCKeditor->Create(),
455                                'label_category' => lang('Category') . ':',
456                                'value_category' => '<select name="news[category]">' . $this->selectlist('write', (int)$this->news_data['category']) . '</select>',
457                                'label_visible' => lang('Visible') . ':',
458                                'value_begin_d' =>  $this->sbox->getDays('news[begin_d]',date('j',$this->news_data['begin'])),
459                                'value_begin_m' =>  $this->sbox->getMonthText('news[begin_m]',date('n',$this->news_data['begin'])),
460                                'value_begin_y' =>  $this->sbox->getYears('news[begin_y]',date('Y',$this->news_data['begin']),date('Y')),
461                                'select_from' => $options['from'],
462                                'select_until' => $options['until'],
463                                'value_end_d' =>  $this->sbox->getDays('news[end_d]',date('j',$this->news_data['end'])) ,
464                                'value_end_m' =>  $this->sbox->getMonthText('news[end_m]',date('n',$this->news_data['end'])),
465                                'value_end_y' =>  $this->sbox->getYears('news[end_y]',date('Y',$this->news_data['end']),date('Y')),
466                                'label_is_html' => lang('Contains HTML'),
467                                'value_is_html' => '<input type="checkbox" value="1" name="news[is_html]  checked="1""' . ($this->news_data['is_html'] ? ' checked="1"' : '') .'>',
468                        ));
469                       
470                        $this->template->pfp('out','form');
471                }
472               
473                function write_news($message = '')
474                {
475                        $this->template->set_file(array(
476                                'main' => 'write.tpl'
477                        ));
478                        $this->template->set_block('main','list');
479                        $this->template->set_block('main','row');
480                        $this->template->set_block('main','row_empty');
481
482                        $GLOBALS['phpgw']->common->phpgw_header();
483                        echo parse_navbar();
484
485                        $category_list = $this->selectlist('write', (int)$this->news_data['category']);
486                        if ($category_list == '')
487                                $this->deny();
488
489                        $this->template->set_block('main','category');
490                        $var['lang_read'] = lang('Read');
491                        $var['lang_write'] = lang('Write');
492                        $var['readable'] = $this->selectlist('read');
493                        $var['cat_name'] = $this->cat_id ? $this->bo->catbo->id2name($this->cat_id) : lang('Global news');
494
495                        $this->template->set_var($var);
496                        $this->template->parse('_category','category');
497
498                        if ($message)
499                        {
500                                $this->template->set_var('message',$message);
501                        }
502
503                        $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'));
504                        $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'));
505                        $this->template->set_var('header_status',lang('Visible'));
506                        $this->template->set_var('header_edit',lang('Edit'));
507                        $this->template->set_var('header_delete',lang('Delete'));
508                        $this->template->set_var('header_view',lang('View'));
509
510                        $items      = $this->bo->get_newslist($this->cat_id,$this->start,$this->order,$this->sort);
511
512                        $left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');
513                        $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=news_admin.uinews.write_news');
514                       
515                        $this->template->set_var(array(
516                                'left' => $left,
517                                'right' => $right,
518                                'lang_showing' => $this->nextmatchs->show_hits($this->bo->total,$this->start),
519                        ));
520
521                        foreach($items as $item)
522                        {
523                                $this->nextmatchs->template_alternate_row_color($this->template);
524                                $this->template->set_var('row_date',$GLOBALS['phpgw']->common->show_date($item['date']));
525                                if(strlen($item['news_subject']) > 40)
526                                {
527                                        $subject = $GLOBALS['phpgw']->strip_html(substr($item['subject'],40,strlen($item['subject'])));
528                                }
529                                else
530                                {
531                                        $subject = $GLOBALS['phpgw']->strip_html($item['subject']);
532                                }
533                                $this->template->set_var('row_subject',$subject);
534                                $this->template->set_var('row_status',$this->bo->get_visibility($item));
535
536                                $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>');
537                                $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>');
538                                $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>');
539
540                                $this->template->parse('rows','row',True);
541                        }
542
543                        if(!$this->bo->total)
544                        {
545                                $this->nextmatchs->template_alternate_row_color($this->template);
546                                $this->template->set_var('row_message',lang('No entries found'));
547                                $this->template->parse('rows','row_empty',True);
548                        }
549
550                        $this->template->set_var('link_add',$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.uinews.add'));
551                        $this->template->set_var('lang_add',lang('Add new news'));
552
553                        $this->template->pfp('out','list');
554                }
555               
556                function deny()
557                {
558                        echo '<p><center><b>'.lang('Access not permitted').'</b></center>';
559                        $GLOBALS['phpgw']->common->phpgw_exit(True);
560                }
561
562        }
563?>
Note: See TracBrowser for help on using the repository browser.