[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Documents/models/ -> Record.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  class Documents_Record_Model extends Vtiger_Record_Model {
  12  
  13      /**
  14       * Function to get the Display Name for the record
  15       * @return <String> - Entity Display Name for the record
  16       */
  17  	function getDisplayName() {
  18          return Vtiger_Util_Helper::getLabel($this->getId());
  19      }
  20  
  21  	function getDownloadFileURL() {
  22          if ($this->get('filelocationtype') == 'I') {
  23              $fileDetails = $this->getFileDetails();
  24              return 'index.php?module='. $this->getModuleName() .'&action=DownloadFile&record='. $this->getId() .'&fileid='. $fileDetails['attachmentsid'];
  25          } else {
  26              return $this->get('filename');
  27          }
  28      }
  29  
  30  	function checkFileIntegrityURL() {
  31          return "javascript:Documents_Detail_Js.checkFileIntegrity('index.php?module=".$this->getModuleName()."&action=CheckFileIntegrity&record=".$this->getId()."')";
  32      }
  33  
  34  	function checkFileIntegrity() {
  35          $recordId = $this->get('id');
  36          $downloadType = $this->get('filelocationtype');
  37          $returnValue = false;
  38  
  39          if ($downloadType == 'I') {
  40              $fileDetails = $this->getFileDetails();
  41              if (!empty ($fileDetails)) {
  42                  $filePath = $fileDetails['path'];
  43  
  44                  $savedFile = $fileDetails['attachmentsid']."_".$this->get('filename');
  45  
  46                  if(fopen($filePath.$savedFile, "r")) {
  47                      $returnValue = true;
  48                  }
  49              }
  50          }
  51          return $returnValue;
  52      }
  53  
  54  	function getFileDetails() {
  55          $db = PearDatabase::getInstance();
  56          $fileDetails = array();
  57  
  58          $result = $db->pquery("SELECT * FROM vtiger_attachments
  59                              INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
  60                              WHERE crmid = ?", array($this->get('id')));
  61  
  62          if($db->num_rows($result)) {
  63              $fileDetails = $db->query_result_rowdata($result);
  64          }
  65          return $fileDetails;
  66      }
  67  
  68  	function downloadFile() {
  69          $fileDetails = $this->getFileDetails();
  70          $fileContent = false;
  71  
  72          if (!empty ($fileDetails)) {
  73              $filePath = $fileDetails['path'];
  74              $fileName = $fileDetails['name'];
  75  
  76              if ($this->get('filelocationtype') == 'I') {
  77                  $fileName = html_entity_decode($fileName, ENT_QUOTES, vglobal('default_charset'));
  78                  $savedFile = $fileDetails['attachmentsid']."_".$fileName;
  79  
  80                  $fileSize = filesize($filePath.$savedFile);
  81                  $fileSize = $fileSize + ($fileSize % 1024);
  82  
  83                  if (fopen($filePath.$savedFile, "r")) {
  84                      $fileContent = fread(fopen($filePath.$savedFile, "r"), $fileSize);
  85  
  86                      header("Content-type: ".$fileDetails['type']);
  87                      header("Pragma: public");
  88                      header("Cache-Control: private");
  89                      header("Content-Disposition: attachment; filename=$fileName");
  90                      header("Content-Description: PHP Generated Data");
  91                  }
  92              }
  93          }
  94          echo $fileContent;
  95      }
  96  
  97  	function updateFileStatus() {
  98          $db = PearDatabase::getInstance();
  99  
 100          $db->pquery("UPDATE vtiger_notes SET filestatus = 0 WHERE notesid= ?", array($this->get('id')));
 101      }
 102  
 103  	function updateDownloadCount() {
 104          $db = PearDatabase::getInstance();
 105          $notesId = $this->get('id');
 106  
 107          $result = $db->pquery("SELECT filedownloadcount FROM vtiger_notes WHERE notesid = ?", array($notesId));
 108          $downloadCount = $db->query_result($result, 0, 'filedownloadcount') + 1;
 109  
 110          $db->pquery("UPDATE vtiger_notes SET filedownloadcount = ? WHERE notesid = ?", array($downloadCount, $notesId));
 111      }
 112  
 113  	function getDownloadCountUpdateUrl() {
 114          return "index.php?module=Documents&action=UpdateDownloadCount&record=".$this->getId();
 115      }
 116      
 117  	function get($key) {
 118          $value = parent::get($key);
 119          if ($key === 'notecontent') {
 120              return decode_html($value);
 121          }
 122          return $value;
 123      }
 124  
 125  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1