<?
  global $specialbanners;
  global $normalbanners;
  global $minibanners;
  
  function notexpired($date_set){
	$Date_1=date("Y-m-d"); 
	$Date_2=$date_set; 
	$Date_List_1=explode("-",$Date_1); 
	$Date_List_2=explode("-",$Date_2); 
	$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]); 
	$d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]); 	
	$Days=round(($d2-$d1)/3600/24);
	
	if ($Days>0 )
	{ return true; }
	 else 
	 { return false;}
	} 
  
function get_specialbanners ()
  {
    $s = array ();
    $file = fopen ('adsadmin/specialbanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    return $s;
  }

  function save_specialbanners ()
  {
    global $specialbanners;
    $s = array ();
    $file = fopen ('adsadmin/specialbanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    $file = fopen ('adsadmin/specialbanners.php', 'w');
    reset ($specialbanners);
    fputs ($file, '<?/*
');
    while (list ($kk, $vv) = each ($specialbanners))
    {
      if ($kk != 'logged')
      {
        if (!preg_match ('/_generated/', $kk))
        {
          fputs ($file, (('' . $kk . '	') . $vv . '
'));
          continue;
        }

        continue;
      }
    }

    fputs ($file, '*/?>
');
    fclose ($file);
  }
  
  function get_normalbanners ()
  {
    $s = array ();
    $file = fopen ('adsadmin/normalbanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    return $s;
  }

  function save_normalbanners ()
  {
    global $normalbanners;
    $s = array ();
    $file = fopen ('adsadmin/normalbanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    $file = fopen ('adsadmin/normalbanners.php', 'w');
    reset ($normalbanners);
    fputs ($file, '<?/*
');
    while (list ($kk, $vv) = each ($normalbanners))
    {
      if ($kk != 'logged')
      {
        if (!preg_match ('/_generated/', $kk))
        {
          fputs ($file, (('' . $kk . '	') . $vv . '
'));
          continue;
        }

        continue;
      }
    }

    fputs ($file, '*/?>
');
    fclose ($file);
  }
  
  function get_minibanners ()
  {
    $s = array ();
    $file = fopen ('adsadmin/minibanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    return $s;
  }

  function save_minibanners ()
  {
    global $minibanners;
    $s = array ();
    $file = fopen ('adsadmin/minibanners.php', 'r');
    if ($file)
    {
      while ($buf = fgets ($file, 20000))
      {
        $buf = chop ($buf);
        if (($buf != '<?/*' AND $buf != '*/?>'))
        {
          list ($kk, $vv) = split ('	', $buf, 2);
          $s[$kk] = $vv;
          continue;
        }
      }
    }

    fclose ($file);
    $file = fopen ('adsadmin/minibanners.php', 'w');
    reset ($minibanners);
    fputs ($file, '<?/*
');
    while (list ($kk, $vv) = each ($minibanners))
    {
      if ($kk != 'logged')
      {
        if (!preg_match ('/_generated/', $kk))
        {
          fputs ($file, (('' . $kk . '	') . $vv . '
'));
          continue;
        }

        continue;
      }
    }

    fputs ($file, '*/?>
');
    fclose ($file);
  }
  
  
  
    $get = $HTTP_GET_VARS;
  $post = $HTTP_POST_VARS;
  $frm = array_merge ($get, $post);
  
  if ($frm['a'] == 'specialbanners')
  {
  $specialbanners=get_specialbanners();
  	if (($frm['action'] == 'save'))
	{
		for($i=1;$i<=5;$i++)
		{
		$specialbanners['enable_special'.$i] = $frm['enable_special'.$i];
		$specialbanners['name_special'.$i] = $frm['name_special'.$i];
		$specialbanners['url_special'.$i] = $frm['url_special'.$i];
		$specialbanners['imgurl_special'.$i] = $frm['imgurl_special'.$i];
		$specialbanners['expireddate_special'.$i] = $frm['expireddate_special'.$i];
		$specialbanners['description_special'.$i] = $frm['description_special'.$i];
		}
					
	  	save_specialbanners ();
      	header ('Location: ?a=specialbanners');
      	exit ();
	}
  }
  
    if ($frm['a'] == 'normalbanners')
  {
    $normalbanners=get_normalbanners();
  	if (($frm['action'] == 'save'))
	{
		for($i=1;$i<=10;$i++)
		{
		$normalbanners['enable_normal'.$i] = $frm['enable_normal'.$i];
		$normalbanners['name_normal'.$i] = $frm['name_normal'.$i];
		$normalbanners['url_normal'.$i] = $frm['url_normal'.$i];
		$normalbanners['imgurl_normal'.$i] = $frm['imgurl_normal'.$i];
		$normalbanners['expireddate_normal'.$i] = $frm['expireddate_normal'.$i];
		$normalbanners['description_normal'.$i] = $frm['description_normal'.$i];
		}

	  	save_normalbanners ();
      	header ('Location: ?a=normalbanners');
      	exit ();
	}
  }
  
     if ($frm['a'] == 'minibanners')
  {
    $minibanners=get_minibanners();
  	if (($frm['action'] == 'save'))
	{
		for($i=1;$i<=10;$i++)
		{
		$minibanners['enable_mini'.$i] = $frm['enable_mini'.$i];
		$minibanners['name_mini'.$i] = $frm['name_mini'.$i];
		$minibanners['url_mini'.$i] = $frm['url_mini'.$i];
		$minibanners['imgurl_mini'.$i] = $frm['imgurl_mini'.$i];
		$minibanners['expireddate_mini'.$i] = $frm['expireddate_mini'.$i];
		$minibanners['description_mini'.$i] = $frm['description_mini'.$i];
		}	

	  	save_minibanners ();
      	header ('Location: ?a=minibanners');
      	exit ();
	}
  }
?>