<?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('widget');?>"><?php echo $jkl["hd15"];?></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('widget', 'support');?>"><?php echo $jkl["hd16"];?></a>
        </li>
      <?php } ?>
      <?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('widget', 'faq');?>"><?php echo $jkl["hd17"];?></a>
        </li>
      <?php } ?>
    </ul>
    <hr>
  </div>
</div>

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

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

      <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 $jkl["g289"];?></h4>
        </div>
        <div class="card-body">

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

          <?php if (!empty($jakosub) && !$jakosub['trial'] && $totalAll >= $jakosub['chatwidgets']) { ?>
            <div class="alert alert-rose"><?php echo sprintf($jkl['i14'], $totalAll, $jakosub['chatwidgets'], $jkl['hd15']);?></div>
          <?php } else { ?>

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

            <div class="form-group">
              <label class="control-label" for="title"><?php echo $jkl["g16"];?></label>
              <input type="text" name="title" class="form-control<?php if (isset($errors["e"])) echo " is-invalid";?>" value="<?php if (isset($_POST["title"])) echo $_POST["title"];?>" />
            </div>

            <div class="form-group">
              <label class="control-label" for="department"><?php echo $jkl["g131"];?></label>
              <select name="jak_depid" id="department" class="selectpicker col-12" data-live-search="true">
                <option value="0"><?php echo $jkl["g105"];?></option>
                <?php if (isset($JAK_DEPARTMENTS) && is_array($JAK_DEPARTMENTS)) foreach($JAK_DEPARTMENTS as $z) { ?>
                  <option value="<?php echo $z["id"];?>"><?php echo $z["title"];?></option>
                <?php } ?>
              </select>
            </div>

            <div class="form-group">
              <label class="control-label" for="operator"><?php echo $jkl["g130"];?></label>
              <select name="jak_opid" id="operator" class="selectpicker col-12" data-live-search="true">
                <option value="0"><?php echo $jkl["g105"];?></option>
                <?php if (isset($JAK_OPERATORS) && is_array($JAK_OPERATORS)) foreach($JAK_OPERATORS as $o) { ?>
                  <option value="<?php echo $o["id"];?>"><?php echo $o["username"];?></option>
                <?php } ?>
              </select>
            </div>

            <div class="form-group">
              <label class="control-label" for="jak_lang"><?php echo $jkl["g22"];?></label>
              <select name="jak_lang" class="selectpicker col-12" data-live-search="true">
                <?php if (isset($lang_files) && is_array($lang_files)) foreach($lang_files as $lf) { ?><option value="<?php echo $lf;?>"<?php if (JAK_LANG == $lf) { ?> selected="selected"<?php } ?>><?php echo ucwords($lf);?></option><?php } ?>
              </select>
            </div>

          <?php } ?>

        </div>

        <div class="card-footer">
          <?php if ($totalAll < $jakosub['chatwidgets']) { ?>
            <button type="submit" name="create_widget" class="btn btn-primary btn-block"><?php echo $jkl["g38"];?></button>
          <?php } ?>
        </div>

      </div>

    </form>

  </div>
  <div class="col-md-7">

    <div class="card">
      <div class="card-header card-header-icon card-header-rose">
        <div class="card-icon">
          <i class="material-icons">widgets</i>
        </div>
        <h4 class="card-title "><?php echo $jkl["g291"];?></h4>
      </div>
      <div class="card-body">

        <?php if (isset($CHATWIDGET_ALL) && is_array($CHATWIDGET_ALL) && !empty($CHATWIDGET_ALL)) { ?>
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th><?php echo $jkl["g16"];?></th>
                  <th><?php echo $jkl["g47"];?></th>
                  <th><?php echo $jkl["g48"];?></th>
                </tr>
              </thead>
              <?php foreach($CHATWIDGET_ALL as $v) { ?>
                <tr>
                  <td><?php echo $v["id"];?></td>
                  <td><a class="btn btn-sm btn-primary" href="<?php echo JAK_rewrite::jakParseurl('widget', 'edit', $v["id"]);?>"><?php echo $v["title"];?></a></td>
                  <td><a class="btn btn-default btn-sm" href="<?php echo JAK_rewrite::jakParseurl('widget', 'edit', $v["id"]);?>"><i class="fa fa-pencil"></i></a></td>
                  <td><?php if ($v['id'] != 1) { ?><a class="btn btn-danger btn-sm btn-confirm" href="<?php echo JAK_rewrite::jakParseurl('widget', 'delete', $v["id"]);?>" data-title="<?php echo addslashes($jkl["g48"]);?>" data-text="<?php echo addslashes($jkl["e44"]);?>" 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 } ?></td>
                </tr>
              <?php } ?>
            </table>
          </div>

        <?php } else { ?>

          <div class="alert alert-rose">
            <?php echo $jkl['i3'];?>
          </div>

        <?php } ?>

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

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