<?php
/***
 * Auth: Aarti Ojha
 * Description: This page is used for creating or editing a category, allowing the user to select a complaint type, enter a category name, and add a description.
 * 
*/
   $id = base64_decode($_GET['id']);
   //get customer type list
   $result_type = categorytype();
   //fetch editable data
   $category_data = category_data($id);
  ?>
  <div id="success"></div>
  <form name="mastersrcat" method="post" action="" id="mastersrcat">
    <input name="id" id="id" type="hidden" value="<?=$id?>">
  <span class="breadcrumb_head" style="height:37px;padding:9px 16px"><?=($id!='') ? "Edit" : "New"?> Category</span>
      <div class="style2-table">             
          <div class="table">
              <table class="tableview tableview-2 main-form">
                  <tbody>
                    <tr>
                      <td id="msg" colspan="2"
                              style="color: #ffffff; width: 100%; background: #00cc66; padding: 5px; border: 1px solid #02944b; text-align: center;display: none"></td>
                      </tr>
                      <tr>
                      <td colspan="2" class="left">
                            <label>Complaint Type<em>*</em></label>
                            <div class="log-case">
                                <select name="type" id="type" class="select-styl1">
                                    <option value="0">Select Complaint Type</option>
                                    <?php 
                                    // Loop through complaint types
                                    while ($row = mysqli_fetch_array($result_type)) {
                                        // Check if the current complaint type matches the type associated with the category
                                        $selected = ($category_data['type'] == $row['complaint_name']) ? 'selected' : '';
                                    ?>
                                        <option value="<?= $row['complaint_name'] ?>" <?= $selected ?>>
                                            <?= $row['complaint_name'] ?>
                                        </option>
                                    <?php } ?>
                                </select>
                            </div>
                        </td>
                      </tr>
                      <tr>
                          <td colspan="2" class="left">
                              <label>Category Name<em>*</em></label>
                              <div class="log-case">
                                  <input name="category" id="category" type="text"
                                      value="<?=$category_data['category']?>" class="input-style1" />
                              </div>
                          </td>
                      </tr>
                      <tr>
                          <td colspan="2" class="left">
                              <label>Description</label>
                              <div class="log-case">
                                  <textarea name="V_Description" id="V_Description" cols=""
                                      rows="4" class="text-area1"><?=$category_data['VDescription']?></textarea>
                              </div>
                          </td>
                      </tr>
                      <tr>
                          <td>
                              <center>
                                 <?php if($id!=''){?>
                                  <input name="Update" type="submit" value="Update" class="button-orange1" id="submitclk" style="float: inherit;"/>
                                  <?php }else{ ?>
                                    <input name="Submit" type="submit" value="Create" class="button-orange1" id="submitclk" style="float: inherit;" />
                                  <?php } ?>
                             </center>
                          </td>
                      </tr>
                  </tbody>
              </table>
          </div>
      </div>
  </form>