<?php 



  include('libraryPHP/site_config.php');

 include('libraryPHP/session_check_url.php');





?>



<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">

      <title><?php echo $appName?> | <?php echo $pageTitle?></title>

        

         <!-- App favicon -->



    <?php echo $appFaviconHtml?> 



    <!-- theme css start -->

    <?php include("commoncss.php"); ?>

    <!-- theme css end -->

   <!--  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> -->

        <link rel="stylesheet" href="plugins/select2/css/select2.min.css">



         <link rel="stylesheet" href="plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">




    <style>

        .select2-container--default .select2-selection--multiple .select2-selection__choice__display {

            /* cursor: default; */

            padding-left: 14px;

            padding-right: 5px;



        }



        .select2-container--default .select2-selection--multiple .select2-selection__choice {

            background: #00a88f;

        }

    </style>



</head>



<body>



    <!-- Main Wrapper -->

    <div class="main-wrapper">



        <!-- Header start  -->

        <?php include("header.php"); ?>

        <!-- /Header end -->



        <!-- Sidebar -->

        <?php include("sidebar.php"); ?>

        <!-- /Sidebar -->



        <!-- Page Wrapper -->

        <div class="page-wrapper">



            <div class="content container-fluid">



                <!-- Page Header -->

                <div class="page-header">

                    <div class="row">

                        <div class="col">

                            <h3 class="page-title"> Broadcast</h3>

                            <ul class="breadcrumb">

                                <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>

                                <li class="breadcrumb-item active"> Broadcast</li>

                            </ul>

                        </div>

                    </div>

                </div>

                <!-- /Page Header -->



                <!-- start write start -->

                <div class="col-12">

                    <div class="card">



                        <form class="form-horizontal" method="post" enctype="multipart/form-data" id="broadcast_form" name="broadcast_form">


                            <div class="card-body">

                                <h4 class="card-title">Broadcast</h4>

                                <div class=" form-line">



                                    <input required="required" type="hidden" id="action" name="action" value="add_broadcast" aria-required="true">


                                     <input  required="required" type="hidden" id="action" name="action" value="add_broadcast">



                                         



                                             <label  class=" btn btn-primary btn-rounded ">



                                             <input type="radio" name="broadcast" value="all" onclick="allUser()" checked>&nbsp;All Business



                                             </label>



                                             <label  class=" btn btn-primary btn-rounded ">



                                             <input type="radio" name="broadcast" id="s_users" value="selected_user" class="select txt-input" onclick="myFun()">&nbsp;Select Business



                                             </label>



                                              <label  class=" btn btn-primary btn-rounded ">



                                             <input type="radio" name="broadcast" value="all_store" onclick="allUser1()" >&nbsp;All Trade Assoication


                                             </label>



                                             <label  class=" btn btn-primary btn-rounded ">



                                             <input type="radio" name="broadcast" id="s_users" value="selected_store" class="select txt-input" onclick="myFun1()">&nbsp;Select Trade Assoication



                                             </label>







                                             



                                           





                                         </div>



                                                <div class="users_div" style="display:none " >



                                                    <div class="form-group mb-0"  id="show_selected_users">



                                                        <div class="form-group mt-4">



                                                              <label>Select Business</label>



                                                                 <select class="form-control select2 "  multiple="multiple" style="width: 100%;" name="select_user[]" data-placeholder="Select users" id="select_user[]">

                                                              <option value=""   hidden>Choose select business</option>

                                                        <?php
                                                            $user_id= 0;
                                                            $name = '';
                                                            foreach ($getEditData['user_arr'] as $key => $value) {
                                                                $user_id = $value['user_id'];
                                                              
                                                                if(empty($value['email'])){
                                                                   $ls ='+91 '.$value['mobile'];
                                                                }else{
                                                                    $ls =$value['email']; 
                                                                }
                                                               
                                                               
                                                          ?>
                                                  <option value="<?php echo $value['user_id']; ?>"><?php echo $value['name'].'('.$ls.')'; ?></option>

                                               <?php } ?>
                                                               

                                                           

                                                        </select>

                                                        <label id="select_user[]-error" class="error" for="select_user[]"> </label>



                                                            </div>



                                                        </div>



                                                    </div>





                                                       <div class="users_div1" style="display:none " >



                                                    <div class="form-group mb-0"  id="show_selected_users">



                                                        <div class="form-group">



                                                              <label>Select Trade Association</label>



                                                             

                                                                 <select class="form-control select2 "  multiple="multiple" style="width: 100%;" name="select_store[]">

                                                                <optgroup label="Please Select Trade Association">

                                                        <?php
                                                            $user_id = 0;
                                                            $name = '';
                                                            foreach ($getEditData['store_arr'] as $key => $value) {
                                                                $user_id = $value['user_id'];
                                                              
                                                               if(empty($value['email'])){
                                                                   $ls ='+91 '.$value['mobile'];
                                                                }else{
                                                                    $ls =$value['email']; 
                                                                }
                                                          ?>
                                                  <option value="<?php echo $value['user_id']; ?>"><?php echo $value['name']; ?><?php echo '('.$ls.')';?></option>

                                               <?php } ?>
                                                               

                                                            </optgroup>

                                                        </select>

                                                        <label id="select_store[]-error" class="error" for="select_store[]" style="display: none;"></label>



                                                              

                                                    



                                                            </div>



                                                        </div>



                                                    </div>







                                                       <div class="users_div2" style="display:none " >



                                                    <div class="form-group mb-0"  id="show_selected_users">



                                                        <div class="form-group">



                                                              <label>Select Driver</label>



                                                              

                                                                 <select class="form-control select2 "  multiple="multiple" style="width: 100%;" name="select_driver[]">

                                                                <optgroup label="Please Select User">

                                                     <?php
                                                            $user_id= 0;
                                                            $name = '';
                                                            foreach ($getEditData['driver_arr'] as $key => $value) {
                                                                $user_id = $value['user_id'];
                                                                $name = $value['name'];
                                                                $mobile_number =$value['mobile'];
                                                          ?>
                                                  <option value="<?php echo $value['user_id']; ?>"><?php echo $value['name']; ?><?php echo '('.$value['mobile'].')';?></option>

                                               <?php } ?>
                                                               

                                                            </optgroup>

                                                        </select>



                                                              

                                                        <label id="select_company[]-error" class="error" for="select_company[]"></label>



                                                            </div>



                                                        </div>


                                </div>


                                <br>
                                <label for="title" >Title</label>

                                <div class="form-group">



                                    <div class="form-line">

                                        <input type="text" id="title" name="title" class="form-control" placeholder="Enter title" maxlength="50">

                                    </div>

                                </div>



                                <label for="title">Message</label>

                                <div class="form-group">

                                    <div class="form-line">

                                        <textarea class="form-control" name="message" placeholder="Enter message" style="height: 100px; resize: none;" maxlength="250"></textarea>

                                    </div>

                                </div>



                                <button type="submit" class="btn btn-primary">Submit</button>



                            </div>



                        </form>



                    </div>

                </div> <!-- end col -->



                <!-- start write end -->

            </div>

        </div>

        <!-- /Page Wrapper -->

        <!-- footer start -->

        <?php include("footer.php"); ?>

        <!-- footer end -->



    </div>

    <!-- /Main Wrapper -->



    <!-- sctipt start  -->

    

  
    <!-- script end -->

   <?php include('commonjs.php')?>



    

        <script src="libraryJS/NotificationSend.js"></script>
<?php include('extrajs.php') ?>
<script src="plugins/select2/js/select2.full.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){  

    $.validator.addMethod("valueNotEquals", function(value, element, arg){
  return arg !== value;
 }, "Value must not equal arg.");
  
         //----------------- validation code start here -------------------
        $("form[name='broadcast_form']").validate({
            rules: {
                title: {
                    required: true,
                   
                    maxlength: 50,
                },
                message: {
                    required: true,
                   
                    maxlength: 250,
                },

                
                'select_user[]' :{
                    required: true,
                },

              
            },
            messages: {
                title: {
                    required: 'Please enter title',
                    
                    maxlength: msgValidation.validMaxLength[language],
                },
                message: {
                    required: 'Please enter message ',
                  
                    maxlength: msgValidation.validMaxLengthMessage[language],
                },

              
                'select_user[]': {
                    required:'Please select users',
                },
                 
            },

             submitHandler: function(form) {       

                var link = URLAPI+'common_controller.php';
                //var data=$(form).serialize();
                var data = new FormData($(form)[0]);
                console.log('data',data); 
                var messsage = msgLoading.blankMessage[language];
                console.log('messsage',messsage);
                apiRequest.postFile(link, data, messsage).then(function(obj){
                    console.log('obj',obj);
                    if(obj.success === true){ 

                    //  $('#broadcast_form')[0].reset(); 
                        $('.users_div').hide();       

                         //---------------- Notification send code ------------

                        var notification_arr=obj.data.notification_arr;
                        consoleProvider.log('notification_arr',notification_arr);
                        if(notification_arr != 'NA'){
                            //oneSignalNotificationSendCall(notification_arr);
                        }
                        //---------------- Notification send code end -------
                        //------------ Operation Message --------------------

                        var title ='';
                        var messsage = obj.msg[language];
                        msgSuccessErrorHtml.success(title, messsage, msgSuccessErrorHtmlSelector);
                        //------------ Operation Message End--------------------
                        swal_alert(title,messsage,"manage_broadcast.php","success");
                        return true;

                    } else {

                        //------------ Operation Message --------------------

                        var title = msgTitleOperation.broadcastsend[language];
                        var messsage = obj.msg[language];
                        msgSuccessErrorHtml.error(title, messsage, msgSuccessErrorHtmlSelector);

                        //------------ Operation Message End--------------------

                        swal_alert(title,messsage,"#","error");

                    }

                },function(err){

                    console.log('err',err); 

                    //------------ Operation Message --------------------

                    var title = msgTitleOperation.errorOnServer[language];
                    var messsage = msgOperations.errorOnServer[language];
                    msgSuccessErrorHtml.warning(title, messsage, msgSuccessErrorHtmlSelector);

                    //------------ Operation Message End--------------------

                    swal({

                        title: title,
                        text: messsage,
                        icon: "error", //error, success, info
                        button: "Ok",
                      });
                    return false; 
                });  
                return false;
            }
        });
    });
</script>
  




  











   <script type="text/javascript">



     function allUser(){



         $('.users_div').hide();

          $('.users_div1').hide();



        $("#users_div2").hide();



    }



    function allUser1(){



         $('.users_div').hide();

          $('.users_div1').hide();



        $(".users_div2").hide();



    }



     function allUser2(){



         $('.users_div').hide();

          $('.users_div1').hide();



        $(".users_div2").hide();



    }







    function myFun(){



          $('.users_div').show();

          $('.users_div1').hide();



        $(".users_div2").hide();



    }



      function myFun1(){



          $('.users_div').hide();

           $('.users_div1').show();



        $(".users_div2").hide();



    }



     function myFun2(){



          $('.users_div').hide();

           $('.users_div1').hide();



        $(".users_div2").show();



    }





</script>







<script>



 $(function () {



    



    $('.select2').select2()







   



    $('.select2bs4').select2({



      theme: 'bootstrap4'



      



    })



 });



</script>


</body>



</html>