$order_id = $_SESSION['MDS_order_id'];
$update_order = false;
if ($row['status'] == 'reserved' && $row[user_id] == $user_id) {
    // the block was already selected by the client, this is a double click
    echo 'new';
    $update_order = true;
} elseif ($row['status'] == 'reserved') {
    // reserved by someone-else
    echo 'ordered';
    $update_order = false;
    // cannot place or remove from order
} elseif ($row['status'] != '') {
    $update_order = false;
    echo $row['status'];
} else {
    $update_order = true;
    $echo_oid = true;
    if ($max_selected) {
        echo 'max_selected';
        die;
    }
}
if ($update_order) {
    $sql = "select * from banners where banner_id='{$BID}'";
    $result = mysql_query($sql) or die(mysql_error() . $sql);
    $b_row = mysql_fetch_array($result);
    select_block('', '', $block_id);
    if ($echo_oid) {
        echo $order_id;
    }
}
function select_block($map_x, $map_y)
{
    global $BID;
    global $b_row;
    global $label;
    global $order_id;
    // calculate clicked block from co-ords.
    if (func_num_args() > 2) {
        $clicked_block = func_get_arg(2);
    } else {
        $map_x = floor($map_x / BLK_WIDTH) * BLK_WIDTH;
        // got to floor it to get the top-right corner of the block
        $map_y = floor($map_y / BLK_HEIGHT) * BLK_HEIGHT;
        //$clicked_block = (($map_y*$b_row['grid_width'])+$map_x)/10 ;
        $GRD_WIDTH = BLK_WIDTH * G_WIDTH;
        $clicked_block = $map_x / BLK_WIDTH + $map_y / BLK_HEIGHT * ($GRD_WIDTH / BLK_WIDTH);
    }
    if ($clicked_block == 0) {
        $clicked_block = "0";
        // convert to string
    }
    $sql = "select Rank from users where ID=" . $_SESSION['MDS_ID'];
    $result = mysql_query($sql) or die(mysql_error() . $sql);
    $u_row = mysql_fetch_array($result);
    //Check if max_orders < order count
    if (!can_user_order($b_row, $_SESSION['MDS_ID'])) {
        return $label['advertiser_max_order_html'];
        // order count > max orders
    }
    if (!function_exists('delete_ads_files')) {
        require_once "../include/ads.inc.php";
    }
    # check the status of the block.
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "LOCK TABLES blocks WRITE, orders WRITE, ads WRITE, form_fields READ, currencies READ, prices READ, banners READ, packages READ";
        $result = mysql_query($sql) or die(" <b>Dear Webmaster: The current MySQL user does not have permission to lock tables. Please give this user permission to lock tables, or turn off locking in the Admin. To turn off locking in the Admin, please go to Main Config and look under the MySQL Settings.<b>");
    } else {
        // poor man's lock
        $sql = "UPDATE `config` SET `val`='YES' WHERE `key`='SELECT_RUNNING' AND `val`='NO' ";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_affected_rows() == 0) {
            // make sure it cannot be locked for more than 30 secs
            // This is in case the proccess fails inside the lock
            // and does not release it.
            $unix_time = time();
            // get the time of last run
            $sql = "SELECT * FROM `config` where `key` = 'LAST_SELECT_RUN' ";
            $result = @mysql_query($sql);
            $t_row = @mysql_fetch_array($result);
            if ($unix_time > $t_row['val'] + 30) {
                // release the lock
                $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
                $result = @mysql_query($sql) or die(mysql_error());
                // update timestamp
                $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
                $result = @mysql_query($sql) or die(mysql_error());
            }
            usleep(5000000);
            // this function is executing in another process. sleep for half a second
            select_block($map_x, $map_y, $clicked_block);
        }
    }
    ####################################################
    //$sql = "SELECT status, user_id FROM blocks where `x`=$map_x AND `y`=$map_y and banner_id=$BID ";
    $sql = "SELECT status, user_id, ad_id FROM blocks where block_id='{$clicked_block}' AND banner_id='{$BID}' ";
    $result = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_array($result);
    if ($row['status'] == '' || $row['status'] == 'reserved' && $row['user_id'] == $_SESSION['MDS_ID']) {
        // put block on order
        $sql = "SELECT * FROM orders where user_id='" . $_SESSION['MDS_ID'] . "' and status='new' and banner_id='{$BID}' ";
        $result = mysql_query($sql) or die(mysql_error());
        $row = mysql_fetch_array($result);
        if ($row['blocks'] != '') {
            $blocks = explode(",", $row['blocks']);
        } else {
            $blocks = array();
        }
        $new_blocks = array();
        // remove selected block
        for ($i = 0; $i < sizeof($blocks); $i++) {
            if (strcmp($blocks[$i], $clicked_block) != 0) {
                $new_blocks[] = "" . $blocks[$i];
            } else {
                //clicked for 2nd time;
                $double_clicked = true;
            }
        }
        if (!$double_clicked) {
            # add newly selected block
            $new_blocks[] = "{$clicked_block}";
            //echo "not-double<br>";
        }
        // check max blocks
        if (USE_AJAX == 'NO') {
            if (G_MAX_BLOCKS > 0) {
                if (sizeof($new_blocks) > G_MAX_BLOCKS) {
                    $max_selected = true;
                    $cannot_sel = "<font color=red><b>" . str_replace('%MAX_BLOCKS%', G_MAX_BLOCKS, $label['max_blocks_selected']) . "</b></font>";
                }
            }
        }
        if (!$max_selected) {
            $blocks = $new_blocks;
            $quantity = sizeof($blocks) * (BLK_WIDTH * BLK_HEIGHT);
            //$row['blocks']=implode(",",$blocks);
            $blocks = implode(",", $blocks);
            // change to string
            $now = gmdate("Y-m-d H:i:s");
            $sql = "REPLACE INTO orders (user_id, order_id, blocks, status, order_date, price, quantity, banner_id, currency, days_expire, date_stamp, approved) VALUES ('" . $_SESSION['MDS_ID'] . "', '" . $row['order_id'] . "', '" . $blocks . "', 'new', NOW(), '" . $price . "', '" . $quantity . "', '" . $BID . "', '" . get_default_currency() . "', " . $b_row['days_expire'] . ", '{$now}', '" . AUTO_APPROVE . "') ";
            $result = mysql_query($sql) or die(mysql_error() . $sql);
            $_SESSION['MDS_order_id'] = mysql_insert_id();
            $order_id = $_SESSION['MDS_order_id'];
            $sql = "delete from blocks where user_id='" . $_SESSION['MDS_ID'] . "' AND status = 'reserved' AND banner_id='{$BID}' ";
            mysql_query($sql) or die(mysql_error() . $sql);
            $cell = "0";
            for ($i = 0; $i < $b_row['grid_height']; $i++) {
                for ($j = 0; $j < $b_row['grid_width']; $j++) {
                    if (in_array($cell, $new_blocks)) {
                        $price = get_zone_price($BID, $i, $j);
                        $currency = get_default_currency();
                        $sql = "REPLACE INTO `blocks` ( `block_id` , `user_id` , `status` , `x` , `y` , `image_data` , `url` , `alt_text`, `approved`, `banner_id`, `currency`, `price`, `order_id`) VALUES ('{$cell}',  '" . $_SESSION['MDS_ID'] . "' , 'reserved' , '" . $j * BLK_WIDTH . "' , '" . $i * BLK_HEIGHT . "' , '' , '' , '', '" . AUTO_APPROVE . "', '" . $BID . "', '" . get_default_currency() . "', '" . $price . "', '" . $_SESSION['MDS_order_id'] . "')";
                        $total += $price;
                        mysql_query($sql) or die(mysql_error() . $sql);
                    }
                    $cell++;
                }
            }
            // update price
            $sql = "UPDATE orders SET price='{$total}' WHERE order_id='" . $_SESSION['MDS_order_id'] . "'";
            mysql_query($sql) or die(mysql_error() . $sql);
            $sql = "UPDATE orders SET original_order_id='" . $_SESSION['MDS_order_id'] . "' WHERE order_id='" . $_SESSION['MDS_order_id'] . "'";
            mysql_query($sql) or die(mysql_error() . $sql);
            // check that we have ad_id, if not then create an ad for this order.
            if (!$row['ad_id']) {
                $_REQUEST[$ad_tag_to_field_id['URL']['field_id']] = 'http://';
                $_REQUEST[$ad_tag_to_field_id['ALT_TEXT']['field_id']] = 'ad text';
                $_REQUEST['order_id'] = $_SESSION['MDS_order_id'];
                $_REQUEST['banner_id'] = $BID;
                $_REQUEST['user_id'] = $_SESSION['MDS_ID'];
                $ad_id = insert_ad_data();
                $sql = "UPDATE orders SET ad_id='{$ad_id}' WHERE order_id='" . $_SESSION['MDS_order_id'] . "' ";
                $result = mysql_query($sql) or die(mysql_error());
                $sql = "UPDATE blocks SET ad_id='{$ad_id}' WHERE order_id='" . $_SESSION['MDS_order_id'] . "' ";
                $result = mysql_query($sql) or die(mysql_error());
                $_REQUEST['ad_id'] = $ad_id;
            }
            ###################################################
            if (USE_LOCK_TABLES == 'Y') {
                $sql = "UNLOCK TABLES";
                $result = mysql_query($sql) or die(mysql_error() . " <b>Dear Webmaster: The current MySQL user set in config.php does not have permission to lock tables. Please give this user permission to lock tables, or set USE_LOCK_TABLES to N in the config.php file that comes with this script.<b>");
            } else {
                // release the poor man's lock
                $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
                mysql_query($sql);
                $unix_time = time();
                // update timestamp
                $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
                $result = @mysql_query($sql) or die(mysql_error());
            }
            ####################################################
        }
    } else {
        if ($row['status'] == 'nfs') {
            $cannot_sel = "<font color=red><b>" . $label['advertiser_sel_nfs_error'] . "</b></font>";
        } else {
            $label['advertiser_sel_sold_error'] = str_replace("%BLOCK_ID%", $clicked_block, $label['advertiser_sel_sold_error']);
            $cannot_sel = "<font color=red><b>" . $label['advertiser_sel_sold_error'] . "</b></font><br>";
        }
    }
    return $cannot_sel;
}
Beispiel #3
0
            $cannot_sel = select_block($_REQUEST['map_x'] + BLK_WIDTH, $_REQUEST['map_y']);
        }
        if ($_REQUEST['map_y'] + BLK_HEIGHT <= $max_y) {
            $cannot_sel = select_block($_REQUEST['map_x'], $_REQUEST['map_y'] + BLK_HEIGHT);
        }
        if ($_REQUEST['map_x'] + BLK_WIDTH <= $max_x && $_REQUEST['map_y'] + BLK_HEIGHT <= $max_y) {
            $cannot_sel = select_block($_REQUEST['map_x'] + BLK_WIDTH, $_REQUEST['map_y'] + BLK_HEIGHT);
        }
        if ($_REQUEST['map_x'] + BLK_WIDTH * 2 <= $max_x) {
            $cannot_sel = select_block($_REQUEST['map_x'] + BLK_WIDTH * 2, $_REQUEST['map_y']);
        }
        if ($_REQUEST['map_x'] + BLK_WIDTH * 2 <= $max_x && $_REQUEST['map_y'] + BLK_HEIGHT <= $max_y) {
            $cannot_sel = select_block($_REQUEST['map_x'] + BLK_WIDTH * 2, $_REQUEST['map_y'] + BLK_HEIGHT);
        }
    } else {
        $cannot_sel = select_block($_REQUEST['map_x'], $_REQUEST['map_y']);
    }
}
require "header.php";
//print_r($_REQUEST);
?>

<div id="blocks">

</div>

<script language="JavaScript">

var browser_compatible=false;
var browser_checked=false;
var selectedBlocks= new Array();