- Entity Display Name for the record */ function getDisplayName() { return Vtiger_Util_Helper::getLabel($this->getId()); } function getDownloadFileURL() { if ($this->get('filelocationtype') == 'I') { $fileDetails = $this->getFileDetails(); return 'index.php?module='. $this->getModuleName() .'&action=DownloadFile&record='. $this->getId() .'&fileid='. $fileDetails['attachmentsid']; } else { return $this->get('filename'); } } function checkFileIntegrityURL() { return "javascript:Documents_Detail_Js.checkFileIntegrity('index.php?module=".$this->getModuleName()."&action=CheckFileIntegrity&record=".$this->getId()."')"; } function checkFileIntegrity() { $recordId = $this->get('id'); $downloadType = $this->get('filelocationtype'); $returnValue = false; if ($downloadType == 'I') { $fileDetails = $this->getFileDetails(); if (!empty ($fileDetails)) { $filePath = $fileDetails['path']; $savedFile = $fileDetails['attachmentsid']."_".$this->get('filename'); if(fopen($filePath.$savedFile, "r")) { $returnValue = true; } } } return $returnValue; } function getFileDetails() { $db = PearDatabase::getInstance(); $fileDetails = array(); $result = $db->pquery("SELECT * FROM vtiger_attachments INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid WHERE crmid = ?", array($this->get('id'))); if($db->num_rows($result)) { $fileDetails = $db->query_result_rowdata($result); } return $fileDetails; } function downloadFile() { $fileDetails = $this->getFileDetails(); $fileContent = false; if (!empty ($fileDetails)) { $filePath = $fileDetails['path']; $fileName = $fileDetails['name']; if ($this->get('filelocationtype') == 'I') { $fileName = html_entity_decode($fileName, ENT_QUOTES, vglobal('default_charset')); $savedFile = $fileDetails['attachmentsid']."_".$fileName; $fileSize = filesize($filePath.$savedFile); $fileSize = $fileSize + ($fileSize % 1024); if (fopen($filePath.$savedFile, "r")) { $fileContent = fread(fopen($filePath.$savedFile, "r"), $fileSize); header("Content-type: ".$fileDetails['type']); header("Pragma: public"); header("Cache-Control: private"); header("Content-Disposition: attachment; filename=$fileName"); header("Content-Description: PHP Generated Data"); } } } echo $fileContent; } function updateFileStatus() { $db = PearDatabase::getInstance(); $db->pquery("UPDATE vtiger_notes SET filestatus = 0 WHERE notesid= ?", array($this->get('id'))); } function updateDownloadCount() { $db = PearDatabase::getInstance(); $notesId = $this->get('id'); $result = $db->pquery("SELECT filedownloadcount FROM vtiger_notes WHERE notesid = ?", array($notesId)); $downloadCount = $db->query_result($result, 0, 'filedownloadcount') + 1; $db->pquery("UPDATE vtiger_notes SET filedownloadcount = ? WHERE notesid = ?", array($downloadCount, $notesId)); } function getDownloadCountUpdateUrl() { return "index.php?module=Documents&action=UpdateDownloadCount&record=".$this->getId(); } function get($key) { $value = parent::get($key); if ($key === 'notecontent') { return decode_html($value); } return $value; } }