<?php include_once 'header.php';?>

<div class="row">
  <div class="col-md-12">
    <ul class="nav nav-pills nav-pills-warning">
      <li class="nav-item">
        <a class="nav-link<?php if (!in_array($page1, array("support", "faq"))) echo ' active';?>" href="<?php echo JAK_rewrite::jakParseurl('departments');?>"><?php echo $jkl["hd2"];?></a>
      </li>
      <?php if (jak_get_access("support", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link<?php if ($page1 == 'support') echo ' active';?>" href="<?php echo JAK_rewrite::jakParseurl('departments', 'support');?>"><?php echo $jkl["hd3"];?></a>
        </li>
      <?php } if (jak_get_access("faq", $jakuser->getVar("permissions"), JAK_MAIN_OP)){?>
        <li class="nav-item">
          <a class="nav-link<?php if ($page1 == 'faq') echo ' active';?>" href="<?php echo JAK_rewrite::jakParseurl('departments', 'faq');?>"><?php echo $jkl["hd4"];?></a>
        </li>
      <?php } ?>
    </ul>
    <hr>
  </div>
</div>

<div class="row">
  <div class="col-md-9">

    <div class="card">
      <div class="card-header card-header-icon card-header-rose">
        <div class="card-icon">
          <i class="material-icons">list_alt</i>
        </div>
        <h4 class="card-title "><?php echo ($page1 == 'faq' ? $jkl["hd20"] : $jkl["g98"]);?></h4>
      </div>
      <div class="card-body">

        <?php if (isset($DEPARTMENTS_ALL) && is_array($DEPARTMENTS_ALL)) { ?>
          <form method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>">
            <div class="table-responsive">
              <table class="table table-striped table-hover" id="sortTable">
                <thead>
                  <tr>
                    <th>#</th>
                    <th><?php echo $jkl["g16"];?></th>
                    <th><?php echo $jkl["g52"];?></th>
                    <th><?php echo $jkl["g47"];?></th>
                    <?php if ($page1 == 'faq') { ?>
                      <th><?php echo $jkl["g341"];?></th>
                    <?php } ?>
                    <th><?php echo $jkl["g101"];?></th>
                    <th><?php echo $jkl["g48"];?></th>
                    <th><?php echo $jkl["g102"];?></th>
                  </tr>
                </thead>
                <?php foreach($DEPARTMENTS_ALL as $v) { if ($v["subcat"] == 0) { ?>
                  <tr>
                    <td><?php echo $v["id"];?><input type="hidden" name="real_dep_id[]" value="<?php echo $v["id"];?>" /></td>
                    <td class="title"><a href="<?php echo (!in_array($page1, array("support", "faq")) ? JAK_rewrite::jakParseurl('departments', 'edit', $v["id"]) : JAK_rewrite::jakParseurl('departments', $page1, 'edit', $v["id"]));?>"><?php echo $v["title"];?></a></td>
                    <td><?php echo $v["description"];?></td>
                    <td><a class="btn btn-default btn-sm" href="<?php echo (!in_array($page1, array("support", "faq")) ? JAK_rewrite::jakParseurl('departments', 'edit', $v["id"]) : JAK_rewrite::jakParseurl('departments', $page1, 'edit', $v["id"]));?>"><i class="fa fa-pencil"></i></a></td>
                    <?php if ($page1 == 'faq') { ?>
                      <td><a class="btn btn-default btn-sm" href="<?php echo JAK_rewrite::jakParseurl('departments', 'faq', 'subcat', $v["id"]);?>"><i class="fa fa-edit"></i></a></td>
                    <?php } ?>
                    <td><?php if ($v["id"] != 1) { ?><a class="btn btn-default btn-sm" href="<?php echo (!in_array($page1, array("support", "faq")) ? JAK_rewrite::jakParseurl('departments', 'lock', $v["id"]) : JAK_rewrite::jakParseurl('departments', $page1, 'lock', $v["id"]));?>"><i class="fa fa-<?php if ($v["active"] == '1') { ?>check<?php } else { ?>lock<?php } ?>"></i></a><?php } else { ?><i class="fa fa-check"></i><?php } ?></td>
                    <td><?php if ($v["id"] != 1) { ?><a class="btn btn-danger btn-sm btn-confirm" href="<?php echo (!in_array($page1, array("support", "faq")) ? JAK_rewrite::jakParseurl('departments', 'delete', $v["id"]) : JAK_rewrite::jakParseurl('departments', $page1, 'delete', $v["id"]));?>" data-title="<?php echo addslashes($jkl["g48"]);?>" data-text="<?php echo addslashes($jkl["e30"]);?>" data-type="warning" data-okbtn="<?php echo addslashes($jkl["g279"]);?>" data-cbtn="<?php echo addslashes($jkl["g280"]);?>"><i class="fa fa-trash"></i></a><?php } else { ?><i class="fa fa-lock"></i><?php } ?></td>
                    <td><input type="text" name="corder[]" class="corder form-control" value="<?php echo $v["dorder"];?>" /></td>
                  </tr>
                <?php } } ?>
              </table>
            </div>

            <div class="card-footer">
              <button type="submit" name="save" class="btn btn-primary pull-right"><?php echo $jkl["g38"];?></button>
            </div>

          <?php } ?>
        </form>
      </div>    
    </div>

  </div>
  <div class="col-md-3">
    <div class="card">
      <div class="card-header card-header-icon card-header-success">
        <div class="card-icon">
          <i class="material-icons">add</i>
        </div>
        <h4 class="card-title "><?php echo ($page1 == 'faq' ? $jkl["hd21"] : $jkl["g99"]);?></h4>
      </div>
      <div class="card-body">


        <?php if (!empty($jakosub) && $jakosub['trial']) { ?>
          <div class="alert alert-info"><?php echo $jkl['i11'];?></div>
        <?php } ?>

        <?php if (!empty($jakosub) && !$jakosub['trial'] && $totalAll >= $jakosub['departments']) { ?>
          <div class="alert alert-danger"><?php echo sprintf($jkl['i14'], $totalAll, $jakosub['departments'], ($page1 == 'faq' ? $jkl['hd4'] : $jkl['m9']));?></div>
        <?php } else { ?>

          <?php if ($errors) { ?>
            <div class="alert alert-danger"><?php if (isset($errors["e"])) echo $errors["e"];
            if (isset($errors["e1"])) echo $errors["e1"];?></div>
          <?php } ?>

          <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

            <div class="form-group<?php if (isset($errors["e"])) echo " has-danger";?>">
              <label class="control-label" for="title"><?php echo $jkl["g16"];?></label>
              <input type="text" name="title" class="form-control" value="<?php if (isset($_POST["title"])) echo $_POST["title"];?>" />
            </div>
            <div class="form-group<?php if (isset($errors["e1"])) echo " has-danger";?>">
              <label class="control-label" for="email"><?php echo $jkl["g68"];?></label>
              <input type="text" name="email" class="form-control" value="<?php if (isset($_POST["email"])) echo $_POST["email"];?>" />
            </div>
            <?php if (JAK_BILLING_MODE == 1) { ?>
              <div class="form-group">
                <label class="control-label" for="credits"><?php echo $jkl["hd56"];?></label>
                <input type="number" min="0" name="credits" class="form-control" value="<?php if (isset($_POST["credits"])) { echo $_POST["credits"]; } else { echo "0";}?>">
              </div>
            <?php } else { ?>
              <input type="hidden" name="credits" value="0">
            <?php } if ($page1 != 'faq') { ?>
              <div class="form-group">
                <label class="control-label" for="faq"><?php echo $jkl["g278"];?></label>
                <input type="text" name="faq" class="form-control" value="<?php if (isset($_POST["faq"])) echo $_POST["faq"];?>">
              </div>

            <?php } if ($page1 == 'faq') { ?>

              <div class="form-group">
                <label for="jak_class"><?php echo $jkl["m13"];?></label>
                <select name="jak_class" class="selectpicker col-12" data-size="4" data-live-search="true">
                  <option value="secondary"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "default") { ?> selected="selected"<?php } ?>>Default</option>
                  <option value="primary"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "primary") { ?> selected="selected"<?php } ?>>Primary</option>
                  <option value="success"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "success") { ?> selected="selected"<?php } ?>>Success</option>
                  <option value="info"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "info") { ?> selected="selected"<?php } ?>>Info</option>
                  <option value="warning"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "warning") { ?> selected="selected"<?php } ?>>Warning</option>
                  <option value="danger"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "danger") { ?> selected="selected"<?php } ?>>Danger</option>
                  <option value="dark"<?php if (isset($_REQUEST["jak_class"]) && $_REQUEST["jak_class"] == "dark") { ?> selected="selected"<?php } ?>>Dark</option>
                </select>
              </div>

              <div class="form-group">
                <label for="subcat"><?php echo $jkl["hd4"];?></label>
                <select name="jak_subcat" id="subcat" class="selectpicker col-12" data-live-search="true">

                  <option value="0"<?php if (!isset($_REQUEST["subcat"]) || $_REQUEST["subcat"] == 0) echo ' selected';?>><?php echo $jkl["hd289"];?></option>
                  <?php if (isset($DEPARTMENTS_ALL) && is_array($DEPARTMENTS_ALL)) foreach($DEPARTMENTS_ALL as $z) { if ($z["subcat"] == 0) { ?>

                    <option value="<?php echo $z["id"];?>"<?php if (isset($_REQUEST["subcat"]) && $_REQUEST["subcat"] == $z["id"]) echo ' selected';?>><?php echo $z["title"];?></option>

                  <?php } } ?>

                </select>
                <small class="form-text text-muted">
                  <?php echo $jkl["hd310"];?>
                </small>
              </div>

            <?php } ?>

            <div class="form-group">
              <label class="control-label" for="jak_guesta"><?php echo $jkl["hd18"];?></label>
              <div class="form-check">
                <label class="form-check-label">
                  <input class="form-check-input" type="radio" name="jak_guesta" value="1"<?php if (!isset($_POST["jak_guesta"]) || isset($_POST["jak_guesta"]) && $_POST["jak_guesta"] == 1) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g19"];?>
                  <span class="circle">
                    <span class="check"></span>
                  </span>
                </label>
              </div>
              <div class="form-check">
                <label class="form-check-label">
                  <input class="form-check-input" type="radio" name="jak_guesta" value="0"<?php if (isset($_POST["jak_guesta"]) && $_POST["jak_guesta"] == 0) { ?> checked="checked"<?php } ?>> <?php echo $jkl["g18"];?>
                  <span class="circle">
                    <span class="check"></span>
                  </span>
                </label>
              </div>
            </div>

            <div class="form-group">
              <label class="control-label" for="description"><?php echo $jkl["g52"];?></label>
              <textarea name="description" class="form-control" rows="3"><?php if (isset($_POST["description"])) echo $_POST["description"];?></textarea>
            </div>

            <div class="form-actions">
              <button type="submit" name="insert_department" class="btn btn-primary btn-block"><?php echo $jkl["g38"];?></button>
            </div>

          </form>
        <?php } ?>
      </div>
    </div>
  </div>      
</div>

<?php include_once 'footer.php';?>
