PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Campaigns/CampaignDiagnostic.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 287 lines | 159 code | 51 blank | 77 comment | 38 complexity | 045490a73d26ef81dd6be4123fc62d97 MD5 | raw file
  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-2013 SugarCRM Inc.
  6. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  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. /************** general UI Stuff *************/
  46. global $mod_strings;
  47. global $app_list_strings;
  48. global $app_strings;
  49. global $current_user;
  50. //if (!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
  51. //account for use within wizards
  52. if(!isset($_REQUEST['inline']) || $_REQUEST['inline'] != 'inline'){
  53. $params = array();
  54. $params[] = "<a href='index.php?module=Campaigns&action=index'>{$mod_strings['LBL_MODULE_NAME']}</a>";
  55. $params[] = $mod_strings['LBL_CAMPAIGN_DIAGNOSTICS'];
  56. echo getClassicModuleTitle('Campaigns', $params, true);
  57. }
  58. global $theme;
  59. global $currentModule;
  60. if(isset($_REQUEST['inline']) && $_REQUEST['inline'] == 'inline'){
  61. {
  62. }
  63. }else{
  64. //use html if not inline
  65. $ss = new Sugar_Smarty();
  66. $ss->assign("MOD", $mod_strings);
  67. $ss->assign("APP", $app_strings);
  68. if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
  69. if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
  70. if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
  71. // handle Create $module then Cancel
  72. if (empty($_REQUEST['return_id'])) {
  73. $ss->assign("RETURN_ACTION", 'index');
  74. }
  75. }
  76. /************ EMAIL COMPONENTS *************/
  77. //monitored mailbox section
  78. $focus = new Administration();
  79. $focus->retrieveSettings(); //retrieve all admin settings.
  80. //run query for mail boxes of type 'bounce'
  81. $email_health = 0;
  82. $email_components = 2;
  83. $mbox_qry = "select * from inbound_email where deleted ='0' and mailbox_type = 'bounce'";
  84. $mbox_res = $focus->db->query($mbox_qry);
  85. $mboxTable = "<table border ='0' width='100%' class='detail view' cellpadding='0' cellspacing='0'>";
  86. //put all rows returned into an array
  87. $mbox = array();
  88. while ($mbox_row = $focus->db->fetchByAssoc($mbox_res)){$mbox[] = $mbox_row;}
  89. $mbox_msg = ' ';
  90. //if the array is not empty, then set "good" message
  91. if(isset($mbox) && count($mbox)>0){
  92. $mboxTable .= "<tr><td colspan='5' style='text-align: left;'><b>" .count($mbox) ." ". $mod_strings['LBL_MAILBOX_CHECK1_GOOD']." </b>.</td></tr>";
  93. $mboxTable .= "<tr><th scope='col' width='20%'><b>".$mod_strings['LBL_MAILBOX_NAME']."</b></th>"
  94. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_LOGIN']."</b></th>"
  95. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAILBOX']."</b></th>"
  96. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_SERVER_URL']."</b></th>"
  97. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_LIST_STATUS']."</b></th></tr>";
  98. foreach($mbox as $details){
  99. $mboxTable .= "<tr><td>".$details['name']."</td>";
  100. $mboxTable .= "<td>".$details['email_user']."</td>";
  101. $mboxTable .= "<td>".$details['mailbox']."</td>";
  102. $mboxTable .= "<td>".$details['server_url']."</td>";
  103. $mboxTable .= "<td>".$details['status']."</td></tr>";
  104. }
  105. }else{
  106. //if array is empty, then set "bad" message and increment health counter
  107. $mboxTable .= "<tr><td colspan='5'><b class='error'>". $mod_strings['LBL_MAILBOX_CHECK1_BAD']."</b></td></tr>";
  108. $email_health =$email_health +1;
  109. }
  110. $mboxTable.= '</table>' ;
  111. $ss->assign("MAILBOXES_DETECTED_MESSAGE", $mboxTable);
  112. //email settings configured
  113. $conf_msg="<table border='0' width='100%' class='detail view' cellpadding='0' cellspacing='0'>";
  114. if (strstr($focus->settings['notify_fromaddress'], 'example.com')){
  115. //if from address is the default, then set "bad" message and increment health counter
  116. $conf_msg .= "<tr><td colspan = '5'><b class='error'> ".$mod_strings['LBL_MAILBOX_CHECK2_BAD']." </b></td></td>";
  117. $email_health =$email_health +1;
  118. }else{
  119. $conf_msg .= "<tr><td colspan = '5'><b> ".$mod_strings['LBL_MAILBOX_CHECK2_GOOD']."</b></td></tr>";
  120. $conf_msg .= "<tr><th scope='col' width='20%'><b>".$mod_strings['LBL_WIZ_FROM_NAME']."</b></th>"
  121. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_WIZ_FROM_ADDRESS']."</b></th>"
  122. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SENDTYPE']."</b></th>";
  123. if($focus->settings['mail_sendtype']=='SMTP'){
  124. $conf_msg .= " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SMTPSERVER']."</b></th>"
  125. . " <th scope='col' width='20%'><b>".$mod_strings['LBL_MAIL_SMTPUSER']."</b></th></tr>";
  126. }else{$conf_msg .= "</tr>";}
  127. $conf_msg .= "<tr><td>".$focus->settings['notify_fromname']."</td>";
  128. $conf_msg .= "<td>".$focus->settings['notify_fromaddress']."</td>";
  129. $conf_msg .= "<td>".$focus->settings['mail_sendtype']."</td>";
  130. if($focus->settings['mail_sendtype']=='SMTP'){
  131. $conf_msg .= "<td>".$focus->settings['mail_smtpserver']."</td>";
  132. $conf_msg .= "<td>".$focus->settings['mail_smtpuser']."</td></tr>";
  133. }else{$conf_msg .= "</tr>";}
  134. }
  135. $conf_msg .= '</table>';
  136. $ss->assign("EMAIL_SETTINGS_CONFIGURED_MESSAGE", $conf_msg);
  137. $email_setup_wiz_link='';
  138. if ($email_health>0){
  139. if (is_admin($current_user)){
  140. $email_setup_wiz_link="<a href='index.php?module=Campaigns&action=WizardEmailSetup'>".$mod_strings['LBL_EMAIL_SETUP_WIZ']."</a>";
  141. }else{
  142. $email_setup_wiz_link=$mod_strings['LBL_NON_ADMIN_ERROR_MSG'];
  143. }
  144. }
  145. $ss->assign("EMAIL_SETUP_WIZ_LINK", $email_setup_wiz_link);
  146. $ss->assign( 'EMAIL_IMAGE', define_image($email_health, 2));
  147. $ss->assign( 'EMAIL_COMPONENTS', $mod_strings['LBL_EMAIL_COMPONENTS']);
  148. $ss->assign( 'SCHEDULER_COMPONENTS', $mod_strings['LBL_SCHEDULER_COMPONENTS']);
  149. $ss->assign( 'RECHECK_BTN', $mod_strings['LBL_RECHECK_BTN']);
  150. /************* SCHEDULER COMPONENTS ************/
  151. //create and run the scheduler queries
  152. $sched_qry = "select job, name, status from schedulers where deleted = 0 and status = 'Active'";
  153. $sched_res = $focus->db->query($sched_qry);
  154. $sched_health = 0;
  155. $sched = array();
  156. $check_sched1 = 'function::runMassEmailCampaign';
  157. $check_sched2 = 'function::pollMonitoredInboxesForBouncedCampaignEmails';
  158. $sched_mes = '';
  159. $sched_mes_body = '';
  160. $scheds = array();
  161. //build the table rows for scheduler display
  162. while ($sched_row = $focus->db->fetchByAssoc($sched_res)){$scheds[] = $sched_row;}
  163. foreach ($scheds as $funct){
  164. if( ($funct['job']==$check_sched1) || ($funct['job']==$check_sched2)){
  165. $sched_mes = 'use';
  166. $sched_mes_body .= "<tr><td style='text-align: left;'>".$funct['name']."</td>";
  167. $sched_mes_body .= "<td style='text-align: left;'>".$funct['status']."</td></tr>";
  168. if($funct['job']==$check_sched1){
  169. $check_sched1 ="found";
  170. }else{
  171. $check_sched2 ="found";
  172. }
  173. }
  174. }
  175. //determine which table header to use, based on whether or not schedulers were found
  176. $show_admin_link = false;
  177. if($sched_mes == 'use'){
  178. $sched_mes = "<h5>".$mod_strings['LBL_SCHEDULER_CHECK_GOOD']."</h5><br><table class='other view' cellspacing='1'>";
  179. $sched_mes .= "<tr><th scope='col' width='40%'><b>".$mod_strings['LBL_SCHEDULER_NAME']."</b></tH>"
  180. . " <th scope='col' width='60%'><b>".$mod_strings['LBL_SCHEDULER_STATUS']."</b></tH></tr>";
  181. }else{
  182. $sched_mes = "<table class='other view' cellspacing='1'>";
  183. $sched_mes .= "<tr><td colspan ='3'><font color='red'><b> ".$mod_strings['LBL_SCHEDULER_CHECK_BAD']."</b></font></td></tr>";
  184. $show_admin_link = true;
  185. }
  186. //determine if error messages need to be displayed for schedulers
  187. if($check_sched2 != 'found'){
  188. $sched_health =$sched_health +1;
  189. $sched_mes_body .= "<tr><td colspan ='3'><font color='red'> ".$mod_strings['LBL_SCHEDULER_CHECK1_BAD']."</font></td></tr>";
  190. }
  191. if($check_sched1 != 'found'){
  192. $sched_health =$sched_health +1;
  193. $sched_mes_body .= "<tr><td colspan ='3' scope='row'><font color='red'>".$mod_strings['LBL_SCHEDULER_CHECK2_BAD']."</font></td></tr>";
  194. }
  195. $admin_sched_link='';
  196. if ($sched_health>0){
  197. if (is_admin($current_user)){
  198. $admin_sched_link="<a href='index.php?module=Schedulers&action=index'>".$mod_strings['LBL_SCHEDULER_LINK']."</a>";
  199. }else{
  200. $admin_sched_link=$mod_strings['LBL_NON_ADMIN_ERROR_MSG'];
  201. }
  202. }
  203. //put table html together and display
  204. $final_sched_msg = $sched_mes . $sched_mes_body . '</table>' . $admin_sched_link;
  205. $ss->assign("SCHEDULER_EMAILS_MESSAGE", $final_sched_msg);
  206. $ss->assign( 'SCHEDULE_IMAGE', define_image($sched_health, 2));
  207. /********** FINAL END OF PAGE UI Stuff ********/
  208. if(!isset($_REQUEST['inline']) || $_REQUEST['inline'] != 'inline'){
  209. $ss->display('modules/Campaigns/CampaignDiagnostic.html');
  210. }
  211. /**
  212. * This function takes in 3 parameters and determines the appropriate image source.
  213. *
  214. * @param int $num parameter is the "health" parameter being tracked whenever there is something wrong. (higher number =bad)
  215. * @param int $total Parameter is the total number things being checked.
  216. * @return string HTML img tag
  217. */
  218. function define_image($num, $total)
  219. { global $mod_strings;
  220. //if health number is equal to total number then all checks failed, set red image
  221. if($num == $total){
  222. //red
  223. return SugarThemeRegistry::current()->getImage('red_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_INVALID']);
  224. }elseif($num == 0){
  225. //if health number is zero, then all checks passed, set green image
  226. //green
  227. return SugarThemeRegistry::current()->getImage('green_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_VALID']);
  228. }else{
  229. //if health number is between total and num params, then some checks failed but not all, set yellow image
  230. //yellow
  231. return SugarThemeRegistry::current()->getImage('yellow_camp', "align='absmiddle'", null, null, ".gif", $mod_strings['LBL_ALERT']);
  232. }
  233. }
  234. ?>