<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "../lib/viewer_functions.php";

  //
  list($categoryRecords, $selectedCategory) = getCategories(array(
    'tableName'            => 'category',

    'rootCategoryNum'      => '',         // Only categories _below_ this one will be shown (defaults to 0 for all)
    'defaultCategory'      => 'first',    // Enter 'first', a category number, or leave blank '' for none
//    'ulAttributes'       => "ulAttributesText",    // add html attributes to <ul> tags

    'selectedCategoryNum'   => '',        // defaults to getLastNumberInUrl()
    'categoryFormat'        => 'showall', // showall, onelevel, twolevel, breadcrumb

    'ulAttributesCallback' => 'myUlAttr', // ADVANCED: custom function to return ul attributes, eg: myUlAttr($category);
    'liAttributesCallback' => 'myLiAttr', // ADVANCED: custom function to return li attributes, eg: myLiAttr($category);

    //'debugSql'           => true,

  ));

function myUlAttr($category) {
  return "id='ul_uniqueId_{$category['num']}'";
}

function myLiAttr($category) {
  return "id='li_uniqueId_{$category['num']}'";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css">
    body          { font-family: arial; }
  </style>
 </head>
<body>

<table border="1" cellspacing="0" cellpadding="2" width="800"><tr><td valign="top" width="200">

<!-- category menu -->
  <h3>Nested Menu</h3>
  <?php foreach ($categoryRecords as $categoryRecord): ?>
    <?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

    <?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
    <a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
    (<?php echo $categoryRecord['_isChildSelected'] ?>)
    <?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>

    <br/>
  <?php endforeach; ?>
<!-- /category menu -->

  <br/><br/>

  <h3>Unorder List Menu</h3>
  <!-- unordered list -->
  <ul>
  <?php foreach ($categoryRecords as $categoryRecord): ?>
    <?php echo $categoryRecord['_listItemStart'] ?>

    <?php if ($categoryRecord['_isSelected']): ?>
      <b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></b>
    <?php else: ?>
      <a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
    <?php endif; ?>

    <?php echo $categoryRecord['_listItemEnd'] ?>
  <?php endforeach; ?>
  </ul>
  <!-- /unordered list -->

  <br/><br/>


</td><td valign="top">


<?php
  $selectedNum     = intval($selectedCategory['num']);
  $recordsOnBranch = mysql_select('category', "lineage LIKE '%:$selectedNum:%'");
  $branchNums      = array_pluck($recordsOnBranch, 'num');
  $branchNumsAsCSV = mysql_getValuesAsCSV($branchNums);

  print "Selected category num: " .$selectedCategory['num']. "<br/>\n";
  print "All nums in branch: $branchNumsAsCSV<br/>\n";
  print "Sample MySQL where: IN ($branchNumsAsCSV)";
?>
<br/><br/>
<?php

  //
  list($recordsOnBranch) = getCategories(array(
    'tableName'            => 'category',
    'rootCategoryNum'      => $selectedCategory['parentNum'],
    'categoryFormat'       => 'showall',
  ));

  $branchNums      = array_pluck($recordsOnBranch, 'num');
  $branchNumsAsCSV = mysql_getValuesAsCSV($branchNums);

  print "Selected category num: " .$selectedCategory['num']. "<br/>\n";
  print "All nums in branch: $branchNumsAsCSV<br/>\n";
  print "Sample MySQL where: IN ($branchNumsAsCSV)";

showme($recordsOnBranch);
?>


<?php showme($selectedCategory); ?>

</td></tr></table>




</body>
</html>
