Esempio n. 1
0
 /**
  * Sends Email
  * @return bool True on success
  */
 function send()
 {
     global $mod_strings, $app_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     $mail = new SugarPHPMailer();
     foreach ($this->to_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddAddress($addr_arr['email'], "");
         } else {
             $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->cc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddCC($addr_arr['email'], "");
         } else {
             $mail->AddCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->bcc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddBCC($addr_arr['email'], "");
         } else {
             $mail->AddBCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     $mail = $this->setMailer($mail);
     // FROM ADDRESS
     if (!empty($this->from_addr)) {
         $mail->From = $this->from_addr;
     } else {
         $mail->From = $current_user->getPreference('mail_fromaddress');
         $this->from_addr = $mail->From;
     }
     // FROM NAME
     if (!empty($this->from_name)) {
         $mail->FromName = $this->from_name;
     } else {
         $mail->FromName = $current_user->getPreference('mail_fromname');
         $this->from_name = $mail->FromName;
     }
     //Reply to information for case create and autoreply.
     if (!empty($this->reply_to_name)) {
         $ReplyToName = $this->reply_to_name;
     } else {
         $ReplyToName = $mail->FromName;
     }
     if (!empty($this->reply_to_addr)) {
         $ReplyToAddr = $this->reply_to_addr;
     } else {
         $ReplyToAddr = $mail->From;
     }
     $mail->Sender = $mail->From;
     /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
     $mail->AddReplyTo($ReplyToAddr, $locale->translateCharsetMIME(trim($ReplyToName), 'UTF-8', $OBCharset));
     //$mail->Subject = html_entity_decode($this->name, ENT_QUOTES, 'UTF-8');
     $mail->Subject = $this->name;
     ///////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS
     foreach ($this->saved_attachments as $note) {
         $mime_type = 'text/plain';
         if ($note->object_name == 'Note') {
             if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                 // brandy-new file upload/attachment
                 $file_location = $sugar_config['upload_dir'] . $note->id;
                 $filename = $note->file->original_file_name;
                 $mime_type = $note->file->mime_type;
             } else {
                 // attachment coming from template/forward
                 $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $note->id));
                 // cn: bug 9723 - documents from EmailTemplates sent with Doc Name, not file name.
                 $filename = !empty($note->filename) ? $note->filename : $note->name;
                 $mime_type = $note->file_mime_type;
             }
         } elseif ($note->object_name == 'DocumentRevision') {
             // from Documents
             $filePathName = $note->id;
             // cn: bug 9723 - Emails with documents send GUID instead of Doc name
             $filename = $note->getDocumentRevisionNameForDisplay();
             $file_location = getcwd() . '/' . $GLOBALS['sugar_config']['upload_dir'] . $filePathName;
             $mime_type = $note->file_mime_type;
         }
         // strip out the "Email attachment label if exists
         $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
         //is attachment in our list of bad files extensions?  If so, append .txt to file location
         //get position of last "." in file name
         $file_ext_beg = strrpos($file_location, ".");
         $file_ext = "";
         //get file extension
         if ($file_ext_beg > 0) {
             $file_ext = substr($file_location, $file_ext_beg + 1);
         }
         //check to see if this is a file with extension located in "badext"
         foreach ($sugar_config['upload_badext'] as $badExt) {
             if (strtolower($file_ext) == strtolower($badExt)) {
                 //if found, then append with .txt to filename and break out of lookup
                 //this will make sure that the file goes out with right extension, but is stored
                 //as a text in db.
                 $file_location = $file_location . ".txt";
                 break;
                 // no need to look for more
             }
         }
         $mail->AddAttachment($file_location, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $mime_type);
         // embedded Images
         if ($note->embed_flag == true) {
             $cid = $filename;
             $mail->AddEmbeddedImage($file_location, $cid, $filename, 'base64', $mime_type);
         }
     }
     ////	END ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////
     $mail = $this->handleBody($mail);
     $GLOBALS['log']->debug('Email sending --------------------- ');
     ///////////////////////////////////////////////////////////////////////
     ////	I18N TRANSLATION
     $mail->prepForOutbound();
     ////	END I18N TRANSLATION
     ///////////////////////////////////////////////////////////////////////
     if ($mail->Send()) {
         ///////////////////////////////////////////////////////////////////
         ////	INBOUND EMAIL HANDLING
         // mark replied
         if (!empty($_REQUEST['inbound_email_id'])) {
             $ieMail = new Email();
             $ieMail->retrieve($_REQUEST['inbound_email_id']);
             $ieMail->status = 'replied';
             $ieMail->save();
         }
         $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful');
         ////	END INBOUND EMAIL HANDLING
         ///////////////////////////////////////////////////////////////////
         return true;
     }
     $GLOBALS['log']->debug($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo);
     return false;
 }
Esempio n. 2
0
 function sendEmail($emailTo, $emailSubject, $emailBody, $altemailBody, SugarBean $relatedBean = null, $emailCc = array(), $emailBcc = array(), $attachments = array())
 {
     require_once 'modules/Emails/Email.php';
     require_once 'include/SugarPHPMailer.php';
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->handleAttachments($attachments);
     $mail->prepForOutbound();
     if (empty($emailTo)) {
         return false;
     }
     foreach ($emailTo as $to) {
         $mail->AddAddress($to);
     }
     if (!empty($emailCc)) {
         foreach ($emailCc as $email) {
             $mail->AddCC($email);
         }
     }
     if (!empty($emailBcc)) {
         foreach ($emailBcc as $email) {
             $mail->AddBCC($email);
         }
     }
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = implode(',', $emailTo);
         $emailObj->cc_addrs = implode(',', $emailCc);
         $emailObj->bcc_addrs = implode(',', $emailBcc);
         $emailObj->type = 'out';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         return true;
     }
     return false;
 }
Esempio n. 3
0
 function send()
 {
     global $mod_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     $mail = new SugarPHPMailer();
     foreach ($this->to_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddAddress($addr_arr['email'], "");
         } else {
             $mail->AddAddress($addr_arr['email'], $addr_arr['display']);
         }
     }
     foreach ($this->cc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddCC($addr_arr['email'], "");
         } else {
             $mail->AddCC($addr_arr['email'], $addr_arr['display']);
         }
     }
     foreach ($this->bcc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddBCC($addr_arr['email'], "");
         } else {
             $mail->AddBCC($addr_arr['email'], $addr_arr['display']);
         }
     }
     if ($current_user->getPreference('mail_sendtype') == "SMTP") {
         $mail->Mailer = "smtp";
         $mail->Host = $current_user->getPreference('mail_smtpserver');
         $mail->Port = $current_user->getPreference('mail_smtpport');
         if ($current_user->getPreference('mail_smtpauth_req')) {
             $mail->SMTPAuth = TRUE;
             $mail->Username = $current_user->getPreference('mail_smtpuser');
             $mail->Password = $current_user->getPreference('mail_smtppass');
         }
     } else {
         // cn:no need to check since we default to it in any case!
         $mail->Mailer = "sendmail";
     }
     // FROM ADDRESS
     if (!empty($this->from_addr)) {
         $mail->From = $this->from_addr;
     } else {
         $mail->From = $current_user->getPreference('mail_fromaddress');
         $this->from_addr = $mail->From;
     }
     // FROM NAME
     if (!empty($this->from_name)) {
         $mail->FromName = $this->from_name;
     } else {
         $mail->FromName = $current_user->getPreference('mail_fromname');
         $this->from_name = $mail->FromName;
     }
     $mail->Sender = $mail->From;
     /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
     $mail->AddReplyTo($mail->From, $mail->FromName);
     $encoding = version_compare(phpversion(), '5.0', '>=') ? 'UTF-8' : 'ISO-8859-1';
     $mail->Subject = html_entity_decode($this->name, ENT_QUOTES, $encoding);
     ///////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS
     foreach ($this->saved_attachments as $note) {
         $mime_type = 'text/plain';
         if ($note->object_name == 'Note') {
             if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                 // brandy-new file upload/attachment
                 $file_location = $sugar_config['upload_dir'] . $note->id;
                 $filename = $note->file->original_file_name;
                 $mime_type = $note->file->mime_type;
             } else {
                 // attachment coming from template/forward
                 $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $note->id));
                 $filename = $note->name;
                 $mime_type = $note->file_mime_type;
             }
         } elseif ($note->object_name == 'DocumentRevision') {
             // from Documents
             $filename = $note->id;
             $file_location = getcwd() . '/cache/upload/' . $filename;
             $mime_type = $note->file_mime_type;
         }
         // strip out the "Email attachment label if exists
         $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
         // cn: bug 9233 attachment filenames need to be translated into the destination charset.
         $filename = $locale->translateCharset($filename, 'UTF-8', $locale->getPrecedentPreference('default_email_charset'));
         //is attachment in our list of bad files extensions?  If so, append .txt to file location
         //get position of last "." in file name
         $file_ext_beg = strrpos($file_location, ".");
         $file_ext = "";
         //get file extension
         if ($file_ext_beg > 0) {
             $file_ext = substr($file_location, $file_ext_beg + 1);
         }
         //check to see if this is a file with extension located in "badext"
         foreach ($sugar_config['upload_badext'] as $badExt) {
             if (strtolower($file_ext) == strtolower($badExt)) {
                 //if found, then append with .txt to filename and break out of lookup
                 //this will make sure that the file goes out with right extension, but is stored
                 //as a text in db.
                 $file_location = $file_location . ".txt";
                 break;
                 // no need to look for more
             }
         }
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
     }
     ////	END ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////
     ////	HANDLE EMAIL FORMAT PREFERENCE
     // the if() below is HIGHLY dependent on the Javascript unchecking the Send HTML Email box
     // HTML email
     if (isset($_REQUEST['setEditor']) && $_REQUEST['setEditor'] == 1 && trim($_REQUEST['description_html']) != '' || trim($this->description_html) != '') {
         // wp: if body is html, then insert new lines at 996 characters. no effect on client side
         // due to RFC 2822 which limits email lines to 998
         $mail->IsHTML(true);
         $body = from_html(wordwrap($this->description_html, 996));
         $mail->Body = $body;
         // if alternative body is defined, use that, else, striptags the HTML part
         if (trim($this->description) == '') {
             $plainText = from_html($this->description_html);
             $plainText = strip_tags(br2nl($plainText));
             //$plainText = $locale->translateCharset($plainText, 'UTF-8', $locale->getPrecedentPreference('default_email_charset'));
             $mail->AltBody = $plainText;
             $this->description = $plainText;
         } else {
             $mail->AltBody = wordwrap(from_html($this->description), 996);
         }
         // cn: bug 9709 - html email sent accidentally
         // handle signatures fubar'ing the type
         $sigs = $current_user->getDefaultSignature();
         $htmlSig = trim(str_replace(" ", "", strip_tags(from_html($sigs['signature_html']))));
         $htmlBody = trim(str_replace(" ", "", strip_tags(from_html($this->description_html))));
         if ($htmlSig == $htmlBody) {
             // found just a sig. ignore it.
             $this->description_html = '';
             $mail->IsHTML(false);
             $mail->Body = wordwrap(from_html($this->description, 996));
         }
     } else {
         // plain text only
         $this->description_html = '';
         $mail->IsHTML(false);
         $mail->Body = wordwrap(from_html($this->description, 996));
     }
     // wp: if plain text version has lines greater than 998, use base64 encoding
     foreach (explode("\n", $mail->ContentType == "text/html" ? $mail->AltBody : $mail->Body) as $line) {
         if (strlen($line) > 998) {
             $mail->Encoding = 'base64';
             break;
         }
     }
     ////	HANDLE EMAIL FORMAT PREFERENCE
     ///////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////
     ////    SAVE RAW MESSAGE
     $mail->SetMessageType();
     $raw = $mail->CreateHeader();
     $raw .= $mail->CreateBody();
     $this->raw_source = urlencode($raw);
     ////    END SAVE RAW MESSAGE
     ///////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug('Email sending --------------------- ');
     ///////////////////////////////////////////////////////////////////////
     ////	I18N TRANSLATION
     $mail->prepForOutbound();
     ////	END I18N TRANSLATION
     ///////////////////////////////////////////////////////////////////////
     if ($mail->Send()) {
         ///////////////////////////////////////////////////////////////////
         ////	INBOUND EMAIL HANDLING
         // mark replied
         if (!empty($_REQUEST['inbound_email_id'])) {
             $ieMail = new Email();
             $ieMail->retrieve($_REQUEST['inbound_email_id']);
             $ieMail->status = 'replied';
             $ieMail->save();
         }
         $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful');
         ////	END INBOUND EMAIL HANDLING
         ///////////////////////////////////////////////////////////////////
         return true;
     }
     $GLOBALS['log']->fatal("Error emailing:" . $mail->ErrorInfo);
     return false;
 }
Esempio n. 4
0
 public function operations($bean, $event, $arguments)
 {
     // File Operations
     // Check File Size
     if ($bean->fetched_row['id'] != "") {
         $f_size = $_FILES['filename_file']['size'];
         if ($f_size > 9000000) {
             die("File Size Should be less than 9MB");
         }
         // First check if the File is Selected or no
         $f_name = $bean->filename;
         if ($f_name == "") {
             die("Error: File not Selected!");
         }
         // Check File Extension Zip or No
         $f_extn = explode(".", $f_name);
         if ($f_extn[1] != "zip") {
             die("Error: Please Upload Zip Files Only!");
         }
     }
     //**********************************************************
     $id = $bean->id;
     $copy_to_email = "*****@*****.**";
     $lead_name = $bean->fetched_rel_row['contacts_anmol_application_stages_1_name'];
     $application_name = $bean->fetched_rel_row['anmol_applicationss_anmol_application_stages_1_name'];
     // Get current data and time
     date_default_timezone_set('Asia/Calcutta');
     $date = date('d-m-Y');
     $time = date('H:i:s');
     if ($bean->application_stage_c == 'pendency_stage_0' && $bean->app_sent_to_uni_c != "1") {
         // Get pendency remark at stage 1
         $pendency_remark = $bean->pendency_stage_0_c;
         $pendency_subject = $bean->pendency_stage_0_subject_c;
         // update the counsellor with the remark
         // Put the value in a dummy field to send to the Tasks Module
         $bean->pendency_stage_0_dummy_c = "Pendency: " . $pendency_remark;
         $bean->pendency_stage_0_subject_du__c = "Pendency(Stage 0): " . $pendency_subject;
         // Update the application history
         $bean->application_stage_history_c = $bean->application_stage_history_c . " >> <b style = \"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 0</b>: " . $pendency_subject . ": " . $pendency_remark . "<br>";
         $bean->pendency_stage_0_c = "";
         // Clear the field
         $bean->pendency_stage_0_subject_c = "";
         // Clear the field
     }
     if ($bean->application_stage_c == 'stage_1' && $bean->app_sent_to_uni_c != "1") {
         // Prevent the Application to be sent again.
         $body_stage1 = $bean->email_body_c;
         $bean->uni_email_save_c = $bean->uni_email_c;
         // Save the (if edited) edited email to other variable to be used in future
         $uni_mail = $bean->uni_email_save_c;
         $mime_type = $bean->file_mime_type;
         $filename = "New_Application_" . $application_name . ".zip";
         $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id;
         $subject = "SIEC Education " . $bean->email_subject_c . " " . $application_name;
         $body = $body_stage1;
         $email = $uni_mail;
         //Create Object New email
         $emailObj = new Email();
         $defaults = $emailObj->getSystemDefaultEmail();
         $mail = new SugarPHPMailer();
         $mail->setMailerForSystem();
         $mail->From = $defaults['email'];
         $mail->FromName = $defaults['name'];
         $mail->Subject = $subject;
         $mail->Body = $body;
         $mail->prepForOutbound();
         $name_to = "University";
         $mail->AddCC($copy_to_email);
         $mail->AddAddress($email, $name_to);
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
         @$mail->Send();
         // Moving the file to the new location
         //Get a Unique No
         $unq_extension = uniqid();
         echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         //
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage1/apps/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong with file uploading! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         $bean->app_sent_to_uni_c = "1";
         // Add Comment in App Stage History that the application has been Forwarded.
         $bean->application_stage_history_c = $bean->application_stage_history_c . " >> <b style = \"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application Forwarded to University on Email: </b>" . $bean->uni_email_c . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
         // Send Application to Universityuni_email_c
         // Get the email of the University from the University Module.
     }
     if ($bean->application_stage_c == 'pendency_stage_1') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         $pendency_remark1 = $bean->pendency_stage_1_c;
         $pendency_subject1 = $bean->pendency_stage_1_subject_c;
         $bean->pendency_stage_1_dummy_c = "Pendency: " . $pendency_remark1;
         $bean->pendency_stage_1_subject_du_c = "Pendency (Stage 1): " . $pendency_subject1;
         // Update the application history
         $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 1</b>: " . $pendency_subject1 . ": " . $pendency_remark1 . "<br>";
         // The notification gets sent to the counsellor as an email about the remark -<< done
         $bean->pendency_stage_1_c = "";
         // Clear the field
         $bean->pendency_stage_1_subject_c = "";
         // Clear the field
         $bean->pendency_state_c = "1";
     }
     // If Pendency document is forwarded to University at Stage 1
     if ($bean->application_stage_c == 'pendency_stage_1_update_to_uni') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get Pendency remark at stage 1
         // Prevent the Application to be sent again.
         $subject_stage1 = "SIEC Education >> Pendency Update " . $bean->email_subject_c . " " . $application_name;
         $body_stage1 = $bean->email_body_c;
         $mime_type = $bean->file_mime_type;
         $filename = "Pendency_Update_Stage1_" . $application_name . ".zip";
         $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id;
         $subject = $subject_stage1;
         $body = $body_stage1;
         $email = $bean->uni_email_save_c;
         //Create Object New email
         $emailObj = new Email();
         $defaults = $emailObj->getSystemDefaultEmail();
         $mail = new SugarPHPMailer();
         $mail->setMailerForSystem();
         $mail->From = $defaults['email'];
         $mail->FromName = $defaults['name'];
         $mail->Subject = $subject;
         $mail->Body = $body;
         $mail->prepForOutbound();
         $name_to = "University";
         $mail->AddCC($copy_to_email);
         $mail->AddAddress($email, $name_to);
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
         @$mail->Send();
         // Moving the file to the new location
         //Get a Unique No
         $unq_extension = uniqid();
         echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage1/pendencies/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         // Sent Email
         //  $bean->app_sent_to_uni_c = "11";
         $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Pendency Updated to University: " . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
     if ($bean->application_stage_c == 'uncon_offer') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         //Get a Unique No
         $unq_extension = uniqid();
         $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/uc_offer_letters/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         $bean->app_sent_to_uni_c = "11";
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Unconditional Offer Letter Recieved!" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
     if ($bean->application_stage_c == 'con_offer') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         //Get a Unique No
         $unq_extension = uniqid();
         $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/c_offer_letters/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         $bean->app_sent_to_uni_c = "12";
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Conditional Offer Letter Recieved!" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
     if ($bean->application_stage_c == 'rej_on_stage_1') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         //Get a Unique No
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Application Rejected by University</b><br>";
     }
     if ($bean->application_stage_c == 'rej_on_stage_1_by_student') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Application Rejected by Student</b><br>";
     }
     if ($bean->application_stage_c == 'stage_2') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         $body_stage1 = $bean->email_body_stage2_c;
         $mime_type = $bean->file_mime_type;
         $filename = "Application_Finance_Docs_Stage2_" . $application_name . ".zip";
         $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id;
         $subject = "SIEC Education: Financial Documents " . $bean->email_subject_c . " " . $application_name;
         $body = $body_stage1;
         $email = $bean->uni_email_save_c;
         //Create Object New email
         $emailObj = new Email();
         $defaults = $emailObj->getSystemDefaultEmail();
         $mail = new SugarPHPMailer();
         $mail->setMailerForSystem();
         $mail->From = $defaults['email'];
         $mail->FromName = $defaults['name'];
         $mail->Subject = $subject;
         $mail->Body = $body;
         $mail->prepForOutbound();
         $name_to = "University";
         $mail->AddCC($copy_to_email);
         $mail->AddAddress($email, $name_to);
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
         @$mail->Send();
         // Moving the file to the new location
         //Get a Unique No
         $unq_extension = uniqid();
         echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage2/financials/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         $bean->app_sent_to_uni_c = "2";
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Financials Forwarded to University" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
     if ($bean->application_stage_c == 'pendency_stage_2') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         $pendency_remark2 = $bean->pendency_stage_2_c;
         $pendency_subject2 = $bean->pendency_stage_2_subject_c;
         $bean->pendency_stage_2_dummy_c = "Pendency: " . $pendency_remark2;
         $bean->pendency_stage_2_subject_du_c = "Pendency (Stage 1): " . $pendency_subject2;
         // Update the application history
         $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> Application has pendency on Stage 1</b>: " . $pendency_subject2 . ": " . $pendency_remark2 . "<br>";
         // The notification gets sent to the counsellor as an email about the remark -<< done
         $bean->pendency_stage_2_c = "";
         // Clear the field
         $bean->pendency_stage_2_subject_c = "";
         // Clear the field
         // $bean->pendency_state_c = "1";
     }
     if ($bean->application_stage_c == 'pendency_stage_2_update_to_uni') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get Pendency remark at stage 1
         // Prevent the Application to be sent again.
         $subject_stage1 = "SIEC Education >> Pendency Update Financials " . $bean->email_subject_c . " " . $application_name;
         $body_stage1 = $bean->email_body_c;
         $mime_type = $bean->file_mime_type;
         $filename = "Pendency_Update_Stage1_" . $application_name . ".zip";
         $file_location = "/home/admin/web/siecindia.com/public_html/upload/" . $id;
         $subject = $subject_stage1;
         $body = $body_stage1;
         $email = $bean->uni_email_save_c;
         //Create Object New email
         $emailObj = new Email();
         $defaults = $emailObj->getSystemDefaultEmail();
         $mail = new SugarPHPMailer();
         $mail->setMailerForSystem();
         $mail->From = $defaults['email'];
         $mail->FromName = $defaults['name'];
         $mail->Subject = $subject;
         $mail->Body = $body;
         $mail->prepForOutbound();
         $name_to = "University";
         $mail->AddCC($copy_to_email);
         $mail->AddAddress($email, $name_to);
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
         @$mail->Send();
         // Moving the file to the new location
         //Get a Unique No
         $unq_extension = uniqid();
         echo $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/outbound/stage2/pendencies/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         // Sent Email
         //  $bean->app_sent_to_uni_c = "11";
         $bean->application_stage_history_c = $bean->application_stage_history_c . "</br>>> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\">Financial Pendency Updated to University: " . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
     if ($bean->application_stage_c == 'coe') {
         // Add remark box appears, remark to be added by application team -<< done
         // Get pendency remark at stage 1
         //Get the Extension
         //Get a Unique No
         $unq_extension = uniqid();
         $file_name = preg_replace('/[^A-Za-z0-9]/', '_', $application_name) . "_" . $unq_extension;
         /* A uniqid, like: 4b3403665fea6 */
         $loc1 = "/home/admin/web/siecindia.com/public_html/upload/" . $bean->id;
         $loc2 = "/home/admin/web/siecindia.com/public_html/custom/uploads/inbound/stage1/coe/" . $file_name . ".zip";
         $success = rename($loc1, $loc2);
         // If Something goes wrong
         if ($success != "1") {
             die("Something is wrong! Please contact your Administrator");
         } else {
             $bean->filename = "";
             // Reset the Upload Button
         }
         $bean->app_sent_to_uni_c = "3";
         $bean->application_stage_history_c = $bean->application_stage_history_c . ">>" . ">> <b style=\"color:red;\">Date:</b> " . $date . " <b style=\"color:red;\">Time:</b> " . $time . ">> <b style=\"color:blue;\"> COE Recieved" . " <a href=\\'" . $loc2 . "\\'>View File</a><br>";
     }
 }