home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / KOMUNIK / progweb / progweb.exe / phpnuke / html / search.php < prev    next >
PHP Script  |  2000-12-05  |  12KB  |  239 lines

  1. <?php
  2.  
  3. ######################################################################
  4. # PHP-NUKE: Web Portal System
  5. # ===========================
  6. #
  7. # Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
  8. # http://phpnuke.org
  9. #
  10. # This modules is a search engine. A portal without Search? bah!
  11. #
  12. # This program is free software. You can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License.
  15. ######################################################################
  16.  
  17. if(!isset($mainfile)) { include("mainfile.php"); }
  18.  
  19. switch($op) {
  20.  
  21.         case "comments":
  22.                 break;
  23.  
  24.         default:
  25.                 $offset=30;
  26.                 if (!isset($min)) $min=0;
  27.                 if (!isset($max)) $max=$min+$offset;
  28.                 $query = stripslashes($query);
  29.                 include("header.php");
  30.         if ($topic>0) {
  31.             $result = mysql_query("select topicimage, topictext from topics where topicid=$topic");
  32.             list($topicimage, $topictext) = mysql_fetch_row($result);
  33.         } else {
  34.             $topictext = "".translate("All Topics")."";
  35.             $topicimage = "AllTopics.gif";
  36.         }
  37.         echo "<table border=0 width=100% bgcolor=000000 cellpadding=1 cellspacing=0><tr><td>";
  38.         echo "<table border=0 width=100% bgcolor=FFFFFF cellpadding=5 cellspacing=0><tr><td>";
  39.         echo "<center><font size=4><b>".translate("Search in")." $topictext</b></center><br>";
  40.         ?>
  41.                 <TABLE WIDTH=100% BORDER=0>
  42.                 <TR><TD>
  43.         <img src=<?php echo "$tipath$topicimage"; ?> align=right border=0 Alt="<?php echo "$topictext"; ?>">
  44.                 <form action="search.php" method=get>
  45.                 <input size=25 type=text name=query value="<?php echo $query; ?>">
  46.         <input type=submit value="<?php echo translate("Search"); ?>"><br>
  47.                 <!-- Topic Selection -->
  48.         <?php
  49.         $toplist = mysql_query("select topicid, topictext from topics order by topictext");
  50.         echo "<SELECT NAME=\"topic\">";
  51.                 echo "<OPTION VALUE=\"\">".translate("All Topics")."</option>\n";
  52.                 while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
  53.                         if ($topicid==$topic) { $sel = "selected "; }
  54.                         echo "<option $sel value=\"$topicid\">$topics</option>\n";
  55.             $sel = "";
  56.                 }
  57.         echo "</SELECT>";
  58.         // Authors Selection -->
  59.                 $thing = mysql_query("select aid from authors order by aid");
  60.                 echo "<SELECT NAME=\"author\">";
  61.                 echo "<OPTION VALUE=\"\">".translate("All Authors")."</option>\n";
  62.                 while(list($authors) = mysql_fetch_row($thing)) {
  63.                         if ($authors==$author) { $sel = "selected "; }
  64.             echo "<option value=\"$authors\">$authors</option>\n";
  65.             $sel = "";
  66.                 }
  67.                 echo "</SELECT>";
  68.                 ?>
  69.                 <!-- Date Selection -->
  70.                 <select name="days">
  71.                         <option <?php echo $days == 0 ? "selected " : ""; ?> value=0><?php echo translate("All"); ?></option>
  72.                         <option <?php echo $days == 7 ? "selected " : ""; ?> value=7>1 <?php echo translate("week"); ?></option>
  73.                         <option <?php echo $days == 14 ? "selected " : ""; ?> value=14>2 <?php echo translate("weeks"); ?></option>
  74.                         <option <?php echo $days == 30 ? "selected " : ""; ?> value=30>1 <?php echo translate("month"); ?></option>
  75.             <option <?php echo $days == 60 ? "selected " : ""; ?> value=60>2 <?php echo translate("months"); ?></option>
  76.                         <option <?php echo $days == 90 ? "selected " : ""; ?> value=90>3 <?php echo translate("months"); ?></option>
  77.                 </select><br>
  78.                 <? echo translate("Search on:") ?> <input type=radio name=type value=stories checked> <?php echo translate("Stories") ?> <input type=radio name=type value=comments> <?php echo translate("Comments") ?> <input type=radio name=type value=sections> <?php echo translate("Sections") ?> <input type=radio name=type value=users> <?php echo translate("Users") ?>
  79.                 <?PHP
  80.                 echo "</form></td></tr></TABLE><P>";
  81.     
  82.     if ($type=="stories" OR !$type) {
  83.  
  84.                 $q = "select s.sid, s.aid, s.title, s.time, a.url, s.comments, s.topic from stories s, authors a where s.aid=a.aid ";
  85.                 if (isset($query)) $q .= "AND (s.title LIKE '%$query%' OR s.hometext LIKE '%$query%' OR s.bodytext LIKE '%$query%' OR s.notes LIKE '%$query%') ";
  86.                 if ($author != "") $q .= "AND s.aid='$author' ";
  87.                 if ($topic != "") $q .= "AND s.topic='$topic' ";
  88.                 if ($days != "" && $days!=0) $q .= "AND TO_DAYS(NOW()) - TO_DAYS(time) <= $days ";
  89.                 $q .= " ORDER BY s.time DESC LIMIT $min,$offset";
  90.         $t = $topic;
  91.                 $result = mysql_query($q);
  92.                 $nrows  = mysql_num_rows($result);
  93.                 $x=0;
  94.                 echo "<table width=99% cellspacing=0 cellpadding=0 border=0>\n";
  95.         if ($nrows>0) {
  96.                         while(list($sid, $aid, $title, $time, $url, $comments, $topic) = mysql_fetch_row($result)) {
  97.                 
  98.             $result2=mysql_query("select topictext from topics where topicid=$topic");
  99.             list($topictext) = mysql_fetch_row($result2);
  100.                         
  101.                     $furl = "article.php?sid=$sid";
  102.                                 formatTimestamp($time);
  103.                                 printf("<tr><td><font size=3><a href=\"%s\"><b>%s</b></a> <font size=2> ".translate("by")." <a href=\"%s\">%s</a>",$furl,$title,$url,$aid);
  104.                                 print " ".translate("on")." $datetime (<b>$comments</b>)</td></tr>\n";
  105.                                 $x++;
  106.                         }
  107.                 
  108.         echo "</td></tr></table>";
  109.         } else {
  110.                         echo "<center><font color=Red>".translate("No matches found to your query")."</font></center><br><br>";
  111.             echo "</td></tr></table>";
  112.                 }
  113.  
  114.                 $prev=$min-$offset;
  115.                 if ($prev>=0) {
  116.                         print "<a href=\"search.php?author=$author&topic=$t&min=$prev&query=$query&type=$type\">";
  117.                         print "<br><br><center><b>$min ".translate("previous matches")."</b></a>";
  118.                 }
  119.  
  120.                 $next=$min+$offset;
  121.         if ($x>=29) {
  122.                         print "<a href=\"search.php?author=$author&topic=$t&min=$max&query=$query&type=$type";
  123.                         print "§ion=$section\"><br><br><center><b>".translate("next matches")."</b></a>";
  124.                 }
  125.  
  126.  
  127.     } elseif ($type=="comments") {
  128.     
  129.                 $result = mysql_query("select tid, sid, subject, date, name from comments where (subject like '%$query%' OR comment like '%$query%') order by date DESC limit $min,$offset");
  130.                 $nrows  = mysql_num_rows($result);
  131.                 $x=0;
  132.         echo "<table width=99% cellspacing=0 cellpadding=0 border=0>\n";
  133.         if ($nrows>0) {
  134.                         while(list($tid, $sid, $subject, $date, $name) = mysql_fetch_row($result)) {
  135.                 $furl = "article.php?thold=-1&mode=flat&order=1&sid=$sid#$tid";
  136.                             if(!$name) {
  137.                 $name = "$anonymous";
  138.                 }
  139.                 formatTimestamp($date);
  140.                             echo "<tr><td><font size=3><a href=\"$furl\"><b>$subject</b></a> <font size=2> ".translate("by")." $name";
  141.                             print " ".translate("on")." $datetime</td></tr>\n";
  142.                             $x++;
  143.                         }
  144.  
  145.         echo "</td></tr></table>";
  146.         } else {
  147.                         echo "<center><font color=Red>".translate("No matches found to your query")."</font></center><br><br>";
  148.             echo "</td></tr></table>";
  149.                 }
  150.  
  151.                 $prev=$min-$offset;
  152.                 if ($prev>=0) {
  153.                         print "<a href=\"search.php?author=$author&topic=$t&min=$prev&query=$query&type=$type\">";
  154.                         print "<br><br><center><b>$min ".translate("previous matches")."</b></a>";
  155.                 }
  156.  
  157.                 $next=$min+$offset;
  158.         if ($x>=29) {
  159.                         print "<a href=\"search.php?author=$author&topic=$t&min=$max&query=$query&type=$type";
  160.                         print "§ion=$section\"><br><br><center><b>".translate("next matches")."</b></a>";
  161.                 }
  162.  
  163.     } elseif ($type=="sections") {
  164.     
  165.                 $result = mysql_query("select artid, secid, title, content from seccont where (title like '%$query%' OR content like '%$query%') order by artid DESC limit $min,$offset");
  166.                 $nrows  = mysql_num_rows($result);
  167.                 $x=0;
  168.         echo "<table width=99% cellspacing=0 cellpadding=0 border=0>\n";
  169.         if ($nrows>0) {
  170.                         while(list($artid, $secid, $title, $content) = mysql_fetch_row($result)) {
  171.                 $result2 = mysql_query("select secname from sections where secid='$secid'");
  172.                 list($sectitle) = mysql_fetch_row($result2);
  173.                 $surl = "sections.php?op=listarticles&secid=$secid";
  174.                 $furl = "sections.php?op=viewarticle&artid=$artid";
  175.                             echo "<tr><td><font size=3><a href=\"$furl\"><b>$title</b></a> ".translate("in the Section")." <a href=$surl>$sectitle</a></td></tr>\n";
  176.                             $x++;
  177.                         }
  178.  
  179.         echo "</td></tr></table>";
  180.         } else {
  181.                         echo "<center><font color=Red>".translate("No matches found to your query")."</font></center><br><br>";
  182.             echo "</td></tr></table>";
  183.                 }
  184.  
  185.                 $prev=$min-$offset;
  186.                 if ($prev>=0) {
  187.                         print "<a href=\"search.php?author=$author&topic=$t&min=$prev&query=$query&type=$type\">";
  188.                         print "<br><br><center><b>$min ".translate("previous matches")."</b></a>";
  189.                 }
  190.  
  191.                 $next=$min+$offset;
  192.         if ($x>=29) {
  193.                         print "<a href=\"search.php?author=$author&topic=$t&min=$max&query=$query&type=$type";
  194.                         print "§ion=$section\"><br><br><center><b>".translate("next matches")."</b></a>";
  195.                 }
  196.  
  197.     } elseif ($type=="users") {
  198.     
  199.                 $result = mysql_query("select uname, name from users where (uname like '%$query%' OR name like '%$query%' OR bio like '%$query%') order by uname ASC limit $min,$offset");
  200.                 $nrows  = mysql_num_rows($result);
  201.                 $x=0;
  202.         echo "<table width=99% cellspacing=0 cellpadding=0 border=0>\n";
  203.         if ($nrows>0) {
  204.                         while(list($uname, $name) = mysql_fetch_row($result)) {
  205.                 $furl = "user.php?op=userinfo&uname=$uname";
  206.                 if ($name=="") {
  207.                 $name = "".translate("No name entered")."";
  208.                 }
  209.                             echo "<tr><td><font size=3><a href=\"$furl\"><b>$uname</b></a> ($name)</td></tr>\n";
  210.                             $x++;
  211.                         }
  212.  
  213.         echo "</td></tr></table>";
  214.         } else {
  215.                         echo "<center><font color=Red>".translate("No matches found to your query")."</font></center><br><br>";
  216.             echo "</td></tr></table>";
  217.                 }
  218.  
  219.                 $prev=$min-$offset;
  220.                 if ($prev>=0) {
  221.                         print "<a href=\"search.php?author=$author&topic=$t&min=$prev&query=$query&type=$type\">";
  222.                         print "<br><br><center><b>$min ".translate("previous matches")."</b></a>";
  223.                 }
  224.  
  225.                 $next=$min+$offset;
  226.         if ($x>=29) {
  227.                         print "<a href=\"search.php?author=$author&topic=$t&min=$max&query=$query&type=$type";
  228.                         print "§ion=$section\"><br><br><center><b>".translate("next matches")."</b></a>";
  229.                 }
  230.  
  231.  
  232.  
  233.     }
  234.         
  235.         echo "</td></tr></table></td></tr></table>\n";
  236.         include("footer.php");
  237.                 break;
  238. }
  239. ?>