<?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-index.php");

# ADJUST EXPLORE MODE IF NECESSARY
if (isset ($_REQUEST['explore']) && ( $_REQUEST['explore'] == 't' || $_REQUEST['explore'] == 'f' )) {
  $NETJUKE_SESSION_VARS['explore'] = $_REQUEST['explore'];
  netjuke_session ('update');
}

# HTML HEADER

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

# GET TABLE STATS
  if ($NETJUKE_SESSION_VARS['explore'] == 't')
    $ge_cnt = getCount('ge', ' where track_cnt > 0 and parent_id = 0 ');
  else
    $ge_cnt = getCount('ge', ' where track_cnt > 0 ');

# GENRE TABLE

  $ge_html = '';

  $sql = " SELECT ge.id, ge.name, ge.img_src, count(tr.id), upper(ge.name) AS val "
       . " from netjuke_genres ge, netjuke_tracks tr "
       . " where track_cnt > 0 and tr.ge_id = ge.id " . ($NETJUKE_SESSION_VARS['explore'] == 't' ? " and parent_id = 0" : '')
       . " group by ge.id order by val asc";
  $dbrs = $dbconn->Execute( $sql );

  $cnt = $row_cnt = 0;
  $subs = '';

  if ($dbrs !== false) {

    while (!$dbrs->EOF) {

	  if ($NETJUKE_SESSION_VARS['explore'] == 't') {
	  	$sql = "select count(id) from netjuke_genres where parent_id = ".$dbrs->fields[0];
	  	$db_cn = $dbconn->Execute ($sql);
	  	$sub_cnt = $db_cn->fields[0];
	  }

      if ($cnt % 3 == 0) {
        $ge_html .= "<TR>\n";
        $row_cnt++;
      }

      $ge_html .= "<td class='content' width='33%'>";

      if ($NETJUKE_SESSION_VARS['explore'] == 't')
        $subs = "&subs=1";
      else
        $subs = "&subs=0";

      $ge_html .= buildButton("./play.php?do=play_all&random=0&type=ge&id=".$dbrs->fields[0].$subs, BRWS_PLAY_GE_HELP, 'play')
               .  " ".buildButton("./play.php?do=play_all&random=1&type=ge&id=".$dbrs->fields[0].$subs, BRWS_PLAY_RANDGE_HELP, 'randplay')
               .  " ".(($NETJUKE_SESSION_VARS['gr_id'] <= 2) ? buildButton("./admin/md-edit.php?do=edit&type=ge&id=".$dbrs->fields[0], BRWS_PLAY_EDITGE_HELP, 'edit', 'NetjukeRemote') : "")
               .  ($NETJUKE_SESSION_VARS['explore'] == 't' ? " <A HREF='explore.php?do=list.artists&ge_id=".$dbrs->fields[0]."'" : " <A HREF='search.php?do=list.tracks&col=ge_id&val=".$dbrs->fields[0]."&sort=ge'" )
               .  "   title=\"".BRWS_GE_HELP."\">"
               .  format_for_display($dbrs->fields[1])."</A>"
               .  ($NETJUKE_SESSION_VARS['explore'] == 't' && $sub_cnt != 0 ? ' ['.$sub_cnt.']' : '')
			   .  " (".$dbrs->fields[3].")";

      $ge_html .= "</td>\n";

      if (($cnt + 1) % 3 == 0) $ge_html .= "</TR>\n";

      $dbrs->MoveNext();

      $cnt++;

    }

    $dbrs->Close();

  }

  if ( ($cnt + 2) % 3 == 0 ) {

    $ge_html .= "<td class='content' nowrap>&nbsp;</td>\n";
    $ge_html .= "<td class='content' nowrap>&nbsp;</td>\n";
    $ge_html .= "</tr>";

  } elseif ( ($cnt + 1) % 3 == 0 ) {

    $ge_html .= "<td class='content' nowrap>&nbsp;</td>\n";
    $ge_html .= "</tr>\n";

  }

  $row_cnt = $row_cnt;
  if (abs($row_cnt) < 5) $row_cnt = 5;

# ARTISTS TABLE

  $ar_html = GetLatestArtistsHTML ($row_cnt);

# ALBUM TABLE

  $al_html = GetLatestAlbumsHTML ($row_cnt);

  // Generate the explore/browse button
  if ($NETJUKE_SESSION_VARS['explore'] == 'f')
    $button = "<input type=button value='". BRWS_EXPLORE_HEADER ."'  onClick=\"self.location.href = '".WEB_PATH."/index.php?explore=t';\" class='btn_header' title=\"".  BRWS_EXPLORE_HEADER_HELP ."\">";
  else
    $button = "<input type=button value='". BRWS_BROWSE_HEADER ."'  onClick=\"self.location.href = '".WEB_PATH."/index.php?explore=f';\" class='btn_header' title=\"".  BRWS_BROWSE_HEADER_HELP ."\">";

  // print the common summary header
  SummaryHeader();

?>


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

         <table width='100%' border=0 cellspacing=1 cellpadding=3 class="border">
         <tr>

           <td class="header" colspan=3 nowrap>
            <table border=0 width=100% cellspacing=0 cellpadding=0>
              <tr>
                <td align=left class="header" nowrap>
                  <B><?php echo  BRWS_GE_HEADER ?></B> (<?php echo  $ge_cnt ?>)
                </td>
                 <td align=right>
                    <?php
                echo buildButton("./play.php?do=play_all&random=0&type=all", BRWS_PLAY_ALL_HELP, 'play', '', true);
                echo " ".buildButton("./play.php?do=play_all&random=1&type=all".$dbrs->fields[0].$subs, BRWS_RANDPLAY_ALL_HELP, 'randplay', '', true);
                echo " ".$button; ?>
                </td>
              </tr>
            </table>
           </td>
         </tr>

         <?php echo  $ge_html ?>

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

		</td>
		<td width="26%" align="right" valign="top">

         <table width='90%' border=0 cellspacing=1 cellpadding=3 class="border">
           <tr>
             <td class="header" nowrap>
              <table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align=left class="header" nowrap>
                <B><?php echo  BRWS_AR_HEADER ?></B>
                </td><td align=right>
                  <?php
                    echo buildButton("./play.php?do=play_latest&random=0&type=ar&count=".$row_cnt, BRWS_PLAY_ALL_AR_HELP, 'play', '', true);
                    echo " ".buildButton("./play.php?do=play_latest&random=1&type=ar&count=".$row_cnt, BRWS_RANDPLAY_ALL_AR_HELP, 'randplay', '', true);
                  ?>
                </td></tr>
              </table>
             </td>
           </tr>

           <?php echo  $ar_html ?>

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

		</td>
		<td width="26%" align="right" valign="top">

         <table width='90%' border=0 cellspacing=1 cellpadding=3 class="border">
           <tr>
             <td class="header" nowrap>
              <table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align=left class="header" nowrap>
                 <B><?php echo  BRWS_AL_HEADER ?></B>
                 </td><td align=right nowrap>
                   <?php
                     echo buildButton("./play.php?do=play_latest&random=0&type=al&count=".$row_cnt, BRWS_PLAY_ALL_AL_HELP, 'play', '', true);
                     echo " ".buildButton("./play.php?do=play_latest&random=1&type=al&count=".$row_cnt, BRWS_RANDPLAY_ALL_AL_HELP, 'randplay', '', true);
                   ?>
                 </td></tr>
               </table>
             </td>
           </tr>

           <?php echo  $al_html ?>

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

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

<?php

  # HTML footer
  include (INTERFACE_FOOTER);

?>
