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