<?php

// defines if this script requires to be logged in
define( "PRIVATE", false );

# CALL COMMON LIBRARIES

require_once('./lib/inc-common.php');
require_once(FS_PATH."/etc/locale/".LANG_PACK."/inc-community.php");

# make sure the community feature is enabled
if (ENABLE_COMMUNITY != 't') header(WEB_PATH."/index.php");


  $row_cnt = 10;


# $row_cnt LATEST SHARED PLAYLISTS

  $shrd_html = '';

  $dbrs = $dbconn->SelectLimit(  " SELECT id, us_email, title, comment "
                               . " from netjuke_plists  "
                               . " where shared_list = 't' "
                               . " order by created desc "
                               , $row_cnt );

  while (!$dbrs->EOF) {

    $shrd_html .= "<TR><td align=left class='content'>"
               . buildButton(WEB_PATH."/play.php?do=plist&val=".$dbrs->fields[0], CMNT_SHRD_PLAY_HELP, 'play')
               . " ".buildButton(WEB_PATH."/play.php?do=plist&random=1&val=".$dbrs->fields[0], CMNT_SHRD_PLAY_RAND_HELP, 'randplay')
               . " ".buildButton(WEB_PATH."/pl-shrd-view.php?do=view&pl_id=".$dbrs->fields[0]."&section=community", CMNT_SHRD_VIEW_HELP, 'info')
               . " <a href=\"".WEB_PATH."/pl-shrd-view.php?do=view&pl_id=".$dbrs->fields[0]."&section=community\" title=\"".CMNT_SHRD_VIEW_HELP."\">"
               . $dbrs->fields[2]."</a>"
               . "<br>".CMNT_SHRD_BY.": ".get_display_name($dbrs->fields[1]);

    if ($dbrs->fields[3] != '') $shrd_html .= "<br>" . $dbrs->fields[3];

    $shrd_html .= "</td></tr>";

    $dbrs->MoveNext();

  }

  $dbrs->Close();


# TOP $row_cnt DOWNLOADS

  $dl_html = '';

  $dbrs = $dbconn->SelectLimit(  " SELECT tr.id, tr.name, tr.dl_cnt "
                               . "   , tr.ar_id, ar.name, tr.al_id, al.name "
                               . "   , tr.ge_id, ge.name, tr.location "
                               . " from netjuke_tracks tr, netjuke_artists ar, "
                               . "   netjuke_albums al, netjuke_genres ge "
                               . " where tr.ar_id = ar.id "
                               . "   and tr.al_id = al.id "
                               . "   and tr.ge_id = ge.id "
                               . " order by tr.dl_cnt desc "
                               , $row_cnt );

  $cnt = 0;
  $top_10_plist = '';

  while (!$dbrs->EOF) {

    if ($cnt != 0) $top_10_plist .= ',';
    $top_10_plist .= $dbrs->fields[0];

    $cnt++;

    if (ENABLE_DOWNLOAD == 't') {

      $tr_location = $dbrs->fields[9];
      if (substr_count($tr_location,"://") < 1) $tr_location = STREAM_SRVR."/".$tr_location;
      if (substr_count($tr_location,"://") < 1) $tr_location  = WEB_PATH."/".$tr_location;
      $dload = " ".buildButton($tr_location, CMNT_DL_DLOAD_HELP, 'dload');

    } else {

      $dload = "";

    }

    if ($NETJUKE_SESSION_VARS['explore'] == 'f')
      $nav = "/search.php?do=list.tracks&col=ge.id&val=";
    else
      $nav = "/explore.php?do=list.artists&ge_id=";

    $dl_html .= "<TR>"
             .  "<td width='1%' align=right valign=top class='content'>"
             .  "$cnt "
             .  "</td>"
             .  "<td width='4%' align=center valign=top class='content' nowrap>"
             .  buildButton(WEB_PATH."/play.php?do=play&val=".$dbrs->fields[0], CMNT_DL_PLAY_HELP, 'play')
             .  $dload." ".buildButton(WEB_PATH."/tr-info.php?id=".$dbrs->fields[0], CMNT_DL_INFO_HELP, 'info', "NetJukeGetInfo")
             .  "</td>"
             .  "<td width='95%' align=left valign=top class='content'>"
             .  format_for_display($dbrs->fields[1])
             .  " &nbsp;[ <a href='".WEB_PATH.$nav.$dbrs->fields[7]."&sort=ge' title=\"".CMNT_DL_GENRE_HELP."\">".format_for_display($dbrs->fields[8])."</a> ]"
             .  "<br>".CMNT_DL_ARTIST.": <a href='".WEB_PATH."/search.php?do=list.tracks&col=ar.id&val=".$dbrs->fields[3]."&sort=ar' title=\"".CMNT_DL_ARTIST_HELP."\">".format_for_display($dbrs->fields[4])."</a>"
             .  " - ".CMNT_DL_ALBUM.": <a href='".WEB_PATH."/search.php?do=list.tracks&col=al.id&val=".$dbrs->fields[5]."&sort=al' title=\"".CMNT_DL_ALBUM_HELP."\">".format_for_display($dbrs->fields[6])."</a>"
             .  "</td></tr>";

    $dbrs->MoveNext();

  }

  $dbrs->Close();

# HTML HEADER

  $section = "community";
  include (INTERFACE_HEADER);

  // print the common summary header
  SummaryHeader();

?>

  <table width='100%' border=0 cellspacing=0 cellpadding=0>
      <tr>
       <td width="40%" align='left' valign='top' nowrap>

         <table width='100%' border=0 cellspacing=1 cellpadding=3 class="border">
         <tr>
           <td class="header" nowrap>
             <table width='100%' border=0 cellspacing=0 cellpadding=0>
             <form>
               <tr class="header">
                 <td align=left valign=middle nowrap>
                   <B><?php echo  CMNT_SHRD_HEADER ?></B>
                 </td>
                 <td align=right valign=middle nowrap>
                   <input type=button value="<?php echo  CMNT_SHRD_LIST_BTN ?>" onClick="self.location.href='<?php echo  WEB_PATH.'/pl-shrd-list.php' ?>';" class='btn_header'>
                 </td>
               </tr>
             </form>
             </table>
           </td>
         </tr>

         <?php echo  $shrd_html ?>

         </table>
         <?php
          if (ENABLE_XML == 't') {
            $xml_button = buildButton (WEB_PATH."/xml.php?do=show.latest&type=shared", COMMON_XML_HELP, 'xml');
            echo '<br><center>'.$xml_button.'</center>';
          }
        ?>

       </td>
       <td width="60%" align='right' valign='top' nowrap>

         <table width='95%' border=0 cellspacing=1 cellpadding=3 class="border">
         <tr>
           <td colspan=3 class="header" nowrap>
             <table width='100%' border=0 cellspacing=0 cellpadding=0>
             <form>
               <tr class="header">
                 <td align=left valign=middle nowrap>
                   <B><?php echo  CMNT_DL_HEADER ?></B>
                 </td>
                 <td align=right valign=middle nowrap>
                   <input type=button value="<?php echo  CMNT_DL_TOP10_BTN ?>" onClick="self.location.href='<?php echo  WEB_PATH.'/play.php?do=play&val='.$top_10_plist ?>';" class='btn_header'>
                 </td>
               </tr>
             </form>
             </table>
           </td>
         </tr>

         <?php echo  $dl_html ?>

         </table>
         <?php
          if (ENABLE_XML == 't') {
            $xml_button = buildButton (WEB_PATH."/xml.php?do=show.latest&type=popular", COMMON_XML_HELP, 'xml');
            echo '<br><center>'.$xml_button.'</center>';
          }
        ?>

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

<?php

  # HTML footer
  include (INTERFACE_FOOTER);

?>
