<?php
$bigSettingsMapper = new BigContact_Models_SettingsMapper();
if (!$bigSettings = $bigSettingsMapper->fetchAll())
    $bigSettings = new BigContact_Models_Settings();
else
    $bigSettings = $bigSettings[0];

$messages = array();
$message_type = '';

if (!empty($_POST)) {
    if (isset($_POST['email-to']))
        $bigSettings->setEmail_to(trim(strip_tags($_POST['email-to'])));
    if (isset($_POST['email-appoint']))
        $bigSettings->setAppointTo(trim(strip_tags($_POST['email-appoint'])));
    if (isset($_POST['general-subject']))
        $bigSettings->setEmailSubject(trim(strip_tags($_POST['general-subject'])));
    if (isset($_POST['general-message']))
        $bigSettings->setEmailMessage(trim(strip_tags($_POST['general-message'])));
    if (isset($_POST['appoint-subject']))
        $bigSettings->setAppointSubject(trim(strip_tags($_POST['appoint-subject'])));
    if (isset($_POST['appoint-message']))
        $bigSettings->setAppointMessage(trim(strip_tags($_POST['appoint-message'])));
    if (isset($_POST['response']))
        $bigSettings->setResponse(trim(strip_tags($_POST['response'])));
    if (isset($_POST['response-reply']))
        $bigSettings->setReplyEmail(trim(strip_tags($_POST['response-reply'])));
    if (isset($_POST['response-subject']))
        $bigSettings->setReplySubject(trim(strip_tags($_POST['response-subject'])));
    if (isset($_POST['response-message']))
        $bigSettings->setReplyMessage(trim(strip_tags($_POST['response-message'])));
    if (isset($_POST['gapikey']))
        $bigSettings->setGapiKey(trim(strip_tags($_POST['gapiKey'])));
    if (isset($_POST['jQuery-ui-style']))
        $bigSettings->setJQueryUiPath(trim(strip_tags($_POST['jQuery-ui-style'])));
    if (isset($_POST['time-date-picker']))
        $bigSettings->setCalendarType(trim(strip_tags($_POST['time-date-picker'])));
    if (isset($_POST['date-format']))
        $bigSettings->setDateFormat(trim(strip_tags($_POST['date-format'])));
    if (isset($_POST['time-format']))
        $bigSettings->setTimeFormat(trim(strip_tags($_POST['time-format'])));
    if (isset($_POST['ampm']))
        $bigSettings->setAmpm('true');
    else
        $bigSettings->setAmpm('false');
    if (isset($_POST['minute-bar']))
        $bigSettings->setShowMinute('true');
    else
        $bigSettings->setShowMinute('false');
    //date-format,time-format,,ampm,minute-bar
    if (!$bigSettingsMapper->save($bigSettings)) {
        $messages[] = 'No changes made';
        $message_type = 'update';
    } else {
        $messages[] = 'Options updated';
        $message_type = 'update';
    }
}
$jQuery_styles = Functions_GetJQueryUiStyles();
?>

<div class="wrap">
    <?php $title = __('Big Contact Settings') ?>
    <div id="icon-options-general" class="icon32"><br></div>
    <h2><?php echo $title . ' '; ?></h2>
    <?php echo Functions_GetMessages($messages, $message_type) ?>
    <form method="post" action="?page=big-contact-settings">
        <h3>General Email Settings:</h3>
        <table class="form-table">
            <tr valign="top">
                <th scope="row"><label for="email-to">General E-mail To</label><br /><span class="description">Who should receive the e-mails? Enter each address on a new line</span></th>
                <td><textarea name="email-to" id="email-to" class="regular-text" cols="55" rows="3"><?php _e($bigSettings->getEmailTo()) ?></textarea></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="email-appoint">Appointment E-mail To</label><br /><span class="description">Who should receive the Appointment e-mails? Enter each address on a new line</span></th>
                <td><textarea name="email-appoint" id="email-appoint" class="regular-text" cols="55" rows="3"><?php _e($bigSettings->getAppointTo()) ?></textarea></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="general-subject">General Email Subject</label></th>
                <td><input type="text" name="general-subject" id="general-subject" class="regular-text" value="<?php _e($bigSettings->getEmailSubject()) ?>"/></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="appoint-subject">Appointment Email Subject</label></th>
                <td><input type="text" name="appoint-subject" id="appoint-subject" class="regular-text" value="<?php _e($bigSettings->getAppointSubject()) ?>"/></td>
            </tr>
        </table>
        <h3>Appointment Response Settings:</h3>
        <table class="form-table">
            <tr valign="top">
                <th scope="row">Send Reply E-mail</th>
                <td><label for="response"><input type="checkbox" name="response" id="response" <?php if ($bigSettings->getResponse() == 'on') echo 'checked' ?> /> Send confirmation email on appointment request.</label></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="response-reply">Reply E-mail</label><br /><span class="description">example: no-reply@company.com</span></th>
                <td><input type="text" name="response-reply" id="response-reply" class="regular-text" value="<?php _e($bigSettings->getReplyEmail()) ?>"/></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="response-subject">Subject</label></th>
                <td><input type="text" name="response-subject" id="response-subject" class="regular-text" value="<?php _e($bigSettings->getReplySubject()) ?>"/></td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="response-message">Message Template</label>
                    <br /><span class="description">[name] = clients name<br />
                        [email] = clients email<br /> [phone] = clients phone<br />
                        [extra] = clients extra<br /> [message] = clients message<br />
                        [date] => appointment date</span></th>
                <td><textarea name="response-message" id="response-message" class="regular-text" cols="55" rows="9"><?php _e($bigSettings->getReplyMessage()) ?></textarea></td>
            </tr>
        </table>
        <h3>Calendar Settings:</h3>
        <table class="form-table">
            <tr valign="top">
                <th scope="row"><label for="jQuery-ui-style">Select Calendar Style</label></th>
                <td><select name="jQuery-ui-style" id="jQuery-ui-style" class="regular-text">
                        <?php foreach ($jQuery_styles as $jQuery_style): ?>
                            <option value="<?php echo $jQuery_style->getPath() ?>"
                            <?php if ($bigSettings->getJQueryUiPath() == $jQuery_style->getPath()): ?>
                                        selected="selected"
                                    <?php endif; ?>>
                                        <?php echo $jQuery_style->getName() ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><label for="time-date-picker">Calendar Type</label></th>
                <td><select name="time-date-picker" id="time-date-picker">
                        <option <?php selected($bigSettings->getCalendarType(), 'date'); ?> value="date">Date Picker</option>
                        <option <?php selected($bigSettings->getCalendarType(), 'datetime'); ?> value="datetime">Date and Time Picker</option>
                    </select>
                </td>
            </tr>
            <tr valign="top">
                <th><label for="date-format">Date Format</label></th>
                <td><input type="text" name="date-format" id="date-format" class="regular-text" value="<?php echo $bigSettings->getDateFormat(); ?>" /><br />
                    <span class="description">
                        Visit JQuery <a href="http://docs.jquery.com/UI/Datepicker/formatDate">UI/Datepicker/formatDate</a> to find more date formats.
                    </span>
                </td>
            </tr>
            <tr valign="top">
                <th><label for="time-format">Time Format</label></th>
                <td><input type="text" name="time-format" id="time-format" class="regular-text" value="<?php echo $bigSettings->getTimeFormat(); ?>" /><br />
                    <span class="description">
                        Change the format (default is "hh:mm tt"): <br />
                        h --> Hour with no leading 0<br />
                        hh --> Hour with leading 0<br />
                        m --> Minute with no leading 0<br />
                        mm --> Minute with leading 0<br />
                        s --> Second with no leading 0<br />
                        ss --> Second with leading 0<br />
                        l --> Milliseconds always with leading 0<br />
                        t --> a or p for AM/PM<br />
                        T --> A or P for AM/PM<br />
                        tt --> am or pm for AM/PM<br />
                        TT --> AM or PM for AM/PM<br />
                    </span>
                </td>
            </tr>
            <tr valign="top">
                <th><label for="ampm">Use AM/PM</label></th>
                <td><label for="ampm"><input type="checkbox" name="ampm" id="ampm" <?php checked($bigSettings->getAmpm(), 'true'); ?>/> Check to enable am/pm notation</label></td>
            </tr>
            <tr valign="top">
                <th><label for="minute-bar">Show Minute Bar</label></th>
                <td><label for="minute-bar"><input type="checkbox" name="minute-bar" id="minute-bar" <?php checked($bigSettings->getShowMinute(), 'true'); ?>/> Check to enable the minute bar</label></td>
            </tr>
        </table>
        <h3>Google Maps Api Settings:</h3>
        <table class="form-table">
            <tr valign="top">
                <th scope="row"><label for="gapiKey">Enter your Google Maps API key</label></th>
                <td><input type="text" name="gapiKey" id="gapiKey" class="regular-text" value="<?php _e($bigSettings->getGapiKey()) ?>"/><br/>
                    <span class="description">To create your API key:<br /><br />

                        1. Visit the APIs Console at <a href="https://code.google.com/apis/console">https://code.google.com/apis/console</a> and log in with your Google Account.<br />
                        2. Click the Services link from the left-hand menu.<br />
                        3. Activate the Google Maps API v3 service.<br />
                        4. Click the API Access link from the left-hand menu. Your API key is available from the API Access page, in the Simple API Access section. Maps API applications use the Key for browser apps.</span></td>
            </tr>
        </table>
        <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"  /></p></form>

</div>