Location: PHPKode > scripts > music-i-love CLASSIFIED ADS > music-i-love-classified-ads/body_for_ads.php
<center>
<img border=0 src="ads.gif">
</center>

<br>

<center>
<table class="classification">
<tr>
<td class="recent_1">

<?php
if (substr_count($_SERVER['QUERY_STRING'], "RECENT") == 0)  
{
echo(" <img id=\"dot\" border=0 src=\"dot.gif\"> ");
}
else
{
echo(" <img id=\"dot\" border=0 src=\"dot2.gif\"> ");
}
?>

</td>
<td class="recent_2" 

<?php
if (substr_count($_SERVER['QUERY_STRING'], "RECENT") == 0)
{
echo(" OnMouseOver=\"document.getElementById('dot').src='dot2.gif'\" OnMouseOut=\"document.getElementById('dot').src='dot.gif'\" ");
}
?>

> &nbsp <a class="recent_2" href="<?php echo($_SERVER["PHP_SELF"]); ?>?topic_get=RECENT"> The most recent</a></td>
</tr>
</table>
</center>


<br>



<center>
<table class="classification">
<tr>

<?php
$topic_number=0;



foreach ($topic_array as $topic_foreach)
{



  if ($ads_dir_op_for_total = opendir($ads_dir))
  { 

$single_class_records_total=0;

  while (false !== ($ads_dir_file_name_for_total = readdir($ads_dir_op_for_total))) 
    {


     if (!is_dir($ads_dir_file_name_for_total))
       {

 
 
    if ((strlen($topic_number)) == strpos($ads_dir_file_name_for_total, "-") && (strstr($ads_dir_file_name_for_total, $topic_number . "-") == true))
          {
     $single_class_records_total++;
          }



     //getting an array of ids to learn the max value

    $ads_dir_file_name_short_1 = substr_replace($ads_dir_file_name_for_total, "", 0, stripos($ads_dir_file_name_for_total, "-")+1) ;
                     
    $id_get_array[] = str_replace(".txt", "", $ads_dir_file_name_short_1) ;
 
     
       }
    }

  if (!empty($id_get_array))
    {
  $max_id = max($id_get_array);
    }
   else
    {
  $max_id = 0;
    }
  }


  if ($topic_get != "RECENT" && $topic_get == array_search($topic_foreach, $topic_array))
  {
echo("<td class=\"classification_2\" ><a href=\"" . $_SERVER["PHP_SELF"] . "?topic_get=$topic_number\">&nbsp $topic_foreach &nbsp $single_class_records_total</a> </td>");
  }
 else
  {
echo("<td class=\"classification_1\" OnMouseOver=\"this.style.background='#CD7F32'\" OnMouseOut=\"this.style.background='#D0C032'\"><a href=\"" . $_SERVER["PHP_SELF"] . "?topic_get=$topic_number\">&nbsp $topic_foreach &nbsp $single_class_records_total</a> </td>");
  }




$topic_number++;


 if ($topic_number != count($topic_array) && substr_count($topic_number/2, ".") == 0)
  {
echo("</tr>
      <tr>");
  }
 else if ($topic_number == count($topic_array) && substr_count($topic_number/2, ".") > 0)
  {
echo("<td class=\"empty\">&nbsp</td></tr>");
  }

else if ($topic_number == count($topic_array) && substr_count($topic_number/2, ".") == 0)
  {
echo("</tr>");
  }



}

?>
</table>
</center>
<br><br><br>





















<?php








if ($posting == "yes")
{

 if (isset($topic_get) && $topic_get != "RECENT")
  {
echo("<br><br>


	<center>
	<table class=submit cellspacing=0 border=0>
	<tr>
	<td align=center>

<center>
 <b><h2><div class=ad_table_title>Your Ad Posting</div></h2></b>

<br>

<form method=\"post\" name=\"adsform\" action=\"" . $_SERVER["PHP_SELF"] . "?topic_get_from_adsform=$topic_get&max_id=$max_id\">
<table>

 <tr>
   <td width=\"100\"><small>* Your Name </small></td>
   <td>
    <input name=\"name\" type=\"text\" id=\"name\" size=\"50\" maxlength=\"50\" > </td>
 </tr>

 <tr>
   <td width=\"100\"><small>* Phone</small></td>
   <td>
    <input name=\"phone\" type=\"number\" id=\"phone\" size=\"50\" maxlength=\"20\" > </td>
 </tr>

  <tr>
   <td width=\"100\"><small>* E-mail </small></td>
   <td>
    <input name=\"email\" type=\"text\" id=\"email\" size=\"50\" maxlength=\"50\"> </td>
 </tr>

<tr>
   <td width=\"100\"><small>URL</small></td>
   <td>
    <input name=\"url\" value=\"http://www.\" type=\"text\" id=\"url\" size=\"50\" maxlength=\"70\" > </td>
 </tr>


  <tr>
     <td width=\"100\"><small> Location </small></td>
     <td>   
 <input name=\"location\" type=\"text\" id=\"location\" size=\"50\" maxlength=\"50\"> </td>
 </tr>

 <tr>
   <td width=\"100\"><small>*Ad Text</small></td>
   <td>
    <textarea name=\"ad\" cols=\"48\" rows=\"10\" id=\"ad\" ></textarea></td>
 </tr>


  <tr>
   <td width=\"100\">&nbsp;</td>
   <td colspan=4>
    <input name=\"btnSign\" class=submit type=\"submit\" id=\"btnSign\" value=\"Submit\" onClick=\"return checkForm();\"> &nbsp&nbsp&nbsp&nbsp
</td>
 </tr>

</table>
</form>
<center>

	</td>
	</tr>  	
     </table>
     


 </center>
<br><br><br><br>");

  }
else
  {

 echo("<center> <font color=\"red\"> No ads topic is selected! First select the topic from the titles above, <br> then click the link to add a posting.</font></center>");
  }


}

else
{

echo("<center><a href=\"" . $_SERVER["PHP_SELF"] . "?topic_get=$topic_get&posting=yes\"> Click HERE to post your ad! </a></center><br>"); 


}







echo("<br>");





if ($posting != "yes")
{

if ($ads_dir_op = opendir($ads_dir))
 { 

while (false !== ($ads_dir_file_name = readdir($ads_dir_op))) 
  {


$ads_dir_files = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $ads_folder . "/" . $ads_dir_file_name ;


// ******* Deleting files that are older than allowed




    if ($ads_dir_file_name != "." && $ads_dir_file_name != "..")
     {

     if (is_file($ads_dir_files))
       {
     $ads_dir_files_opened_for_del = fopen($ads_dir_files, 'r');                 
     $ads_dir_files_content_for_del = fread($ads_dir_files_opened_for_del, filesize($ads_dir_files));
     fclose($ads_dir_files_opened_for_del);
     
list($a, $b, $c, $d, $e, $f, $url_for_del_sec, $k, $l, $m, $unix) = explode("||", $ads_dir_files_content_for_del);


	if ($unix + ((60*60*24) * $how_old) < time() && $url_for_del_sec != "http://www.music-i-love.com" && $url_for_del_sec != "http://www.english-lithuanian.com")
	 {
	unlink($ads_dir_files);
	 }

       }

     }



// ******** Deletion is complete




list($topic_key_expl, $topic_id_expl) = explode("-", $ads_dir_file_name) ;


   if ($topic_get != "RECENT")
    {   
//collecting records of a single class
        
    if($ads_dir_file_name != "." && $ads_dir_file_name != ".." && $topic_get == $topic_key_expl)
      {     

	if (is_file($ads_dir_files))
        {
     $ads_dir_files_opened = fopen($ads_dir_files, 'r');                 
     $ads_dir_files_content = fread($ads_dir_files_opened, filesize($ads_dir_files));
     fclose($ads_dir_files_opened);

     $ads_dir_files_content_array[] = $ads_dir_files_content;

     $topic_id_expl_array[] = str_replace(".txt", "", $topic_id_expl);
	}
                       
      }
    }
   else
    {
//collecting all records

    if($ads_dir_file_name != "." && $ads_dir_file_name != "..")
      {     

	if (is_file($ads_dir_files))
        {
     $ads_dir_files_opened = fopen($ads_dir_files, 'r');                 
     $ads_dir_files_content = fread($ads_dir_files_opened, filesize($ads_dir_files));
     fclose($ads_dir_files_opened);

     $ads_dir_files_content_array[] = $ads_dir_files_content;

     $topic_id_expl_array[] =  str_replace(".txt", "", $topic_id_expl);
	}
 
                       
      }
    }

  }

 }


if (!empty($ads_dir_files_content_array))
 {
//using IDs with .txt as keys for values

$ads_dir_files_content_array = array_combine($topic_id_expl_array, $ads_dir_files_content_array);

krsort($ads_dir_files_content_array);





 //we need $ads_dir_files_content_array array shortened only when showing ads in general in oder to know where a listing and certain page of a listing starts. If  //one particular posting is showed, we do not need the array to shorten in oder to allow the sript to look for the right ad by ID in the whole array

  if (empty($id_get))
  {

 //***shortening array in reference to the number of page viewed and to entries per page

 $including_next_from_get = ($quantity_of_pages_per_listing * $entries_per_page) * $next_from_get ;


 $start_from = $including_next_from_get + ($page_get * $entries_per_page) - $entries_per_page ;


 $ads_dir_files_content_array_short = array_slice($ads_dir_files_content_array, $start_from, $entries_per_page);

 //***********
  }
  else
  {
 $ads_dir_files_content_array_short = $ads_dir_files_content_array ;
  }




foreach ($ads_dir_files_content_array_short as $ads_dir_files_content_foreach)
  {

list($id, $topic, $time, $name, $ads_tel_no, $email, $www_url, $text, $location, $ip, $unix_time) = explode("||", $ads_dir_files_content_foreach);


$text_abbr = substr_replace($text, '', 40);


   if (!empty($www_url))
     {
    $url = "<a target=\"_blank\" class=ad_in_detail_url href=\"$www_url\">$www_url</a>";
     }
    else
     {
    $url = "<a target=\"_blank\" class=ad_in_detail_url href=\"\"></a>";
     }





    if (empty($id_get))
    {

echo("
<center>
<table class=\"ads_table\" cellspacing=0 >
<tr>
<td class=\"ads_table_1\">$text_abbr</td>
<td class=\"ads_table_2\"><center><b><a href=\"" . $_SERVER["PHP_SELF"] . "?topic_get=$topic_get&id_get=$id\">Read</a></b></center></td>
<td class=\"ads_table_3\">$time</td>
</tr>
</table>
</center>
<br>");
   
    }
    else
    {


     if ($id_get == $id)
      {

	echo("


	<center>
	<table class=ad_in_detail_table cellspacing=0 border=0>
	<tr>
	<td class=ad_in_detail_bg_1> 
	&nbsp
	</td>
	</tr>

	<tr>
	<td class=ad_in_detail_bg_2> &nbsp&nbsp&nbsp

 

<table border=0 align=center>
<tr>
<td width=180px >&nbsp</td>
<td width=180px class=\"ad_date\">$time </td>
</tr>
</table>


<div class=txt>

<br><br><br> 
<div class=\"ad_body\">$text </div>
<br><br><br>



<table>
<tr>
<td bgcolor=\"CCFF33\">Name:</td> <td bgcolor=\"CCFF33\">$name</td>
</tr>
</table>

<table>
<tr>
<td bgcolor=\"CCFF33\">Location:</td> <td bgcolor=\"CCFF33\">$location</td>
</tr>
</table>

<table>
<tr>
<td bgcolor=\"CCFF33\">Phone:</td> <td bgcolor=\"CCFF33\">$ads_tel_no</td>
</tr>
</table>

<table>
<tr>
<td bgcolor=\"CCFF33\">E-mail</td> <td bgcolor=\"CCFF33\">$email</td>
</tr>
</table>


<table>
<tr>
<td bgcolor=\"CCFF33\">URL:</td> <td bgcolor=\"CCFF33\">$url</td>
</tr>
</table>

</div>

	</td>
	</tr>
	
	<tr>
	<td class=ad_in_detail_bg_3> 
	&nbsp
	</td>
        </tr>
	</table>
       </center>
	<br><br>
	");


      }

    }


  }




if (empty($id_get))
  {

echo("<center>
<table>
<tr >");



//**** printing previous

echo("<td class=paging_1>");

       if (!empty($next_from_get))
	{
$previous = $next_from_get -1 ;
  
echo("<a class=paging href=\"$self?next_from=$previous&topic_get=$topic_get\"><img border=0 src=\"prev.gif\"></a>");
	}

echo("</td>");

//**** end of printing previous



//**** printing pages

$number_of_pages = ceil((count($ads_dir_files_content_array) - $including_next_from_get) / $entries_per_page);


     for ($i = 1 ; $i <= $number_of_pages; $i++)
        {

     if ($i <= $quantity_of_pages_per_listing)
          {

       $iii = ($next_from_get * $quantity_of_pages_per_listing) + $i ;


    if ($page_get == $i)
            { 
 echo("<td class=paging_2>$iii</td> ");
            }
           else
            {

  echo("<td class=paging_3><a class=paging href=\"$self?next_from=$next_from_get&page=$i&topic_get=$topic_get\">
$iii</a></td> ");
            }
          
          } 
  

      
	else 
          {

$next_from_validity = "yes" ;

	      break;
          }
 

        }


//**** end of printing pages




//**** printing next

echo("<td class=paging_1>");



     if ($next_from_validity == "yes")
        {
$next = $next_from_get +1 ;

echo("<a class=paging href=\"$self?next_from=$next&topic_get=$topic_get\"><img border=0 src=\"next.gif\"></a>");
        }

echo("</td>");

//**** end of printing next


echo("</tr>
</table>
</center>");
  }






 }
else
 {

echo("<center>No ads for this topic yet. You can be the first!</center>");

 }

}

?>
Return current item: music-i-love CLASSIFIED ADS