예제 #1
0
    private function __construct_all()
    {
        global $objLogin;
        $this->params = array();
        if (isset($_POST['website_url'])) {
            $website_url = prepare_input($_POST['website_url'], false, 'medium');
            if (preg_match('/www./i', $website_url) && !preg_match('/http:/i', $website_url)) {
                $website_url = 'http://' . $website_url;
            }
            $this->params['website_url'] = $website_url;
        }
        if (isset($_POST['listing_location_id'])) {
            $this->params['listing_location_id'] = prepare_input($_POST['listing_location_id']);
        }
        if (isset($_POST['listing_sub_location_id'])) {
            $this->params['listing_sub_location_id'] = prepare_input($_POST['listing_sub_location_id']);
        }
        if (isset($_POST['business_email'])) {
            $this->params['business_email'] = prepare_input($_POST['business_email']);
        }
        if (isset($_POST['business_phone'])) {
            $this->params['business_phone'] = prepare_input($_POST['business_phone']);
        }
        if (isset($_POST['business_fax'])) {
            $this->params['business_fax'] = prepare_input($_POST['business_fax']);
        }
        if (isset($_POST['priority_order'])) {
            $this->params['priority_order'] = prepare_input($_POST['priority_order']);
        }
        if (isset($_POST['is_featured'])) {
            $this->params['is_featured'] = (int) $_POST['is_featured'];
        } else {
            $this->params['is_featured'] = '0';
        }
        if (isset($_POST['is_published'])) {
            $this->params['is_published'] = (int) $_POST['is_published'];
        } else {
            $this->params['is_published'] = '0';
        }
        if (isset($_POST['is_approved'])) {
            $this->params['is_approved'] = prepare_input($_POST['is_approved']);
        }
        if (isset($_POST['access_level'])) {
            $this->params['access_level'] = prepare_input($_POST['access_level']);
        }
        if (isset($_POST['date_published'])) {
            $this->params['date_published'] = prepare_input($_POST['date_published']);
        }
        if (isset($_POST['customer_id'])) {
            $this->params['customer_id'] = (int) $_POST['customer_id'];
        }
        if (isset($_POST['map_code'])) {
            $this->params['map_code'] = prepare_input($_POST['map_code'], false, 'low');
        }
        if (isset($_POST['video_url'])) {
            $this->params['video_url'] = prepare_input($_POST['video_url'], false, 'low');
        }
        if (isset($_POST['keywords'])) {
            $this->params['keywords'] = implode(',', array_map('trim', explode(',', prepare_input($_POST['keywords']))));
        }
        if (isset($_POST['advertise_plan_id'])) {
            $this->params['advertise_plan_id'] = prepare_input($_POST['advertise_plan_id']);
        }
        ///$this->params['language_id'] 	= MicroGrid::GetParameter('language_id');
        $rid = MicroGrid::GetParameter('rid');
        $action = MicroGrid::GetParameter('action');
        $operation = MicroGrid::GetParameter('operation');
        $filter_by_cid = MicroGrid::GetParameter('filter_by_cid', false);
        $payments_module = Modules::IsModuleInstalled('payments') && ModulesSettings::Get('payments', 'is_active') == 'yes' ? true : false;
        $watermark = ModulesSettings::Get('listings', 'watermark') == 'yes' ? true : false;
        $watermark_text = ModulesSettings::Get('listings', 'watermark_text');
        if ($action != 'view') {
            $listings_info = self::GetListingInfo($rid);
        }
        ## for images
        if (isset($_POST['image_file'])) {
            $this->params['image_file'] = prepare_input($_POST['image_file']);
        } else {
            if (isset($_FILES['image_file']['name']) && $_FILES['image_file']['name'] != '') {
                // nothing
            } else {
                if (self::GetParameter('action') == 'create') {
                    $this->params['image_file'] = '';
                }
            }
        }
        if ($payments_module) {
            $listings_count = $objLogin->GetAvailableListings();
        } else {
            $listings_count = -1;
        }
        $this->primaryKey = 'id';
        $this->tableName = TABLE_LISTINGS;
        $this->dataSet = array();
        $this->error = '';
        $this->formActionURL = 'index.php?' . ($objLogin->GetLoggedType() == 'customer' ? 'customer=my_listings' : 'admin=mod_listings_management');
        $categoriesActionURL = 'index.php?' . ($objLogin->GetLoggedType() == 'customer' ? 'customer=listings_categories' : 'admin=mod_listings_categories');
        $this->actions = array('add' => $objLogin->GetLoggedType() == 'customer' && $listings_count == 0 ? false : true, 'edit' => true, 'details' => true, 'delete' => true);
        $this->actionIcons = true;
        $this->allowRefresh = true;
        $this->allowTopButtons = true;
        $this->advertisePlanID = '0';
        $this->accessLevel = '';
        $this->isApproved = 0;
        $this->allowLanguages = false;
        //$this->languageId  	=  '';
        $default_lang = $objLogin->GetLoggedType() == 'customer' ? Languages::GetDefaultLang() : $objLogin->GetPreferredLang();
        $is_expired = false;
        if ($action == 'edit' && $action == 'details') {
            $is_expired = $listings_info['finish_publishing'] == '0000-00-00 00:00:00' || $listings_info['finish_publishing'] > date('Y-m-d H:i:s') ? false : true;
        }
        $this->WHERE_CLAUSE = 'WHERE ld.language_id = \'' . $default_lang . '\'';
        if ($operation != 'reset_filtering' && !empty($filter_by_cid)) {
            $this->WHERE_CLAUSE .= ' AND l.id IN (SELECT lc.listing_id FROM ' . TABLE_LISTINGS_CATEGORIES . ' lc WHERE lc.category_id = ' . (int) $filter_by_cid . ')';
        }
        $this->ORDER_CLAUSE = 'ORDER BY l.date_published ASC';
        $this->isAlterColorsAllowed = true;
        $this->isPagingAllowed = true;
        $this->pageSize = 20;
        $this->isSortingAllowed = true;
        $this->isExportingAllowed = $objLogin->IsLoggedInAsAdmin() ? true : false;
        $this->arrExportingTypes = array('csv' => true);
        // prepare access levels array
        $arr_access_levels = array('public' => _PUBLIC, 'registered' => _REGISTERED);
        // prepare featured array
        $arr_featured = array('0' => _NO, '1' => _YES);
        // prepare published array
        $arr_published = array('0' => _NO, '1' => _YES);
        // prepare advertise plans array
        $arr_advertise_plans = array();
        $total_plans = AdvertisePlans::GetAllPlans();
        foreach ($total_plans[0] as $key => $val) {
            $arr_advertise_plans[$val['id']] = $val['plan_name'];
        }
        if ($payments_module) {
            $arr_customer_advertise_plans = array();
            if ($objLogin->IsLoggedInAsCustomer()) {
                $plans = $objLogin->GetCustomerPlans();
                foreach ($plans as $key => $val) {
                    $arr_customer_advertise_plans[$val['id']] = $val['name'] . ' (' . $val['count'] . ' ' . _LISTINGS . ')';
                }
            }
        }
        // prepare categories array
        $objCategories = Categories::Instance();
        $total_categories = $objCategories->GetAllExistingCategories();
        $arr_categories = array();
        foreach ($total_categories as $key => $val) {
            if ($val['level'] == '1') {
                $arr_categories[$val['id']] = $val['name'];
            } else {
                if ($val['level'] == '2') {
                    $arr_categories[$val['id']] = '  • ' . $val['name'];
                } else {
                    if ($val['level'] == '3') {
                        $arr_categories[$val['id']] = '    :: ' . $val['name'];
                    }
                }
            }
        }
        $datetime_format = get_datetime_format();
        $date_format = get_date_format();
        $arr_locations = array();
        $arr_sub_locations = array();
        if ($action != 'view') {
            // prepare array for location
            $total_locations = ListingsLocations::GetAllLocations('name ASC');
            foreach ($total_locations[0] as $key => $val) {
                $arr_locations[$val['id']] = $val['name'];
            }
            if ($action != 'edit' && $action != 'details') {
                // prepare array for sub-location
                $listing_location_id = (int) MicroGrid::GetParameter('listing_location_id', false);
                $total_sub_locations = ListingsSubLocations::GetAllSubLocations($listing_location_id, 'name ASC');
                foreach ($total_sub_locations[0] as $key => $val) {
                    $arr_sub_locations[$val['id']] = $val['name'];
                }
            }
        }
        // define filtering fields
        $this->isFilteringAllowed = true;
        $this->arrFilteringFields = array(_NAME => array('table' => 'ld', 'field' => 'business_name', 'type' => 'text', 'sign' => 'like%', 'width' => '110px'), _CATEGORY => array('table' => 'c', 'field' => 'id', 'type' => 'dropdownlist', 'source' => $arr_categories, 'sign' => '=', 'width' => '', 'visible' => $objLogin->IsLoggedInAsAdmin() ? true : false, 'custom_handler' => true), _FEATURED => array('table' => 'l', 'field' => 'is_featured', 'type' => 'dropdownlist', 'source' => $arr_featured, 'sign' => '=', 'width' => '', 'visible' => $objLogin->IsLoggedInAsAdmin() ? true : false), _PUBLISHED => array('table' => 'l', 'field' => 'is_published', 'type' => 'dropdownlist', 'source' => $arr_published, 'sign' => '=', 'width' => ''));
        // retrieve pre-moderation settings
        $pre_moderation_allow = ModulesSettings::Get('listings', 'pre_moderation_allow') == 'yes' ? true : false;
        ///////////////////////////////////////////////////////////////////////////////
        // 1. prepare translation fields array
        $this->arrTranslations = $this->PrepareTranslateFields(array('business_name', 'business_address', 'business_description'));
        ///////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////
        // 2. prepare translations array for edit/detail modes
        $sql_translation_description = $this->PrepareTranslateSql(TABLE_LISTINGS_DESCRIPTION, 'listing_id', array('business_name', 'business_address', 'business_description'));
        ///////////////////////////////////////////////////////////////////////////////
        // retrieve default priority order for new record
        $default_priority_order = '';
        if (self::GetParameter('action') == 'add') {
            $default_priority_order = $this->GetMaxOrder('priority_order', 9999);
        }
        // get plan features
        $advertise_plan_id = '';
        if ($action == 'add' || $action == 'create') {
            $advertise_plan_id = MicroGrid::GetParameter('advertise_plan_id', false);
        } else {
            if (in_array($action, array('details', 'edit', 'update'))) {
                // 1st time
                if (MicroGrid::GetParameter('advertise_plan_id', false)) {
                    $advertise_plan_id = MicroGrid::GetParameter('advertise_plan_id', false);
                } else {
                    $advertise_plan_id = $listings_info['advertise_plan_id'];
                }
            }
        }
        if (empty($advertise_plan_id)) {
            $advertise_plan_id = 1;
        }
        $advertise_plan_info = AdvertisePlans::GetPlanInfo($advertise_plan_id);
        // print_r($advertise_plan_info);
        $bpf_business_name = $advertise_plan_info[0]['business_name'];
        $bpf_business_description = $advertise_plan_info[0]['business_description'];
        $bpf_address = $advertise_plan_info[0]['address'];
        $bpf_logo = $advertise_plan_info[0]['logo'];
        $bpf_images_count = $advertise_plan_info[0]['images_count'];
        $bpf_phone = $advertise_plan_info[0]['phone'];
        $bpf_map = $advertise_plan_info[0]['map'];
        $bpf_video_link = $advertise_plan_info[0]['video_link'];
        $this->bpf_keywords_count = (int) $advertise_plan_info[0]['keywords_count'];
        // not needed to be inserted: inquiries_count, inquiries_count/per month, rating_button
        //----------------------------------------------------------------------
        // VIEW MODE
        //----------------------------------------------------------------------
        $this->VIEW_MODE_SQL = 'SELECT l.' . $this->primaryKey . ',
		                            l.customer_id,
									l.image_file,
									l.image_file_thumb,
									l.website_url,
									l.business_email,
									l.business_phone,
									l.business_fax,
									l.priority_order,
									l.access_level,
									l.is_featured,
									l.advertise_plan_id,
									IF(
										l.finish_publishing = "0000-00-00 00:00:00",
										"- ' . _NEVER . ' -",
										IF(l.finish_publishing < \'' . date('Y-m-d H:i:s') . '\', "<span class=no>' . _EXPIRED . '</span>", l.finish_publishing)
									) as finish_publishing,
									CONCAT("<img src=\\"images/", IF(l.is_published, "published_g.gif", "published_x.gif"), "\\" alt=\\"\\" />") as mod_is_published,
									CONCAT("<img src=\\"images/", IF(l.is_approved, "published_g.gif", "waiting.gif"), "\\" alt=\\"\\" />") as mod_is_approved,
									ld.business_name,
									IF(l.customer_id = 0, \'Admin\', cust.user_name) as customer_username,
									CONCAT("[ ' . _CATEGORIES . ' ]", " (", (SELECT COUNT(*) FROM ' . TABLE_LISTINGS_CATEGORIES . ' lc WHERE lc.listing_id = l.id), ")") as link_categories
								FROM ' . $this->tableName . ' l
								    ' . ($objLogin->GetLoggedType() == 'customer' ? 'INNER JOIN ' . TABLE_CUSTOMERS . ' cust ON (l.customer_id = cust.id AND l.customer_id=' . (int) $objLogin->GetLoggedID() . ')' : 'LEFT OUTER JOIN ' . TABLE_CUSTOMERS . ' cust ON (l.customer_id = cust.id)') . '
									LEFT OUTER JOIN ' . TABLE_LISTINGS_DESCRIPTION . ' ld ON (l.id = ld.listing_id AND ld.language_id = \'' . $default_lang . '\')';
        // define view mode fields
        $this->arrViewModeFields = array('image_file_thumb' => array('title' => _IMAGE, 'type' => 'image', 'sortable' => false, 'align' => 'left', 'width' => '64px', 'image_width' => '50px', 'image_height' => '30px', 'target' => 'images/listings/', 'no_image' => 'no_image.png'), 'business_name' => array('title' => _NAME, 'type' => $objLogin->GetLoggedType() == 'customer' ? 'link' : 'label', 'align' => 'left', 'width' => '200px', 'sortable' => true, 'nowrap' => '', 'visible' => true, 'tooltip' => '', 'maxlength' => '45', 'format' => '', 'format_parameter' => '', 'href' => 'index.php?page=listing&lid={id}', 'target' => '_new'), 'advertise_plan_id' => array('title' => _ADVERTISE_PLAN, 'type' => 'enum', 'align' => 'center', 'width' => '90px', 'sortable' => true, 'nowrap' => '', 'visible' => true, 'source' => $arr_advertise_plans), 'customer_username' => array('title' => _CUSTOMER, 'type' => 'label', 'align' => 'center', 'width' => '', 'visible' => $objLogin->IsLoggedInAsAdmin() ? true : false), 'access_level' => array('title' => _ACCESS, 'type' => 'enum', 'align' => 'center', 'width' => '70px', 'sortable' => true, 'nowrap' => '', 'source' => $arr_access_levels, 'visible' => $objLogin->IsLoggedInAsAdmin() ? true : false), 'mod_is_published' => array('title' => _PUBLISHED, 'type' => 'label', 'align' => 'center', 'width' => '70px', 'visible' => $objLogin->IsLoggedInAsAdmin()), 'mod_is_approved' => array('title' => _STATUS, 'type' => 'label', 'align' => 'center', 'width' => '80px', 'visible' => $objLogin->IsLoggedInAsCustomer()), 'finish_publishing' => array('title' => _FINISH_PUBLISHING, 'type' => 'label', 'align' => 'center', 'width' => '90px', 'sortable' => true, 'nowrap' => '', 'visible' => true, 'tooltip' => '', 'maxlength' => '', 'format' => 'date', 'format_parameter' => $date_format), 'link_categories' => array('title' => '', 'type' => 'link', 'align' => 'center', 'width' => '115px', 'sortable' => true, 'nowrap' => '', 'visible' => '', 'tooltip' => '', 'maxlength' => '', 'format' => '', 'format_parameter' => '', 'href' => $categoriesActionURL . '&listing_id={id}', 'target' => ''), 'priority_order' => array('title' => _ORDER, 'type' => 'label', 'align' => 'center', 'width' => '60px', 'movable' => true, 'visible' => $objLogin->IsLoggedInAsAdmin() ? true : false), 'id' => array('title' => 'ID', 'type' => 'label', 'align' => 'center', 'width' => '50px'));
        //----------------------------------------------------------------------
        // ADD MODE
        //----------------------------------------------------------------------
        // define add mode fields
        $this->arrAddModeFields = array('separator_general' => array('separator_info' => array('legend' => _GENERAL), 'advertise_plan_id' => array('title' => _ADVERTISE_PLAN, 'type' => 'enum', 'width' => '', 'required' => true, 'readonly' => false, 'default' => '', 'source' => $objLogin->IsLoggedInAsAdmin() ? $arr_advertise_plans : $arr_customer_advertise_plans, 'default_option' => '', 'unique' => false, 'javascript_event' => 'onchange="appChangePlan(\'' . $this->tableName . '\')"', 'visible' => $payments_module), 'listing_location_id' => array('title' => _LOCATION, 'type' => 'enum', 'width' => '', 'source' => $arr_locations, 'required' => true, 'default' => '', 'javascript_event' => 'onchange="appRefillLocations(\'' . $this->tableName . '\')"'), 'listing_sub_location_id' => array('title' => _SUB_LOCATION, 'type' => 'enum', 'width' => '', 'source' => $arr_sub_locations, 'required' => true, 'default' => ''), 'website_url' => array('title' => _WEBSITE_URL . ' (http://)', 'type' => 'textbox', 'width' => '270px', 'required' => false, 'readonly' => false, 'validation_type' => 'text', 'maxlength' => '255'), 'business_email' => array('title' => _EMAIL_ADDRESS, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => 'email', 'maxlength' => '75'), 'date_published' => array('title' => '', 'type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => $pre_moderation_allow && $objLogin->GetLoggedType() == 'customer' ? '0000-00-00 00:00:00' : date('Y-m-d H:i:s')), 'customer_id' => array('title' => '', 'type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => $objLogin->GetLoggedType() == 'customer' ? $objLogin->GetLoggedID() : '0')));
        if ($bpf_phone) {
            $this->arrAddModeFields['separator_general']['business_phone'] = array('title' => _PHONE, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
            $this->arrAddModeFields['separator_general']['business_fax'] = array('title' => _FAX, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
        }
        if ($bpf_video_link) {
            $this->arrAddModeFields['separator_general']['video_url'] = array('title' => _VIDEO, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
        }
        if ($this->bpf_keywords_count) {
            $this->arrAddModeFields['separator_general']['keywords'] = array('title' => _KEYWORDS, 'type' => 'textarea', 'required' => false, 'width' => '480px', 'height' => '58px', 'editor_type' => 'simple', 'readonly' => false, 'default' => '', 'validation_type' => '', 'validation_maxlength' => '1024', 'unique' => false);
        } else {
            $this->arrAddModeFields['separator_general']['keywords'] = array('title' => '', 'type' => 'hidden', 'required' => false, 'readonly' => false, 'default' => '');
        }
        if ($bpf_logo) {
            $this->arrAddModeFields['separator_gallery']['separator_info'] = array('legend' => _GALLERY);
            $this->arrAddModeFields['separator_gallery']['image_file'] = array('title' => _LOGO, 'type' => 'image', 'width' => '210px', 'required' => false, 'readonly' => false, 'target' => 'images/listings/', 'no_image' => '', 'image_width' => '150px', 'image_height' => '120px', 'random_name' => 'true', 'unique' => false, 'thumbnail_create' => true, 'thumbnail_field' => 'image_file_thumb', 'thumbnail_width' => '150px', 'thumbnail_height' => '120px', 'file_maxsize' => '200k');
            for ($i = 1; $i <= $bpf_images_count; $i++) {
                $this->arrAddModeFields['separator_gallery']['image_' . $i] = array('title' => _IMAGE . ' #' . $i, 'type' => 'image', 'width' => '210px', 'required' => false, 'readonly' => false, 'target' => 'images/listings/', 'no_image' => '', 'image_width' => '150px', 'image_height' => '120px', 'random_name' => 'true', 'unique' => false, 'thumbnail_create' => true, 'thumbnail_field' => 'image_' . $i . '_thumb', 'thumbnail_width' => '150px', 'thumbnail_height' => '120px', 'file_maxsize' => '500k', 'watermark' => $watermark, 'watermark_text' => $watermark_text);
            }
        }
        if ($bpf_map) {
            $this->arrAddModeFields['separator_map']['separator_info'] = array('legend' => _MAP_CODE);
            $this->arrAddModeFields['separator_map']['map_code'] = array('title' => _MAP_CODE, 'type' => 'textarea', 'required' => false, 'width' => '480px', 'height' => '100px', 'editor_type' => 'simple', 'readonly' => false, 'default' => '', 'validation_type' => '', 'validation_maxlength' => '1024', 'unique' => false);
        } else {
            $this->arrAddModeFields['separator_general']['map_code'] = array('title' => '', 'type' => 'hidden', 'required' => false, 'readonly' => false, 'default' => '');
        }
        if ($objLogin->IsLoggedInAsAdmin()) {
            $this->arrAddModeFields['separator_general']['is_published'] = array('title' => _PUBLISHED, 'type' => 'checkbox', 'readonly' => false, 'default' => '1', 'true_value' => '1', 'false_value' => '0');
            $this->arrAddModeFields['separator_general']['is_approved'] = array('title' => '', 'type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '1');
            $this->arrAddModeFields['separator_general']['priority_order'] = array('title' => _ORDER, 'type' => 'textbox', 'width' => '50px', 'required' => true, 'default' => $default_priority_order, 'readonly' => false, 'validation_type' => 'numeric|positive', 'maxlength' => '4');
            $this->arrAddModeFields['separator_general']['is_featured'] = array('title' => _FEATURED, 'type' => 'checkbox', 'readonly' => false, 'default' => '1', 'true_value' => '1', 'false_value' => '0');
            $this->arrAddModeFields['separator_general']['access_level'] = array('title' => _ACCESSIBLE_BY, 'type' => 'enum', 'width' => '', 'required' => true, 'readonly' => false, 'default' => 'public', 'source' => $arr_access_levels, 'default_option' => '', 'unique' => false, 'javascript_event' => '');
        } else {
            if ($pre_moderation_allow) {
                $this->arrAddModeFields['separator_general']['is_published'] = array('type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '0');
                $this->arrAddModeFields['separator_general']['is_approved'] = array('type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '0');
                $this->arrAddModeFields['separator_general']['access_level'] = array('type' => 'hidden', 'required' => true, 'default' => 'public');
            } else {
                $this->arrAddModeFields['separator_general']['is_published'] = array('type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '1');
                $this->arrAddModeFields['separator_general']['is_approved'] = array('type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '1');
            }
        }
        //----------------------------------------------------------------------
        // EDIT MODE
        //----------------------------------------------------------------------
        // define edit mode fields
        $this->EDIT_MODE_SQL = 'SELECT
								l.*,
								' . $sql_translation_description . '
								IF(
									l.finish_publishing = \'0000-00-00 00:00:00\',
									"- ' . _NEVER . ' -",
									IF(l.finish_publishing < \'' . date('Y-m-d H:i:s') . '\', \'<span class=no>' . _EXPIRED . '</span>\', l.finish_publishing)
								) as finish_publishing,								
								CONCAT("<img src=\\"images/listings/", l.image_file_thumb, "\\" alt=\\"\\" width=\\"40px\\ height=\\"30px\\" />") as my_image_file,
								IF(l.is_featured, \'' . _YES . '\', \'' . _NO . '\') as mod_is_featured,
								IF(l.is_published, "<span class=yes>' . _YES . '</span>", "<span class=no>' . _NO . '</span>") as mod_is_published,
								IF(l.is_approved, "<span class=yes>' . _APPROVED . '</span>", "<span class=no>' . _PENDING . '</span>") as mod_is_approved
							FROM ' . $this->tableName . ' l
								' . ($objLogin->GetLoggedType() == 'customer' ? 'INNER JOIN ' . TABLE_CUSTOMERS . ' cust ON (l.customer_id = cust.id AND l.customer_id=' . (int) $objLogin->GetLoggedID() . ')' : '') . '
							WHERE l.' . $this->primaryKey . ' = _RID_';
        // define edit mode fields
        $this->arrEditModeFields = array('separator_general' => array('separator_info' => array('legend' => _GENERAL), 'advertise_plan_id' => array('title' => _ADVERTISE_PLAN, 'type' => 'enum', 'width' => '', 'required' => true, 'readonly' => $objLogin->IsLoggedInAsAdmin() ? $is_expired ? true : false : true, 'default' => '', 'source' => $arr_advertise_plans, 'default_option' => '', 'unique' => false, 'javascript_event' => 'onchange="appChangePlan(\'' . $this->tableName . '\')"', 'visible' => $payments_module), 'listing_location_id' => array('title' => _LOCATION, 'type' => 'enum', 'width' => '', 'source' => $arr_locations, 'required' => true, 'javascript_event' => 'onchange="appRefillLocations(\'' . $this->tableName . '\')"'), 'listing_sub_location_id' => array('title' => _SUB_LOCATION, 'type' => 'enum', 'width' => '', 'source' => $arr_sub_locations, 'required' => true), 'website_url' => array('title' => _WEBSITE_URL . ' (http://)', 'type' => 'textbox', 'width' => '270px', 'required' => false, 'readonly' => false, 'validation_type' => 'text', 'maxlength' => '255'), 'business_email' => array('title' => _EMAIL_ADDRESS, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => 'email', 'maxlength' => '75')));
        if ($bpf_phone) {
            $this->arrEditModeFields['separator_general']['business_phone'] = array('title' => _PHONE, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
            $this->arrEditModeFields['separator_general']['business_fax'] = array('title' => _FAX, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
        }
        if ($bpf_video_link) {
            $this->arrEditModeFields['separator_general']['video_url'] = array('title' => _VIDEO, 'type' => 'textbox', 'width' => '210px', 'required' => false, 'default' => '', 'readonly' => false, 'validation_type' => '', 'maxlength' => '32');
        }
        if ($this->bpf_keywords_count) {
            $this->arrEditModeFields['separator_general']['keywords'] = array('title' => _KEYWORDS, 'type' => 'textarea', 'required' => false, 'width' => '480px', 'height' => '58px', 'editor_type' => 'simple', 'readonly' => false, 'default' => '', 'validation_type' => '', 'validation_maxlength' => '1024', 'unique' => false);
        }
        if ($bpf_logo) {
            $this->arrEditModeFields['separator_gallery']['separator_info'] = array('legend' => _GALLERY);
            $this->arrEditModeFields['separator_gallery']['image_file'] = array('title' => _LOGO, 'type' => 'image', 'width' => '210px', 'required' => false, 'readonly' => false, 'target' => 'images/listings/', 'no_image' => '', 'image_width' => '150px', 'image_height' => '120px', 'random_name' => 'true', 'unique' => false, 'thumbnail_create' => true, 'thumbnail_field' => 'image_file_thumb', 'thumbnail_width' => '150px', 'thumbnail_height' => '120px', 'file_maxsize' => '200k');
            for ($i = 1; $i <= $bpf_images_count; $i++) {
                $this->arrEditModeFields['separator_gallery']['image_' . $i] = array('title' => _IMAGE . ' #' . $i, 'type' => 'image', 'width' => '210px', 'required' => false, 'readonly' => false, 'target' => 'images/listings/', 'no_image' => '', 'image_width' => '150px', 'image_height' => '120px', 'random_name' => 'true', 'unique' => false, 'thumbnail_create' => true, 'thumbnail_field' => 'image_' . $i . '_thumb', 'thumbnail_width' => '150px', 'thumbnail_height' => '120px', 'file_maxsize' => '500k', 'watermark' => $watermark, 'watermark_text' => $watermark_text);
            }
        }
        if ($bpf_map) {
            $this->arrEditModeFields['separator_map']['separator_info'] = array('legend' => _MAP_CODE);
            $this->arrEditModeFields['separator_map']['map_code'] = array('title' => _MAP_CODE, 'type' => 'textarea', 'required' => false, 'width' => '480px', 'height' => '100px', 'editor_type' => 'simple', 'readonly' => false, 'default' => '', 'validation_type' => '', 'validation_maxlength' => '1024', 'unique' => false);
        }
        $this->arrEditModeFields['separator_general']['mod_is_approved'] = array('title' => _STATUS, 'type' => 'label');
        if ($objLogin->IsLoggedInAsAdmin()) {
            $this->arrEditModeFields['separator_general']['priority_order'] = array('title' => _ORDER, 'type' => 'textbox', 'width' => '50px', 'required' => true, 'readonly' => false, 'validation_type' => 'numeric|positive', 'maxlength' => '4');
            $this->arrEditModeFields['separator_general']['is_featured'] = array('title' => _FEATURED, 'type' => 'checkbox', 'readonly' => $is_expired ? true : false, 'true_value' => '1', 'false_value' => '0');
            ///$this->arrEditModeFields['separator_general']['date_published'] = array('title'=>_DATE_PUBLISHED, 'type'=>'hidden', 'required'=>true, 'readonly'=>false, 'default'=>date('Y-m-d H:i:s'));
            $this->arrEditModeFields['separator_general']['is_published'] = array('title' => _PUBLISHED, 'type' => 'checkbox', 'readonly' => $is_expired ? true : false, 'visible' => $is_expired ? false : true, 'true_value' => '1', 'false_value' => '0');
            $this->arrEditModeFields['separator_general']['access_level'] = array('title' => _ACCESSIBLE_BY, 'type' => 'enum', 'width' => '', 'required' => true, 'readonly' => $is_expired ? true : false, 'default' => 'public', 'source' => $arr_access_levels, 'default_option' => '', 'unique' => false, 'javascript_event' => '');
        }
        $this->arrEditModeFields['separator_general']['finish_publishing'] = array('title' => _FINISH_PUBLISHING, 'type' => 'label', 'format' => 'date', 'format_parameter' => $date_format);
        $this->arrEditModeFields['separator_general']['customer_id'] = array('title' => '', 'type' => 'hidden', 'required' => true, 'readonly' => false, 'default' => '');
        //----------------------------------------------------------------------
        // DETAILS MODE
        //----------------------------------------------------------------------
        $this->DETAILS_MODE_SQL = $this->EDIT_MODE_SQL;
        $this->arrDetailsModeFields = array('separator_general' => array('separator_info' => array('legend' => _GENERAL), 'advertise_plan_id' => array('title' => _ADVERTISE_PLAN, 'type' => 'enum', 'source' => $arr_advertise_plans, 'visible' => $payments_module), 'listing_location_id' => array('title' => _LOCATION, 'type' => 'enum', 'source' => $arr_locations), 'listing_sub_location_id' => array('title' => _SUB_LOCATION, 'type' => 'enum', 'source' => $arr_sub_locations), 'website_url' => array('title' => _WEBSITE_URL, 'type' => 'label'), 'business_email' => array('title' => _EMAIL_ADDRESS, 'type' => 'label'), 'mod_is_approved' => array('title' => _STATUS, 'type' => 'label'), 'mod_is_published' => array('title' => _PUBLISHED, 'type' => 'label'), 'date_published' => array('title' => _DATE_PUBLISHED, 'type' => 'datetime', 'format' => 'datetime', 'format_parameter' => $datetime_format)));
        if ($bpf_phone) {
            $this->arrDetailsModeFields['separator_general']['business_phone'] = array('title' => _PHONE, 'type' => 'label');
            $this->arrDetailsModeFields['separator_general']['business_fax'] = array('title' => _FAX, 'type' => 'label');
        }
        if ($bpf_video_link) {
            $this->arrDetailsModeFields['separator_general']['video_url'] = array('title' => _VIDEO, 'type' => 'label');
        }
        if ($this->bpf_keywords_count) {
            $this->arrDetailsModeFields['separator_general']['keywords'] = array('title' => _KEYWORDS, 'type' => 'label');
        }
        if ($bpf_logo) {
            $this->arrDetailsModeFields['separator_gallery']['separator_info'] = array('legend' => _GALLERY);
            $this->arrDetailsModeFields['separator_gallery']['image_file'] = array('title' => _LOGO, 'type' => 'image', 'target' => 'images/listings/', 'image_width' => '90px', 'image_height' => '80px', 'no_image' => 'no_image.png');
            for ($i = 1; $i <= $bpf_images_count; $i++) {
                $this->arrDetailsModeFields['separator_gallery']['image_' . $i] = array('title' => _IMAGE . ' #' . $i, 'type' => 'image', 'target' => 'images/listings/', 'image_width' => '90px', 'image_height' => '80px', 'no_image' => 'no_image.png');
            }
        }
        if ($bpf_map) {
            $this->arrDetailsModeFields['separator_map']['separator_info'] = array('legend' => _MAP_CODE);
            $this->arrDetailsModeFields['separator_map']['map_code'] = array('title' => _MAP_CODE, 'type' => 'html');
        }
        if ($objLogin->IsLoggedInAsAdmin()) {
            $this->arrDetailsModeFields['separator_general']['priority_order'] = array('title' => _ORDER, 'type' => 'label');
            $this->arrDetailsModeFields['separator_general']['mod_is_featured'] = array('title' => _FEATURED, 'type' => 'label');
            $this->arrDetailsModeFields['separator_general']['access_level'] = array('title' => _ACCESSIBLE_BY, 'type' => 'enum', 'source' => $arr_access_levels);
        }
        $this->arrDetailsModeFields['separator_general']['finish_publishing'] = array('title' => _FINISH_PUBLISHING, 'type' => 'label', 'format' => 'date', 'format_parameter' => $date_format);
        ///////////////////////////////////////////////////////////////////////////////
        // 3. add translation fields to all modes
        $arrTranslations = array();
        if ($bpf_business_name) {
            $arrTranslations['business_name'] = array('title' => _NAME, 'type' => 'textbox', 'required' => true, 'width' => '410px', 'maxlength' => '125');
        }
        if ($bpf_address) {
            $arrTranslations['business_address'] = array('title' => _ADDRESS, 'type' => 'textarea', 'required' => false, 'width' => '410px', 'height' => '50px', 'maxlength' => '255');
        }
        if ($bpf_business_description) {
            $arrTranslations['business_description'] = array('title' => _DESCRIPTION, 'type' => 'textarea', 'required' => false, 'width' => '410px', 'height' => '90px', 'maxlength' => '1024');
        }
        $this->AddTranslateToModes($this->arrTranslations, $arrTranslations);
        ///////////////////////////////////////////////////////////////////////////////
    }
예제 #2
0
 /**
  * Returns lisitngs of all plans for specific customer
  * 		@param $customer_id
  */
 public static function GetListingsForCustomer($customer_id = 0)
 {
     $result = array();
     $result_listings = array();
     $result_plans = array();
     $result_temp = AdvertisePlans::GetAllPlans();
     for ($i = 0; $i < $result_temp[1]; $i++) {
         $result_plans[$result_temp[0][$i]['id']] = $result_temp[0][$i]['plan_name'];
     }
     $sql = 'SELECT plan1_listings, plan2_listings, plan3_listings, plan4_listings FROM ' . TABLE_CUSTOMERS . ' WHERE id = ' . (int) $customer_id;
     $result_listings = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY);
     if ($result_listings[1] > 0) {
         if ($result_listings[0]['plan1_listings'] > 0) {
             $result[0] = array('id' => '1', 'count' => $result_listings[0]['plan1_listings'], 'name' => isset($result_plans['1']) ? $result_plans['1'] : '');
         }
         if ($result_listings[0]['plan2_listings'] > 0) {
             $result[1] = array('id' => '2', 'count' => $result_listings[0]['plan2_listings'], 'name' => isset($result_plans['2']) ? $result_plans['2'] : '');
         }
         if ($result_listings[0]['plan3_listings'] > 0) {
             $result[2] = array('id' => '3', 'count' => $result_listings[0]['plan3_listings'], 'name' => isset($result_plans['3']) ? $result_plans['3'] : '');
         }
         if ($result_listings[0]['plan4_listings'] > 0) {
             $result[3] = array('id' => '4', 'count' => $result_listings[0]['plan4_listings'], 'name' => isset($result_plans['4']) ? $result_plans['4'] : '');
         }
     }
     return $result;
 }