function saveFile($document, $portal = false) { global $sugar_config; $focus = new Document(); if (!empty($document['id'])) { $focus->retrieve($document['id']); } else { return '-1'; } if (!empty($document['file'])) { $decodedFile = base64_decode($document['file']); $this->upload_file->set_for_soap($document['filename'], $decodedFile); $ext_pos = strrpos($this->upload_file->stored_file_name, "."); $this->upload_file->file_ext = substr($this->upload_file->stored_file_name, $ext_pos + 1); if (in_array($this->upload_file->file_ext, $sugar_config['upload_badext'])) { $this->upload_file->stored_file_name .= ".txt"; $this->upload_file->file_ext = "txt"; } $revision = new DocumentRevision(); $revision->filename = $this->upload_file->get_stored_file_name(); $revision->file_mime_type = $this->upload_file->getMimeSoap($revision->filename); $revision->file_ext = $this->upload_file->file_ext; //$revision->document_name = ; $revision->revision = $document['revision']; $revision->document_id = $document['id']; $revision->save(); $focus->document_revision_id = $revision->id; $focus->save(); $return_id = $revision->id; $this->upload_file->final_move($revision->id); } else { return '-1'; } return $return_id; }
function getTechnicalDescriptions() { $attachmentIds = explode(' ', trim($this->attachmentsequence)); $attachments = array(); foreach ($attachmentIds as $id) { $attachment_data = array(); $revision = new DocumentRevision(); if (!$revision->retrieve($id)) { $attachment = new Document(); if ($attachment->retrieve($id)) { if ($attachment->subcategory_id == 'Technical') { //$attachment_data = array(); $attachment_data["id"] = $attachment->id; $attachment_data["document_name"] = $attachment->document_name; $attachment_data["document_revision_id"] = $attachment->document_revision_id; // $attachment_data["doc_status"] = 'new'; $attachments[] = $attachment_data; } } } else { $attachment = new Document(); if ($attachment->retrieve($revision->document_id)) { if ($attachment->subcategory_id == 'Technical') { //$attachment_data = array(); $attachment_data["id"] = $attachment->id; $attachment_data["document_name"] = $attachment->document_name . '_rev.' . $revision->revision; $attachment_data["document_revision_id"] = $revision->id; // $attachment_data["doc_status"] = 'new'; $attachments[] = $attachment_data; } } } } return $attachments; }
function get_all_linked_attachment_revisions($attachmentsequence) { $attachmentIds = explode(' ', trim($attachmentsequence)); $attachments = array(); foreach ($attachmentIds as $id) { $revision = new DocumentRevision(); if (!$revision->retrieve($id)) { // if in old format try to recover by document id $attachment = new Document(); if ($attachment->retrieve($id)) { $attachment->revision = ''; $attachment->doc_rev_id = ''; $attachments[] = $attachment; } } else { $attachment = new Document(); if ($attachment->retrieve($revision->document_id)) { $attachment->revision = $revision->revision; $attachment->doc_rev_id = $revision->id; $attachments[] = $attachment; } } } return $attachments; }
/** * Constructs an attachment from the SugarBean that is passed in. * * @static * @access public * @param SugarBean $bean required * @return Attachment * @throws MailerException */ public static function attachmentFromSugarBean(SugarBean $bean) { $filePath = null; $fileName = null; $mimeType = ""; if ($bean instanceof Document) { if (empty($bean->id)) { throw new MailerException("Invalid Attachment: document not found", MailerException::InvalidAttachment); } $document_revision_id = $bean->document_revision_id; $documentRevision = new DocumentRevision(); if (!empty($document_revision_id)) { $documentRevision->retrieve($bean->document_revision_id); } if (empty($document_revision_id) || $documentRevision->id != $document_revision_id) { throw new MailerException("Invalid Attachment: Document with Id (" . $bean->id . ") contains an invalid or empty revision id: (" . $document_revision_id . ")", MailerException::InvalidAttachment); } $bean = $documentRevision; } $beanName = get_class($bean); switch ($beanName) { case "Note": case "DocumentRevision": $filePath = rtrim(SugarConfig::getInstance()->get('upload_dir', 'upload'), '/\\') . '/' . $bean->id; $fileName = empty($bean->filename) ? $bean->name : $bean->filename; $mimeType = empty($bean->file_mime_type) ? $mimeType : $bean->file_mime_type; break; default: throw new MailerException("Invalid Attachment: SugarBean '{$beanName}' not supported as an Email Attachment", MailerException::InvalidAttachment); break; } // Path must Exist and Must be a Regular File if (!is_file($filePath)) { throw new MailerException("Invalid Attachment: file not found: {$filePath}", MailerException::InvalidAttachment); } $attachment = new Attachment($filePath, $fileName, Encoding::Base64, $mimeType); return $attachment; }
/** * @see SugarView::display() */ public function display() { global $app_list_strings, $mod_strings; $load_signed = false; if (isset($_REQUEST['load_signed_id']) && !empty($_REQUEST['load_signed_id'])) { $load_signed = true; if (isset($_REQUEST['record'])) { $this->bean->related_doc_id = $_REQUEST['record']; } if (isset($_REQUEST['selected_revision_id'])) { $this->bean->related_doc_rev_id = $_REQUEST['selected_revision_id']; } $this->bean->id = null; $this->bean->document_name = null; $this->bean->filename = null; $this->bean->is_template = 0; } //if if (!empty($this->bean->id) || empty($this->bean->id) && !empty($_REQUEST['record']) && !empty($_REQUEST['action']) && strtolower($_REQUEST['action']) == 'quickedit') { $this->ss->assign("FILE_OR_HIDDEN", "hidden"); if (!$this->ev->isDuplicate) { $this->ss->assign("DISABLED", "disabled"); } } else { $this->bean->revision = 1; $this->ss->assign("FILE_OR_HIDDEN", "file"); } $popup_request_data = array('call_back_function' => 'document_set_return', 'form_name' => 'EditView', 'field_to_name_array' => array('id' => 'related_doc_id', 'document_name' => 'related_document_name')); $json = getJSONobj(); $this->ss->assign('encoded_document_popup_request_data', $json->encode($popup_request_data)); //get related document name. if (!empty($this->bean->related_doc_id)) { $this->ss->assign("RELATED_DOCUMENT_NAME", Document::get_document_name($this->bean->related_doc_id)); $this->ss->assign("RELATED_DOCUMENT_ID", $this->bean->related_doc_id); if (!empty($this->bean->related_doc_rev_id)) { $this->ss->assign("RELATED_DOCUMENT_REVISION_OPTIONS", get_select_options_with_id(DocumentRevision::get_document_revisions($this->bean->related_doc_id), $this->bean->related_doc_rev_id)); } else { $this->ss->assign("RELATED_DOCUMENT_REVISION_OPTIONS", get_select_options_with_id(DocumentRevision::get_document_revisions($this->bean->related_doc_id), '')); } } else { $this->ss->assign("RELATED_DOCUMENT_REVISION_DISABLED", "disabled"); } //set parent information in the form. if (isset($_REQUEST['parent_id'])) { $this->ss->assign("PARENT_ID", $_REQUEST['parent_id']); } //if if (isset($_REQUEST['parent_name'])) { $this->ss->assign("PARENT_NAME", $_REQUEST['parent_name']); if (!empty($_REQUEST['parent_type'])) { switch (strtolower($_REQUEST['parent_type'])) { case "contracts": $this->ss->assign("LBL_PARENT_NAME", $mod_strings['LBL_CONTRACT_NAME']); break; //todo remove leads case. //todo remove leads case. case "leads": $this->ss->assign("LBL_PARENT_NAME", $mod_strings['LBL_CONTRACT_NAME']); break; } //switch } //if } //if if (isset($_REQUEST['parent_type'])) { $this->ss->assign("PARENT_TYPE", $_REQUEST['parent_type']); } if ($load_signed) { $this->ss->assign("RELATED_DOCUMENT_REVISION_DISABLED", "disabled"); $this->ss->assign("RELATED_DOCUMENT_BUTTON_AVAILABILITY", "hidden"); $this->ss->assign("LOAD_SIGNED_ID", $_REQUEST['load_signed_id']); } else { $this->ss->assign("RELATED_DOCUMENT_BUTTON_AVAILABILITY", "button"); } //if-else parent::display(); }
function fill_in_additional_detail_fields() { global $theme; global $current_language; global $timedate; global $locale; parent::fill_in_additional_detail_fields(); $mod_strings = return_module_language($current_language, 'Documents'); if (!empty($this->document_revision_id)) { $query = "SELECT users.first_name AS first_name, users.last_name AS last_name, document_revisions.date_entered AS rev_date,\n \t document_revisions.filename AS filename, document_revisions.revision AS revision,\n \t document_revisions.file_ext AS file_ext, document_revisions.file_mime_type AS file_mime_type\n \t FROM users, document_revisions\n \t WHERE users.id = document_revisions.created_by AND document_revisions.id = '{$this->document_revision_id}'"; $result = $this->db->query($query); $row = $this->db->fetchByAssoc($result); //populate name if (isset($this->document_name)) { $this->name = $this->document_name; } if (isset($row['filename'])) { $this->filename = $row['filename']; } //$this->latest_revision = $row['revision']; if (isset($row['revision'])) { $this->revision = $row['revision']; } //image is selected based on the extension name <ext>_icon_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($row['file_ext'])) { $img_name = SugarThemeRegistry::current()->getImageURL(strtolower($row['file_ext']) . "_image_inline.gif"); $img_name_bare = strtolower($row['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')) { if (!empty($this->doc_type) && $this->doc_type != 'Sugar' && !empty($this->doc_url)) { $file_url = "<a href='" . $this->doc_url . "' target='_blank'>" . SugarThemeRegistry::current()->getImage($this->doc_type . '_image_inline', 'border="0"', null, null, '.png', $mod_strings['LBL_LIST_VIEW_DOCUMENT']) . "</a>"; } else { $file_url = "<a href='index.php?entryPoint=download&id={$this->document_revision_id}&type=Documents' target='_blank'>" . SugarThemeRegistry::current()->getImage($img_name, 'border="0"', null, null, '.gif', $mod_strings['LBL_LIST_VIEW_DOCUMENT']) . "</a>"; } $this->file_url = $file_url; $this->file_url_noimage = "index.php?entryPoint=download&type=Documents&id={$this->document_revision_id}"; } else { $this->file_url = ""; $this->file_url_noimage = ""; } //get last_rev_by user name. if (!empty($row)) { $this->last_rev_created_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']); $this->last_rev_create_date = $timedate->to_display_date_time($this->db->fromConvert($row['rev_date'], 'datetime')); $this->last_rev_mime_type = $row['file_mime_type']; } global $app_list_strings; if (!empty($this->status_id)) { //_pp($this->status_id); $this->status = $app_list_strings['document_status_dom'][$this->status_id]; } if (!empty($this->related_doc_id)) { $this->related_doc_name = Document::get_document_name($this->related_doc_id); $this->related_doc_rev_number = DocumentRevision::get_document_revision_name($this->related_doc_rev_id); } }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'include/formbase.php'; require_once 'include/upload_file.php'; global $upload_maxsize; global $mod_strings; global $sugar_config; $focus = new EmailTemplate(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); //process the text only flag if (isset($_POST['text_only']) && $_POST['text_only'] == '1') { $focus->text_only = 1; } else { $focus->text_only = 0; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!isset($_REQUEST['published'])) { $focus->published = 'off'; } $preProcessedImages = array(); $emailTemplateBodyHtml = from_html($focus->body_html); if (strpos($emailTemplateBodyHtml, '"cache/images/')) { $matches = array(); preg_match_all('#<img[^>]*[\\s]+src[^=]*=[\\s]*["\']cache/images/(.+?)["\']#si', $emailTemplateBodyHtml, $matches); foreach ($matches[1] as $match) { $filename = urldecode($match); $file_location = sugar_cached("images/{$filename}"); $mime_type = pathinfo($filename, PATHINFO_EXTENSION); if (file_exists($file_location)) { $id = create_guid(); $newFileLocation = "upload://{$id}"; if (!copy($file_location, $newFileLocation)) { $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$newFileLocation}"); } else { $secureLink = "index.php?entryPoint=download&type=Notes&id={$id}"; $emailTemplateBodyHtml = str_replace("cache/images/{$match}", $secureLink, $emailTemplateBodyHtml); unlink($file_location); $preProcessedImages[$filename] = $id; } } // if } // foreach } // if if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = FALSE; } $focus->body_html = $emailTemplateBodyHtml; $return_id = $focus->save($check_notify); /////////////////////////////////////////////////////////////////////////////// //// ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS $max_files_upload = count($_FILES); if (!empty($focus->id)) { $note = new Note(); $where = "notes.parent_id='{$focus->id}'"; if (!empty($_REQUEST['old_id'])) { // to support duplication of email templates $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'"; } $notes_list = $note->get_full_list("", $where, true); } if (!isset($notes_list)) { $notes_list = array(); } if (!is_array($focus->attachments)) { // PHP5 does not auto-create arrays(). Need to initialize it here. $focus->attachments = array(); } $focus->attachments = array_merge($focus->attachments, $notes_list); //for($i = 0; $i < $max_files_upload; $i++) { foreach ($_FILES as $key => $file) { $note = new Note(); //Images are presaved above so we need to prevent duplicate files from being created. if (isset($preProcessedImages[$file['name']])) { $oldId = $preProcessedImages[$file['name']]; $note->id = $oldId; $note->new_with_id = TRUE; $GLOBALS['log']->debug("Image {$file['name']} has already been processed."); } $i = preg_replace("/email_attachment(.+)/", '$1', $key); $upload_file = new UploadFile($key); if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) { if ($_REQUEST['embedded' . $i] == 'true') { $note->embed_flag = true; } else { $note->embed_flag = false; } } array_push($focus->attachments, $note); } } $focus->saved_attachments = array(); foreach ($focus->attachments as $note) { if (!empty($note->id) && $note->new_with_id === FALSE) { if (empty($_REQUEST['old_id'])) { array_push($focus->saved_attachments, $note); } else { // we're duplicating a template with attachments // dupe the file, create a new note, assign the note to the new template $newNote = new Note(); $newNote->retrieve($note->id); $newNote->id = create_guid(); $newNote->parent_id = $focus->id; $newNote->new_with_id = true; $newNote->date_modified = ''; $newNote->date_entered = ''; $newNoteId = $newNote->save(); UploadFile::duplicate_file($note->id, $newNoteId, $note->filename); } continue; } $note->parent_id = $focus->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; $note_id = $note->save(); array_push($focus->saved_attachments, $note); $note->id = $note_id; if ($note->new_with_id === FALSE) { $note->file->final_move($note->id); } else { $GLOBALS['log']->debug("Not performing final move for note id {$note->id} as it has already been processed"); } } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS $count = ''; //_pp($_REQUEST); //_ppd(count($_REQUEST['document'])); if (!empty($_REQUEST['document'])) { $count = count($_REQUEST['document']); } else { $count = 10; } for ($i = 0; $i < $count; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); array_push($focus->saved_attachments, $docRev); $docNote->name = $doc->document_name; $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $focus->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); UploadFile::duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $focus->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// //// END ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////////// clear_register_value('select_array', $focus->object_name); if ($redirect) { $GLOBALS['log']->debug("Saved record with id of " . $return_id); handleRedirect($return_id, "EmailTemplates"); } else { return $focus; } }
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'modules/EmailTemplates/EmailTemplate.php'; require_once 'modules/Documents/Document.php'; require_once 'modules/DocumentRevisions/DocumentRevision.php'; require_once 'modules/Notes/Note.php'; require_once 'include/formbase.php'; require_once 'include/upload_file.php'; global $upload_maxsize, $upload_dir; global $mod_strings; $focus = new EmailTemplate(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!isset($_REQUEST['published'])) { $focus->published = 'off'; } $return_id = $focus->save(); /////////////////////////////////////////////////////////////////////////////// //// ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS $max_files_upload = 10; if (!empty($focus->id)) { $note = new Note(); $where = "notes.parent_id='{$focus->id}'"; if (!empty($_REQUEST['old_id'])) { // to support duplication of email templates $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'"; } $notes_list = $note->get_full_list("", $where, true); } if (!isset($notes_list)) { $notes_list = array(); } if (!is_array($focus->attachments)) { // PHP5 does not auto-create arrays(). Need to initialize it here. $focus->attachments = array(); } $focus->attachments = array_merge($focus->attachments, $notes_list); for ($i = 0; $i < $max_files_upload; $i++) { $note = new Note(); $upload_file = new UploadFile('email_attachment' . $i); if ($upload_file == -1) { continue; } if (isset($_FILES['email_attachment' . $i]) && $upload_file->confirm_upload()) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; array_push($focus->attachments, $note); } } $focus->saved_attachments = array(); foreach ($focus->attachments as $note) { if (!empty($note->id)) { if (empty($_REQUEST['old_id'])) { // to support duplication of email templates array_push($focus->saved_attachments, $note); } else { // we're duplicating a template with attachments // dupe the file, create a new note, assign the note to the new template $newNote = new Note(); $newNote->retrieve($note->id); $newNote->id = create_guid(); $newNote->parent_id = $focus->id; $newNote->new_with_id = true; $newNoteId = $newNote->save(); $dupeFile = new UploadFile('duplicate'); $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename); } continue; } $note->parent_id = $focus->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; $note_id = $note->save(); array_push($focus->saved_attachments, $note); $note->id = $note_id; $note->file->final_move($note->id); } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS for ($i = 0; $i < 10; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $noteFile = new UploadFile('none'); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); array_push($focus->saved_attachments, $docRev); $docNote->name = $doc->document_name; $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $focus->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $focus->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// //// END ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////////// if ($redirect) { $GLOBALS['log']->debug("Saved record with id of " . $return_id); handleRedirect($return_id, "EmailTemplates"); } else { return $focus; } }
/** * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a * properly authenticated user to download a document that they have proper rights to download. * * @param String $session -- Session ID returned by a previous call to login. * @param String $id -- ID of the document revision to obtain * @return return_document_revision - this is a complex type as defined in SoapTypes.php */ function get_document_revision($session, $id) { global $sugar_config; $error = new SoapError(); if (!validate_authenticated($session)) { $error->set_error('invalid_login'); return array('id' => -1, 'error' => $error->get_soap_array()); } $dr = new DocumentRevision(); $dr->retrieve($id); if (!empty($dr->filename)) { $filename = "upload://{$dr->id}"; $contents = base64_encode(sugar_file_get_contents($filename)); return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error' => $error->get_soap_array()); } else { $error->set_error('no_records'); return array('id' => -1, 'error' => $error->get_soap_array()); } }
if (isset($focus->template_type)) { $xtpl->assign("TEMPLATE_TYPE_OPTIONS", get_select_options_with_id($app_list_strings['document_template_type_dom'], $focus->template_type)); } else { $xtpl->assign("TEMPLATE_TYPE_OPTIONS", get_select_options_with_id($app_list_strings['document_template_type_dom'], '')); } $popup_request_data = array('call_back_function' => 'document_set_return', 'form_name' => 'EditView', 'field_to_name_array' => array('id' => 'related_doc_id', 'document_name' => 'related_document_name')); $json = getJSONobj(); $xtpl->assign('encoded_document_popup_request_data', $json->encode($popup_request_data)); //get related document name. if (!empty($focus->related_doc_id)) { $xtpl->assign("RELATED_DOCUMENT_NAME", Document::get_document_name($focus->related_doc_id)); $xtpl->assign("RELATED_DOCUMENT_ID", $focus->related_doc_id); if (!empty($focus->related_doc_rev_id)) { $xtpl->assign("RELATED_DOCUMENT_REVISION_OPTIONS", get_select_options_with_id(DocumentRevision::get_document_revisions($focus->related_doc_id), $focus->related_doc_rev_id)); } else { $xtpl->assign("RELATED_DOCUMENT_REVISION_OPTIONS", get_select_options_with_id(DocumentRevision::get_document_revisions($focus->related_doc_id), '')); } } else { $xtpl->assign("RELATED_DOCUMENT_REVISION_DISABLED", "disabled"); } //set parent information in the form. if (isset($_REQUEST['parent_id'])) { $xtpl->assign("PARENT_ID", $_REQUEST['parent_id']); } if (isset($_REQUEST['parent_name'])) { $xtpl->assign("PARENT_NAME", $_REQUEST['parent_name']); if (!empty($_REQUEST['parent_type'])) { switch (strtolower($_REQUEST['parent_type'])) { case "contracts": $xtpl->assign("LBL_PARENT_NAME", $mod_strings['LBL_CONTRACT_NAME']); break;
/** * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a * properly authenticated user to download a document that they have proper rights to download. * * @param String $session -- Session ID returned by a previous call to login. * @param String $id -- ID of the document revision to obtain * @return new_return_document_revision - Array String 'id' -- The ID of the document revision containing the attachment * String document_name - The name of the document * String revision - The revision value for this revision * String 'filename' -- The file name of the attachment * Binary 'file' -- The binary contents of the file. * @exception 'SoapFault' -- The SOAP error, if any */ function get_document_revision($session, $id) { $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_document_revision'); global $sugar_config; $error = new SoapError(); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) { $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision'); return; } // if require_once 'modules/DocumentRevisions/DocumentRevision.php'; $dr = new DocumentRevision(); $dr->retrieve($id); if (!empty($dr->filename)) { $filename = $sugar_config['upload_dir'] . "/" . $dr->id; if (filesize($filename) > 0) { $contents = sugar_file_get_contents($filename); } else { $contents = ''; } $contents = base64_encode($contents); $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision'); return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents)); } else { $error->set_error('no_records'); self::$helperObject->setFaultObject($error); $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision'); } }
function fill_in_additional_detail_fields() { global $theme; global $current_language; global $timedate; global $locale; parent::fill_in_additional_detail_fields(); $mod_strings = return_module_language($current_language, 'Documents'); $query = "SELECT filename,revision,file_ext FROM document_revisions WHERE id='{$this->document_revision_id}'"; $result = $this->db->query($query); $row = $this->db->fetchByAssoc($result); //popuplate filename if (isset($row['filename'])) { $this->filename = $row['filename']; } //$this->latest_revision = $row['revision']; if (isset($row['revision'])) { $this->revision = $row['revision']; } //populate the file url. //image is selected based on the extension name <ext>_icon_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($row['file_ext'])) { $img_name = SugarThemeRegistry::current()->getImageURL(strtolower($row['file_ext']) . "_image_inline.gif"); $img_name_bare = strtolower($row['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 = "<a href='index.php?entryPoint=download&id=" . basename(UploadFile::get_url($this->filename, $this->document_revision_id)) . "&type=Documents' target='_blank'>" . SugarThemeRegistry::current()->getImage($img_name, 'alt="' . $mod_strings['LBL_LIST_VIEW_DOCUMENT'] . '" border="0"') . "</a>"; $this->file_url_noimage = basename(UploadFile::get_url($this->filename, $this->document_revision_id)); } else { $this->file_url = ""; $this->file_url_noimage = ""; } //get last_rev_by user name. $query = "SELECT first_name,last_name, document_revisions.date_entered as rev_date FROM users, document_revisions WHERE users.id = document_revisions.created_by and document_revisions.id = '{$this->document_revision_id}'"; $result = $this->db->query($query, true, "Eror fetching user name: "); $row = $this->db->fetchByAssoc($result); if (!empty($row)) { $this->last_rev_created_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']); $this->last_rev_create_date = $timedate->to_display_date_time($row['rev_date']); } global $app_list_strings; if (!empty($this->status_id)) { //_pp($this->status_id); $this->status = $app_list_strings['document_status_dom'][$this->status_id]; } $this->related_doc_name = Document::get_document_name($this->related_doc_id); $this->related_doc_rev_number = DocumentRevision::get_document_revision_name($this->related_doc_rev_id); $this->save_file = basename($this->file_url_noimage); }
/** * 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 $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; }
$kbdoc = new KBDocument(); $kbdoc->kbdocument_name = $v['name']; $kbdoc->status_id = 'Published'; $kbdoc->team_id = 1; $kbdoc->assigned_user_id = 'seed_will_id'; $kbdoc->active_date = $v['start_date']; $kbdoc->exp_date = $v['exp_date']; $kbdoc->is_external_article = 1; $kbdoc->save(); $kbdocRevision = new KBDocumentRevision(); $kbdocRevision->change_log = translate('DEF_CREATE_LOG', 'KBDocuments'); $kbdocRevision->revision = '1'; $kbdocRevision->kbdocument_id = $kbdoc->id; $kbdocRevision->latest = true; $kbdocRevision->save(); $docRevision = new DocumentRevision(); $docRevision->filename = $kbdoc->kbdocument_name; $docRevision->save(); $kbdocContent = new KBContent(); $kbdocContent->document_revision_id = $docRevision->id; $kbdocContent->team_id = $kbdoc->team_id; $kbdocContent->kbdocument_body = $v['body']; $kbdocContent->save(); $kbdocRevision->kbcontent_id = $kbdocContent->id; $kbdocRevision->document_revision_id = $docRevision->id; $kbdocRevision->save(); $kbdoc->kbdocument_revision_id = $kbdocRevision->id; $kbdoc->save(); foreach ($v['tags'] as $tag) { $kbdocKBTag = new KBDocumentKBTag(); $kbdocKBTag->kbtag_id = array_search($tag, $kbtags_hash);
function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'include/formbase.php'; require_once 'include/upload_file.php'; global $upload_maxsize, $upload_dir; global $mod_strings; global $sugar_config; $focus = new EmailTemplate(); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); //process the text only flag if (isset($_POST['text_only']) && $_POST['text_only'] == '1') { $focus->text_only = 1; } else { $focus->text_only = 0; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (!isset($_REQUEST['published'])) { $focus->published = 'off'; } $emailTemplateBodyHtml = from_html($focus->body_html); $fileBasePath = "{$sugar_config['cache_dir']}images/"; $filePatternSearch = "{$sugar_config['cache_dir']}"; $filePatternSearch = str_replace("/", "\\/", $filePatternSearch); $filePatternSearch = $filePatternSearch . "images\\/"; $fileBasePath1 = "\"" . $fileBasePath; if (strpos($emailTemplateBodyHtml, "\"{$fileBasePath}")) { $matches = array(); preg_match_all("/{$filePatternSearch}.+?\"/i", $emailTemplateBodyHtml, $matches); foreach ($matches[0] as $match) { $filenameUndecoded = str_replace($fileBasePath, '', $match); $filename = urldecode(substr($filenameUndecoded, 0, -1)); $filenameUndecoded = str_replace("\"", '', $filenameUndecoded); $cid = $filename; $file_location = clean_path(getcwd() . "/{$sugar_config['cache_dir']}images/{$filename}"); $mime_type = strtolower(substr($filename, strrpos($filename, ".") + 1, strlen($filename))); if (file_exists($file_location)) { $id = create_guid(); $newFileLocation = "{$sugar_config['upload_dir']}{$id}.{$mime_type}"; if (!copy($file_location, $newFileLocation)) { $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$sugar_config['upload_dir']} [ {$newFileLocation} ]"); } else { $emailTemplateBodyHtml = str_replace("{$sugar_config['cache_dir']}images/{$filenameUndecoded}", $newFileLocation, $emailTemplateBodyHtml); unlink($file_location); } } // if } // foreach } // if $focus->body_html = $emailTemplateBodyHtml; $return_id = $focus->save(); /////////////////////////////////////////////////////////////////////////////// //// ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS $max_files_upload = count($_FILES); if (!empty($focus->id)) { $note = new Note(); $where = "notes.parent_id='{$focus->id}'"; if (!empty($_REQUEST['old_id'])) { // to support duplication of email templates $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'"; } $notes_list = $note->get_full_list("", $where, true); } if (!isset($notes_list)) { $notes_list = array(); } if (!is_array($focus->attachments)) { // PHP5 does not auto-create arrays(). Need to initialize it here. $focus->attachments = array(); } $focus->attachments = array_merge($focus->attachments, $notes_list); //for($i = 0; $i < $max_files_upload; $i++) { foreach ($_FILES as $key => $file) { $note = new Note(); $i = preg_replace("/email_attachment(.+)/", '$1', $key); $upload_file = new UploadFile($key); if ($upload_file == -1) { continue; } if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) { if ($_REQUEST['embedded' . $i] == 'true') { $note->embed_flag = true; } else { $note->embed_flag = false; } } array_push($focus->attachments, $note); } } $focus->saved_attachments = array(); foreach ($focus->attachments as $note) { if (!empty($note->id)) { if (empty($_REQUEST['old_id'])) { // to support duplication of email templates array_push($focus->saved_attachments, $note); } else { // we're duplicating a template with attachments // dupe the file, create a new note, assign the note to the new template $newNote = new Note(); $newNote->retrieve($note->id); $newNote->id = create_guid(); $newNote->parent_id = $focus->id; $newNote->new_with_id = true; $newNote->date_modified = ''; $newNote->date_entered = ''; $newNoteId = $newNote->save(); $dupeFile = new UploadFile('duplicate'); $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename); } continue; } $note->parent_id = $focus->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; $note_id = $note->save(); array_push($focus->saved_attachments, $note); $note->id = $note_id; $note->file->final_move($note->id); } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS $count = ''; //_pp($_REQUEST); //_ppd(count($_REQUEST['document'])); if (!empty($_REQUEST['document'])) { $count = count($_REQUEST['document']); } else { $count = 10; } for ($i = 0; $i < $count; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $noteFile = new UploadFile('none'); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); array_push($focus->saved_attachments, $docRev); $docNote->name = $doc->document_name; $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $focus->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $focus->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// //// END ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////////// if ($redirect) { $GLOBALS['log']->debug("Saved record with id of " . $return_id); handleRedirect($return_id, "EmailTemplates"); } else { return $focus; } }
* * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not * reasonably feasible for technical reasons, the Appropriate Legal Notices must * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". ********************************************************************************/ /********************************************************************************* * Description: Deletes an Account record and then redirects the browser to the * defined return URL. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ global $mod_strings; if (!isset($_REQUEST['record'])) { sugar_die($mod_strings['ERR_DELETE_RECORD']); } $focus = new Document(); $focus->retrieve($_REQUEST['record']); if (!$focus->ACLAccess('Delete')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } if (isset($_REQUEST['object']) && ($_REQUEST['object'] = "documentrevision")) { //delete document revision. $focus = new DocumentRevision(); UploadFile::unlink_file($_REQUEST['revision_id'], $_REQUEST['filename']); } $focus->mark_deleted($_REQUEST['record']); header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
public function testbean_implements() { $documentRevision = new DocumentRevision(); $this->assertEquals(false, $documentRevision->bean_implements('')); //test with blank value $this->assertEquals(false, $documentRevision->bean_implements('test')); //test with invalid value $this->assertEquals(true, $documentRevision->bean_implements('FILE')); //test with valid value }
/** * @group 61144 */ public function testRealteDocumentRevision() { $actual = $this->revision->get_document_revision_name($this->revision->id); $this->assertEquals($this->revision->revision, $actual, 'Revision is incorrect'); }
* To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ global $app_strings; global $app_list_strings; global $mod_strings; global $current_user; global $locale; $xtpl = new XTemplate('modules/MailMerge/Step4.html'); $xtpl->assign("MOD", $mod_strings); $xtpl->assign("APP", $app_strings); if (!empty($_POST['document_id'])) { $_SESSION['MAILMERGE_DOCUMENT_ID'] = $_POST['document_id']; } $document_id = $_SESSION['MAILMERGE_DOCUMENT_ID']; $revision = new DocumentRevision(); $revision->retrieve($document_id); //$document = new Document(); //$document->retrieve($document_id); if (!empty($_POST['selected_objects'])) { $selObjs = urldecode($_POST['selected_objects']); $_SESSION['SELECTED_OBJECTS_DEF'] = $selObjs; } $selObjs = $_SESSION['SELECTED_OBJECTS_DEF']; $sel_obj = array(); parse_str(stripslashes(html_entity_decode($selObjs, ENT_QUOTES)), $sel_obj); foreach ($sel_obj as $key => $value) { $sel_obj[$key] = stripslashes($value); } $relArray = array(); //build relationship array
private function saveAttachedDocuments() { // $documents = 'documents'; // $this->bean->load_relationship($documents); $sequence = array(); if (isset($_POST["document_status"]) && !empty($_POST["document_status"])) { for ($i = 0; $i < count($_POST["document_status"]); $i++) { $document_id = $_POST['document_ids'][$i]; if ($_POST["document_status"][$i] == 'delete') { $revision = new DocumentRevision(); if ($revision->retrieve($_POST['document_ids'][$i])) { $document_id = $revision->document_id; } $document = new Document(); $document->retrieve($document_id); $changes = array('field_name' => $document->document_name, 'data_type' => 'varchar', 'before' => $document->filename, 'after' => '<deleted>'); global $sugar_version; if (floatval(substr($sugar_version, 0, 3)) > 6.3) { $this->bean->db->save_audit_records($this->bean, $changes); } else { $this->bean->dbManager->helper->save_audit_records($this->bean, $changes); } } else { $revision = new DocumentRevision(); if ($revision->retrieve($_POST['document_ids'][$i])) { $document_id = $revision->document_id; } // $this->bean->$documents->add($document_id); //2.1 We do not add documents here; only pdf files should be added $document = new Document(); $document->retrieve($document_id); if ($_POST["document_status"][$i] == 'new') { $changes = array('field_name' => $document->document_name, 'data_type' => 'varchar', 'before' => '<n/a>', 'after' => $document->filename); global $sugar_version; if (floatval(substr($sugar_version, 0, 3)) > 6.3) { $this->bean->db->save_audit_records($this->bean, $changes); } else { $this->bean->dbManager->helper->save_audit_records($this->bean, $changes); } } $sequence[] = $_POST['document_ids'][$i]; } } } $this->bean->attachmentsequence = implode(' ', $sequence); }
} $bean_name = $beanList[$module]; if (!file_exists('modules/' . $module . '/' . $bean_name . '.php')) { die($app_strings['ERROR_TYPE_NOT_VALID']); } require_once 'modules/' . $module . '/' . $bean_name . '.php'; $focus = new $bean_name(); $focus->retrieve($_REQUEST['id']); if (!$focus->ACLAccess('view')) { die($mod_strings['LBL_NO_ACCESS']); } // if // Pull up the document revision, if it's of type Document if (isset($focus->object_name) && $focus->object_name == 'Document') { // It's a document, get the revision that really stores this file $focusRevision = new DocumentRevision(); $focusRevision->retrieve($_REQUEST['id']); if (empty($focusRevision->id)) { // This wasn't a document revision id, it's probably actually a document id, we need to grab that, get the latest revision and use that $focusDocument = new Document(); $focusDocument->retrieve($_REQUEST['id']); $focusRevision->retrieve($focusDocument->document_revision_id); if (!empty($focusRevision->id)) { $_REQUEST['id'] = $focusRevision->id; } } } // See if it is a remote file, if so, send them that direction if (isset($focus->doc_url) && !empty($focus->doc_url)) { header('Location: ' . $focus->doc_url); sugar_die();
public function handleAttachments($focus, $redirect, $return_id) { /////////////////////////////////////////////////////////////////////////////// //// ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS global $mod_strings; $max_files_upload = count($_FILES); if (!empty($focus->id)) { $note = new Note(); $where = "notes.parent_id='{$focus->id}'"; if (!empty($_REQUEST['old_id'])) { // to support duplication of email templates $where .= " OR notes.parent_id='" . htmlspecialchars($_REQUEST['old_id'], ENT_QUOTES) . "'"; } $notes_list = $note->get_full_list("", $where, true); } if (!isset($notes_list)) { $notes_list = array(); } if (!is_array($focus->attachments)) { // PHP5 does not auto-create arrays(). Need to initialize it here. $focus->attachments = array(); } $focus->attachments = array_merge($focus->attachments, $notes_list); //for($i = 0; $i < $max_files_upload; $i++) { foreach ($_FILES as $key => $file) { $note = new Note(); //Images are presaved above so we need to prevent duplicate files from being created. if (isset($preProcessedImages[$file['name']])) { $oldId = $preProcessedImages[$file['name']]; $note->id = $oldId; $note->new_with_id = TRUE; $GLOBALS['log']->debug("Image {$file['name']} has already been processed."); } $i = preg_replace("/email_attachment(.+)/", '$1', $key); $upload_file = new UploadFile($key); if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) { if ($_REQUEST['embedded' . $i] == 'true') { $note->embed_flag = true; } else { $note->embed_flag = false; } } array_push($focus->attachments, $note); } } $focus->saved_attachments = array(); foreach ($focus->attachments as $note) { if (!empty($note->id) && $note->new_with_id === FALSE) { if (empty($_REQUEST['old_id'])) { array_push($focus->saved_attachments, $note); } else { // we're duplicating a template with attachments // dupe the file, create a new note, assign the note to the new template $newNote = new Note(); $newNote->retrieve($note->id); $newNote->id = create_guid(); $newNote->parent_id = $focus->id; $newNote->new_with_id = true; $newNote->date_modified = ''; $newNote->date_entered = ''; /* BEGIN - SECURITY GROUPS */ //Need to do this so that attachments show under an EmailTemplate correctly for a normal user global $current_user; $newNote->assigned_user_id = $current_user->id; /* END - SECURITY GROUPS */ $newNoteId = $newNote->save(); UploadFile::duplicate_file($note->id, $newNoteId, $note->filename); } continue; } $note->parent_id = $focus->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; /* BEGIN - SECURITY GROUPS */ //Need to do this so that attachments show under an EmailTemplate correctly for a normal user global $current_user; $note->assigned_user_id = $current_user->id; /* END - SECURITY GROUPS */ $note_id = $note->save(); array_push($focus->saved_attachments, $note); $note->id = $note_id; if ($note->new_with_id === FALSE) { $note->file->final_move($note->id); } else { $GLOBALS['log']->debug("Not performing final move for note id {$note->id} as it has already been processed"); } } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS $count = ''; //_pp($_REQUEST); //_ppd(count($_REQUEST['document'])); if (!empty($_REQUEST['document'])) { $count = count($_REQUEST['document']); } else { $count = 10; } for ($i = 0; $i < $count; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); array_push($focus->saved_attachments, $docRev); $docNote->name = $doc->document_name; $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $focus->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); UploadFile::duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $focus->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// //// END ATTACHMENT HANDLING /////////////////////////////////////////////////////////////////////////////// clear_register_value('select_array', $focus->object_name); if ($redirect) { $GLOBALS['log']->debug("Saved record with id of " . $return_id); handleRedirect($return_id, "EmailTemplates"); } else { return $focus; } }
$xtpl->assign("FILE_URL_NOIMAGE", $focus->file_url_noimage); $xtpl->assign("LAST_REV_CREATOR", $focus->last_rev_created_name); if (isset($focus->last_rev_create_date)) { $xtpl->assign("LAST_REV_DATE", $focus->last_rev_create_date); } else { $xtpl->assign("LAST_REV_DATE", ""); } $xtpl->assign("DOCUMENT_REVISION_ID", $focus->document_revision_id); $detailView->processListNavigation($xtpl, "DOCUMENT", $offset); $xtpl->parse("main.open_source"); if (!empty($focus->related_doc_id)) { $xtpl->assign("RELATED_DOCUMENT_NAME", Document::get_document_name($focus->related_doc_id)); } if (!empty($focus->related_doc_rev_id)) { $xtpl->assign("RELATED_DOC_REV_ID", $focus->related_doc_rev_id); $xtpl->assign("RELATED_DOCUMENT_VERSION", DocumentRevision::get_document_revision_name($focus->related_doc_rev_id)); } if (!empty($focus->is_template) && $focus->is_template == 1) { $xtpl->assign("IS_TEMPLATE_CHECKED", "checked"); } if (!empty($focus->template_type)) { $xtpl->assign("TEMPLATE_TYPE", $app_list_strings['document_template_type_dom'][$focus->template_type]); } // adding custom fields: require_once 'modules/DynamicFields/templates/Files/DetailView.php'; $xtpl->parse("main"); $xtpl->out("main"); require_once 'include/SubPanel/SubPanelTiles.php'; $subpanel = new SubPanelTiles($focus, 'Documents'); echo $subpanel->display(); require_once 'modules/SavedSearch/SavedSearch.php';
$item_ids = array(); parse_str(stripslashes(html_entity_decode($selObjs, ENT_QUOTES)), $item_ids); if ($module == 'CampaignProspects') { $module = 'Prospects'; if (!empty($_SESSION['MAILMERGE_CAMPAIGN_ID'])) { $targets = array_keys($item_ids); require_once 'modules/Campaigns/utils.php'; campaign_log_mail_merge($_SESSION['MAILMERGE_CAMPAIGN_ID'], $targets); } } $class_name = $beanList[$module]; $includedir = $beanFiles[$class_name]; require_once $includedir; $seed = new $class_name(); $fields = get_field_list($seed); $document = new DocumentRevision(); //new Document(); $document->retrieve($document_id); if (!empty($relModule)) { $rel_class_name = $beanList[$relModule]; require_once $beanFiles[$rel_class_name]; $rel_seed = new $rel_class_name(); } global $sugar_config; $filter = array(); if (array_key_exists('mailmerge_filter', $sugar_config)) { // $filter = $sugar_config['mailmerge_filter']; } array_push($filter, 'link'); $merge_array = array(); $merge_array['master_module'] = $module;
* Description: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'XTemplate/xtpl.php'; require_once 'data/Tracker.php'; require_once 'modules/Documents/Document.php'; require_once 'modules/DocumentRevisions/DocumentRevision.php'; require_once 'modules/Notes/Forms.php'; require_once 'include/upload_file.php'; global $app_strings; global $app_list_strings; global $mod_strings; global $current_user; $focus = new DocumentRevision(); if (isset($_REQUEST['record'])) { $focus->retrieve($_REQUEST['record']); } $old_id = ''; if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { if (!empty($focus->filename)) { $old_id = $focus->id; } $focus->id = ""; } echo "\n<p>\n"; echo get_module_title('DocumentRevisions', $mod_strings['LBL_MODULE_NAME'] . ": " . $focus->document_name, true); echo "\n</p>\n"; global $theme; $theme_path = "themes/" . $theme . "/";
private function createNewRevision($productCatalog, &$document) { global $timedate; global $app_list_strings; $productCatalogFilename = $this->categoryPagesToPdf($productCatalog); if (!$productCatalogFilename) { $GLOBALS['log']->fatal('OQC: Failed to create new catalog revision'); return false; } $revision = new DocumentRevision(); if (!$revision->retrieve($document->document_revision_id)) { $revision->document_id = $document->id; $revision->revision = 0; } $revision->revision = $revision->revision + 1; if (DEBUG_PDF_CREATION) { $revision->file_mime_type = 'text/plain'; $revision->file_ext = 'log'; $revision->filename = $app_list_strings['oqc']['pdf']['common']['filenamePrefixCatalog'] . "_" . date("Ymd") . "_{$revision->revision}.log"; } else { $revision->file_mime_type = 'application/pdf'; $revision->file_ext = 'pdf'; $revision->filename = $app_list_strings['oqc']['pdf']['common']['filenamePrefixCatalog'] . "_" . date("Ymd") . "_{$revision->revision}.pdf"; } // set fields to null in order to correctly generate new values $revision->date_entered = ''; $revision->date_modified = ''; //$revision->filename = $app_list_strings['oqc']['pdf']['common']['filenamePrefixCatalog'] . "_" . date("Ymd") . "_{$revision->revision}.pdf"; $revision->id = ''; $revision->save(); rename($productCatalogFilename, getDocumentFilename($revision->id)); $document->document_revision_id = $revision->id; return true; }
/** * handles attachments of various kinds when sending email */ function handleAttachments() { global $mod_strings; /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DRAFTS if (($this->type == 'out' || $this->type == 'draft') && $this->status == 'draft' && isset($_REQUEST['record'])) { $this->getNotes($_REQUEST['record']); // cn: get notes from OLD email for use in new email } //// END ATTACHMENTS FROM DRAFTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM FORWARDS // Bug 8034 Jenny - Need the check for type 'draft' here to handle cases where we want to save // forwarded messages as drafts. We still need to save the original message's attachments. if (($this->type == 'out' || $this->type == 'draft') && isset($_REQUEST['origType']) && $_REQUEST['origType'] == 'forward' && isset($_REQUEST['return_id']) && !empty($_REQUEST['return_id'])) { $this->getNotes($_REQUEST['return_id'], true); } // cn: bug 8034 - attachments from forward/replies lost when saving in draft if (isset($_REQUEST['prior_attachments']) && !empty($_REQUEST['prior_attachments']) && $this->new_with_id == true) { $exIds = explode(",", $_REQUEST['prior_attachments']); if (!isset($_REQUEST['template_attachment'])) { $_REQUEST['template_attachment'] = array(); } $_REQUEST['template_attachment'] = array_merge($_REQUEST['template_attachment'], $exIds); } //// END ATTACHMENTS FROM FORWARDS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM TEMPLATES // to preserve individual email integrity, we must dupe Notes and associated files // for each outbound email - good for integrity, bad for filespace if (isset($_REQUEST['template_attachment']) && !empty($_REQUEST['template_attachment'])) { $removeArr = array(); $noteArray = array(); if (isset($_REQUEST['temp_remove_attachment']) && !empty($_REQUEST['temp_remove_attachment'])) { $removeArr = $_REQUEST['temp_remove_attachment']; } foreach ($_REQUEST['template_attachment'] as $noteId) { if (in_array($noteId, $removeArr)) { continue; } $noteTemplate = new Note(); $noteTemplate->retrieve($noteId); $noteTemplate->id = create_guid(); $noteTemplate->new_with_id = true; // duplicating the note with files $noteTemplate->parent_id = $this->id; $noteTemplate->parent_type = $this->module_dir; $noteTemplate->date_entered = ''; $noteTemplate->save(); $noteFile = new UploadFile('none'); $noteFile->duplicate_file($noteId, $noteTemplate->id, $noteTemplate->filename); $noteArray[] = $noteTemplate; } $this->attachments = array_merge($this->attachments, $noteArray); } //// END ATTACHMENTS FROM TEMPLATES /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ADDING NEW ATTACHMENTS $max_files_upload = 10; // Jenny - Bug 8211 Since attachments for drafts have already been processed, // we don't need to re-process them. if ($this->status != "draft") { $notes_list = array(); if (!empty($this->id) && !$this->new_with_id) { $note = new Note(); $where = "notes.parent_id='{$this->id}'"; $notes_list = $note->get_full_list("", $where, true); } $this->attachments = array_merge($this->attachments, $notes_list); } // cn: Bug 5995 - rudimentary error checking $filesError = array(0 => 'UPLOAD_ERR_OK - There is no error, the file uploaded with success.', 1 => 'UPLOAD_ERR_INI_SIZE - The uploaded file exceeds the upload_max_filesize directive in php.ini.', 2 => 'UPLOAD_ERR_FORM_SIZE - The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 3 => 'UPLOAD_ERR_PARTIAL - The uploaded file was only partially uploaded.', 4 => 'UPLOAD_ERR_NO_FILE - No file was uploaded.', 5 => 'UNKNOWN ERROR', 6 => 'UPLOAD_ERR_NO_TMP_DIR - Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.', 7 => 'UPLOAD_ERR_CANT_WRITE - Failed to write file to disk. Introduced in PHP 5.1.0.'); for ($i = 0; $i < $max_files_upload; $i++) { // cn: Bug 5995 - rudimentary error checking if (!isset($_FILES["email_attachment{$i}"])) { $GLOBALS['log']->debug("Email Attachment {$i} does not exist."); continue; } if ($_FILES['email_attachment' . $i]['error'] != 0 && $_FILES['email_attachment' . $i]['error'] != 4) { $GLOBALS['log']->debug('Email Attachment could not be attach due to error: ' . $filesError[$_FILES['email_attachment' . $i]['error']]); continue; } $note = new Note(); $note->parent_id = $this->id; $note->parent_type = $this->module_dir; $upload_file = new UploadFile('email_attachment' . $i); if (empty($upload_file)) { continue; } if (isset($_FILES['email_attachment' . $i]) && $upload_file->confirm_upload()) { $note->filename = $upload_file->get_stored_file_name(); $note->file = $upload_file; $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name; $this->attachments[] = $note; } } $this->saved_attachments = array(); foreach ($this->attachments as $note) { if (!empty($note->id)) { array_push($this->saved_attachments, $note); continue; } $note->parent_id = $this->id; $note->parent_type = 'Emails'; $note->file_mime_type = $note->file->mime_type; $note_id = $note->save(); $this->saved_attachments[] = $note; $note->id = $note_id; $note->file->final_move($note->id); } //// END NEW ATTACHMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// ATTACHMENTS FROM DOCUMENTS for ($i = 0; $i < 10; $i++) { if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) { $doc = new Document(); $docRev = new DocumentRevision(); $docNote = new Note(); $noteFile = new UploadFile('none'); $doc->retrieve($_REQUEST['documentId' . $i]); $docRev->retrieve($doc->document_revision_id); $this->saved_attachments[] = $docRev; // cn: bug 9723 - Emails with documents send GUID instead of Doc name $docNote->name = $docRev->getDocumentRevisionNameForDisplay(); $docNote->filename = $docRev->filename; $docNote->description = $doc->description; $docNote->parent_id = $this->id; $docNote->parent_type = 'Emails'; $docNote->file_mime_type = $docRev->file_mime_type; $docId = $docNote = $docNote->save(); $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename); } } //// END ATTACHMENTS FROM DOCUMENTS /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// //// REMOVE ATTACHMENTS if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) { foreach ($_REQUEST['remove_attachment'] as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $this->db->query($q); } } //this will remove attachments that have been selected to be removed from drafts. if (isset($_REQUEST['removeAttachment']) && !empty($_REQUEST['removeAttachment'])) { $exRemoved = explode('::', $_REQUEST['removeAttachment']); foreach ($exRemoved as $noteId) { $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\''; $this->db->query($q); } } //// END REMOVE ATTACHMENTS /////////////////////////////////////////////////////////////////////////// }
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'XTemplate/xtpl.php'; require_once 'data/Tracker.php'; require_once 'modules/Documents/Document.php'; require_once 'modules/DocumentRevisions/DocumentRevision.php'; require_once 'include/upload_file.php'; require_once 'modules/Users/User.php'; global $app_strings; global $app_list_strings; global $mod_strings; global $current_user; global $gridline; $focus = new DocumentRevision(); if (isset($_REQUEST['record'])) { $focus->retrieve($_REQUEST['record']); } $old_id = ''; echo "\n<p>\n"; echo get_module_title('DocumentRevisions', $mod_strings['LBL_MODULE_NAME'] . ": " . $focus->document_name, true); echo "\n</p>\n"; global $theme; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; require_once $theme_path . 'layout_utils.php'; $GLOBALS['log']->info("Document revision detail view"); $xtpl = new XTemplate('modules/DocumentRevisions/DetailView.html'); $xtpl->assign("MOD", $mod_strings); $xtpl->assign("APP", $app_strings);
/** * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a * properly authenticated user to download a document that they have proper rights to download. * * @param String $session -- Session ID returned by a previous call to login. * @param String $id -- ID of the document revision to obtain * @return return_document_revision - this is a complex type as defined in SoapTypes.php */ function get_document_revision($session, $id) { global $sugar_config; $error = new SoapError(); if (!validate_authenticated($session)) { $error->set_error('invalid_login'); return array('id' => -1, 'error' => $error->get_soap_array()); } $dr = new DocumentRevision(); $dr->retrieve($id); if (!empty($dr->filename)) { $filename = $sugar_config['upload_dir'] . "/" . $dr->id; $handle = sugar_fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $contents = base64_encode($contents); $fh = sugar_fopen($sugar_config['upload_dir'] . "/rogerrsmith.doc", 'w'); fwrite($fh, base64_decode($contents)); return array('document_revision' => array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error' => $error->get_soap_array()); } else { $error->set_error('no_records'); return array('id' => -1, 'error' => $error->get_soap_array()); } }
function gen_prosmotr() { require_once 'custom/include/PHPWord/PHPWord.php'; $bean = loadBean('Meetings'); $bean->retrieve($_REQUEST['record']); $user = loadBean('Users'); // получаем реелтора $user->retrieve($bean->assigned_user_id); $client = loadBean($bean->parent_type); // получаем клиента $client->retrieve($bean->parent_id); $realty = loadBean('Realty'); // получаем объект $realty->retrieve($bean->realty_id); /*$client = loadBean('Contacts');// получаем клиента $client->retrieve($bean->contact_id);*/ $doc = new Document(); // создаем запись в документах и описание файла к нему $doc->id = create_guid(); $doc->new_with_id = true; $doc->document_name = "Просмотровый лист по показу {$bean->name}"; $doc->status_id = "Active"; $doc_rev = new DocumentRevision(); $doc_rev->filename = "просмотровый лист - {$bean->name}.docx"; $doc_rev->file_ext = "docx"; $doc_rev->file_mime_type = "application/octet-stream"; $doc_rev->revision = "1"; $doc_rev->document_id = $doc->id; $doc_rev->save(); $doc->document_revision_id = $doc_rev->id; $doc->save(); /*$client->load_relationship('documents'); // цепляем документ к клиенту $client->documents->add($doc->id,array());*/ //Set table cells style $cellStyle = array('borderTopSize' => 1, 'borderTopColor' => '000000', 'borderLeftSize' => 1, 'borderLeftColor' => '000000', 'borderRightSize' => 1, 'borderRightColor' => '000000', 'borderBottomSize' => 1, 'borderBottomColor' => '000000'); // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); //Add title $section->addText('Просмотровый лист', array('size' => 18, 'bold' => true), array('align' => 'center')); // Add table $table = $section->addTable(); $table->addRow(); // Add Cell $table->addCell(1750, $cellStyle)->addText("Дата и время"); $table->addCell(1750, $cellStyle)->addText("Адрес"); $table->addCell(1750, $cellStyle)->addText("Описание"); $table->addCell(1750, $cellStyle)->addText("Объект"); $table->addCell(1750, $cellStyle)->addText("Клиент"); $table->addCell(1750, $cellStyle)->addText("Риэлтор"); $table->addRow(); $table->addCell(1750, $cellStyle)->addText($bean->date_start); $table->addCell(1750, $cellStyle)->addText($bean->location); $table->addCell(1750, $cellStyle)->addText($bean->description); $table->addCell(1750, $cellStyle)->addText($realty->name); $table->addCell(1750, $cellStyle)->addText($client->first_name . ' ' . $client->last_name); $table->addCell(1750, $cellStyle)->addText($user->first_name . ' ' . $user->last_name); // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save("upload/{$doc_rev->id}"); echo "<h1>Просмотровый лист создан</h1><br/>\n\t\t<a href='index.php?entryPoint=download&id={$doc_rev->id}&type=Documents'>Скачать файл</a><br/>\n\t\t<a href='index.php?module=Documents&action=DetailView&record={$doc->id}'>Перейти в документ</a><hr/>\n\t\t<a href='index.php?module=Meetings&action=DetailView&record={$_REQUEST['record']}'>Вернуться в карточку показа</a>\n\t\t"; }