<td>
	<font face="arial" size="2"><?php 
    echo get_formatted_date(get_local_time($row[max_date]));
    ?>
</font>
	</td>
	<td>
	<font face="arial" size="2"><?php 
    $sql = "Select * FROM  `ads` as t1, `orders` AS t2 WHERE t1.ad_id=t2.ad_id AND t1.banner_id='{$BID}' and t1.order_id > 0 AND t1.user_id='" . $row['user_id'] . "' ORDER BY `ad_date`";
    $m_result = mysql_query($sql) or die(mysql_error());
    while ($prams = mysql_fetch_array($m_result, MYSQL_ASSOC)) {
        $ALT_TEXT = get_template_value('ALT_TEXT', 1);
        $ALT_TEXT = str_replace("'", "", $ALT_TEXT);
        $ALT_TEXT = str_replace("\"", '', $ALT_TEXT);
        $js_str = " onmousemove=\"sB(event, '" . $ALT_TEXT . "', this, " . $prams['ad_id'] . ")\" onmouseout=\"hI()\" ";
        echo $br . '<a target="_blank" ' . $js_str . ' href="' . get_template_value('URL', 1) . '">' . get_template_value('ALT_TEXT', 1) . '</a>';
        $br = '<br>';
    }
    ?>
</font>
	</td>
	<td>
	<font face="arial" size="2"><?php 
    echo $row['pixels'];
    ?>
</font>
	</td>
	</tr>
<?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;
}
Exemple #3
0
function update_blocks_with_ad($ad_id, $user_id)
{
    global $prams;
    $prams = load_ad_values($ad_id);
    if ($prams['order_id'] > 0) {
        $sql = "UPDATE blocks SET alt_text='" . addslashes(get_template_value('ALT_TEXT', 1)) . "', url='" . addslashes(get_template_value('URL', 1)) . "'  WHERE order_id='" . $prams['order_id'] . "' AND user_id='" . $user_id . "' ";
        mysql_query($sql) or die(mysql_error());
        mds_log("Updated blocks with ad URL, ALT_TEXT", $sql);
    }
}
function echo_ad_list_data($admin)
{
    global $column_list, $column_info, $label, $cur_offset, $order_str, $q_offset, $show_emp, $cat, $list_mode;
    if ($_REQUEST['order_by'] != '') {
        $ord = $_REQUEST['ord'];
        if ($ord == 'asc') {
            $ord = 'desc';
        } elseif ($ord == 'desc') {
            $ord = 'asc';
        } else {
            $ord = 'desc';
        }
        $order_str = "&order_by=" . $_REQUEST['order_by'] . "&ord=" . $ord;
    }
    foreach ($column_list as $template_tag) {
        $val = get_template_value($template_tag, 1, $admin);
        //$val = $val.$template_tag;
        if ($column_info[$template_tag]['admin'] == 'Y' && !$admin) {
            continue;
            // do not render this column
        }
        if ($column_info[$template_tag]['trunc'] > 0) {
            $val = truncate_html_str($val, $column_info[$template_tag]['trunc'], $trunc_str_len);
        }
        // process the value depending on what kind of template tag it was given.
        if ($template_tag == 'DATE') {
            $init_date = strtotime(trim_date($val) . " GMT");
            // the last date modified
            $dst_date = strtotime(trim_date(gmdate("r")) . " GMT");
            // now
            if (!$init_date) {
                $days = "x";
            } else {
                $diff = $dst_date - $init_date;
                $days = floor($diff / 60 / 60 / 24);
            }
            //echo $days;
            $FORMATTED_DATE = get_formatted_date(get_local_time($val));
            $val = $FORMATTED_DATE . "<br>";
            if ($days == 0) {
                $val = $val . '<span class="today"><b>' . $label["ads_list_today"] . '</span>';
            } elseif ($days > 0 && $days < 2) {
                $val = $val . '<span class="days_ago">' . $days . " " . $label["ads_list_day_ago"] . "</span>";
            } elseif ($days > 1 && $days < 8) {
                $val = $val . '<span class="days_ago">' . $days . " " . $label["ads_list_days_ago"] . "</span>";
            } elseif ($days >= 8) {
                $val = $val . '<span class="days_ago2">' . $days . " " . $label["ads_list_days_ago"] . "</span>";
            }
        }
        if ($column_info[$template_tag]['is_bold'] == 'Y') {
            $b1 = "<b>";
            $b2 = "</b>";
        } else {
            $b1 = '';
            $b2 = '';
        }
        if ($column_info[$template_tag]['clean'] == 'Y') {
            // fix up punctuation spacing
            $val = preg_replace('/ *(,|\\.|\\?|!|\\/|\\\\) */i', '$1 ', $val);
        }
        if ($column_info[$template_tag]['link'] == 'Y') {
            // Render as a Link to the record?
            $AD_ID = get_template_value('AD_ID', 1, $admin);
            $val = '<a href="' . htmlentities($_SERVER['PHP_SELF']) . '?ad_id=' . $AD_ID . '&offset=' . $cur_offset . $order_str . $q_string . '"';
            /// IMAGE PREVIEW MOUSEOVER Code
            // Note: to have this feature working, you must have a template tag called 'IMAGE' defined in the resume form
            define('PREVIEW_AD', 'YES');
            if (PREVIEW_AD == 'YES') {
                $ALT_TEXT = get_template_value('ALT_TEXT', 1, $admin);
                //$AD_ID = get_template_value ('AD_ID', 1, $admin);
                $js_str = " onmousemove=\"sB(event,'" . htmlspecialchars(str_replace("'", "\\'", $ALT_TEXT)) . "',this, " . $AD_ID . ")\" onmouseout=\"hI()\" ";
                $val = $val . $js_str;
            }
            $val = $val . '>' . get_template_value($template_tag, 1, $admin) . "</a>";
        }
        ?>
		<td class="list_data_cell" <?php 
        if ($column_info[$template_tag]['no_wrap'] == 'Y') {
            echo ' nowrap ';
        }
        ?>
>
			<?php 
        echo $b1 . $val . $b2;
        ?>
		</td>

		<?php 
    }
}