<?php

    /**
     * Smart Report Maker
     * Version 9.0.0
     * Author : Webuccino
     * All copyrights are preserved to Webuccino
     * URL : http://mysqlreports.com/
     */
    defined('DIRECTACESS') or die("Error 301: Access denied!");
    defined('BASEPATH') or define('BASEPATH', 1);
    $default = "new";
    $disable = "";
    require_once "request.php";
    require_once "lib.php";
    require_once 'checkSession.php';
    require_once 'services/functions.php';

    //$categories = array();
    $categories                     = $srm_dashboard->get_all_categories_names();
    $groups                         = $srm_dashboard->get_all_groups_names();
    $_SESSION["tmp_all_categories"] = $categories;

    $categories_options = array();

    $categories_options[0] = "<option value='no value' selected>Select a saved category</option>";

    foreach ($categories as $category_id => $category_name) {

        if (isset($_SESSION[Session_report_Settings_key]["category_id"]) && $category_id == $_SESSION[Session_report_Settings_key]["category_id"]) {
            $categories_options[] = "<option value='" . $category_id . "' selected>$category_name</option>";
        } else {
            $categories_options[] = "<option value='" . $category_id . "'>$category_name</option>";
        }

    }

    $default          = "existing";
    $currentUserGroup = $_SESSION[Session_security_key][srm_access_group];

    if ($_SESSION[Session_security_key][srm_access_role] == "admin") {

        foreach ($groups as $id => $name) {

            if (isset($_SESSION[Session_report_Settings_key]["access_groups"]) && !empty($_SESSION[Session_report_Settings_key]["access_groups"])) {

                foreach ($_SESSION[Session_report_Settings_key]["access_groups"] as $access_group) {

                    if ($id == $access_group) {
                        $groups_options[] = "<option value='" . $id . "' selected>$name</option>";
                    } else {
                        $groups_options[] = "<option value='" . $id . "'>$name</option>";
                    }

                }

            } else {
                $groups_options[] = "<option value='" . $id . "'>$name</option>";
            }

        }

    } else {

        if (isset($_SESSION[Session_report_Settings_key]["access_groups"]) && !empty($_SESSION[Session_report_Settings_key]["access_groups"]) &&
            in_array($currentUserGroup, $_SESSION[Session_report_Settings_key]["access_groups"])) {

            $groups_options[] = "<option value='" . $currentUserGroup . "' selected>" . $groups[$currentUserGroup] . "</option>";
        } else {
            $groups_options[] = "<option value='" . $currentUserGroup . "'>" . $groups[$currentUserGroup] . "</option>";

        }

    }

    /*
     * #################################################################################################
     * Security options loading
     * ################################################################################################
     */

    if (isset($_SESSION[Session_report_Settings_key]["access_rule"]) && $_SESSION[Session_report_Settings_key]["access_rule"] == private_report && empty($_SESSION[Session_report_Settings_key]["access_groups"])) {
        $only_admin       = "yes";
        $is_public_access = "no";
        $admin_and_users  = "no";
    } elseif (isset($_SESSION[Session_report_Settings_key]["access_rule"]) && $_SESSION[Session_report_Settings_key]["access_rule"] == private_report && !empty($_SESSION[Session_report_Settings_key]["access_groups"])) {
        $is_public_access = "no";
        $only_admin       = "no";
        $admin_and_users  = "yes";
        // loading the members and security settings
    } elseif (isset($_SESSION[Session_report_Settings_key]["access_rule"]) && $_SESSION[Session_report_Settings_key]["access_rule"] == public_report && empty($_SESSION[Session_report_Settings_key]["access_groups"])) {
        $is_public_access = "yes";
        $only_admin       = "no";
        $admin_and_users  = "no";
    } else {
        // default case .
        $is_public_access = "no";
        $only_admin       = "no";
        $admin_and_users  = "yes";
    }

    $used_language = (isset($_SESSION[Session_report_Settings_key]["language"]) && !empty($_SESSION[Session_report_Settings_key]["language"])) ? $_SESSION[Session_report_Settings_key]["language"] : "en";

    if (sessionBe4Step4() === false) {
        header("location: $url?id=1");
        exit();
    } elseif (sessionBe4Step5() === false) {
        header("location: $url?id=2");
        exit();
    }

    $_SESSION[Session_wizard_key]["page_key"] = "step_6";
    require_once 'activePages.php';

    // set layout and images associated with it
    $layout = isset($_SESSION[Session_report_Settings_key]["layout"]) ? $_SESSION[Session_report_Settings_key]["layout"] : 'AlignLeft';

    if (strtolower($layout) == 'alignleft') {
        $image = 'layout_align_left1.gif';
    } elseif (strtolower($layout) == 'mobile') {
        $image = 'mob-layout.png';
    } elseif (strtolower($layout) == 'stepped') {
        $image = 'layout_stepped.gif';
    } elseif (strtolower($layout) == 'block') {
        $image = 'layout_block.gif';
    } elseif (strtolower($layout) == 'horizontal') {
        $image = 'horizontal.gif';
    }

    if (isset($_SESSION[Session_report_Settings_key]["style_name"]) && !empty($_SESSION[Session_report_Settings_key]["style_name"])) {
        $style_name = $_SESSION[Session_report_Settings_key]["style_name"];
    } else {
        $_SESSION[Session_report_Settings_key]["style_name"] = "default";
        $style_name                                          = "default";
    }

    // read styles from styles directory
    $styles     = "";
    $all_styles = array(
        "blue",
        "default",
        "grey"
    );

    if (strtolower($layout) != "mobile") {

        foreach ($all_styles as $style) {

            $formatted_css_name = $style;

            if ($style_name === $formatted_css_name) {
                $styles .= "<option value='$formatted_css_name' selected>" . ucfirst($formatted_css_name) . "</option>";
            } else {
                $styles .= "<option value='$formatted_css_name'>" . ucfirst($formatted_css_name) . "</option>";
            }

        }

    } else {
        $styles .= "<option value='mobile' selected> Mobile </option>";
    }

    // get default value for titles
    function get_default_value($var)
    {

        if (!isset($_SESSION[Session_report_Settings_key]["records_per_page"])) {
            $_SESSION[Session_report_Settings_key]["records_per_page"] = 25;
        }

        if ($var == 'txt_report_title') {
            $s_var = 'title';
        } elseif ($var == 'txt_report_header') {
            $s_var = 'header';
        } elseif ($var == 'txt_report_footer') {
            $s_var = 'footer';
        } elseif ($var == 'txt_report_name') {
            $s_var = 'file_name';
        } elseif ($var == 'txt_records_per_page') {
            $s_var = 'records_per_page';
        }

        if (isset($_SESSION[Session_report_Settings_key][$s_var]) && !empty($_SESSION[Session_report_Settings_key][$s_var])) {
            return $_SESSION[Session_report_Settings_key][$s_var];
        } else {
            return "";
        }

    }

?>

<div class="modal fade" id="confirm-public-report-modal" data-bs-backdrop="static" tabindex="-1" role="dialog"
  aria-labelledby="confirm-public-report" aria-hidden="true">
  <div class="modal-dialog " role="document" style="min-height: calc(100% - 3.5rem);">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="confirm-public-reportLabel">Confirmation</h4>
      </div>
      <div class="modal-body">
        <p>Will this report be accessible to any internet user, even if they haven't logged into the system? Are you
          certain this is your intended action?</p>
        <div class="text-center" style="text-align:center!important">
          <button type="button" class="btn btn-danger" id="saveBtn-confirm-public-report"
            style="outline: none;margin: 5px 3px;padding: 10px 50px;">
            Yes
          </button>
          <button type="button" class="btn btn-light" data-dismiss="modal" id="cancelBtn-confirm-public-report"
            style="outline: none;margin: 5px 3px;padding: 10px 50px;">
            No
          </button>
        </div>

      </div>
    </div>
  </div>
</div>


<div id="tabs" style="min-height: 350px;" class="container col-xs-12">
  <!-- -->
  <!-- Nav tabs nav nav-tabs -->
  <ul class="" style="font-size: 12px;">
    <li class="active"><a id="layout-nav" href="#layout" data-toggle="tab"><span
          class="glyphicon glyphicon-list"></span> Appearance</a></li>
    <li class="active"><a id="security-nav" href="#securityPanel" data-toggle="tab"><span
          class="glyphicon glyphicon-lock"></span>
        Security</a></li>
    <li class="active"><a id="titles-nav" href="#titlesPanel" data-toggle="tab"><span
          class="glyphicon glyphicon-pencil"></span>
        Titles</a></li>
  </ul>
  <!-- Tab panes -->
  <div class="tab-content">
    <div class="tab-pane active" id="layout">
      <form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return false;">
        <!-- Please select the report layout -->
        <div class="row">
          <div class="col-xs-1"></div>
          <div id="layout-error-container" class="col-xs-10"></div>
          <div class="col-xs-1"></div>
        </div>
        <div class="row">
          <div class="col-xs-1"></div>
          <div class="col-xs-3" style="margin: 0px; padding: 0px; border-bottom: 1px solid #dfdfdf;">Layout</div>
          <div class="col-xs-8"></div>
        </div>
        <div class="row">
          <div class="col-xs-1"></div>
          <div class="col-xs-3">


            <div class="row">
              <div class="radio">
                <label> <input type="radio" name="option" id="AlignLeft" value="AlignLeft" /> Align Left
                </label>
              </div>
            </div>
            <div class="row">
              <div class="radio">
                <label> <input type="radio" name="option" id="Stepped" value="Stepped" /> Stepped
                </label>
              </div>
            </div>
            <div class="row">
              <div class="radio">
                <label> <input type="radio" name="option" id="Block" value="Block" /> Block
                </label>
              </div>
            </div>

            <div class="row">
              <div class="radio">
                <label> <input type="radio" name="option" id="Mobile" value="Mobile" /> Mobile
                  <!--onclick="document['img_layout'].src= 'images/mob-layout.png';"-->
                </label>
              </div>
            </div>
            <div class="row">
              <div class="radio">
                <label> <input type="radio" name="option" id="Horizontal" value="Horizontal" />Horizontal <span
                    style="color: red; font-size: 10px;">(new)*</span>
                </label>
              </div>
            </div>
          </div>
          <div class="col-xs-6">
            <img src="includes/images/<?php echo $image; ?>" width="233" height="210" id="img_layout" name="img_layout"
              class="img-thumbnail" />

          </div>
          <div class="col-xs-2">
            <a href="" id="layoutHelp" onclick="return false;"> <img src="includes/images/help.png" width="15"
                height="15" border="0">
            </a>
          </div>
        </div>

        <hr />

        <div class="row" style="margin-top: -10px;">
          <div class="col-xs-1" style="margin-left: -10px;"></div>
          <div class="form-group col-xs-5">
            <label for="style_name">Styles</label>
            <div class="left-inner-addon">
              <i class="glyphicon glyphicon-fire"></i> <select id="style_name" name="style_name" class="form-control">
                <!--  onChange="refresh()" -->
                <?php echo $styles; ?>
              </select>
            </div>
          </div>
          <div class="help-container-i col-xs-6">
            <a href="" id="styleHelp" onClick="return false;"> <img src="includes/images/help.png" width="15"
                height="15" border="0">
            </a>
          </div>

        </div>



        <!-- .row (style_name) -->

      </form>
    </div>
    <div class="tab-pane" id="securityPanel" style="min-height: 250px;">
      <form name="secForm" id="secForm" role="form" action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post"
        onsubmit="return false;">

        <input type='hidden' id='csrfToken' name='csrfToken' value='<?php echo $request_token_value; ?>' />

        <div class="row">
          <div class="col-xs-1"></div>

          <div id="error-container" class="col-xs-10"></div>
          <div class="col-xs-1"></div>
        </div>

        <!-- -->
        <div class="row">
          <a class="cr-hand" id="mainSettings"><span class="glyphicon glyphicon-view"></span> <span
              class="glyphicon glyphicon-eye-open"></span> Who can access the
            generated report ?</a>
        </div>

        <div class="row" id="adminOnly">
          <div class="row">
            <div class="col-xs-1"></div>
            <div class="col-xs-10">
              <div>
                <label class="lblsecurity"> <input class="radiosecurity" type="radio" id="adminAndUsers"
                    value="adminAndUsers" name="access"                                                        <?php

                                                            if (strtolower($admin_and_users) == "yes") {
                                                                echo "checked";
                                                            }

                                                        ?> />
                  Admins and registered members from specific group(s).
                </label>

                <a href="" id="accessGroupsHelp" onclick="return false;" data-toggle="popover" data-original-title=""
                  title=""> <img src="includes/images/help.png" width="15" height="15" border="0">
                </a>

                <div id="groups-list">
                  <select id="groups" size=13 class="form-control" multiple style="height: 100px;">
                    <?php

                        foreach ($groups_options as $option) {
                            echo $option;
                        }

                    ?>
                  </select>
                </div>

              </div>
              <div>
                <label class="lblsecurity"> <input class="radiosecurity" type="radio" value="adminOnly" name="access"                                                                                                                      <?php

                                                                                                                          if (strtolower($only_admin) === "yes") {
                                                                                                                              echo "checked";
                                                                                                                          }

                                                                                                                      ?> />
                  Admins exclusively.
                </label>
              </div>

              <div>
                <label class="lblsecurity"> <input class="radiosecurity" type="radio" id="public" value="public"
                    name="access"                                  <?php

                                      if (strtolower($is_public_access) === "yes" && strtolower($only_admin) != "yes" && strtolower($admin_and_users) != "yes") {
                                          echo "checked";
                                      }

                                  ?> />
                  The public (accessible to anyone on the internet).
                </label>
              </div>
              <br />

            </div>
          </div>
        </div>

    </div>




    </form>
  </div>
  <div class="tab-pane" id="titlesPanel">

    <form id="titlesForm" name="titlesForm" action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post"
      onsubmit="return false;">
      <!-- Report Settings -->
      <div class="row">
        <div class="col-xs-1"></div>
        <div id="titles-error-container" class="col-xs-10"></div>
        <div class="col-xs-1"></div>
      </div>
      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_report_title">Report Title</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i> <input name="txt_report_title" class="form-control" type="text"
              id="txt_report_title" value="<?php echo get_default_value('txt_report_title') ?>" />
          </div>
        </div>
        <div class="help-container-i col-xs-1">
          <a href="" id="rTitleHelp" onClick="return false;"> <img src="includes/images/help.png" width="15" height="15"
              border="0">
          </a>
        </div>
      </div>
      <br />
      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="style_name">Category</label>

          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-fire"></i> <select id="existing_category_name" name="existing_category_name"
              class="form-control"                                   <?php

                                       if ($disable == "existing") {
                                           echo "disabled";
                                       }

                                   ?>>
              <!--  onChange="refresh()" -->
              <?php

                  foreach ($categories_options as $option) {
                      echo $option;
                  }

              ?>
            </select>

          </div>
        </div>


        <div class="help-container-i col-xs-1">
          <a href="" id="CategoryHelp" onClick="return false;"> <img src="includes/images/help.png" width="15"
              height="15" border="0">
          </a>
        </div>

      </div>


      <br />
      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_report_title">Report Language</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i> <select name="txt_report_language" class="form-control"
              id="txt_report_language">

            </select>
          </div>
        </div>
        <div class="help-container-i col-xs-1">
          <a href="" id="rLanguageHelp" onClick="return false;"> <img src="includes/images/help.png" width="15"
              height="15" border="0">
          </a>
        </div>
      </div>
      <br />








      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_report_footer">Report Footer</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i>
            <textarea name="txt_report_footer" class="form-control" rows="2"
              id="txt_report_footer"><?php echo get_default_value('txt_report_footer') ?></textarea>
          </div>
        </div>
        <div class="help-container-i col-xs-1">
          <a href="" id="rFooterHelp" onClick="return false;"> <img src="includes/images/help.png" width="15"
              height="15" border="0" align="absmiddle">
          </a>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_report_header">Report Header</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i>
            <textarea name="txt_report_header" class="form-control" rows="2"
              id="txt_report_header"><?php echo get_default_value('txt_report_header') ?></textarea>
          </div>
        </div>
        <div class="help-container-i col-xs-1">
          <a href="" id="rHeaderHelp" onClick="return false;"> <img src="includes/images/help.png" width="15"
              height="15" border="0">
          </a>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_report_name">Report Name</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i> <input name="txt_report_name" type="text" id="txt_report_name"
              class="form-control" value="<?php echo get_default_value('txt_report_name') ?>" />
          </div>
        </div>
        <div class="help-container-i col-xs-1">
          <a href="" id="rNameHelp" onClick="return false;"> <img src="includes/images/help.png" width="15" height="15"
              border="0">
          </a>
        </div>
      </div>


      <div class="row">
        <div class="col-xs-1"></div>
        <div class="form-group col-xs-10" style="margin-top: -10px;">
          <label for="txt_records_per_page">Records Per Page</label>
          <div class="left-inner-addon">
            <i class="glyphicon glyphicon-edit"></i> <input name="txt_records_per_page" type="text"
              id="txt_records_per_page" class="form-control"
              value="<?php echo get_default_value('txt_records_per_page') ?>">
          </div>
        </div>

        <div class="help-container-i col-xs-1">
          <a href="" id="rPPHelp" onClick="return false;"> <img src="includes/images/help.png" width="15" height="15"
              border="0">
          </a>
        </div>
      </div>
    </form>

  </div>
  <div class="row">
    <div class="col-xs-1"></div>
    <div class="col-xs-4">
      <button name="btn_back" id="btn_back" class="btn btn-sunny btn-block">
        <span class="icon glyphicon glyphicon-backward"></span><span class="separator"></span> Back
      </button>
    </div>
    <div class="col-xs-3"></div>
    <div class="col-xs-4">
      <button name="continue" id="btn_cont" class="btn btn-sunny btn-block">
        <span class="icon glyphicon glyphicon-flag"></span><span class="separator"></span> Finish
      </button>
    </div>
  </div>
  <!-- .row (navigation buttons) -->
</div>
<!-- to complete index tags -->
</div>

</div>
</div>
</div>
<script>
var layout = "<?php echo $layout; ?>";
var stylesExceptMobile = ["blue", "default", "grey"];



var selected_access_rule = "";
$(function() {
  $("#tabs").tabs();
  //show and hide the advanced div in the security pannel


  $(".lblsecurity").mousedown(function() {
    selected_access_rule = $(".radiosecurity:checked").val();

  });







  var languages =                  <?php echo json_encode($languages_array); ?>;



  var counter = 0;
  var used_language =                      <?php echo "'" . $used_language . "'"; ?>;
  if (used_language == "no")
    used_language = "en";

  $.each(languages, function(key, value) {




    $("#txt_report_language")
      .append($("<option></option>")
        .attr("value", value.replace(/[&\/\\#,+();$~%.'":*?<>{}]/g, ''))
        .text(key.replace(/[&\/\\#,+();$~%.'":*?<>{}]/g, '')));



  });

  $("#txt_report_language").val(used_language).attr("selected", "selected");






  $("#" + layout).prop("checked", true);

  $("#page-header").empty();
  $("#page-header").append(
    '<div id="img-container"><img src="includes/images/appearance.png" width="70" height="70"/></div>');
  $("#page-header").append('<div id="text-container"><h4>Apperance</h4>Choose how report seem</div>');

  $("#layout-nav").click(function() {

    $("#page-header").empty();
    $("#page-header").append(
      '<div id="img-container"><img src="includes/images/appearance.png" width="70" height="70"/></div>');
    $("#page-header").append('<div id="text-container"><h4>Apperance</h4>Choose how report seem</div>');

  });

  $("#security-nav").click(function() {

    $("#page-header").empty();
    $("#page-header").append(
      '<div id="img-container"><img src="includes/images/security.png" width="70" height="70"/></div>');
    $("#page-header").append(
      '<div id="text-container"><h4>Security</h4>Set Security options to your report</div>');

  });

  $("#titles-nav").click(function() {

    $("#page-header").empty();
    $("#page-header").append(
      '<div id="img-container"><img src="includes/images/titles.png" width="70" height="70"/></div>');
    $("#page-header").append('<div id="text-container"><h4>Titles</h4>Set Titles for your report</div>');

  });
  // -------------------------------------- accordion in security panel-------------------------------
  $("#secOptions-controller").mousedown(function() {

    if ($("#secOptions").css("display") === "none") {
      $("#status-icon").removeClass("glyphicon-play");
      $("#status-icon").addClass("caret");
      $("#secOptions").show();
      $("#status-icon1").removeClass("caret");
      $("#status-icon1").addClass("glyphicon-play");
      $("#memberLogin").hide();
      $("#status-icon2").removeClass("caret");
      $("#status-icon2").addClass("glyphicon-play");
      $("#forgetPass").hide();
    } else {
      $("#status-icon").removeClass("caret");
      $("#status-icon").addClass("glyphicon-play");
      $("#secOptions").hide();
    }
  });

  //$("#secOptions-controller").trigger("mousedown");


  // -------------------------------------------------------------------------------

  $("#Mobile").click(function() {
    $("#img_layout").attr("src", "includes/images/mob-layout.png");
    $("#style_name").empty();
    $("#style_name").append("<option value='mobile' selected>mobile</option>");
  });

  $("#AlignLeft").click(function() {
    $("#img_layout").attr("src", "includes/images/layout_align_left2.gif");
    setStyleOptions();
  });
  $("#Stepped").click(function() {
    $("#img_layout").attr("src", "includes/images/layout_stepped.gif");
    setStyleOptions();
  });
  $("#Block").click(function() {
    $("#img_layout").attr("src", "includes/images/layout_block.gif");
    setStyleOptions();
  });

  $("#Horizontal").click(function() {
    $("#img_layout").attr("src", "includes/images/horizontal.gif");
    setStyleOptions();
  });



  // disabled system in security panel
  $('[data-disable-controller]').each(function() {

    var controllerId = $(this).data("disableController");
    var element = $(this);
    //intial value
    $(this).prop("disabled", !($("#" + controllerId).prop('checked') === true));
    //disable and clear text
    $("#" + controllerId).click(function() {

      element.prop("disabled", !($(this).prop('checked') == true));
      if ($(this).prop('checked') !== true)
        element.val("");

    });
  });


  // -------------------------------------------------------------------------------------------

  $("#container").on("click", "#btn_cont", function() {
    $("#error-container").empty();
    $("#layout-error-container").empty();
    $("#titles-error-container").empty();

    var token = $("#csrfToken").val();
    var chosenLayout = $("input[name=option]:radio:checked").val();
    var lang = $("#txt_report_language").val();
    var category_option = true;



    var selected_Category = $("#existing_category_name").val();

    if (category_option == "existing" && (selected_Category == "" || selected_Category == 'no value')) {
      $("#titles-nav").trigger("click");
      $("#titles-error-container").append("<div class='alert alert-danger'>" + "Please select a category" +
        "</div>");
      return;
    }
    var all_categories =                         <?php echo json_encode($categories); ?>;



    var chosenStyle = $("#style_name").val();
    var secValues = $("#secForm").serialize();
    var groups = $('#groups').val();

    var titlesValues = $("#titlesForm").serialize();
    var data = "token=" + token + "&lang=" + lang + "&layout=" + chosenLayout + "&style_name=" + chosenStyle +
      "&" + secValues + "&" + titlesValues + "&selected_category=" + selected_Category;

    if (groups)
      data = data + "&groups=" + (Array.isArray(groups) ? groups.join(', ') : groups);


    $.ajax({
      url: "services/step_6.php",
      type: "post",
      data: data,
      beforeSend: function() {
        $("#global-loader").fadeIn();

      },
      success: function(data) {
        data = data.trim();
        $("#error-container").empty();
        $("#layout-error-container").empty();
        $("#titles-error-container").empty();
        if (data === "success") {

          location.assign("engine/common.php");
          SwitchStatusDone();
        } else {
          $("#global-loader").fadeOut();

          modifier = data.substring(0, 6);
          data = data.substring(6, data.length);
          if (modifier === "<1stT>") {
            $("#layout-nav").trigger("click");
            $("#layout-error-container").append("<div class='alert alert-danger'>" + data + "</div>");
          } else if (modifier === "<3stT>") {
            $("#titles-nav").trigger("click");
            $("#titles-error-container").append("<div class='alert alert-danger'>" + data + "</div>");
          } else {
            $("#security-nav").trigger("click");
            $("#error-container").append("<div class='alert alert-danger'>" + data + "</div>");
          }
          SwitchStatusError();
        }
      },
      error: function(response) {
        alertify.error("error");
      }
    });
  });

  $("#btn_back").mousedown(function() {
    backToPage("5");
  });




});



function setStyleOptions() {
  var isSelected = "";
  $("#style_name").empty();
  for (var i = 0; i < stylesExceptMobile.length; i++) {
    if (i === 2)
      isSelected = "selected";
    else
      isSelected = "";
    $("#style_name").append("<option value='" + stylesExceptMobile[i] + "'" + isSelected + ">" + stylesExceptMobile[i] +
      "</option>");
  }
}

if (!$("#adminAndUsers").prop("checked")) {
  $('#groups').fadeOut();

}

$('#adminAndUsers').change(function() {
  $('#groups').fadeIn();
})

$('input[type="radio"]').bind('click', function() {
  // Processing only those that match the name attribute of the currently clicked button...
  $('input[name="' + $(this).attr('name') + '"]').not($(this)).trigger(
    'deselect'); // Every member of the current radio group except the clicked one...
});

$('#adminAndUsers').bind('deselect', function() {
  $('#groups').fadeOut();
});

$('#public').change(function() {
  if (this.checked) {
    $("#confirm-public-report-modal").modal({
      keyboard: false,
      backdrop: 'static',
      show: true
    });



  }
});

$("#saveBtn-confirm-public-report").on('click', function() {
  $("#confirm-public-report-modal").modal("hide");
});

$("#cancelBtn-confirm-public-report").on('click', function() {
  $("#adminAndUsers").prop("checked", true);
  $('#groups').fadeIn();
});

<?php

if (online_demo_mode === 1): ?>

$(document).ready(function() {
  $("input[type='radio']").off('click');

  $("input[type='radio']").click(function() {
    alertify.error("Available Only in Full version");
    return false;
  });

  var lastStyleName = $("#style_name option:selected");
  $("#style_name").on("change", function(e) {

    lastStyleName.prop("selected", true);
    alertify.error("Available only in full version");
  });


  var lastGroupsSelect = $("#groups option:selected");
  $("#groups").on("change", function(e) {

    $("#groups").prop('multiple', false);
    lastGroupsSelect.prop("selected", true);
    alertify.error("Available only in full version");
  });

  $("form :input").on("change keydown keyup", function(e) {
    e.preventDefault();
    alertify.error("Available only in full version");

  });

  var lastExistingCategoryName = $("#existing_category_name option:selected");
  $("#existing_category_name").on("change", function(e) {

    lastExistingCategoryName.prop("selected", true);
    alertify.error("Available only in full version");
  });

  var lastTxtReportLanguage = $("#txt_report_language option:selected");
  $("#txt_report_language").on("change", function(e) {

    lastTxtReportLanguage.prop("selected", true);
    alertify.error("Available only in full version");
  });

});

<?php endif?>

/*function confirm_public(){
 if (confirm('Are you sure you want this report to be a public report, where anyone on the Internet can access it, without authentication ? ') != false) {
 return false;
 }
 }*/
</script>