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

<div class="row">

<?php if ($newwidg) { ?>
  <div class="col-md-4">
  <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 ($errors) { ?>
        <div class="alert alert-rose"><?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">
              <p><label for="title"><?php echo $jkl["g16"];?></label></p>
            <input type="text" name="title" class="form-control<?php if (isset($errors["e"])) echo " is-invalid";?>" value="<?php if (isset($_REQUEST["title"])) echo $_REQUEST["title"];?>">
          </div>

          <div class="form-group">
            <p><label for="operator"><?php echo $jkl["g20"];?></label></p>
            <select name="jak_opid[]" id="operator" class="selectpicker col-12" data-size="4" data-live-search="true" multiple>
          
            <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 for="jak_maxclients"><?php echo $jkl["g21"];?></label>
            <input type="number" name="jak_maxclients" class="form-control" min="2" max="50" step="1" value="<?php if (isset($_REQUEST["jak_maxclients"])) echo $_REQUEST["jak_maxclients"];?>">
          </div>

          <div class="form-group">
            <label for="jak_password"><?php echo $jkl["l2"];?></label>
            <input type="password" name="jak_password" class="form-control" value="">
          </div>

          <div class="form-group">
            <p><label for="jak_lang"><?php echo $jkl["g22"];?></label></p>
            <select name="jak_lang" class="selectpicker col-12" data-size="4" 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>
          
          <div class="form-actions">
            <button type="submit" name="create_groupchat" class="btn btn-primary btn-block"><?php echo $jkl["g38"];?></button>
          </div>

        </form>
    </div>
  </div>
</div>
<div class="col-md-8">
<?php } else { ?>
  <div class="col-md-12">
  <div class="alert alert-info"><?php echo sprintf($jkl['i14'], $totalAll, $jakosub['groupchats'], $jkl['m29']);?></div>

  <?php if ($totalAll > 1 && $totalAll > $jakosub['groupchats']) { ?>
  <div class="alert alert-rose"><?php echo sprintf($jkl['i64'], $delW);?></div>

  <?php } if (isset($jakosub['groupchats']) && $jakosub['groupchats'] == 0) { ?>
  <div class="alert alert-rose"><?php echo $jkl['i13'];?></div>

<?php } } ?>

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

        <?php if (isset($GROUPCHAT_ALL) && is_array($GROUPCHAT_ALL) && !empty($GROUPCHAT_ALL)) { ?>
      <div class="table-responsive">
      <table class="table table-striped">
        <thead>
          <tr>
            <th>#</th>
            <th><?php echo $jkl["g16"];?></th>
            <th><?php echo $jkl["g138"];?></th>
            <th><?php echo $jkl["g47"];?></th>
            <th><?php echo $jkl['g101'];?></th>
            <th><?php echo $jkl["g48"];?></th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>#</th>
            <th><?php echo $jkl["g16"];?></th>
            <th><?php echo $jkl["g138"];?></th>
            <th><?php echo $jkl["g47"];?></th>
            <th><?php echo $jkl['g101'];?></th>
            <th><?php echo $jkl["g48"];?></th>
          </tr>
        </tfoot>
        <tbody>
          <?php foreach($GROUPCHAT_ALL as $i => $v) { ?>
          <tr>
          <td></td>
          <td><a class="btn btn-sm btn-primary" href="<?php echo JAK_rewrite::jakParseurl('groupchats', 'edit', $v["id"]);?>"><?php echo $v["title"];?></a></td>
          <td><a class="btn btn-default btn-sm" href="<?php echo str_replace(JAK_OPERATOR_LOC."/", "", JAK_rewrite::jakParseurl('groupchats', $v["id"], $v["lang"]));?>" target="_blank"><i class="fa fa-comments"></i></a></td>
          <td><a class="btn btn-default btn-sm" href="<?php echo JAK_rewrite::jakParseurl('groupchats', 'edit', $v["id"]);?>"><i class="fa fa-pencil"></i></a></td>
          <td><a class="btn btn-default btn-sm" href="<?php echo JAK_rewrite::jakParseurl('groupchats', 'lock', $v["id"]);?>"><i class="fa fa-<?php echo ($v["active"] ? 'check' : 'lock');?>"></i></a></td>
          <td><?php if ($totalAll > 1) { ?><a class="btn btn-danger btn-sm btn-confirm" href="<?php echo JAK_rewrite::jakParseurl('groupchats', '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-alt"></i></a><?php } ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
      </div>

      <?php } else { ?>

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

      <?php } ?>

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

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