Ejemplo n.º 1
0
function bsaAddNewSpace()
{
    if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["bsaProAction"] == 'updateSpace') {
        if (isset($_SESSION['bsa_space_' . $_GET['space_id']])) {
            unset($_SESSION['bsa_space_' . $_GET['space_id']]);
            // Reset cache
        }
        if ($_POST["name"] != '') {
            $model = new BSA_PRO_Model();
            $cpc_status = $model->billingValidator('cpc');
            $cpm_status = $model->billingValidator('cpm');
            $cpd_status = $model->billingValidator('cpd');
            if ($cpc_status == 'isset' || $cpc_status == 'incorrect' || $cpm_status == 'isset' || $cpm_status == 'incorrect' || $cpd_status == 'isset' || $cpd_status == 'incorrect') {
                if ($cpc_status == 'incorrect' || $cpm_status == 'incorrect' || $cpd_status == 'incorrect') {
                    echo '
					<div class="updated settings-error">
						<p><strong>Error, incorrect contract values!</strong> Please enter the price and values for some contract, add them one by one (all values must be different).<br><br>
						<strong>Note!</strong><br>
						Enter <strong>0</strong> in the price field if you do not want to use some of billing model.</p>
					</div>';
                } else {
                    $model->updateSpace($_GET['space_id'], $_POST['name'], $_POST['title'], $_POST['add_new'], $_POST['cpc_price'] > 0 ? $_POST['cpc_price'] : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_price'] : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_price'] : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_1'] > 0 ? $_POST['cpc_contract_1'] : 0 : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_2'] > 0 ? $_POST['cpc_contract_2'] : 0 : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_3'] > 0 ? $_POST['cpc_contract_3'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_1'] > 0 ? $_POST['cpm_contract_1'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_2'] > 0 ? $_POST['cpm_contract_2'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_3'] > 0 ? $_POST['cpm_contract_3'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_1'] > 0 ? $_POST['cpd_contract_1'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_2'] > 0 ? $_POST['cpd_contract_2'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_3'] > 0 ? $_POST['cpd_contract_3'] : 0 : 0, $_POST['discount_2'] > 0 && $_POST['discount_2'] <= 100 ? $_POST['discount_2'] : 0, $_POST['discount_3'] > 0 && $_POST['discount_3'] <= 100 ? $_POST['discount_3'] : 0, $_POST['grid_system'], $_POST['template'], $_POST['display_type'], $_POST['random'], $_POST['max_items'], $_POST['col_per_row'], $_POST['font'], $_POST['font_url'], $_POST['header_bg'], $_POST['header_color'], $_POST['link_color'], $_POST['ads_bg'], $_POST['ad_bg'], $_POST['ad_title_color'], $_POST['ad_desc_color'], $_POST['ad_url_color'], $_POST['ad_extra_color_1'], $_POST['ad_extra_color_2'], $_POST['animation'], isset($_POST['space_categories']) && $_POST['space_categories'] != '' ? implode(",", $_POST['space_categories']) : null, isset($_POST['space_tags']) && $_POST['space_tags'] != '' ? implode(",", $_POST['space_tags']) : null, isset($_POST['show_in_country']) && $_POST['show_in_country'] != '' ? implode(",", $_POST['show_in_country']) : null, isset($_POST['hide_in_country']) && $_POST['hide_in_country'] != '' ? implode(",", $_POST['hide_in_country']) : null, isset($_POST['show_in_advanced']) && $_POST['show_in_advanced'] != '' ? $_POST['show_in_advanced'] : null, isset($_POST['hide_in_advanced']) && $_POST['hide_in_advanced'] != '' ? $_POST['hide_in_advanced'] : null, isset($_POST['devices']) && $_POST['devices'] != '' ? implode(",", $_POST['devices']) : null, isset($_POST['unavailable_dates']) && $_POST['unavailable_dates'] != '' ? $_POST['unavailable_dates'] : null, isset($_POST['show_ads']) && isset($_POST['show_close_btn']) && isset($_POST['close_ads']) ? ($_POST['show_ads'] > 0 ? $_POST['show_ads'] : '0') . ',' . ($_POST['show_close_btn'] > 0 ? $_POST['show_close_btn'] : '0') . ',' . ($_POST['close_ads'] > 0 ? $_POST['close_ads'] : '0') : '0,0,0', $_POST['status'] == 'active' ? 'active' : 'inactive');
                    do_action('bsa-pro-updateSpace', $_POST, $_GET['space_id']);
                    echo '
					<div class="updated settings-error">
						<p><strong>Space updated.</strong></p>
					</div>';
                }
            } else {
                echo '
				<div class="updated settings-error">
					<p><strong>Error, empty contracts!</strong> You should set at least one contract.</p>
				</div>';
            }
        } else {
            echo '
			<div class="updated settings-error">
				<p><strong>Space not saved.</strong> The name field is required!</p>
			</div>';
        }
    } elseif ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["bsaProAction"] == 'addNewSpace') {
        if ($_POST["name"] != '') {
            $model = new BSA_PRO_Model();
            $cpc_status = $model->billingValidator('cpc');
            $cpm_status = $model->billingValidator('cpm');
            $cpd_status = $model->billingValidator('cpd');
            if ($cpc_status == 'isset' || $cpc_status == 'incorrect' || $cpm_status == 'isset' || $cpm_status == 'incorrect' || $cpd_status == 'isset' || $cpd_status == 'incorrect') {
                if ($cpc_status == 'incorrect' || $cpm_status == 'incorrect' || $cpd_status == 'incorrect') {
                    echo '
					<div class="updated settings-error">
						<p><strong>Error, incorrect contract values!</strong> Please enter the price and values for some contract, add them one by one (all values must be different).<br><br>
						<strong>Note!</strong><br>
						Enter <strong>0</strong> in the price field if you do not want to use some of billing model.</p>
					</div>';
                } else {
                    $model->addNewSpace(NULL, $_POST['name'], $_POST['title'], $_POST['add_new'], $_POST['cpc_price'] > 0 ? $_POST['cpc_price'] : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_price'] : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_price'] : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_1'] > 0 ? $_POST['cpc_contract_1'] : 0 : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_2'] > 0 ? $_POST['cpc_contract_2'] : 0 : 0, $_POST['cpc_price'] > 0 ? $_POST['cpc_contract_3'] > 0 ? $_POST['cpc_contract_3'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_1'] > 0 ? $_POST['cpm_contract_1'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_2'] > 0 ? $_POST['cpm_contract_2'] : 0 : 0, $_POST['cpm_price'] > 0 ? $_POST['cpm_contract_3'] > 0 ? $_POST['cpm_contract_3'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_1'] > 0 ? $_POST['cpd_contract_1'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_2'] > 0 ? $_POST['cpd_contract_2'] : 0 : 0, $_POST['cpd_price'] > 0 ? $_POST['cpd_contract_3'] > 0 ? $_POST['cpd_contract_3'] : 0 : 0, $_POST['discount_2'] > 0 && $_POST['discount_2'] <= 100 ? $_POST['discount_2'] : 0, $_POST['discount_3'] > 0 && $_POST['discount_3'] <= 100 ? $_POST['discount_3'] : 0, $_POST['grid_system'], $_POST['template'], $_POST['display_type'], $_POST['random'], $_POST['max_items'], $_POST['col_per_row'], $_POST['font'], $_POST['font_url'], $_POST['header_bg'], $_POST['header_color'], $_POST['link_color'], $_POST['ads_bg'], $_POST['ad_bg'], $_POST['ad_title_color'], $_POST['ad_desc_color'], $_POST['ad_url_color'], $_POST['ad_extra_color_1'], $_POST['ad_extra_color_2'], $_POST['animation'], isset($_POST['space_categories']) && $_POST['space_categories'] != '' ? implode(",", $_POST['space_categories']) : null, isset($_POST['space_tags']) && $_POST['space_tags'] != '' ? implode(",", $_POST['space_tags']) : null, isset($_POST['show_in_country']) && $_POST['show_in_country'] != '' ? implode(",", $_POST['show_in_country']) : null, isset($_POST['hide_in_country']) && $_POST['hide_in_country'] != '' ? implode(",", $_POST['hide_in_country']) : null, isset($_POST['show_in_advanced']) && $_POST['show_in_advanced'] != '' ? $_POST['show_in_advanced'] : null, isset($_POST['hide_in_advanced']) && $_POST['hide_in_advanced'] != '' ? $_POST['hide_in_advanced'] : null, isset($_POST['devices']) && $_POST['devices'] != '' ? implode(",", $_POST['devices']) : null, isset($_POST['unavailable_dates']) && $_POST['unavailable_dates'] != '' ? $_POST['unavailable_dates'] : null, isset($_POST['show_ads']) && isset($_POST['show_close_btn']) && isset($_POST['close_ads']) ? ($_POST['show_ads'] > 0 ? $_POST['show_ads'] : '0') . ',' . ($_POST['show_close_btn'] > 0 ? $_POST['show_close_btn'] : '0') . ',' . ($_POST['close_ads'] > 0 ? $_POST['close_ads'] : '0') : '0,0,0', $_POST['status'] == 'active' ? 'active' : 'inactive');
                    do_action('bsa-pro-addNewSpace', $_POST, $model->getTableName('spaces'));
                    $_SESSION['bsa_space_status'] = 'space_added';
                    echo '
					<div class="updated settings-error">
						<p><strong>Space saved.</strong> Click <a href="' . admin_url() . 'admin.php?page=bsa-pro-sub-menu-spaces">here</a> to show all spaces.</p>
					</div>';
                }
            } else {
                echo '
				<div class="updated settings-error">
					<p><strong>Error, empty contracts!</strong> You should set at least one contract.</p>
				</div>';
            }
        } else {
            echo '
			<div class="updated settings-error">
				<p><strong>Space not saved.</strong> The name field is required!</p>
			</div>';
        }
    }
}