
<div class="breadcrumb">
    <h1>Point master</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Add New Point master</li>

    </ul>
</div>


<div class="separator-breadcrumb border-top"></div>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">Add New Point master</div>
                <form action="" method="post" enctype="multipart/form-data">

					<?php if(isset($pointmasterDetail->pointmaster_id) && $pointmasterDetail->pointmaster_i!=0) { ?>
						<input type="hidden" id="pointmaster_id" name="pointmaster_id" value="<?php echo $pointmasterDetail->pointmaster_i ?>" />
						?>" />
					<?php } ?>

                    <div class="row">

                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_title">Title </label>
                            <input type="text" class="form-control" id="pointmaster_title" name="pointmaster_title" value="<?php echo $pointmasterDetail->pointmaster_title; ?>" placeholder="Enter title">
                            <div class="invalid-tooltip" id="msg_pointmaster_title"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_description">Description </label>
                            <input type="text" class="form-control" id="pointmaster_description" name="pointmaster_description" value="<?php echo $pointmasterDetail->pointmaster_description; ?>" placeholder="Enter tracking id">
                            <div class="invalid-tooltip" id="msg_pointmaster_description"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_domain_id">Domain <span class="asterisk">*</span></label>
                            <select class="form-control" id="pointmaster_domain_id" name="pointmaster_domain_id">
                              <option value="">Select Domain</option>
                              <?php 
                               if($alldomain && count($alldomain)>0){
                                  foreach ($alldomain as $key => $domain) {?>
                                    <option value="<?php echo $domain->domain_id ?>" 
                                      <?php $domain->domain_id == $pointmasterDetail->pointmaster_domain_id ?"selected:'selected'":"" ?> ><?php echo $domain->domain_title ?></option>
                                  <?php }
                               }
                              ?>
                            </select>
                            <div class="invalid-tooltip" id="msg_pointmaster_domain_id"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_category_id">Category <span class="asterisk">*</span></label>
                            <select class="form-control" id="pointmaster_category_id" name="pointmaster_category_id">
                            	<option value="">Select Category</option>
                            	<?php 
                               if($allcategory && count($allcategory)>0){
                                  foreach ($allcategory as $key => $category) {?>
                                    <option value="<?php echo $category->pointcategory_id ?>" <?php $category->pointcategory_id== $pointmasterDetail->pointmaster_category_id?"selected:'selected'":"" ?> ><?php echo $category->pointcategory_title ?></option>
                                  <?php }
                               }
                              ?>
                            </select>
                            <div class="invalid-tooltip" id="msg_pointmaster_category_id"></div>
                        </div>
                        
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_code">Code </label>
                            <input type="text" class="form-control" id="pointmaster_code" name="pointmaster_code" value="<?php echo $pointmasterDetail->pointmaster_code; ?>" placeholder="Enter code">
                            <div class="invalid-tooltip" id="msg_pointmaster_code"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                        <label for="clinic_id">Clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id">
                            <option value="">Select Clinic</option>
                            <?php
                                  $clinicobj = new clinic();
                                  $fields = array('clinic_id,clinic_name');
                                  $clinicArg = array("fields"=>$fields);
                                  $clinicdata = $clinicobj->getAllRecords($clinicArg);
                                  foreach ($clinicdata as $ckey => $clinic_value) 
                                    { 
                                      ?>
                                        <option value="<?php echo $clinic_value->clinic_id; ?>" <?php $clinic_value->clinic_id==$pointmasterDetail->pointmaster_clinic_id?"Selected='selected'":"" ?>><?php echo $clinic_value->clinic_name; ?></option>
                              <?php }
                            ?>

                        </select>
                    </div>
                    <!-- <div class="col-md-6 form-group mb-3">
                        <label for="campaign_id">Campaign</label>
                        <select class="form-control" id="campaign_id" name="campaign_id">
                            <option value="">Select Campaign</option>
                            <?php
                              if($pointmasterDetail->pointmaster_clinic_id!=""){
                                  $messagecentercampaignObj = new messagecentercampaign();;
                                  $where = array('clinicid='=>$pointmasterDetail->pointmaster_clinic_id,'isactive='=>0,'isdeleted='=>0);
                                  $clinicArg = array("where"=>$where);
                                  $allCampaign = $messagecentercampaignObj->getAllRecords($clinicArg);
                                  if($allCampaign && count($allCampaign)>0){
                                  foreach ($allCampaign as $ckey => $campaign) 
                                    { 
                                      ?>
                                        <option value="<?php echo $campaign->messagecentercampaign_id; ?>" <?php $campaign->messagecentercampaign_id==$pointmasterDetail->pointmaster_campaign_id?"Selected='selected'":"" ?>><?php echo $campaign->categorytype." -- ".$campaign->title; ?></option>
                              <?php }}
                             } 
                            ?>

                        </select>
                    </div> -->

                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_tracking_id">Tracking Id </label>
                            <input type="text" class="form-control" id="pointmaster_tracking_id" name="pointmaster_tracking_id" value="<?php echo $pointmasterDetail->pointmaster_tracking_id; ?>" placeholder="Enter tracking id">
                            <div class="invalid-tooltip" id="msg_pointmaster_tracking_id"></div>
                        </div>
                        
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_campaign_sdate">Campaign Start Date </label>
                            <input type="date" class="form-control" id="pointmaster_campaign_sdate" name="pointmaster_campaign_sdate" value="<?php echo $pointmasterDetail->pointmaster_campaign_sdate; ?>" placeholder="Enter Campaign Start Date">
                            <div class="invalid-tooltip" id="msg_pointmaster_campaign_sdate"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_campaign_edate">Campaign End Date </label>
                            <input type="date" class="form-control" id="pointmaster_campaign_edate" name="pointmaster_campaign_edate" value="<?php echo $pointmasterDetail->pointmaster_campaign_edate; ?>" placeholder="Enter tracking id">
                            <div class="invalid-tooltip" id="msg_pointmaster_campaign_edate"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_frequency">Frequency</label>
                            <select class="form-control" id="pointmaster_frequency" name="pointmaster_frequency">
                              <option value="">Select Frequency</option>
                              <option value="Onetime" <?php $clinic_value->pointmaster_frequency=="Onetime"?"Selected='selected'":"" ?>>Onetime</option>
                              <option value="Recurring" <?php $clinic_value->pointmaster_frequency=="Recurring"?"Selected='selected'":"" ?>>Recurring</option>
                              <option value="Limited" <?php $clinic_value->pointmaster_frequency=="Limited"?"Selected='selected'":"" ?>>Limited</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_pointmaster_frequency"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_end_date">End Date </label>
                            <input type="date" class="form-control" id="pointmaster_end_date" name="pointmaster_end_date" value="<?php echo $pointmasterDetail->pointmaster_end_date; ?>" placeholder="Enter end date">
                            <div class="invalid-tooltip" id="msg_pointmaster_end_date"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_total_points">Total Points </label>
                            <input type="text" class="form-control" id="pointmaster_total_points" name="pointmaster_total_points" value="<?php echo $pointmasterDetail->pointmaster_total_points; ?>" placeholder="Enter sender">
                            <div class="invalid-tooltip" id="msg_pointmaster_total_points"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_unit_point">Unit Point </label>
                            <input type="text" class="form-control" id="pointmaster_unit_point" name="pointmaster_unit_point" value="<?php echo $pointmasterDetail->pointmaster_unit_point; ?>" placeholder="Enter sender">
                            <div class="invalid-tooltip" id="msg_pointmaster_unit_point"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_sender">Sender </label>
                            <input type="text" class="form-control" id="pointmaster_sender" name="pointmaster_sender" value="<?php echo $pointmasterDetail->pointmaster_sender; ?>" placeholder="Enter sender">
                            <div class="invalid-tooltip" id="msg_pointmaster_sender"></div>
                        </div>


                        <div class="col-md-6 form-group mb-3">
                            <label for="pointmaster_receiver">Receiver </label>
                            <input type="text" class="form-control" id="pointmaster_receiver" name="pointmaster_receiver" value="<?php echo $pointmasterDetail->pointmaster_receiver; ?>" placeholder="Enter receiver">
                            <div class="invalid-tooltip" id="msg_pointmaster_receiver"></div>
                        </div>

                        <div class="col-md-12">
                            <button class="btn btn-primary" id="submit" name="submit">Submit</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
    $("#clinic_id").select2({
        tags: true
    });
    $("#campaign_id").select2({
        tags: true
    });
    $("#clinic_id").on("change",function(){

        var clinic_id = $("#clinic_id").val();
        $.ajax({
            url: "pointadd.php?act=getCampaign", 
            type: "POST",
            data: ({clinic_id: clinic_id}),
            success: function(data){  
              $("#campaign_id").html(data);

            }
       });
    })
  });  
	$( "form" ).on( "submit", function(e) {
      e.preventDefault();
      var pointmaster_title = $("#pointmaster_title").val();
      var pointmaster_category_id = $("#pointmaster_category_id").val();
      var pointmaster_domain_id = $("#pointmaster_domain_id").val();
      var pointmaster_code = $("#pointmaster_code").val();
      var pointmaster_tracking_id = $("#pointmaster_tracking_id").val();
      var pointmaster_clinic_id = $("#clinic_id").val();
      var pointmaster_receiver = $("#pointmaster_receiver").val();
      var pointmaster_sender = $("#pointmaster_sender").val();
      var pointmaster_unit_point = $("#pointmaster_unit_point").val();
      var pointmaster_total_points = $("#pointmaster_total_points").val();
      var pointmaster_frequency = $("#pointmaster_frequency").val();
      var pointmaster_campaign_sdate = $("#pointmaster_campaign_sdate").val();
      var pointmaster_campaign_edate = $("#pointmaster_campaign_edate").val();
      var pointmaster_end_date = $("#pointmaster_end_date").val();
      var pointmaster_description = $("#pointmaster_description").val();
            
      //$("#template_content_data").val();
      
      if($("#pointmaster_category_id").val()=='')
       {
          $("#pointmaster_category_id").addClass('error');
          $("#pointmaster_category_id").focus();
          $("#msg_pointmaster_category_id").html('Please select type').show();
          return false;
        }
        else
        {
          if(pointmaster_category_id !='')
            {
              $("#pointmaster_category_id").removeClass('error');
              $("#msg_pointmaster_category_id").hide();
            }

          <?php if(!isset($_REQUEST['pointmaster_id']))
          { ?>
            
              $.ajax({
                      url: "pointadd.php",
                      data: { act:"load",
                            pointmaster_title:pointmaster_title,
                            pointmaster_category_id:pointmaster_category_id,
                            pointmaster_domain_id:pointmaster_domain_id,
                            pointmaster_code:pointmaster_code,
                            pointmaster_tracking_id:pointmaster_tracking_id,
                            pointmaster_clinic_id:pointmaster_clinic_id,
                            pointmaster_sender:pointmaster_sender,
                            pointmaster_receiver:pointmaster_receiver,
                            pointmaster_total_points:pointmaster_total_points,
                            pointmaster_unit_point:pointmaster_unit_point,
                            pointmaster_campaign_sdate:pointmaster_campaign_sdate,
                            pointmaster_campaign_edate:pointmaster_campaign_edate,
                            pointmaster_frequency:pointmaster_frequency,
                            pointmaster_end_date:pointmaster_end_date,
                            pointmaster_description:pointmaster_description },
                      method: 'POST',
                      success: function(msg){
                          if(msg!=''){
                            window.location='pointlist.php';
                              //return false;
                          }
                      }
                  });
          <?php 
          }else
          {  ?>
           
            $.ajax({      
                    url: "pointadd.php",
                    data: { act:"load",
                          pointmaster_title:pointmaster_title,pointmaster_category_id:pointmaster_category_id,pointmaster_domain_id:pointmaster_domain_id,pointmaster_code:pointmaster_code,pointmaster_tracking_id:pointmaster_tracking_id,pointmaster_clinic_id:pointmaster_clinic_id,pointmaster_id:<?php echo $_REQUEST['pointmaster_id']; ?>,pointmaster_sender:pointmaster_sender,pointmaster_receiver:pointmaster_receiver,pointmaster_total_points:pointmaster_total_points,pointmaster_unit_point:pointmaster_unit_point,
                            pointmaster_campaign_sdate:pointmaster_campaign_sdate,
                            pointmaster_campaign_edate:pointmaster_campaign_edate,
                            pointmaster_frequency:pointmaster_frequency,
                            pointmaster_end_date:pointmaster_end_date,
                            pointmaster_description:pointmaster_description },
                    method: 'POST',
                    success: function(msg){
                        if(msg!=''){
                            window.location='pointlist.php';
                        }
                    }
                });
         <?php }
          ?>
      }

  });
</script>