]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Notes/NoteSoap.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Notes / NoteSoap.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 require_once('include/upload_file.php');
39
40 require_once('include/upload_file.php');
41
42 class NoteSoap
43 {
44     var $upload_file;
45
46     function NoteSoap()
47     {
48         $this->upload_file = new UploadFile('uploadfile');
49     }
50
51     function saveFile($note, $portal = false)
52     {
53         global $sugar_config;
54
55         $focus = new Note();
56
57
58
59         if(!empty($note['id'])){
60                 $focus->retrieve($note['id']);
61                 if(empty($focus->id)) {
62                     return '-1';
63                 }
64         }else{
65                 return '-1';
66         }
67
68         if(!empty($note['file'])){
69                 $decodedFile = base64_decode($note['file']);
70                 $this->upload_file->set_for_soap($note['filename'], $decodedFile);
71
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";
77                 }
78
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);
84         }else{
85                 return '-1';
86         }
87
88         return $return_id;
89     }
90
91     function newSaveFile($note, $portal = false){
92         global $sugar_config;
93
94         $focus = new Note();
95
96
97         if(!empty($note['id'])){
98                 $focus->retrieve($note['id']);
99             if(empty($focus->id)) {
100                 return '-1';
101             }
102         } else {
103                 return '-1';
104         }
105
106         if(!empty($note['file'])){
107             $decodedFile = base64_decode($note['file']);
108             $this->upload_file->set_for_soap($note['filename'], $decodedFile);
109
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";
115             }
116
117             $focus->filename = $this->upload_file->get_stored_file_name();
118             $focus->file_mime_type = $this->upload_file->getMimeSoap($focus->filename);
119             $focus->save();
120         }
121
122         $return_id = $focus->id;
123
124         if(!empty($note['file'])){
125                 $this->upload_file->final_move($focus->id);
126         }
127
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;
135                         }else{
136                                 $focus->contact_id=$module_id;
137                         }
138                         $focus->save();
139
140         } // if
141         return $return_id;
142     }
143
144     function retrieveFile($id, $filename)
145     {
146         if(empty($filename)){
147                 return '';
148         }
149
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);
155         }
156         return -1;
157     }
158
159 }