<?php

// *****************************
// *                           *
// *        Wizard_Done        *
// *                           *
// *****************************

  include ("/connect/config.php");
  include ("check_session.php");
  include ("get_web_mode.php");
/*  include ("get_user_ID.php"); */
  include ("menu_builder_utilities.php");
/*
  // folder to store 'template wizard' user image uploads
  define ('USERS_IMAGE_FOLDER', '/' . BWB_IMAGE_DIR . '/');

  // true sets some variables or bypasses some code to make anonymous development easier
  define ('DEVELOPMENT', true);

  if (!DEVELOPMENT) {
    // check for valid cPanel User
    $cPanel_user_ID = get_user_ID();
    if ($cPanel_user_ID === false) {
      exit;
    } else {
      define('HOME_PATH', '/home/'.$cPanel_user_ID.'/public_html/');
    }
  } else {
    // SET THESE FOR ADMIN DEVELOPMENT PURPOSES
    $cPanel_user_ID = 'ebconten';
    define('HOME_PATH', '/home/'.$cPanel_user_ID.'/public_html/');
  }

  define ('SCRIPT_PATH', dirname(__FILE__));

  if (DEVELOPMENT) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    ini_set('log_errors', 1);
    ini_set('error_log', SCRIPT_PATH . '/error_log.txt');
  }

  if (get_web_mode($bwb_dbh)) {
    define('LOCAL_MODE', true);
  } else {
    define('LOCAL_MODE', false);
  }
*/
echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT";




  $mpnr ="menu_page_name_row";
  $ifn = "file_name";
  $itn = "image_tag";
  foreach ($_REQUEST as $key => $val) {
    switch ($key) {
      case "wizard_template_ID":
        $ID_request = $val;
      case "wizard_template_ID_previous":
        if ( empty($ID_request)) {
          $ID_request = $val;
        }
        break;
      case (stripos($key,$mpnr)):
        $menu[str_replace($mpnr,'',$key)-1] = $val;
        break;
      case "site_title":
          $wizArray['header_title'] = $val;
        break;
      case "tagline":
        $wizArray['tagline'] = $val;
        break;
      case (stripos($key,$ifn)):
        $image[str_replace($ifn.'_','',$key)]['name'] = $val;
        break;
      case (stripos($key,$itn)):
        $image[str_replace($itn.'_','',$key)]['tag'] = $val;
        break;
    }
   }

   if (!empty($ID_request)) $wizArray['template'] = $ID_request;

   if (!empty($menu) && is_array($menu)) {
     $menus = get_menu_label_list("*",false,"page_name IN ('" . implode("','",$menu) . "')");
     foreach ($menus as $key => $menu) {
       $wizArray[$menu['page_name'] . "_page"] = $menu['page_name'];
       $wizArray[$menu['page_name'] . "_sort"] = $key;
       $wizArray[$menu['page_name'] . "_link_text"] = $menu['link_text'];
       $wizArray[$menu['page_name'] . "_plugin_id"] = ($menu['plugin_id']>-1?$menu['plugin_id']:"");
     }
   }

   if (!empty($image) && is_array($image)) {
     foreach ($image as $key => $img) {
       if (!empty($img['name']) && !empty($img['tag'])) {
         $wizArray[$img['tag']] = $img['name'];
       }
     }
   }

echo json_encode($wizArray);
?>