<?
// (c) 2011 RapidComp, Andreas Schmidt & Michael Niendorf GbR
// Das Hosting schliesst automatisch die Akzeptanz eines RapidComp Lizenzvertrages bzw. der AGBs ein,
// der/die unter anderem als Textdokument bei RapidComp GbR erhältlich ist/sind.

 $Geschlecht=getDaten("sex");                           //CamTyp-Filter, optional
 if (!in_array($Geschlecht,array('a','m','w','p','s'))) 
    $Geschlecht='a';

 $Breite=(int)trim(getDaten("w"));                      //Breite in Pixeln (178-1762)
 $Hoehe=(int)trim(getDaten("h"));                       //Höhe in Pixeln (170-1682)

 $Target=getDaten("Target");                            //Ziel zum Klick (click.php)
 $targeturl=getDaten("targeturl");                      //wenn auf 1 dann direkt zur Camprofilseite

 $BGColor=getDaten("BGCol");                            //Hintergrundfarbe Seite
 $piccol=getDaten("piccol");                            //Rahmenfarbe Cover
 $pichovercol=getDaten("pichcol");                      //Rahmenfarbe Cover (Hover)
 $acol=getDaten("acol");                                //Textfarbe Profillink
 $ahover=getDaten("ahcol");                             //Textfarbe Profillink (Hover)

 $t1col=getDaten("t1col");                              //Textfarbe 1. Überschrift
 $t2col=getDaten("t2col");                              //Textfarbe 2. Überschrift
 
 $BorderColor=getDaten("BorderCol");                    //Rahmenfarbe Seite

 $BaseTarget=getDaten("BaseTarget");                    //Zielfenster

 $TeasPFStyle=getDaten("TeasPFStyle");                  //TeaserProfillinkstyle (01, 02 oder 03: 01)
 $TeasPFCol=getDaten("TeasPFCol");                      //TeaserProfillinkfarbe (schw oder w: schw)
 $TeasPFHoverCol=getDaten("TeasPFHCol");                //TeaserProfillinkfarbe (Hover) (gruen, lila, orange, pink, rot, schwarz, tuerkis oder weiss: lila)

 $Skin=getDaten("Skin");                                 //vordefinierte Skin (1-11), optional
 switch($Skin){
     default:     
      if (empty($BorderColor)) $BorderColor="#000000";
      if (empty($BGColor)) $BGColor="#FFFFFF";
      if (empty($t1col)) $t1col="#F700B9";
      if (empty($h2col)) $h2col="#000000";

      if (empty($piccol)) $piccol="#000000";
      if (empty($pichovercol)) $pichovercol="#F700B9";
      if (empty($acol)) $acol="#000000";
      if (empty($ahover)) $ahover="#F700B9";

      if (empty($TeasPFStyle)) $TeasPFStyle="01";
      if (empty($TeasPFCol)) $TeasPFCol="schw";
      if (empty($TeasPFHoverCol)) $TeasPFHoverCol="pink";
      break;
 }
 
 if (!preg_match("/^#[0-9A-F]{6}$/i",$BorderColor)) $BorderColor="#000000";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$BGColor)) $BGColor="#FFFFFF";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$piccol)) $piccol="#F700B9";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$pichovercol)) $pichovercol="#F700B9";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$acol)) $acol="#000000";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$ahover)) $ahover="#F700B9";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$t1col)) $t1col="#F700B9";
 if (!preg_match("/^#[0-9A-F]{6}$/i",$t2col)) $t2col="#000000";
 
 if (!preg_match("/^[_0-9A-Z]+$/i",$BaseTarget)) $BaseTarget="_top";
 
 if ($TeasPFCol!="schw" && $TeasPFCol!="w") $TeasPFCol="schw";
 if ($TeasPFHoverCol!="gruen" && $TeasPFHoverCol!="lila" && $TeasPFHoverCol!="orange" && $TeasPFHoverCol!="pink" && $TeasPFHoverCol!="rot" && $TeasPFHoverCol!="schwarz" && $TeasPFHoverCol!="tuerkis" && $TeasPFHoverCol!="weiss") $TeasPFHoverCol="lila";
 
 if ($TeasPFStyle!="01" && $TeasPFStyle!="02" && $TeasPFStyle!="03") $TeasPFStyle="01";

 function getGeoRegion($LandISO="",$RegionID=0){
    if (strlen($LandISO)>3) $LandISO=substr($LandISO,0,3);
    $RegionID="$RegionID";
    if (strlen($RegionID)>3) $RegionID=substr($RegionID,0,3);
    return str_pad(strtoupper($LandISO),3,'_',STR_PAD_RIGHT).str_pad($RegionID,3,'0',STR_PAD_LEFT);
 }

 $GeoRegionen=array(
    'DE_000'=>array("Deutschland",'karte_deutschland.gif','Deutschland'),
    'DE_001'=>array("Baden-Württemberg",'karte_baden_wuerttemb.gif','Ba.-Wü.'),
    'DE_002'=>array("Bayern",'karte_bayern.gif','Bayern'),
    'DE_003'=>array("Bremen",'karte_bremen.gif','Bremen'),
    'DE_004'=>array("Hamburg",'karte_hamburg.gif','Hamburg'),
    'DE_005'=>array("Hessen",'karte_hessen.gif','Hessen'),
    'DE_006'=>array("Niedersachsen",'karte_niedersachsen.gif','Niedersachsen'),
    'DE_007'=>array("Nordrhein-Westfalen",'karte_nordrhein_westf.gif','NRW'),
    'DE_008'=>array("Rheinland-Pfalz",'karte_rheinland_pfalz.gif','Rheinland-Pfalz'),
    'DE_009'=>array("Saarland",'karte_saarland.gif','Saarland'),
    'DE_010'=>array("Schleswig-Holstein",'karte_schleswig_holstein.gif','SH'),
    'DE_011'=>array("Brandenburg",'karte_brandenburg.gif','Brandenburg'),
    'DE_012'=>array("Mecklenburg-Vorpommern",'karte_meck_vorpomm.gif','MVP'),
    'DE_013'=>array("Sachsen",'karte_sachsen.gif','Sachsen'),
    'DE_014'=>array("Sachsen-Anhalt",'karte_sachsen_anhalt.gif','Sachsen-Anhalt'),
    'DE_015'=>array("Thüringen",'karte_thueringen.gif','Thüringen'),
    'DE_016'=>array("Berlin",'karte_berlin.gif','Berlin')
 );
 
 $Region=getGeoRegion();
 if (!$GeoIP=getDaten("ip")) $GeoIP=$_SERVER['REMOTE_ADDR'];
 if ($GeoDaten=geoip_record_by_name($GeoIP)) $Region=getGeoRegion($GeoDaten['country_code'],(int)$GeoDaten['region']);

 $SourceFile=$Geschlecht."_region$Region.ab16";
 
 if (!file_exists("$relPath/WBMExportData/$SourceFile.php")) $SourceFile="a.ab16";
 
 
 $ElemWidth=83;
 $ElemHeight=80;
 $ElemBorder=2;
 
 $Cams=array();
 @include("$relPath/WBMExportData/stars_$SourceFile.php");
 $StarCams=$Cams;
 
 $Cams=array();
 @include("$relPath/WBMExportData/$SourceFile.php");

 if ($Breite<$ElemWidth*2+2) $Breite=$ElemWidth*2+2;      //2Pixel Border
 if ($Breite>$ElemWidth*10+2) $Breite=$ElemWidth*10+2;    //2Pixel Border
 $ElemsPerRow=floor(($Breite-2)/$ElemWidth);   //2Pixel Border

 $HeaderBreite=$ElemsPerRow*$ElemWidth-$ElemBorder;
 $RestBreite=$HeaderBreite;
 $IconHeight=0;
 $FooterHeight=$Breite>250?10:20;
 $HeaderHeight=$Breite>250?35:35;
 if ($Breite<145) $FooterHeight+=10;

 if (array_key_exists($Region,$GeoRegionen))
     $HeaderHeight+=$Breite>=270?20:40;
 
 if ($Hoehe<$HeaderHeight+$ElemHeight+2) $Hoehe=$HeaderHeight+$ElemHeight+2;        //2Pixel Border 
 if ($Hoehe>$HeaderHeight+$ElemHeight*10+2) $Hoehe=$HeaderHeight+$ElemHeight*10+2;      //2Pixel Border, xPixel Header

 $MaxRows=max(1,floor(($Hoehe-$HeaderHeight-$FooterHeight-2)/$ElemHeight)); //2Pixel Border
 
 $MaxElems=max(1,$ElemsPerRow*$MaxRows);

 $HeadTextWidth=$RestBreite;
 
 $StdLinkParams=" href=\"".htmlentities($Target)."\" target=\"".htmlentities($BaseTarget)."\"";
     
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CamDorado</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
BODY {
    margin:0px;
    padding:0px;
    background-color: <? Print $BGColor;?>;    
}

.MainFrame {
    border: 1px solid <? Print $BorderColor;?>;
    width:<? Print ($Breite-2)?>px;    
    height: <? Print ($Hoehe-2)?>px;    
    text-align:center;
    font-family: Arial,Helvetica; 
    font-size: 11px;
}


.divteaser_79_72{
    width:79px;
    float:left;
    display:block;
    margin: 2px;
    height: 72px;
}
.txt{
    font-family:Tahoma;
   font-style:normal;  
   font-size: 16px;
    color: #F700B9;
    margin: 0px 0px 0px 0px;
}
.txt_1{
    font-family:Tahoma;
   font-style:normal;  
   font-size: 16px;
    color: #000000;
    margin: 0px 0px 0px 0px;
}
.txt_2{
    font-family: Tahoma;
   font-style: normal;  
   font-size: 23px;
    color: #F700B9;
    margin: 0px 0px 0px 0px;
}

.txt {  font-family:Tahoma;font-style:normal;font-size:16px;margin:0px;color: <? Print $t1col;?>;}
.txt_1 { font-family:Tahoma;font-style:normal;font-size:16px;margin:0px;color: <? Print $t2col;?>;}
.txt_2 { font-family:Tahoma;font-style:normal;font-size:23px;margin:0px;color: <? Print $t1col;?>;}

.bildrahmen {text-decoration:none;}
.bildrahmen img {border:1px solid <? Print $piccol;?>}
.bildrahmen:hover img { border-color: <? Print $pichovercol;?>}
.divteaser_79_72 .CamNick {position:relative;white-space:nowrap;width:74px;overflow:hidden;}
.divteaser_79_72 .CamNick a{ text-decoration:none;white-space:nowrap;color:<? Print $acol;?>}
.divteaser_79_72 .CamNick a:hover{ color:<? Print $ahover;?>;}

.special_link {overflow:hidden;width:<? Print ($Breite-2)?>px;text-align:center;}
.special_link a{
    background-image: url('./images/pfeil_<? Print $TeasPFCol;?>_<? Print $TeasPFHoverCol;?><? Print $TeasPFStyle;?>.gif');
    background-repeat: no-repeat;
    background-position: right 3px;
    padding: 0px 12px 0px 0px;
    font-family: Tahoma;
    font-weight: bold;
    font-size: 12px;
    color: <? Print $acol;?>;
    text-decoration: none;
    text-transform: uppercase;
    
}
.special_link a:hover{
    background-position: right -20px;
    color: <? Print $ahover;?>;
}

</style>
<script src="./js/Mover.js" type="text/javascript"></script>
</head>
<body>
<div class="MainFrame">
<div style="height:<? Print $HeaderHeight;?>px;overflow:hidden;">
 <div class="txt"><b>CamDorado.com</b></div>
<? if (array_key_exists($Region,$GeoRegionen)){?>
 <div class="txt_1">Camgirls aus <? Print htmlentities($GeoRegionen[$Region][2]);?> und Umgebung</div><? }?>
</div>
<div style="margin: 0px auto; width:<? Print $ElemsPerRow*$ElemWidth;?>px;">
<?

$StarCams=array_values($StarCams);
$Cams=array_values($Cams);$IndexList=array();

$StarCntNeeded=0;
if ($MaxElems>count($Cams)) $StarCntNeeded=count($Cams)-$MaxElems;
else $StarCntNeeded=floor($MaxElems/5);

if (count($Cams)>1) $StarCntNeeded++;
$StarCntNeeded=min($StarCntNeeded,count($StarCams));

$TmpCams=array();
while (count($TmpCams)<$MaxElems && count($StarCams)>0 &&  $StarCntNeeded>0){
     $RandValStars=rand(0,count($StarCams)-1);
     $TmpCams[rand(1,10000)]=$StarCams[$RandValStars];
     array_splice($StarCams,$RandValStars,1);
     $StarCntNeeded--;
}

while (count($IndexList)<min($MaxElems-count($TmpCams),count($Cams))){
    $RandVal=rand(0,count($Cams)-1);
    if (!in_array($RandVal,$IndexList)) $IndexList[]=$RandVal;
}

$TCnt=0;

foreach($IndexList AS $k) $TmpCams[rand(1,10000)]=$Cams[$k];

ksort($TmpCams);

foreach($TmpCams AS $Data){
 $LinkTarget=$Target;
 $CamID=$Data['ID'];
 if (!empty($targeturl))
  $LinkTarget.="&turl=".urlencode("http://www.camdorado.com/free/indexCam".$CamID.".html");


 $LinkParams=" href=\"".htmlentities($LinkTarget)."\" target=\"".htmlentities($BaseTarget)."\"";
?>
<div class="divteaser_79_72">
<a<? Print $LinkParams;?> class="bildrahmen"><img src="<? Print "$absPath/CamPics/".htmlentities($CamID)."_77x52px.jpg";?>" width="77" height="52" border="0" alt=""></a>
<div class="CamNick"><a<? Print $LinkParams;?> onmouseover="StartMover(this);" onmouseout="StopMover(this);"><? Print htmlentities($Data['Nick']);?></a></div>
</div>
<? }?>
<div style="clear:both;"></div></div>
<? if (!array_key_exists($Region,$GeoRegionen)){?>
<div class="special_link" align="right"><a <? Print $StdLinkParams;?> onmouseover="StartMover(this);" onmouseout="StopMover(this);">mehr Girls aus deiner Region</a></div>
<? }else{?>
<div class="special_link" align="right"><a <? Print $StdLinkParams;?> onmouseover="StartMover(this);" onmouseout="StopMover(this);">mehr Girls aus <? Print htmlentities($GeoRegionen[$Region][2]);?></a></div>
<? }?>
</div>
</body>
</html>