[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/data/ -> Tracker.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/data/Tracker.php,v 1.15 2005/04/28 05:44:22 samk Exp $
  17   * Description:  Updates entries for the Last Viewed functionality tracking the
  18   * last viewed records on a per user basis.
  19   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  20   * All Rights Reserved.
  21   * Contributor(s): ______________________________________..
  22   ********************************************************************************/
  23  
  24  include_once ('config.php');
  25  require_once ('include/logging.php');
  26  require_once ('include/database/PearDatabase.php');
  27  
  28  /** This class is used to track the recently viewed items on a per user basis.
  29   * It is intended to be called by each module when rendering the detail form.
  30   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  31   * All Rights Reserved.
  32   * Contributor(s): ______________________________________..
  33  */
  34  class Tracker {
  35      var $log;
  36      var $db;
  37      var $table_name = "vtiger_tracker";
  38  
  39      // Tracker vtiger_table
  40      var $column_fields = Array(
  41          "id",
  42          "user_id",
  43          "module_name",
  44          "item_id",
  45          "item_summary"
  46      );
  47  
  48      function Tracker()
  49      {
  50          $this->log = LoggerManager::getLogger('Tracker');
  51      //$this->db = new PearDatabase();
  52      global $adb;
  53          $this->db = $adb;
  54      }
  55  
  56      /**
  57       * Add this new item to the vtiger_tracker vtiger_table.  If there are too many items (global config for now)
  58       * then remove the oldest item.  If there is more than one extra item, log an error.
  59       * If the new item is the same as the most recent item then do not change the list
  60   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  61   * All Rights Reserved.
  62   * Contributor(s): ______________________________________..
  63       */
  64      function track_view($user_id, $current_module, $item_id, $item_summary)
  65      {
  66        global $adb;
  67        $this->delete_history($user_id, $item_id);
  68        global $log;
  69  $log->info("in  track view method ".$current_module);
  70          // Add a new item to the user's list
  71  
  72          $esc_item_id = addslashes($item_id);
  73          
  74  //No genius required. Just add an if case and change the query so that it puts the tracker entry whenever you touch on the DetailView of the required entity
  75           //get the first name and last name from the respective modules
  76       if($current_module != '')
  77       {
  78           $query = "select fieldname,tablename,entityidfield from vtiger_entityname where modulename = '$current_module'";
  79           $result = $adb->query($query);
  80           $fieldsname = $adb->query_result($result,0,'fieldname');
  81           $tablename = $adb->query_result($result,0,'tablename'); 
  82           $entityidfield = $adb->query_result($result,0,'entityidfield'); 
  83           if(!(strpos($fieldsname,',') === false))
  84           {
  85               $fieldlists = explode(',',$fieldsname);
  86               $fieldsname = "concat(";
  87               $fieldsname = $fieldsname.implode(",' ',",$fieldlists);
  88               $fieldsname = $fieldsname.")";
  89           }    
  90           $query1 = "select $fieldsname as entityname from $tablename where $entityidfield =" .$item_id; 
  91           $result = $adb->query($query1);
  92           $item_summary = $adb->query_result($result,0,'entityname');
  93           if(strlen($item_summary) > 30)
  94           {
  95              $item_summary=substr($item_summary,0,30).'...';
  96           }
  97       }
  98       
  99       #if condition added to skip vtiger_faq in last viewed history
 100            $query = "INSERT into $this->table_name (user_id, module_name, item_id, item_summary) values ('$user_id', '$current_module', '$esc_item_id', ".$this->db->formatString($this->table_name,'item_summary',$item_summary).")";
 101            
 102            $this->log->info("Track Item View: ".$query);
 103            
 104            $this->db->query($query, true);
 105            
 106            
 107            $this->prune_history($user_id);
 108      }
 109  
 110      /**
 111       * param $user_id - The id of the user to retrive the history for
 112       * param $module_name - Filter the history to only return records from the specified module.  If not specified all records are returned
 113       * return - return the array of result set rows from the query.  All of the vtiger_table vtiger_fields are included
 114   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 115   * All Rights Reserved.
 116   * Contributor(s): ______________________________________..
 117       */
 118      function get_recently_viewed($user_id, $module_name = "")
 119      {
 120          if (empty($user_id)) {
 121              return;
 122          }
 123  
 124  //        $query = "SELECT * from $this->table_name WHERE user_id='$user_id' ORDER BY id DESC";
 125      $query = "SELECT * from $this->table_name inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_tracker.item_id WHERE user_id='$user_id' and vtiger_crmentity.deleted=0 ORDER BY id DESC";
 126          $this->log->debug("About to retrieve list: $query");
 127          $result = $this->db->query($query, true);
 128          $list = Array();
 129          while($row = $this->db->fetchByAssoc($result, -1, false))
 130          {
 131          //echo "while loppp";
 132          //echo '<BR>';
 133  
 134  
 135              // If the module was not specified or the module matches the module of the row, add the row to the list
 136              if($module_name == "" || $row[module_name] == $module_name)
 137              {
 138          //Adding Security check
 139          require_once ('include/utils/utils.php');
 140          require_once ('include/utils/UserInfoUtil.php');
 141          $entity_id = $row['item_id'];
 142          $module = $row['module_name'];
 143          //echo "module is ".$module."  id is      ".$entity_id;
 144          //echo '<BR>';
 145          if($module == "Users")
 146          {
 147              global $current_user;
 148              if(is_admin($current_user))
 149              {
 150                  $per = 'yes';
 151              }    
 152          }
 153          else
 154          {
 155              
 156              $per = isPermitted($module,'DetailView',$entity_id);
 157              
 158          }
 159          if($per == 'yes')
 160          {
 161                      $list[] = $row;
 162          }
 163              }
 164          }
 165          return $list;
 166      }
 167  
 168  
 169  
 170      /**
 171       * INTERNAL -- This method cleans out any entry for a record for a user.
 172       * It is used to remove old occurances of previously viewed items.
 173   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 174   * All Rights Reserved.
 175   * Contributor(s): ______________________________________..
 176       */
 177      function delete_history( $user_id, $item_id)
 178      {
 179          $query = "DELETE from $this->table_name WHERE user_id='$user_id' and item_id='$item_id'";
 180         $this->db->query($query, true);
 181      }
 182  
 183      /**
 184       * INTERNAL -- This method cleans out any entry for a record.
 185   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 186   * All Rights Reserved.
 187   * Contributor(s): ______________________________________..
 188       */
 189      function delete_item_history($item_id)
 190      {
 191          $query = "DELETE from $this->table_name WHERE item_id='$item_id'";
 192         $this->db->query($query, true);
 193  
 194      }
 195  
 196      /**
 197       * INTERNAL -- This function will clean out old history records for this user if necessary.
 198   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 199   * All Rights Reserved.
 200   * Contributor(s): ______________________________________..
 201       */
 202      function prune_history($user_id)
 203      {
 204          global $history_max_viewed;
 205  
 206          // Check to see if the number of items in the list is now greater than the config max.
 207          $query = "SELECT count(*) from $this->table_name WHERE user_id='$user_id'";
 208  
 209          $this->log->debug("About to verify history size: $query");
 210  
 211          $count = $this->db->getOne($query);
 212  
 213  
 214          $this->log->debug("history size: (current, max)($count, $history_max_viewed)");
 215          while($count > $history_max_viewed)
 216          {
 217              // delete the last one.  This assumes that entries are added one at a time.
 218              // we should never add a bunch of entries
 219              $query = "SELECT * from $this->table_name WHERE user_id='$user_id' ORDER BY id ASC";
 220              $this->log->debug("About to try and find oldest item: $query");
 221              $result =  $this->db->limitQuery($query,0,1);
 222  
 223              $oldest_item = $this->db->fetchByAssoc($result, -1, false);
 224              $query = "DELETE from $this->table_name WHERE id='{$oldest_item['id']}'";
 225              $this->log->debug("About to delete oldest item: ");
 226  
 227              $result = $this->db->query($query, true);
 228  
 229  
 230              $count--;
 231          }
 232      }
 233  
 234  }
 235  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7