<?php $this->load->view('includes/header'); ?>  

<div class="page-title">                    

  <h2><span ></span><?php echo $heading_title; ?></h2>

</div>

<div class="page-content-wrap">

  <div class="row">

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

      <div class="panel panel-default">

        <div class="panel-body">

          <?php echo validation_message(); ?>

          <?php echo form_open_multipart("", 'class="form-horizontal"'); ?> 

          <div class="table-responsive">

            <table class="table datatable" id="my_data">

              <thead>

                <tr>

                  <th style="width: 35%;">Product Info</th>

                  <th style="width: 35%;">User Info</th>                    

                  <th style="width: 10%;">Comments</th>

                  <th style="width: 10%;">Action</th>

                </tr>

              </thead>

              <tbody>

                <tr>

                  <td>

                    <?php

                    if (!empty($res['customers_id'])) {

                      echo "<b>Company Name : </b>" . get_db_field_value('wps_customers', "company_name", "WHERE customers_id='" . $res['customers_id'] . "'") . "<br /><br />";

                    }

                    if (!empty($res['products_id'])) {

                      echo "<b>Product Enquired : </b>" . get_db_field_value('wps_products', "product_name", "WHERE products_id='" . $res['products_id'] . "'") . "<br /><br />";

                    }

                    if ($res['quantity'] > 0) {

                      echo "<b>Quantity : </b>" . $res['quantity'];

                    }

                    if ($res['is_verified'] == '1') {

                      ?>

                      <br /><span class="btn btn-success">Verified</span>  

                      <?php

                    } else {

                      ?>

                      <br /><span class="btn btn-danger">Pending</span>  

                      <?php

                    }

                    ?>

                  </td>

                  <td>

                    <?php echo $res['first_name']; ?> <?php echo $res['last_name']; ?> <br>

                    <?php

                    if ($res['mobile_number'] != "" && $res['mobile_number'] != '0') {

                      $address_details[] = "<b>Mobile No. : </b>" . $res['mobile_number'];

                    }

                    if ($res['post_url'] != "" && $res['post_url']) {

                      $address_details[] = "<b>Posted URL : </b>" . $res['post_url'];

                    }

                    if (!empty($address_details)) {

                      echo implode("<br>", $address_details) . "<br /><br />";

                    }

                    echo '<b>Email ID :</b> ' . $res['email'] . '<br />';

                    ?>

                  </td>

                  <td>

                    <a href="#" data-toggle="modal" data-target=".enq_list_<?php echo $res['id']; ?>">

                      View Message

                    </a>

                    <div class="modal fade enq_list_<?php echo $res['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="description" aria-hidden="true">

                      <div class="modal-dialog modal-lg">

                        <div class="modal-content">



                          <div class="modal-header">

                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

                            <h4 class="modal-title" id="description">Message</h4>

                          </div>

                          <div class="modal-body">

                            <?php echo html_entity_decode($res['message']); ?>

                          </div>

                        </div>

                      </div>

                    </div>

                  </td>

                  <td>

                    <?php echo anchor("sitepanel/enquiry/edit/" . $res['id'] . "" . query_string(), '<span>Edit Enquiry</span>', 'class="btn btn-info edit_en" target="_blank"'); ?>

                    <input type="hidden" value="<?php echo $res['id']; ?>" id="enqID" />

                    <input type="hidden" value="" id="ids" class="ids" />

                  </td>

                </tr>

              </tbody>

            </table>

            <table class="table table-condensed">

              <tr>

                <td style="width:20%;">Search Keyword</td>

                <td style="width:40%;" colspan="2">State/City</td>

                <td style="width:20%;">Membership</td>

                <td style="width:20%;">Search</td>

              </tr>

              <tr>

                <td>

                  <input type="text" name="keyword" id="keyword" class="form-control" value="<?php echo set_value('keyword'); ?>" />

                </td>

                <td>

                  <select name="state" id="state" class="form-control">

                    <option value="">--Select State--</option>

                    <?php
                    //$stateid=get_db_field_value('wps_customers', "state", "WHERE customers_id='" . $res['customers_id'] . "'");
                    foreach ($state as $sk => $sval) {
                      $sel = '';
                      //$sel = ($stateid== $sval['id']) ? 'selected' : '';

                      ?>

                      <option value="<?php echo $sval['id']; ?>" <?php echo $sel; ?>><?php echo $sval['name']; ?></option>

                      <?php

                    }

                    ?>

                  </select>

                </td>

                <td>

                  <select name="city" id="city" class="form-control">

                    <option value="">--Select City--</option>

                  </select>

                </td>

                <td>

                  <select name="membership" id="membership" class="form-control">

                    <option value="">--Select Membership--</option>

                  </select>

                </td>

                <td>

                  <input type="button" name="action" value="Search Members" class="btn btn-primary getMembers" />

                </td>

              </tr>

            </table>

            <div class="memberList" style="display:none;">
            
              <div class="container">
                <div class="row">
                  <div class="col-md-3"></div>
                  <div class="col-md-3">Company Name</div>
                  <div class="col-md-3">Email</div>
                  <div class="col-md-3">Mobile</div>
                </div>
                  <div class="row" id="prodListingContainer" style="height: 400px;overflow:auto;">

                  </div>
                <div class="row">
                  <div class="col-md-12 text-right"><button type="button" name="loadmore" class="btn btn-success loadmore">Load More</button></div>
                </div>
                <div class="row">
                  <div class="col-md-12 text-right"><button type="button" name="enq" class="btn btn-success forwardEnq">Forward Enquiry</button></div>
                </div>
              </div>
            </div>

          </div>

          <?php echo form_close(); ?>

        </div>

      </div>

    </div>

  </div>

</div>

<?php $this->load->view('includes/footer'); ?>
<script type="text/javascript">

      $('.loadmore').click(function () {
      var page = 1;
      var triggeredPaging = 0; //$(window).scroll

      var keyword = $('#keyword').val();
      var enqId = '<?php echo $res['id'];?>';
      var state = $('#state').val();
      var city = $('#city').val();
      var membership =$('#membership').val();

        page = $('.listpager').length;
        //alert(page);
        //alert(enqId);
        var membership = $('#membership').val();
        $.post(site_url + 'sitepanel/enquiry/getmembers', {keyword: keyword, state: state, city: city, membership: membership, enqId : $('#enqID').val(),OffSet:page}, function (data) {
          //$('.memberList').html(data);
          $("#prodListingContainer").append(data);
          //$('#prodListingContainer').html(data);
        });

      });

</script>

<script type="text/javascript">

  //get city

  $('#state').change(function () {

    var stId = $(this).val();

    $.post('<?php echo site_url(); ?>home/get_citylist', {stateId: stId}, function (data) {

      $('#city').html('');

      $('#city').html(data);

    });

  });



  //Get Members

  $('.getMembers').click(function () {
    
    var keyword = $('#keyword').val();

    var state = $('#state').val();

    var city = $('#city').val();

    var membership = $('#membership').val();
    $.post(site_url + 'sitepanel/enquiry/getmembers', {keyword: keyword, state: state, city: city, membership: membership, enqId : $('#enqID').val()}, function (data) {
      $('.memberList').show();
      //$('.memberList').html(data);
      $('#prodListingContainer').html(data);
    });

  });



  $(".memberList").on("click", ".enqCheck", function () {

    var ids = $(".enqCheck:checked").map(function () {

      return $(this).val()

    }).get();

    $('#ids').val(ids);

  });



  $(".memberList").on("click", ".forwardEnq", function () {

    $.post(site_url + 'sitepanel/enquiry/assignEnquiry', {ids: $('#ids').val(), enqID: $('#enqID').val()}, function (data) {

      alert(data);

    });

  });



</script>