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

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

<?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="row">
  <div class="col-md-8">

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

        <div class="form-group">
          <label for="subject"><?php echo $jkl["g16"];?></label>
          <input type="text" name="subject" id="subject" class="form-control<?php if (isset($errors["e"])) echo " is-invalid";?>" 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">
          <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>

    <?php if (isset($JAK_TICKET_FILES) && !empty($JAK_TICKET_FILES)) { ?>

    <div class="card">
      <div class="card-header">
        <h3 class="card-title"><i class="fa fa-file-archive"></i> <?php echo $jkl["hd265"];?></h3>
      </div><!-- /.card-header -->
      <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($k["path"])) { ?>
              <a href="<?php echo BASE_URL_ORIG;?>_showfile.php?i=<?php echo jak_encrypt_decrypt($k["encrypt"]);?>" target="_blank"><img src="<?php echo BASE_URL_ORIG;?>_showfile.php?i=<?php echo jak_encrypt_decrypt($k["encrypt"]);?>" alt="<?php echo $k["name"];?>" class="img-thumbnail" width="50px"></a>
            <?php } else { ?>
              <a href="<?php echo BASE_URL_ORIG;?>_showfile.php?i=<?php echo jak_encrypt_decrypt($k["encrypt"]);?>" target="_blank"><?php echo $k["name"];?></a>
            <?php } ?>
              
            <div class="form-check form-check-inline">
              <label class="form-check-label">
                <input class="form-check-input" type="checkbox" name="move-files[]" value="<?php echo $k;?>">
                <span class="form-check-sign">
                  <span class="check"></span>
                </span>
              </label>
            </div>

          </td></tr>
        <?php } ?>
        </table>

        <div id="share-attachments" class="dropzone upload-ticket"></div>
      </div>
      <div class="card-footer">
        <a href="<?php echo JAK_rewrite::jakParseurl('support', 'read', $page2);?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
        <button type="submit" name="save" class="btn btn-primary"><?php echo $jkl["g38"];?></button>
      </div>
    </div>

    <?php } ?>

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

    <div class="card box-info">
      <div class="card-header card-header-icon card-header-rose">
        <div class="card-icon">
          <i class="material-icons">person</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"].'"'.(!empty($OPERATOR_CC) && in_array($o["id"], $OPERATOR_CC) ? ' selected' : '').'>'.$o["name"].' ('.$o["email"].')</option>';
                } ?>
            </select>
          </dd>

            <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">
              <option value="1" selected><?php echo $jkl["hd169"];?></option>
              <option value="2"><?php echo $jkl["hd170"];?></option>
              <option value="3"><?php echo $jkl["hd171"];?></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"].'"'.($ticketinfo["depid"] == $d["id"] ? ' selected' : '').'>'.$d["title"].'</option>';
              } ?>
            </select>
            </dd>
            <?php } ?>

          <?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['hd172'];?></dt>
          <dd class="col-sm-7">
            <select name="jak_private" id="jak_private" class="selectpicker col-12">
              <option value="1"<?php if (isset($_REQUEST["jak_private"]) && $_REQUEST["jak_private"] == 1 || !isset($_REQUEST["jak_private"])) echo " selected";?>><?php echo $jkl['g19'];?></option>
              <option value="0"<?php if (isset($_REQUEST["jak_private"]) && $_REQUEST["jak_private"] == 0 || !isset($_REQUEST["jak_private"])) echo " selected";?>><?php echo $jkl['g18'];?></option>
            </select>
          </dd>

            <dt class="col-sm-5"><?php echo $jkl['hd77'];?></dt>
            <dd class="col-sm-7"><a href="<?php echo JAK_rewrite::jakParseurl('users', 'clients', $JAK_CLIENT_DATA["id"]);?>"><?php echo $JAK_CLIENT_DATA["name"];?></a></dd>

            <dt class="col-sm-5"><?php echo $jkl['u1'];?></dt>
            <dd class="col-sm-7"><a href="<?php echo JAK_rewrite::jakParseurl('users', 'clients', $JAK_CLIENT_DATA["id"]);?>"><?php echo $JAK_CLIENT_DATA["email"];?></a></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['hd269'];?></dt>
            <dd class="col-sm-7"><input type="text" name="jak_duedate" class="form-control datepicker" value="<?php echo ($_REQUEST["jak_duedate"] ? $_REQUEST["jak_duedate"] : date($duedateformat[0], strtotime('+'.JAK_TICKET_DUEDATE_PRESET.'day')));?>" autocomplete="off"></dd>

        </dl>
      </div>
      <div class="card-footer">
        <a href="<?php echo JAK_rewrite::jakParseurl('support', 'read', $page2);?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
        <button type="submit" name="save" class="btn btn-primary"><?php echo $jkl["g38"];?></button>
      </div>
    </div>

    <?php if (!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', 'read', $page2);?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
        <button type="submit" name="save" class="btn btn-primary"><?php echo $jkl["g38"];?></button>
      </div>
    </div>

    <?php } ?>

    <div class="card">
      <div class="card-header">
        <h3 class="card-title"><?php echo $jkl["g181"];?></h3>
      </div><!-- /.box-header -->
      <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 class="card-footer">
        <a href="<?php echo JAK_rewrite::jakParseurl('support', 'read', $page2);?>" class="btn btn-default"><?php echo $jkl["g103"];?></a>
        <button type="submit" name="save" class="btn btn-primary"><?php echo $jkl["g38"];?></button>
      </div>
    </div>
  </div>
</div>

  <input type="hidden" name="clientid" value="<?php echo $ticketinfo["clientid"];?>">
  <input type="hidden" name="depid" value="<?php echo $ticketinfo["clientid"];?>">

</form>

</div>
</div>

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