[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/news_admin/inc/ -> class.sonews.inc.php (source)

   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: class.sonews.inc.php 20194 2006-01-02 18:17:29Z nelius_weiss $ */
  16  
  17      class sonews
  18      {
  19          var $db;
  20          var $table = 'egw_news';
  21  
  22  		function sonews()
  23          {
  24              $this->db = clone($GLOBALS['egw']->db);
  25              $this->db->set_app('news_admin');
  26          }
  27  
  28  		function get_newslist($cat_id, $start, $order,$sort,$limit=0,$activeonly,$total=false)
  29          {
  30              if(!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort))
  31              {
  32                  $ordermethod = ' ORDER BY news_date DESC';
  33              }
  34              else
  35              {
  36                  $ordermethod = ' ORDER BY '.$order . ' ' . $sort;
  37              }
  38  
  39              $where = array('news_cat' => $cat_id);
  40              if($activeonly)
  41              {
  42                  $now = time();
  43                  $where[] = "news_begin <= $now AND news_end >= $now";
  44              }
  45              //$this->db->select($this->table,'COUNT(*)',$where,__LINE__,__FILE__);
  46              //$total = $this->db->next_record() ? $this->db->f(0) : 0;
  47  
  48              $this->db->select($this->table,'*',$where,__LINE__,__FILE__,$start,$ordermethod,false,$limit);
  49  
  50              $news = array();
  51              while($this->db->next_record())
  52              {
  53                  $news[$this->db->f('news_id')] = array(
  54                      'subject' => @htmlspecialchars($this->db->f('news_subject', True),ENT_COMPAT,$GLOBALS['egw']->translation->charset()),
  55                      'submittedby' => $this->db->f('news_submittedby'),
  56                      'date'    => $this->db->f('news_date'),
  57                      'id'      => $this->db->f('news_id'),
  58                      'category' => $this->db->f('news_cat'),
  59                      'begin'   => $this->db->f('news_begin'),
  60                      'end'     => $this->db->f('news_end'),
  61                      'teaser'  => @htmlspecialchars($this->db->f('news_teaser', True),ENT_COMPAT,$GLOBALS['egw']->translation->charset()),
  62                      'content' => $this->db->f('news_content',True),
  63                      'is_html' => ($this->db->f('is_html') ? True : False),
  64                  );
  65              }
  66              return $news;
  67          }
  68  
  69  		function get_all_public_news($limit=5)
  70          {
  71              $now = time();
  72              $this->db->select($this->table,'*',"news_begin <= $now AND news_end >= $now",__LINE__,__FILE__,
  73                  0,'ORDER BY news_date DESC',false,$limit);
  74  
  75              $news = array();
  76              while ($this->db->next_record())
  77              {
  78                  $news[$this->db->f('news_id')] = array(
  79                      'subject' => $this->db->f('news_subject', True),
  80                      'submittedby' => $this->db->f('news_submittedby'),
  81                      'date'    => $this->db->f('news_date'),
  82                      'id'      => $this->db->f('news_id'),
  83                      'teaser'  => $this->db->f('news_teaser', True),
  84                      'content' => $this->db->f('news_content', True),
  85                      'is_html' => ($this->db->f('is_html') ? True : False),
  86                  );
  87              }
  88              return $news;
  89          }
  90  
  91  		function add($news)
  92          {
  93              $this->db->insert($this->table,array(
  94                  'news_date'            => (int)$news['date'],
  95                  'news_submittedby'    => $GLOBALS['egw_info']['user']['account_id'],
  96                  'news_content'        => $news['content'],
  97                  'news_subject'        => $news['subject'],
  98                  'news_begin'        => (int)$news['begin'],
  99                  'news_end'            => (int)$news['end'],
 100                  'news_teaser'        => $news['teaser'],
 101                  'news_cat'            => (int)$news['category'],
 102                  'is_html'            => (int)!!$news['is_html'],
 103                  //added by wbshang,2005-5-13
 104                  // removed by RalfBecker 2005-11-13, as mail_receiver is no column
 105  //                'mail_receiver'     => @implode(",",$news['mailto']),
 106              ),false, __LINE__, __FILE__);
 107  
 108              return $this->db->get_last_insert_id($this->table, 'news_id');
 109          }
 110  
 111  		function edit($news)
 112          {
 113              $this->db->update($this->table,array(
 114                  'news_content'    => $news['content'],
 115                  'news_subject'    => $news['subject'],
 116                  'news_teaser'    => $news['teaser'],
 117                  'news_begin'    => $news['begin'],
 118                  'news_end'        => $news['end'],
 119                  'news_cat'        => $news['category'],
 120                  'is_html'        => $news['is_html'] ? 1 : 0,
 121                  //added by wbshang,2005-5-13
 122                  // removed by RalfBecker 2005-11-13, as mail_receiver is no column
 123  //                'mail_receiver'     => @implode(",",$news['mailto']),
 124              ), array('news_id' => (int)$news['id']), __LINE__, __FILE__);
 125          }
 126  
 127  		function delete($news_id)
 128          {
 129              $this->db->delete($this->table,array('news_id' => $news_id),__LINE__,__FILE__);
 130          }
 131  
 132  		function get_news($news_id)
 133          {
 134              $this->db->select($this->table,'*',array('news_id' => $news_id),__LINE__,__FILE__);
 135              $this->db->next_record();
 136  
 137              return array(
 138                  'id'       => $this->db->f('news_id'),
 139                  'date'     => $this->db->f('news_date'),
 140                  'subject'  => $this->db->f('news_subject', True),
 141                  'submittedby' => $this->db->f('news_submittedby'),
 142                  'teaser'   => $this->db->f('news_teaser', True),
 143                  'content'  => $this->db->f('news_content', True),
 144                  'begin'    => $this->db->f('news_begin'),
 145                  'end'      => $this->db->f('news_end'),
 146                  'category' => $this->db->f('news_cat'),
 147                  'is_html'  => ($this->db->f('is_html') ? True : False),
 148              );
 149          }
 150  
 151          // the following functions are added by wbshang,2005-5-13
 152  
 153          // to get the cat_ids that have received the news by email
 154  		function get_receiver_cats($news_id)
 155          {
 156              // removed by RalfBecker 2005-11-13, as mail_receiver is no column
 157  /*
 158              $sql = "SELECT mail_receiver FROM phpgw_news WHERE news_id=" . (int)$news_id;
 159              $this->db->query($sql,__LINE__,__FILE__);
 160              $this->db->next_record();
 161              return $this->db->f('mail_receiver');
 162  */
 163          }
 164      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7