[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: news_admin/inc class.bo.inc.php,1.1.2.2,1.1.2.3
From: |
Michael Totschnig <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: news_admin/inc class.bo.inc.php,1.1.2.2,1.1.2.3 class.so.inc.php,1.1.2.2,1.1.2.3 class.ui.inc.php,1.1.2.2,1.1.2.3 |
Date: |
Sat, 28 Jun 2003 00:33:49 -0400 |
Update of /cvsroot/phpgroupware/news_admin/inc
In directory subversions:/tmp/cvs-serv10181/inc
Modified Files:
Tag: Version-0_9_16-branch
class.bo.inc.php class.so.inc.php class.ui.inc.php
Log Message:
restrict visibility of news item with start and end date
make news_date again the exact timestamp of the creation date
Index: class.bo.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/news_admin/inc/class.bo.inc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** class.bo.inc.php 23 Jun 2003 22:56:30 -0000 1.1.2.2
--- class.bo.inc.php 28 Jun 2003 04:33:47 -0000 1.1.2.3
***************
*** 26,29 ****
--- 26,31 ----
var $debug;
var $use_session = False;
+ var $unixtimestampmax;
+ var $dateformat;
function bo($session=False)
***************
*** 48,55 ****
--- 50,61 ----
}
}
+ $this->cat_id = $this->cat_id ? $this->cat_id :
'all';
$this->save_sessiondata();
}
$this->catbo =
createobject('phpgwapi.categories','','news_admin');
$this->cats =
$this->catbo->return_array('all',0,False,'','','cat_name',True);
+ //change this around 19 Jan 2038 03:14:07 GMT
+ $this->unixtimestampmax = 2147483647;
+ $this->dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
}
***************
*** 122,126 ****
function edit($news)
{
! $oldnews = $this->so->get_news($news['id']);
return ($this->acl->is_writeable($oldnews['category'])
&&
$this->acl->is_writeable($news['category'])) ?
--- 128,132 ----
function edit($news)
{
! $oldnews = $this->sonews->get_news($news['id']);
return ($this->acl->is_writeable($oldnews['category'])
&&
$this->acl->is_writeable($news['category'])) ?
***************
*** 129,132 ****
--- 135,264 ----
}
+ function get_visibility(&$news)
+ {
+ $now = time();
+
+ if ($news['end'] < $now)
+ {
+ return lang('Never');
+ }
+ else
+ {
+ if ($news['begin'] < $now)
+ {
+ if ($news['end'] ==
$this->unixtimestampmax)
+ {
+ return lang('Always');
+ }
+ else
+ {
+ return lang('until') .
date($this->dateformat,$news['end']);
+ }
+ }
+ else
+ {
+ if ($news['end'] ==
$this->unixtimestampmax)
+ {
+ return lang('from') .
date($this->dateformat,$news['begin']);
+
+ }
+ else
+ {
+ return lang('from') . ' ' .
date($this->dateformat,$news['begin']) . ' ' .
+ lang('until') . ' ' .
date($this->dateformat,$news['end']);
+ }
+ }
+ }
+ }
+
+ //return the selectboxes with calculated defaults, and change
begin and end by sideaffect
+ function get_options(&$news)
+ {
+ $now = time();
+ //always is default
+ if (!isset($news['begin']))
+ {
+ //these are only displayed values not
necessarily the ones that will get stored
+ $news['begin'] = $now;
+ $news['end'] = $now;
+ $from = 1;
+ $until = 1;
+ }
+ //if enddate is in the past set option to never
+ elseif ($news['end'] < $now)
+ {
+ $news['begin'] = $now;
+ $news['end'] = $now;
+ $from = 0;
+ $until = 1;
+ }
+ else
+ {
+ if ($news['begin'] < $now)
+ {
+ $news['begin'] = $now;
+ if ($news['end'] ==
$this->unixtimestampmax)
+ {
+ $news['end'] = $now;
+ $from = 1;
+ $until = 1;
+ }
+ else
+ {
+ $from = 0.5;
+ $until = 0.5;
+ }
+ }
+ else
+ {
+ if ($news['end'] ==
$this->unixtimestampmax)
+ {
+ $news['end'] = $now;
+ $from = 0.5;
+ $until = 1;
+ }
+ else
+ {
+ $from = 0.5;
+ $until = 0.5;
+ }
+ }
+ }
+ $options['from'] = '<option value="1"' . (($from == 1)
? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
+ $options['from'] .= '<option value="0"' . (($from == 0)
? ' selected="selected"' : '') . '>' . lang('Never') . '</option>';
+ $options['from'] .= '<option value="0.5"' . (($from ==
0.5) ? ' selected="selected"' : '') . '>' . lang('From') . '</option>';
+ $options['until'] = '<option value="1"' . (($until ==
1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
+ $options['until'] .= '<option value="0.5"' . (($until
== 0.5) ? ' selected="selected"' : '') . '>' . lang('until') . '</option>';
+ return $options;
+ }
+
+ //set the begin and end dates
+ function set_dates($from,$until,&$news)
+ {
+ switch($from)
+ {
+ //always
+ case 1:
+ $news['begin'] = $news['date'];
+ $news['end'] = $this->unixtimestampmax;
+ break;
+ //never
+ case 0:
+ $news['begin'] = 0;
+ $news['end'] = 0;
+ break;
+ default:
+ $news['begin'] =
mktime(0,0,0,intval($news['begin_m']), intval($news['begin_d']),
intval($news['begin_y']));
+ switch($until)
+ {
+ case 1:
+ $news['end'] =
$this->unixtimestampmax;
+ break;
+ default:
+ $news['end'] =
mktime(0,0,0,intval($news['end_m']), intval($news['end_d']),
intval($news['end_y']));
+ }
+ }
+ }
+
// function format_fields($fields)
// {
***************
*** 148,152 ****
{
$news = $this->sonews->get_news($news_id);
! return $this->acl->is_readable($news['category']) ?
$news : False;
}
}
--- 280,292 ----
{
$news = $this->sonews->get_news($news_id);
! if ($this->acl->is_readable($news['category']))
! {
! $this->total = 1;
! return $news;
! }
! else
! {
! return False;
! }
}
}
Index: class.so.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/news_admin/inc/class.so.inc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** class.so.inc.php 23 Jun 2003 22:56:30 -0000 1.1.2.2
--- class.so.inc.php 28 Jun 2003 04:33:47 -0000 1.1.2.3
***************
*** 46,50 ****
$sql = 'SELECT * FROM phpgw_news WHERE news_cat ' .
$filter;
! $sql .= $activeonly ? " AND news_status='Active'" : '';
$sql .= $ordermethod;
--- 46,54 ----
$sql = 'SELECT * FROM phpgw_news WHERE news_cat ' .
$filter;
! if ($activeonly)
! {
! $now = time();
! $sql .= " AND news_begin<=$now AND
news_end>=$now";
! }
$sql .= $ordermethod;
***************
*** 62,66 ****
'date' => $this->db->f('news_date'),
'id' => $this->db->f('news_id'),
! 'status' => $this->db->f('news_status'),
'teaser' =>
htmlentities(stripslashes($this->db->f('news_teaser'))),
'content' =>
nl2br(htmlentities(stripslashes($this->db->f('news_content'))))
--- 66,71 ----
'date' => $this->db->f('news_date'),
'id' => $this->db->f('news_id'),
! 'begin' => $this->db->f('news_begin'),
! 'end' => $this->db->f('news_end'),
'teaser' =>
htmlentities(stripslashes($this->db->f('news_teaser'))),
'content' =>
nl2br(htmlentities(stripslashes($this->db->f('news_content'))))
***************
*** 72,76 ****
function get_all_public_news($limit=5)
{
! $this->db->limit_query("SELECT * FROM phpgw_news WHERE
news_status='Active' ORDER BY news_date DESC",0,__LINE__,__FILE__,$limit);
$news = array();
--- 77,82 ----
function get_all_public_news($limit=5)
{
! $now = time();
! $this->db->limit_query("SELECT * FROM phpgw_news WHERE
news_begin<=$now AND news_end>=$now ORDER BY news_date
DESC",0,__LINE__,__FILE__,$limit);
$news = array();
***************
*** 92,99 ****
function add($news)
{
! $sql = 'INSERT INTO phpgw_news
(news_date,news_submittedby,news_content,news_subject,news_status,news_teaser,news_cat)
';
! $sql .= 'VALUES (' . mktime(0,0,0,
intval($news['date_m']), intval($news['date_d']), intval($news['date_y'])) .
',';
$sql .= $GLOBALS['phpgw_info']['user']['account_id'] .
",'" . $this->db->db_addslashes($news['content']) ."','";
! $sql .= $this->db->db_addslashes($news['subject'])
."','" . $this->db->db_addslashes($news['status']) . "','";
$sql .= $this->db->db_addslashes($news['teaser']) .
"'," . intval($news['category']) . ')';
$this->db->query($sql);
--- 98,105 ----
function add($news)
{
! $sql = 'INSERT INTO phpgw_news
(news_date,news_submittedby,news_content,news_subject,news_begin,news_end,news_teaser,news_cat)
';
! $sql .= 'VALUES (' . intval($news['date']) . ',';
$sql .= $GLOBALS['phpgw_info']['user']['account_id'] .
",'" . $this->db->db_addslashes($news['content']) ."','";
! $sql .= $this->db->db_addslashes($news['subject'])
."'," . intval($news['begin']) . "," . intval($news['end']) . ",'";
$sql .= $this->db->db_addslashes($news['teaser']) .
"'," . intval($news['category']) . ')';
$this->db->query($sql);
***************
*** 105,113 ****
{
$this->db->query("UPDATE phpgw_news SET "
- . "news_date='" .
mktime(0,0,0,intval($news['date_m']), intval($news['date_d']),
intval($news['date_y'])) . "',"
. "news_content='" .
$this->db->db_addslashes($news['content']) . "',"
. "news_subject='" .
$this->db->db_addslashes($news['subject']) . "', "
. "news_teaser='" .
$this->db->db_addslashes($news['teaser']) . "', "
! . "news_status='" .
$this->db->db_addslashes($news['status']) . "', "
. "news_cat='" .
$this->db->db_addslashes($news['category']) . "' "
. "WHERE news_id=" .
intval($news['id']),__LINE__,__FILE__);
--- 111,119 ----
{
$this->db->query("UPDATE phpgw_news SET "
. "news_content='" .
$this->db->db_addslashes($news['content']) . "',"
. "news_subject='" .
$this->db->db_addslashes($news['subject']) . "', "
. "news_teaser='" .
$this->db->db_addslashes($news['teaser']) . "', "
! . "news_begin=" . intval($news['begin']) . ", "
! . "news_end=" . intval($news['end']) . ", "
. "news_cat='" .
$this->db->db_addslashes($news['category']) . "' "
. "WHERE news_id=" .
intval($news['id']),__LINE__,__FILE__);
***************
*** 124,128 ****
$this->db->next_record();
! $items = array(
'id' => $this->db->f('news_id'),
'date' => $this->db->f('news_date'),
--- 130,134 ----
$this->db->next_record();
! $item = array(
'id' => $this->db->f('news_id'),
'date' => $this->db->f('news_date'),
***************
*** 131,138 ****
'teaser' =>
$this->db->f('news_teaser'),
'content' => $this->db->f('news_content'),
! 'status' => $this->db->f('news_status'),
'category' => $this->db->f('news_cat')
);
! return $items;
}
--- 137,145 ----
'teaser' =>
$this->db->f('news_teaser'),
'content' => $this->db->f('news_content'),
! 'begin' => $this->db->f('news_begin'),
! 'end' => $this->db->f('news_end'),
'category' => $this->db->f('news_cat')
);
! return $item;
}
Index: class.ui.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/news_admin/inc/class.ui.inc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** class.ui.inc.php 23 Jun 2003 22:56:30 -0000 1.1.2.2
--- class.ui.inc.php 28 Jun 2003 04:33:47 -0000 1.1.2.3
***************
*** 71,74 ****
--- 71,80 ----
}
}
+ if (!$default)
+ {
+ $link_data['cat_id'] = 'all';
+ $selectlist .= '<option
style="font-weight:bold" value="' .
$GLOBALS['phpgw']->link('/index.php',$link_data)
+ . '">' . lang('All news') . '</option>'
. "\n";
+ }
return $selectlist;
}
***************
*** 96,104 ****
$var['lang_write'] = lang('Write');
$var['readable'] = $this->selectlist('read');
! $var['maintainlink'] =
$this->bo->acl->is_permitted($this->cat_id,PHPGW_ACL_ADD) ?
('<a href="' .
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.ui.write_news&start=0&cat_id='.$this->cat_id)
.
'">' . lang('Maintain') . '</a>') :
'';
! $var['cat_name'] = $this->cat_id ?
$this->bo->catbo->id2name($this->cat_id) : lang('Global news');
$this->template->set_var($var);
$this->template->parse('_category','category');
--- 102,110 ----
$var['lang_write'] = lang('Write');
$var['readable'] = $this->selectlist('read');
! $var['maintainlink'] = (($this->cat_id != 'all') &&
$this->bo->acl->is_permitted($this->cat_id,PHPGW_ACL_ADD)) ?
('<a href="' .
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.ui.write_news&start=0&cat_id='.$this->cat_id)
.
'">' . lang('Maintain') . '</a>') :
'';
! $var['cat_name'] = ($this->cat_id != 'all') ?
$this->bo->catbo->id2name($this->cat_id) : lang('All news');
$this->template->set_var($var);
$this->template->parse('_category','category');
***************
*** 270,274 ****
{
$this->news_data = $_POST['news'];
-
if (! $this->news_data['subject'])
{
--- 276,279 ----
***************
*** 281,284 ****
--- 286,291 ----
if (!is_array($errors))
{
+ $this->news_data['date'] = time();
+
$this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
$this->news_id =
$this->bo->add($this->news_data);
$this->message = lang('Message has been
added');
***************
*** 294,302 ****
else
{
! $this->news_data = array('date_d' => date('j'),
!
'date_m' => date('n'),
!
'date_y' => date('Y'),
!
'category' => $this->cat_id,
! );
}
$this->modify('add');
--- 301,305 ----
else
{
! $this->news_data['category'] = $this->cat_id;
}
$this->modify('add');
***************
*** 361,364 ****
--- 364,368 ----
if(!is_array($errors))
{
+
$this->bo->set_dates($_POST['from'],$_POST['until'],$this->news_data);
$this->bo->edit($this->news_data);
$this->message = lang('News item has
been updated');
***************
*** 372,378 ****
{
$this->news_data =
$this->bo->get_news($this->news_id,True);
! $this->news_data['date_d'] =
date('j',$this->news_data['date']);
! $this->news_data['date_m'] =
date('n',$this->news_data['date']);
! $this->news_data['date_y'] =
date('Y',$this->news_data['date']);
}
$this->modify();
--- 376,382 ----
{
$this->news_data =
$this->bo->get_news($this->news_id,True);
! $this->news_data['date_d'] =
date('j',$this->news_data['begin']);
! $this->news_data['date_m'] =
date('n',$this->news_data['begin']);
! $this->news_data['date_y'] =
date('Y',$this->news_data['begin']);
}
$this->modify();
***************
*** 381,384 ****
--- 385,389 ----
function modify($type = 'edit')
{
+ $options = $this->bo->get_options($this->news_data);
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
***************
*** 404,435 ****
)
);
! $this->template->set_var('form_button','<input
type="submit" name="submitit" value="' . lang('save') . '">');
! $this->template->set_var('value_id',$this->news_id);
! $this->template->set_var('done_button','<input
type="submit" name="cancel" value="' . lang('Done') . '">');
!
!
$this->template->set_var('label_subject',lang('subject') . ':');
! $this->template->set_var('value_subject','<input
name="news[subject]" size="60" value="' . $this->news_data['subject'] . '">');
!
! $this->template->set_var('label_teaser',lang('teaser')
. ':');
! $this->template->set_var('value_teaser','<input
name="news[teaser]" size="60" value="' .
stripslashes($this->news_data['teaser']) . '" maxLength=100>');
!
!
$this->template->set_var('label_content',lang('Content') . ':');
! $this->template->set_var('value_content','<textarea
cols="60" rows="6" name="news[content]" wrap="virtual">' .
stripslashes($this->news_data['content']) . '</textarea>');
!
!
$this->template->set_var('label_category',lang('Category') . ':');
! $this->template->set_var('value_category','<select
name="news[category]">' . $this->selectlist('write',
(int)$this->news_data['category']) . '</select>');
!
! $this->template->set_var('label_status',lang('Status')
. ':');
! $this->template->set_var('value_status','<select
name="news[status]"><option value="Active"'
! . (($this->news_data['status'] == 'Active') ? '
selected="selected"' : '')
! . '>' . lang('Active')
! . '</option><option value="Disabled"'
! . (($this->news_data['status'] == 'Disabled') ?
' selected="selected"' : '')
! . '>' . lang('Disabled') .
'</option></select>');
!
! $this->template->set_var('label_date',
$GLOBALS['phpgw']->lang('Publish Date') . ':');
! $this->template->set_var('value_date_d',
$this->sbox->getDays('news[date_d]', $this->news_data['date_d']) );
! $this->template->set_var('value_date_m',
$this->sbox->getMonthText('news[date_m]', $this->news_data['date_m']) );
! $this->template->set_var('value_date_y',
$this->sbox->getYears('news[date_y]', $this->news_data['date_y']) );
$this->template->pfp('out','form');
--- 409,434 ----
)
);
! $this->template->set_var(array(
! 'form_button' => '<input type="submit"
name="submitit" value="' . lang('save') . '">',
! 'value_id' => $this->news_id,
! 'done_button' => '<input type="submit"
name="cancel" value="' . lang('Done') . '">',
! 'label_subject' => lang('subject') . ':',
! 'value_subject' => '<input name="news[subject]"
size="60" value="' . $this->news_data['subject'] . '">',
! 'label_teaser' => lang('teaser') . ':',
! 'value_teaser' => '<input name="news[teaser]"
size="60" value="' . stripslashes($this->news_data['teaser']) . '"
maxLength=100>',
! 'label_content' => lang('Content') . ':',
! 'value_content' => '<textarea cols="60"
rows="6" name="news[content]" wrap="virtual">' .
stripslashes($this->news_data['content']) . '</textarea>',
! 'label_category' => lang('Category') . ':',
! 'value_category' => '<select
name="news[category]">' . $this->selectlist('write',
(int)$this->news_data['category']) . '</select>',
! 'label_visible' => lang('Visible') . ':',
! 'value_begin_d' =>
$this->sbox->getDays('news[begin_d]',date('j',$this->news_data['begin'])),
! 'value_begin_m' =>
$this->sbox->getMonthText('news[begin_m]',date('n',$this->news_data['begin'])),
! 'value_begin_y' =>
$this->sbox->getYears('news[begin_y]',date('Y',$this->news_data['begin']),date('Y')),
! 'select_from' => $options['from'],
! 'select_until' => $options['until'],
! 'value_end_d' =>
$this->sbox->getDays('news[end_d]',date('j',$this->news_data['end'])) ,
! 'value_end_m' =>
$this->sbox->getMonthText('news[end_m]',date('n',$this->news_data['end'])),
! 'value_end_y' =>
$this->sbox->getYears('news[end_y]',date('Y',$this->news_data['end']),date('Y')),
! ));
$this->template->pfp('out','form');
***************
*** 463,467 ****
$this->template->set_var('header_date',$this->nextmatchs->show_sort_order($this->sort,'news_date',$this->order,'/index.php',lang('Date'),'&menuaction=news_admin.ui.write_news'));
$this->template->set_var('header_subject',$this->nextmatchs->show_sort_order($this->sort,'news_subject',$this->order,'/index.php',lang('Subject'),'&menuaction=news_admin.ui.write_news'));
!
$this->template->set_var('header_status',$this->nextmatchs->show_sort_order($this->sort,'news_status',$this->order,'/index.php',lang('Status'),'&menuaction=news_admin.ui.write_news'));
$this->template->set_var('header_edit','edit');
$this->template->set_var('header_delete','delete');
--- 462,466 ----
$this->template->set_var('header_date',$this->nextmatchs->show_sort_order($this->sort,'news_date',$this->order,'/index.php',lang('Date'),'&menuaction=news_admin.ui.write_news'));
$this->template->set_var('header_subject',$this->nextmatchs->show_sort_order($this->sort,'news_subject',$this->order,'/index.php',lang('Subject'),'&menuaction=news_admin.ui.write_news'));
!
$this->template->set_var('header_status',lang('Visible'));
$this->template->set_var('header_edit','edit');
$this->template->set_var('header_delete','delete');
***************
*** 492,496 ****
}
$this->template->set_var('row_subject',$subject);
!
$this->template->set_var('row_status',lang($item['status']));
$this->template->set_var('row_view','<a href="'
.
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.ui.read_news&news_id='
. $item['id']) . '">' . lang('view') . '</a>');
--- 491,495 ----
}
$this->template->set_var('row_subject',$subject);
!
$this->template->set_var('row_status',$this->bo->get_visibility($item));
$this->template->set_var('row_view','<a href="'
.
$GLOBALS['phpgw']->link('/index.php','menuaction=news_admin.ui.read_news&news_id='
. $item['id']) . '">' . lang('view') . '</a>');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: news_admin/inc class.bo.inc.php,1.1.2.2,1.1.2.3 class.so.inc.php,1.1.2.2,1.1.2.3 class.ui.inc.php,1.1.2.2,1.1.2.3,
Michael Totschnig <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] CVS: news_admin/templates/default admin_form.tpl,1.1.2.1.2.1,1.1.2.1.2.2 write.tpl,1.1.2.1,1.1.2.2
- Next by Date:
[Phpgroupware-cvs] CVS: news_admin index.php,1.7.2.1.2.1,1.7.2.1.2.2
- Previous by thread:
[Phpgroupware-cvs] CVS: news_admin/templates/default admin_form.tpl,1.1.2.1.2.1,1.1.2.1.2.2 write.tpl,1.1.2.1,1.1.2.2
- Next by thread:
[Phpgroupware-cvs] CVS: news_admin index.php,1.7.2.1.2.1,1.7.2.1.2.2
- Index(es):