&mode=, * где: * * $_GET['siteId'] - Идентификатор сайта, с которого пришел запрос. * $_GET['mode'] - Режим показа 0 - вертикальный 1 - горизонтальный, по умолчанию - 0. * * $_GET['nojs'] - Недокументируемый параметр. Если указан, вместо * JavaScript-a выдается HTML (For debuging) * * Script uses three additional scrips: * 1. show_findspends.php - Find banners by users competition. Generates array "$banners". * 2. show_findrandom.php - Find banners in random way. Generates array "$banners". * 3. show_output.php - Outputs array "$banners". * * About array "$banners" see comments in these scripts. */ require_once (dirname (__FILE__) . '/config.php'); /* * Main code goes here: */ // 1) Preparation: // Seed the random generator with microseconds (this seems to be good enougth): list ($usec, $sec) = explode (' ', microtime ()); srand ((float) $sec + ((float) $usec * 100000)); // Connect to database: if (@ mysql_connect ($cfg['mySqlHost'], $cfg['mySqlUser'], $cfg['mySqlPass']) == false) return; mysql_query("SET NAMES CP1251"); if (@ mysql_select_db ($cfg['mySqlBase']) == false) return; // 2) Check 'showMode': $showMode = 'silent'; //Do not show banners if DB corrupted or connection failed. $result = mysql_query ("SELECT showMode FROM orbnRuntimeConfig LIMIT 1 ;"); if ($result) $showMode = mysql_result ($result, 0, 0); if ($showMode == 'silent') return; //Show nothing // If showMode == random or siteId is not provided - show banners in random way: if (($showMode == 'random') || !isset ($_GET['siteId'])) { include (dirname (__FILE__) . '/show_findrandom.php'); include (dirname (__FILE__) . '/show_output.php'); return; } $siteId = $_GET['siteId']; // 3) Increase site's `visited` field & test whether the site exists and not blocked: mysql_query ("UPDATE orbnSites SET visited = visited + 1 WHERE (siteId = '$siteId') AND (blocked != '1') LIMIT 1 ;"); if (mysql_affected_rows () != 1) { //Site $siteId does not exists - show random: include (dirname (__FILE__) . '/show_findrandom.php'); include (dirname (__FILE__) . '/show_output.php'); return; } // 4) Find banners by spend & output to user: include (dirname (__FILE__) . '/show_findspends.php'); include (dirname (__FILE__) . '/show_output.php'); // 5) Register shows in database: $bannersCount = count ($banners); if ($bannersCount < 1) return; // Update `shows` field for caller site: shows += $bannersCount mysql_query ("UPDATE orbnSites SET shows = shows + $bannersCount WHERE siteId = '$siteId' LIMIT 1 ;"); // Find owner of the caller site & increase his raise: $raise += $bannersCount $result = mysql_query ("SELECT userId FROM orbnSites WHERE ( siteId = $siteId ) LIMIT 1 ;"); if ($result) { $siteOwnerId = mysql_result ($result, 0, 0); mysql_query ("UPDATE orbnUsers SET raise = raise + $bannersCount WHERE userId = '$siteOwnerId' LIMIT 1 ;"); } // A) Update `showed*` fields for corresponding spends and banners table: // B) Update user's `spend` field: $commissionSpend = 0; foreach ($banners as $banner) { $spendTable = $banner['spendTable']; $spendIdName = $banner['spendIdName']; $spendId = $banner['spendId']; $spendOwner = $banner['userId']; $bannerTable = $banner['bannerTable']; $bannerIdName = $banner['bannerIdName']; $bannerId = $banner['bannerId']; // A) Update `showed*` fields for corresponding spends and banners table: mysql_query ("UPDATE $spendTable SET showed = showed + 1 WHERE $spendIdName = $spendId LIMIT 1 ;"); if ($spendTable == 'orbnFund') mysql_query ("UPDATE $bannerTable SET showedByFund = showedByFund + 1 WHERE $bannerIdName = $bannerId LIMIT 1 ;"); // B) Update user's `spend` field (or count commissionSpend): if ($banner['commissionSpend']) { ++$commissionSpend; continue; } mysql_query ("UPDATE orbnUsers SET spend = spend + 1 WHERE userId = $spendOwner LIMIT 1 ;"); } // Register commissionSpend: if ($commissionSpend > 0) mysql_query ("UPDATE orbnUsers SET commissionSpend = commissionSpend + $commissionSpend WHERE userId = 0 LIMIT 1 ;"); ?>