function phpAds_buildBannerCode($bannerid, $fullpreview = false)
{
    global $strShowBanner, $strLogin;
    global $phpAds_config;
    global $phpAds_TextAlignLeft, $phpAds_TextAlignRight;
    $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tbannerid = '" . $bannerid . "'\n\t");
    $row = phpAds_dbFetchArray($res);
    if ($fullpreview || $phpAds_config['gui_show_banner_preview']) {
        // Determine target
        if ($row['target'] == '') {
            if (!isset($target) || $target == '') {
                $target = '_blank';
            }
            // default
        } else {
            $target = $row['target'];
        }
        // Replace url_prefix
        $row['htmlcache'] = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $row['htmlcache']);
        switch ($row['storagetype']) {
            case 'html':
                if ($fullpreview || $phpAds_config['gui_show_banner_html']) {
                    $htmlcode = $row['htmlcache'];
                    $htmlcode = str_replace('{bannerid}', $bannerid, $htmlcode);
                    $htmlcode = str_replace('{zoneid}', '', $htmlcode);
                    $htmlcode = str_replace('{source}', '', $htmlcode);
                    $htmlcode = str_replace('{target}', $target, $htmlcode);
                    $htmlcode = str_replace('[bannertext]', '', $htmlcode);
                    $htmlcode = str_replace('[/bannertext]', '', $htmlcode);
                    $htmlcode = phpAds_replaceVariablesInBannerCode($htmlcode);
                    $buffer = $htmlcode;
                } else {
                    $htmlcode = str_replace("\n", '', stripslashes($row['htmltemplate']));
                    $htmlcode = strlen($htmlcode) > 500 ? substr($htmlcode, 0, 500) . "..." : $htmlcode;
                    $htmlcode = chunk_split($htmlcode, 65, "\n");
                    $htmlcode = str_replace("\n", "<br>\n", htmlspecialchars($htmlcode));
                    $buffer = "<img src='images/break-el.gif' height='1' width='100%' vspace='5'><br>";
                    $buffer .= "<table border='0' cellspacing='0' cellpadding='0'><tr>";
                    $buffer .= "<td width='80%' valign='top' align='" . $phpAds_TextAlignLeft . "'>\n";
                    $buffer .= $htmlcode;
                    $buffer .= "\n</td>";
                    $buffer .= "<td width='20%' valign='top' align='" . $phpAds_TextAlignLeft . "' nowrap>&nbsp;&nbsp;";
                    $buffer .= "<a href='banner-htmlpreview.php?bannerid={$bannerid}' target='_new' ";
                    $buffer .= "onClick=\"return openWindow('banner-htmlpreview.php?bannerid=" . $bannerid . "', '', 'status=no,scrollbars=no,resizable=no,width=" . ($row['width'] + 64) . ",height=" . ($row['bannertext'] ? $row['height'] + 80 : $row['height'] + 64) . "');\">";
                    $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0'>&nbsp;" . $strShowBanner . "</a>&nbsp;&nbsp;</td>";
                    $buffer .= "</tr></table>";
                }
                break;
            case 'network':
                if (ereg("\\[title\\]([^\\[]*)\\[\\/title\\]", $row['htmltemplate'], $matches)) {
                    $title = $matches[1];
                }
                if (ereg("\\[logo\\](.*)\\[\\/logo\\]", $row['htmltemplate'], $matches)) {
                    $logo = $matches[1];
                }
                if (ereg("\\[login\\](.*)\\[\\/login\\]", $row['htmltemplate'], $matches)) {
                    $login = $matches[1];
                }
                $buffer = "<img src='images/break-l.gif' height='1' width='468' vspace='6'>";
                $buffer .= "<table width='468' cellpadding='0' cellspacing='0' border='0'><tr>";
                $buffer .= "<td valign='bottom'><img src='networks/logos/" . $logo . "'>&nbsp;&nbsp;&nbsp;</td>";
                $buffer .= "<td valign='bottom' align='" . $phpAds_TextAlignRight . "'><br><b>" . $title . "</b>&nbsp;&nbsp;&nbsp;<a href='" . $login . "' target='_blank'>";
                $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0' vspace='2'> " . $strLogin . "</a></td>";
                $buffer .= "</tr></table>";
                $buffer .= "<img src='images/break-l.gif' height='1' width='468' vspace='6'>";
                break;
            default:
                $htmlcode = $row['htmlcache'];
                // Set basic variables
                $htmlcode = str_replace('{bannerid}', $row['bannerid'], $htmlcode);
                $htmlcode = str_replace('{zoneid}', '', $htmlcode);
                $htmlcode = str_replace('{source}', '', $htmlcode);
                $htmlcode = str_replace('{target}', $target, $htmlcode);
                $htmlcode = str_replace('[bannertext]', '', $htmlcode);
                $htmlcode = str_replace('[/bannertext]', '', $htmlcode);
                if ($row['storagetype'] == 'url') {
                    $htmlcode = phpAds_replaceVariablesInBannerCode($htmlcode);
                }
                $buffer = $htmlcode;
                break;
        }
        // Remove appended HTML for the preview
        if (strlen($row['append'])) {
            $buffer = str_replace($row['append'], '', $buffer);
        }
        // If the HTML contains ActiveX code we need
        // to use a JavaScript workaround because the outcome of the Eolas lawsuit
        // agains Microsoft. Without these changes the user would get a warning dialogbox.
        if ($fullpreview && !(strpos(strtolower($row['htmlcache']), "<object") === false) && (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !strstr($_SERVER['HTTP_USER_AGENT'], 'Opera'))) {
            $activexbuffer = "<script language='JavaScript' type='text/javascript' src='{url_prefix}/adx.js'></script>";
            $activexbuffer .= "<script language='JavaScript' type='text/javascript'>\n";
            $activexbuffer .= "<!--\n";
            $activexbuffer .= "var phpads_activex = \"";
            $activexbuffer .= str_replace('</', '<"+"/', addcslashes($buffer, "..\"\\"));
            $activexbuffer .= "\";\n";
            $activexbuffer .= "phpads_deliverActiveX(phpads_activex);\n";
            $activexbuffer .= "//-->\n";
            $activexbuffer .= "</script>";
            $buffer = $activexbuffer;
        }
    } else {
        if ($row['contenttype'] == 'txt') {
            $width = 300;
            $height = 200;
        } else {
            $width = $row['width'] + 64;
            $height = $row['bannertext'] ? $row['height'] + 90 : $row['height'] + 64;
        }
        $buffer = "<img src='images/break-el.gif' height='1' width='100%' vspace='5'><br>";
        $buffer .= "<a href='banner-htmlpreview.php?bannerid={$bannerid}' target='_new' ";
        $buffer .= "onClick=\"return openWindow('banner-htmlpreview.php?bannerid=" . $bannerid . "', '', 'status=no,scrollbars=no,resizable=no,width=" . $width . ",height=" . $height . "');\">";
        $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0'>&nbsp;" . $strShowBanner . "</a>&nbsp;&nbsp;";
    }
    // Disable logging of adclicks
    $buffer = str_replace('adclick.php?', 'adclick.php?log=no&', $buffer);
    $buffer = str_replace('adclick.php%3F', 'adclick.php%3Flog=no%26', $buffer);
    $buffer = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $buffer);
    return $buffer;
}
 echo "<body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#EFEFEF'>";
 echo "<table cellpadding='0' cellspacing='0' border='0'>";
 echo "<tr height='32'><td width='32'><img src='images/cropmark-tl.gif' width='32' height='32'></td>";
 echo "<td background='images/ruler-top.gif'>&nbsp;</td><td width='32'><img src='images/cropmark-tr.gif' width='32' height='32'></td></tr>";
 echo "<tr height='" . $row['height'] . "'><td width='32' background='images/ruler-left.gif'>&nbsp;</td><td bgcolor='#FFFFFF' width='" . $row['width'] . "'>";
 if ($row['contenttype'] == 'html') {
     $htmlcode = $row['htmlcache'];
     // Basic modifications
     $htmlcode = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $htmlcode);
     $htmlcode = str_replace('{bannerid}', $bannerid, $htmlcode);
     $htmlcode = str_replace('{zoneid}', '', $htmlcode);
     $htmlcode = str_replace('{source}', '', $htmlcode);
     $htmlcode = str_replace('{target}', '_blank', $htmlcode);
     $htmlcode = str_replace('[bannertext]', '', $htmlcode);
     $htmlcode = str_replace('[/bannertext]', '', $htmlcode);
     $htmlcode = phpAds_replaceVariablesInBannerCode($htmlcode);
     // Remove appended HTML for the preview
     $htmlcode = str_replace($row['append'], '', $htmlcode);
     // Disable logging of adclicks
     $htmlcode = str_replace('adclick.php?', 'adclick.php?log=no&', $htmlcode);
 } else {
     $htmlcode = phpAds_buildBannerCode($row['bannerid'], true);
 }
 // Output banner
 echo $htmlcode;
 echo "</td><td width='32'>&nbsp;</td></tr>";
 echo "<tr height='32'><td width='32'><img src='images/cropmark-bl.gif' width='32' height='32'></td><td>";
 if ($row['contenttype'] == 'txt') {
     echo "&nbsp;";
 } else {
     echo "&nbsp;&nbsp;&nbsp;width: " . $row['width'] . "&nbsp;&nbsp;height: " . $row['height'] . "&nbsp" . ($row['bannertext'] ? '+ text&nbsp;' : '');
function phpAds_buildBannerCode($bannerid, $fullpreview = false)
{
    global $strShowBanner, $strLogin;
    global $phpAds_config;
    global $phpAds_TextAlignLeft, $phpAds_TextAlignRight;
    $res = phpAds_dbQuery("\n\t\tSELECT\n\t\t\t*\n\t\tFROM\n\t\t\t" . $phpAds_config['tbl_banners'] . "\n\t\tWHERE\n\t\t\tbannerid = '" . $bannerid . "'\n\t");
    $row = phpAds_dbFetchArray($res);
    if ($fullpreview || $phpAds_config['gui_show_banner_preview']) {
        if ($row['active'] == "f") {
            echo "<div style='filter: Alpha(Opacity=50)'>";
        }
        // Determine target
        if ($row['target'] == '') {
            if (!isset($target) || $target == '') {
                $target = '_blank';
            }
            // default
        } else {
            $target = $row['target'];
        }
        // Replace url_prefix
        $row['htmlcache'] = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $row['htmlcache']);
        // Replace image_url_prefix
        $row['htmlcache'] = str_replace('{image_url_prefix}', $phpAds_config['type_web_url'], $row['htmlcache']);
        switch ($row['storagetype']) {
            case 'html':
                if ($phpAds_config['gui_show_banner_html']) {
                    $htmlcode = $row['htmlcache'];
                    $htmlcode = str_replace('{bannerid}', $bannerid, $htmlcode);
                    $htmlcode = str_replace('{zoneid}', '', $htmlcode);
                    $htmlcode = str_replace('{source}', '', $htmlcode);
                    $htmlcode = str_replace('{target}', $target, $htmlcode);
                    $htmlcode = str_replace('[bannertext]', '', $htmlcode);
                    $htmlcode = str_replace('[/bannertext]', '', $htmlcode);
                    $htmlcode = phpAds_replaceVariablesInBannerCode($htmlcode);
                    $buffer = $htmlcode;
                } else {
                    $htmlcode = str_replace("\n", '', stripslashes($row['htmltemplate']));
                    $htmlcode = strlen($htmlcode) > 500 ? substr($htmlcode, 0, 500) . "..." : $htmlcode;
                    $htmlcode = chunk_split($htmlcode, 65, "\n");
                    $htmlcode = str_replace("\n", "<br>\n", htmlspecialchars($htmlcode));
                    $buffer = "<img src='images/break-el.gif' height='1' width='100%' vspace='5'><br>";
                    $buffer .= "<table border='0' cellspacing='0' cellpadding='0'><tr>";
                    $buffer .= "<td width='80%' valign='top' align='" . $phpAds_TextAlignLeft . "'>\n";
                    $buffer .= $htmlcode;
                    $buffer .= "\n</td>";
                    $buffer .= "<td width='20%' valign='top' align='" . $phpAds_TextAlignLeft . "' nowrap>&nbsp;&nbsp;";
                    $buffer .= "<a href='banner-htmlpreview.php?bannerid={$bannerid}' target='_new' ";
                    $buffer .= "onClick=\"return openWindow('banner-htmlpreview.php?bannerid=" . $bannerid . "', '', 'status=no,scrollbars=no,resizable=no,width=" . ($row['width'] + 64) . ",height=" . ($row['bannertext'] ? $row['height'] + 80 : $row['height'] + 64) . "');\">";
                    $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0'>&nbsp;" . $strShowBanner . "</a>&nbsp;&nbsp;</td>";
                    $buffer .= "</tr></table>";
                }
                break;
            case 'network':
                if (ereg("\\[title\\]([^\\[]*)\\[\\/title\\]", $row['htmltemplate'], $matches)) {
                    $title = $matches[1];
                }
                if (ereg("\\[logo\\](.*)\\[\\/logo\\]", $row['htmltemplate'], $matches)) {
                    $logo = $matches[1];
                }
                if (ereg("\\[login\\](.*)\\[\\/login\\]", $row['htmltemplate'], $matches)) {
                    $login = $matches[1];
                }
                $buffer = "<img src='images/break-l.gif' height='1' width='468' vspace='6'>";
                $buffer .= "<table width='468' cellpadding='0' cellspacing='0' border='0'><tr>";
                $buffer .= "<td valign='bottom'><img src='networks/logos/" . $logo . "'>&nbsp;&nbsp;&nbsp;</td>";
                $buffer .= "<td valign='bottom' align='" . $phpAds_TextAlignRight . "'><br><b>" . $title . "</b>&nbsp;&nbsp;&nbsp;<a href='" . $login . "' target='_blank'>";
                $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0' vspace='2'> " . $strLogin . "</a></td>";
                $buffer .= "</tr></table>";
                $buffer .= "<img src='images/break-l.gif' height='1' width='468' vspace='6'>";
                break;
            default:
                $htmlcode = $row['htmlcache'];
                // Set basic variables
                $htmlcode = str_replace('{bannerid}', $row['bannerid'], $htmlcode);
                $htmlcode = str_replace('{zoneid}', '', $htmlcode);
                $htmlcode = str_replace('{source}', '', $htmlcode);
                $htmlcode = str_replace('{target}', $target, $htmlcode);
                $htmlcode = str_replace('[bannertext]', '', $htmlcode);
                $htmlcode = str_replace('[/bannertext]', '', $htmlcode);
                if ($row['storagetype'] == 'url') {
                    $htmlcode = phpAds_replaceVariablesInBannerCode($htmlcode);
                }
                $buffer = $htmlcode;
                break;
        }
        // Remove appended HTML for the preview
        $buffer = str_replace($row['append'], '', $buffer);
        if ($row['active'] == "f") {
            echo "</div>";
        }
        //if (!$bannertext == "")
        //	$buffer .= "<br>".$bannertext;
    } else {
        if ($row['contenttype'] == 'txt') {
            $width = 300;
            $height = 200;
        } else {
            $width = $row['width'] + 64;
            $height = $row['bannertext'] ? $row['height'] + 90 : $row['height'] + 64;
        }
        $buffer = "<img src='images/break-el.gif' height='1' width='100%' vspace='5'><br>";
        $buffer .= "<a href='banner-htmlpreview.php?bannerid={$bannerid}' target='_new' ";
        $buffer .= "onClick=\"return openWindow('banner-htmlpreview.php?bannerid=" . $bannerid . "', '', 'status=no,scrollbars=no,resizable=no,width=" . $width . ",height=" . $height . "');\">";
        $buffer .= "<img src='images/icon-zoom.gif' align='absmiddle' border='0'>&nbsp;" . $strShowBanner . "</a>&nbsp;&nbsp;";
    }
    // Disable logging of adclicks
    $buffer = str_replace('adclick.php?', 'adclick.php?log=no&', $buffer);
    return $buffer;
}