<?php
  $wizard_template_page = substr(__FILE__,-5,1);
  include ("wizard_common_top.php");

?>
   </header>
  <div id="wrapper" onclick="">
    <section>
<?php

 include ("menu_builder_utilities.php");
  if (!empty($menu_row_cache)  && is_array($menu_row_cache)) {
    $menu = $menu_row_cache;
  } else {
    $menu = get_menu_label_list('*',true);
  }
//echo "START";
//echo "wiz step 2 menu_row_cache =";
//print_r($menu);
//echo "rows=";
//print_r($rows);
//echo "menu_row_cache= ";         
//echo $menu_row_cache;
//echo "is_array? ="; 
//echo is_array($menu_row_cache);
//echo "END";
/*print "<pre style=\"text-align:right;\">";
echo "post=";
print_r($_POST);
echo "ecommerce=";
print_r($ecommerce);
print "</pre>";*/


  $menu_rows = count($menu)+1; // number of rows initially displayed
  $myString1 = "";
  $myString1 .= str_pad("", 10) . "<h1>Select Your Pages</h1>\n";
  $myString1 .= str_pad("", 12) . "<p>We've started you off
                                  with some commonly used page templates.  Click on any Page Name to change it.  Click the  'x' to remove any you don't want, and the arrows 
                                  to arrange them.</p>\n";
  $myString1 .= str_pad("", 12) . "<p>The menu will be updated automatically!</p>\n";
  $myString1 .= str_pad("", 12) . "<div id='table'>\n";

  for ($menu_row=0; $menu_row <= $menu_rows; $menu_row++) {
    $is_header = false;
    $is_footer = false;
    switch ($menu_row) {
      case 0: // HEADER: column labels
        $is_header = true;
        $menu_col_array = array ('Page Name','File Name','Plugin Available','Up','Down','Del');
        $menu_css_array = array ('','','','','','');
        break;
      case $menu_rows: // FOOTER: add row
        $is_footer= true;
        $menu_col_array = array ("<h1 style='float: right;'>Add a Page: &nbsp;  </h1>",'','','','','');
        $menu_css_array = array ('','','',' e_add','','');
        $menu_tt_array = array ("",
                                " title='click to edit Page Name'\n" . str_pad("", 25) . "alt='click to select edit Page Name' ",
                                "",
                                " title='add row' alt='add row'",
                                "",
                                "");
        $menu_js_array = array ('','',''," id='add_icon' onclick='add_row(this);'",'',"");
        break;
      default: // menu row items
        //echo $menu[$menu_row-1]['link_text'];
        $menu_col_array = array ($menu[$menu_row-1]['link_text'],$menu[$menu_row-1]['page_name'],($menu[$menu_row-1]['plugin_id']==-1?"no":"yes"),'','','');
        $menu_css_array = array ('','',''," e_up"," e_down"," e_del");
        $menu_tt_array = array (" title='click to select page Label'\n" . str_pad("", 25) . "alt='click to select page Label' ",
                                " title='click to edit Page Name'\n" . str_pad("", 25) . "alt='click to select edit Page Name' ",
                                "",
                                " title='move row up'\n" . str_pad("", 25) . "alt='move row up'",
                                " title='move row down'\n" . str_pad("", 25) . "alt='move row down'",
                                " title='delete row'\n" . str_pad("", 25) . "alt='delete row'");
        $menu_js_array = array ("","","",
                                " onclick='move_up(this);'",
                                " onclick='move_down(this);'",
                                " onclick='delete_row(this);'");
      }

    $myString1 .= str_pad("", 14) . "<div id='menu_row_";
    $myString1 .= (($menu_row < $menu_rows) ? $menu_row : "add") . "' class='row";

    if ($is_header) {
      $myString1 .= " header_row";
    } elseif ($is_footer) {
      $myString1 .= " add_row";
    } else {
      $myString1 .= (($menu_row & 1)?" odd_row":" even_row");
      if ($menu_row == 1) {
        $myString1 .= " first";
      } elseif ($menu_row == $menu_rows-1) {
        $myString1 .= " last";
      }
    }
    $myString1 .= "'>\n";

    $menu_col = "";

    for ($menu_col=0; $menu_col<6; $menu_col++) {
      $myString1 .= str_pad("", 16) . "<span class='cell col_";
      $myString1 .= intval($menu_col+1) . $menu_css_array[$menu_col] . "'>\n";

      switch ($menu_col) {
        case 0: // LABEL:
          if ($is_header) {
            $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          } else{
            $myString1 .= str_pad("", 18) . "<a class='view_value'\n";
            //Don't put the onclick method on the last 'add row':
            $myString1 .= str_pad("", 25) . (($menu_row < $menu_rows) ? "onclick='return toggle_child(this);'" : "")." \n";
            //Becaause it has an <a> tag and the add row label should not be clickable, remove the cursor pointer...
            $myString1 .= str_pad("", 25) . (($menu_row < $menu_rows) ? "" : "style='cursor: default;'")." \n";
            $myString1 .= str_pad("", 22) . $menu_tt_array[$menu_col] . ">\n";
//echo $menu_col_array[$menu_col];
            $myString1 .= str_pad("", 20) . $menu_col_array[$menu_col] . "\n";
            $myString1 .= str_pad("", 18) . "</a>\n";
            $myString1 .= get_menu_label_selector($menu_row,$menu_col_array[$menu_col],$menu_rows);
          }
        break;
        case 1: // FILE NAME:
          if ($is_header) {
            $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          } else{
            $myString1 .= str_pad("", 18) . "<a class='view_value'\n";
            $myString1 .= str_pad("", 22) . "onclick='return toggle_child(this);'\n";
            $myString1 .= str_pad("", 22) . $menu_tt_array[$menu_col] . ">\n";
            $myString1 .= str_pad("", 20) . $menu_col_array[$menu_col] . "\n";
            $myString1 .= str_pad("", 18) . "</a>\n";
            $myString1 .= str_pad("", 18) . "<input onKeyPress='return ignoreEnterKey(event,this);' \n";
//            $myString1 .= str_pad("", 29) . "onblur='set_value(this);' \n";  NOTE: THIS HAS BEEN REMOVED BECAUSE IT TRIGGERS A BLANK WITH add_row()
            $myString1 .= str_pad("", 31) . "name='menu_page_name_row" . $menu_row . "' \n";
            $myString1 .= str_pad("", 33) . "id='edit_fn" . $menu_row . "' \n";
            $myString1 .= str_pad("", 30) . "class='edit_value hide_value' \n";
            $myString1 .= str_pad("", 31) . "type='text' \n";
            $myString1 .= str_pad("", 30) . "value='" . $menu_col_array[$menu_col] . "'>\n";
          }
          break;
        case 2: // PLUGIN?:
   /*       $myString1 .= str_pad("", 18) . "<span class='view_value'>\n";  */
          $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          if (!$is_header) {
              $myString1 .= str_pad("", 18) . "<input name='menu_plugin_row" . $menu_row . "' \n";
    //        $myString1 .= str_pad("", 33) . "id='edit_fn" . $menu_row . "' \n";
              $myString1 .= str_pad("", 25) . "type='hidden' \n";
              $myString1 .= str_pad("", 24) . "value='" . $menu_col_array[$menu_col] . "'>\n";
          }
   /*       $myString1 .= str_pad("", 18) . "</span>";         */
          break;
        case 3:
          if (!$is_header) {
            $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          }
        case 4:
          if (!$is_header) {
            $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          }
        case 5: // EDIT ICONS:
          $myString1 .= str_pad("", 18) . $menu_col_array[$menu_col] . "\n";
          if (!$is_header) {
            $myString1 .= str_pad("", 18) . "<a" . $menu_js_array[$menu_col] . "\n";
            $myString1 .= str_pad("", 22) . $menu_tt_array[$menu_col] . ">\n";
            $myString1 .= str_pad("", 18) . "</a>";
          }
        break;
      }
      $myString1 .= "\n" . str_pad("", 16) . "</span>\n";
    }

    $myString1 .= str_pad("", 14) . "</div> <!-- END row -->\n";
  }

  $myString1 .= str_pad("", 12) . "</div> <!-- END table -->\n";
  $myString1 .= str_pad("", 12) . "<p></p>\n";
  $myString1 .= str_pad("", 12) . "<div class='nav_btn_box'>\n";
  $myString1 .= str_pad("", 14) . "<label class='float_l' for='goto_page_1'>\n";
  $myString1 .= str_pad("", 16) . "<img class='nav_btn' src='/wizard/images/blue_back_btn.png' alt='back_button'>\n";
  $myString1 .= str_pad("", 14) . "</label>\n";
  $myString1 .= str_pad("", 14) . "<label class='float_r' for='goto_page_3' class='right_btn'>\n";
  $myString1 .= str_pad("", 16) . "<img class='nav_btn' src='/wizard/images/blue_next_btn.png' alt='next_button'>\n";
  $myString1 .= str_pad("", 14) . "</label>\n";
  $myString1 .= str_pad("", 12) . "</div>\n";
$myString1 .= str_pad("", 12) . "<div id='test'>\n";
$myString1 .= str_pad("", 12) . "</div>\n";

  echo $myString1;

  echo "<script type='text/javascript' language='JavaScript'>\n";
  echo "  var menu_row_count=" . $menu_rows . ";\n";
  $php_array = get_menu_label_list('id, link_text, page_name, plugin_id',false);
  $js_array = json_encode($php_array);
  echo "var menu_array = ". $js_array . ";\n";
  echo "</script>\n\n";
?>
    </section> <!-- END -->

<?php
  include ("wizard_common_bottom.php")
?>