<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="btn-group pull-right m-t-10">
                    <button onclick="openaddevent();" class="btn btn-primary waves-effect waves-light m-r-10"><i class="fa fa-plus"></i> Add Event</button>
                    
                </div>
                <h4 class="page-title">Instance Settings:</h4>
                 <div class="col-md-12">
                     <?php if ($this->session->flashdata('Success') && $this->session->flashdata('Success') != ""){  ?>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="alert alert-success">
                                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                                <strong>Success!</strong> <?php echo $this->session->flashdata('Success'); ?>
                            </div>
                        </div>
                    </div>
                    <?php } ?>
                    <?php if ($this->session->flashdata('Error') && $this->session->flashdata('Error') != ""){  ?>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="alert alert-danger">
                                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                                <strong>Error!</strong> <?php echo $this->session->flashdata('Error'); ?>
                            </div>
                        </div>
                    </div>
                    <?php } ?>
                     <div class="card-box ">
                         <div class="row">
                             <div class="col-md-6">
                                 <h4 class='panel-heading'>SMS API Credentials</h4>
                                 <form method="post" action='<?php echo base_url();?>superuser_controller/update_smscred'>
                                    <div class="form-group">
                                      
                                        <input type='hidden' readonly="readonly" name="id_sms_cred" value="<?php if(sizeof($cred)>0){ echo $cred[0]['id_sms_cred'];}?>" />
                                    </div>
                                    <div class="form-group">
                                        <label class="form-label" for="username">User Name</label>
                                        <input class='form-control' name="username" value="<?php if(sizeof($cred)>0){ echo $cred[0]['username'];}?>" />
                                    </div>
                                    <div class="form-group">
                                        <label class="form-label" for="password">Password</label>
                                        <input class='form-control' name="password" value="<?php if(sizeof($cred)>0){ echo $cred[0]['password'];}?>" />
                                    </div>
                                    <div class="form-group">
                                        <label class="form-label" for="domain">Domain</label>
                                        <input class='form-control' name="domain" value="<?php if(sizeof($cred)>0){ echo $cred[0]['domain'];}?>" />
                                    </div>
                                    <div class="form-group">
                                        <label class="form-label" for="status">Status</label>
                                        <select class='form-control' name="status">
                                            <option <?php if(sizeof($cred)>0){if($cred[0]['status']=='valid'){echo 'selected="seleted"';} }?> value='valid'>Valid</option>
                                            <option <?php if(sizeof($cred)>0){if($cred[0]['status']=='invalid'){echo 'selected="seleted"';} }?> value='invalid'>Invalid</option>
                                        </select>

                                    </div>
                                     <div class="">
                                         <button type='submit' style='float: right' class="btn btn-pink">Save</button>
                                     </div> 
                                 </form>
                             </div>
                             <div>
                             <div class="row">
                                 <div class="col-md-12">
                                     <hr/>
                                 <form method="post" action='<?php echo base_url();?>superuser_controller/download_customers'>
                                     <div class="col-md-12"><h4>Customer List for Messaging</h4></div>
                                 <div class="row">
                                     <div class="col-md-4">
                                         <?php if($this->session->userdata('common_products')=='Yes'){?>
                                         <select onchange="$('#business_name').val(this.options[this.selectedIndex].text);" name="business_id" class="form-control">
                                             <?php foreach($businesses as $b){ ?>
                                             <option value="<?php echo $b['id_business']; ?>" >
                                                 <?php echo $b['business_name']; ?>
                                             </option>
                                             <?php } ?>
                                         </select>
                                         <?php } else { ?>
                                         <select onchange="$('#business_name').val(this.options[this.selectedIndex].text);" name="business_id" class="form-control">
                                             <?php foreach($business as $b){ ?>
                                             <option value="<?php echo $b['id_business']; ?>" >
                                                 <?php echo $b['business_name']; ?>
                                             </option>
                                             <?php } ?>
                                         </select>
                                         
                                         <?php } ?>
                                         <input type="hidden" id="business_name" name="business_name" >
                                     </div>
                                     <div class="col-md-4">
                                         <button type="submit" class="btn btn-pink" >Download CSV</button>
                                     </div>
                                 </div>
                                 </form>
                            </div>
                         </div>
                     </div>
                </div>
            </div>
        
            
            <div class="col-sm-12">
                 <div class="card-box">
                     <div class="row">
                        <div class="btn-group pull-right m-t-10">
                            <button onclick="openaddtask();" class="btn btn-primary waves-effect waves-light m-r-10"><i class="fa fa-plus"></i> Add Task</button>

                        </div>
                         
                         <div>
                             <table class="table table-striped table-responsive">
                                 <thead>
                                 <tr>
                                     <th style="width: 10%">ID</th>
                                     <th style="width: 10%">Task Name</th>
                                     <th style="width: 25%">Query</th>
                                    <th style="width: 25%">SMS Text</th>
                                     <th style="width: 10%">Status</th>
                                     <th style="width: 10%">Test</th>
                                     <th style="width: 10%">Update</th>
                                 </tr>
                                 </thead>
                                 <tbody>
                                     <?php foreach($tasks as $task){?>
                                     <tr>
                                        <form action="<?php echo base_url();?>superuser_controller/updatetask" method="post">
                                        <td><input style="border:none; background:transparent;" name="id_scheduled_tasks" value="<?php echo $task['id_scheduled_tasks']; ?>"/></td>
                                        <td><input style="border:none; background:transparent;" name="task_name" value="<?php echo $task['task_name']; ?>"</td>
                                        <td><textarea rows="8" cols="40" type="text" style="border:none; background:transparent;" name="s_query"  ><?php echo $task['s_query']; ?></textarea></td>
                                        <td><textarea rows="8" cols="40" type="text" style="border:none; background:transparent;" name="msg"><?php echo $task['msg']; ?></textarea></td>   
                                        <td><input  style="border:none; background:transparent;" name="status" value="<?php echo $task['status']; ?>"/></td> 
                                        <td><button onclick="$('#operation_<?php echo $task['id_scheduled_tasks']; ?>').val('test');" class="btn btn-sm" type="submit">Test</button></td>
                                        <td><button onclick="$('#operation_<?php echo $task['id_scheduled_tasks']; ?>').val('update');" class="btn btn-sm" type="submit">Update</button><input type="hidden"  name="operation" id="operation_<?php echo $task['id_scheduled_tasks']; ?>"  /></td>
                                        
                                        </form>
                                     </tr>
                                     <?php } ?>
                                 </tbody>
                             </table>
                         </div>
                         
                     </div>
                </div>     
            </div>
        
        </div>