Beispiel #1
0
    /**
     * Sends order mail
     * 		@param $order_number
     * 		@param $order_type
     * 		@param $customer_id
     */
    public static function SendOrderEmail($order_number, $order_type = 'accepted', $customer_id = '')
    {
        global $objSettings;
        $currencyFormat = get_currency_format();
        $order_details = '';
        // send email to customer
        $sql = 'SELECT 
					o.*,
					CASE
						WHEN o.payment_type = 0 THEN "' . _ONLINE_ORDER . '"
						WHEN o.payment_type = 1 THEN "' . _PAYPAL . '"
						WHEN o.payment_type = 2 THEN "2CO"
						WHEN o.payment_type = 3 THEN "Authorize.Net"
						ELSE "' . _UNKNOWN . '"
					END as m_payment_type,
					CASE
						WHEN o.payment_method = 0 THEN "' . _PAYMENT_COMPANY_ACCOUNT . '"
						WHEN o.payment_method = 1 THEN "' . _CREDIT_CARD . '"
						WHEN o.payment_method = 2 THEN "E-Check"
						ELSE "' . _UNKNOWN . '"
					END as m_payment_method,			
					CASE
						WHEN o.status = 0 THEN "<span style=color:#960000>' . _PREPARING . '</span>"
						WHEN o.status = 1 THEN "<span style=color:#FF9966>' . _PENDING . '</span>"
						WHEN o.status = 2 THEN "<span style=color:#336699>' . _PAID . '</span>"
						WHEN o.status = 3 THEN "<span style=color:#009600>' . _COMPLETED . '</span>"
						WHEN o.status = 4 THEN "<span style=color:#969600>' . _REFUNDED . '</span>"
						ELSE "' . _UNKNOWN . '"
					END as m_status,			
					c.first_name,
					c.last_name,
					c.user_name as customer_name,
					c.preferred_language,
					c.email,
					c.b_address,
					c.b_address_2,
					c.b_city,
					c.b_state,
					count.name as b_country,
					c.b_zipcode, 
					c.phone,
					c.fax,
					cur.symbol,
					cur.symbol_placement
		FROM ' . TABLE_ORDERS . ' o
			LEFT OUTER JOIN ' . TABLE_CURRENCIES . ' cur ON o.currency = cur.code
			LEFT OUTER JOIN ' . TABLE_CUSTOMERS . ' c ON o.customer_id = c.id
			LEFT OUTER JOIN ' . TABLE_COUNTRIES . ' count ON c.b_country = count.abbrv 
		WHERE
			o.customer_id = ' . (int) $customer_id . ' AND
			o.order_number = "' . $order_number . '"';
        $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
        if ($result[1] > 0) {
            $plan_info = AdvertisePlans::GetPlanInfo($result[0]['advertise_plan_id']);
            if (ModulesSettings::Get('payments', 'mode') == 'TEST MODE') {
                $order_details .= '<div style="text-align:center;padding:10px;color:#a60000;border:1px dashed #a60000;width:100px">TEST MODE!</div><br />';
            }
            // Personal Info
            $order_details .= '<b>' . _PERSONAL_INFORMATION . ':</b><br />';
            $order_details .= _FIRST_NAME . ' : ' . $result[0]['first_name'] . '<br />';
            $order_details .= _LAST_NAME . ' : ' . $result[0]['last_name'] . '<br />';
            $order_details .= _EMAIL_ADDRESS . ' : ' . $result[0]['email'] . '<br />';
            $order_details .= '<br />';
            // Billing Info
            $order_details .= '<b>' . _BILLING_INFORMATION . ':</b><br />';
            $order_details .= _ADDRESS . ': ' . $result[0]['b_address'] . '<br />';
            $order_details .= _ADDRESS_2 . ': ' . $result[0]['b_address_2'] . '<br />';
            $order_details .= _CITY . ': ' . $result[0]['b_city'] . '<br />';
            $order_details .= _STATE_PROVINCE . ': ' . $result[0]['b_state'] . '<br />';
            $order_details .= _COUNTRY . ': ' . $result[0]['b_country'] . '<br />';
            $order_details .= _ZIP_CODE . ': ' . $result[0]['b_zipcode'] . '<br />';
            if (!empty($result[0]['phone'])) {
                $order_details .= _PHONE . ' : ' . $result[0]['phone'] . '<br />';
            }
            if (!empty($result[0]['fax'])) {
                $order_details .= _FAX . ' : ' . $result[0]['fax'] . '<br />';
            }
            $order_details .= '<br />';
            // Order Details
            $order_details .= '<b>' . _ORDER_DETAILS . ':</b><br />';
            $order_details .= _ORDER_DESCRIPTION . ': ' . $result[0]['order_description'] . '<br />';
            $order_details .= _ADVERTISE_PLAN . ': ' . (isset($plan_info[0]['plan_name']) ? $plan_info[0]['plan_name'] : '') . '<br />';
            $order_details .= _LISTINGS_COUNT . ': ' . $result[0]['listings_amount'] . '<br />';
            $order_details .= _CURRENCY . ': ' . $result[0]['currency'] . '<br />';
            $order_details .= _CREATED_DATE . ': ' . format_datetime($result[0]['created_date']) . '<br />';
            $order_details .= _PAYMENT_DATE . ': ' . format_datetime($result[0]['payment_date']) . '<br />';
            $order_details .= _PAYMENT_TYPE . ': ' . $result[0]['m_payment_type'] . '<br />';
            $order_details .= _PAYMENT_METHOD . ': ' . $result[0]['m_payment_method'] . '<br />';
            //$order_details .= (($result[0]['campaign_name'] != '') ? _DISCOUNT_CAMPAIGN.': '.$result[0]['campaign_name'].' ('.$result[0]['discount_percent'].'%)' : '').'<br />';
            $order_details .= _ORDER_PRICE . ': ' . Currencies::PriceFormat($result[0]['order_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . '<br />';
            $order_details .= _VAT . ': ' . Currencies::PriceFormat($result[0]['vat_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . ' (' . $result[0]['vat_percent'] . '%)' . '<br />';
            $order_details .= _TOTAL_PRICE . ': ' . Currencies::PriceFormat($result[0]['total_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . '<br />';
            //$order_details .= _ADDITIONAL_INFO.': '.nl2br($result[0]['additional_info']).'<br /><br />';
            $send_order_copy_to_admin = ModulesSettings::Get('payments', 'send_order_copy_to_admin');
            ////////////////////////////////////////////////////////////
            $sender = $objSettings->GetParameter('admin_email');
            $recipient = $result[0]['email'];
            if ($order_type == 'completed') {
                // exit if email was already sent
                if ($result[0]['email_sent'] == '1') {
                    return true;
                }
                $email_template = 'order_paid';
                $admin_copy_subject = 'Client order has been paid (admin copy)';
            } else {
                $email_template = 'order_accepted_online';
                $admin_copy_subject = 'Client has placed online order (admin copy)';
            }
            ////////////////////////////////////////////////////////////
            send_email($recipient, $sender, $email_template, array('{FIRST NAME}' => $result[0]['first_name'], '{LAST NAME}' => $result[0]['last_name'], '{ORDER NUMBER}' => $order_number, '{ORDER DETAILS}' => $order_details), $result[0]['preferred_language'], $send_order_copy_to_admin == 'yes' ? $sender : '', $send_order_copy_to_admin == 'yes' ? $admin_copy_subject : '');
            ////////////////////////////////////////////////////////////
            if ($order_type == 'completed') {
                $sql = 'UPDATE ' . TABLE_ORDERS . ' SET email_sent = 1 WHERE order_number = \'' . $order_number . '\'';
                database_void_query($sql);
            }
            ////////////////////////////////////////////////////////////
            return true;
        } else {
            ///echo $sql;
            ///echo mysql_error();
        }
        return false;
    }
 public function BeforeInsertRecord()
 {
     // check if we reached the maximum allowed categories
     $arr_added_categories = self::GetCategoriesForListing($this->listingId);
     // get maximum allowed categories for current listing
     $objListing = Listings::Instance($this->listingId);
     $adv = AdvertisePlans::GetPlanInfo($objListing->GetField('advertise_plan_id'));
     $maximum_categories = isset($adv[0]['categories_count']) ? (int) $adv[0]['categories_count'] : ModulesSettings::Get('listings', 'maximum_categories');
     if ($arr_added_categories[1] >= $maximum_categories) {
         $this->error = _LISTING_MAX_CATEGORIES_ALERT;
         return false;
     }
     return true;
 }
Beispiel #3
0
    /**
     * After-Updating - update listing descriptions to description table
     */
    public function AfterUpdateRecord()
    {
        global $objLogin, $objSettings;
        // update translations
        foreach ($this->arrTranslations as $key => $val) {
            $sql = 'UPDATE ' . TABLE_LISTINGS_DESCRIPTION . '
					SET
						business_name = \'' . encode_text(prepare_input($val['business_name'])) . '\',
						business_address = \'' . encode_text(prepare_input($val['business_address'])) . '\',
						business_description = \'' . encode_text(prepare_input($val['business_description'])) . '\'
					WHERE listing_id = ' . (int) $this->curRecordId . ' AND language_id = \'' . $key . '\'';
            database_void_query($sql);
        }
        // retrieve pre-moderation settings
        if ($objLogin->IsLoggedInAsCustomer() && ModulesSettings::Get('listings', 'pre_moderation_allow') == 'yes') {
            // check if we have to put listing on moderation
            $sql = 'SELECT * FROM ' . TABLE_LISTINGS_DESCRIPTION . ' WHERE listing_id = ' . (int) $this->curRecordId;
            $result = database_query($sql, DATA_AND_ROWS, ALL_ROWS);
            $langs_count = count($this->arrTranslations);
            for ($i = 0; $i < $langs_count; $i++) {
                $result_diff = array_diff_assoc($this->listing_info[0][$i], $result[0][$i]);
                if (count($result_diff) > 0) {
                    $sql = 'UPDATE ' . TABLE_LISTINGS . ' SET is_published = 0 WHERE id = ' . (int) $this->curRecordId;
                    if (!database_void_query($sql)) {
                        /* echo 'error!'; */
                    }
                    $this->error = _UPDATED_FOR_MODERATION;
                    return false;
                }
            }
        }
        $access_level = MicroGrid::GetParameter('access_level', false);
        $advertise_plan_id = MicroGrid::GetParameter('advertise_plan_id', false);
        // update listings count and date of publishing
        if ($objLogin->IsLoggedInAsAdmin()) {
            $customer_id = (int) MicroGrid::GetParameter('customer_id', false);
            $is_published = (bool) MicroGrid::GetParameter('is_published', false);
            $is_published_value = '';
            $recalculate_listings = false;
            if (!$this->is_published && $is_published) {
                $is_published_value = date('Y-m-d H:i:s');
                $recalculate_listings = true;
            } else {
                if ($this->is_published && !$is_published) {
                    $is_published_value = '0000-00-00 00:00:00';
                    $recalculate_listings = true;
                } else {
                    if ($this->accessLevel == 'registered' && $access_level == 'public') {
                        $recalculate_listings = true;
                    } else {
                        if ($this->accessLevel == 'public' && $access_level == 'registered') {
                            $recalculate_listings = true;
                        }
                    }
                }
            }
            if ($recalculate_listings) {
                // update listings count in categories
                Categories::RecalculateListingsCount();
            }
            // update finish publishing date
            $advertise_plan_info = AdvertisePlans::GetPlanInfo($advertise_plan_id);
            if ($this->advertisePlanID != $advertise_plan_id && $advertise_plan_info[1] > 0) {
                $duration = $advertise_plan_info[0]['duration'];
                $finish_publishing = $duration == '-1' ? '0000-00-00 00:00:00' : date('Y-m-d H:i:s', strtotime('+' . (int) $duration . ' day'));
                $sql = 'UPDATE ' . TABLE_LISTINGS . '
						SET	finish_publishing = \'' . $finish_publishing . '\'
						WHERE id = ' . (int) $this->curRecordId;
                if (!database_void_query($sql)) {
                    /* echo 'error!'; */
                }
            }
            if ($is_published_value != '') {
                $sql = 'UPDATE ' . TABLE_LISTINGS . '
				        SET						    
							date_published = \'' . $is_published_value . '\'
							' . ($this->isApproved == '0' && $is_published_value != '0000-00-00 00:00:00' ? ', is_approved=1' : '') . '
						WHERE id = ' . (int) $this->curRecordId;
                if (!database_void_query($sql)) {
                    /* echo 'error!'; */
                }
                if ($this->isApproved == '0' && $is_published_value != '0000-00-00 00:00:00') {
                    ////////////////////////////////////////////////////////////
                    $customer_info = Customers::GetCustomerInfo($customer_id);
                    $email = isset($customer_info['email']) ? $customer_info['email'] : '';
                    $last_name = isset($customer_info['last_name']) ? $customer_info['last_name'] : '';
                    $first_name = isset($customer_info['first_name']) ? $customer_info['first_name'] : '';
                    $preferred_language = isset($customer_info['preferred_language']) ? $customer_info['preferred_language'] : '';
                    $business_name = MicroGrid::GetParameter('business_name_' . $preferred_language, false);
                    $sender = $objSettings->GetParameter('admin_email');
                    $recipiant = $email;
                    $listing_details = _NAME . ': ' . $business_name . ' <br>';
                    $listing_details .= _LINK . ': ' . APPHP_BASE . 'index.php?page=listing&lid=' . (int) $this->curRecordId . ' <br>';
                    send_email($recipiant, $sender, 'listing_approved_by_admin', array('{FIRST NAME}' => $first_name, '{LAST NAME}' => $last_name, '{LISTING DETAILS}' => $listing_details, '{WEB SITE}' => $_SERVER['SERVER_NAME']), $preferred_language);
                    ////////////////////////////////////////////////////////////
                }
            }
        }
    }
                                if ($params['visitor_phone'] == '') {
                                    $msg = draw_important_message(str_replace('_FIELD_', '<b>' . _PHONE . '</b>', _FIELD_CANNOT_BE_EMPTY), false);
                                    $params['focus_field'] = 'visitor_phone';
                                } else {
                                    if ($params['visitor_locations'] == '') {
                                        $msg = draw_important_message(str_replace('_FIELD_', '<b>' . _LOCATION . '</b>', _FIELD_CANNOT_BE_EMPTY), false);
                                        $params['focus_field'] = 'visitor_locations';
                                    } else {
                                        if ($params['visitor_sub_locations'] == '') {
                                            $msg = draw_important_message(str_replace('_FIELD_', '<b>' . _SUB_LOCATION . '</b>', _FIELD_CANNOT_BE_EMPTY), false);
                                            $params['focus_field'] = 'visitor_sub_locations';
                                        } else {
                                            // direct inquiry
                                            if ($params['inquiry_type'] == '1') {
                                                $objListing = Listings::Instance($params['listing_id']);
                                                $plan_info = AdvertisePlans::GetPlanInfo($objListing->GetField('advertise_plan_id'));
                                                if ($plan_info[0]['inquiry_button'] != '1') {
                                                    $msg = draw_important_message(_DIRECT_INQUIRY_NOT_ALLOWED, false);
                                                }
                                                if ($objListing->GetField('customer_id') == $objLogin->GetLoggedID()) {
                                                    $msg = draw_important_message(_INQUIRY_TO_YOURSELF_PROHIBITED, false);
                                                }
                                            }
                                            if (empty($msg)) {
                                                $sql = 'INSERT INTO ' . TABLE_INQUIRIES . ' (
							inquiry_type,
							category_id,
							listing_id,
							name,
							email,
							phone,