<?
  /* Main include info */
  ini_set('include_path',"/usr/web/sites/tuve.tv/include/");
  include("site.inc");

  /* Assign the page title */
  $data[tpl]->assign("PAGE_TITLE","");

  /* Main defines */
  $data[tpl]->define(array(index=>"index/index.html"));
  $data[tpl]->define(array(body=>"/search.html"));
  $data['tpl']->define(array("vs-rows"=>"vs-rows.html"));

  $skey = $data['search'];

  if ($data['stype'] == "people") {
    Header("Location: /people.php?data[skey]=$skey\n");
    exit;
    }

  $data['tpl']->assign("SEARCH",$skey);
  $gTypes = array('NA','Male','Female');

  if ($data['stype'] == "people") {
    $query = "SELECT uid,username,profile_image,caption,gender,byear,state_prov,country,laston FROM users WHERE username LIKE '%$skey%' OR firstname LIKE '%$skey%' OR lastname LIKE '%$skey%'";
    $res = mysql_query($query);

    for ($i = 0;$i < mysql_numrows($res);$i++) {
      $username = mysql_result($res,$i,'username');
      $thumb    = mysql_result($res,$i,'profile_image');
      $caption  = mysql_result($res,$i,'caption');
      $gender   = mysql_result($res,$i,'gender');
      $age      = date("Y") - mysql_result($res,$i,'byear');
      $location = mysql_result($res,$i,'state_prov') . ", " . mysql_result($res,$i,'country');
      $laston   = date("m/d/Y",mysql_result($res,$i,'laston'));

      $srows .= "<TR><TD ALIGN=\"CENTER\"><A HREF=\"/$username\"><IMG SRC=\"$thumb-small.png\" width=\"75\"><BR>$username</A></TD><TD VALIGN=\"TOP\"><B>Caption:</B> $caption<BR><B>Gender:</B> $gTypes[$gender]<BR><B>Age:</B> $age<BR><B>Location:</B> $location<BR><B>Last on:</B> $laston</TD></TR>\n";
      $srows .= "<TR><TD COLSPAN=\"2\"><HR></TD></TR>";
      }
    $data['tpl']->assign("SROWS",$srows);
    }
  else if ($data['stype'] == "video") {
    if ($data['rating'])
      $query = "SELECT vid,thumb,artist,title,length,count,username FROM videos v INNER JOIN users u ON v.oid = u.uid WHERE artist LIKE '%$skey%' OR title LIKE '%$skey%' AND rating <= $data[rating] ORDER BY artist,title";
    else
      $query = "SELECT vid,thumb,artist,title,length,count,username FROM videos v INNER JOIN users u ON v.oid = u.uid WHERE artist LIKE '%$skey%' OR title LIKE '%$skey%' AND rating < 4 ORDER BY artist,title";
    $res = mysql_Query($query);

    for ($i = 0;$i < mysql_numrows($res);$i++) {

      $len = mysql_result($res,$i,'length');
      $fLen = "0";
      if ($len > 3600) {
        $fLen = $len / 3600;
        $len = $len % $fLen;
        }
      if ($len > 60) {
        $fLen .= ":" . floor($len / 60);
        }
      $fLen .= ":" . $len % 60;

      $data['tpl']->assign("LENGTH",$fLen);
      $data['tpl']->assign("VIEWS",mysql_result($res,$i,'count'));
      $data['tpl']->assign("USERNAME",mysql_result($res,$i,'username'));
      $data['tpl']->assign("VID",mysql_result($res,$i,'vid'));
      $data['tpl']->assign("THUMB",mysql_result($res,$i,'thumb'));
      $data['tpl']->assign("ARTIST",mysql_result($res,$i,'artist'));
      $data['tpl']->assign("TITLE",mysql_result($res,$i,'title'));
      $data['tpl']->parse("SROWS",".vs-rows");
      } 
    }

  /* Parse and print */
  $data[tpl]->parse(BODY, array("body"));
  $data[tpl]->parse(INDEX, array("index"));
  $data[tpl]->FastPrint("INDEX");
?>
