<?php

global $zc_ms;
//$all_stats = $this->get_plugin_option( 'stats' );
//$total_song_count = $all_stats['total_song_count'];
//$playlist_count = $all_stats['sample_playlist_count'];
$all_settings = $zc_ms->get_plugin_option( 'settings' );
$date_format = isset($all_settings['date_format']) ? $all_settings['date_format'] : '';
$table_height = isset($all_settings['table_height']) ? $all_settings['table_height'] : '';
$branding = $all_settings['branding'];
$set_role = $all_settings['user_role'];
$show_page_title =$all_settings[ 'show_page_title' ];
if(isset($all_settings['opening_text'])){
    $opening_text = $all_settings['opening_text'];
}
$custom_msg = $all_settings['custom_msg'];
$body_font_colour 	= $all_settings['body_font_colour'];
$header_row_color =  $all_settings['header_row_color'];
$body_row_color = $all_settings['body_row_color'];
$args = array('post_type' => 'songs','post_status' => 'publish',  'fields' => 'ids', 'posts_per_page' => -1 );//, 'offset' => $x * 1000);
$total_songs = 0;
$query = new WP_Query($args);
if( $query->have_posts() ) {
    $total_songs = $query->post_count;
}
?>

<div class="container-fluid" style="padding: 20px">
    <?php
    wp_enqueue_media();?>
    <div id="overlay" class="hidden"></div>
    <div id="icon-edit" class="icon32 icon32-posts-songs"></div>
    <h2>Song Selector Settings
    </h2>
    <form action="options.php" onsubmit="" method="post">
        <?php settings_fields($zc_ms->options_group);

        ?>
        <table class="table">

            <tr>
                <th scope="row"><strong>Shortcode</strong></th>
                <td>
                    <p id="shortcode">[song-selector-free]</p>
                    <p><em>Use above shortcode to display the song selector on the front end.</em>
                    </p>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><strong>User Role Settings</strong></th>
                <td>
                    <p>Define user role for new users:</p>
                    <p>
                        <select id="user-role" name="new_opt[settings][user_role]">
                            <?php  global $wp_roles; $roles = $wp_roles->get_names();?>
                            <?php foreach($roles as $role) { ?>
                                <option value="<?php echo $role;?>" <?php if ($role == $set_role) { echo 'selected="selected"';}?>><?php echo $role;?></option>
                            <?php }//end foreach ?>
                        </select>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><strong>PDF Settings</strong></th>
                <td>
                    <label for="image_url" >PDF Logo Image:  </label>
                    <input type="text" name="new_opt[settings][branding][logo_url]" id="image_url" class="regular-text" value="<?php echo $branding['logo_url'] ?>">
                    <input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
                    <p style="margin-bottom: 15px">PDF Playlist Heading Font Colour:  <input style="width:140px" type="text" name="new_opt[settings][branding][headline_font_color]" value="<?php echo $branding['headline_font_color'] ?>" id="headline-color" title="Specify color of the headline text"/></p>
                    <p style="margin-bottom: 15px">PDF Playlist Heading Font Size:  <input style="width:140px" type="text" name="new_opt[settings][branding][headline_font_size]" value="<?php echo $branding['headline_font_size'] ?>" id="headline-size" title="Specify the size of the headline text"/></p>
                    <p style="margin-bottom: 15px">PDF Playlist Body Font Colour:  <input style="width:140px" type="text" name="new_opt[settings][body_font_colour]" value="<?php echo $body_font_colour ?>"  /></p>
                    <p>Generate Print Version PDF:</p>
                    <?php $wp_upload = wp_upload_dir();?>
                    <p><input type="button" id="sample-pdf" class="button-secondary generate-pdf" value="Generate Print Version PDF" title="Export the print version to pdf" name="sample" /><a target="_blank" href="<?php echo $wp_upload['baseurl'] . '/EMP/song-list.pdf'; ?>" id="s-pdf-link" class="pdf-link"></a></p>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><strong>Song counts</strong></th>
                <td>
                    <p style="margin-bottom: 20px"> Update Playlists counts </p>
                    <p style="margin-bottom: 20px"><input type="button" id="playlists-counts" class="button-secondary" value="Update counts" title="Recalculate playlist counts for sample and master playlists" /></p>
                    <label><i>Re-Calculate playlist counts for print and master playlists</i></label>

                    <div id='counts-stats'>


                    </div>
                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><strong>Available genres</strong></th>
                <td>
                    <p style="margin-bottom: 20px"> Update the available genres List</p>
                    <p style="margin-bottom: 20px"><input type="button" id="available-genres" class="button-secondary" value="Update available genres" title="Populate the available genres list" /></p>
                    <div id='genres-stats'></div>
                </td>
            </tr>

            <tr valign="top">
                <th scope="row"><strong>Display Settings</strong></th>
                <td>
                    <p style="margin-bottom: 20px">Song Selector Header Row / Hyperlinks (if empty theme colour will be used):  <input style="width:140px" type="text" name="new_opt[settings][header_row_color]" value="<?php echo $header_row_color ?>"  /></p>
                    <p style="margin-bottom: 20px">Song Selector Body Font Colour (if empty theme colour will be used): <input style="width:140px" type="text" name="new_opt[settings][body_row_color]" value="<?php echo $body_row_color ?>"  /></p>
                    <p style="margin-bottom: 20px">Song List Table height: <input style="width:100px" type="text" name="new_opt[settings][table_height]" value="<?= $table_height; ?>"  />px. Note: minimum height is 200px</p>

                    <p style="margin-bottom: 20px"><b style="width: 20%; display: block;float: left;">Show Page Title</b>
                        <select  name="new_opt[settings][show_page_title]">

                            <option value="1" <?php if ($show_page_title == '1') { echo 'selected="selected"';}?>><?php echo 'Yes';?></option>
                            <option value="0" <?php if ($show_page_title == '0') { echo 'selected="selected"';}?>><?php echo 'No';?></option>

                        </select></p>
                    
                    <p style="margin-bottom: 20px"><b style="width: 20%; display: block;float: left;">Date Format</b>
                        <input type="radio" value="dd/mm/yy" name="new_opt[settings][date_format]" <?= empty($date_format) || $date_format === 'dd/mm/yy' ? 'checked' : ''; ?> />&nbsp; DD/MM/YY
                        <input style="margin-left: 10px" type="radio" value="mm/dd/yy" name="new_opt[settings][date_format]" <?= $date_format === 'mm/dd/yy' ? 'checked' : ''; ?> />&nbsp;MM/DD/YY
                    </p>

                </td>
            </tr>
            <tr valign="top">
                <th scope="row"><strong>Welcome Message</strong></th>
                <td>
                    <div style="margin-bottom: 20px; ">
                        <div style=" margin-bottom:10px;"> <input type="radio" name="new_opt[settings][opening_text]" value="" <?= $opening_text === "" ? " checked":""?>> Please register & login so you can access our FULL PLAYLIST of <b><?=$total_songs; ?></b> songs and have the ability to save your playlists and print them out.</div>
                        <div style=""><input type="radio" name ="new_opt[settings][opening_text]" value="custom" <?= $opening_text === "custom" ? " checked":""?>> Show my own message.<br><textarea name="new_opt[settings][custom_msg]"  rows="5" cols="40"><?= $custom_msg; ?></textarea></div>
                    </div>
                </td>
            </tr>
            <tr valign="top">
                <th></th>
                <td><button name="info_update" type="submit" class="btn btn-primary" > <?php esc_attr_e('Save Changes'); ?></button>
            </tr>

            <tr>
                <th></th>
                <td> Please support this plugin by leaving your review at wordpress.org <a href="http://bit.ly/1Iu4Ngn" target="_blank">http://bit.ly/1Iu4Ngn</a> </td>
            </tr>

        </table>


    </form>
</div>
