]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/CampaignDiagnostic.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Campaigns / CampaignDiagnostic.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-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:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 /************** general UI Stuff *************/
47
48
49
50
51 global $mod_strings;
52 global $app_list_strings;
53 global $app_strings;
54 global $current_user;
55
56 //if (!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
57 //account for use within wizards
58 if(!isset($_REQUEST['inline']) || $_REQUEST['inline'] != 'inline'){
59         $params = array();
60         $params[] = "<a href='index.php?module=Campaigns&action=index'>{$mod_strings['LBL_MODULE_NAME']}</a>";
61         $params[] = $mod_strings['LBL_CAMPAIGN_DIAGNOSTICS'];
62         
63         echo getClassicModuleTitle('Campaigns', $params, true);
64 }
65
66 global $theme;
67 global $currentModule;
68
69
70
71
72 if(isset($_REQUEST['inline']) && $_REQUEST['inline'] == 'inline'){
73     {
74
75 }
76 }else{
77     //use html if not inline
78     $ss = new Sugar_Smarty();
79     $ss->assign("MOD", $mod_strings);
80     $ss->assign("APP", $app_strings);
81     if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
82     if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
83     if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
84     // handle Create $module then Cancel
85     if (empty($_REQUEST['return_id'])) {
86         $ss->assign("RETURN_ACTION", 'index');
87     }
88 }
89
90 /************  EMAIL COMPONENTS *************/
91 //monitored mailbox section
92 $focus = new Administration();
93 $focus->retrieveSettings(); //retrieve all admin settings.
94
95
96 //run query for mail boxes of type 'bounce' 
97 $email_health = 0;
98 $email_components = 2;
99 $mbox_qry = "select * from inbound_email where deleted ='0' and mailbox_type = 'bounce'";
100 $mbox_res = $focus->db->query($mbox_qry);
101 $mboxTable = "<table border ='0' width='100%'  class='detail view' cellpadding='0' cellspacing='0'>";
102 //put all rows returned into an array
103 $mbox = array();
104 while ($mbox_row = $focus->db->fetchByAssoc($mbox_res)){$mbox[] = $mbox_row;}
105     $mbox_msg = ' ';
106 //if the array is not empty, then set "good" message
107 if(isset($mbox) && count($mbox)>0){
108     $mboxTable .= "<tr><td colspan='5' style='text-align: left;'><b>" .count($mbox) ." ". $mod_strings['LBL_MAILBOX_CHECK1_GOOD']." </b>.</td></tr>";
109         $mboxTable .= "<tr><th scope='col' width='20%'><b>".$mod_strings['LBL_MAILBOX_NAME']."</b></th>"
110                    .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_LOGIN']."</b></th>"
111                    .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAILBOX']."</b></th>"
112                    .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_SERVER_URL']."</b></th>"
113                    .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_LIST_STATUS']."</b></th></tr>";
114
115     foreach($mbox as $details){
116         $mboxTable .= "<tr><td>".$details['name']."</td>";
117         $mboxTable .= "<td>".$details['email_user']."</td>";
118         $mboxTable .= "<td>".$details['mailbox']."</td>";
119         $mboxTable .= "<td>".$details['server_url']."</td>";
120         $mboxTable .= "<td>".$details['status']."</td></tr>";
121     }
122
123 }else{
124     //if array is empty, then set "bad" message and increment health counter
125     $mboxTable .=  "<tr><td colspan='5'><b class='error'>". $mod_strings['LBL_MAILBOX_CHECK1_BAD']."</b></td></tr>";
126     $email_health =$email_health +1;
127 }
128
129 $mboxTable.= '</table>' ;
130
131
132     
133 $ss->assign("MAILBOXES_DETECTED_MESSAGE", $mboxTable);
134
135 //email settings configured 
136 $conf_msg="<table border='0' width='100%' class='detail view' cellpadding='0' cellspacing='0'>";
137 if (strstr($focus->settings['notify_fromaddress'], 'example.com')){
138     //if from address is the default, then set "bad" message and increment health counter
139     $conf_msg .= "<tr><td colspan = '5'><b class='error'> ".$mod_strings['LBL_MAILBOX_CHECK2_BAD']." </b></td></td>";
140     $email_health =$email_health +1;
141 }else{
142     $conf_msg .= "<tr><td colspan = '5'><b> ".$mod_strings['LBL_MAILBOX_CHECK2_GOOD']."</b></td></tr>";
143     $conf_msg .= "<tr><th scope='col' width='20%'><b>".$mod_strings['LBL_WIZ_FROM_NAME']."</b></th>"
144                .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_WIZ_FROM_ADDRESS']."</b></th>"
145                .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SENDTYPE']."</b></th>";
146     if($focus->settings['mail_sendtype']=='SMTP'){
147      $conf_msg .= " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SMTPSERVER']."</b></th>"
148                .  " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SMTPUSER']."</b></th></tr>";
149
150     }else{$conf_msg .= "</tr>";}
151                    
152     
153
154         $conf_msg .= "<tr><td>".$focus->settings['notify_fromname']."</td>";
155         $conf_msg .= "<td>".$focus->settings['notify_fromaddress']."</td>";
156         $conf_msg .= "<td>".$focus->settings['mail_sendtype']."</td>";
157      if($focus->settings['mail_sendtype']=='SMTP'){
158         $conf_msg .= "<td>".$focus->settings['mail_smtpserver']."</td>";
159         $conf_msg .= "<td>".$focus->settings['mail_smtpuser']."</td></tr>";
160
161     }else{$conf_msg .= "</tr>";}       
162
163 }
164           
165 $conf_msg .= '</table>'; 
166 $ss->assign("EMAIL_SETTINGS_CONFIGURED_MESSAGE", $conf_msg);
167 $email_setup_wiz_link='';
168 if ($email_health>0){
169     if (is_admin($current_user)){
170         $email_setup_wiz_link="<a href='index.php?module=Campaigns&action=WizardEmailSetup'>".$mod_strings['LBL_EMAIL_SETUP_WIZ']."</a>";
171     }else{
172         $email_setup_wiz_link=$mod_strings['LBL_NON_ADMIN_ERROR_MSG'];
173     }    
174 }
175
176 $ss->assign("EMAIL_SETUP_WIZ_LINK", $email_setup_wiz_link);
177 $ss->assign( 'EMAIL_IMAGE', define_image($email_health, 2));
178 $ss->assign( 'EMAIL_COMPONENTS', $mod_strings['LBL_EMAIL_COMPONENTS']);
179 $ss->assign( 'SCHEDULER_COMPONENTS', $mod_strings['LBL_SCHEDULER_COMPONENTS']);
180 $ss->assign( 'RECHECK_BTN', $mod_strings['LBL_RECHECK_BTN']);
181
182 /************* SCHEDULER COMPONENTS ************/
183
184 //create and run the scheduler queries 
185 $sched_qry = "select job, name, status from schedulers where deleted = 0 and status = 'Active'";
186 $sched_res = $focus->db->query($sched_qry);
187 $sched_health = 0;
188 $sched = array();
189 $check_sched1 = 'function::runMassEmailCampaign';
190 $check_sched2 = 'function::pollMonitoredInboxesForBouncedCampaignEmails';
191 $sched_mes = '';
192 $sched_mes_body = '';
193
194 $scheds = array();
195 //build the table rows for scheduler display
196 while ($sched_row = $focus->db->fetchByAssoc($sched_res)){$scheds[] = $sched_row;}
197 foreach ($scheds as $funct){
198   if( ($funct['job']==$check_sched1)  ||   ($funct['job']==$check_sched2)){
199         $sched_mes = 'use';
200         $sched_mes_body .= "<tr><td style='text-align: left;'>".$funct['name']."</td>";
201         $sched_mes_body .= "<td style='text-align: left;'>".$funct['status']."</td></tr>";
202         if($funct['job']==$check_sched1){
203             $check_sched1 ="found";
204         }else{
205             $check_sched2 ="found";
206         }  
207         
208   }
209 }
210
211 //determine which table header to use, based on whether or not schedulers were found
212 $show_admin_link = false;
213 if($sched_mes == 'use'){
214     $sched_mes = "<h5>".$mod_strings['LBL_SCHEDULER_CHECK_GOOD']."</h5><br><table class='other view' cellspacing='1'>";
215     $sched_mes .= "<tr><th scope='col' width='40%'><b>".$mod_strings['LBL_SCHEDULER_NAME']."</b></tH>"
216                .  " <th scope='col' width='60%'><b>".$mod_strings['LBL_SCHEDULER_STATUS']."</b></tH></tr>";
217             
218 }else{
219     $sched_mes = "<table class='other view' cellspacing='1'>";
220     $sched_mes  .= "<tr><td colspan ='3'><font color='red'><b> ".$mod_strings['LBL_SCHEDULER_CHECK_BAD']."</b></font></td></tr>";
221     $show_admin_link = true;
222 }
223
224 //determine if error messages need to be displayed for schedulers
225 if($check_sched2 != 'found'){
226     $sched_health =$sched_health +1;
227     $sched_mes_body  .= "<tr><td colspan ='3'><font color='red'> ".$mod_strings['LBL_SCHEDULER_CHECK1_BAD']."</font></td></tr>";
228 }
229 if($check_sched1 != 'found'){
230     $sched_health =$sched_health +1;
231     $sched_mes_body  .= "<tr><td colspan ='3' scope='row'><font color='red'>".$mod_strings['LBL_SCHEDULER_CHECK2_BAD']."</font></td></tr>";
232 }
233 $admin_sched_link='';
234 if ($sched_health>0){
235     if (is_admin($current_user)){
236         $admin_sched_link="<a href='index.php?module=Schedulers&action=index'>".$mod_strings['LBL_SCHEDULER_LINK']."</a>";
237     }else{
238      $admin_sched_link=$mod_strings['LBL_NON_ADMIN_ERROR_MSG'];   
239     }    
240 }    
241
242 //put table html together and display
243     $final_sched_msg = $sched_mes . $sched_mes_body . '</table>' . $admin_sched_link;        
244     $ss->assign("SCHEDULER_EMAILS_MESSAGE", $final_sched_msg);
245     $ss->assign( 'SCHEDULE_IMAGE', define_image($sched_health, 2));
246
247
248 /********** FINAL END OF PAGE UI Stuff ********/
249 if(!isset($_REQUEST['inline']) || $_REQUEST['inline'] != 'inline'){
250
251       $ss->display('modules/Campaigns/CampaignDiagnostic.html');
252 }
253
254 /**
255  * This function takes in 3 parameters and determines the appropriate image source.  
256  * 
257  * @param  int $num parameter is the "health" parameter being tracked whenever there is something wrong.  (higher number =bad)
258  * @param  int $total Parameter is the total number things being checked.
259  * @return string HTML img tag
260  */
261 function define_image($num, $total)
262 { global $mod_strings;
263     //if health number is equal to total number then all checks failed, set red image
264     if($num == $total){
265         //red
266         return SugarThemeRegistry::current()->getImage('red_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_INVALID']);
267
268
269     }elseif($num == 0){
270         //if health number is zero, then all checks passed, set green image
271         //green
272        return SugarThemeRegistry::current()->getImage('green_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_VALID']);
273
274
275     }else{
276         //if health number is between total and num params, then some checks failed but not all, set yellow image
277         //yellow
278         return SugarThemeRegistry::current()->getImage('yellow_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_ALERT']);
279
280
281     }
282 }
283     
284 ?>