<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: myyp.php,v 1.17.2.8 2004/04/18 20:15:20 ajvwaay Exp $



/************************************************************************/
/*  My Yellow Pages v1.0 (MPN Addon)                                    */
/*  Kazumi Ono AKA onokazu                                              */
/*  2001-7-3                                                            */
/*  http://www.myweb.ne.jp                                              */
/*  http://mpn.phpwebhosting.com                                        */
/************************************************************************/
/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/


//include("functions.$phpEx");
include_once("class.myfunctions.$phpEx");

include_once("module.errorhandler.$phpEx");

$eh = new ErrorHandler; //ErrorHandler object
$mf = new MyFunctions;
$mf->table = $mpnTables['yp_categories'];
$mf->id = "cid";
$mf->itemtable = $mpnTables['yp_business'];
$mf->itemid = "bid";
$mf->ratingtable = $mpnTables['yp_votedata'];

function SearchForm() {
        global $phpEx, $HTTP_POST_VARS, $HTTP_GET_VARS;
        if (isset($HTTP_POST_VARS['term']))
        {
            $term = $HTTP_POST_VARS['term'];
        }
    elseif(isset($HTTP_GET_VARS['term']))
        {
            $term = $HTTP_GET_VARS['term'];
        }
        else
        {
            $term = null;
        }

        $term = stripslashes($term);

    $term = urldecode($term);

    if (isset($HTTP_POST_VARS['addterms']))
        {
            $addterms =$HTTP_POST_VARS['addterms'];
        }
    elseif(isset($HTTP_GET_VARS['addterms']))
        {
            $addterms =$HTTP_GET_VARS['addterms'];
        }
        else
        {
            $addterms = null;
        }

    if (isset($HTTP_POST_VARS['which']))
        {
            $which =$HTTP_POST_VARS['which'];
        }
    elseif(isset($HTTP_GET_VARS['which']))
        {
            $which =$HTTP_GET_VARS['which'];
        }
        else
        {
            $which = null;
        }

        echo "<form action=myyp.$phpEx?op=search method=POST>\n";

        echo "<div class='center'><table border=0 cellspacing=0 cellpadding=0>\n";

        echo "<tr><td class='center' colspan=\"2\"><span class='label'>".translate("Search for").":</span>&nbsp;<input type=\"text\" size=\"30\" name=\"term\" value=\"$term\">&nbsp;&nbsp;<span class='label'>".translate("Match").":</span>&nbsp;";
    echo "<input type=radio name=\"addterms\" value=\"all\"";
    if($addterms=="all") echo " checked";
    echo ">".translate("ALL")."&nbsp;<input type=radio name=\"addterms\" value=\"any\"";
    if($addterms=="any") echo " checked";
    echo ">".translate("ANY")."</font></td></tr><tr>";
    echo "<td valign=\"top\" class='center'><span class='label'>" . translate( 'In Section' ) . ":</span>&nbsp;<select name=\"which\" size=\"1\"><option value=\"title\"";
    if($which=="title") echo " selected";
    echo ">".translate("Name")."</option><option value=\"desc\"";
    if($which=="desc") echo " selected";
    echo ">".translate("Description")."</option></select>&nbsp;<input class='button' type=submit value=".translate("Search")."></td></tr>";

    echo "</table></div>\n";

    echo "<input type='hidden' name='stripit_form' value='term' />\n";

    echo "</form>";
}
function mainheader()
{
    global $phpEx, $mpnTables, $sitename;

    echo "<h1>$sitename " . translate ( 'Business Listings' ) . "</h1>\n";
    echo "<br />\n";


    /*// echo "<a href=./myyp.$phpEx><img src=images/myyp/logo.gif border=0></a>";

        echo "<br /><br />";
       echo "<table align=center cellspacing=0 cellpadding=2 border=0 bgcolor=#000000>";
        echo "<tr><td>";
        echo "<table align=center cellspacing=0 cellpadding=3 border=0 bgcolor=#ffffff>";
        echo "<tr><td><font size=2>";*/

    echo "<a href=myyp.$phpEx>".translate("Main")."</a>\n";

    echo "&nbsp;|&nbsp;\n";

    echo "<a href=myyp.$phpEx?op=addBusiness>".translate("Submit")."</a>\n";

    echo "&nbsp;|&nbsp;\n";

    echo "<a href=myyp.$phpEx?op=topTen&hit=1>".translate("Popular")."</a>\n";

    echo "&nbsp;|&nbsp;\n";

    echo "<a href=myyp.$phpEx?op=topTen&rate=1>".translate("Top Rated")."</a>\n";

    echo "<br /><br />\n";

    list( $numrows ) = mysql_fetch_row( mysql_query( "select count(*) from ".$mpnTables['yp_business']." where status > 0" ) );

    if ( $numrows > 1 || ( isset( $_REQUEST['op'] ) && $_REQUEST['op'] != 'addBusiness' ) )
    {
        SearchForm();
    }
}

function index() {
    global $mpnTables, $phpEx, $eh, $sitename, $mf;
    include("header.$phpEx");

    $result=mysql_query("SELECT cid, title, imgurl FROM ".$mpnTables['yp_categories']." WHERE pid = 0 ORDER BY title") or $eh->show("0013");

    mainheader();

    list($numrows)=mysql_fetch_row(mysql_query("select count(*) from ".$mpnTables['yp_business']." where status>0"));

    if ( $numrows == 1 )
    {
        $phrase1 = translate( 'There is' );
        $phrase2 = translate( 'Business' );
    }
    else
    {
        $phrase1 = translate( 'There are' );
        $phrase2 = translate( 'Businesses' );
    }

    echo "<div class='subtitle'>\n";

        echo $phrase1 . ' <b>' . $numrows . '</b> ' . $phrase2 . ' ' . translate( 'in our database' );

    echo "</div><br /><br />\n";

    OpenTable();

    echo "<center><table border=0 cellspacing=5 cellpadding=0 width=\"90%\"><tr>";
    $count = 0;
    while($myrow = mysql_fetch_array($result))
    {
        $title = $myrow['title'];
        $imgurl = $myrow['imgurl'];

        // Kiril: New Sanitizer

        $sanity_ary = compact( 'title', 'imgurl' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Saintizer

        $imgurl = urldecode($imgurl);

            echo "<td valign=\"top\" align=\"right\">";
            if ($myrow['imgurl']){
            echo "<a href=myyp.$phpEx?op=viewcat&cid=".$myrow['cid']."><img src=\"".$imgurl."\" height=\"50\" border=\"0\"></a>";
            } else {
            echo "";
            }
        $totalbiz = $mf->getTotalItems($myrow['cid'], 1);
            echo "</td><td valign=\"top\" width=\"40%\"><font size=2><a href=myyp.$phpEx?op=viewcat&cid=".$myrow['cid']."><b>$title</b></a>&nbsp;($totalbiz)<br />";
        // get child category objects
        $arr=array();
        $arr=$mf->getFirstChild($myrow['cid']);
        $space = 0;
        $chcount = 0;
        if (is_array($arr)) {
            foreach($arr as $ele)
            {
                $chtitle=stripslashes($ele->title);

                if ($chcount>4){
                    echo "...";
                    break;
                }
                if ($space>0) {
                        echo ", ";
                    }

                    echo "<a href=myyp.$phpEx?op=viewcat&cid=".$ele->cid.">".$chtitle."</a>";
                    $space++;
                $chcount++;

            }
        }
            if ($count<1) {
                echo "</font></td>";
            }
            $count++;
            if ($count==2) {
                echo "</font></td></tr><tr>";
                $count = 0;
            }
    }
    echo "</font></td></tr></table></center>";

    echo "<div align=\"left\"><font size=\"3\"><b>".translate("Latest Listings")."</b></font><br /><br />";
    showNew("".$mpnTables['yp_business']."");
    echo "</div>";
    CloseTable();
    include("footer.$phpEx");
}

function addBusiness() {
    global $mpnTables, $phpEx, $eh, $mf;

    if ( ! _MPN_USER ) { goBack( translate( 'Registered Users Only' ) ); }
    /*
    if(isset($user))
    {
        $cookie = cookiedecode($user);
        if(!check_username($cookie[1]))
        {
            $eh->show("1014");
        }
    } else {
        $eh->show("1014");
    }*/
        include("header.$phpEx");
        mainheader();
        OpenTable();

        echo "<table width=\"100%\" cellspacing=0 cellpadding=1 border=0><tr><td colspan=2>
    <table width=\"100%\" cellspacing=0 cellpadding=8 border=0><tr><td>
    <br /><br />";
        echo "
        <LI>".translate("Submit your business only once.")."</li>
        <LI>".translate("All business information are posted pending verification.")."</li>
        <LI>".translate("Username and IP are recorded, so please don't abuse the system.")."</li>
            <form action=\"myyp.$phpEx\" method=post>
            <table width=\"80%\"><tr><td align=\"right\">
            ".translate("Business Name: ")."</td><td>";
        echo "<input type=text name=title size=50 maxlength=100>";
        echo "</td></tr><tr><td align=\"right\">".translate("URL: ")."</td><td>";
        echo "<input type=text name=url size=50 maxlength=100 value=\"http://\">";
        echo "</td></tr>";
        echo "<tr><td align=\"right\">".translate("Category: ")."</td><td>";
        $mf->makeMySelBox();
        echo "</td></tr><tr><td></td><td></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Email: ")."</td><td>\n";
    echo "<input type=text name=email size=50 maxlength=60></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Phone: ")."</td><td>\n";
    echo "<input type=text name=phone size=25 maxlength=20></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Fax: ")."</td><td>\n";
    echo "<input type=text name=fax size=25 maxlength=20></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Summary:  (150 characters max)")."</td><td>\n";
    echo "<input type=text name=summary size=60 maxlength=150></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Address: ")."</td><td>\n";
    echo "<input type=text name=address size=60 maxlength=100></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("City: ")."</td><td>\n";
    echo "<input type=text name=city size=\"50\" maxlength=\"50\"></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("State/Province: ")."</td><td>\n";
    echo "<input type=text name=\"state\" size=\"25\" maxlength=\"25\"></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Zip Code: ")."</td><td>\n";
    echo "<input type=text name=zipcode size=\"15\" maxlength=\"10\"></td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Country: ")."</td><td>\n";
//    makeCountrySelBox($presetcountry);
    makeCountrySelBox();
    echo "</td></tr>\n";
    echo "<tr><td align=\"right\">".translate("Logo URL: ")."</td><td>\n";
    echo "<input type=\"text\" name=\"logourl\" size=\"50\" maxlength=\"150\" value=\"http://\"></td></tr>\n";
        echo "<tr><td align=\"right\" valign=\"top\">".translate("Description:")."</td><td>\n";
        echo "<textarea name=description cols=70 rows=10></textarea>\n";
        echo "</td></tr>\n";
        echo "</td></tr></table>\n<br />\n";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='description|title|url|email|phone|fax|summary|address|city|state|zipcode|logourl' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input type=\"hidden\" name=\"op\" value=\"addBusinessS\"></input><input type=\"hidden\" name=\"submitter\" value=\"" . $GLOBALS['uinf']['uname'] . "\">
            </input><center><input class='button' type=\"submit\" class=\"button\" value=\"".translate("Submit")."\"></input></center>\n";
        echo "</form>";
        echo "</td></tr></table></td></tr></table>";
        CloseTable();
        include("footer.$phpEx");
}
function addBusinessS()
{
    global $mpnTables, $phpEx, $HTTP_POST_VARS, $eh;

    if ( ! _MPN_USER ) { goBack( translate( 'Registered Users Only' ) ); }

    /*if(isset($user)) {
            $cookie = cookiedecode($user);
        if(!check_username($cookie[1])){
            $eh->show("1014");
        }
        } else {
            $eh->show("1014");
        }*/
    include("header.$phpEx");
    $url = $HTTP_POST_VARS["url"];
    if (($url) || ($url!="")) {
        $url = trim($url);
        if ($url == "http://") {
            $url = "";
        } else {
            if (!stristr($url, "http://")) {
                $url = "http://" . $url;
            }
        $url = urlencode($url);
        }
    }

        if(!isset($HTTP_POST_VARS['submitter'])) {
                $submitter = $GLOBALS['uinf']['uname'];
        }else{
        $submitter = $HTTP_POST_VARS['submitter'];
    }
// Check if Title exist
        if ($HTTP_POST_VARS["title"]=="") {
            OpenTable();
            echo "<font size=3 color=Red>";
            echo "<b>".translate("ERROR: You need to type a TITLE for your business!")."</b>";
            CloseTable();
            include("footer.$phpEx");
        exit();
        }

// Check if Description exist
        if ($HTTP_POST_VARS['description']=="") {
            OpenTable();
            echo "<font size=3 color=Red>";
            echo "<b>".translate("ERROR: You need to type a DESCRIPTION for your business!")."</b><br /><br />";
            echo "</TD></TR></TABLE></TD></TR></TABLE>";
            include("footer.$phpEx");
        exit();
        }

    $logourl = $HTTP_POST_VARS["logourl"];
    if (($logourl) || ($logourl!="")) {
        $logourl = trim($logourl);
        if ($logourl == "http://") {
            $logourl = "";
        } else {
            if (!stristr($logourl, "http://")) {
                $logourl = "http://" . $logourl;
            }
        $logourl = urlencode($logourl);
        }
    }

    if (isset( $HTTP_POST_VARS['cid'] ))
    {
        $cid = $HTTP_POST_VARS['cid'];
    }
    else
    {
        $cid = null;
    }

    /*$url = $myts->makeTboxData4Save($url);
    $title = $myts->makeTboxData4Save($HTTP_POST_VARS["title"]);
        $email = $myts->makeTboxData4Save($HTTP_POST_VARS["email"]);
        $phone =  $myts->makeTboxData4Save($HTTP_POST_VARS["phone"]);
        $fax =  $myts->makeTboxData4Save($HTTP_POST_VARS["fax"]);
    $summary = $myts->makeTboxData4Save($HTTP_POST_VARS["summary"]);
        $address =  $myts->makeTboxData4Save($HTTP_POST_VARS["address"]);
        $city =  $myts->makeTboxData4Save($HTTP_POST_VARS["city"]);
        $state =  $myts->makeTboxData4Save($HTTP_POST_VARS["state"]);
        $zipcode =  $myts->makeTboxData4Save($HTTP_POST_VARS["zipcode"]);
        $country = $myts->makeTboxData4Save($HTTP_POST_VARS["country"]);
        $logourl =  $myts->makeTboxData4Save($logourl);
        $description = $myts->makeTareaData4Save($HTTP_POST_VARS["description"]);*/

    extract( $HTTP_POST_VARS );

    $q = "insert into ".$mpnTables['yp_business']." values (NULL, '$cid', '$title', '$url', '$email', '$phone', '$fax', '$summary', '$address', '$city', '$state', '$zipcode', '$country', '$logourl', '$submitter', 0, now(), 0, 0, 0, 0)";
        mysql_query($q) or $eh->show("0013");
    $newid = mysql_insert_id();
        mysql_query("insert into ".$mpnTables['yp_businesstxt']." values (NULL, '$newid', '$description')") or $eh->show("0013");
    mainheader();
    OpenTable();

        echo "<font size=3>";
        echo "".translate("We received your Business information. Thanks!")."<br />";
        echo "".translate("You'll receive an E-mail when it's approved.")."<br /><br />";
        echo "</TD></TR></TABLE></TD></TR></TABLE>";
        include("footer.$phpEx");

}


function viewcat() {
    global $admin, $perpage, $mpnTables, $phpEx, $HTTP_GET_VARS, $eh, $mf;
    $cid = $HTTP_GET_VARS['cid'];
    include("header.$phpEx");
    mainheader();
    OpenTable();

    if (!isset($HTTP_GET_VARS['min'])) {
        $min = 0;
    } else {
        $min = $HTTP_GET_VARS['min'];
    }
    if (!isset($max)) $max=$min+$perpage;
    if(isset($HTTP_GET_VARS['orderby'])) {
        $orderby = convertorderbyin($HTTP_GET_VARS['orderby']);
        } else {
        $orderby = "title ASC";
        }
        if (isset( $HTTP_GET_VARS['show'] ) && $HTTP_GET_VARS['show']!="") {
        $perpage = $HTTP_GET_VARS['show'];
        } else {
        $show=$perpage;
        }
        echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\"><tr><td align=\"center\">\n";
        echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" bgcolor=\"cccccc\"><tr><td>\n";
        $pathstring = "<a href=myyp.$phpEx>".translate("Main")."</a>&nbsp;:&nbsp;";
    $nicepath = $mf->getNicePathFromId($cid, "myyp.php?op=viewcat");
    $pathstring .= $nicepath;
    echo "<b>".$pathstring."</b>";
        echo "</td></tr></table>";

    // get child category objects
    $arr=array();
    $arr=$mf->getFirstChild($cid);
    if($arr!=0){
        echo "</td></tr><tr><td align=\"left\"><font size=\"2\"><b>Categories</b></font><br />\n</td></tr>\n<tr><td align=\"center\">";
        $scount = 0;
            echo "<table width=\"90%\"><tr>";

            foreach($arr as $ele){
            $title = $ele->title;
            $totalbiz = $mf->getTotalItems($ele->cid, 1);
                    echo "<td align=\"left\"><font size=\"2\"><b><a href=myyp.$phpEx?op=viewcat&cid=".$ele->cid.">".$title."</a></b>&nbsp;(".$totalbiz.")&nbsp;&nbsp;</font></td>";
                    $scount++;
                    if ($scount==4) {
                        echo "</tr><tr>";
                            $scount = 0;
                    }
            }
            echo "</tr></table><br />\n";
        echo "<hr>";
    }
    $fullcountresult=mysql_query("select count(*) from ".$mpnTables['yp_business']." where cid=$cid and status>0");
        list($numrows) = mysql_fetch_row($fullcountresult);
        $totalselectedlinks = $numrows;
    if($numrows>0){
            $result=mysql_query("select bid, title, url, email, phone, fax, summary, address, city, state, zipcode, country, logourl, status, date, hits, rating, votes, comments from ".$mpnTables['yp_business']." where cid=$cid and status>0 order by $orderby limit $min,$perpage");

        //if 2 or more items, show the sort menu
        if($numrows>1){
                $orderbyTrans = convertorderbytrans($orderby);
                echo "<br /><font size=2><center>".translate("Sort by").":&nbsp;&nbsp;
                ".translate("Title")." (<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=titleA>A</a>\<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=titleD>D</a>)
                ".translate("Date")." (<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=dateA>A</a>\<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=dateD>D</a>)
              ".translate("Rating")." (<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=ratingA>A</a>\<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=ratingD>D</a>)
              ".translate("Popularity")." (<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=hitsA>A</a>\<a href=myyp.$phpEx?op=viewcat&cid=$cid&orderby=hitsD>D</a>)
                </font>";
                echo "<b><br /><font color=BBBBBB size=2>".translate("Sites currently sorted by").": $orderbyTrans</font></b></center><br /><br />";
        }
            echo "<table width=\"100%\" cellspacing=0 cellpadding=10 border=0><tr><td><font size=2>";
            $x=0;
            while(list($bid, $btitle, $url, $email, $phone, $fax, $summary, $address, $city, $state, $zipcode, $country, $logourl, $status, $time, $hits, $rating, $votes, $comments)=mysql_fetch_row($result))
            {
            $rating = number_format($rating, 2);

            // Kiril: New Sanitizer

            $sanity_ary = compact( 'btitle', 'url', 'email', 'phone', 'fax', 'summary', 'address', 'city', 'state', 'zipcode', 'country', 'logourl', 'comments' );
            $_SERVER['SAN'] -> slashIT( $sanity_ary );
            extract( $sanity_ary );

            $_SERVER['SAN'] -> adjustFormat( $comments, 3, 10 );
            unset( $sanity_ary );

            // End New Saintizer

            $url = urldecode($url);
            $logourl = urldecode($logourl);

/*            $btitle = $myts->makeTboxData4Show($btitle);
            $url = $myts->makeTboxData4Show($url);
            $email = $myts->makeTboxData4Show($email);
            $phone = $myts->makeTboxData4Show($phone);
            $fax = $myts->makeTboxData4Show($fax);
            $summary = $myts->makeTboxData4Show($summary);
            $address = $myts->makeTboxData4Show($address);
            $city = $myts->makeTboxData4Show($city);
            $state = $myts->makeTboxData4Show($state);
            $zipcode = $myts->makeTboxData4Show($zipcode);
            $country = $myts->makeTboxData4Show($country);
            $logourl = $myts->makeTboxData4Show($logourl);*/

            $datetime = formatTimestamp($time);

            if ($admin != "") {
                echo "<a href=admin.$phpEx?fct=myyp&op=modBiz&bid=$bid><img src=images/links/editicon.gif border=0 Alt=\"".translate("Edit This Business")."\"></a>  ";
            }
                echo "<a href=myyp.$phpEx?op=viewbizdetails&bid=$bid><b>$btitle</b></a>";
                $newimage = newlinkgraphic($time, $status);
            echo $newimage;
                popgraphic($hits);
                echo "<br />";
                echo "<i>$summary</i><br />";
            echo "$address<br />";
            echo "$city, $state $zipcode<br />";
            echo "$country<br />$phone<br />$fax<br />$email<br />$url<br />";
                echo "<font color=777777>".translate("Date: ")."</font>$datetime<font color=777777> ".translate("Hits: ")."</font>$hits ";
                //voting & comments stats

                if ($rating!="0" || $rating!="0.0") {
                if ($votes == 1) {
                    $votestring = "".translate("vote")."";
                } else {
                    $votestring = "".translate("votes")."";
                }
                echo "<font color=777777>".translate("Rating: ")."</font>$rating ($votes $votestring)";
            }
                if ($comments != 0) {
                if ($comments == 1) {
                    $poststring = "".translate("post")."";
                } else {
                    $poststring = "".translate("posts")."";
                }
                echo "<font color=777777>".translate("Comments: ")."</font>$comments $poststring";
            }
                echo "<br /><br />";
                $x++;
            }
            $orderby = convertorderbyout($orderby);
            //Calculates how many pages exist.  Which page one should be on, etc...
            $linkpagesint = ($totalselectedlinks / $perpage);
            $linkpageremainder = ($totalselectedlinks % $perpage);
            if ($linkpageremainder != 0) {
                $linkpages = ceil($linkpagesint);
                if ($totalselectedlinks < $perpage) {
                    $linkpageremainder = 0;
                }
            } else {
                $linkpages = $linkpagesint;
            }
            //Page Numbering
            if ($linkpages!=1 && $linkpages!=0) {
                echo "<br /><br />";
                echo "".translate("Select page").":&nbsp;&nbsp;";
                $prev=$min-$perpage;
                if ($prev>=0) {
                    echo "&nbsp;<a href=myyp.$phpEx?op=viewcat&cid=$cid&min=$prev&orderby=$orderby&show=$show>";
                        echo "<b>[&lt;&lt; ".translate("Previous")." ]</b></a>&nbsp;";
                }
                $counter = 1;
                $currentpage = ($max / $perpage);
                while ($counter<=$linkpages ) {
                    $cpage = $counter;
                        $mintemp = ($perpage * $counter) - $perpage;
                        if ($counter == $currentpage) {
                    echo "<b>$counter</b>&nbsp;";
                } else {
                    echo "<a href=myyp.$phpEx?op=viewcat&cid=$cid&min=$mintemp&orderby=$orderby&show=$show>$counter</a>&nbsp;";
                }
                        $counter++;
                }
                $next=$min+$perpage;
                if ($x>=$perpage) {
                    echo "&nbsp;<a href=myyp.$phpEx?op=viewcat&cid=$cid&min=$max&orderby=$orderby&show=$show>";
                        echo "<b>[ ".translate("Next")." &gt;&gt;]</b></a>";
                }
            }
        echo "</td></tr></table>";
        }
        echo "</td></tr></table>\n";
        CloseTable();
        include("footer.$phpEx");
}

function newlinkgraphic($time, $status) {
    $newimage = null;
        $startdate = time();
        $count = 0;
    $time = substr($time, 0, 10);
        while ($count <= 7) {
            $daysold = strftime("%Y-%m-%d", $startdate);
            if ("$daysold" == "$time") {
                    if ($count<=7) {
                if($status==1){
                    $newimage = "&nbsp;<img src = images/myyp/newred.gif alt=\"".translate("New this week")."\">";
                    break;
                }elseif($status==2){
                    $newimage = "&nbsp;<img src = images/myyp/update.gif alt=\"".translate("Updated this week")."\">";
                    break;
                }
            }
            }
            $count++;
            $startdate = (time()-(86400 * $count));
        }
    return $newimage;
}

function popgraphic($hits) {
        global $popular;
        if ($hits>=$popular) {
            echo "&nbsp;<img src = images/links/pop.gif alt=\"".translate("Popular")."\">";
        }
}
//Reusable Link Sorting Functions
function convertorderbyin($orderby) {
        if ($orderby == "titleA")                        $orderby = "title ASC";
        if ($orderby == "dateA")                        $orderby = "date ASC";
        if ($orderby == "hitsA")                        $orderby = "hits ASC";
        if ($orderby == "ratingA")                        $orderby = "rating ASC";
        if ($orderby == "titleD")                        $orderby = "title DESC";
        if ($orderby == "dateD")                        $orderby = "date DESC";
        if ($orderby == "hitsD")                        $orderby = "hits DESC";
        if ($orderby == "ratingD")                        $orderby = "rating DESC";
        return $orderby;
}
function convertorderbytrans($orderby) {
        if ($orderby == "hits ASC")   $orderbyTrans = "".translate("Popularity (Least to Most Hits)")."";
        if ($orderby == "hits DESC")    $orderbyTrans = "".translate("Popularity (Most to Least Hits)")."";
        if ($orderby == "title ASC")    $orderbyTrans = "".translate("Title (A to Z)")."";
    if ($orderby == "title DESC")   $orderbyTrans = "".translate("Title (Z to A)")."";
        if ($orderby == "date ASC") $orderbyTrans = "".translate("Date (Old Business Info Listed First)")."";
        if ($orderby == "date DESC")   $orderbyTrans = "".translate("Date (New Business Info Listed First)")."";
        if ($orderby == "rating ASC")  $orderbyTrans = "".translate("Rating (Lowest Scores to Highest Scores)")."";
        if ($orderby == "rating DESC") $orderbyTrans = "".translate("Rating (Highest Scores to Lowest Scores)")."";
        return $orderbyTrans;
}
function convertorderbyout($orderby) {
        if ($orderby == "title ASC")            $orderby = "titleA";
        if ($orderby == "date ASC")            $orderby = "dateA";
        if ($orderby == "hits ASC")          $orderby = "hitsA";
        if ($orderby == "rating ASC")        $orderby = "ratingA";
        if ($orderby == "title DESC")              $orderby = "titleD";
        if ($orderby == "date DESC")            $orderby = "dateD";
        if ($orderby == "hits DESC")          $orderby = "hitsD";
        if ($orderby == "rating DESC")        $orderby = "ratingD";
        return $orderby;
}
function visit($bid) {
        global $mpnTables, $eh;
        mysql_query("update ".$mpnTables['yp_business']." set hits=hits+1 where bid=$bid and status>0");
        $result = mysql_query("select url from ".$mpnTables['yp_business']." where bid=$bid and status>0");
        list($url) = mysql_fetch_row($result);
        //$url = $url;
        $url = urldecode($url);

        $_SERVER['F_LIB'] -> redirectRequest( $url );
        exit;
}
function searchbiz($term, $which, $addterms, $min, $orderby, $show) {
        global $admin, $perpage, $show, $linksresults, $mpnTables, $phpEx, $eh, $mf;
        if (!isset($min)) $min=0;
        if (!isset($max)) $max=$min+$linksresults;
        if(isset($orderby)) $orderby = convertorderbyin($orderby);
        else $orderby = "title ASC";
        if ($show!="") {
        $linksresults = $show;
        } else {
        $show=$linksresults;
        }

        $term = stripslashes( $term );
        $addquery = '';
        $subquery = '';

    $term = urldecode($term);
    trim($term);
    if(isset($term) && $term != ""){
        $terms = explode(" ",addslashes($term));    // Get all the words into an array
        $addquery .= "(b.title LIKE '%$terms[0]%'";
        $subquery .= "(t.description LIKE '%$terms[0]%'";

        if($addterms=="any"){   // AND/OR relates to the ANY or ALL on Search Page
            $andor = "OR";
        } else{
            $andor = "AND";
        }
        $size = sizeof($terms);
        for($i=1;$i<$size;$i++) {
            $addquery.=" $andor b.title LIKE '%$terms[$i]%'";
            $subquery .= " $andor t.description LIKE '%$terms[$i]%'";
        }
        $addquery.=")";
        $subquery.=")";
    }else{
        $eh->show("1013");
    }
    $countquery = "select count(*) ";
    $searchquery = "select b.* ";
    if($which=="title") {
        $query = "from ".$mpnTables['yp_business']." b where b.status>0 and";
        $query .= " $addquery ";
    } else {
        $query = "from ".$mpnTables['yp_business']." b, ".$mpnTables['yp_businesstxt']." t where b.bid=t.bid and b.status>0 and";
        $query .= " $subquery ";
    }
    $countquery = $countquery.$query;
    $query .= "ORDER BY $orderby LIMIT $min, $linksresults";
    $searchquery= $searchquery.$query;
        $fullcountresult=mysql_query($countquery);
        list($countarray) = mysql_fetch_row($fullcountresult);
        $totalselectedlinks = $countarray;
    include("header.$phpEx");
        mainheader();
        OpenTable();

    echo "<TABLE WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=8 BORDER=0><TR><TD>";
    if($countarray>0){

            $result = mysql_query($searchquery);
            $nrows  = mysql_num_rows($result);
            $x=0;


            if ($nrows>0) {
                echo "<table width=\"100%\" bgcolor=CCCCCC><tr><td><font size=3>&nbsp;<b><font color=\"#ff0000\">$countarray</font>".translate(" matche(s) found for ")."\"<font color=\"#ff0000\">$term</font>\"</b></font></td></tr></table>";
            $term = urlencode($term);
                $orderbyTrans = convertorderbytrans($orderby);
                    echo "<br /><center><font size=2>".translate("Sort by").":&nbsp;&nbsp;
                      ".translate("Title")." (<a href=myyp.$phpEx?op=search&term=$term&orderby=titleA&which=$which&addterms=$addterms>A</a>\<a href=myyp.$phpEx?op=search&term=$term&orderby=titleD&which=$which&addterms=$addterms>D</a>)
                      ".translate("Date")." (<a href=myyp.$phpEx?op=search&term=$term&orderby=dateA&which=$which&addterms=$addterms>A</a>\<a href=myyp.$phpEx?op=search&term=$term&orderby=dateD&which=$which&addterms=$addterms>D</a>)
                      ".translate("Rating")." (<a href=myyp.$phpEx?op=search&term=$term&orderby=ratingA&which=$which&addterms=$addterms>A</a>\<a href=myyp.$phpEx?op=search&term=$term&orderby=ratingD&which=$which&addterms=$addterms>D</a>)
                      ".translate("Popularity")." (<a href=myyp.$phpEx?op=search&term=$term&orderby=hitsA&which=$which&addterms=$addterms>A</a>\<a href=myyp.$phpEx?op=search&term=$term&orderby=hitsD&which=$which&addterms=$addterms>D</a>)
                      </font>";
                    echo "<br /><b><font color=BBBBBB size=2>".translate("Sites currently sorted by").": $orderbyTrans</font></b><br /><br /></center>";
                    while(list($bid, $cid, $title, $url, $email, $phone, $fax, $summary, $address, $city, $state, $zipcode, $country, $logourl, $submitter, $status, $time, $hits, $rating, $votes, $comments) = mysql_fetch_row($result)){

                $rating = number_format($rating, 2);

                // Kiril: New Sanitizer

                $sanity_ary = compact( 'title', 'url', 'email', 'phone', 'fax', 'summary', 'address', 'city', 'state', 'zipcode', 'country', 'logourl', 'submitter', 'comments' );
                $_SERVER['SAN'] -> slashIT( $sanity_ary );
                extract( $sanity_ary );

                $_SERVER['SAN'] -> adjustFormat( $comments, 3, 10 );
                unset( $sanity_ary );

                // End New Saintizer

                $url = urldecode($url);
                $logourl = urldecode($logourl);

        /*            $title = $myts->makeTboxData4Show($title);
                    $url = $myts->makeTboxData4Show($url);
                    $url = urldecode($url);
                    $email = $myts->makeTboxData4Show($email);
                    $phone = $myts->makeTboxData4Show($phone);
                    $fax = $myts->makeTboxData4Show($fax);
                    $summary = $myts->makeTboxData4Show($summary);
                    $address = $myts->makeTboxData4Show($address);
                    $city = $myts->makeTboxData4Show($city);
                    $state = $myts->makeTboxData4Show($state);
                    $zipcode = $myts->makeTboxData4Show($zipcode);
                    $country = $myts->makeTboxData4Show($country);
                    $logourl = $myts->makeTboxData4Show($logourl);
                    $logourl = urldecode($logourl);*/


                $datetime = formatTimestamp($time);
                        $title = ereg_replace($query, "<b>$query</b>", $title);
                        $summary = ereg_replace($query, "<b>$query</b>", $summary);
                    if ($admin != "") {
                    echo "<a href=admin.$phpEx?op=YPModBiz&bid=$bid><img src=images/links/editicon.gif border=0 Alt=\"".translate("Edit This Business")."\"></a>  ";
                    }
                        echo "<a href=myyp.$phpEx?op=viewbizdetails&bid=$bid><b>$title</b></a>";
                    $newimage = newlinkgraphic($time, $status);
                echo $newimage;
                    popgraphic($hits);
                    echo "<br />";
                    echo "<i>$summary</i><br />";
                echo "$address<br />";
                echo "$city, $state $zipcode<br />";
                echo "$country<br />$phone<br />$fax<br />$email<br />$url<br />";
                        echo "<font color=777777>".translate("Date: ")."</font>$datetime<font color=777777> ".translate("Hits: ")."</font>$hits ";
                    //voting & comments stats
                        if ($votes == 1) {
                    $votestring = "".translate("vote")."";
                        } else {
                    $votestring = "".translate("votes")."";
                }
                    if ($rating!="0" || $rating!="0.0") {
                    echo "<font color=777777> ".translate("Rating").":</font> $rating ($votes $votestring)";
                }
                    if ($comments == 1) {
                    $poststring = "".translate("post")."";
                } else {
                    $poststring = "".translate("posts")."";
                }
                    if ($comments != 0) {
                    echo "<font color=777777> ".translate("Comments").":</font> $comments $poststring";
                }
                $pathstring = "<a href=myyp.$phpEx>".translate("Main")."</a>&nbsp;/&nbsp;";
                $nicepath = $mf->getNicePathFromId($cid, "myyp.php?op=viewcat");
                $nicepath = str_replace(":","/",$nicepath);
                $pathstring .= $nicepath;
                        echo "<br /><b>".translate("Found in: ")."</b>$pathstring<br /><br />";
                        $x++;
                    }
                    $orderby = convertorderbyout($orderby);
                } else {
                    echo "<center><font color=Red size=3>".translate("No matches found to your query")."</font></center><br /><br />";
                }
        //Calculates how many pages exist.  Which page one should be on, etc...
            $linkpagesint = ($totalselectedlinks / $linksresults);
            $linkpageremainder = ($totalselectedlinks % $linksresults);
            if ($linkpageremainder != 0) {
                $linkpages = ceil($linkpagesint);
                    if ($totalselectedlinks < $linksresults) {
                            $linkpageremainder = 0;
                    }
            }
            else {
                    $linkpages = $linkpagesint;
            }
            //Page Numbering
            if ($linkpages!=1 && $linkpages!=0) {
                echo "<br /><br />";
                    echo "Select page:&nbsp;&nbsp;";
                    $prev=$min-$linksresults;
                    if ($prev>=0) {
                        echo "&nbsp;<a href=myyp.$phpEx?op=search&term=$term&min=$prev&orderby=$orderby&show=$show&which=$which&addterms=$addterms>";
                            echo "<b>[&lt;&lt; ".translate("Previous")." ]</b></a>&nbsp;";
                    }
                    $counter = 1;
                    $currentpage = ($max / $linksresults);
                    while ($counter<=$linkpages ) {
                        $cpage = $counter;
                            $mintemp = ($perpage * $counter) - $linksresults;
                            if ($counter == $currentpage) {
                    echo "<b>$counter</b>&nbsp;";
                            } else {
                    echo "<a href=myyp.$phpEx?op=search&term=$term&min=$mintemp&orderby=$orderby&show=$show&which=$which&addterms=$addterms>$counter</a>&nbsp;";
                }
                            $counter++;
                    }
                    $next=$min+$linksresults;
                    if ($x>=$perpage) {
                            echo "&nbsp;<a href=myyp.$phpEx?op=search&term=$term&min=$max&orderby=$orderby&show=$show&which=$which&addterms=$addterms>";
                            echo "<b>[ ".translate("Next")." &gt;&gt;]</b></a>";
                    }
            }

        } else {
            echo "<center><font color=Red size=3>".translate("No matches found to your query")."</font></center><br /><br />";
        }
        echo "</td></tr></table>\n";
        CloseTable();
        include("footer.$phpEx");
}

function viewbizdetails($bid) {
        global $admin, $anonymus, $mpnTables, $phpEx, $eh, $bgcolor2, $textcolor1, $mf;
        $result = mysql_query("select b.*, t.description from ".$mpnTables['yp_business']." b, ".$mpnTables['yp_businesstxt']." t where b.bid = $bid and b.status>0 and t.bid = $bid") or $eh->show("0013");
        list($bid, $cid, $title, $url, $email, $phone, $fax, $summary, $address, $city, $state, $zipcode, $country, $logourl, $submitter, $status, $time, $hits, $rating, $votes, $comments, $description) = mysql_fetch_row($result);

        $rating = number_format($rating, 2);

        // Kiril: New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'email', 'phone', 'fax', 'summary', 'address', 'city', 'state', 'zipcode', 'country', 'logourl', 'submitter', 'comments', 'description' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );

        $slice_ary = array_slice( $sanity_ary, -2 );
        $_SERVER['SAN'] -> adjustFormat( $slice_ary, 3, 10 );
        extract( $slice_ary );
        unset( $sanity_ary, $slice_ary );

        // End New Saintizer

        $url = urldecode($url);
        $logourl = urldecode($logourl);

       /*
        $title = $myts->makeTboxData4Show($title);
        $url = $myts->makeTboxData4Show($url);
        $url = urldecode($url);
        $email = $myts->makeTboxData4Show($email);
        $phone = $myts->makeTboxData4Show($phone);
        $fax = $myts->makeTboxData4Show($fax);
        $summary = $myts->makeTboxData4Show($summary);
        $address = $myts->makeTboxData4Show($address);
        $city = $myts->makeTboxData4Show($city);
        $state = $myts->makeTboxData4Show($state);
        $zipcode = $myts->makeTboxData4Show($zipcode);
        $country = $myts->makeTboxData4Show($country);
        $logourl = $myts->makeTboxData4Show($logourl);
        $logourl = urldecode($logourl);
        $description = $myts->makeTareaData4Show($description);*/


    $datetime = formatTimestamp($time);

        include("header.$phpEx");
        mainheader();
        OpenTable();

        echo "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"98%\">";
    echo "<tr><td colspan=\"3\">";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" bgcolor=\"cccccc\"><tr><td>\n";
        $pathstring = "<a href=myyp.$phpEx>".translate("Main")."</a>&nbsp;:&nbsp;";
    $nicepath = $mf->getNicePathFromId($cid, "myyp.php?op=viewcat");
    $pathstring .= $nicepath;
    echo "<b>".$pathstring."</b>";
        echo "</td></tr></table>";
    echo "</td></tr>";
        echo "<tr><td colspan=\"3\">
            <table width=\"100%\" cellspacing=2 cellpadding=2 border=0 bgcolor=\"$bgcolor2\"><tr><td>
               <font color=\"$textcolor1\"><b>$title</b></font>
            </td></tr></table>
          </td></tr>
          <tr><td valign=\"top\" width=\"30%\">";
        if ($logourl){
            echo "<a href=myyp.$phpEx?op=visit&bid=$bid><img src=\"$logourl\" border=\"0\"></a><br />";
        }
        echo "<p>
 <a href=myyp.$phpEx?op=modifybizrequest&bid=$bid>".translate("Modify")."</a>";
        echo "<br /><a href=myyp.$phpEx?op=doRating&bid=$bid>".translate("Rate this Business")."</a>";
        if($url){
        echo "<br /><a href=myyp.$phpEx?op=brokenlink&bid=$bid>".translate("Report Broken Link")."</a>";
        }
    echo "<br /><a href=\"myyp.$phpEx?op=printBizPage&bid=$bid\"><image src=images/print.gif border=\"0\" width=\"15\" height\"11\" alt=\"".translate("Printer friendly Page")."\"></a>&nbsp;&nbsp;<a href=\"myyp.$phpEx?op=sendBusiness&bid=$bid\"><image src=\"images/friend.gif\" border=\"0\" width=\"15\" height=\"11\" alt=\"".translate("Send this Business Card to a Friend")."\"></a>";
    if ($admin != "") {
        echo "&nbsp;&nbsp;<a href=admin.$phpEx?fct=myyp&op=modBiz&bid=$bid><img src=images/links/editicon.gif border=0 Alt=\"".translate("Edit This Business")."\"></a>  ";
        }
        echo "</p>";
        echo "<p>".translate("Date: ")."$datetime";
        $newimage = newlinkgraphic($time, $status);
    echo $newimage;
        echo "<br />".translate("Hits: ")."$hits";
        popgraphic($hits);
        echo "<br /> ".translate("Votes: ")."$votes<br />
          ".translate("Rating: ")."$rating";
        echo "</p>";
    $mapadd = urlencode($address);
    $mapcity = urlencode($city);
    echo "<p><a href=\"http://www.mapblast.com/myblast/map.mb?CMD=GEO&AD2=$mapadd&req_action=crmap&AD4=$country&AD2_street=$mapadd&AD3=$mapcity&x=35&y=11\" target=\"_blank\">";
//    echo "<IMG SRC=\"http://www.mapblast.com/myblast/images/corporate/rect_logo.gif\" WIDTH=\"127\" HEIGHT=\"34\" ALT=\"mapblast\" BORDER=\"0\">";

        // Need to change this image
        echo "<p><a href=\"http://mapquest.com/maps/map.adp?country=US&address=$address&city=$city&state=$state&zipcode=$zipcode&homesubmit.x=42&homesubmit.y=6\" target=\"_blank\">";
        echo "<IMG SRC=\"http://cdn.mapquest.com/mqhome/hp_bussol_1\" BORDER=\"1\">";
        echo "</a></p></td>";
        echo "<td width=\"1\">&nbsp;</td>";
        echo "<td valign=\"top\">";

#       echo "$summary<br />";
        echo "$address<br />";
        echo "$city, $state $zipcode<br />";
        echo "$country<br />$phone<br />$fax<br /><a href=\"mailto:$email\">$email</a><br /><a href=myyp.$phpEx?op=visit&bid=$bid>$url</a><br />";

        echo "<p><b>".translate("Details: ")."</b><br />$description";
        echo "</p></td></tr>";
        echo "</table><br />";
// insert comments here
        CloseTable();
        include("footer.$phpEx");
}

function brokenlink() {
        global $HTTP_GET_VARS, $phpEx, $anonymous;
        $bid = $HTTP_GET_VARS['bid'];
        include("header.$phpEx");
        mainheader();

        echo "<h1>".translate("Report Broken Link")."</h1><br /><br />";

        OpenTable();


        echo "<center><form action=\"myyp.$phpEx\" method=\"post\">";
        echo "<input type=hidden name=bid value=$bid>";
        echo "".translate("Thank you for helping to maintain this directory's integrity.")."
          <br />
          ".translate("For security reasons your user name and IP address will also be temporarily recorded.")."
          <br /><br />";
        echo "<input type=hidden name=\"op\" value=\"brokenlinkS\"><input class='button' type=\"submit\" value=\"".translate("Report Broken Link")."\"></center></form><br />";
        CloseTable();
        include("footer.$phpEx");
}

function brokenlinkS($bid) {
        global $mpnTables, $phpEx, $anonymous, $eh;

        /*if(isset($user)) {
            $cookie = cookiedecode($user);
        if(!check_username($cookie[1])){
            $sender = "$anonymous";
        }else{
            $sender = $cookie[1];
        }
        } else {
            $sender = "$anonymous";
        }*/

        $sender = $GLOBALS['uinf']['uname'];

    $ip = getenv("REMOTE_ADDR");
    if ($sender != $anonymous) {
    // Check if REG user is trying to report twice.
            $result=mysql_query("select count(*) from ".$mpnTables['yp_brokenlink']." where bid=$bid and sender='$sender'");
            list($count)=mysql_fetch_row($result);
            if ($count>0) {
                    $eh->show(1012,2);
                }

        }

        // Check if the sender is trying to vote more than once.
        $result=mysql_query("select count(*) FROM ".$mpnTables['yp_brokenlink']." WHERE bid=$bid AND ip = '$ip'");
        $anoncount = mysql_num_rows($result);
        list($count)=mysql_fetch_row($result);
        if ($count>0) {
                $eh->show(1012,2);
        }

    $query = "insert into ".$mpnTables['yp_brokenlink']." values ('', '$bid', '$sender', '$ip')";
    mysql_query($query) or $eh->show("0012");
        include("header.$phpEx");
        echo "<br /><center>".translate("Thanks for the information. We'll look into your request shortly.")."<br /><br /><a href=\"myyp.$phpEx?op=viewbizdetails&bid=$bid\">".translate("Back to Business Data")."</a>";
        include("footer.$phpEx");
}
function modifybizrequest() {
        global $HTTP_GET_VARS, $mpnTables, $phpEx, $eh, $mf;
        $bid = $HTTP_GET_VARS['bid'];

        if ( ! _MPN_USER ) { goBack( translate( 'Registered Users Only' ) ); }

        /*if(isset($user))
        {
            $cookie = cookiedecode($user);
            if(!check_username($cookie[1]))
            {
                $eh->show("1015");
            } else {
                    $blocknow = 0;
            }
        } else {
            $eh->show("1015");
        }
        */
        include("header.$phpEx");


       // if (!$blocknow)
        ///{
        mainheader();
        OpenTable();

        echo "<table width=450 align=center>";
            $result = mysql_query("select cid, title, url, email, phone, fax, summary, address, city, state, zipcode, country, logourl from ".$mpnTables['yp_business']." where bid=$bid and status>0");
            echo "<font size=3><b>".translate("Request Business Info Modification")."</b><br /><br /><font size=2>";
            list($cid, $title, $url, $email, $phone, $fax, $summary, $address, $city, $state, $zipcode, $country, $logourl) = mysql_fetch_row($result);

           $result2 = mysql_query("select description from ".$mpnTables['yp_businesstxt']." where bid=$bid");
        list($description)=mysql_fetch_row($result2);

        // Kiril: New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'email', 'phone', 'fax', 'summary', 'address', 'city', 'state', 'zipcode', 'country', 'logourl', 'description' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Saintizer

        $url = urldecode($url);
        $logourl = urldecode($logourl);

       /*
        $title = $myts->makeTboxData4Edit($title);
        $url = $myts->makeTboxData4Edit($url);
        $url = urldecode($url);
        $email = $myts->makeTboxData4Edit($email);
        $phone = $myts->makeTboxData4Edit($phone);
        $fax = $myts->makeTboxData4Edit($fax);
        $summary = $myts->makeTboxData4Edit($summary);
        $address = $myts->makeTboxData4Edit($address);
        $city = $myts->makeTboxData4Edit($city);
        $state = $myts->makeTboxData4Edit($state);
        $zipcode = $myts->makeTboxData4Edit($zipcode);
        $country = $myts->makeTboxData4Edit($country);
        $logourl = $myts->makeTboxData4Edit($logourl);
        $logourl = urldecode($logourl);
        */



       // $description = $myts->makeTareaData4Edit($description);


            echo "<form action=myyp.$phpEx method=post>";
            echo "<table width=\"80%\"><tr><td align=\"right\">";
        echo "<font color=\"#0000ff\">".translate("Business ID: ")."</font></td><td>";
            echo "<b>$bid</b>";
            echo "</td></tr><tr><td align=\"right\">".translate("Business Name: ")."</td><td>";
            echo "<input type=\"text\" name=\"title\" size=\"50\" maxlength=\"100\" value=\"$title\">";
            echo "</td></tr><tr><td align=\"right\">".translate("URL: ")."</td><td>";
            echo "<input type=\"text\" name=\"url\" size=\"50\" maxlength=\"100\" value=\"$url\">";
            echo "</td></tr>";
            echo "<tr><td align=\"right\">".translate("Category: ")."</td><td>";
            $mf->makeMySelBox($cid);
            echo "</td></tr><tr><td></td><td></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Email: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"email\" size=\"50\" maxlength=\"60\" value=\"$email\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Phone: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"phone\" size=\"25\" maxlength=\"20\" value=\"$phone\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Fax: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"fax\" size=\"25\" maxlength=\"20\" value=\"$fax\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Summary:  (150 characters max)")."</td><td>\n";
        echo "<input type=\"text\" name=\"summary\" size=\"60\" maxlength=\"150\" value=\"$summary\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Address: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"address\" size=\"60\" maxlength=\"100\" value=\"$address\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("City: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"city\" size=\"50\" maxlength=\"50\" value=\"$city\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("State/Province: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"state\" size=\"25\" maxlength=\"25\" value=\"$state\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Zip Code: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"zipcode\" size=\"15\" maxlength=\"10\" value=\"$zipcode\"></td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Country: ")."</td><td>\n";
        makeCountrySelBox($country);
        echo "</td></tr>\n";
        echo "<tr><td align=\"right\">".translate("Logo URL: ")."</td><td>\n";
        echo "<input type=\"text\" name=\"logourl\" size=\"50\" maxlength=\"150\" value=\"$logourl\"></td></tr>\n";
            echo "<tr><td align=\"right\" valign=\"top\">".translate("Description:")."</td><td>\n";
            echo "<textarea name=description cols=70 rows=10>$description</textarea>\n";
            echo "</td></tr>\n";
            echo "<tr><td colspan=\"2\" align=\"center\"><br />\n";

            // Kiril: New Sanitizer

            echo "<input type='hidden' name='stripit_form' value='description|title|url|email|phone|fax|summary|address|city|state|zipcode|logourl' />\n";
            echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

            // End Sanitizer

        echo "<input type=\"hidden\" name=\"bid\" value=\"$bid\"></input>";
            echo "<input type=\"hidden\" name=\"modifysubmitter\" value=\"" . $GLOBALS['uinf']['uname'] . "\"></input>";
        echo "<input type=\"hidden\" name=\"op\" value=\"modifybizrequestS\"></input><input class='button' type=\"submit\" value=\"".translate("Send Request")."\"></input></form>";
            echo "</td></tr></table>";
       // }

        CloseTable();
        include("footer.$phpEx");
}

function modifybizrequestS() {
        global $mpnTables, $HTTP_POST_VARS, $phpEx, $eh;

       if ( ! _MPN_USER ) { goBack( translate( 'Registered Users Only' ) ); }

       $ratinguser = $GLOBALS['uinf']['uname'];

       /* if(isset($user)) {
            $cookie = cookiedecode($user);
        if(!check_username($cookie[1])){
            $eh->show("1015");
        } else {
                $blocknow = 0;
             = $cookie[1];
        }
        } else {
            $eh->show("1015");
        }
        */
        $bid = $HTTP_POST_VARS["bid"];
    $url = $HTTP_POST_VARS["url"];
    if (($url) || ($url!="")) {
        $url = trim($url);
        if ($url == "http://") {
            $url = "";
        } else {
            if (!stristr($url, "http://")) {
                $url = "http://" . $url;
            }
            $url = urlencode($url);
        }
    }
    $logourl = $HTTP_POST_VARS["logourl"];
    if (($logourl) || ($logourl!="")) {
        $logourl = trim($logourl);
        if ($logourl == "http://") {
            $logourl = "";
        } else {
            if (!stristr($logourl, "http://")) {
                $logourl = "http://" . $logourl;
            }
            $logourl = urlencode($logourl);
        }
    }

// Check if Title exist
        if ($HTTP_POST_VARS["title"]=="") {
            OpenTable();
            echo "<em class='warn'>".translate("ERROR: You need to type a TITLE for your business!")."</em>";
            CloseTable();
            include("footer.$phpEx");
        exit();
        }

// Check if Description exist
        if ($HTTP_POST_VARS['description']=="") {
            OpenTable();
            echo "<em class='warn'>".translate("ERROR: You need to type a DESCRIPTION for your business!")."</em>";
            CloseTable();
            include("footer.$phpEx");
        exit();
        }
        include("header.$phpEx");

        //if (!$blocknow)
        //{
/*            $cid = $HTTP_POST_VARS["cid"];
            $title = $myts->makeTboxData4Save($HTTP_POST_VARS["title"]);
            $url = $myts->makeTboxData4Save($url);
            $email = $myts->makeTboxData4Save($HTTP_POST_VARS["email"]);
            $phone =  $myts->makeTboxData4Save($HTTP_POST_VARS["phone"]);
            $fax =  $myts->makeTboxData4Save($HTTP_POST_VARS["fax"]);
            $summary = $myts->makeTboxData4Save($HTTP_POST_VARS["summary"]);
            $address =  $myts->makeTboxData4Save($HTTP_POST_VARS["address"]);
            $city =  $myts->makeTboxData4Save($HTTP_POST_VARS["city"]);
            $state =  $myts->makeTboxData4Save($HTTP_POST_VARS["state"]);
            $zipcode =  $myts->makeTboxData4Save($HTTP_POST_VARS["zipcode"]);
            $country = $myts->makeTboxData4Save($HTTP_POST_VARS["country"]);
            $logourl =  $myts->makeTboxData4Save($logourl);
            $description = $myts->makeTareaData4Save($HTTP_POST_VARS["description"]);*/

            extract( $HTTP_POST_VARS );

            if ( ! isset( $cid ) ) { $cid = 0; }


            mysql_query("insert into ".$mpnTables['yp_modrequest']." values (NULL, '$bid', '$cid', '$title', '$url', '$email', '$phone', '$fax', '$summary', '$address', '$city', '$state', '$zipcode', '$country', '$logourl', '$description', '$ratinguser')") or $eh->show("0013");
            echo "".translate("Thanks for the information. We'll look into your request shortly.")."<br /><br /><a href=\"myyp.$phpEx\">".translate("Back to Yellow Pages")."</a>";
        //}
        include("footer.$phpEx");
}


function addRating($bid, $rating) {

       global $sitename, $anonymous, $mpnTables, $phpEx, $eh, $mf;


       $ratinguser = $GLOBALS['uinf']['uname'];

    /*if(isset($user)) {
            $cookie = cookiedecode($user);
        if(!check_username($cookie[1])){
            $ratinguser = "$anonymous";
        }else{
            $ratinguser = $cookie[1];
        }
        } else {
            $ratinguser = "$anonymous";
        }*/

        //Make sure only 1 anonymous from an IP in a single day.
        $anonwaitdays = 1;
        $ip = getenv("REMOTE_ADDR");
        // Check if Rating is Null
        if ($rating=="--") {
            $eh->show("1011",2);
        }

        // Check if Business POSTER is voting (UNLESS Anonymous users allowed to post)
        if ($ratinguser != $anonymous) {
            $result=mysql_query("select submitter from ".$mpnTables['yp_business']." where bid=$bid");
            while(list($ratinguserDB)=mysql_fetch_row($result)) {
                if ($ratinguserDB==$ratinguser) {
                        $eh->show("1010",2);
                    }
            }

        // Check if REG user is trying to vote twice.
            $result=mysql_query("select ratinguser from ".$mpnTables['yp_votedata']." where bid=$bid");
            while(list($ratinguserDB)=mysql_fetch_row($result)) {
                if ($ratinguserDB==$ratinguser) {

                        $eh->show("1009",2);
                    }
            }
        }
        // Check if ANONYMOUS user is trying to vote more than once per day.
        if ($ratinguser==$anonymous){
#           $yesterdaytimestamp = (time()-(86400 * $anonwaitdays));
#           $ytsDB = Date("Y-m-d H:i:s", $yesterdaytimestamp);
            $result=mysql_query("select * FROM ".$mpnTables['yp_votedata']." WHERE bid=$bid AND ratinguser='$anonymous' AND ratinghostname = '$ip' AND TO_DAYS(NOW()) - TO_DAYS(ratingtimestamp) < $anonwaitdays");
        $anonvotecount = mysql_num_rows($result);
            if ($anonvotecount >= 1) {
                $eh->show("1009",2);
            }
        }

        //All is well.  Add to Line Item Rate to DB.
        mysql_query("INSERT into ".$mpnTables['yp_votedata']." values (NULL, '$bid', '$ratinguser', '$rating', '$ip', now())") or $eh->show("0013");
        //All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB.
        $mf->updaterating($bid);
    include("header.$phpEx");
        mainheader();

        OpenTable();

        echo "<center><b>".translate("Your vote is appreciated.")."</font></b>";
        echo "".translate("Thank you for taking the time to rate a site here at"). " $sitename ";
        echo "".translate("Input from users such as yourself will help other visitors better decide which business to choose.")."";

        echo "<br /><br /><a href=\"myyp.$phpEx?op=viewbizdetails&bid=$bid\">".translate("Back to Business Data")."</a></center>";

        CloseTable();

        include("footer.$phpEx");
}




function doRating($bid) {
        global $phpEx, $anonymous, $mpnTables;

       $ratinguser = $GLOBALS['uinf']['uname'];

   /* if(isset($user)) {
            $cookie = cookiedecode($user);
        if(!check_username($cookie[1])){
            $ratinguser = "$anonymous";
        }else{
            $ratinguser = $cookie[1];
        }
        } else {
            $ratinguser = "$anonymous";
        }*/
    include("header.$phpEx");
        mainheader();
        OpenTable();

        $result=mysql_query("select title from ".$mpnTables['yp_business']." where bid=$bid");
    list($title)=mysql_fetch_row($result);
        echo "
        <hr size=1 noshade>
    <table border=0 cellpadding=1 cellspacing=0 width=\"80%\"><tr><td>
        <h1>$title</h1>
        <UL>
        <LI>".translate("Please do not vote for the same resource more than once.")."
        <LI>".translate("The scale is 1 - 10, with 1 being poor and 10 being excellent.")."
        <LI>".translate("Please be objective, if everyone receives a 1 or a 10, the ratings aren't very useful.")."
        <LI>".translate("Do not vote for your own resource.")."";
        echo "
        </UL>
        </td></tr>
        <tr><td align=\"center\">
        <form method=POST action=\"myyp.$phpEx\">
        <input type=hidden name=\"bid\" value=\"$bid\">
        <select name=\"rating\">
        <option>--
        <option>10
        <option>9
        <option>8
        <option>7
        <option>6
        <option>5
        <option>4
        <option>3
        <option>2
        <option>1
        </select><br /><br /><input type=hidden name=op value=\"addRating\"><input class='button' type=submit value=\"".translate("Rate It!")."\">
        ";
        echo "</form></td></tr></table>";
        CloseTable();
        include("footer.$phpEx");
}

function printBizPage($bid) {
    global $site_logo, $sitename, $site_font, $mpnTables;
    $result=mysql_query("select b.cid, b.title, b.url, b.email, b.phone, b.fax, b.address, b.city, b.state, b.zipcode, b.country, b.logourl, b.date, t.description from ".$mpnTables['yp_business']." b, ".$mpnTables['yp_businesstxt']." t where b.bid=$bid and b.bid=t.bid");
    list($cid, $title, $url, $email, $phone, $fax, $address, $city, $state, $zipcode, $country, $logourl, $time, $description) = mysql_fetch_row($result);

        // Kiril: New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'email', 'phone', 'fax', 'summary', 'address', 'city', 'state', 'zipcode', 'country', 'logourl', 'description' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );


        $_SERVER['SAN'] -> adjustFormat( $description, 3, 10 );
        unset( $sanity_ary );

        // End New Saintizer

        $url = urldecode($url);
        $logourl = urldecode($logourl);


  /*      $title = $myts->makeTboxData4Show($title);
        $url = $myts->makeTboxData4Show($url);
        $url = urldecode($url);
        $email = $myts->makeTboxData4Show($email);
        $phone = $myts->makeTboxData4Show($phone);
        $fax = $myts->makeTboxData4Show($fax);
        $address = $myts->makeTboxData4Show($address);
        $city = $myts->makeTboxData4Show($city);
        $state = $myts->makeTboxData4Show($state);
        $zipcode = $myts->makeTboxData4Show($zipcode);
        $country = $myts->makeTboxData4Show($country);
        $description = $myts->makeTareaData4Show($description);*/


    $datetime = formatTimestamp($time);

    // Start Output

    echo $_SERVER['F_LIB'] -> generateSAHeader( 'mpnprint', 'mpn_print.css', 'screen,print', $title );

    echo "<body>\n";

    echo "<h1>$title</h1>\n";
    echo "<h2>" . translate( 'A' ) . " $sitename " . translate( 'Business Listing' ) . "</h2>\n";
    echo "<h3>" . _MPN_ROOT_URI . "</h3>\n";
    echo "<br /><br />\n";


    /* if (($logourl) || ($logourl!="")) {

       $logourl = $myts->makeTboxData4Show($logourl);
        $logourl=urldecode($logourl);

        echo "<img src=\"$logourl\" border=0 alt=\"\"><br /><br />";
    }*/

    echo "<h4>" . translate( 'Business Information' ) . "</h4>\n";

    echo "<hr /><br />\n";

        echo "<p class='info'>\n";

            echo "<b>" .translate( "Business Name" ) . ":</b>&nbsp;$title\n";
            echo "<br />";
            echo "<b>" . translate( "Date Added" ) . ":</b>&nbsp;$datetime\n";
            echo "<br />";
            echo "<b>" . translate( "Address" ) . ":</b>&nbsp;$address\n";
            echo "<br />";
            echo "<b>" . translate( "Country" ) . ":</b>&nbsp;$country\n";
            echo "<br />";
            echo "<b>" . translate( "State" ) . ":</b>&nbsp;$state\n";
            echo "<br />";
            echo "<b>" . translate( "City" ) . ":</b>&nbsp;$city\n";
            echo "<br />";
            echo "<b>" . translate( "Zipcode" ) . ":</b>&nbsp;$zipcode\n";
            echo "<br /><br />";
            echo "<b>" . translate( "Phone" ) . ":</b>&nbsp;$phone\n";
            echo "<br />";
            echo "<b>" . translate( "Fax" ) . ":</b>&nbsp;$fax\n";
            echo "<br />";
            echo "<b>" . translate( "Email" ) . ":</b>&nbsp;$email\n";
            echo "<br />";
            echo "<b>" . translate( "Website" ) . ":</b>&nbsp;$url\n";
            echo "<br />";

        echo "</p>\n";

        if ( $description != '' )
        {
            echo "<h4>" . translate( 'Business Description' ) . "</h4>\n";

            echo "<hr /><br />\n";

            echo "<div class='content'>\n";

                echo $description;

            echo "</div>\n";
        }

        echo "<br /><br /><hr /><br />\n";

        echo "<div class='footer'>\n";

            echo "".translate("This business information comes from:")." $sitename<br />
            <a href=\"" . _MPN_ROOT_URI . "\">" . _MPN_ROOT_URI . "</a><br /><br />
            ".translate("The URL for this business card is:")."<br />
            <a href=\"" . _MPN_ROOT_URI . "myyp.php?op=viewbizdetails&bid=$bid\">" . _MPN_ROOT_URI . "myyp.php?op=viewbizdetails&bid=$bid</a>\n";

        echo "</div>\n";

        echo "</body></html>\n";

}

function sendBusiness($bid) {
        global $phpEx, $mpnTables;
        if(!isset($bid)) { exit(); }
        include ("header.$phpEx");
        $result=mysql_query("select title from ".$mpnTables['yp_business']." where bid=$bid");
        list($title) = mysql_fetch_row($result);

        $title = stripslashes($title);


        OpenTable();
        echo "
        <font size=\"3\"><b>".translate("Send Business Card to a Friend")."</b><br /><br />".translate("You will send the business card for")." $title ".translate("to a specified friend:")."</font><br /><br />
        <form action=\"myyp.$phpEx\" method=post>
        <input type=hidden name=bid value=$bid>";
        if ( _MPN_USER ) {
        $result=mysql_query("select name, email from ".$mpnTables['users']." where uname='" . $GLOBALS['uinf']['uname'] . "' && uid > 1");
        list($yn, $ye) = mysql_fetch_row($result);
        }

        echo "
            <TABLE BORDER=0>
               <TR>
                  <TD ALIGN=\"RIGHT\">".translate("Your Name: ")."</TD>
                  <TD><input class=textbox type=text name=\"yname\" value=\"$yn\" $style_text  SIZE=35></TD>
               </TR>
               <TR>
                  <TD ALIGN=\"RIGHT\">".translate("Your Email: ")."</TD>
                  <TD><input class=textbox type=text name=\"ymail\" value=\"$ye\" $style_text  SIZE=35></TD>
               </TR>
               <TR>
                   <TD ALIGN=\"RIGHT\">".translate("Friend Name: ")."</TD>
                   <TD><input class=textbox type=text name=\"fname\" $style_text  SIZE=35></TD>
               </TR>
               <TR>
                   <TD ALIGN=\"RIGHT\">".translate("Friend Email: ")."</TD>
                   <TD><input class=textbox type=text name=\"fmail\" $style_text  SIZE=35></TD>
               </TR>
           </TABLE>";
        echo "<input type=hidden name=op value=businessSent>
              <input class='button' type=submit value=".translate("Send").">
              </form>";
        CloseTable();
        include ('footer.php');
}


function businessSent($bid, $yname, $ymail, $fname, $fmail) {
        global $sitename, $mpnTables, $phpEx, $smtp, $mailmethod;
        require_once('class.phpmailer.php');
        $mail = new phpmailer();

        /* SET MAIL DELIVERY OPTIONS */
        $mail->IsHTML(true);
        if ($mailmethod == "0") {
            $mail->IsMail();
        } else {
            $mail->IsSMTP();
            $mail->Host = $smtp;
        }
        $result2=mysql_query("select title, summary, date from ".$mpnTables['yp_business']." where bid=$bid");
        list($title, $summary, $time) = mysql_fetch_row($result2);

        $title = stripslashes($title);
        $summary = stripslashes($summary);

        $subject = "".translate("Interesting Business at")." $sitename";
        $message = "".translate("Hello")." $fname:\n\n".translate("Your Friend")." $yname ".translate("considered the following business card interesting and wanted to send it to you.")."\n\n$title\n$summary\n(".translate("Date:")." $time)\n".translate("URL").": <a href=\"" . _MPN_ROOT_URI . "myyp.$phpEx?op=viewbizdetails&bid=$bid\">" . _MPN_ROOT_URI . "myyp.$phpEx?op=viewbizdetails&bid=$bid</a>\n\n".translate("Visit our Yellow Pages at")." <a href=\"" . _MPN_ROOT_URI . "\">$sitename</a>".translate(" for more of these interesting business links.");

        $mail->From = $ymail;
        $mail->FromName = $yname;
        $mail->AddAddress($fmail);
        $mail->Subject = stripslashes($subject);
        $mail->Body = nl2br( stripslashes($message) );
        $mail->AltBody = strip_tags( stripslashes($message));
        $mail->Send();

        include ("header.$phpEx");
    OpenTable();
        echo "<center>".translate("The business card for")." <b>$title</b> ".translate("has been sent to")." $fname... ".translate("Thanks!")."<br /><a href=\"myyp.$phpEx?op=viewbizdetails&bid=$bid\">".translate("Back to Yellow Pages")."</a></center>";
    CloseTable();
        include ("footer.$phpEx");
}



function showNew(){
    global $phpEx, $mpnTables, $mf;
    $result = mysql_query("SELECT bid,cid,title,summary,date,status FROM ".$mpnTables['yp_business']." where status>0 ORDER BY date DESC LIMIT 10");
    while(list($bid,$cid,$title,$summary,$time,$status)=mysql_fetch_row($result)){
        $title = stripslashes($title);
        $summary = stripslashes($summary);
        $path = $mf->getPathFromId($cid);
        echo "<a href=myyp.$phpEx?op=viewbizdetails&bid=$bid><b>$title</b></a>";
            $newimage = newlinkgraphic($time, $status);
        echo $newimage;
            echo "<br />";
            echo "$summary<br />";
        echo "<font size=\"1\"><i>".translate("Category: ")."$path</i></font>";
        echo "<br /><br />";
    }
}


//generates top 10 charts by rating and hits for each main category
function topTen($rate, $hit){
    global $admin, $phpEx, $eh, $HTTP_GET_VARS, $mf;
    include("header.$phpEx");
    if($rate){
        $sort = "Rating";
        $sortDB = "rating";
    }elseif($hit){
        $sort = "Hits";
        $sortDB = "hits";
    }else{
    }
    mainheader();


    $arr=array();
    $result=mysql_query("select cid, title from ".$mpnTables['yp_categories']." where pid=0");
    if ($result) {

        openTable();

        while(list($cid,$ctitle)=mysql_fetch_row($result))
        {

            $boxtitle = "<FONT SIZE=\"3\" FACE=\"Arial, Verdana\">".$ctitle." Top 10 (by ".$sort.")</font>";
            $thing = "<table width=\"100%\" border=\"0\"><tr><td width=\"7%\" bgcolor=\"#DFDFDF\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Rank</b></font></td><td width=\"28%\" bgcolor=\"#DFDFDF\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Title</b></font></td><td width=\"40%\" bgcolor=\"#DFDFDF\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Category</b></font></td><td width=\"8%\" bgcolor=\"#DFDFDF\" align=\"center\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Hits</b></font></td><td width=\"9%\" bgcolor=\"#DFDFDF\" align=\"center\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Rating</b></font></td><td width=\"8%\" bgcolor=\"#DFDFDF\" align=\"right\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><b>Vote</b></font></td></tr>";
            $query = "select bid, cid, title, hits, rating, votes from ".$mpnTables['yp_business']." where status>0 and (cid=$cid";
            $arr=$mf->getAllChildId($cid);
            for($i=0;$i<sizeof($arr);$i++){
                $query .= " or cid=".$arr[$i]."";
            }
            $query .= ") order by ".$sortDB." DESC LIMIT 10";
            $result2 = mysql_query($query) or $eh->show("0013");
            $rank = 1;
            while(list($bid,$bcid,$btitle,$hits,$rating,$votes)=mysql_fetch_row($result2)){
                $rating = number_format($rating, 2);
                if($hit){
                    $hits = "<font color=\"#ff0000\">$hits</font>";
                } elseif($rate) {
                    $rating = "<font color=\"#ff0000\">$rating</font>";
                }else{
                }
                $catpath = $mf->getPathFromId($bcid);
                $catpath= substr($catpath, 1);
                $thing .= "<tr><td><FONT SIZE=\"2\" FACE=\"Arial, Verdana\">$rank</font></td>";
                $thing .= "<td><FONT SIZE=\"2\" FACE=\"Arial, Verdana\"><a href=\"myyp.".$phpEx."?op=viewbizdetails&bid=$bid\">$btitle</a></font></td>";
                $thing .= "<td><FONT SIZE=\"2\" FACE=\"Arial, Verdana\">$catpath</font></td>";
                $thing .= "<td align=\"center\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\">$hits</font></td>";
                $thing .= "<td align=\"center\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\">$rating</font></td><td align=\"right\"><FONT SIZE=\"2\" FACE=\"Arial, Verdana\">$votes</font></td></tr>";
                $rank++;
            }
            $thing .= "</table>";
            themecenterposts($boxtitle,$thing);
            echo "<br />";
        }
    CloseTable();
    }

    include("footer.$phpEx");
}

function makeCountrySelBox($country=""){
    $countries = array("United States","Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain"
,"Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guatemala","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Ivory Coast","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Norfolk Island","North Korea","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent/Grenadines","Samoa","San Marino","Saotome and Principe","Saudi Arabia","Senegal","Seychelles","Sierra Leone","Singapore","Slovak Republic","Slovenia","Solomon Islands","Somalia","South Africa","South Korea","Spain","Sri Lanka","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Virgin Islands","Uruguay","Uzbekistan","Vanuatu","Vatican","Venezuela","Vietnam","Western Sahara","Yemen","Yugoslavia","Zambia","Zimbabwe");

    $countrycodes =array("USA","AFG","ALB","DZA","ASM","AND","AGO","AIA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BIH","BWA","BRA","VGB","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","COL","COM","COG","COK","CRI","HRV","CUB","CYP","CZE","DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GTM","GIN","GNB","GUY","HTI","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","ISR","ITA","CIV","JAM","JPN","JOR","KAZ","KEN","KIR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MEX","FSM","MDA","MCO","MNG","MSR","MAR","MOZ","MMR","NAM","NPL","NLD","ANT","NCL","NZL","NIC","NER","NGA","NFK","PRK","MNP","NOR","OMN","PAK","PLW","PAN","PNG","PRY","PER","PHL","POL","PRT","PRI","QAT","REU","ROM","RUS","RWA","SHN","KNA","LCA","SPM","VCT","WSM","SMR","STP","SAU","SEN","SYC","SLE","SGP","SVK","SVN","SLB","SOM","ZAF","KOR","ESP","LKA","SDN","SUR","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","UGA","UKR","ARE","GBR","USA","VIR","URY","UZB","VUT","VAT","VEN","VNM","ESH","YEM","YUG","ZMB","ZWE");
    echo "<select name=country>";
    for($i=0;$i<sizeof($countries);$i++){
        if($country==$countrycodes[$i]){
            echo "<option value=\"$countrycodes[$i]\" selected>$countries[$i]</option>";
        } else {
            echo "<option value=\"$countrycodes[$i]\">$countries[$i]</option>";
        }
    }
    echo "</select>";
}

if (!isset($op))
{
    $op = null;
}

switch($op) {
    case "addBusinessS":
        addBusinessS();
        break;

    case "topTen":
        if (!isset($rate))
        {
            $rate = null;
        }

        if (!isset($hit))
        {
            $hit = null;
        }

        topTen($rate, $hit);
        break;

    case "viewcat":
        viewcat();
        break;

    case "brokenlink":
        brokenlink();
        break;

    case "modifybizrequest":
        modifybizrequest();
        break;

    case "modifybizrequestS":
        modifybizrequestS();
        break;

    case "brokenlinkS":
        brokenlinkS($bid);
        break;

    case "visit":
        visit($bid);
        break;

    case "addBusiness":
        addBusiness();
        break;

    case "search":

        $term = ( ! isset( $term ) ) ? ( '' ) : ( $term );
        $which = ( ! isset( $which ) ) ? ( '' ) : ( $which );
        $addterms = ( ! isset( $addterms ) ) ? ( '' ) : ( $addterms );
        $min = ( ! isset( $min ) ) ? ( '' ) : ( $min );
        $orderby = ( ! isset( $orderby ) ) ? ( '' ) : ( $orderby );
        $show = ( ! isset( $show ) ) ? ( '' ) : ( $show );

        searchbiz($term, $which, $addterms, $min, $orderby, $show);
        break;

    case "doRating":
        doRating($bid);
        break;

    case "addRating":
        addRating($bid, $rating);
        break;

    case "viewbizdetails":
        viewbizdetails($bid);
        break;

    case "printBizPage":
        printBizPage($bid);
        break;

    case "sendBusiness":
        sendBusiness($bid);
        break;

    case "businessSent":
        businessSent($bid, $yname, $ymail, $fname, $fmail);
        break;

    default:
        index();
        break;
}
?>
