<?
  /* 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=>"view.html"));
  $data['tpl']->define(array(view_row=>"view-row.html"));

  //DoSession();


  $query = "SELECT v.artist,title,v.oid,description,username,bio,photo FROM videos v INNER JOIN users u ON v.oid = u.uid RIGHT JOIN artists a ON v.aid = a.aid WHERE vid = $data[vid]";
  $res = mysql_query($query);

  if ($res) {
    $OID = mysql_result($res,0,'oid');
    $vTitle = "Artist: " . mysql_result($res,0,'artist') . "<BR>Title: " . mysql_result($res,0,'title');
    $data['tpl']->assign("CVID",$data['vid']);
    $data['tpl']->assign("VID_TITLE",$vTitle);
    $data['tpl']->assign("USER",mysql_result($res,0,'username'));
    $data['tpl']->assign("BIOGRAPHY",fixHTML(mysql_result($res,0,'bio')));
    $data['tpl']->assign("BIO_IMG",mysql_result($res,0,'photo'));
    $data['tpl']->assign("DESCRIPTION",fixHTML(mysql_result($res,0,'description')));
    }


  if ($data['rating']) 
    $query = "SELECT vid,artist,title,thumb,count,length FROM videos WHERE oid = $OID AND rating <= $data[rating] AND mType = 1 ORDER BY vid DESC";
  else
    $query = "SELECT vid,artist,title,thumb,count,length FROM videos WHERE oid = $OID AND rating < 4 AND mType = 1 ORDER BY vid DESC";
  $res = mysql_query($query);

  //$rows = mysq_num_rows($res);

  for ($i = 0;$i < mysql_num_rows($res) && $i < 20;$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("ARTIST",mysql_result($res,$i,'artist'));
    $data['tpl']->assign("TITLE",mysql_result($res,$i,'title'));
    $data['tpl']->assign("VID",mysql_result($res,$i,'vid'));
    $data['tpl']->assign("THUMB",mysql_result($res,$i,'thumb'));
    $data['tpl']->assign("VIEWS",mysql_result($res,$i,'count'));
    $data['tpl']->parse("NEW_VIDS",".view_row");
    }

  


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