setupCustomFields('DocumentRevisions'); //parameter is module name $this->disable_row_level_security =true; //no direct access to this module. } function save($check_notify = false){ parent::save($check_notify); //update documents table. //$query = "UPDATE documents set document_version_id='$this->id' where id = '$this->document_id'"; //$this->db->query($query); } function get_summary_text() { return "$this->filename"; } function retrieve($id, $encode=false){ $ret = parent::retrieve($id, $encode); return $ret; } function is_authenticated() { return $this->authenticated; } function fill_in_additional_list_fields() { $this->fill_in_additional_detail_fields(); } function fill_in_additional_detail_fields() { global $theme; global $current_language; parent::fill_in_additional_detail_fields(); $mod_strings=return_module_language($current_language, 'Documents'); //find the document name and current version. $query = "SELECT document_name, revision, document_revision_id FROM documents, document_revisions where documents.id = '$this->document_id' AND document_revisions.id = documents.document_revision_id"; $result = $this->db->query($query,true,"Error fetching document details...:"); $row = $this->db->fetchByAssoc($result); if ($row != null) { $this->document_name = $row['document_name']; $this->latest_revision = $row['revision']; $this->latest_revision_id = $row['document_revision_id']; } //populate the file url. //image is selected based on the extension name _image_inline, extension is stored in document_revisions. //if file is not found then default image file will be used. global $img_name; global $img_name_bare; if (!empty($this->file_ext)) { $img_name = SugarThemeRegistry::current()->getImageURL("{$this->file_ext}_image_inline.gif"); $img_name_bare = "{$this->file_ext}_image_inline"; } //set default file name. if (!empty($img_name) && file_exists($img_name)) { $img_name = $img_name_bare; } else { $img_name = "def_image_inline"; //todo change the default image. } if($this->ACLAccess('DetailView')){ $this->file_url = "".SugarThemeRegistry::current()->getImage($img_name,'alt="'.$mod_strings['LBL_LIST_VIEW_DOCUMENT'].'" border="0"').""; }else{ $this->file_url = ""; } } /** * Returns a filename based off of the logical (Sugar-side) Document name and combined with the revision. Tailor * this to needs created by email RFCs, filesystem name conventions, charset conventions etc. * @param string revId Revision ID if not latest * @return string formatted name */ function getDocumentRevisionNameForDisplay($revId='') { global $sugar_config; global $current_language; $localLabels = return_module_language($current_language, 'DocumentRevisions'); // prep - get source Document if(!class_exists('Documents')) { } $document = new Document(); // use passed revision ID if(!empty($revId)) { $tempDoc = new DocumentRevision(); $tempDoc->retrieve($revId); } else { $tempDoc = $this; } // get logical name $document->retrieve($tempDoc->document_id); $logicalName = $document->document_name; // get revision string $revString = ''; if(!empty($tempDoc->revision)) { $revString = "-{$localLabels['LBL_REVISION']}_{$tempDoc->revision}"; } // get extension $realFilename = $tempDoc->filename; $fileExtension_beg = strrpos($realFilename, "."); $fileExtension = ""; if($fileExtension_beg > 0) { $fileExtension = substr($realFilename, $fileExtension_beg + 1); } //check to see if this is a file with extension located in "badext" foreach($sugar_config['upload_badext'] as $badExt) { if(strtolower($fileExtension) == strtolower($badExt)) { //if found, then append with .txt to filename and break out of lookup //this will make sure that the file goes out with right extension, but is stored //as a text in db. $fileExtension .= ".txt"; break; // no need to look for more } } $fileExtension = ".".$fileExtension; $return = $logicalName.$revString.$fileExtension; // apply RFC limitations here if(mb_strlen($return) > 1024) { // do something if we find a real RFC issue } return $return; } function fill_document_name_revision($doc_id) { //find the document name and current version. $query = "SELECT documents.document_name, revision FROM documents, document_revisions where documents.id = '$doc_id'"; $query .= " AND document_revisions.id = documents.document_revision_id"; $result = $this->db->query($query,true,"Error fetching document details...:"); $row = $this->db->fetchByAssoc($result); if ($row != null) { $this->name = $row['document_name']; $this->latest_revision = $row['revision']; } } function list_view_parse_additional_sections(&$list_form, $xTemplateSection){ return $list_form; } function get_list_view_data(){ $revision_fields = $this->get_list_view_array(); $forecast_fields['FILE_URL'] = $this->file_url; return $revision_fields; } //static function.. function get_document_revision_name($doc_revision_id){ if (empty($doc_revision_id)) return null; $db = DBManagerFactory::getInstance(); $query="select revision from document_revisions where id='$doc_revision_id'"; $result=$db->query($query); if (!empty($result)) { $row=$db->fetchByAssoc($result); if (!empty($row)) { return $row['revision']; } } return null; } //static function. function get_document_revisions($doc_id){ $return_array= Array(); if (empty($doc_id)) return $return_array; $db = DBManagerFactory::getInstance(); $query="select id, revision from document_revisions where document_id='$doc_id' and deleted=0"; $result=$db->query($query); if (!empty($result)) { while (($row=$db->fetchByAssoc($result)) != null) { $return_array[$row['id']]=$row['revision']; } } return $return_array; } } ?>