[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/bookmarks/inc/ -> class.so.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Bookmarks                                                   *
   4      * http://www.egroupware.org                                                *
   5      * Based on Bookmarker Copyright (C) 1998  Padraic Renaghan                 *
   6      *                     http://www.renaghan.com/bookmarker                   *
   7      * Ported to phpgroupware by Joseph Engo                                    *
   8      * Ported to three-layered design by Michael Totschnig                      *
   9      * SQL reworked by RalfBecker@outdoor-training.de to get everything quoted  *
  10      * --------------------------------------------                             *
  11      *  This program is free software; you can redistribute it and/or modify it *
  12      *  under the terms of the GNU General Public License as published by the   *
  13      *  Free Software Foundation; either version 2 of the License, or (at your  *
  14      *  option) any later version.                                              *
  15      \**************************************************************************/
  16  
  17      /* $Id: class.so.inc.php 19868 2005-11-19 09:40:52Z ralfbecker $ */
  18  
  19      class so
  20      {
  21          var $db;
  22          var $total_records;
  23  
  24          function so()
  25          {
  26              $this->db = clone($GLOBALS['egw']->db);
  27              $this->db->set_app('bookmarks');
  28              $this->table = 'egw_bookmarks';
  29              $this->user = $GLOBALS['egw_info']['user']['account_id'];
  30          }
  31  
  32  		function _list($cat_list,$public_user_list,$start,$where_clause)
  33          {
  34              $where = $this->db->expression($this->table,'(',array('bm_owner'=>$this->user),
  35                  (boolean) $public_user_list,' OR (',array(
  36                      'bm_access'=>'public',
  37                      'bm_owner' => $public_user_list,
  38                  ),'))',(boolean)$cat_list,' AND ',array(
  39                      'bm_category' => $cat_list,
  40                  ),(boolean)$where_clause,' AND ',$where_clause);
  41  
  42              if ($start !== False)
  43              {
  44                  $this->db->select($this->table,'count(*)',$where,__LINE__,__FILE__);
  45                  $this->total_records = $this->db->next_record() ? $this->db->f(0) : 0;
  46                  $this->db->select($this->table,'*',$where.' ORDER BY bm_category, bm_name',__LINE__,__FILE__,$start);
  47              }
  48              else
  49              {
  50                  $this->db->select($this->table,'*',$where.' ORDER BY bm_category, bm_name',__LINE__,__FILE__);
  51                  $this->total_records = $this->db->num_rows();
  52              }
  53              while ($this->db->next_record())
  54              {
  55                  $result[$this->db->f('bm_id')] = $this->_db2bookmark();
  56              }
  57              return $result;
  58          }
  59  
  60  		function _db2bookmark($do_htmlspecialchars = True)
  61          {
  62              foreach(array('name','url','desc','keywords','owner','access','category','rating','visits','info') as $name)
  63              {
  64                  $bookmark[$name] = $this->db->f('bm_'.$name);
  65              }
  66              if ($do_htmlspecialchars)
  67              {
  68                  foreach(array('name','url','desc','keywords') as $name)
  69                  {
  70                      $bookmark[$name] = $GLOBALS['egw']->strip_html($bookmark[$name]);
  71                  }
  72              }
  73              return $bookmark;
  74          }
  75  
  76  		function read($id,$do_htmlspecialchars=True)
  77          {
  78              $this->db->select($this->table,'*',array('bm_id'=>$id),__LINE__,__FILE__);
  79              if (!$this->db->next_record())
  80              {
  81                  return False;
  82              }
  83              return $this->_db2bookmark($do_htmlspecialchars);
  84          }
  85  
  86  		function exists($url)
  87          {
  88              $this->db->select($this->table,'count(*)',array('bm_url'=>$url,'bm_owner'=>$this->user),__LINE__,__FILE__);
  89              $this->db->next_record();
  90  
  91              return (bool)$this->db->f(0);
  92          }
  93  
  94  		function add($values)
  95          {
  96              $columns = $this->_bookmark2db($values,$values['timestamps'] ? $values['timestamps'] : time() . ',0,0');
  97              $columns['bm_owner'] = (int) $GLOBALS['egw_info']['user']['account_id'];
  98              $columns['bm_visits'] = 0;
  99  
 100              if (!$this->db->insert($this->table,$columns,False,__LINE__,__FILE__))
 101              {
 102                  return False;
 103              }
 104              return $this->db->get_last_insert_id($this->table,'bm_id');
 105          }
 106  
 107  		function update($id, $values)
 108          {
 109              #echo "so::update<pre>".htmlspecialchars(print_r($values,True))."</pre>\n";
 110  
 111              $this->db->select($this->table,'bm_info',array('bm_id'=>$id),__LINE__,__FILE__);
 112              $this->db->next_record();
 113              $ts = explode(',',$GLOBALS['egw']->db->f('bm_info'));
 114              $ts[2] = time();
 115  
 116              $columns = $this->_bookmark2db($values,implode(',',$ts));
 117  
 118              // Update bookmark information.
 119              if (!$this->db->update($this->table,$columns,array('bm_id'=>$id),__LINE__,__FILE__))
 120              {
 121                  return False;
 122              }
 123              return True;
 124          }
 125  
 126  		function _bookmark2db($values,$timestamps)
 127          {
 128              if ($values['access'] != 'private')
 129              {
 130                  $values['access'] = 'public';
 131              }
 132              foreach(array('name','url','desc','keywords','access','category','rating') as $name)
 133              {
 134                  $columns['bm_'.$name] = $values[$name];
 135              }
 136              $columns['bm_info'] = $timestamps;
 137  
 138              return $columns;
 139          }
 140  
 141  		function updatetimestamp($id,$timestamp)
 142          {
 143              $this->db->update($this->table,array(
 144                  'bm_info'=>$timestamp,
 145                  'bm_visits=bm_visits+1'
 146              ),array('bm_id'=>$id),__LINE__,__FILE__);
 147          }
 148  
 149  		function delete($id)
 150          {
 151              $this->db->delete($this->table,array('bm_id'=>$id),__LINE__,__FILE__);
 152              if ($this->db->Errno != 0)
 153              {
 154                  return False;
 155              }
 156              return True;
 157          }
 158      }


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