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