Exemple #1
0
function publish_image($BID)
{
    if (!is_numeric($BID)) {
        return false;
    }
    $BANNER_DIR = get_banner_dir();
    $file_path = SERVER_PATH_TO_ADMIN;
    // eg e:/apache/htdocs/ojo/admin/
    $p = preg_split('%[/\\\\]%', $file_path);
    array_pop($p);
    array_pop($p);
    $dest = implode('/', $p);
    $dest = $dest . "/" . $BANNER_DIR;
    if (OUTPUT_JPEG == 'Y') {
        copy($file_path . "temp/temp{$BID}.jpg", $dest . "main{$BID}.jpg");
        //echo "copy ".$file_path."temp/temp$BID.jpg, ".$dest."main$BID.jpg";
        //unlink ($file_path."temp/temp.png");
    } elseif (OUTPUT_JPEG == 'N') {
        copy($file_path . "temp/temp{$BID}.png", $dest . "main{$BID}.png");
        //unlink ($file_path."temp/temp.png");
    } elseif (OUTPUT_JPEG == 'GIF') {
        copy($file_path . "temp/temp{$BID}.gif", $dest . "main{$BID}.gif");
    }
    // output the tile image
    $b_row = load_banner_row($BID);
    if ($b_row['tile'] == '') {
        $b_row['tile'] = get_default_image('tile');
    }
    $tile = imagecreatefromstring(base64_decode($b_row['tile']));
    imagegif($tile, $dest . "bg-main{$BID}.gif");
    //imagepng($tile, $dest."bg-main$BID.gif");
    // update the records
    $sql = "SELECT * FROM blocks WHERE approved='Y' and status='sold' AND image_data <> '' AND banner_id='{$BID}' ";
    $r = mysql_query($sql) or die(mysql_error() . $sql);
    while ($row = mysql_fetch_array($r)) {
        // set the 'date_published' only if it was not set before, date_published can only be set once.
        $now = gmdate("Y-m-d H:i:s");
        $sql = "UPDATE orders set `date_published`='{$now}' where order_id='" . $row['order_id'] . "' AND date_published IS NULL ";
        $result = mysql_query($sql) or die(mysql_error());
        // update the published status, always updated to Y
        $sql = "UPDATE orders set `published`='Y' where order_id='" . $row['order_id'] . "'  ";
        $result = mysql_query($sql) or die(mysql_error());
        $sql = "UPDATE blocks set `published`='Y' where block_id='" . $row['block_id'] . "' AND banner_id='{$BID}'";
        $result = mysql_query($sql) or die(mysql_error());
    }
    //Make sure to un-publish any blocks that are not approved...
    $sql = "SELECT block_id, order_id FROM blocks WHERE approved='N' AND status='sold' AND banner_id='{$BID}' ";
    //echo $sql;
    $result = mysql_query($sql) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $sql = "UPDATE blocks set `published`='N' where block_id='" . $row['block_id'] . "'  AND banner_id='{$BID}'  ";
        mysql_query($sql) or die(mysql_error());
        $sql = "UPDATE orders set `published`='N' where order_id='" . $row['order_id'] . "'  AND banner_id='{$BID}'  ";
        mysql_query($sql) or die(mysql_error());
    }
    // update the time-stamp on the banner
    $sql = "UPDATE banners SET time_stamp='" . time() . "' WHERE banner_id='" . $BID . "' ";
    mysql_query($sql) or die(mysql_error());
    //echo $sql;
}
Exemple #2
0
                publish_image($BID);
                process_map($BID);
                //echo 'published.';
            }
            echo 'Ad Saved. <A href="ads.php?BID=' . $prams['banner_id'] . '">&lt;&lt; Go to the Ad List</a>';
            echo "<hr>";
        }
    } else {
        $prams = load_ad_values($_REQUEST['ad_id']);
        display_ad_form(1, 'edit', $prams);
    }
    $prams = load_ad_values($_REQUEST['ad_id']);
    $sql = "select * FROM users where ID='" . $prams['user_id'] . "' ";
    $result = mysql_query($sql);
    $u_row = mysql_fetch_array($result);
    $b_row = load_banner_row($prams['banner_id']);
    ?>

	<h3>Additional Info</h3>
	<b>Customer:</b><?php 
    echo $u_row['LastName'] . ', ' . $u_row['FirstName'];
    ?>
<BR>
	<b>Order #:</b><?php 
    echo $prams['order_id'];
    ?>
<br>
	<b>Grid:</b><a href='ordersmap.php?banner_id=<?php 
    echo $prams['banner_id'];
    ?>
'><?php 
function reserve_pixels_for_temp_order($temp_order_row)
{
    // check if the user can get the order
    if (!can_user_order(load_banner_row($temp_order_row['banner_id']), $_SESSION['MDS_ID'], $temp_order_row['package_id'])) {
        echo 'can\'t touch this<br>';
        return false;
    }
    require_once '../include/ads.inc.php';
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "LOCK TABLES blocks WRITE, orders WRITE, ads WRITE, temp_orders WRITE,  currencies READ, prices READ, banners READ, form_fields READ, form_field_translations 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
            reserve_pixels_for_temp_order($temp_order_row);
            return;
        }
    }
    ####################################################
    $filename = SERVER_PATH_TO_ADMIN . 'temp/' . "info_" . md5(session_id()) . ".txt";
    $fh = fopen($filename, 'rb');
    $block_info = fread($fh, filesize($filename));
    fclose($fh);
    //$block_info = unserialize($temp_order_row['block_info']);
    $block_info = unserialize($block_info);
    //echo "block info:";
    //print_r($block_info);
    $in_str = $temp_order_row['blocks'];
    $sql = "select block_id from blocks where banner_id='" . $temp_order_row['banner_id'] . "' and block_id IN(" . $in_str . ") ";
    //echo $sql."<br>";
    $result = mysql_query($sql) or die($sql . mysql_error());
    if (mysql_num_rows($result) > 0) {
        return false;
        // the pixels are not available!
    }
    // approval status, default is N
    $banner_row = load_banner_row($temp_order_row['banner_id']);
    $approved = $banner_row['auto_approve'];
    $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, package_id, ad_id, approved) VALUES ('" . $_SESSION['MDS_ID'] . "', '', '" . $in_str . "', 'new', '" . $now . "', '" . $temp_order_row['price'] . "', '" . $temp_order_row['quantity'] . "', '" . $temp_order_row['banner_id'] . "', '" . get_default_currency() . "', " . $temp_order_row['days_expire'] . ", '" . $now . "', " . $temp_order_row['package_id'] . ", " . $temp_order_row['ad_id'] . ", '" . $approved . "') ";
    $result = mysql_query($sql) or die(mysql_error() . $sql);
    $order_id = mysql_insert_id();
    mds_log("Changed temp order to a real order - " . $sql);
    //echo "<hr>";echo $sql; echo "<hr>";
    $sql = "UPDATE ads SET user_id='" . $_SESSION['MDS_ID'] . "', order_id='" . $order_id . "' where ad_id='" . $temp_order_row['ad_id'] . "' ";
    //echo $sql;
    mysql_query($sql) or die(mysql_error() . $sql);
    $sql = "UPDATE orders SET original_order_id='" . $order_id . "' where order_id='" . $order_id . "' ";
    //echo $sql;
    mysql_query($sql) or die(mysql_error() . $sql);
    global $prams;
    $prams = load_ad_values($temp_order_row['ad_id']);
    $url = get_template_value('URL', 1);
    $alt_text = get_template_value('ALT_TEXT', 1);
    //print_R($block_info);
    //echo "<P>url: $url, alt_text: $alt_text </p>";
    foreach ($block_info as $key => $block) {
        $sql = "REPLACE INTO `blocks` ( `block_id` , `user_id` , `status` , `x` , `y` , `image_data` , `url` , `alt_text`, `approved`, `banner_id`, `currency`, `price`, `order_id`, `ad_id`) VALUES ('" . $key . "',  '" . $_SESSION['MDS_ID'] . "' , 'reserved' , '" . $block['map_x'] . "' , '" . $block['map_y'] . "' , '" . $block['image_data'] . "' , '" . addslashes($url) . "' , '" . addslashes($alt_text) . "', '" . $approved . "', '" . $temp_order_row['banner_id'] . "', '" . get_default_currency() . "', '" . $block['price'] . "', '" . $order_id . "', '" . $temp_order_row['ad_id'] . "')";
        //echo $sql."<br>";
        mds_log("Updated block - " . $sql);
        mysql_query($sql) or die(mysql_error() . $sql);
    }
    delete_temp_order(session_id(), false);
    // false = do not delete the ad...
    ###################################################
    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 'No' in the Main Config section in the Admin.<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());
    }
    ####################################################
    return $order_id;
}
function load_banner_constants($BID)
{
    $row = load_banner_row($BID);
    // defaults
    if (!$row['block_width']) {
        $row['block_width'] = 10;
    }
    if (!$row['block_height']) {
        $row['block_height'] = 10;
    }
    if (!$row['grid_block']) {
        $row['grid_block'] = get_default_image('grid_block');
    }
    if (!$row['nfs_block']) {
        $row['nfs_block'] = get_default_image('nfs_block');
    }
    if (!$row['usr_grid_block']) {
        $row['usr_grid_block'] = get_default_image('usr_grid_block');
    }
    if (!$row['usr_nfs_block']) {
        $row['usr_nfs_block'] = get_default_image('usr_nfs_block');
    }
    if (!$row['usr_sel_block']) {
        $row['usr_sel_block'] = get_default_image('usr_sel_block');
    }
    if (!$row['usr_ord_block']) {
        $row['usr_ord_block'] = get_default_image('usr_ord_block');
    }
    if (!$row['usr_res_block']) {
        $row['usr_res_block'] = get_default_image('usr_res_block');
    }
    if (!$row['usr_sol_block']) {
        $row['usr_sol_block'] = get_default_image('usr_sol_block');
    }
    // define constants
    define("G_NAME", $row['name']);
    define("G_PRICE", $row['price_per_block']);
    define("G_CURRENCY", $row['currency']);
    define("DAYS_EXPIRE", $row['days_expire']);
    define("BLK_WIDTH", $row['block_width']);
    define("BLK_HEIGHT", $row['block_height']);
    define("BANNER_ID", $row['banner_id']);
    define("G_WIDTH", $row['grid_width']);
    define("G_HEIGHT", $row['grid_height']);
    define("GRID_BLOCK", base64_decode($row['grid_block']));
    define("NFS_BLOCK", base64_decode($row['nfs_block']));
    define("USR_GRID_BLOCK", base64_decode($row['usr_grid_block']));
    define("USR_NFS_BLOCK", base64_decode($row['usr_nfs_block']));
    define("USR_SEL_BLOCK", base64_decode($row['usr_sel_block']));
    define("USR_ORD_BLOCK", base64_decode($row['usr_ord_block']));
    define("USR_RES_BLOCK", base64_decode($row['usr_res_block']));
    define("USR_SOL_BLOCK", base64_decode($row['usr_sol_block']));
    define("G_BGCOLOR", $row['bgcolor']);
    define("AUTO_APPROVE", $row['auto_approve']);
    define("AUTO_PUBLISH", $row['auto_publish']);
    define("G_MAX_ORDERS", $row['max_orders']);
    define("G_MAX_BLOCKS", $row['max_blocks']);
    define("G_MIN_BLOCKS", $row['min_blocks']);
    //define ("BANNER_ROW", serialize($row));
    return $row;
}