".__LINE__." - Invalid query: ". mysql_error() ."
"; include("functions.php"); # Load extra configuration $q = q("select * from config"); while ($r = a($q)) { $config[$r['name']] = $r['value']; } $tpl = $config['tpl']; ## session_start(); ob_start(); if (get_magic_quotes_gpc()) { strips($_GET); strips($_POST); strips($_COOKIE); strips($_REQUEST); if (isset($_SERVER['PHP_AUTH_USER'])) strips($_SERVER['PHP_AUTH_USER']); if (isset($_SERVER['PHP_AUTH_PW'])) strips($_SERVER['PHP_AUTH_PW']); } #error_reporting(E_ALL); #ini_set('display_errors', 1); # Set the list of ads displayed $ads_ids = array(); $ads_importance = array(); $layout_id = 0; switch ($_GET['type']) { case 'website': $r = aq("select * from wbs where nr_crt='".$_GET['id']."'"); // halt if the website is disabled if ($r['status'] == 0) { exit; } // set layout if override if ($r['override'] == 1) { $layout_id = $r['layout_id']; } // get ad list $q = q("select * from ads where wbs_id='".$_GET['id']."' and status='1'"); while ($r = a($q)) { $ads_ids[$r['nr_crt']] = $r['nr_crt']; $ads_importance[$r['nr_crt']] = $r['weight']; } break; case 'ad': $r = aq("select * from ads where nr_crt='".$_GET['id']."' and status='1'"); $ads_ids[$r['nr_crt']] = $r['nr_crt']; $ads_importance[$r['nr_crt']] = $r['weight']; // set layout $layout_id = $r['layout_id']; // halt if the website is disabled $r = aq("select * from wbs where nr_crt='".$r['wbs_id']."'"); if ($r['status'] == 0) { exit; } break; default: echo "Error!"; exit; } #### HALT IF THERE ARE NO RESULTS if (count($ads_ids) == 0) { exit; } #### # NUMBER OF DISPLAYS if (!is_numeric($_SESSION['i'])) { $_SESSION[i] = '1'; } else { $_SESSION['i']++; } #select the ads from the database; probability algoritm $list = array(); foreach ($ads_ids as $id) { for ($a=1;$a<=$ads_importance[$id];$a++) { $list[] = $id; } } //--> imbunatatire: sa se tina cont de numarul de afisari al fiecarei reclame $total = count($list) - 1; $id = rand(0,$total); $ad = aq("select * from ads where nr_crt='".$list[$id]."'"); if (!is_numeric($layout_id) || $layout_id <= 0) { $layout_id = $ad['layout_id']; } $layout = aq("select * from layout where nr_crt='".$layout_id."'"); # HALT IF DISPLAY LIMMITATIONS IN EFFECT $views = $_SESSION['i']; if ($ad['sa_s'] == 1 && $ad['sa_v'] <= $views) { exit; } if ($ad['saf_s'] == 1 && $ad['saf_v'] > $views) { exit; } # UPDATE STATS // user (ip) $ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); $nr = nr("select count(*) from stats_usr where ip='".$ip."'"); if ($nr == 0) { q("insert into stats_usr(ip,c,i,data_activ) values('".$ip."','0','0','".time()."')"); } $r = aq("select * from stats_usr where ip='".$ip."'"); $usr_id = $r['nr_crt']; q("update stats_usr set data_activ='".time()."' where nr_crt='".$usr_id."'"); // referer if (strlen($_SERVER['HTTP_REFERER']) > 0) { $ref = $_SERVER['HTTP_REFERER']; $nr = nr("select count(*) from stats_ref where adr='".$ref."'"); if ($nr == 0) { q("insert into stats_ref(adr,data_activ) values('".$ref."','".time()."')"); } $r = aq("select * from stats_ref where adr='".$ref."'"); $ref_id = $r['nr_crt']; q("update stats_ref set data_activ='".time()."' where nr_crt='".$ref_id."'"); } else { $ref_id = '0'; } // update stats q("insert into stats(wbs_id,ad_id,usr_id,ref_id,data,tip) values('".$ad['wbs_id']."','".$ad['nr_crt']."','".$usr_id."','".$ref_id."','".time()."','1')"); q("update stats_usr set i=i+1 where nr_crt='".$usr_id."'"); q("update ads set i=i+1 where nr_crt='".$ad['nr_crt']."'"); q("update wbs set i=i+1 where nr_crt='".$ad['wbs_id']."'"); if ($ad['disable_link'] == 1) { q("update wbs set i=i-1 where nr_crt='".$ad['wbs_id']."'"); } ### # Create code from .tpl file $template = new Template("data"); $template->set_filenames(array( 'base' => 'stripead.tpl') ); // assign normal variables if ($ad['disable_link'] == 0) { $template->assign_block_vars('link',array()); } else { $template->assign_block_vars('nolink',array()); } if ($ad['direct_link'] == 1) { $link = $ad['link']; } else { $link = $config['site_url']."redirect.php?id=".$ad['nr_crt']."&to=".base64_encode($ad['link']); } if ($ad['oinw'] == 1) { $target = '_blank'; } else { $target = '_self'; } if ($layout['b'] == 'bold') { $bold = 'bold'; } else { $bold = 'normal'; } if ($layout['i'] == 'italic') { $italic = 'italic'; } else { $italic = 'normal'; } if ($layout['u'] == 'underline') { $underline = 'underline'; $opposite_decoration = 'none'; } else { $underline = 'none'; $opposite_decoration = 'underline'; } if ($layout['stt'] == 1) { $stick = "yes"; } else { $stick = "no"; } $template->assign_vars(array( 'titlu'=>$ad['titlu'], 'link'=>$link, 'target'=>$target, 'site_url'=>$config['site_url'], 'font'=>$layout['font'], 'size'=>$layout['size'], 'text_color'=>$layout['text_color'], 'bg_color'=>$layout['bg_color'], 'border_color'=>$layout['border_color'], 'text_align'=>$layout['text_align'], 'style'=>$italic, 'weight'=>$bold, 'decoration'=>$underline, 'opposite_decoration'=>$opposite_decoration, 'stick'=>$stick )); $template->pparse('base'); # Display ad $output = ob_get_contents(); ob_clean(); switch ($_GET['mode']) { case 'javascript': $maxlinelength = "100"; $charposition = 0; if ($javascript == true) { echo $javascript_text; } while ($charposition <= strlen($output)) { $text = substr($output,$charposition,$maxlinelength); $text = str_replace(array('"'),array('\"'),$text); $text = str_replace(array("\n","\t","\r"),"",$text); echo 'document.write("'.$text.'");'."\n"; $charposition = $charposition + $maxlinelength; } break; case 'php': echo $output; break; default: echo "Error!"; exit; } ?>