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

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

Implementação do FCKEDITOR na edição de artigos no news_admin, para permitir texto rico.

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