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

<?php 
    if($campaign_one) { ?>
    
        <div class="content">
            <div class="container-fluid">           
                <div class="row">
                    <div class="col-md-3"></div>
                    <div class="col-md-6">
                        <div class="card ">
                            <div class="header" style="margin-bottom:15px;">
                                <div class="pull-left">
                                    <h4 class="title"><i class="pe-7s-pen"></i>&nbsp;&nbsp; <?php echo $campaign_one->c_name; ?></h4>
                                </div>
                            </div>
                            <div class="content">
                            <form method="POST" action="<?php echo base_url(); ?>admin/update_campaign" id="newform">
                                         <div>
                                    <br><br>
                                    <span style="color:#ffbe00;">Mandatory Settings:</span>
                                    <hr>
                                </div>
                                <fieldset>
                                    <input type="hidden" name="c_slug" value="<?php echo $campaign_one->c_slug; ?>">
                                    <div class="form-group">
                                        <label>Campaign Name:</label>
                                        <input value="<?php echo $campaign_one->c_name; ?>" placeholder="Choose a unique name for your campaign" required type="text" class="form-control" name="newc_name" id="newc_name">
                                    </div>
                                </fieldset>

                                <fieldset>
                                    <div class="form-group">
                                        <label>Coupon Codes:</label><br>
                                        <textarea required class="form-control" placeholder="COUPON1
COUPON2 
COUPON3" name="newc_coupons" id="newc_coupons" rows="15" cols="50"><?php echo $campaign_one->c_coupons; ?></textarea>
                                        <span class="help-block">(enter each coupon on a new line; 
                        <!--<span id="warning">as a Basic member you can have 100 active coupons at a time</span>) --> </span>
                                    
                                    </div>
                                </fieldset>
                                <div>
                                    <br><br>
                                    <span style="color:#ffbe00;">Optional Settings:</span>
                                    <hr>
                                </div>
                                <fieldset>
                                    <div class="form-group">
                                        <label>Domain:</label>
                                        <select required class="form-control" name="newc_domain" id="newc_domain">
                                            <option value="<?php echo $campaign_one->c_domain; ?>"  selected><?php echo $campaign_one->c_domain; ?></option> </select>
                                        <!--<span class="help-block"><a href="add.php">(add a custom domain)</a></span>-->
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group">
                                        <label>Daily Coupon Distribution Limit:</label>
                                        <input type="text"  value="<?php echo $campaign_one->c_dailylimit; ?>" class="form-control" name="newc_dailylimit" id="newc_dailylimit" placeholder="leave blank for no limit">
                                        <span class="help-block">e.g. setting this to 10 means that only 10 different coupon codes will be shown every day.</span>
                                    </div>
                                </fieldset>
                                <fieldset>
                                                                <fieldset>
                                    <div class="form-group">
                                        <label>Start Date:</label>
                                        <input  type="text" class="form-control datetimepicker" value="<?php echo $campaign_one->c_startdate; ?>" name="newc_startdate" id="newc_startdate" placeholder="leave blank to make active immediately">
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group">
                                        <label>End Date:</label>
                                        <input  type="text" class="form-control datetimepicker" value="<?php echo $campaign_one->c_enddate; ?>" name="newc_enddate" id="newc_enddate" placeholder="leave blank for evergreen">
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group">
                                        When/If the campaign ends (due to end date or running out of coupons), what would you like to do?<br>
                                        <input required type="radio"  id="real_whattodo" name="real_whattodo" value="2" <?php if($campaign_one->real_whattodo == 2) { echo "checked";} ?>>                                        
                                        <label>                                         
                                            Show a message
                                        </label>
                                        <br>
                                        <input required type="radio"  id="real_whattodo"  name="real_whattodo" value="1" <?php if($campaign_one->real_whattodo == 1) { echo "checked";} ?>>
                                        <label>                                          
                                            Redirect to another page
                                        </label>
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group" style="<?php if($campaign_one->real_whattodo == 2) { echo "display:none;";} ?>" id="redirectdiv">
                                        <label>When the campaign ends, redirect visitors to:</label>
                                        <input required url="true" value="<?php echo $campaign_one->c_redirect; ?>" type="text" class="form-control" name="newc_redirect" id="newc_redirect">
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group"  id="displaytextdiv" style="<?php if($campaign_one->real_whattodo == 1) { echo "display:none;";} ?>">
                                        <label>When the campaign ends, show the following message:</label>
                                        <input required value="<?php echo $campaign_one->c_displaytext; ?>" type="text" class="form-control" name="newc_displaytext" id="newc_displaytext">
                                    </div>
                                </fieldset>
                                <fieldset>
                                    <div class="form-group">
                                        <label>CSS Code:</label><br>
                                        <textarea class="form-control" name="newc_css" id="newc_css" rows="15" cols="50"><?php echo $campaign_one->c_css; ?></textarea>
                                        <span class="help-block">(#code and #sorry are the 2 elements you can style)</span>
                                    </div>
                                </fieldset>
                                
                                <button type="submit" class="btn btn-success btn-fill" name="save" id="save">Save Campaign <i class="fa fa-caret-right"></i></button> 
                                </form>
                            </div>
                        </div>
                                
                                
                    </div>
                    <div class="col-md-3"></div>
                </div>
            </div>
        </div>
 <?php } ?>               
                

    </div>




</div>



</body>
    <!--   Core JS Files and PerfectScrollbar library inside jquery.ui   -->
    <script src="<?php echo base_url(); ?>assets/js/jquery.min.js" type="text/javascript"></script>
    <script src="<?php echo base_url(); ?>assets/js/jquery-ui.min.js" type="text/javascript"></script>
    <script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js" type="text/javascript"></script>


    <!--  Forms Validations Plugin -->
    <script src="<?php echo base_url(); ?>assets/js/jquery.validate.min.js"></script>

    <!--  Plugin for Date Time Picker and Full Calendar Plugin-->
    <script src="<?php echo base_url(); ?>assets/js/moment.min.js"></script>

    <!--  Date Time Picker Plugin is included in this js file -->
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-datetimepicker.js"></script>

    <!--  Select Picker Plugin -->
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-selectpicker.js"></script>

    <!--  Checkbox, Radio, Switch and Tags Input Plugins -->
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-checkbox-radio-switch-tags.js"></script>

    <!--  Charts Plugin -->
    <script src="<?php echo base_url(); ?>assets/js/chartist.min.js"></script>

    <!--  Notifications Plugin    -->
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-notify.js"></script>

    <!-- Sweet Alert 2 plugin -->
    <script src="<?php echo base_url(); ?>assets/js/sweetalert2.js"></script>

    <!-- Vector Map plugin -->
    <script src="<?php echo base_url(); ?>assets/js/jquery-jvectormap.js"></script>

    <!-- Wizard Plugin    -->
    <script src="<?php echo base_url(); ?>assets/js/jquery.bootstrap.wizard.min.js"></script>

    <!--  Bootstrap Table Plugin    -->
    <script src="<?php echo base_url(); ?>assets/js/bootstrap-table.js"></script>

    <!--  Plugin for DataTables.net  -->
    <script src="<?php echo base_url(); ?>assets/js/jquery.datatables.js"></script>


    <!--  Full Calendar Plugin    -->
    <script src="<?php echo base_url(); ?>assets/js/fullcalendar.min.js"></script>

    <!-- Light Bootstrap Dashboard Core javascript and methods -->
    <script src="<?php echo base_url(); ?>assets/js/light-bootstrap-dashboard.js"></script>



    <script type="text/javascript">
    function showerror(msg)
            {
            $.notify(
                {
                icon: "pe-7s-bell",
                message: msg
                },
                {
                type: 'danger',
                timer: 5000,
                placement: 
                    {
                    from: 'top',
                    align: 'center'
                    }
                });
            }
                    
        function showsuccess(msg)
            {
            $.notify(
                {
                icon: "pe-7s-smile",
                message: msg
                },
                {
                type: 'success',
                timer: 5000,
                placement: 
                    {
                    from: 'top',
                    align: 'center'
                    }
                });
            }
        
    
        $(document).ready(function(){   
        
        
/*         
        
        var limit = 100;
        var textarea = document.getElementById("newc_coupons");
        var warning = document.getElementById("warning");
        var spaces = textarea.getAttribute("cols");

        textarea.onkeyup = function() {
           var lines = textarea.value.split("\n");
            
           for (var i = 0; i < lines.length; i++) 
           {
                 if (lines[i].length <= spaces) continue;
                 var j = 0;
                 
                var space = spaces;
                
                while (j++ <= spaces) 
                {
                   if (lines[i].charAt(j) === " ") space = j;  
                }
            lines[i + 1] = lines[i].substring(space + 1) + (lines[i + 1] || "");
            lines[i] = lines[i].substring(0, space);
          }
            if(lines.length>limit)
            {
                textarea.style.color = 'red';
                setTimeout(function(){
                    textarea.style.color = '';
                },2000);
                warning.style.color = 'red';
                setTimeout(function(){
                    warning.style.color = '';
                },2000);
            }    
           textarea.value = lines.slice(0, limit).join("\n");
        };
        
                
        
        */
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            

            $('.datetimepicker').datetimepicker({
                icons: {
                    time: "fa fa-clock-o",
                    date: "fa fa-calendar",
                    up: "fa fa-chevron-up",
                    down: "fa fa-chevron-down",
                    previous: 'fa fa-chevron-left',
                    next: 'fa fa-chevron-right',
                    today: 'fa fa-screenshot',
                    clear: 'fa fa-trash',
                    close: 'fa fa-remove'
                }
            });
            
            var validator = $( "#newform" ).validate();
            
            $('input[type=radio][name=real_whattodo]').change(function() {
        if (this.value == 2) {
            $("#redirectdiv").hide();
            $("#displaytextdiv").show();
        }
        else if (this.value == 1) {
            $("#displaytextdiv").hide();
            $("#redirectdiv").show();
        }
    });
            
            
            
                        

        });
    </script>

</html>
