2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require_once('include/upload_file.php');
40 require_once('include/upload_file.php');
48 $this->upload_file = new UploadFile('uploadfile');
51 function saveFile($note, $portal = false)
59 if(!empty($note['id'])){
60 $focus->retrieve($note['id']);
61 if(empty($focus->id)) {
68 if(!empty($note['file'])){
69 $decodedFile = base64_decode($note['file']);
70 $this->upload_file->set_for_soap($note['filename'], $decodedFile);
72 $ext_pos = strrpos($this->upload_file->stored_file_name, ".");
73 $this->upload_file->file_ext = substr($this->upload_file->stored_file_name, $ext_pos + 1);
74 if (in_array($this->upload_file->file_ext, $sugar_config['upload_badext'])) {
75 $this->upload_file->stored_file_name .= ".txt";
76 $this->upload_file->file_ext = "txt";
79 $focus->filename = $this->upload_file->get_stored_file_name();
80 $focus->file_mime_type = $this->upload_file->getMimeSoap($focus->filename);
81 $focus->id = $note['id'];
82 $return_id = $focus->save();
83 $this->upload_file->final_move($focus->id);
91 function newSaveFile($note, $portal = false){
97 if(!empty($note['id'])){
98 $focus->retrieve($note['id']);
99 if(empty($focus->id)) {
106 if(!empty($note['file'])){
107 $decodedFile = base64_decode($note['file']);
108 $this->upload_file->set_for_soap($note['filename'], $decodedFile);
110 $ext_pos = strrpos($this->upload_file->stored_file_name, ".");
111 $this->upload_file->file_ext = substr($this->upload_file->stored_file_name, $ext_pos + 1);
112 if (in_array($this->upload_file->file_ext, $sugar_config['upload_badext'])) {
113 $this->upload_file->stored_file_name .= ".txt";
114 $this->upload_file->file_ext = "txt";
117 $focus->filename = $this->upload_file->get_stored_file_name();
118 $focus->file_mime_type = $this->upload_file->getMimeSoap($focus->filename);
122 $return_id = $focus->id;
124 if(!empty($note['file'])){
125 $this->upload_file->final_move($focus->id);
128 if (!empty($note['related_module_id']) && !empty($note['related_module_name'])) {
129 $focus->process_save_dates=false;
130 $module_name = $note['related_module_name'];
131 $module_id = $note['related_module_id'];
132 if($module_name != 'Contacts'){
133 $focus->parent_type=$module_name;
134 $focus->parent_id = $module_id;
136 $focus->contact_id=$module_id;
144 function retrieveFile($id, $filename)
146 if(empty($filename)){
150 $this->upload_file->stored_file_name = $filename;
151 $filepath = $this->upload_file->get_upload_path($id);
152 if(file_exists($filepath)){
153 $file = file_get_contents($filepath);
154 return base64_encode($file);