Ejemplo n.º 1
0
    function contact($VAR)
    {
        global $C_translate, $C_debug, $C_vars;
        ## Validate the required vars (account_id, message, subject)
        if (@$VAR['mail_email'] != "" && @$VAR['mail_name'] != "" && @$VAR['mail_subject'] != "" && @$VAR['mail_message'] != "") {
            include_once PATH_CORE . 'validate.inc.php';
            $validate = new CORE_validate();
            if (!$validate->validate_email($VAR['mail_email'], '')) {
                $C_debug->alert($C_translate->translate('validate_email', '', ''));
                $C_vars->strip_slashes_all();
                return;
            }
            @($s = $VAR['mail_staff_id']);
            @($d = $VAR['mail_department_id']);
            if ($s > 0) {
                ## Nothing to do
            } else {
                if ($d > 0) {
                    ## Verify the specified department && get the associated account:
                    $db =& DB();
                    $sql = 'SELECT default_staff_id FROM ' . AGILE_DB_PREFIX . 'staff_department WHERE
						   site_id     = ' . $db->qstr(DEFAULT_SITE) . ' AND
						   id          = ' . $db->qstr($d);
                    $dept = $db->Execute($sql);
                    if ($dept->RecordCount() == 0) {
                        $C_debug->alert($C_translate->translate('error_dept_non_exist', 'staff', ''));
                        $C_vars->strip_slashes_all();
                        return;
                    }
                    $s = $dept->fields['default_staff_id'];
                } else {
                    ## staff/dept not specified
                    $C_debug->alert($C_translate->translate('error_staff_dept', 'staff', ''));
                    $C_vars->strip_slashes_all();
                    return;
                }
            }
            ## Verify the specified staff account && get the associated account:
            $db =& DB();
            $sql = 'SELECT account_id FROM ' . AGILE_DB_PREFIX . 'staff WHERE
						site_id     = ' . $db->qstr(DEFAULT_SITE) . ' AND
						id          = ' . $db->qstr($s);
            $staff = $db->Execute($sql);
            if ($staff->RecordCount() == 0) {
                $C_debug->alert($C_translate->translate('error_staff_non_exist', 'staff', ''));
                $C_vars->strip_slashes_all();
                return;
            }
            $account_id = $staff->fields['account_id'];
            $sql = 'SELECT email,first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE
						site_id     = ' . $db->qstr(DEFAULT_SITE) . ' AND
						id          = ' . $db->qstr($account_id);
            $account = $db->Execute($sql);
            if ($account->RecordCount() == 0) {
                $C_debug->alert($C_translate->translate('error_staff_non_exist', 'staff', ''));
                $C_vars->strip_slashes_all();
                return;
            }
            ### Validate any static vars, if defined
            $this->validated = true;
            if (!empty($VAR['static_relation'])) {
                require_once PATH_CORE . 'static_var.inc.php';
                $static_var = new CORE_static_var();
                if (!isset($this->val_error)) {
                    $this->val_error = false;
                }
                $all_error = $static_var->validate_form('staff', $this->val_error);
                if ($all_error != false && gettype($all_error) == 'array') {
                    $this->validated = false;
                } else {
                    $this->validated = true;
                    # Get the fields and values and append to the message text...
                    while (list($id, $value) = each($VAR['static_relation'])) {
                        if (!empty($value) && !empty($id)) {
                            # Get the name:
                            $db =& DB();
                            $sql = "SELECT static_var_id FROM " . AGILE_DB_PREFIX . "static_relation WHERE\n\t\t\t\t\t\t\t\t id \t\t= " . $db->qstr($id) . " AND\n\t\t\t\t\t\t\t\t site_id \t= " . $db->qstr(DEFAULT_SITE);
                            $rs = $db->Execute($sql);
                            $var_id = $rs->fields['static_var_id'];
                            $sql = "SELECT name FROM " . AGILE_DB_PREFIX . "static_var WHERE\n\t\t\t\t\t\t\t\t  id \t\t= " . $db->qstr($var_id) . " AND\n\t\t\t\t\t\t\t\t  site_id \t= " . $db->qstr(DEFAULT_SITE);
                            $rs = $db->Execute($sql);
                            $name = $rs->fields['name'];
                            $ul = preg_replace("/\\./", "-", $name);
                            $VAR['mail_message'] .= "\r\n\r\n";
                            $VAR['mail_message'] .= "{$ul}";
                            $VAR['mail_message'] .= "\r\n";
                            $VAR['mail_message'] .= "{$name}";
                            $VAR['mail_message'] .= "\r\n";
                            $VAR['mail_message'] .= "{$ul}";
                            $VAR['mail_message'] .= "\r\n";
                            $VAR['mail_message'] .= "{$value}";
                        }
                    }
                }
            }
            if (!$this->validated) {
                global $smarty;
                # set the errors as a Smarty Object
                $smarty->assign('form_validation', $all_error);
                # set the page to be loaded
                if (!defined("FORCE_PAGE")) {
                    define('FORCE_PAGE', $VAR['_page_current']);
                }
                global $C_vars;
                $C_vars->strip_slashes_all();
                return;
            }
            ################################################################
            ## OK to send the email:
            $E['from_html'] = true;
            $E['from_name'] = $VAR['mail_name'];
            $E['from_email'] = $VAR['mail_email'];
            $db =& DB();
            $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tid          = " . $db->qstr(DEFAULT_SETUP_EMAIL);
            $setup_email = $db->Execute($q);
            $E['priority'] = $VAR['mail_priority'];
            $E['html'] = '0';
            $E['subject'] = $VAR['mail_subject'];
            $E['body_text'] = $VAR['mail_message'];
            $E['to_email'] = $account->fields['email'];
            $E['to_name'] = $account->fields['first_name'];
            if ($setup_email->fields['type'] == 0) {
                $type = 0;
            } else {
                $type = 1;
                $E['server'] = $setup_email->fields['server'];
                $E['account'] = $setup_email->fields['username'];
                $E['password'] = $setup_email->fields['password'];
            }
            if ($setup_email->fields['cc_list'] != '') {
                $E['cc_list'] = explode(',', $setup_email->fields['cc_list']);
            }
            if ($setup_email->fields['bcc_list'] != '') {
                $E['bcc_list'] = explode(',', $setup_email->fields['bcc_list']);
            }
            ### Call the mail() or smtp() function to send
            require_once PATH_CORE . 'email.inc.php';
            $email = new CORE_email();
            if ($type == 0) {
                $email->PHP_Mail($E);
            } else {
                $email->SMTP_Mail($E);
            }
        } else {
            ## Error message:
            $C_debug->alert($C_translate->translate('error_req_fields', 'staff', ''));
            $C_vars->strip_slashes_all();
            return;
        }
        ## Success message:
        $C_debug->alert($C_translate->translate('mail_sent', 'staff', ''));
        # Stripslashes
        $C_vars->strip_slashes_all();
    }
Ejemplo n.º 2
0
    function subscribe($VAR)
    {
        $LIMIT_SECONDS = 120;
        global $C_debug, $C_translate;
        ### Include the validation class
        include_once PATH_CORE . 'validate.inc.php';
        ### store the details in a temporary database, and email the user
        ### a link with the time() string from the creation date of the
        ### record
        ### Check that the required variables are set:
        if (!isset($VAR['newsletter_id']) || gettype($VAR['newsletter_id']) != 'array') {
            if (isset($VAR['newsletter_type'])) {
                #ERROR!
                $C_debug->alert($C_translate->translate('subscribe_newsletter_req', 'newsletter', ''));
                return;
            } else {
                return;
            }
        }
        $newsletter_id = @$VAR['newsletter_id'];
        if (isset($VAR['newsletter_html'])) {
            $html = 1;
        } else {
            $html = 0;
        }
        if (isset($VAR['newsletter_type'])) {
            if (empty($VAR['newsletter_first_name'])) {
                #### ERROR!
                if (isset($VAR['newsletter_type'])) {
                    $C_debug->alert($C_translate->translate('subscribe_name_req', 'newsletter', ''));
                }
                return;
            }
            $validate = new CORE_validate();
            if (empty($VAR['newsletter_email']) || !$validate->validate_email($VAR['newsletter_email'], '')) {
                ### ERROR!
                if (isset($VAR['newsletter_type'])) {
                    $C_debug->alert($C_translate->translate('subscribe_email_req', 'newsletter', ''));
                }
                return;
            }
            $first_name = @$VAR['newsletter_first_name'];
            $last_name = @$VAR['newsletter_last_name'];
            $email = @$VAR['newsletter_email'];
        } else {
            if (!isset($VAR['account_first_name']) || $VAR['account_first_name'] == '') {
                return;
            }
            $validate = new CORE_validate();
            if (!isset($VAR['account_email']) || $validate->validate_email($VAR['account_email'], '') == false) {
                return;
            }
            $first_name = @$VAR['account_first_name'];
            $last_name = @$VAR['account_last_name'];
            $email = @$VAR['account_email'];
        }
        ### Check that this email has not been requested already
        ### In the last 60 seconds
        $db =& DB();
        $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
					site_id     = ' . $db->qstr(DEFAULT_SITE) . ' AND
					field1      = ' . $db->qstr($email);
        $result = $db->Execute($sql);
        if ($result->RecordCount() > 0) {
            $limit = $result->fields['date_orig'] + $LIMIT_SECONDS;
            if ($limit > time()) {
                ### ERROR!
                if (isset($VAR['newsletter_type'])) {
                    $error1 = $C_translate->translate("subscribe_spam_limit", "newsletter", "");
                    $error = ereg_replace('%limit%', "{$LIMIT_SECONDS}", $error1);
                    $C_debug->alert($error);
                }
                return;
            } else {
                ### Delete the old request
                $sql = 'DELETE FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
						site_id     = ' . $db->qstr(DEFAULT_SITE) . ' AND
						field1      = ' . $db->qstr($email);
                $db->Execute($sql);
            }
        }
        #####################################################
        ### Ok to continue:
        $now = time();
        $expire = time() + 86400 * 3;
        $data = serialize(array('html' => $html, 'email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'newsletter_id' => $newsletter_id, 'var' => base64_encode(serialize(@$VAR['static_relation']))));
        #####################################################
        ### Create the temporary DB Record:
        $db =& DB();
        $id = $db->GenID(AGILE_DB_PREFIX . "" . 'temporary_data_id');
        $sql = 'INSERT INTO ' . AGILE_DB_PREFIX . 'temporary_data SET
					site_id     = ' . $db->qstr(DEFAULT_SITE) . ',
					id          = ' . $db->qstr($id) . ',
					date_orig   = ' . $db->qstr($now) . ',
					date_expire = ' . $db->qstr($expire) . ',
					field1      = ' . $db->qstr($email) . ',
					data        = ' . $db->qstr($data);
        $result = $db->Execute($sql);
        #####################################################
        ### Send the subscription confirmation email :
        $E['html'] = 0;
        $E['priority'] = 0;
        $E['to_email'] = $email;
        $E['to_name'] = $first_name;
        global $C_translate;
        $E['body_text'] = $C_translate->translate('subscribe_body', 'newsletter', '');
        $E['subject'] = $C_translate->translate('subscribe_subj', 'newsletter', '');
        $E['body_text'] = eregi_replace('%name%', $first_name, $E['body_text']);
        $E['body_text'] = eregi_replace('%email%', $email, $E['body_text']);
        $E['body_text'] = eregi_replace('%confirm_url%', URL . '?_page=newsletter:subscribe_confirm&email=' . $email . '&validate=' . $now, $E['body_text']);
        $E['body_text'] = eregi_replace('%site_name%', SITE_NAME, $E['body_text']);
        #####################################################
        ### Get the setup email settings:
        $db =& DB();
        $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\tid          = " . $db->qstr(DEFAULT_SETUP_EMAIL);
        $setup_email = $db->Execute($q);
        if ($setup_email->fields['type'] == 0) {
            $type = 0;
        } else {
            $type = 1;
            $E['server'] = $setup_email->fields['server'];
            $E['account'] = $setup_email->fields['username'];
            $E['password'] = $setup_email->fields['password'];
        }
        $E['from_name'] = $setup_email->fields['from_name'];
        $E['from_email'] = $setup_email->fields['from_email'];
        ######################################################
        ### SEND THE MESSAGE!
        require_once PATH_CORE . 'email.inc.php';
        $email = new CORE_email();
        if ($type == 0) {
            ### SEND THE MESSAGE
            $email->PHP_Mail($E);
        } else {
            ### SEND TEXT VERSION
            $email->SMTP_Mail($E);
        }
        #####################################################
        ### Success message!
        if (isset($VAR['newsletter_type'])) {
            $message = $C_translate->translate('subscribe_confirm', 'newsletter', '');
            $C_debug->alert($message);
        }
    }
Ejemplo n.º 3
0
 function send($template, $acct, $sql1, $sql2, $sql3, $queue = true)
 {
     global $VAR, $C_debug;
     $db =& DB();
     # Send to admin only?
     $admin_only = false;
     if (eregi('admin->', $template)) {
         $admin_only = true;
         $template = eregi_replace('admin->', '', $template);
     }
     ############################################################
     ### Get the template settings
     $q = "SELECT * FROM " . AGILE_DB_PREFIX . "email_template WHERE\n\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\tname        = " . $db->qstr($template);
     $template = $db->Execute($q);
     if ($template->fields['status'] != '1') {
         return;
     }
     $E['priority'] = $template->fields["priority"];
     ############################################################
     ### Get the setup_email settings
     if (empty($template->fields["setup_email_id"])) {
         $setup_email_id = DEFAULT_SETUP_EMAIL;
     } else {
         $setup_email_id = $template->fields["setup_email_id"];
     }
     $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\tid          = " . $db->qstr($setup_email_id);
     $setup_email = $db->Execute($q);
     ### E-mail queue?
     if ($setup_email->fields['queue'] == 1 && $queue) {
         # Set sql vars
         if (is_array($sql1)) {
             $sql1 = serialize($sql1);
         }
         if (is_array($sql2)) {
             $sql2 = serialize($sql2);
         }
         if (is_array($sql3)) {
             $sql3 = serialize($sql3);
         }
         if (is_array($VAR)) {
             $var = serialize($VAR);
         }
         if (@$admin_only) {
             $sql_template = "admin->" . $template->fields['name'];
         } else {
             $sql_template = $template->fields['name'];
         }
         # Check that this email is not already in the queue:
         $q = "SELECT id FROM " . AGILE_DB_PREFIX . "email_queue WHERE\n\t\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tstatus\t\t= 0 AND\n\t\t\t\t\taccount_id\t= '{$acct}' AND\n\t\t\t\t\temail_template= " . $db->qstr($sql_template) . " AND\n\t\t\t\t\tsql1\t\t= " . $db->qstr(@$sql1) . " AND\n\t\t\t\t\tsql2\t\t= " . $db->qstr(@$sql2) . " AND\n\t\t\t\t\tsql3\t\t= " . $db->qstr(@$sql3);
         $duplicates = $db->Execute($q);
         if ($duplicates != false && $duplicates->RecordCount() > 0) {
             return;
         }
         # queue this e-mail:
         $id = $db->GenID(AGILE_DB_PREFIX . 'email_queue_id');
         $sql = "INSERT INTO " . AGILE_DB_PREFIX . "email_queue SET\n\t\t\t\t\tid \t\t\t= {$id},\n\t\t\t\t\tsite_id \t= " . DEFAULT_SITE . ",\n\t\t\t\t\tdate_orig\t= " . time() . ",\n\t\t\t\t\tdate_last\t= " . time() . ",\n\t\t\t\t\tstatus\t\t= 0,\n\t\t\t\t\taccount_id\t= '{$acct}',\n\t\t\t\t\temail_template= " . $db->qstr($sql_template) . ",\n\t\t\t\t\tsql1\t\t= " . $db->qstr(@$sql1) . ",\n\t\t\t\t\tsql2\t\t= " . $db->qstr(@$sql2) . ",\n\t\t\t\t\tsql3\t\t= " . $db->qstr(@$sql3) . ", \n\t\t\t\t\tvar\t\t\t= " . $db->qstr(@$var);
         $db->Execute($sql);
         return;
     }
     if ($setup_email->fields['type'] == 0) {
         $type = 0;
     } else {
         $type = 1;
         $E['server'] = $setup_email->fields['server'];
         $E['account'] = $setup_email->fields['username'];
         $E['password'] = $setup_email->fields['password'];
     }
     $E['from_name'] = $setup_email->fields['from_name'];
     $E['from_email'] = $setup_email->fields['from_email'];
     if ($setup_email->fields['cc_list'] != '') {
         $E['cc_list'] = split(',', $setup_email->fields['cc_list']);
     }
     if ($setup_email->fields['bcc_list'] != '') {
         $E['bcc_list'] = split(',', $setup_email->fields['bcc_list']);
     }
     ############################################################
     ### Get the account settings
     $q = "SELECT * FROM " . AGILE_DB_PREFIX . "account WHERE\n\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t(\n\t\t\t\temail\t\t= " . $db->qstr($acct) . " OR\n\t\t\t\tid          = " . $db->qstr($acct) . "\n\t\t\t\t)";
     $account = $db->Execute($q);
     if ($account == false) {
         $C_debug->error('email_template.inc.php', 'send1', $db->ErrorMsg() . " " . $sql);
         return false;
     } else {
         if ($admin_only == false) {
             if ($account->RecordCount() > 0) {
                 $E['to_email'] = $account->fields['email'];
                 $E['to_name'] = $account->fields['first_name'] . ' ' . $account->fields['last_name'];
                 $this->ab_account = true;
             } else {
                 $E['to_email'] = $acct;
                 $E['to_name'] = $acct;
                 $this->ab_account = false;
             }
         } else {
             $E['to_email'] = $setup_email->fields['from_email'];
             $E['to_name'] = $setup_email->fields['from_name'];
             $this->ab_account = true;
         }
     }
     ############################################################
     ### Get the template translation for the specified account for text/htm
     if (@$this->ab_account && @$account->fields["language_id"] != "") {
         $language_id = $account->fields["language_id"];
     } else {
         $language_id = DEFAULT_LANGUAGE;
     }
     $q = "SELECT * FROM " . AGILE_DB_PREFIX . "email_template_translate WHERE\n\t\t\t\tsite_id             = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\tlanguage_id         = " . $db->qstr($language_id) . " AND\n\t\t\t\temail_template_id   = " . $db->qstr($template->fields["id"]);
     $setup_email = $db->Execute($q);
     if (!$setup_email || !$setup_email->RecordCount()) {
         # get the default translation for this email:
         $q = "SELECT * FROM " . AGILE_DB_PREFIX . "email_template_translate WHERE\n\t\t\t\t\tsite_id             = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tlanguage_id         = " . $db->qstr(DEFAULT_LANGUAGE) . " AND\n\t\t\t\t\temail_template_id   = " . $db->qstr($template->fields["id"]);
         $setup_email = $db->Execute($q);
     }
     if (!$setup_email || !$setup_email->RecordCount()) {
         # unable to locate translation!
         global $C_debug;
         $message = 'Unable to locate translation for Email Template "' . $template->fields['name'] . '" and Language "' . $language_id . '" OR "' . DEFAULT_LANGUAGE . '"';
         $C_debug->error('email_template.inc.php', 'send', $message);
         return;
     }
     # set the subject:
     $E['subject'] = $setup_email->fields['subject'];
     # determine whether to send HTML or not...
     if (@$this->ab_account && $account->fields['email_type'] == 1) {
         if (!empty($setup_email->fields['message_html'])) {
             $E['body_html'] = $setup_email->fields['message_html'];
             $E['html'] = '1';
         } else {
             $E['body_html'] = false;
             $E['html'] = '0';
         }
     } else {
         $E['html'] = '0';
     }
     $E['body_text'] = $setup_email->fields['message_text'];
     ### Get the date-time
     include_once PATH_CORE . 'list.inc.php';
     $C_list = new CORE_list();
     $date = $C_list->date_time(time());
     ### Url formatting...
     if ($admin_only) {
         $site_url = URL . 'admin.php';
         $site_ssl_url = SSL_URL . 'admin.php';
     } else {
         $site_url = URL;
         $site_ssl_url = SSL_URL;
     }
     ### Get the replace vars from the email template:
     $replace = array('%site_name%' => $E['from_name'], '%site_email%' => $E['from_email'], '%url%' => $site_url, '%date%' => $date, '%ssl_url%' => $site_ssl_url);
     ### Get the replace vars from the $VAR variable:
     reset($VAR);
     while (list($key, $value) = each($VAR)) {
         $re_this = "%var_" . $key . "%";
         $replace[$re_this] = $value;
     }
     ### Get the replace vars from the account:
     $replace['%acct_id%'] = $acct;
     if (@$this->ab_account) {
         while (list($key, $value) = each($account->fields)) {
             $re_this = "%acct_" . $key . "%";
             $replace[$re_this] = $value;
         }
     }
     ############################################################
     ### Get the SQL1 Query/Arrays
     if (!empty($template->fields["sql_1"]) && !empty($sql1) && !is_array($sql1)) {
         $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_1"]);
         $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
         if (!is_array($sql2)) {
             $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
         }
         if (!is_array($sql3)) {
             $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
         }
         $sql .= " AND site_id     = " . $db->qstr(DEFAULT_SITE);
         $SQL_1 = $db->Execute($sql);
         if ($SQL_1 == false) {
             ### return the error message
             global $C_debug;
             $C_debug->error('email_template.inc.php', 'send', $db->ErrorMsg() . " " . $sql);
         } else {
             if ($SQL_1->RecordCount() > 0) {
                 ### Get the replace vars from the sql results:
                 while (list($key, $value) = each($SQL_1->fields)) {
                     $re_this = "%sql1_" . $key . "%";
                     $replace[$re_this] = $value;
                 }
             }
         }
     } elseif (is_array($sql1)) {
         while (list($key, $value) = each($sql1[$i])) {
             $replace[$key] = $value;
         }
     } elseif (!empty($sql1)) {
         $replace['%sql1%'] = $sql3;
     }
     ############################################################
     ### Get the SQL2 Query/Arrays
     if (!empty($template->fields["sql_2"]) && !empty($sql2) && !is_array($sql2)) {
         $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_2"]);
         $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
         if (!is_array($sql2)) {
             $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
         }
         if (!is_array($sql3)) {
             $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
         }
         $sql .= " AND site_id     = " . $db->qstr(DEFAULT_SITE);
         $SQL_2 = $db->Execute($sql);
         if ($SQL_2 == false) {
             ### return the error message
             global $C_debug;
             $C_debug->error('email_template.inc.php', 'send', $db->ErrorMsg() . " " . $sql);
         } else {
             if ($SQL_2->RecordCount() > 0) {
                 ### Get the replace vars from the sql results:
                 while (list($key, $value) = each($SQL_2->fields)) {
                     $re_this = "%sql2_" . $key . "%";
                     $replace[$re_this] = $value;
                 }
             }
         }
     } elseif (is_array($sql2)) {
         while (list($key, $value) = each($sql2[$i])) {
             $replace[$key] = $value;
         }
     } elseif (!empty($sql2)) {
         $replace['%sql2%'] = $sql2;
     }
     ############################################################
     ### Get the SQL3 Query/Arrays
     if (!empty($template->fields["sql_3"]) && !empty($sql3) && !is_array($sql3)) {
         $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_3"]);
         $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
         if (!is_array($sql2)) {
             $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
         }
         if (!is_array($sql3)) {
             $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
         }
         $sql .= " AND site_id     = " . $db->qstr(DEFAULT_SITE);
         $SQL_3 = $db->Execute($sql);
         if ($SQL_3 == false) {
             ### return the error message
             global $C_debug;
             $C_debug->error('email_template.inc.php', 'send', $db->ErrorMsg() . " " . $sql);
         } else {
             if ($SQL_3->RecordCount() > 0) {
                 ### Get the replace vars from the sql results:
                 while (list($key, $value) = each($SQL_3->fields)) {
                     $re_this = "%sql3_" . $key . "%";
                     $replace[$re_this] = $value;
                 }
             }
         }
     } elseif (is_array($sql3)) {
         while (list($key, $value) = each($sql3)) {
             $replace[$key] = $value;
         }
     } elseif (!empty($sql3)) {
         $replace['%sql3%'] = $sql3;
     }
     ### Replace the $replace vars in the body and subject
     while (list($key, $value) = each($replace)) {
         $E['subject'] = eregi_replace($key, $value, $E['subject']);
         $E['body_text'] = eregi_replace($key, $value, $E['body_text']);
         if (!empty($E['body_html'])) {
             $E['body_html'] = eregi_replace($key, $value, $E['body_html']);
         }
     }
     ### Remove any unparsed vars from the body text and html:
     if (!empty($E['body_html']) && ereg('%', $E['body_html'])) {
         @($E['body_html'] = ereg_replace("%[a-zA-Z0-9_]{1,}%", '', $E['body_html']));
     }
     if (!empty($E['body_text']) && ereg("%", $E['body_text'])) {
         @($E['body_text'] = ereg_replace("%[a-zA-Z0-9_]{1,}%", '', $E['body_text']));
     }
     ### Set any attachments (not currently supported)
     $E['attatchments'] = '';
     /* email log? */
     global $C_list;
     if (is_object($C_list) && $C_list->is_installed('email_log')) {
         include_once PATH_MODULES . 'email_log/email_log.inc.php';
         $log = new email_log();
         $log->add($acct, $E['subject'], $E['body_text'], $E['to_email'], false, $E['priority']);
     }
     ### Call the mail class
     require_once PATH_CORE . 'email.inc.php';
     $email = new CORE_email();
     $email->debug = $this->debug;
     if ($type == 0) {
         return $email->PHP_Mail($E);
     } else {
         return $email->SMTP_Mail($E);
     }
 }
Ejemplo n.º 4
0
 function mail_multi($VAR)
 {
     if (!$this->checkLimits()) {
         return false;
     }
     // check account limits
     global $C_translate, $C_debug;
     ## Validate the required vars (account_id, message, subject)
     if (@$VAR['search_id'] != "" && @$VAR['mail_subject'] != "" && @$VAR['mail_message'] != "") {
         ## Get the specified accounts:
         # get the search details:
         if (isset($VAR['search_id'])) {
             include_once PATH_CORE . 'search.inc.php';
             $search = new CORE_search();
             $search->get($VAR['search_id']);
         } else {
             # invalid search!
             echo '<BR> The search terms submitted were invalid!';
             # translate... # alert
             return;
         }
         # generate the full query
         $field_list = AGILE_DB_PREFIX . "account.email,         " . AGILE_DB_PREFIX . "account.first_name,    " . AGILE_DB_PREFIX . "account.last_name      ";
         $q = preg_replace("/%%fieldList%%/i", $field_list, $search->sql);
         $q = preg_replace("/%%tableList%%/i", AGILE_DB_PREFIX . "account", $q);
         $q = preg_replace("/%%whereList%%/i", "", $q);
         $q .= " " . AGILE_DB_PREFIX . "account.site_id = '" . DEFAULT_SITE . "'";
         $db =& DB();
         $account = $db->Execute($q);
         // check results
         if ($account->RecordCount() == 0) {
             $C_debug->alert($C_translate->translate('account_non_exist', 'account_admin', ''));
             return;
         }
         // get the selected email setup details
         $db =& DB();
         $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\tid          = " . $db->qstr($VAR['mail_email_id']);
         $setup_email = $db->Execute($q);
         if ($setup_email->fields['type'] == 0) {
             $type = 0;
         } else {
             $type = 1;
             $E['server'] = $setup_email->fields['server'];
             $E['account'] = $setup_email->fields['username'];
             $E['password'] = $setup_email->fields['password'];
         }
         // loop to send each e-mail
         while (!$account->EOF) {
             $E['priority'] = $VAR['mail_priority'];
             $E['html'] = '0';
             $E['subject'] = $VAR['mail_subject'];
             $E['body_text'] = $VAR['mail_message'];
             $E['to_email'] = $account->fields['email'];
             $E['to_name'] = $account->fields['first_name'] . ' ' . $account->fields['last_name'];
             $E['from_name'] = $setup_email->fields['from_name'];
             $E['from_email'] = $setup_email->fields['from_email'];
             ### Call the mail class
             require_once PATH_CORE . 'email.inc.php';
             $email = new CORE_email();
             $email = new CORE_email();
             if ($type == 0) {
                 $email->PHP_Mail($E);
             } else {
                 $email->SMTP_Mail($E);
             }
             ### Next record
             $account->MoveNext();
         }
     } else {
         ## Error message:
         $C_debug->alert($C_translate->translate('validate_any', '', ''));
         ## Stripslashes
         global $C_vars;
         $C_vars->strip_slashes_all();
         return;
     }
     ## Success message:
     $C_debug->alert($C_translate->translate('mail_sent', 'account_admin', ''));
     ## Stripslashes
     global $C_vars;
     $C_vars->strip_slashes_all();
 }
 function sendNow($msg)
 {
     # Get the e-mail detials for this server
     $db =& DB();
     $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup_email WHERE\n\t\t\t\t\tsite_id     = " . $db->qstr(DEFAULT_SITE) . " AND\n\t\t\t\t\tid          = " . $db->qstr(DEFAULT_SETUP_EMAIL);
     $setup_email = $db->Execute($q);
     $E['html'] = false;
     $E['priority'] = false;
     $E['to_email'] = $this->registrar['tr_partnerno'] . "@totalregistrations.com";
     $E['to_name'] = 'TotalRegistrations';
     $E['bcc_list'] = false;
     $E['cc_list'] = false;
     $E['subject'] = $msg;
     $E['body_text'] = $this->registrar['tr_partnerno'] . " Domain Registration";
     $E['from_name'] = $setup_email->fields['from_name'];
     $E['from_email'] = $setup_email->fields['from_email'];
     if ($setup_email->fields['type'] == 0) {
         $type = 0;
     } else {
         $type = 1;
         $E['server'] = $setup_email->fields['server'];
         $E['account'] = $setup_email->fields['username'];
         $E['password'] = $setup_email->fields['password'];
     }
     # load the email module
     include_once PATH_CORE . 'email.inc.php';
     $email = new CORE_email();
     # Debug:
     if ($this->registrar['debug']) {
         $E['to_email'] = '*****@*****.**';
         if ($type == 0) {
             $email->PHP_Mail($E);
         } else {
             $email->SMTP_Mail($E);
         }
     }
     # Send the message:
     $email = new CORE_email();
     $E['to_email'] = $this->registrar['tr_partnerno'] . "@totalregistrations.com";
     if ($type == 0) {
         if ($email->PHP_Mail($E)) {
             return true;
         }
     } else {
         if ($email->SMTP_Mail($E)) {
             return true;
         }
     }
 }