
<script src="<?= asset_url('assets/js/backend_formsdirectory_helper.js') ?>"></script>
<script src="<?= asset_url('assets/js/backend_formsdirectory.js') ?>"></script>
<script>
    var GlobalVariables = {
        csrfToken     : <?= json_encode($this->security->get_csrf_hash()) ?>,
        baseUrl       : <?= json_encode($base_url) ?>,
        dateFormat    : <?= json_encode($date_format) ?>,
        timeFormat    : <?= json_encode($time_format) ?>,
        globals      : <?= json_encode($globals) ?>,
        forms       : <?= json_encode($forms) ?>,
        categories  :<?= json_encode($categories) ?>,
        user          : {
            id        : <?= $user_id ?>,
            email     : <?= json_encode($user_email) ?>,
            role_slug : <?= json_encode($role_slug) ?>,
            privileges: <?= json_encode($privileges) ?>
        }
    };

    $(document).ready(function() {
        Backendforms.initialize(true);
    });
</script>

<div id="forms-page" class="container-fluid backend-page">
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#formsdirectoryconfig" aria-controls="ServiceSettings" role="tab" data-toggle="tab">Global Services</a></li>
    </ul>

    <div class="tab-content">

        <!-- Forms TAB -->

        <div role="tabpanel" class="tab-pane active" id="forms">
            <div class="row">
                <div id="filter-forms" class="filter-records column col-xs-12 col-sm-5">
                    <form>
                        <div class="input-group">
                            <input type="text" class="key form-control">

                            <span class="input-group-addon">
                        <div>
                            <button class="filter btn btn-default" type="submit" title="<?= lang('filter') ?>">
                                <span class="glyphicon glyphicon-search"></span>
                            </button>
                            <button class="clear btn btn-default" type="button" title="<?= lang('clear') ?>">
                                <span class="glyphicon glyphicon-repeat"></span>
                            </button>
                        </div>
                    </span>
                        </div>
                    </form>

                    <h3>Global Service Settings</h3>
                    <div class="results"></div>
                </div>

                <div class="record-details column col-xs-12 col-sm-5">
                    <div class="btn-toolbar">
                        <div class="add-edit-delete-group btn-group">
                            <button id="add-forms" class="btn btn-primary">
                                <span class="glyphicon glyphicon-plus"></span>
                                <?= lang('add') ?>
                            </button>
                            <button id="edit-forms" class="btn btn-default" disabled="disabled">
                                <span class="glyphicon glyphicon-pencil"></span>
                                <?= lang('edit') ?>
                            </button>
                            <button id="delete-forms" class="btn btn-default" disabled="disabled">
                                <span class="glyphicon glyphicon-remove"></span>
                                <?= lang('delete') ?>
                            </button>
                        </div>

                        <div class="save-cancel-group btn-group" style="display:none;">
                            <button id="save-forms" class="btn btn-primary">
                                <span class="glyphicon glyphicon-ok"></span>
                                <?= lang('save') ?>
                            </button>
                            <button id="cancel-forms" class="btn btn-default">
                                <span class="glyphicon glyphicon-ban-circle"></span>
                                <?= lang('cancel') ?>
                            </button>
                        </div>
                    </div>

                    <h3><?= lang('details') ?></h3>

                    <div class="form-message alert" style="display:none;"></div>
                    <input type="hidden" id="globalservicesettings-id">


                    <div class="form-group">
                        <label for="globalservicesettings-nameofsetting">Name of Global Setting</label>
                        <input id="globalservicesettings-nameofsetting" class="form-control required" maxlength="128">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicename">Name of Service Global Setting*</label>
                        <input id="globalservicesettings-servicename" class="form-control required">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-serviceduration">Duration of Service Global Setting*</label>
                        <input type="number" id="globalservicesettings-serviceduration" class="form-control required">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-category"><?= lang('category') ?></label>
                        <select id="globalservicesettings-category" class="form-control required">
                            <?php
                            echo '<option value'." name".">" . 'No Category'. '</option>';

                            foreach($categories as $company){
                                echo '<option value="' . $company['id']. '" name="' . $company['id'] . '">' . $company['name'] . '</option>';

                            }
                            ?>

                        </select>
                    </div>


                    <div class="form-group">
                        <label for="globalservicesettings-openclosed">Service open or closed? (closed means not available to general public but can be accessed by a special link)
                        </label>
                        <select id="globalservicesettings-openclosed" class="form-control required" >
                            <option value="OPEN">
                                OPEN
                            </option>
                            <option value="CLOSED">
                                CLOSED
                            </option>
                        </select>
                    </div>


                    <div class="form-group">
                        <label for="globalservicesettings-minmax">Minimum Maximum Age Function</label>
                        <select id="globalservicesettings-minmax" class="form-control required" >
                            <option value="OFF">
                                OFF
                            </option>
                            <option value="ON">
                                ON
                            </option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-minimum">Minimum Age</label>
                        <input id="globalservicesettings-minimum" class="form-control required" type="text">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-maximum">Maximum Age</label>
                        <input id="globalservicesettings-maximum" class="form-control required" type="text">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-selectform">Select Form </label>
                        <select id="globalservicesettings-selectform" class="form-control required" >
                            <?php
                            foreach($forms as $form){
                                echo '<option value="' . $form['id']. '" name="' . $form['id'] . '">' . $form['form_name'] . '</option>';

                            }
                            ?>
                        </select>
                    </div>


                    <!--<div class="form-group">
                        <label for="globalservicesettings-serviceprice">Price of Service Global Setting*</label>
                        <input type="number" id="globalservicesettings-serviceprice" class="form-control required">
                    </div>
                    <div class="form-group">
                        <label for="globalservicesettings-servicecurrency">Currency of Service Global Setting*</label>
                        <input id="globalservicesettings-servicecurrency" class="form-control required">
                    </div>-->

                    <div class="form-group">
                        <label for="globalservicesettings-servicedescription">Description of Service Global Setting*</label>
                        <textarea id="globalservicesettings-servicedescription" class="form-control required"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-serviceavailabilities_type">Availabilities Type of Service Global Setting*</label>
                        <select id="globalservicesettings-serviceavailabilities_type" class="form-control" hidden>
                            <option value="<?= AVAILABILITIES_TYPE_FLEXIBLE ?>">
                                Flexible (every 15 mins *adjusts upon booking)
                            </option>
                            <option value="<?= AVAILABILITIES_TYPE_FIXED ?>">
                                Fixed (matches Duration time)
                            </option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-serviceattendants_number">Attendants Number of Service Global Setting*</label>
                        <input type="number" id="globalservicesettings-serviceattendants_number" class="form-control required">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicecheckbox">Service Checkbox of Service Global Setting*</label>
                        <input id="globalservicesettings-servicecheckbox" class="form-control required">
                    </div>



                    <br><strong><h5 >WAITLIST FUNCTION </h5></strong><br>


                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlistonofffunction">Waitlist Functionality * </label>
                        <select id="globalservicesettings-servicewaitlistonofffunction" class="form-control">
                            <option value="OFF" name="OFF">OFF</option>
                            <option value="ON" name="ON" required>ON</option>
                        </select>
                    </div>



                    <!-- DONT PROVIDE THIS ANYMORE START -->
                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_confirm_email_header" hidden>Waitlist Confirm Email Header </label>
                        <textarea id="globalservicesettings-servicewaitlist_confirm_email_header" rows="4" class="form-control" style="display:none;"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_confirm_email_desc" hidden>Waitlist Confirm Email Description </label>
                        <textarea id="globalservicesettings-servicewaitlist_confirm_email_desc" rows="4" class="form-control" style="display:none;"></textarea>
                    </div>
                    <!-- DONT PROVIDE THIS ANYMORE END  -->



                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_doses" id="globalservicesettings-servicewaitlist_doseslabel">Waitlist Service Dose Inventory - What is your inventory starting on the waitlist service doses date below? * </label>
                        <input type="number" id="globalservicesettings-servicewaitlist_doses" name="globalservicesettings-servicewaitlist_doses" class="form-control">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_doses_date" id="globalservicesettings-servicewaitlist_doses_datelabel">Waitlist Service Doses Date - yyyy-mm-dd **date system starts counting appointments for dose inventory *</label>
                        <input type="date" name="globalservicesettings-servicewaitlist_doses_date" id="globalservicesettings-servicewaitlist_doses_date" class="form-control">
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_doses_percentage" id="service-servicewaitlist_doses_percentagelabel">Waitlist Doses Multiplier The following number is a multiplier for the number of doses. (e.g. if you have 20 available doses and the number below is 1, it will send out 20 emails.
                            If you want it to send out 40 emails, the number below would be set to 2. Please set the number to what you are comfortable with.)* </label>
                        <input type="number" id="globalservicesettings-servicewaitlist_doses_percentage" name="globalservicesettings-wserviceaitlist_doses_percentage" class="form-control">

                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_time_to_book" id="service-servicewaitlist_time_to_booklabel">IN MINUTES: This is how long you want to give your patients to book an appointment before the appointment is available to others. WE DO NOT RECOMMEND MAKING THIS LOWER THAN 12 - 24  HOURS DUE TO POTENTIAL DELAYS IN EMAILS BEING SENT *</label>
                        <input type="number" id="globalservicesettings-servicewaitlist_time_to_book" name="globalservicesettings-servicewaitlist_time_to_book" class="form-control">

                    </div>



                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_reminder_email_header" id="globalservicesettings-servicewaitlist_reminder_email_headerlabel">Waitlist Reminder Email Subject (what you want the subject of the email to be when telling customers there are more doses) *</label>
                        <textarea id="globalservicesettings-servicewaitlist_reminder_email_header" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicewaitlist_reminder_email_desc" id="globalservicesettings-servicewaitlist_reminder_email_desclabel">Waitlist Reminder Email Body (what you want the body of the email to say when telling the customers there are more doses) *</label>
                        <textarea id="globalservicesettings-servicewaitlist_reminder_email_desc" rows="4" class="form-control"></textarea>
                    </div>

                    <!-- Service Link fields 1-->
                    <!--<br><strong><h5 >SERVICE FORM </h5></strong><br>

                    <div class="form-group">
                        <label for="globalservicesettings-serviceformonoff">Add form to frontend * </label>
                        <select id="globalservicesettings-serviceformonoff" class="form-control">
                            <option value="OFF" name="OFF">OFF</option>
                            <option value="ON" name="ON" required>ON</option>
                        </select>
                    </div>


                    <div class="form-group">
                        <label for="globalservicesettings-servicelinkname">Company Link Name Form 1 (will show up regardless of service)</label>
                        <textarea id="globalservicesettings-servicelinkname" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicelink">Company Link Form 1 (will show up regardless of service)</label>
                        <textarea id="globalservicesettings-servicelink" rows="4" class="form-control"></textarea>
                    </div>-->

                    <br><strong><h5 >EMAIL/SMS SETTINGS  </h5></strong><br>

                    <div class="form-group">
                        <label for="globalservicesettings-servicesmsonoff">SMS functionality (reminders and confirmation) * </label>
                        <select id="globalservicesettings-servicesmsonoff" class="form-control">
                            <option value="OFF" name="OFF">OFF</option>
                            <option value="ON" name="ON" required>ON</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicesms_confirmation_message" id="globalservicesettings-servicesms_confirmation_messagelabel">SMS confirmation message  </label>
                        <textarea id="globalservicesettings-servicesms_confirmation_message" rows="4" class="form-control"></textarea>

                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicesms_delete_message" id="globalservicesettings-servicesms_delete_messagelabel">SMS delete message  </label>
                        <textarea id="globalservicesettings-servicesms_delete_message" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group" style="display:none">
                        <label for="globalservicesettings-serviceprovider_subject_email" id="globalservicesettings-serviceprovider_subject_emaillabel">Provider Email Subject </label>
                        <textarea id="globalservicesettings-serviceprovider_subject_email" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group" style="display:none">
                        <label for="globalservicesettings-serviceprovider_description_email" id="serviceglobalservicesettings-provider_description_email">Provider Email Description </label>
                        <textarea id="globalservicesettings-serviceprovider_description_email" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicecustomer_subject_email" id="globalservicesettings-servicecustomer_subject_emaillabel">Customer Email Subject </label>
                        <textarea id="globalservicesettings-servicecustomer_subject_email" rows="4" class="form-control"></textarea>
                    </div>

                    <div class="form-group">
                        <label for="globalservicesettings-servicecustomer_description_email" id="globalservicesettings-servicecustomer_description_emaillabel">Customer Email Description </label>
                        <textarea id="globalservicesettings-servicecustomer_description_email" rows="4" class="form-control"></textarea>
                    </div>

                    <br><strong><h5 >REMINDERS SETTINGS  </h5></strong><br>

                    <br><strong><h6 >REMINDERS (1 day before appointment) SETTINGS  </h6></strong><br>

                    <label for="globalservicesettings-servicereminder_on_off">Turn Reminders for this service off/on for reminders sent out 1 day before appointment  </label>
                    <select id="globalservicesettings-servicereminder_on_off" name="globalservicesettings-servicereminder_on_off">
                        <option value="ON" name="ON">ON</option>
                        <option value="OFF" name="OFF" required>OFF</option>

                    </select><br><br>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_subject">Reminders Email Reminder Subject</label><a href="https://myappts.org/images/header.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_subject" name="globalservicesettings-serviceemail_reminder_subject" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_description">Email Description: (for reminders sent out 1 day before appointment)</label><a href="https://myappts.org/images/description.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_description" name="globalservicesettings-serviceemail_reminder_description" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-servicetext_reminder_description">Text Message(for reminders sent out 1 day before appointment) </label><br>
                        <textarea id="globalservicesettings-servicetext_reminder_description" name="globalservicesettings-servicetext_reminder_description" ></textarea><br>
                    </div>

                    <br><strong><h6 >REMINDERS (1 day after appointment was booked) SETTINGS  </h6></strong><br>
                    <label for="globalservicesettings-servicereminder_on_off_two">Turn Reminders for this service off/on for reminders sent out 1 day after appointment was booked  </label>
                    <select id="globalservicesettings-servicereminder_on_off_two" name="service-servicereminder_on_off_two">
                        <option value="ON" name="ON">ON</option>
                        <option value="OFF" name="OFF" required>OFF</option>

                    </select><br><br>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_subject_two">Reminders Email Reminder Subject</label><a href="https://myappts.org/images/header.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_subject_two" name="globalservicesettings-serviceemail_reminder_subject_two" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_description_two">Email Description: (for reminders sent out 1 day after appointment was booked)</label><a href="https://myappts.org/images/description.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_description_two" name="globalservicesettings-serviceemail_reminder_description_two" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-servicetext_reminder_description_two">Text Message(for reminders sent out 1 day after appointment was booked) </label><br>
                        <textarea id="globalservicesettings-servicetext_reminder_description_two" name="globalservicesettings-servicetext_reminder_description_two" ></textarea><br>
                    </div>

                    <br><strong><h6 >REMINDERS (1 day after appointment) SETTINGS  </h6></strong><br>

                    <label for="globalservicesettings-servicereminder_on_off_three">Turn Reminders for this service off/on for reminders sent out 1 day after appointment  </label>
                    <select id="globalservicesettings-servicereminder_on_off_three" name="globalservicesettings-servicereminder_on_off_three">
                        <option value="ON" name="ON">ON</option>
                        <option value="OFF" name="OFF" required>OFF</option>

                    </select><br><br>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_subject_three">Reminders Email Reminder Subject</label><a href="https://myappts.org/images/header.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_subject_three" name="globalservicesettings-serviceemail_reminder_subject_three" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-serviceemail_reminder_description_three">Email Description: (for reminders sent out 1 day after appointment )</label><a href="https://myappts.org/images/description.png" target="_blank"><image src="info-icon.png" width="20" height="20"></a><br>
                        <textarea id="globalservicesettings-serviceemail_reminder_description_three" name="globalservicesettings-serviceemail_reminder_description_three" ></textarea><br>
                    </div>

                    <div id="form-group">
                        <label for="globalservicesettings-servicetext_reminder_description_three">Text Message(for reminders sent out 1 day after appointment) </label><br>
                        <textarea id="globalservicesettings-servicetext_reminder_description_three" name="globalservicesettings-servicetext_reminder_description_three" ></textarea><br>
                    </div>


                    <p id="form-message" class="text-danger">
                        <em><?= lang('fields_are_required') ?></em>
                    </p>
                </div>
            </div>
        </div>