]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/InboundEmail/ShowInboundFoldersList.php
Release 6.1.5
[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 if(!empty($_REQUEST['ie_id'])) {
114     $ie->retrieve($_REQUEST['ie_id']);
115 }
116 $ie->email_user     = $_REQUEST['email_user'];
117 $ie->server_url     = $_REQUEST['server_url'];
118 $ie->port           = $_REQUEST['port'];
119 $ie->protocol       = $_REQUEST['protocol'];
120 //Bug 23083.Special characters in email password results in IMAP authentication failure
121 if(!empty($_REQUEST['email_password'])) {
122     $ie->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
123     $ie->email_password = str_rot13($ie->email_password);
124 }
125 //$ie->mailbox      = $_REQUEST['mailbox'];
126
127 $ie->mailbox        = 'INBOX';
128
129 if($popupBoolean) {
130     $returnArray = $ie->getFoldersListForMailBox();
131     $foldersList = $returnArray['foldersList'];
132     if ($returnArray['status']) {
133         $msg = $returnArray['statusMessage'];
134         $requestMailBox = explode(",", $_REQUEST['mailbox']);
135         $foldersListArray = explode(",", $foldersList);
136         $deletedFoldersString = "";
137         $count = 0;
138         if (!empty($requestMailBox) && !empty($foldersListArray)) {
139             foreach($requestMailBox as $mailbox) {
140                 if (!in_array($mailbox, $foldersListArray)) {
141                     if ($count != 0) {
142                         $deletedFoldersString = $deletedFoldersString . " ,";
143                     }
144                     $deletedFoldersString = $deletedFoldersString . $mailbox;
145                     $count++;
146                 }
147             } // foreach
148         } // if
149         if (!empty($deletedFoldersString)) {
150             $deletedFoldersList = $mod_strings['LBL_DELETED_FOLDERS_LIST'];
151             $deletedFoldersList = sprintf($deletedFoldersList, $deletedFoldersString);
152         }
153     } else {
154         $msg = $returnArray['statusMessage'];
155     }
156 }
157
158 ////    END TITLES
159 ///////////////////////////////////////////////////////////////////////////////
160
161 ///////////////////////////////////////////////////////////////////////////////
162 ////    COMMON CODE
163 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">
164                         <tr>
165                                 <td>&nbsp;
166                                 </td>
167                                 <td valign="top">
168                                         <div id="sf_msg">
169                                         '.$msg.'
170                                         </div>
171                                 </td>
172                         </tr>';
173 if (!empty($subdcriptionFolderHelp)) {
174 echo '<tr>
175                                 <td>&nbsp;
176                                 </td>
177                                 <td>&nbsp;
178                                 </td>
179                         </tr>
180                         <tr align="center">
181                                 <td>&nbsp;
182                                 </td>
183                                 <td>'.$subdcriptionFolderHelp.'
184                                 </td>
185                         </tr>';
186 } // if
187 echo '<tr>
188                                 <td>&nbsp;
189                                 </td>
190                                 <td valign="top">
191                                         <div id="sf_deletedFoldersList" style="display:none;">
192                                         '.$deletedFoldersList.'
193                                         </div>
194                                 </td>
195                         </tr>
196                         <tr align="center">
197                                 <td>&nbsp;
198                                 </td>
199                                 <td  valign="top">
200                                         <select '.$multipleString.' size="12" name="inboundmailboxes" id="sf_inboundmailboxes">
201                                         </select>
202                                 </td>
203                         </tr>
204                         <tr>
205                                 <td>&nbsp;
206                                 </td>
207                                 <td>&nbsp;
208                                 </td>
209                         </tr>
210                         <tr align="center">
211                                 <td>&nbsp;
212                                 </td>
213                                 <td>
214                                         <input type="button" style="" class="button" value="'.$app_strings['LBL_DONE_BUTTON_LABEL'].'" onclick="setMailbox();">
215                                         <input type="button" class="button" value="'.$app_strings['LBL_EMAIL_CANCEL'].'" onclick="SUGAR.inboundEmail.listDlg.hide()">
216                                 </td>
217                         </tr>
218                         <tr>
219                                 <td>&nbsp;
220                                 </td>
221                                 <td>&nbsp;
222                                 </td>
223                         </tr>';
224 echo '  </table>';
225
226 ////    END COMMON CODE
227 ///////////////////////////////////////////////////////////////////////////////
228
229 ///////////////////////////////////////////////////////////////////////////////
230 ////    COMPLETE RENDERING OF THE POPUP
231 echo '<input type="hidden" id="sf_returnstatus" name="returnstatus" value="'. $returnArray['status'] .'">';
232 echo '<input type="hidden" id="sf_foldersList" name="foldersList" value="'. $foldersList .'">';
233 echo '<input type="hidden" id="sf_selectedfoldersList" name="selectedfoldersList" value="'. implode(",", $requestMailBox) .'">';
234 echo '<input type="hidden" id="sf_searchField" name="searchField" value="'. $searchField .'">';
235
236 echo '
237 <script type="text/javascript">
238     SUGAR.inboundEmail.listDlg.setHeader("'.$title.'");
239     function setMailbox(box) {
240         var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
241         var selectedmbox = "";
242         var j = 0;
243         for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
244             if (inboundmailboxes.options[i].selected) {
245                 if (j != 0) {
246                     selectedmbox = selectedmbox + ",";
247                 } // if
248                 selectedmbox = selectedmbox + inboundmailboxes.options[i].value;
249                 j++;
250             } // if
251         } // for
252         var searchFieldValue = document.getElementById("sf_searchField").value;
253         if (searchFieldValue.length > 0) {
254             if (searchFieldValue == "trash") {
255                 var tf = document.getElementById("trashFolder");
256                 tf.value = selectedmbox;
257             } else if(searchFieldValue == "sent") {
258                 var sf = document.getElementById("sentFolder");
259                 sf.value = selectedmbox;
260             } // else
261         } else {
262             var mb = document.getElementById("mailbox");
263             mb.value = selectedmbox;
264         }
265         SUGAR.inboundEmail.listDlg.hide();
266      }
267         function switchMsg() {
268                 if(typeof(document.getElementById("sf_msg")) != "undefined") {
269                         document.getElementById("sf_msg").innerHTML = "'.$msg.'";
270                         var deletedFoldersList = document.getElementById("sf_deletedFoldersList");
271                         deletedFoldersList.innerHTML = "'. $deletedFoldersList .'";
272                         if (deletedFoldersList.innerHTML.length > 0) {
273                                 deletedFoldersList.style.display = "";
274                         } // if
275                         var selectedFoldersListObject = new Object();
276                         var selectedFoldersListArray = document.getElementById("sf_selectedfoldersList").value.split(",");
277                         for (var j = 0 ; j < selectedFoldersListArray.length ; j++) {
278                                 selectedFoldersListObject[selectedFoldersListArray[j]] = selectedFoldersListArray[j];
279                         } // for
280                         if (document.getElementById("sf_returnstatus").value == "1") {
281                                 var foldersList = document.getElementById("sf_foldersList").value;
282                                 var foldersArray = foldersList.split(",");
283                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
284                                 for (var i = 0 ; i < foldersArray.length ; i++) {
285                                         var opt = new Option(foldersArray[i], foldersArray[i]);
286                                         if (selectedFoldersListObject[foldersArray[i]] != null) {
287                                                 opt.selected = true;
288                                         }
289                                         inboundmailboxes.options.add(opt);
290                                 } // for
291                         } // if
292                         var selectdFoldersValue = document.getElementById("sf_selectedfoldersList").value;
293                         var searchFieldValue = document.getElementById("sf_searchField").value;
294                         if (selectdFoldersValue.length <= 0) {
295                                 if (searchFieldValue.length > 0) {
296                                         if (searchFieldValue == "trash") {
297                                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
298                                                 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
299                                                         if ((inboundmailboxes.options[i].text.search(/trash/i) != -1) ||
300                                                                 (inboundmailboxes.options[i].text.search(/delete/i) != -1)) {
301
302                                                                 inboundmailboxes.options[i].selected = true;
303                                                                 break;
304                                                         }
305                                                 } // for
306                                         } // if
307                                         if (searchFieldValue == "sent") {
308                                                 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
309                                                 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
310                                                         if (inboundmailboxes.options[i].text.search(/sent/i) != -1) {
311
312                                                                 inboundmailboxes.options[i].selected = true;
313                                                                 break;
314                                                         }
315                                                 } // for
316                                         } // if
317                                 } // if
318                         } // if
319                 }
320         }
321         switchMsg();
322 </script>'
323 ?>