@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | parent::Basic(); |
61 | 61 | } |
62 | 62 | |
63 | - public function bean_implements($interface){ |
|
64 | - switch($interface){ |
|
63 | + public function bean_implements($interface) { |
|
64 | + switch ($interface) { |
|
65 | 65 | case 'ACL': return true; |
66 | 66 | } |
67 | 67 | return false; |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public static function saveRemindersInviteesData($reminderId, $inviteesData) { |
77 | 77 | $savedInviteeIds = array(); |
78 | - foreach($inviteesData as $k => $inviteeData) { |
|
79 | - if(isset($_POST['isDuplicate']) && $_POST['isDuplicate']) $inviteeData->id = ''; |
|
78 | + foreach ($inviteesData as $k => $inviteeData) { |
|
79 | + if (isset($_POST['isDuplicate']) && $_POST['isDuplicate']) $inviteeData->id = ''; |
|
80 | 80 | $reminderInviteeBean = BeanFactory::getBean('Reminders_Invitees', $inviteeData->id); |
81 | 81 | $reminderInviteeBean->reminder_id = $reminderId; |
82 | 82 | $reminderInviteeBean->related_invitee_module = $inviteeData->module; |
83 | 83 | $reminderInviteeBean->related_invitee_module_id = $inviteeData->module_id; |
84 | - if(!$inviteeData->id) { |
|
84 | + if (!$inviteeData->id) { |
|
85 | 85 | $reminderInviteeBean->save(); |
86 | 86 | $savedInviteeIds[] = $reminderInviteeBean->id; |
87 | 87 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $ret = array(); |
109 | 109 | $reminderInviteeBeen = new Reminder_Invitee(); |
110 | 110 | $reminderInvitees = $reminderInviteeBeen->get_full_list("reminders_invitees.date_entered", "reminders_invitees.reminder_id = '$reminderId'"); |
111 | - if($reminderInvitees) { |
|
111 | + if ($reminderInvitees) { |
|
112 | 112 | foreach ($reminderInvitees as $reminderInvitee) { |
113 | 113 | $ret[] = array( |
114 | 114 | 'id' => $isDuplicate ? null : $reminderInvitee->id, |
@@ -125,21 +125,21 @@ discard block |
||
125 | 125 | $retValue = "unknown"; |
126 | 126 | |
127 | 127 | $bean = BeanFactory::getBean($module, $moduleId); |
128 | - switch($module) { |
|
128 | + switch ($module) { |
|
129 | 129 | case 'Users': |
130 | 130 | case 'Contacts': |
131 | 131 | case 'Leads': |
132 | 132 | default: |
133 | - if(isset($bean->first_name) && isset($bean->last_name)) { |
|
133 | + if (isset($bean->first_name) && isset($bean->last_name)) { |
|
134 | 134 | $retValue = "{$bean->first_name} {$bean->last_name}"; |
135 | 135 | } |
136 | - else if(isset($bean->name)) { |
|
136 | + else if (isset($bean->name)) { |
|
137 | 137 | $retValue = $bean->name; |
138 | 138 | } |
139 | - else if(isset($bean->email)) { |
|
139 | + else if (isset($bean->email)) { |
|
140 | 140 | $retValue = $bean->email; |
141 | 141 | } |
142 | - if(!$retValue) { |
|
142 | + if (!$retValue) { |
|
143 | 143 | $retValue = "$module ($moduleId)"; |
144 | 144 | } |
145 | 145 | break; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public static function deleteRemindersInviteesMultiple($reminderId, $inviteeIds = array()) { |
157 | 157 | $invitees = BeanFactory::getBean('Reminders_Invitees')->get_full_list("", "reminders_invitees.reminder_id = '$reminderId'"); |
158 | - if($invitees) { |
|
158 | + if ($invitees) { |
|
159 | 159 | foreach ($invitees as $invitee) { |
160 | 160 | if (!in_array($invitee->id, $inviteeIds)) { |
161 | 161 | $invitee->mark_deleted($invitee->id); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | |
25 | 25 | |
26 | -function display_updates($focus, $field, $value, $view){ |
|
26 | +function display_updates($focus, $field, $value, $view) { |
|
27 | 27 | global $mod_strings; |
28 | 28 | |
29 | 29 | $hideImage = SugarThemeRegistry::current()->getImageURL('basic_search.gif'); |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | </script> |
128 | 128 | A; |
129 | 129 | |
130 | - $updates = $focus->get_linked_beans('aop_case_updates',"AOP_Case_Updates"); |
|
131 | - if(!$updates || is_null($focus->id)){ |
|
130 | + $updates = $focus->get_linked_beans('aop_case_updates', "AOP_Case_Updates"); |
|
131 | + if (!$updates || is_null($focus->id)) { |
|
132 | 132 | $html .= quick_edit_case_updates(); |
133 | 133 | return $html; |
134 | 134 | //return $mod_strings['LBL_NO_CASE_UPDATES']; |
@@ -154,18 +154,18 @@ discard block |
||
154 | 154 | EOD; |
155 | 155 | |
156 | 156 | |
157 | - usort($updates,function($a,$b){ |
|
157 | + usort($updates, function($a, $b) { |
|
158 | 158 | $aDate = $a->fetched_row['date_entered']; |
159 | 159 | $bDate = $b->fetched_row['date_entered']; |
160 | - if($aDate < $bDate){ |
|
160 | + if ($aDate < $bDate) { |
|
161 | 161 | return -1; |
162 | - }elseif($aDate > $bDate){ |
|
162 | + }elseif ($aDate > $bDate) { |
|
163 | 163 | return 1; |
164 | 164 | } |
165 | 165 | return 0; |
166 | 166 | }); |
167 | 167 | |
168 | - foreach($updates as $update){ |
|
168 | + foreach ($updates as $update) { |
|
169 | 169 | $html .= display_single_update($update, $hideImage); |
170 | 170 | } |
171 | 171 | $html .= "</div>"; |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | /** |
179 | 179 | * @return mixed|string|void |
180 | 180 | */ |
181 | -function display_update_form(){ |
|
181 | +function display_update_form() { |
|
182 | 182 | global $mod_strings, $app_strings; |
183 | - $sugar_smarty = new Sugar_Smarty(); |
|
183 | + $sugar_smarty = new Sugar_Smarty(); |
|
184 | 184 | $sugar_smarty->assign('MOD', $mod_strings); |
185 | 185 | $sugar_smarty->assign('APP', $app_strings); |
186 | 186 | return $sugar_smarty->fetch('modules/AOP_Case_Updates/tpl/caseUpdateForm.tpl'); |
@@ -191,23 +191,23 @@ discard block |
||
191 | 191 | * @param SugarBean $update |
192 | 192 | * @return string - html to be displayed |
193 | 193 | */ |
194 | -function getUpdateDisplayHead(SugarBean $update){ |
|
194 | +function getUpdateDisplayHead(SugarBean $update) { |
|
195 | 195 | global $mod_strings; |
196 | - if($update->contact_id){ |
|
196 | + if ($update->contact_id) { |
|
197 | 197 | $name = $update->getUpdateContact()->name; |
198 | - }elseif($update->assigned_user_id){ |
|
198 | + }elseif ($update->assigned_user_id) { |
|
199 | 199 | $name = $update->getUpdateUser()->name; |
200 | - }else{ |
|
200 | + } else { |
|
201 | 201 | $name = "Unknown"; |
202 | 202 | } |
203 | 203 | $html = "<a href='' onclick='toggleCaseUpdate(\"".$update->id."\");return false;'>"; |
204 | 204 | $html .= "<img id='caseUpdate".$update->id."Image' class='caseUpdateImage' src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."'>"; |
205 | 205 | $html .= "</a>"; |
206 | - $html .= "<span>".($update->internal ? "<strong>" . $mod_strings['LBL_INTERNAL'] . "</strong> " : '') .$name . " ".$update->date_entered."</span><br>"; |
|
207 | - $notes = $update->get_linked_beans('notes','Notes'); |
|
208 | - if($notes){ |
|
209 | - $html.= $mod_strings['LBL_AOP_CASE_ATTACHMENTS']; |
|
210 | - foreach($notes as $note){ |
|
206 | + $html .= "<span>".($update->internal ? "<strong>".$mod_strings['LBL_INTERNAL']."</strong> " : '').$name." ".$update->date_entered."</span><br>"; |
|
207 | + $notes = $update->get_linked_beans('notes', 'Notes'); |
|
208 | + if ($notes) { |
|
209 | + $html .= $mod_strings['LBL_AOP_CASE_ATTACHMENTS']; |
|
210 | + foreach ($notes as $note) { |
|
211 | 211 | $html .= "<a href='index.php?module=Notes&action=DetailView&record={$note->id}'>{$note->filename}</a> "; |
212 | 212 | } |
213 | 213 | } |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | * @param AOP_Case_Updates $update |
221 | 221 | * @return string - the html for the update |
222 | 222 | */ |
223 | -function display_single_update(AOP_Case_Updates $update){ |
|
223 | +function display_single_update(AOP_Case_Updates $update) { |
|
224 | 224 | |
225 | 225 | /*if assigned user*/ |
226 | - if($update->assigned_user_id){ |
|
226 | + if ($update->assigned_user_id) { |
|
227 | 227 | /*if internal update*/ |
228 | - if ($update->internal){ |
|
228 | + if ($update->internal) { |
|
229 | 229 | $html = "<div id='caseStyleInternal'>".getUpdateDisplayHead($update); |
230 | 230 | $html .= "<div id='caseUpdate".$update->id."' class='caseUpdate'>"; |
231 | 231 | $html .= nl2br(html_entity_decode($update->description)); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | /*if contact user*/ |
246 | - if($update->contact_id){ |
|
246 | + if ($update->contact_id) { |
|
247 | 247 | $html = "<div id='extramargin'><div id='caseStyleContact'>".getUpdateDisplayHead($update); |
248 | 248 | $html .= "<div id='caseUpdate".$update->id."' class='caseUpdate'>"; |
249 | 249 | $html .= nl2br(html_entity_decode($update->description)); |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | * @param $case |
260 | 260 | * @return string - html link |
261 | 261 | */ |
262 | -function display_case_attachments($case){ |
|
262 | +function display_case_attachments($case) { |
|
263 | 263 | $html = ''; |
264 | - $notes = $case->get_linked_beans('notes','Notes'); |
|
265 | - if($notes){ |
|
266 | - foreach($notes as $note){ |
|
264 | + $notes = $case->get_linked_beans('notes', 'Notes'); |
|
265 | + if ($notes) { |
|
266 | + foreach ($notes as $note) { |
|
267 | 267 | $html .= "<a href='index.php?module=Notes&action=DetailView&record={$note->id}'>{$note->filename}</a> "; |
268 | 268 | } |
269 | 269 | } |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return string - the html to be displayed and javascript |
279 | 279 | */ |
280 | -function quick_edit_case_updates(){ |
|
280 | +function quick_edit_case_updates() { |
|
281 | 281 | global $action; |
282 | 282 | |
283 | 283 | //on DetailView only |
284 | - if($action != 'DetailView') return; |
|
284 | + if ($action != 'DetailView') return; |
|
285 | 285 | |
286 | 286 | //current record id |
287 | 287 | $record = $_GET['record']; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $roles = $acl->getUserRoles($id); |
295 | 295 | |
296 | 296 | //Return if user cannot edit cases |
297 | - if(in_array( "no edit cases", $roles) || $roles === "no edit cases"){ |
|
297 | + if (in_array("no edit cases", $roles) || $roles === "no edit cases") { |
|
298 | 298 | |
299 | 299 | return; |
300 | 300 | } |
@@ -30,35 +30,35 @@ discard block |
||
30 | 30 | require_once 'include/clean.php'; |
31 | 31 | class AOP_Case_Updates extends AOP_Case_Updates_sugar { |
32 | 32 | |
33 | - function AOP_Case_Updates(){ |
|
33 | + function AOP_Case_Updates() { |
|
34 | 34 | parent::AOP_Case_Updates_sugar(); |
35 | 35 | } |
36 | 36 | |
37 | - function save($check_notify = false){ |
|
37 | + function save($check_notify = false) { |
|
38 | 38 | $this->name = SugarCleaner::cleanHtml($this->name); |
39 | 39 | $this->description = SugarCleaner::cleanHtml($this->description); |
40 | 40 | global $current_user, $sugar_config; |
41 | 41 | parent::save($check_notify); |
42 | 42 | $email_template = new EmailTemplate(); |
43 | - if($_REQUEST['module'] == 'Import'){ |
|
43 | + if ($_REQUEST['module'] == 'Import') { |
|
44 | 44 | //Don't send email on import |
45 | 45 | return; |
46 | 46 | } |
47 | - if(!isAOPEnabled()){ |
|
47 | + if (!isAOPEnabled()) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | - if($this->internal){ |
|
50 | + if ($this->internal) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | $signature = array(); |
54 | 54 | $addDelimiter = true; |
55 | 55 | $aop_config = $sugar_config['aop']; |
56 | - if($this->assigned_user_id){ |
|
57 | - if($aop_config['contact_email_template_id']){ |
|
56 | + if ($this->assigned_user_id) { |
|
57 | + if ($aop_config['contact_email_template_id']) { |
|
58 | 58 | $email_template = $email_template->retrieve($aop_config['contact_email_template_id']); |
59 | 59 | $signature = $current_user->getDefaultSignature(); |
60 | 60 | } |
61 | - if($email_template) { |
|
61 | + if ($email_template) { |
|
62 | 62 | foreach ($this->getContacts() as $contact) { |
63 | 63 | $GLOBALS['log']->info("AOPCaseUpdates: Calling send email"); |
64 | 64 | $emails = array(); |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | $res = $this->sendEmail($emails, $email_template, $signature, $this->case_id, $addDelimiter, $contact->id); |
67 | 67 | } |
68 | 68 | } |
69 | - }else{ |
|
69 | + } else { |
|
70 | 70 | $emails = $this->getEmailForUser(); |
71 | - if($aop_config['user_email_template_id']){ |
|
71 | + if ($aop_config['user_email_template_id']) { |
|
72 | 72 | $email_template = $email_template->retrieve($aop_config['user_email_template_id']); |
73 | 73 | } |
74 | 74 | $addDelimiter = false; |
75 | - if($emails && $email_template){ |
|
75 | + if ($emails && $email_template) { |
|
76 | 76 | $GLOBALS['log']->info("AOPCaseUpdates: Calling send email"); |
77 | - $res = $this->sendEmail($emails, $email_template, $signature, $this->case_id, $addDelimiter,$this->contact_id); |
|
77 | + $res = $this->sendEmail($emails, $email_template, $signature, $this->case_id, $addDelimiter, $this->contact_id); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -83,68 +83,68 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @return aCase |
85 | 85 | */ |
86 | - public function getCase(){ |
|
87 | - $case = BeanFactory::getBean("Cases",$this->case_id); |
|
86 | + public function getCase() { |
|
87 | + $case = BeanFactory::getBean("Cases", $this->case_id); |
|
88 | 88 | return $case; |
89 | 89 | } |
90 | 90 | |
91 | - public function getContacts(){ |
|
91 | + public function getContacts() { |
|
92 | 92 | $case = $this->getCase(); |
93 | - if($case){ |
|
94 | - return $case->get_linked_beans("contacts","Contacts"); |
|
93 | + if ($case) { |
|
94 | + return $case->get_linked_beans("contacts", "Contacts"); |
|
95 | 95 | } |
96 | 96 | return null; |
97 | 97 | } |
98 | 98 | |
99 | - public function getUpdateContact(){ |
|
100 | - if($this->contact_id){ |
|
101 | - return BeanFactory::getBean("Contacts",$this->contact_id); |
|
99 | + public function getUpdateContact() { |
|
100 | + if ($this->contact_id) { |
|
101 | + return BeanFactory::getBean("Contacts", $this->contact_id); |
|
102 | 102 | } |
103 | 103 | return null; |
104 | 104 | } |
105 | - public function getUser(){ |
|
106 | - $user = BeanFactory::getBean('Users',$this->getCase()->assigned_user_id); |
|
105 | + public function getUser() { |
|
106 | + $user = BeanFactory::getBean('Users', $this->getCase()->assigned_user_id); |
|
107 | 107 | return $user; |
108 | 108 | } |
109 | - public function getUpdateUser(){ |
|
110 | - $user = BeanFactory::getBean('Users',$this->assigned_user_id); |
|
109 | + public function getUpdateUser() { |
|
110 | + $user = BeanFactory::getBean('Users', $this->assigned_user_id); |
|
111 | 111 | return $user; |
112 | 112 | } |
113 | 113 | |
114 | - private function getEmailForUser(){ |
|
114 | + private function getEmailForUser() { |
|
115 | 115 | $user = $this->getUser(); |
116 | - if($user){ |
|
116 | + if ($user) { |
|
117 | 117 | return array($user->emailAddress->getPrimaryAddress($user)); |
118 | 118 | } |
119 | 119 | return array(); |
120 | 120 | } |
121 | 121 | |
122 | - private function populateTemplate(EmailTemplate $template, $addDelimiter = true, $contactId = null){ |
|
122 | + private function populateTemplate(EmailTemplate $template, $addDelimiter = true, $contactId = null) { |
|
123 | 123 | global $app_strings, $sugar_config; |
124 | 124 | //Order of beans seems to matter here so we place contact first. |
125 | 125 | $userId = ''; |
126 | 126 | $user = $this->getUpdateUser(); |
127 | - if(!$user){ |
|
127 | + if (!$user) { |
|
128 | 128 | $this->getUser(); |
129 | 129 | } |
130 | - $beans = array("Contacts" => $contactId,"Cases" => $this->getCase()->id, "Users" => $user->id, "AOP_Case_Updates" => $this->id); |
|
130 | + $beans = array("Contacts" => $contactId, "Cases" => $this->getCase()->id, "Users" => $user->id, "AOP_Case_Updates" => $this->id); |
|
131 | 131 | $ret = array(); |
132 | - $ret['subject'] = from_html(aop_parse_template($template->subject,$beans)); |
|
133 | - $body = aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body_html),$beans); |
|
134 | - $bodyAlt = aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body),$beans); |
|
135 | - if($addDelimiter){ |
|
136 | - $body = $app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'] . $body; |
|
137 | - $bodyAlt = $app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'] . $bodyAlt; |
|
132 | + $ret['subject'] = from_html(aop_parse_template($template->subject, $beans)); |
|
133 | + $body = aop_parse_template(str_replace("\$sugarurl", $sugar_config['site_url'], $template->body_html), $beans); |
|
134 | + $bodyAlt = aop_parse_template(str_replace("\$sugarurl", $sugar_config['site_url'], $template->body), $beans); |
|
135 | + if ($addDelimiter) { |
|
136 | + $body = $app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].$body; |
|
137 | + $bodyAlt = $app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].$bodyAlt; |
|
138 | 138 | } |
139 | 139 | $ret['body'] = from_html($body); |
140 | 140 | $ret['body_alt'] = strip_tags(from_html($bodyAlt)); |
141 | 141 | return $ret; |
142 | 142 | } |
143 | 143 | |
144 | - private function sendEmail($emails, $template, $signature = array(), $caseId = null, $addDelimiter = true, $contactId = null){ |
|
144 | + private function sendEmail($emails, $template, $signature = array(), $caseId = null, $addDelimiter = true, $contactId = null) { |
|
145 | 145 | $GLOBALS['log']->info("AOPCaseUpdates: sendEmail called"); |
146 | 146 | require_once("include/SugarPHPMailer.php"); |
147 | - $mailer=new SugarPHPMailer(); |
|
147 | + $mailer = new SugarPHPMailer(); |
|
148 | 148 | $admin = new Administration(); |
149 | 149 | $admin->retrieveSettings(); |
150 | 150 | |
@@ -152,36 +152,36 @@ discard block |
||
152 | 152 | $mailer->setMailerForSystem(); |
153 | 153 | |
154 | 154 | $signatureHTML = ""; |
155 | - if($signature && array_key_exists("signature_html",$signature)){ |
|
155 | + if ($signature && array_key_exists("signature_html", $signature)) { |
|
156 | 156 | $signatureHTML = from_html($signature['signature_html']); |
157 | 157 | } |
158 | 158 | $signaturePlain = ""; |
159 | - if($signature && array_key_exists("signature",$signature)){ |
|
159 | + if ($signature && array_key_exists("signature", $signature)) { |
|
160 | 160 | $signaturePlain = $signature['signature']; |
161 | 161 | } |
162 | 162 | $emailSettings = getPortalEmailSettings(); |
163 | - $GLOBALS['log']->info("AOPCaseUpdates: sendEmail email portal settings are ".print_r($emailSettings,true)); |
|
163 | + $GLOBALS['log']->info("AOPCaseUpdates: sendEmail email portal settings are ".print_r($emailSettings, true)); |
|
164 | 164 | $text = $this->populateTemplate($template, $addDelimiter, $contactId); |
165 | 165 | $mailer->Subject = $text['subject']; |
166 | - $mailer->Body = $text['body'] . $signatureHTML; |
|
166 | + $mailer->Body = $text['body'].$signatureHTML; |
|
167 | 167 | $mailer->IsHTML(true); |
168 | - $mailer->AltBody = $text['body_alt'] . $signaturePlain; |
|
168 | + $mailer->AltBody = $text['body_alt'].$signaturePlain; |
|
169 | 169 | $mailer->From = $emailSettings['from_address']; |
170 | 170 | $mailer->FromName = $emailSettings['from_name']; |
171 | - foreach($emails as $email){ |
|
171 | + foreach ($emails as $email) { |
|
172 | 172 | $mailer->AddAddress($email); |
173 | 173 | } |
174 | - if ($mailer->Send()){ |
|
174 | + if ($mailer->Send()) { |
|
175 | 175 | require_once('modules/Emails/Email.php'); |
176 | 176 | $emailObj = new Email(); |
177 | - $emailObj->to_addrs = implode(",",$emails); |
|
178 | - $emailObj->type= 'out'; |
|
177 | + $emailObj->to_addrs = implode(",", $emails); |
|
178 | + $emailObj->type = 'out'; |
|
179 | 179 | $emailObj->deleted = '0'; |
180 | 180 | $emailObj->name = $mailer->Subject; |
181 | 181 | $emailObj->description = $mailer->AltBody; |
182 | 182 | $emailObj->description_html = $mailer->Body; |
183 | 183 | $emailObj->from_addr = $mailer->From; |
184 | - if ( $caseId) { |
|
184 | + if ($caseId) { |
|
185 | 185 | $emailObj->parent_type = "Cases"; |
186 | 186 | $emailObj->parent_id = $caseId; |
187 | 187 | } |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | $emailObj->created_by = '1'; |
191 | 191 | $emailObj->status = 'sent'; |
192 | 192 | $emailObj->save(); |
193 | - }else{ |
|
194 | - $GLOBALS['log']->info("AOPCaseUpdates: Could not send email: " . $mailer->ErrorInfo); |
|
193 | + } else { |
|
194 | + $GLOBALS['log']->info("AOPCaseUpdates: Could not send email: ".$mailer->ErrorInfo); |
|
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | return true; |
@@ -25,27 +25,27 @@ discard block |
||
25 | 25 | class CaseUpdatesHook { |
26 | 26 | private $slug_size = 50; |
27 | 27 | |
28 | - private function getCaseCounts(){ |
|
28 | + private function getCaseCounts() { |
|
29 | 29 | global $db; |
30 | 30 | $counts = array(); |
31 | 31 | $r = $db->query("SELECT users.id,count(cases.id) AS c FROM users LEFT JOIN cases ON (cases.assigned_user_id = users.id AND cases.status != 'Closed' AND cases.status != 'Duplicate' AND cases.status != 'Rejected') WHERE NOT users.deleted GROUP BY users.id"); |
32 | - while($a = $db->fetchByAssoc($r)){ |
|
32 | + while ($a = $db->fetchByAssoc($r)) { |
|
33 | 33 | $counts[$a['id']] = $a['c']; |
34 | 34 | } |
35 | 35 | return $counts; |
36 | 36 | } |
37 | 37 | |
38 | - private function getAssignToUser(){ |
|
38 | + private function getAssignToUser() { |
|
39 | 39 | require_once 'modules/AOP_Case_Updates/AOPAssignManager.php'; |
40 | 40 | $assignManager = new AOPAssignManager(); |
41 | 41 | return $assignManager->getNextAssignedUser(); |
42 | 42 | } |
43 | 43 | |
44 | - private function arrangeFilesArray(){ |
|
44 | + private function arrangeFilesArray() { |
|
45 | 45 | $count = 0; |
46 | - foreach($_FILES['case_update_file'] as $key => $vals){ |
|
47 | - foreach($vals as $index => $val){ |
|
48 | - if(!array_key_exists('case_update_file'.$index,$_FILES)){ |
|
46 | + foreach ($_FILES['case_update_file'] as $key => $vals) { |
|
47 | + foreach ($vals as $index => $val) { |
|
48 | + if (!array_key_exists('case_update_file'.$index, $_FILES)) { |
|
49 | 49 | $_FILES['case_update_file'.$index] = array(); |
50 | 50 | $count++; |
51 | 51 | } |
@@ -56,34 +56,34 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | |
59 | - public function saveUpdate($bean, $event, $arguments){ |
|
60 | - if(!isAOPEnabled()){ |
|
59 | + public function saveUpdate($bean, $event, $arguments) { |
|
60 | + if (!isAOPEnabled()) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | global $current_user, $app_list_strings; |
64 | - if(empty($bean->fetched_row) || !$bean->id){ |
|
64 | + if (empty($bean->fetched_row) || !$bean->id) { |
|
65 | 65 | |
66 | - if(!$bean->state){ |
|
66 | + if (!$bean->state) { |
|
67 | 67 | $bean->state = $app_list_strings['case_state_default_key']; |
68 | 68 | } |
69 | - if($bean->status == "New"){ |
|
69 | + if ($bean->status == "New") { |
|
70 | 70 | $bean->status = $app_list_strings['case_status_default_key']; |
71 | 71 | } |
72 | 72 | |
73 | 73 | //New case - assign |
74 | - if(!$bean->assigned_user_id){ |
|
74 | + if (!$bean->assigned_user_id) { |
|
75 | 75 | $userId = $this->getAssignToUser(); |
76 | 76 | $bean->assigned_user_id = $userId; |
77 | 77 | $bean->notify_inworkflow = true; |
78 | 78 | } |
79 | 79 | return; |
80 | 80 | } |
81 | - if($_REQUEST['module'] == 'Import'){ |
|
81 | + if ($_REQUEST['module'] == 'Import') { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | //Grab the update field and create a new update with it. |
85 | 85 | $text = $bean->update_text; |
86 | - if(!$text && empty($_FILES['case_update_file'])){ |
|
86 | + if (!$text && empty($_FILES['case_update_file'])) { |
|
87 | 87 | //No text or files, so nothing really to save. |
88 | 88 | return; |
89 | 89 | } |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | $case_update->internal = $bean->internal; |
94 | 94 | $bean->internal = false; |
95 | 95 | $case_update->assigned_user_id = $current_user->id; |
96 | - if(strlen($text) > $this->slug_size){ |
|
97 | - $case_update->name = substr($text,0,$this->slug_size)."..."; |
|
96 | + if (strlen($text) > $this->slug_size) { |
|
97 | + $case_update->name = substr($text, 0, $this->slug_size)."..."; |
|
98 | 98 | } |
99 | 99 | $case_update->description = nl2br($text); |
100 | 100 | $case_update->case_id = $bean->id; |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | |
103 | 103 | $fileCount = $this->arrangeFilesArray(); |
104 | 104 | |
105 | - for($x = 0; $x < $fileCount; $x++){ |
|
106 | - if($_FILES['case_update_file']['error'][$x] == UPLOAD_ERR_NO_FILE){ |
|
105 | + for ($x = 0; $x < $fileCount; $x++) { |
|
106 | + if ($_FILES['case_update_file']['error'][$x] == UPLOAD_ERR_NO_FILE) { |
|
107 | 107 | continue; |
108 | 108 | } |
109 | 109 | $uploadFile = new UploadFile('case_update_file'.$x); |
110 | - if(!$uploadFile->confirm_upload()){ |
|
110 | + if (!$uploadFile->confirm_upload()) { |
|
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | $note = $this->newNote($case_update->id); |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | $uploadFile->final_move($note->id); |
119 | 119 | } |
120 | 120 | $postPrefix = 'case_update_id_'; |
121 | - foreach($_POST as $key => $val){ |
|
122 | - if(strpos($key, $postPrefix) !== 0 || empty($val)){ |
|
121 | + foreach ($_POST as $key => $val) { |
|
122 | + if (strpos($key, $postPrefix) !== 0 || empty($val)) { |
|
123 | 123 | continue; |
124 | 124 | } |
125 | 125 | //Val is selected doc id |
126 | - $doc = BeanFactory::getBean('Documents',$val); |
|
127 | - if(!$doc){ |
|
126 | + $doc = BeanFactory::getBean('Documents', $val); |
|
127 | + if (!$doc) { |
|
128 | 128 | continue; |
129 | 129 | } |
130 | 130 | $note = $this->newNote($case_update->id); |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | $note->save(); |
135 | 135 | $srcFile = "upload://{$doc->document_revision_id}"; |
136 | 136 | $destFile = "upload://{$note->id}"; |
137 | - copy($srcFile,$destFile); |
|
137 | + copy($srcFile, $destFile); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - private function newNote($caseUpdateId){ |
|
141 | + private function newNote($caseUpdateId) { |
|
142 | 142 | $note = BeanFactory::newBean('Notes'); |
143 | 143 | $note->parent_type = 'AOP_Case_Updates'; |
144 | 144 | $note->parent_id = $caseUpdateId; |
@@ -146,30 +146,30 @@ discard block |
||
146 | 146 | return $note; |
147 | 147 | } |
148 | 148 | |
149 | - private function linkAccountAndCase($case_id,$account_id){ |
|
150 | - if(!$account_id || !$case_id){ |
|
149 | + private function linkAccountAndCase($case_id, $account_id) { |
|
150 | + if (!$account_id || !$case_id) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | - $case = BeanFactory::getBean("Cases",$case_id); |
|
154 | - if(!$case->account_id){ |
|
153 | + $case = BeanFactory::getBean("Cases", $case_id); |
|
154 | + if (!$case->account_id) { |
|
155 | 155 | $case->account_id = $account_id; |
156 | 156 | $case->save(); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - public function assignAccount($bean, $event, $arguments){ |
|
161 | - if($arguments['module'] != "Cases" || $arguments['related_module'] != "Contacts"){ |
|
160 | + public function assignAccount($bean, $event, $arguments) { |
|
161 | + if ($arguments['module'] != "Cases" || $arguments['related_module'] != "Contacts") { |
|
162 | 162 | return; |
163 | 163 | } |
164 | - if(!isAOPEnabled()){ |
|
164 | + if (!isAOPEnabled()) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | - $contact = BeanFactory::getBean("Contacts",$arguments['related_id']); |
|
167 | + $contact = BeanFactory::getBean("Contacts", $arguments['related_id']); |
|
168 | 168 | $contact->load_relationship("accounts"); |
169 | - if(!$contact || !$contact->account_id){ |
|
169 | + if (!$contact || !$contact->account_id) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | - $this->linkAccountAndCase($bean->id,$contact->account_id); |
|
172 | + $this->linkAccountAndCase($bean->id, $contact->account_id); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,26 +178,26 @@ discard block |
||
178 | 178 | * @param $event |
179 | 179 | * @param $arguments |
180 | 180 | */ |
181 | - public function saveEmailUpdate($bean, $event, $arguments){ |
|
181 | + public function saveEmailUpdate($bean, $event, $arguments) { |
|
182 | 182 | global $mod_strings; |
183 | - if($bean->intent != "createcase" || $bean->parent_type != "Cases"){ |
|
183 | + if ($bean->intent != "createcase" || $bean->parent_type != "Cases") { |
|
184 | 184 | $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type"); |
185 | 185 | return; |
186 | 186 | } |
187 | - if(!isAOPEnabled()){ |
|
187 | + if (!isAOPEnabled()) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | - if(!$bean->parent_id ){ |
|
190 | + if (!$bean->parent_id) { |
|
191 | 191 | $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate No parent id"); |
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | - if($bean->cases){ |
|
195 | + if ($bean->cases) { |
|
196 | 196 | $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate cases already set"); |
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | - if($bean->fetched_row['parent_id']){ |
|
200 | + if ($bean->fetched_row['parent_id']) { |
|
201 | 201 | //Will have been processed already |
202 | 202 | return; |
203 | 203 | } |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | $ea = new SugarEmailAddress(); |
207 | 207 | $beans = $ea->getBeansByEmailAddress($bean->from_addr); |
208 | 208 | $contact_id = null; |
209 | - foreach($beans as $emailBean){ |
|
210 | - if($emailBean->module_name == "Contacts" && !empty($emailBean->id)){ |
|
209 | + foreach ($beans as $emailBean) { |
|
210 | + if ($emailBean->module_name == "Contacts" && !empty($emailBean->id)) { |
|
211 | 211 | $contact_id = $emailBean->id; |
212 | - $this->linkAccountAndCase($bean->parent_id,$emailBean->account_id); |
|
212 | + $this->linkAccountAndCase($bean->parent_id, $emailBean->account_id); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | $case_update = new AOP_Case_Updates(); |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | $case_update->internal = false; |
221 | 221 | $case_update->case_id = $bean->parent_id; |
222 | 222 | $case_update->save(); |
223 | - $notes = $bean->get_linked_beans('notes','Notes'); |
|
224 | - foreach($notes as $note){ |
|
223 | + $notes = $bean->get_linked_beans('notes', 'Notes'); |
|
224 | + foreach ($notes as $note) { |
|
225 | 225 | //Link notes to case update also |
226 | 226 | $newNote = BeanFactory::newBean('Notes'); |
227 | 227 | $newNote->name = $note->name; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $newNote->save(); |
233 | 233 | $srcFile = "upload://{$note->id}"; |
234 | 234 | $destFile = "upload://{$newNote->id}"; |
235 | - copy($srcFile,$destFile); |
|
235 | + copy($srcFile, $destFile); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $this->updateCaseStatus($case_update->case_id); |
@@ -242,71 +242,71 @@ discard block |
||
242 | 242 | * Changes the status of the supplied case based on the case_status_changes config values. |
243 | 243 | * @param $caseId |
244 | 244 | */ |
245 | - private function updateCaseStatus($caseId){ |
|
245 | + private function updateCaseStatus($caseId) { |
|
246 | 246 | global $sugar_config; |
247 | - if(empty($caseId)){ |
|
247 | + if (empty($caseId)) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | - if(empty($sugar_config['aop']['case_status_changes'])){ |
|
250 | + if (empty($sugar_config['aop']['case_status_changes'])) { |
|
251 | 251 | return; |
252 | 252 | } |
253 | - $statusMap = json_decode($sugar_config['aop']['case_status_changes'],1); |
|
254 | - if(empty($statusMap)){ |
|
253 | + $statusMap = json_decode($sugar_config['aop']['case_status_changes'], 1); |
|
254 | + if (empty($statusMap)) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | - $case = BeanFactory::getBean('Cases',$caseId); |
|
258 | - if(empty($case)){ |
|
257 | + $case = BeanFactory::getBean('Cases', $caseId); |
|
258 | + if (empty($case)) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | - if(array_key_exists($case->status,$statusMap)){ |
|
261 | + if (array_key_exists($case->status, $statusMap)) { |
|
262 | 262 | $case->status = $statusMap[$case->status]; |
263 | - $statusBits = explode('_',$case->status); |
|
263 | + $statusBits = explode('_', $case->status); |
|
264 | 264 | $case->state = array_shift($statusBits); |
265 | 265 | $case->save(); |
266 | 266 | } |
267 | 267 | |
268 | 268 | } |
269 | 269 | |
270 | - private function unquoteEmail($text){ |
|
270 | + private function unquoteEmail($text) { |
|
271 | 271 | global $app_strings; |
272 | 272 | $text = html_entity_decode($text); |
273 | - $text = preg_replace('/(\r\n|\r|\n)/s',"\n",$text); |
|
274 | - $pos = strpos($text,$app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER']); |
|
275 | - if($pos !== false){ |
|
276 | - $text = substr($text,0,$pos); |
|
273 | + $text = preg_replace('/(\r\n|\r|\n)/s', "\n", $text); |
|
274 | + $pos = strpos($text, $app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER']); |
|
275 | + if ($pos !== false) { |
|
276 | + $text = substr($text, 0, $pos); |
|
277 | 277 | } |
278 | 278 | return $text; |
279 | 279 | } |
280 | 280 | |
281 | - public function closureNotifyPrep($bean, $event, $arguments){ |
|
282 | - if($_REQUEST['module'] == 'Import'){ |
|
281 | + public function closureNotifyPrep($bean, $event, $arguments) { |
|
282 | + if ($_REQUEST['module'] == 'Import') { |
|
283 | 283 | return; |
284 | 284 | } |
285 | - if($bean->state!= "Closed" || $bean->fetched_row['state'] == "Closed"){ |
|
285 | + if ($bean->state != "Closed" || $bean->fetched_row['state'] == "Closed") { |
|
286 | 286 | $bean->send_closure_email = false; |
287 | - }else{ |
|
287 | + } else { |
|
288 | 288 | $bean->send_closure_email = true; |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | - public function closureNotify($bean, $event, $arguments){ |
|
294 | - if($_REQUEST['module'] == 'Import'){ |
|
293 | + public function closureNotify($bean, $event, $arguments) { |
|
294 | + if ($_REQUEST['module'] == 'Import') { |
|
295 | 295 | return; |
296 | 296 | } |
297 | - if($bean->state != "Closed" || !$bean->send_closure_email){ |
|
297 | + if ($bean->state != "Closed" || !$bean->send_closure_email) { |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | $this->sendClosureEmail($bean, $arguments['related_bean']); |
301 | 301 | } |
302 | 302 | |
303 | - private function sendClosureEmail(aCase $bean){ |
|
304 | - if(!isAOPEnabled()){ |
|
303 | + private function sendClosureEmail(aCase $bean) { |
|
304 | + if (!isAOPEnabled()) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail called"); |
308 | 308 | require_once("include/SugarPHPMailer.php"); |
309 | - $mailer=new SugarPHPMailer(); |
|
309 | + $mailer = new SugarPHPMailer(); |
|
310 | 310 | $admin = new Administration(); |
311 | 311 | $admin->retrieveSettings(); |
312 | 312 | |
@@ -315,18 +315,18 @@ discard block |
||
315 | 315 | |
316 | 316 | $email_template = new EmailTemplate(); |
317 | 317 | $aop_config = $this->getAOPConfig(); |
318 | - $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail Config is ".print_r($aop_config,true)); |
|
318 | + $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail Config is ".print_r($aop_config, true)); |
|
319 | 319 | $email_template = $email_template->retrieve($aop_config['case_closure_email_template_id']); |
320 | 320 | |
321 | - if(!$email_template){ |
|
321 | + if (!$email_template) { |
|
322 | 322 | $GLOBALS['log']->warn("CaseUpdatesHook: sendClosureEmail template is empty"); |
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | |
326 | - $contact = $bean->get_linked_beans("contacts","Contact"); |
|
327 | - if($contact){ |
|
326 | + $contact = $bean->get_linked_beans("contacts", "Contact"); |
|
327 | + if ($contact) { |
|
328 | 328 | $contact = $contact[0]; |
329 | - }else{ |
|
329 | + } else { |
|
330 | 330 | return false; |
331 | 331 | } |
332 | 332 | |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | $email = $contact->emailAddress->getPrimaryAddress($contact); |
344 | 344 | |
345 | 345 | $mailer->AddAddress($email); |
346 | - if (!$mailer->Send()){ |
|
347 | - $GLOBALS['log']->info("CaseUpdatesHook: Could not send email: " . $mailer->ErrorInfo); |
|
346 | + if (!$mailer->Send()) { |
|
347 | + $GLOBALS['log']->info("CaseUpdatesHook: Could not send email: ".$mailer->ErrorInfo); |
|
348 | 348 | return false; |
349 | - }else{ |
|
349 | + } else { |
|
350 | 350 | $this->logEmail($email, $mailer, $bean->id); |
351 | 351 | return true; |
352 | 352 | } |
@@ -359,25 +359,25 @@ discard block |
||
359 | 359 | * @param $event |
360 | 360 | * @param $arguments |
361 | 361 | */ |
362 | - public function creationNotify($bean, $event, $arguments){ |
|
363 | - if($_REQUEST['module'] == 'Import'){ |
|
362 | + public function creationNotify($bean, $event, $arguments) { |
|
363 | + if ($_REQUEST['module'] == 'Import') { |
|
364 | 364 | return; |
365 | 365 | } |
366 | - if($arguments['module'] != "Cases" || $arguments['related_module'] != "Contacts"){ |
|
366 | + if ($arguments['module'] != "Cases" || $arguments['related_module'] != "Contacts") { |
|
367 | 367 | return; |
368 | 368 | } |
369 | - if(!$bean->fetched_row){ |
|
369 | + if (!$bean->fetched_row) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | - if(!empty($arguments['related_bean'])){ |
|
372 | + if (!empty($arguments['related_bean'])) { |
|
373 | 373 | $contact = $arguments['related_bean']; |
374 | - }else{ |
|
375 | - $contact = BeanFactory::getBean("Contacts",$arguments['related_id']); |
|
374 | + } else { |
|
375 | + $contact = BeanFactory::getBean("Contacts", $arguments['related_id']); |
|
376 | 376 | } |
377 | 377 | $this->sendCreationEmail($bean, $contact); |
378 | 378 | } |
379 | 379 | |
380 | - private function populateTemplate(EmailTemplate $template, aCase $bean, $contact){ |
|
380 | + private function populateTemplate(EmailTemplate $template, aCase $bean, $contact) { |
|
381 | 381 | global $app_strings, $sugar_config; |
382 | 382 | //Order of beans seems to matter here so we place contact first. |
383 | 383 | $beans = array( |
@@ -386,26 +386,26 @@ discard block |
||
386 | 386 | "Users" => $bean->assigned_user_id |
387 | 387 | ); |
388 | 388 | $ret = array(); |
389 | - $ret['subject'] = from_html(aop_parse_template($template->subject,$beans)); |
|
390 | - $ret['body'] = from_html($app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body_html),$beans)); |
|
391 | - $ret['body_alt'] = strip_tags(from_html(aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body),$beans))); |
|
389 | + $ret['subject'] = from_html(aop_parse_template($template->subject, $beans)); |
|
390 | + $ret['body'] = from_html($app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].aop_parse_template(str_replace("\$sugarurl", $sugar_config['site_url'], $template->body_html), $beans)); |
|
391 | + $ret['body_alt'] = strip_tags(from_html(aop_parse_template(str_replace("\$sugarurl", $sugar_config['site_url'], $template->body), $beans))); |
|
392 | 392 | return $ret; |
393 | 393 | } |
394 | 394 | |
395 | - private function getAOPConfig(){ |
|
395 | + private function getAOPConfig() { |
|
396 | 396 | global $sugar_config; |
397 | - if(!array_key_exists("aop",$sugar_config)){ |
|
397 | + if (!array_key_exists("aop", $sugar_config)) { |
|
398 | 398 | return array(); |
399 | 399 | } |
400 | 400 | return $sugar_config['aop']; |
401 | 401 | } |
402 | 402 | |
403 | - private function sendCreationEmail(aCase $bean, $contact){ |
|
404 | - if(!isAOPEnabled()){ |
|
403 | + private function sendCreationEmail(aCase $bean, $contact) { |
|
404 | + if (!isAOPEnabled()) { |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | require_once("include/SugarPHPMailer.php"); |
408 | - $mailer=new SugarPHPMailer(); |
|
408 | + $mailer = new SugarPHPMailer(); |
|
409 | 409 | $admin = new Administration(); |
410 | 410 | $admin->retrieveSettings(); |
411 | 411 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | |
417 | 417 | $aop_config = $this->getAOPConfig(); |
418 | 418 | $email_template = $email_template->retrieve($aop_config['case_creation_email_template_id']); |
419 | - if(!$aop_config['case_creation_email_template_id'] || !$email_template){ |
|
419 | + if (!$aop_config['case_creation_email_template_id'] || !$email_template) { |
|
420 | 420 | $GLOBALS['log']->warn("CaseUpdatesHook: sendCreationEmail template is empty"); |
421 | 421 | return false; |
422 | 422 | } |
@@ -430,24 +430,24 @@ discard block |
||
430 | 430 | $mailer->From = $emailSettings['from_address']; |
431 | 431 | $mailer->FromName = $emailSettings['from_name']; |
432 | 432 | $email = $contact->emailAddress->getPrimaryAddress($contact); |
433 | - if(empty($email) && !empty($contact->email1)){ |
|
433 | + if (empty($email) && !empty($contact->email1)) { |
|
434 | 434 | $email = $contact->email1; |
435 | 435 | } |
436 | 436 | $mailer->AddAddress($email); |
437 | - if (!$mailer->Send()){ |
|
438 | - $GLOBALS['log']->info("CaseUpdatesHook: Could not send email: " . $mailer->ErrorInfo); |
|
437 | + if (!$mailer->Send()) { |
|
438 | + $GLOBALS['log']->info("CaseUpdatesHook: Could not send email: ".$mailer->ErrorInfo); |
|
439 | 439 | return false; |
440 | - }else{ |
|
440 | + } else { |
|
441 | 441 | $this->logEmail($email, $mailer, $bean->id); |
442 | 442 | return true; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | - private function logEmail($email, $mailer, $caseId = null){ |
|
446 | + private function logEmail($email, $mailer, $caseId = null) { |
|
447 | 447 | require_once('modules/Emails/Email.php'); |
448 | 448 | $emailObj = new Email(); |
449 | 449 | $emailObj->to_addrs = $email; |
450 | - $emailObj->type= 'out'; |
|
450 | + $emailObj->type = 'out'; |
|
451 | 451 | $emailObj->deleted = '0'; |
452 | 452 | $emailObj->name = $mailer->Subject; |
453 | 453 | $emailObj->description = $mailer->AltBody; |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $emailObj->save(); |
465 | 465 | } |
466 | 466 | |
467 | - public function filterHTML($bean, $event, $arguments){ |
|
468 | - $bean->description = SugarCleaner::cleanHtml($bean->description,true); |
|
467 | + public function filterHTML($bean, $event, $arguments) { |
|
468 | + $bean->description = SugarCleaner::cleanHtml($bean->description, true); |
|
469 | 469 | } |
470 | 470 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | var $table_name = 'aop_case_updates'; |
37 | 37 | var $tracker_visibility = false; |
38 | 38 | var $importable = false; |
39 | - var $disable_row_level_security = true ; // to ensure that modules created and deployed under CE will continue to function under team security if the instance is upgraded to PRO |
|
39 | + var $disable_row_level_security = true; // to ensure that modules created and deployed under CE will continue to function under team security if the instance is upgraded to PRO |
|
40 | 40 | var $id; |
41 | 41 | var $name; |
42 | 42 | var $date_entered; |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | var $assigned_user_id; |
53 | 53 | var $assigned_user_name; |
54 | 54 | var $assigned_user_link; |
55 | - function AOP_Case_Updates_sugar(){ |
|
55 | + function AOP_Case_Updates_sugar() { |
|
56 | 56 | parent::Basic(); |
57 | 57 | } |
58 | 58 | |
59 | - function bean_implements($interface){ |
|
60 | - switch($interface){ |
|
59 | + function bean_implements($interface) { |
|
60 | + switch ($interface) { |
|
61 | 61 | case 'ACL': return true; |
62 | 62 | } |
63 | 63 | return false; |
@@ -1,76 +1,76 @@ discard block |
||
1 | 1 | <?php |
2 | -class AOPAssignManager{ |
|
2 | +class AOPAssignManager { |
|
3 | 3 | private $ieX = false; |
4 | 4 | private $distributionMethod = ''; |
5 | 5 | private $aopFallback = true; |
6 | 6 | private $assignableUsers = array(); |
7 | 7 | |
8 | - function __construct($ieX = false){ |
|
8 | + function __construct($ieX = false) { |
|
9 | 9 | global $sugar_config; |
10 | 10 | $this->ieX = $ieX; |
11 | - if($ieX) { |
|
11 | + if ($ieX) { |
|
12 | 12 | $inboundDistribMethod = $ieX->get_stored_options("distrib_method", ""); |
13 | - }else{ |
|
13 | + } else { |
|
14 | 14 | $inboundDistribMethod = ''; |
15 | 15 | } |
16 | - if($this->isAOPFallback($inboundDistribMethod)){ |
|
16 | + if ($this->isAOPFallback($inboundDistribMethod)) { |
|
17 | 17 | $this->distributionMethod = $sugar_config['aop']['distribution_method']; |
18 | 18 | $this->aopFallback = true; |
19 | - }else{ |
|
19 | + } else { |
|
20 | 20 | $this->distributionMethod = $inboundDistribMethod; |
21 | 21 | $this->aopFallback = false; |
22 | 22 | } |
23 | 23 | $this->assignableUsers = $this->getAssignableUsers(); |
24 | 24 | } |
25 | 25 | |
26 | - private function isAOPFallback($distribMethod){ |
|
26 | + private function isAOPFallback($distribMethod) { |
|
27 | 27 | return empty($distribMethod) || $distribMethod == 'AOPDefault'; |
28 | 28 | } |
29 | 29 | |
30 | - private function getDistributionOptions(){ |
|
30 | + private function getDistributionOptions() { |
|
31 | 31 | global $sugar_config; |
32 | - if($this->aopFallback){ |
|
32 | + if ($this->aopFallback) { |
|
33 | 33 | return $sugar_config['aop']['distribution_options']; |
34 | - }else{ |
|
34 | + } else { |
|
35 | 35 | return $this->ieX->get_stored_options("distribution_options", ''); |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | - private function getRoleUsers($roleId){ |
|
39 | + private function getRoleUsers($roleId) { |
|
40 | 40 | require_once('modules/ACLRoles/ACLRole.php'); |
41 | 41 | $role = new ACLRole(); |
42 | 42 | $role->retrieve($roleId); |
43 | - $role_users = $role->get_linked_beans( 'users','User'); |
|
43 | + $role_users = $role->get_linked_beans('users', 'User'); |
|
44 | 44 | $r_users = array(); |
45 | - foreach($role_users as $role_user){ |
|
45 | + foreach ($role_users as $role_user) { |
|
46 | 46 | $r_users[$role_user->id] = $role_user->name; |
47 | 47 | } |
48 | 48 | return $r_users; |
49 | 49 | } |
50 | 50 | |
51 | - private function getAssignableUsers(){ |
|
52 | - if($this->distributionMethod == 'singleUser'){ |
|
51 | + private function getAssignableUsers() { |
|
52 | + if ($this->distributionMethod == 'singleUser') { |
|
53 | 53 | return array(); |
54 | 54 | } |
55 | 55 | $distributionOptions = $this->getDistributionOptions(); |
56 | 56 | |
57 | - if(empty($distributionOptions)){ |
|
57 | + if (empty($distributionOptions)) { |
|
58 | 58 | return array(); |
59 | 59 | } |
60 | - switch($distributionOptions[0]) { |
|
60 | + switch ($distributionOptions[0]) { |
|
61 | 61 | Case 'security_group': |
62 | - if(file_exists('modules/SecurityGroups/SecurityGroup.php')){ |
|
62 | + if (file_exists('modules/SecurityGroups/SecurityGroup.php')) { |
|
63 | 63 | require_once('modules/SecurityGroups/SecurityGroup.php'); |
64 | 64 | $security_group = new SecurityGroup(); |
65 | 65 | $security_group->retrieve($distributionOptions[1]); |
66 | - $group_users = $security_group->get_linked_beans( 'users','User'); |
|
66 | + $group_users = $security_group->get_linked_beans('users', 'User'); |
|
67 | 67 | $users = array(); |
68 | 68 | $r_users = array(); |
69 | - if($distributionOptions[2] != ''){ |
|
69 | + if ($distributionOptions[2] != '') { |
|
70 | 70 | $r_users = $this->getRoleUsers($distributionOptions[2]); |
71 | 71 | } |
72 | - foreach($group_users as $group_user){ |
|
73 | - if($distributionOptions[2] != '' && !isset($r_users[$group_user->id])){ |
|
72 | + foreach ($group_users as $group_user) { |
|
73 | + if ($distributionOptions[2] != '' && !isset($r_users[$group_user->id])) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | $users[$group_user->id] = $group_user->name; |
@@ -90,57 +90,57 @@ discard block |
||
90 | 90 | |
91 | 91 | } |
92 | 92 | |
93 | - private function getSingleUser(){ |
|
93 | + private function getSingleUser() { |
|
94 | 94 | global $sugar_config; |
95 | - if($this->singleUser){ |
|
95 | + if ($this->singleUser) { |
|
96 | 96 | return $this->singleUser; |
97 | 97 | } |
98 | - if($this->aopFallback){ |
|
98 | + if ($this->aopFallback) { |
|
99 | 99 | $this->singleUser = !empty($sugar_config['aop']['distribution_user_id']) ? $sugar_config['aop']['distribution_user_id'] : ''; |
100 | - }else{ |
|
100 | + } else { |
|
101 | 101 | $this->singleUser = $this->ieX->get_stored_options("distribution_user_id", ""); |
102 | 102 | } |
103 | 103 | return $this->singleUser; |
104 | 104 | } |
105 | 105 | |
106 | - private function getLeastBusyCounts(){ |
|
107 | - if($this->leastBusyUsers){ |
|
106 | + private function getLeastBusyCounts() { |
|
107 | + if ($this->leastBusyUsers) { |
|
108 | 108 | return $this->leastBusyUsers; |
109 | 109 | } |
110 | 110 | global $db; |
111 | - $idIn = implode("','",$db->arrayQuote(array_keys($this->assignableUsers))); |
|
112 | - if($idIn){ |
|
111 | + $idIn = implode("','", $db->arrayQuote(array_keys($this->assignableUsers))); |
|
112 | + if ($idIn) { |
|
113 | 113 | $idIn = "'".$idIn."'"; |
114 | 114 | } |
115 | 115 | $res = $db->query("SELECT assigned_user_id, COUNT(*) AS c FROM cases WHERE assigned_user_id IN ({$idIn}) AND deleted = 0 GROUP BY assigned_user_id ORDER BY COUNT(*)"); |
116 | 116 | $this->leastBusyUsers = array(); |
117 | - while($row = $db->fetchByAssoc($res)){ |
|
117 | + while ($row = $db->fetchByAssoc($res)) { |
|
118 | 118 | $this->leastBusyUsers[$row['assigned_user_id']] = $row['c']; |
119 | 119 | } |
120 | 120 | return $this->leastBusyUsers; |
121 | 121 | } |
122 | 122 | |
123 | - private function getLeastBusyUser(){ |
|
123 | + private function getLeastBusyUser() { |
|
124 | 124 | $leastBusyCounts = $this->getLeastBusyCounts(); |
125 | 125 | asort($leastBusyCounts); |
126 | 126 | reset($leastBusyCounts); |
127 | 127 | return key($leastBusyCounts); |
128 | 128 | } |
129 | 129 | |
130 | - private function updateLeastBusy($id){ |
|
131 | - if(!$this->leastBusyUsers){ |
|
130 | + private function updateLeastBusy($id) { |
|
131 | + if (!$this->leastBusyUsers) { |
|
132 | 132 | $this->getLeastBusyCounts(); |
133 | 133 | } |
134 | 134 | $this->leastBusyUsers[$id] = $this->leastBusyUsers[$id] + 1; |
135 | 135 | } |
136 | 136 | |
137 | - private function getRandomUser(){ |
|
137 | + private function getRandomUser() { |
|
138 | 138 | $randKey = array_rand($this->assignableUsers); |
139 | 139 | return $this->assignableUsers[$randKey]; |
140 | 140 | } |
141 | 141 | |
142 | - function getNextAssignedUser(){ |
|
143 | - switch($this->distributionMethod){ |
|
142 | + function getNextAssignedUser() { |
|
143 | + switch ($this->distributionMethod) { |
|
144 | 144 | case 'singleUser': |
145 | 145 | $userId = $this->getSingleUser(); |
146 | 146 | break; |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | |
164 | 164 | private function getRoundRobinUser() { |
165 | 165 | $id = empty($this->ieX) ? '' : $this->ieX->id; |
166 | - $file = create_cache_directory('modules/AOP_Case_Updates/Users/') . $id . 'lastUser.cache.php'; |
|
167 | - if(isset($_SESSION['AOPlastuser'][$id]) && $_SESSION['AOPlastuser'][$id] != '') { |
|
166 | + $file = create_cache_directory('modules/AOP_Case_Updates/Users/').$id.'lastUser.cache.php'; |
|
167 | + if (isset($_SESSION['AOPlastuser'][$id]) && $_SESSION['AOPlastuser'][$id] != '') { |
|
168 | 168 | $lastUserId = $_SESSION['AOPlastuser'][$id]; |
169 | 169 | } |
170 | - else if (is_file($file)){ |
|
170 | + else if (is_file($file)) { |
|
171 | 171 | include $file; |
172 | - if(isset($lastUser['User']) && $lastUser['User'] != '') { |
|
172 | + if (isset($lastUser['User']) && $lastUser['User'] != '') { |
|
173 | 173 | $lastUserId = $lastUser['User']; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | $users = array_keys($this->assignableUsers); |
177 | - $lastOffset = array_search($lastUserId,$users); |
|
177 | + $lastOffset = array_search($lastUserId, $users); |
|
178 | 178 | $newOffset = ($lastOffset + 1) % count($users); |
179 | - if(!empty($users[$newOffset])) { |
|
179 | + if (!empty($users[$newOffset])) { |
|
180 | 180 | return $users[$newOffset]; |
181 | 181 | } |
182 | 182 | return reset($users); |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | private function setLastRoundRobinUser($user_id) { |
186 | 186 | $id = empty($this->ieX) ? '' : $this->ieX->id; |
187 | 187 | $_SESSION['AOPlastuser'][$id] = $user_id; |
188 | - $file = create_cache_directory('modules/AOP_Case_Updates/Users/') . $id . 'lastUser.cache.php'; |
|
188 | + $file = create_cache_directory('modules/AOP_Case_Updates/Users/').$id.'lastUser.cache.php'; |
|
189 | 189 | $arrayString = var_export_helper(array('User' => $user_id)); |
190 | - $content =<<<eoq |
|
190 | + $content = <<<eoq |
|
191 | 191 | <?php |
192 | 192 | \$lastUser = {$arrayString}; |
193 | 193 | ?> |
194 | 194 | eoq; |
195 | - if($fh = @sugar_fopen($file, 'w')) { |
|
195 | + if ($fh = @sugar_fopen($file, 'w')) { |
|
196 | 196 | fputs($fh, $content); |
197 | 197 | fclose($fh); |
198 | 198 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | ********************************************************************************/ |
40 | 40 | |
41 | 41 | |
42 | -$fields_array['Schedulers_jobs'] = array ( |
|
43 | - 'column_fields' => array ( |
|
42 | +$fields_array['Schedulers_jobs'] = array( |
|
43 | + 'column_fields' => array( |
|
44 | 44 | 'id', |
45 | 45 | 'deleted', |
46 | 46 | 'date_entered', |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | 'execute_time', |
50 | 50 | 'status', |
51 | 51 | ), |
52 | - 'list_fields' => array ( |
|
52 | + 'list_fields' => array( |
|
53 | 53 | 'id', |
54 | 54 | 'job_id', |
55 | 55 | 'execute_time' |
56 | 56 | ), |
57 | - 'required_fields' => array ( |
|
57 | + 'required_fields' => array( |
|
58 | 58 | 'job_id' => 1, |
59 | 59 | 'execute_time' => 1 |
60 | 60 | ) |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | public $requeue; // Requeue on failure? |
71 | 71 | public $retry_count; |
72 | 72 | public $failure_count; |
73 | - public $job_delay=0; // Frequency to run it |
|
73 | + public $job_delay = 0; // Frequency to run it |
|
74 | 74 | public $assigned_user_id; // User under which the task is running |
75 | 75 | public $client; // Client ID that owns this job |
76 | 76 | public $execute_time_db; |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | |
79 | 79 | // standard SugarBean child attrs |
80 | 80 | var $table_name = "job_queue"; |
81 | - var $object_name = "SchedulersJob"; |
|
81 | + var $object_name = "SchedulersJob"; |
|
82 | 82 | var $module_dir = "SchedulersJobs"; |
83 | 83 | var $new_schema = true; |
84 | 84 | var $process_save_dates = true; |
85 | 85 | // related fields |
86 | - var $job_name; // the Scheduler's 'name' field |
|
87 | - var $job; // the Scheduler's 'job' field |
|
86 | + var $job_name; // the Scheduler's 'name' field |
|
87 | + var $job; // the Scheduler's 'job' field |
|
88 | 88 | // object specific attributes |
89 | 89 | public $user; // User object |
90 | 90 | var $scheduler; // Scheduler parent |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | function SchedulersJob() |
99 | 99 | { |
100 | 100 | parent::Basic(); |
101 | - if(!empty($GLOBALS['sugar_config']['jobs']['min_retry_interval'])) { |
|
101 | + if (!empty($GLOBALS['sugar_config']['jobs']['min_retry_interval'])) { |
|
102 | 102 | $this->min_interval = $GLOBALS['sugar_config']['jobs']['min_retry_interval']; |
103 | 103 | } |
104 | 104 | } |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string Formatted datetime value |
123 | 123 | */ |
124 | - function handleDateFormat($date='now', $user=null, $user_format=false) { |
|
124 | + function handleDateFormat($date = 'now', $user = null, $user_format = false) { |
|
125 | 125 | global $timedate; |
126 | 126 | |
127 | - if(!isset($timedate) || empty($timedate)) |
|
127 | + if (!isset($timedate) || empty($timedate)) |
|
128 | 128 | { |
129 | 129 | $timedate = new TimeDate(); |
130 | 130 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | // get user for calculation |
133 | 133 | $user = (empty($user)) ? $this->user : $user; |
134 | 134 | |
135 | - if($date == 'now') |
|
135 | + if ($date == 'now') |
|
136 | 136 | { |
137 | 137 | $dbTime = $timedate->asUser($timedate->getNow(), $user); |
138 | 138 | } else { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param $job String in URI-clean format |
153 | 153 | * @param $timeout Int value in secs for cURL to timeout. 30 default. |
154 | 154 | */ |
155 | - public function fireUrl($job, $timeout=30) |
|
155 | + public function fireUrl($job, $timeout = 30) |
|
156 | 156 | { |
157 | 157 | // TODO: figure out what error is thrown when no more apache instances can be spun off |
158 | 158 | // cURL inits |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | curl_setopt($ch, CURLOPT_FAILONERROR, true); // silent failure (code >300); |
162 | 162 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // do not follow location(); inits - we always use the current |
163 | 163 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); |
164 | - curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); // not thread-safe |
|
164 | + curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); // not thread-safe |
|
165 | 165 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable to continue program execution |
166 | 166 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // never times out - bad idea? |
167 | 167 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // 5 secs for connect timeout |
168 | - curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); // open brand new conn |
|
168 | + curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); // open brand new conn |
|
169 | 169 | curl_setopt($ch, CURLOPT_HEADER, true); // do not return header info with result |
170 | 170 | curl_setopt($ch, CURLOPT_NOPROGRESS, true); // do not have progress bar |
171 | 171 | $urlparts = parse_url($job); |
172 | - if(empty($urlparts['port'])) { |
|
173 | - if($urlparts['scheme'] == 'https'){ |
|
172 | + if (empty($urlparts['port'])) { |
|
173 | + if ($urlparts['scheme'] == 'https') { |
|
174 | 174 | $urlparts['port'] = 443; |
175 | 175 | } else { |
176 | 176 | $urlparts['port'] = 80; |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | |
184 | 184 | curl_setopt($ch, CURLOPT_NOSIGNAL, true); // ignore any cURL signals to PHP (for multi-threading) |
185 | 185 | $result = curl_exec($ch); |
186 | - $cInfo = curl_getinfo($ch); //url,content_type,header_size,request_size,filetime,http_code |
|
186 | + $cInfo = curl_getinfo($ch); //url,content_type,header_size,request_size,filetime,http_code |
|
187 | 187 | //ssl_verify_result,total_time,namelookup_time,connect_time |
188 | 188 | //pretransfer_time,size_upload,size_download,speed_download, |
189 | 189 | //speed_upload,download_content_length,upload_content_length |
190 | 190 | //starttransfer_time,redirect_time |
191 | - if(curl_errno($ch)) { |
|
191 | + if (curl_errno($ch)) { |
|
192 | 192 | $this->errors .= curl_errno($ch)."\n"; |
193 | 193 | } |
194 | 194 | curl_close($ch); |
195 | 195 | |
196 | - if($result !== FALSE && $cInfo['http_code'] < 400) { |
|
196 | + if ($result !== FALSE && $cInfo['http_code'] < 400) { |
|
197 | 197 | $GLOBALS['log']->debug("----->Firing was successful: $job"); |
198 | 198 | $GLOBALS['log']->debug('----->WTIH RESULT: '.strip_tags($result).' AND '.strip_tags(print_r($cInfo, true))); |
199 | 199 | return true; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $temp_array = $this->get_list_view_array(); |
219 | 219 | $temp_array['JOB_NAME'] = $this->job_name; |
220 | - $temp_array['JOB'] = $this->job; |
|
220 | + $temp_array['JOB'] = $this->job; |
|
221 | 221 | |
222 | 222 | return $temp_array; |
223 | 223 | } |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | public function resolveJob($resolution, $message = null) |
277 | 277 | { |
278 | 278 | $GLOBALS['log']->info("Resolving job {$this->id} as $resolution: $message"); |
279 | - if($resolution == self::JOB_FAILURE) { |
|
279 | + if ($resolution == self::JOB_FAILURE) { |
|
280 | 280 | $this->failure_count++; |
281 | - if($this->requeue && $this->retry_count > 0) { |
|
281 | + if ($this->requeue && $this->retry_count > 0) { |
|
282 | 282 | // retry failed job |
283 | 283 | $this->status = self::JOB_STATUS_QUEUED; |
284 | - if($this->job_delay < $this->min_interval) { |
|
284 | + if ($this->job_delay < $this->min_interval) { |
|
285 | 285 | $this->job_delay = $this->min_interval; |
286 | 286 | } |
287 | 287 | $this->execute_time = $GLOBALS['timedate']->getNow()->modify("+{$this->job_delay} seconds")->asDb(); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $this->addMessages($message); |
300 | 300 | $this->resolution = $resolution; |
301 | 301 | $this->save(); |
302 | - if($this->status == self::JOB_STATUS_DONE && $this->resolution == self::JOB_SUCCESS) { |
|
302 | + if ($this->status == self::JOB_STATUS_DONE && $this->resolution == self::JOB_SUCCESS) { |
|
303 | 303 | $this->updateSchedulerSuccess(); |
304 | 304 | } |
305 | 305 | return true; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | protected function updateSchedulerSuccess() |
312 | 312 | { |
313 | - if(empty($this->scheduler_id)) { |
|
313 | + if (empty($this->scheduler_id)) { |
|
314 | 314 | return; |
315 | 315 | } |
316 | 316 | $this->db->query("UPDATE schedulers SET last_run={$this->db->now()} WHERE id=".$this->db->quoted($this->scheduler_id)); |
@@ -323,11 +323,11 @@ discard block |
||
323 | 323 | */ |
324 | 324 | protected function addMessages($message) |
325 | 325 | { |
326 | - if(!empty($this->errors)) { |
|
326 | + if (!empty($this->errors)) { |
|
327 | 327 | $this->message .= $this->errors; |
328 | 328 | $this->errors = ''; |
329 | 329 | } |
330 | - if(!empty($message)) { |
|
330 | + if (!empty($message)) { |
|
331 | 331 | $this->message .= "$message\n"; |
332 | 332 | } |
333 | 333 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $this->status = self::JOB_STATUS_QUEUED; |
344 | 344 | $this->addMessages($message); |
345 | 345 | $this->resolution = self::JOB_PARTIAL; |
346 | - if(empty($delay)) { |
|
346 | + if (empty($delay)) { |
|
347 | 347 | $delay = intval($this->job_delay); |
348 | 348 | } |
349 | 349 | $this->execute_time = $GLOBALS['timedate']->getNow()->modify("+$delay seconds")->asDb(); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function unexpectedExit() |
369 | 369 | { |
370 | - if(!$this->job_done) { |
|
370 | + if (!$this->job_done) { |
|
371 | 371 | // Job wasn't properly finished, fail it |
372 | 372 | $this->resolveJob(self::JOB_FAILURE, translate('ERR_FAILED', 'SchedulersJobs')); |
373 | 373 | } |
@@ -383,15 +383,15 @@ discard block |
||
383 | 383 | { |
384 | 384 | $job = new self(); |
385 | 385 | $job->retrieve($id); |
386 | - if(empty($job->id)) { |
|
386 | + if (empty($job->id)) { |
|
387 | 387 | $GLOBALS['log']->fatal("Job $id not found."); |
388 | 388 | return "Job $id not found."; |
389 | 389 | } |
390 | - if($job->status != self::JOB_STATUS_RUNNING) { |
|
390 | + if ($job->status != self::JOB_STATUS_RUNNING) { |
|
391 | 391 | $GLOBALS['log']->fatal("Job $id is not marked as running."); |
392 | 392 | return "Job $id is not marked as running."; |
393 | 393 | } |
394 | - if($job->client != $client) { |
|
394 | + if ($job->client != $client) { |
|
395 | 395 | $GLOBALS['log']->fatal("Job $id belongs to client {$job->client}, can not run as $client."); |
396 | 396 | return "Job $id belongs to another client, can not run as $client."; |
397 | 397 | } |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | */ |
412 | 412 | public function errorHandler($errno, $errstr, $errfile, $errline) |
413 | 413 | { |
414 | - switch($errno) |
|
414 | + switch ($errno) |
|
415 | 415 | { |
416 | 416 | case E_USER_WARNING: |
417 | 417 | case E_COMPILE_WARNING: |
@@ -447,14 +447,14 @@ discard block |
||
447 | 447 | { |
448 | 448 | $GLOBALS['current_user'] = $user; |
449 | 449 | // Reset the session |
450 | - if(session_id()) { |
|
450 | + if (session_id()) { |
|
451 | 451 | session_destroy(); |
452 | 452 | } |
453 | - if(!headers_sent()) { |
|
453 | + if (!headers_sent()) { |
|
454 | 454 | session_start(); |
455 | 455 | session_regenerate_id(); |
456 | 456 | } |
457 | - $_SESSION['is_valid_session']= true; |
|
457 | + $_SESSION['is_valid_session'] = true; |
|
458 | 458 | $_SESSION['user_id'] = $user->id; |
459 | 459 | $_SESSION['type'] = 'user'; |
460 | 460 | $_SESSION['authenticated_user_id'] = $user->id; |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | protected function setJobUser() |
468 | 468 | { |
469 | 469 | // set up the current user and drop session |
470 | - if(!empty($this->assigned_user_id)) { |
|
470 | + if (!empty($this->assigned_user_id)) { |
|
471 | 471 | $this->old_user = $GLOBALS['current_user']; |
472 | - if(empty($this->user->id) || $this->assigned_user_id != $this->user->id) { |
|
472 | + if (empty($this->user->id) || $this->assigned_user_id != $this->user->id) { |
|
473 | 473 | $this->user = BeanFactory::getBean('Users', $this->assigned_user_id); |
474 | - if(empty($this->user->id)) { |
|
474 | + if (empty($this->user->id)) { |
|
475 | 475 | $this->resolveJob(self::JOB_FAILURE, sprintf(translate('ERR_NOSUCHUSER', 'SchedulersJobs'), $this->assigned_user_id)); |
476 | 476 | return false; |
477 | 477 | } |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | */ |
490 | 490 | protected function restoreJobUser() |
491 | 491 | { |
492 | - if(!empty($this->old_user->id) && $this->old_user->id != $this->user->id) { |
|
492 | + if (!empty($this->old_user->id) && $this->old_user->id != $this->user->id) { |
|
493 | 493 | $this->sudo($this->old_user); |
494 | 494 | } |
495 | 495 | } |
@@ -504,27 +504,27 @@ discard block |
||
504 | 504 | |
505 | 505 | $this->errors = ""; |
506 | 506 | $exJob = explode('::', $this->target, 2); |
507 | - if($exJob[0] == 'function') { |
|
507 | + if ($exJob[0] == 'function') { |
|
508 | 508 | // set up the current user and drop session |
509 | - if(!$this->setJobUser()) { |
|
509 | + if (!$this->setJobUser()) { |
|
510 | 510 | return false; |
511 | 511 | } |
512 | 512 | $func = $exJob[1]; |
513 | 513 | $GLOBALS['log']->debug("----->SchedulersJob calling function: $func"); |
514 | 514 | set_error_handler(array($this, "errorHandler"), E_ALL & ~E_NOTICE & ~E_STRICT); |
515 | - if(!is_callable($func)) { |
|
515 | + if (!is_callable($func)) { |
|
516 | 516 | $this->resolveJob(self::JOB_FAILURE, sprintf(translate('ERR_CALL', 'SchedulersJobs'), $func)); |
517 | 517 | } |
518 | 518 | $data = array($this); |
519 | - if(!empty($this->data)) { |
|
519 | + if (!empty($this->data)) { |
|
520 | 520 | $data[] = $this->data; |
521 | 521 | } |
522 | 522 | $res = call_user_func_array($func, $data); |
523 | 523 | restore_error_handler(); |
524 | 524 | $this->restoreJobUser(); |
525 | - if($this->status == self::JOB_STATUS_RUNNING) { |
|
525 | + if ($this->status == self::JOB_STATUS_RUNNING) { |
|
526 | 526 | // nobody updated the status yet - job function could do that |
527 | - if($res) { |
|
527 | + if ($res) { |
|
528 | 528 | $this->resolveJob(self::JOB_SUCCESS); |
529 | 529 | return true; |
530 | 530 | } else { |
@@ -534,11 +534,11 @@ discard block |
||
534 | 534 | } else { |
535 | 535 | return $this->resolution != self::JOB_FAILURE; |
536 | 536 | } |
537 | - } elseif($exJob[0] == 'url') { |
|
538 | - if(function_exists('curl_init')) { |
|
537 | + } elseif ($exJob[0] == 'url') { |
|
538 | + if (function_exists('curl_init')) { |
|
539 | 539 | $GLOBALS['log']->debug('----->SchedulersJob firing URL job: '.$exJob[1]); |
540 | 540 | set_error_handler(array($this, "errorHandler"), E_ALL & ~E_NOTICE & ~E_STRICT); |
541 | - if($this->fireUrl($exJob[1])) { |
|
541 | + if ($this->fireUrl($exJob[1])) { |
|
542 | 542 | restore_error_handler(); |
543 | 543 | $this->resolveJob(self::JOB_SUCCESS); |
544 | 544 | return true; |
@@ -552,10 +552,10 @@ discard block |
||
552 | 552 | } |
553 | 553 | } elseif ($exJob[0] == 'class') { |
554 | 554 | $tmpJob = new $exJob[1](); |
555 | - if($tmpJob instanceof RunnableSchedulerJob) |
|
555 | + if ($tmpJob instanceof RunnableSchedulerJob) |
|
556 | 556 | { |
557 | 557 | // set up the current user and drop session |
558 | - if(!$this->setJobUser()) { |
|
558 | + if (!$this->setJobUser()) { |
|
559 | 559 | return false; |
560 | 560 | } |
561 | 561 | $tmpJob->setJob($this); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | |
4 | 4 | /********************************************************************************* |
5 | 5 | * SugarCRM Community Edition is a customer relationship management program developed by |
@@ -87,24 +87,24 @@ discard block |
||
87 | 87 | { |
88 | 88 | static $sfh; |
89 | 89 | |
90 | - if(!isset($sfh)) { |
|
90 | + if (!isset($sfh)) { |
|
91 | 91 | require_once('include/SugarFields/SugarFieldHandler.php'); |
92 | 92 | $sfh = new SugarFieldHandler(); |
93 | 93 | } |
94 | 94 | $value = $params[0]; |
95 | 95 | $vardef = $params[1]; |
96 | - if ( isset($params[2]) ) |
|
96 | + if (isset($params[2])) |
|
97 | 97 | $focus = $params[2]; |
98 | 98 | else |
99 | 99 | $focus = null; |
100 | - if ( $name == 'relate' && !empty($params[3]) ) |
|
100 | + if ($name == 'relate' && !empty($params[3])) |
|
101 | 101 | $this->addRelatedBean = true; |
102 | 102 | else |
103 | 103 | $this->addRelatedBean = false; |
104 | 104 | |
105 | 105 | $field = $sfh->getSugarField(ucfirst($name)); |
106 | - if ( $field instanceOf SugarFieldBase ) { |
|
107 | - $value = $field->importSanitize($value,$vardef,$focus,$this); |
|
106 | + if ($field instanceOf SugarFieldBase) { |
|
107 | + $value = $field->importSanitize($value, $vardef, $focus, $this); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $value; |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | |
129 | 129 | $format = $this->dateformat; |
130 | 130 | |
131 | - if ( !$timedate->check_matching_format($value, $format) ) |
|
131 | + if (!$timedate->check_matching_format($value, $format)) |
|
132 | 132 | return false; |
133 | 133 | |
134 | - if ( !$this->isValidTimeDate($value, $format) ) |
|
134 | + if (!$this->isValidTimeDate($value, $format)) |
|
135 | 135 | return false; |
136 | 136 | |
137 | 137 | $value = $timedate->swap_formats( |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | // cache $sea instance |
157 | 157 | static $sea; |
158 | 158 | |
159 | - if ( !($sea instanceof SugarEmailAddress) ) { |
|
159 | + if (!($sea instanceof SugarEmailAddress)) { |
|
160 | 160 | $sea = new SugarEmailAddress; |
161 | 161 | } |
162 | 162 | |
163 | - if ( !empty($value) && !preg_match($sea->regex,$value) ) { |
|
163 | + if (!empty($value) && !preg_match($sea->regex, $value)) { |
|
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | static $focus_user; |
185 | 185 | |
186 | 186 | // cache this object since we'll be reusing it a bunch |
187 | - if ( !($focus_user instanceof User) ) { |
|
187 | + if (!($focus_user instanceof User)) { |
|
188 | 188 | |
189 | 189 | $focus_user = new User(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | |
193 | - if ( !empty($value) && strtolower($value) != "all" ) { |
|
194 | - $theList = explode(",",$value); |
|
193 | + if (!empty($value) && strtolower($value) != "all") { |
|
194 | + $theList = explode(",", $value); |
|
195 | 195 | $isValid = true; |
196 | 196 | $bad_names = array(); |
197 | 197 | foreach ($theList as $eachItem) { |
198 | - if ( $focus_user->retrieve_user_id($eachItem) |
|
198 | + if ($focus_user->retrieve_user_id($eachItem) |
|
199 | 199 | || $focus_user->retrieve($eachItem) |
200 | 200 | ) { |
201 | 201 | // all good |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | } |
209 | - if(!$isValid) { |
|
209 | + if (!$isValid) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | } |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | |
233 | 233 | $format = $this->timeformat; |
234 | 234 | |
235 | - if ( !$timedate->check_matching_format($value, $format) ) |
|
235 | + if (!$timedate->check_matching_format($value, $format)) |
|
236 | 236 | return false; |
237 | 237 | |
238 | - if ( !$this->isValidTimeDate($value, $format) ) |
|
238 | + if (!$this->isValidTimeDate($value, $format)) |
|
239 | 239 | return false; |
240 | 240 | |
241 | 241 | $value = $timedate->swap_formats( |
@@ -266,46 +266,46 @@ discard block |
||
266 | 266 | $reg = $timedate->get_regular_expression($format); |
267 | 267 | preg_match('@'.$reg['format'].'@', $value, $dateparts); |
268 | 268 | |
269 | - if ( empty($dateparts) ) |
|
269 | + if (empty($dateparts)) |
|
270 | 270 | return false; |
271 | - if ( isset($reg['positions']['a']) |
|
272 | - && !in_array($dateparts[$reg['positions']['a']], array('am','pm')) ) |
|
271 | + if (isset($reg['positions']['a']) |
|
272 | + && !in_array($dateparts[$reg['positions']['a']], array('am', 'pm'))) |
|
273 | 273 | return false; |
274 | - if ( isset($reg['positions']['A']) |
|
275 | - && !in_array($dateparts[$reg['positions']['A']], array('AM','PM')) ) |
|
274 | + if (isset($reg['positions']['A']) |
|
275 | + && !in_array($dateparts[$reg['positions']['A']], array('AM', 'PM'))) |
|
276 | 276 | return false; |
277 | - if ( isset($reg['positions']['h']) && ( |
|
277 | + if (isset($reg['positions']['h']) && ( |
|
278 | 278 | !is_numeric($dateparts[$reg['positions']['h']]) |
279 | 279 | || $dateparts[$reg['positions']['h']] < 1 |
280 | - || $dateparts[$reg['positions']['h']] > 12 ) ) |
|
280 | + || $dateparts[$reg['positions']['h']] > 12 )) |
|
281 | 281 | return false; |
282 | - if ( isset($reg['positions']['H']) && ( |
|
282 | + if (isset($reg['positions']['H']) && ( |
|
283 | 283 | !is_numeric($dateparts[$reg['positions']['H']]) |
284 | 284 | || $dateparts[$reg['positions']['H']] < 0 |
285 | - || $dateparts[$reg['positions']['H']] > 23 ) ) |
|
285 | + || $dateparts[$reg['positions']['H']] > 23 )) |
|
286 | 286 | return false; |
287 | - if ( isset($reg['positions']['i']) && ( |
|
287 | + if (isset($reg['positions']['i']) && ( |
|
288 | 288 | !is_numeric($dateparts[$reg['positions']['i']]) |
289 | 289 | || $dateparts[$reg['positions']['i']] < 0 |
290 | - || $dateparts[$reg['positions']['i']] > 59 ) ) |
|
290 | + || $dateparts[$reg['positions']['i']] > 59 )) |
|
291 | 291 | return false; |
292 | - if ( isset($reg['positions']['s']) && ( |
|
292 | + if (isset($reg['positions']['s']) && ( |
|
293 | 293 | !is_numeric($dateparts[$reg['positions']['s']]) |
294 | 294 | || $dateparts[$reg['positions']['s']] < 0 |
295 | - || $dateparts[$reg['positions']['s']] > 59 ) ) |
|
295 | + || $dateparts[$reg['positions']['s']] > 59 )) |
|
296 | 296 | return false; |
297 | - if ( isset($reg['positions']['d']) && ( |
|
297 | + if (isset($reg['positions']['d']) && ( |
|
298 | 298 | !is_numeric($dateparts[$reg['positions']['d']]) |
299 | 299 | || $dateparts[$reg['positions']['d']] < 1 |
300 | - || $dateparts[$reg['positions']['d']] > 31 ) ) |
|
300 | + || $dateparts[$reg['positions']['d']] > 31 )) |
|
301 | 301 | return false; |
302 | - if ( isset($reg['positions']['m']) && ( |
|
302 | + if (isset($reg['positions']['m']) && ( |
|
303 | 303 | !is_numeric($dateparts[$reg['positions']['m']]) |
304 | 304 | || $dateparts[$reg['positions']['m']] < 1 |
305 | - || $dateparts[$reg['positions']['m']] > 12 ) ) |
|
305 | + || $dateparts[$reg['positions']['m']] > 12 )) |
|
306 | 306 | return false; |
307 | - if ( isset($reg['positions']['Y']) && |
|
308 | - !is_numeric($dateparts[$reg['positions']['Y']]) ) |
|
307 | + if (isset($reg['positions']['Y']) && |
|
308 | + !is_numeric($dateparts[$reg['positions']['Y']])) |
|
309 | 309 | return false; |
310 | 310 | |
311 | 311 | return true; |