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

<?php if (!$supportaccess) { ?>
<div class="alert alert-rose"><?php echo $jkl['i13'];?></div>
<?php } else { if ($errors) { ?>
  <div class="alert alert-danger">
    <?php if (isset($errors["subject"])) echo $errors["subject"];
    if (isset($errors["content-editor"])) echo $errors["content-editor"];
    if (isset($errors["jak_client"])) echo $errors["jak_client"];
    if (isset($errors["emailc"])) echo $errors["emailc"];
    if (isset($errors["namec"])) echo $errors["namec"];?>
  </div>
<?php } ?>

<form class="jak_form" method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>" enctype="multipart/form-data">

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

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

          <div class="form-group<?php if (isset($errors["subject"])) echo " has-danger";?>">
            <label for="subject"><?php echo $jkl["g16"];?></label>
            <input type="text" name="subject" id="subject" class="form-control" value="<?php if (isset($_POST["subject"]) && !empty($_POST["subject"])) echo $_POST["subject"];?>">
          </div>

          <?php if (isset($JAK_RESPONSE_DATA) && !empty($JAK_RESPONSE_DATA)) { ?>
            <div class="form-group">
              <p><label for="supresp"><?php echo $jkl["u35"];?></label></p>
              <select id="supresp" class="selectpicker col-12" data-live-search="true">
                <?php echo $JAK_RESPONSE_DATA;?>
              </select>
            </div>
          <?php } ?>

          <div class="form-group<?php if (isset($errors["content-editor"])) echo " has-danger";?>">
            <p><label for="content-editor"><?php echo $jkl["g321"];?></label></p>
            <textarea name="content" id="content-editor" rows="5" class="form-control"><?php if (isset($_REQUEST["content"]) && !empty($_REQUEST["content"])) echo $_REQUEST["content"];?></textarea>
          </div>

          <div class="form-check form-check-inline">
            <label class="form-check-label">
              <input class="form-check-input" type="checkbox" name="inform-client" value="1"> <?php echo $jkl["hd198"];?>
              <span class="form-check-sign">
                <span class="check"></span>
              </span>
            </label>
          </div>

        </div>
        <div class="card-footer text-right">
          <a href="<?php echo JAK_rewrite::jakParseurl('support');?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
          <?php if (!empty(JAK_OPENAI_APIKEY)) { ?>
          <a href="javascript:" data-scan="grammar" class="btn btn-success btn-translate"><i class="far fa-spell-check"></i> <i class="fa fa-spinner fa-pulse d-none tl-loader"></i></a>
          <a href="javascript:" data-scan="translate" class="btn btn-info btn-translate"><i class="fas fa-language"></i> <i class="fa fa-spinner fa-pulse d-none tl-loader"></i></a>
          <?php } ?>
          <button type="submit" name="save" class="btn btn-primary submitNT"><?php echo $jkl["g38"];?> <i class="fa fa-spinner fa-pulse loader"></i></button>
        </div>
      </div>

      <?php if ($jakuser->getVar("files") && $jakosub['files']) { ?>

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

          <table class="table table-striped" id="attach-list">
            <?php if (isset($JAK_TICKET_FILES) && is_array($JAK_TICKET_FILES)) foreach($JAK_TICKET_FILES as $k) { ?>

              <tr><td>
                <?php if (getimagesize(APP_PATH.JAK_FILES_DIRECTORY.'/support/'.$page2.'/'.$k)) { ?>
                  <a data-toggle="lightbox" href="<?php echo BASE_URL_ORIG.JAK_FILES_DIRECTORY.'/support/'.$page2.'/'.$k;?>"><img src="<?php echo BASE_URL_ORIG.JAK_FILES_DIRECTORY.'/support/'.$page2.'/'.$k;?>" alt="<?php echo $k;?>" class="img-thumbnail" width="50px"></a>
                <?php } else { ?>
                  <?php echo $k;?>
                <?php } ?>
                <a href="<?php echo BASE_URL_ORIG.JAK_FILES_DIRECTORY.'/support/'.$page2.'/'.$k;?>" class="btn btn-info btn-sm"><i class="fa fa-file-download"></i></a> <a href="<?php echo JAK_rewrite::jakParseurl('support', 'deletef', $page2, $k);?>" class="btn btn-danger btn-sm btn-confirm" data-title="<?php echo addslashes($jkl["g48"]);?>" data-text="<?php echo addslashes($jkl["e32"]);?>" 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>
              </td></tr>
            <?php } ?>
          </table>

          <div id="share-attachments" class="dropzone upload-ticket"></div>
        </div>
      </div>

      <?php } ?>

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

      <div class="card">
        <div class="card-header card-header-icon card-header-info">
          <div class="card-icon">
            <i class="material-icons">badge</i>
          </div>
          <h4 class="card-title "><?php echo $jkl["hd180"];?></h4>
        </div>
        <div class="card-body">
          <dl class="row">

            <dt class="col-sm-5"><?php echo $jkl['g130'];?></dt>
            <dd class="col-sm-7">
              <select name="jak_operator" id="jak_operator" class="selectpicker col-12" data-live-search="true">
                <?php foreach ($OPERATOR_ALL as $o) {
                  echo '<option value="'.$o["id"].'"'.($o["id"] == JAK_USERID ? ' selected' : '').'>'.$o["name"].' ('.$o["email"].')</option>';
                } ?>
              </select>
            </dd>

            <dt class="col-sm-5"><?php echo $jkl['hd266'];?></dt>
            <dd class="col-sm-7">
              <select name="jak_opidcc[]" id="jak_opidcc" class="selectpicker col-12" data-live-search="true" multiple>
                <?php foreach ($OPERATOR_ALL as $o) {
                  echo '<option value="'.$o["id"].'"'.(in_array($o["id"], $OPERATOR_CC) ? ' selected' : '').'>'.$o["name"].' ('.$o["email"].')</option>';
                } ?>
              </select>
            </dd>

            <dt class="col-sm-5"><?php echo $jkl['hd194'];?></dt>
            <dd class="col-sm-7">
              <select name="jak_client" id="jak_client" class="selectpicker col-12" data-live-search="true">
                <option value="0"><?php echo $jkl["hd329"];?></option>
                <?php foreach ($CLIENTS_ALL as $v) {
                  echo '<option value="'.$v["id"].':#:'.$v["support_dep"].':#:'.$v["name"].'"'.(isset($_POST["jak_client"]) && $v["id"].':#:'.$v["support_dep"].':#:'.$v["name"] == $_POST["jak_client"] ? ' selected' : '').'>'.$v["name"].' ('.$v["email"].')</option>';
                } ?>
              </select>
            </dd>

            <?php if (isset($DEPARTMENTS_ALL) && !empty($DEPARTMENTS_ALL)) { ?>
              <dt class="col-sm-5"><?php echo $jkl['g131'];?></dt>
              <dd class="col-sm-7">
                <select name="jak_depid" id="jak_depid" class="selectpicker col-12" data-live-search="true">
                  <?php foreach ($DEPARTMENTS_ALL as $d) {
                    echo '<option value="'.$d["id"].'"'.(isset($_POST["jak_depid"]) && $_POST["jak_depid"] == $d["id"] ? ' selected' : '').'>'.$d["title"].'</option>';
                  } ?>
                </select>
              </dd>
            <?php } ?>

            <dt class="col-sm-5"><?php echo $jkl['hd167'];?></dt>
            <dd class="col-sm-7">
              <select name="jak_status" id="jak_status" class="selectpicker col-12">
                <?php if (isset($HD_SUPPORT_STATUS) && !empty($HD_SUPPORT_STATUS)) foreach ($HD_SUPPORT_STATUS as $s) { ?>
                  <option value="<?php echo $s["id"];?>"<?php if ($s["id"] == 1) echo ' selected';?>><?php echo $s["title"];?></option>
                <?php } ?>
              </select>
            </dd>

            <?php if (isset($PRIORITY_ALL) && !empty($PRIORITY_ALL)) { ?>
              <dt class="col-sm-5"><?php echo $jkl['hd149'];?></dt>
              <dd class="col-sm-7">
                <select name="jak_priority" id="jak_priority" class="selectpicker col-12">
                  <?php foreach ($PRIORITY_ALL as $p) {
                    echo '<option value="'.$p["id"].'">'.$p["title"].((JAK_BILLING_MODE == 1 && $p["credits"] != 0) ? ' ('.sprintf($jkl['hd232'], $p["credits"]).')' : '').'</option>';
                  } ?>
                </select>
              </dd>
            <?php } ?>

            <?php if (isset($TOPTIONS_ALL) && !empty($TOPTIONS_ALL)) { ?>
              <dt class="col-sm-5"><?php echo $jkl['hd225'];?></dt>
              <dd class="col-sm-7">
                <select name="jak_toption" id="jak_toption" class="selectpicker col-12">
                  <?php foreach ($TOPTIONS_ALL as $t) {
                    echo '<option value="'.$t["id"].'">'.$t["title"].((JAK_BILLING_MODE == 1 && $t["credits"] != 0) ? ' ('.sprintf($jkl['hd232'], $t["credits"]).')' : '').'</option>';
                  } ?>
                </select>
              </dd>
            <?php } ?>

            <dt class="col-sm-5"><?php echo $jkl['g22'];?></dt>
              <dd class="col-sm-7">
                <select name="jak_tlang" id="jak_tlang" class="selectpicker col-12" data-live-search="true">
                  <option value="">-</option>
                  <?php // The language list
                    foreach(jak_the_lang() as $k => $l) {  
                      echo '<option value="'.$k.'">'.$l.'</option>';    
                    }
                  ?>
              </select>
              </dd>

            <dt class="col-sm-5"><?php echo $jkl['hd172'];?></dt>
            <dd class="col-sm-7">

              <div class="form-group">
                <div class="form-check">
                  <label class="form-check-label">
                    <input class="form-check-input" type="radio" name="jak_private" value="1"<?php if (isset($_REQUEST["jak_private"]) && $_REQUEST["jak_private"] == 1 || (!isset($_REQUEST["jak_private"]) && JAK_TICKET_PRIVATE == 1)) echo " checked";?>> <?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_private" value="0"<?php if (isset($_REQUEST["jak_private"]) && $_REQUEST["jak_private"] == 0|| (!isset($_REQUEST["jak_private"]) && JAK_TICKET_PRIVATE == 0)) echo " checked";?>> <?php echo $jkl["g18"];?>
                    <span class="circle">
                      <span class="check"></span>
                    </span>
                  </label>
                </div>
              </div>

            </dd>

            <dt class="col-sm-5"><?php echo $jkl['g169'];?></dt>
            <dd class="col-sm-7"><input type="text" class="form-control" name="jak_referrer" value="<?php if (isset($_REQUEST["jak_referrer"]) && !empty($_REQUEST["jak_referrer"])) echo $_REQUEST["jak_referrer"];?>"></dd>

            <dt class="col-sm-5"><?php echo $jkl['hd271'];?></dt>
            <dd class="col-sm-7"><input type="text" name="jak_duedate" class="form-control datepicker" value="<?php echo (isset($_REQUEST["jak_duedate"]) ? $_REQUEST["jak_duedate"] : date($duedateformat[0], strtotime('+'.JAK_TICKET_DUEDATE_PRESET.'day')));?>" autocomplete="off"></dd>

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

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

          <div class="form-group">
            <label for="namec"><?php echo $jkl["u"];?></label>
            <input type="text" name="jak_namec" id="namec" class="form-control<?php if (isset($errors["namec"])) echo " is-invalid";?>" value="<?php if (isset($_REQUEST["jak_namec"])) echo $_REQUEST["jak_namec"];?>">
          </div>

          <div class="form-group">
            <label for="emailc"><?php echo $jkl["u1"];?></label>
            <input type="text" name="jak_emailc" id="emailc" class="form-control<?php if (isset($errors["emailc"])) echo " is-invalid";?>" value="<?php if (isset($_REQUEST["jak_emailc"])) echo $_REQUEST["jak_emailc"];?>">
          </div>

          <div class="form-check form-check-inline">
            <label class="form-check-label">
              <input class="form-check-input" type="checkbox" name="send_email" value="1" checked> <?php echo $jkl["hd120"];?>
              <span class="form-check-sign">
                <span class="check"></span>
              </span>
            </label>
          </div>

        </div>
      </div>

      <?php if (isset($custom_fields) && !empty($custom_fields)) { ?>
        <div class="card">
          <div class="card-header">
            <h3 class="card-title"><?php echo $jkl["hd148"];?></h3>
          </div><!-- /.box-header -->
          <div class="card-body">
            <?php echo $custom_fields;?>
          </div>
          <div class="card-footer">
            <a href="<?php echo JAK_rewrite::jakParseurl('support');?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
            <button type="submit" name="save" class="btn btn-primary submitNT"><?php echo $jkl["g38"];?> <i class="fa fa-spinner fa-pulse loader"></i></button>
          </div>
        </div>
      <?php } ?>
      <div class="card">
        <div class="card-header card-header-icon card-header-warning">
          <div class="card-icon">
            <i class="material-icons">note</i>
          </div>
          <h4 class="card-title "><?php echo $jkl["g181"];?></h4>
        </div>
        <div class="card-body">
          <div class="form-group">
            <label for="content-editor"><?php echo $jkl["g181"];?></label>
            <textarea name="jak_notes" rows="3" class="form-control"><?php if (isset($_REQUEST["jak_notes"]) && !empty($_REQUEST["jak_notes"])) echo $_REQUEST["jak_notes"];?></textarea>
          </div>
        </div>
      </div>
    </div>
  </div>

</form>

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