]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/InboundEmail/ShowInboundFoldersList.php
Release 6.5.0
[Github/sugarcrm.git] / modules / InboundEmail / ShowInboundFoldersList.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 /*********************************************************************************
39
40  * Description:
41  ********************************************************************************/
42  // hack to allow "&", "%" and "+" through a $_GET var
43 // set by ie_test_open_popup() javascript call
44 foreach($_REQUEST as $k => $v) {
45         $v = str_replace('::amp::', '&', $v);
46         $v = str_replace('::plus::', '+', $v);
47         $v = str_replace('::percent::', '%', $v);
48         $_REQUEST[$k] = $v;
49 }
50
51 require_once('modules/InboundEmail/language/en_us.lang.php');
52 global $theme;
53
54
55
56
57 // GLOBALS
58 global $mod_strings;
59 global $app_strings;
60 global $app_list_strings;
61 global $current_user;
62 global $sugar_config;
63
64 $title                          = '';
65 $msg                            = '';
66 $tls                            = '';
67 $cert                           = '';
68 $ssl                            = '';
69 $notls                          = '';
70 $novalidate_cert        = '';
71 $useSsl                         = false;
72 $deletedFoldersList = "";
73
74 ///////////////////////////////////////////////////////////////////////////////
75 ////    TITLES
76
77 $popupBoolean = false;
78 if (isset($_REQUEST['target']) && $_REQUEST['target'] == 'Popup') {
79         $popupBoolean = true;
80 }
81 if (isset($_REQUEST['target1']) && $_REQUEST['target1'] == 'Popup') {
82         $popupBoolean = true;
83 }
84
85 if($popupBoolean) {
86         $title = $mod_strings['LBL_SELECT_SUBSCRIBED_FOLDERS'];
87         $msg = $mod_strings['LBL_TEST_WAIT_MESSAGE'];
88 }
89
90 $subdcriptionFolderHelp = $app_strings['LBL_EMAIL_SUBSCRIPTION_FOLDER_HELP'];
91
92 if(isset($_REQUEST['ssl']) && ($_REQUEST['ssl'] == "true" || $_REQUEST['ssl'] == 1)) {
93         $useSsl = true;
94 }
95
96 $searchField = !empty($_REQUEST['searchField']) ? $_REQUEST['searchField'] : "";
97 $multipleString = "multiple=\"true\"";
98 if (!empty($searchField)) {
99         $subdcriptionFolderHelp = "";
100         $multipleString = "";
101         if ($searchField == 'trash') {
102                 $title = $mod_strings['LBL_SELECT_TRASH_FOLDERS'];
103         } else {
104                 $title = $mod_strings['LBL_SELECT_SENT_FOLDERS'];
105         } // else
106
107 } // else
108
109
110 $ie                 = new InboundEmail();
111 if(!empty($_REQUEST['ie_id'])) {
112     $ie->retrieve($_REQUEST['ie_id']);
113 }
114 $ie->email_user     = $_REQUEST['email_user'];
115 $ie->server_url     = $_REQUEST['server_url'];
116 $ie->port           = $_REQUEST['port'];
117 $ie->protocol       = $_REQUEST['protocol'];
118 //Bug 23083.Special characters in email password results in IMAP authentication failure
119 if(!empty($_REQUEST['email_password'])) {
120     $ie->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
121     $ie->email_password = str_rot13($ie->email_password);
122 }
123 //$ie->mailbox      = $_REQUEST['mailbox'];
124
125 $ie->mailbox        = 'INBOX';
126
127 if($popupBoolean) {
128     $returnArray = $ie->getFoldersListForMailBox();
129     $foldersList = $returnArray['foldersList'];
130     if ($returnArray['status']) {
131         $msg = $returnArray['statusMessage'];
132         $requestMailBox = explode(",", $_REQUEST['mailbox']);
133         $foldersListArray = explode(",", $foldersList);
134         $deletedFoldersString = "";
135         $count = 0;
136         if (!empty($requestMailBox) && !empty($foldersListArray)) {
137             foreach($requestMailBox as $mailbox) {
138                 if (!in_array($mailbox, $foldersListArray)) {
139                     if ($count != 0) {
140                         $deletedFoldersString = $deletedFoldersString . " ,";
141                     }
142                     $deletedFoldersString = $deletedFoldersString . $mailbox;
143                     $count++;
144                 }
145             } // foreach
146         } // if
147         if (!empty($deletedFoldersString)) {
148             $deletedFoldersList = $mod_strings['LBL_DELETED_FOLDERS_LIST'];
149             $deletedFoldersList = sprintf($deletedFoldersList, $deletedFoldersString);
150         }
151     } else {
152         $msg = $returnArray['statusMessage'];
153     }
154 }
155
156 ////    END TITLES
157 ///////////////////////////////////////////////////////////////////////////////
158
159 ///////////////////////////////////////////////////////////////////////////////
160 ////    COMMON CODE
161 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">
162                         <tr>
163                                 <td>&nbsp;
164                                 </td>
165                                 <td valign="top">
166                                         <div id="sf_msg">
167                                         '.$msg.'
168                                         </div>
169                                 </td>
170                         </tr>';
171 if (!empty($subdcriptionFolderHelp)) {
172 echo '<tr>
173                                 <td>&nbsp;
174                                 </td>
175                                 <td>&nbsp;
176                                 </td>
177                         </tr>
178                         <tr align="center">
179                                 <td>&nbsp;
180                                 </td>
181                                 <td>'.$subdcriptionFolderHelp.'
182                                 </td>
183                         </tr>';
184 } // if
185 echo '<tr>
186                                 <td>&nbsp;
187                                 </td>
188                                 <td valign="top">
189                                         <div id="sf_deletedFoldersList" style="display:none;">
190                                         '.$deletedFoldersList.'
191                                         </div>
192                                 </td>
193                         </tr>
194                         <tr align="center">
195                                 <td>&nbsp;
196                                 </td>
197                                 <td  valign="top">
198                                         <select '.$multipleString.' size="12" name="inboundmailboxes" id="sf_inboundmailboxes">
199                                         </select>
200                                 </td>
201                         </tr>
202                         <tr>
203                                 <td>&nbsp;
204                                 </td>
205                                 <td>&nbsp;
206                                 </td>
207                         </tr>
208                         <tr align="center">
209                                 <td>&nbsp;
210                                 </td>
211                                 <td>
212                                         <input type="button" style="" class="button" value="'.$app_strings['LBL_DONE_BUTTON_LABEL'].'" onclick="setMailbox();">
213                                         <input type="button" class="button" value="'.$app_strings['LBL_EMAIL_CANCEL'].'" onclick="SUGAR.inboundEmail.listDlg.hide()">
214                                 </td>
215                         </tr>
216                         <tr>
217                                 <td>&nbsp;
218                                 </td>
219                                 <td>&nbsp;
220                                 </td>
221                         </tr>';
222 echo '  </table>';
223
224 ////    END COMMON CODE
225 ///////////////////////////////////////////////////////////////////////////////
226
227 ///////////////////////////////////////////////////////////////////////////////
228 ////    COMPLETE RENDERING OF THE POPUP
229 echo '<input type="hidden" id="sf_returnstatus" name="returnstatus" value="'. $returnArray['status'] .'">';
230 echo '<input type="hidden" id="sf_foldersList" name="foldersList" value="'. htmlspecialchars($foldersList) .'">';
231 echo '<input type="hidden" id="sf_selectedfoldersList" name="selectedfoldersList" value="'. implode(",", $requestMailBox) .'">';
232 echo '<input type="hidden" id="sf_searchField" name="searchField" value="'. $searchField .'">';
233
234 echo '
235 <script type="text/javascript">
236     SUGAR.inboundEmail.listDlg.setHeader("'.$title.'");
237     function setMailbox(box) {
238         var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
239         var selectedmbox = "";
240         var j = 0;
241         for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
242             if (inboundmailboxes.options[i].selected) {
243                 if (j != 0) {
244                     selectedmbox = selectedmbox + ",";
245                 } // if
246                 selectedmbox = selectedmbox + inboundmailboxes.options[i].value;
247                 j++;
248             } // if
249         } // for
250         var searchFieldValue = document.getElementById("sf_searchField").value;
251         if (searchFieldValue.length > 0) {
252             if (searchFieldValue == "trash") {
253                 var tf = document.getElementById("trashFolder");
254                 tf.value = selectedmbox;
255             } else if(searchFieldValue == "sent") {
256                 var sf = document.getElementById("sentFolder");
257                 sf.value = selectedmbox;
258             } // else
259         } else {
260             var mb = document.getElementById("mailbox");
261             mb.value = selectedmbox;
262         }
263         SUGAR.inboundEmail.listDlg.hide();
264      }
265         function switchMsg() {
266                 if(typeof(document.getElementById("sf_msg")) != "undefined") {
267                         document.getElementById("sf_msg").innerHTML = "'.$msg.'";
268                         var deletedFoldersList = document.getElementById("sf_deletedFoldersList");
269                         deletedFoldersList.innerHTML = "'. $deletedFoldersList .'";
270                         if (deletedFoldersList.innerHTML.length > 0) {
271                                 deletedFoldersList.style.display = "";
272                         } // if
273                         var selectedFoldersListObject = new Object();
274                         var selectedFoldersListArray = document.getElementById("sf_selectedfoldersList").value.split(",");
275                         for (var j = 0 ; j < selectedFoldersListArray.length ; j++) {
276                                 selectedFoldersListObject[selectedFoldersListArray[j]] = selectedFoldersListArray[j];
277                         } // for
278                         if (document.getElementById("sf_returnstatus").value == "1") {
279                                 var foldersList = document.getElementById("sf_foldersList").value;
280                                 var foldersArray = foldersList.split(",");
281                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
282                                 for (var i = 0 ; i < foldersArray.length ; i++) {
283                                         var opt = new Option(foldersArray[i], foldersArray[i]);
284                                         if (selectedFoldersListObject[foldersArray[i]] != null) {
285                                                 opt.selected = true;
286                                         }
287                                         inboundmailboxes.options.add(opt);
288                                 } // for
289                         } // if
290                         var selectdFoldersValue = document.getElementById("sf_selectedfoldersList").value;
291                         var searchFieldValue = document.getElementById("sf_searchField").value;
292                         if (selectdFoldersValue.length <= 0) {
293                                 if (searchFieldValue.length > 0) {
294                                         if (searchFieldValue == "trash") {
295                                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
296                                                 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
297                                                         if ((inboundmailboxes.options[i].text.search(/trash/i) != -1) ||
298                                                                 (inboundmailboxes.options[i].text.search(/delete/i) != -1)) {
299
300                                                                 inboundmailboxes.options[i].selected = true;
301                                                                 break;
302                                                         }
303                                                 } // for
304                                         } // if
305                                         if (searchFieldValue == "sent") {
306                                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
307                                                 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
308                                                         if (inboundmailboxes.options[i].text.search(/sent/i) != -1) {
309
310                                                                 inboundmailboxes.options[i].selected = true;
311                                                                 break;
312                                                         }
313                                                 } // for
314                                         } // if
315                                 } // if
316                         } // if
317                 }
318         }
319         switchMsg();
320 </script>'
321 ?>