<?php
function wosmpl_geodata_box_html($post)
{
    $wosmpl_latlon = get_post_meta($post->ID, 'wosmpl_latlon', true);
    $s_cat = get_post_meta($post->ID, 'wosmpl_geo_cat', true);
    $geo_cats = get_option('wosmpl_geo_cats', []);
    $presta_type = get_post_meta($post->ID, 'wosmpl_presta_type', true);
    $wosmpl_post_addr = get_post_meta($post->ID, 'wosmpl_post_addr', true);

    ?>
    <div>
        <div id="wosmpl_latlon_field">
            <label for="wosmpl_latlon">Latitude,Longitude</label>
            <input name="wosmpl_latlon" class="postbox" value="<?php echo $wosmpl_latlon?>"/>
        </div>
        <div id="wosmpl_plain_text_addr">
            <input role="combobox" aria-autocomplete="list" aria-expanded="false" autocomplete="off" value="" placeholder="Ex. 1 rue gaston ..." id="wosmpl_address_auto">
            <div id="wosmpl_address_suggestions"></div>
        </div>
        <div class="clear"></div>
    </div>
    <?php if(count($geo_cats)>0) : ?>
    <div>
    <label for="wosmpl_geo_cat">Cat.</label>
    <select name="wosmpl_geo_cat" class="postbox">
        <option value="0" <?php selected($s_cat, '0'); ?>>Select cat.</option>
        <?php 
        foreach ($geo_cats as $cat) {
          echo '<option value="'.$cat['id'].'" '.selected($s_cat,$cat['id']).'>'.$cat['name'].'</option>';
          }
        ?>
    </select>
    </div>
    <div id="wosmpl_presta_type">
        <label for="wosmpl_presta_type">Presta. type</label>
        <input name="wosmpl_presta_type" value="<?php echo $presta_type?>"/>
    </div>

    <div>
        <input type="hidden" name="wosmpl_post_addr" value="<?php echo $wosmpl_post_addr;?>"/>
        <!-- adresse postale -->
        <?php echo $wosmpl_post_addr; ?>
    </div>
    <?php endif;?>
<?php
}

function wosmpl_additionnal_marker_data_box_html($post){
    $wosmpl_open_hours = get_post_meta($post->ID, 'wosmpl_partner_open_hours', true);
    $wosmpl_partner_specialty =  get_post_meta($post->ID, 'wosmpl_partner_specialty', true);
    
    
    ?>
    <div>
        <div id="wosmpl_open_hours">
            <label for="wosmpl_partner_open_hours">Horaires d'ouverture</label>
            <textarea name="wosmpl_partner_open_hours"><?php echo $wosmpl_open_hours; ?></textarea>
        </div>
        <div id="wosmpl_partner_specialty">
            <label for="wosmpl_partner_specialty">Spécialité</label>
            <textarea name="wosmpl_partner_specialty"><?php echo $wosmpl_partner_specialty; ?></textarea>
        </div>
    
    </div>
    <?php
}

function wosmpl_additionnal_page_data_box_html($post){
    $phone_checked = $email_checked = $website_checked = '';

    $wosmpl_partner_challenge = get_post_meta($post->ID, 'wosmpl_partner_challenge', true);
    $wosmpl_partner_phone = get_post_meta($post->ID, 'wosmpl_partner_phone', true);
    $wosmpl_partner_phone_visible = get_post_meta($post->ID, 'wosmpl_partner_phone_visible', true);
    if($wosmpl_partner_phone_visible == "yes") {
        $phone_checked = 'checked="checked"';
    } 
    $wosmpl_partner_email = get_post_meta($post->ID, 'wosmpl_partner_email', true);
    $wosmpl_partner_email_visible = get_post_meta($post->ID, 'wosmpl_partner_email_visible', true);
    if($wosmpl_partner_email_visible == "yes") {
        $email_checked = 'checked="checked"';
    } 
    $wosmpl_partner_website = get_post_meta($post->ID, 'wosmpl_partner_website', true);
    $wosmpl_partner_website_visible = get_post_meta($post->ID, 'wosmpl_partner_website_visible', true);
    if($wosmpl_partner_website_visible == "yes") {
        $website_checked = 'checked="checked"';
    } 
    
    $img_file = get_post_meta($post->ID, 'wosmpl_partner_pict', true);
    if ($img_file && strlen($img_file) > 40) { //40 because filename is sha1
        $img_src = $img_file;
    } else {
        $img_src = plugins_url('images/no-picture.png', __FILE__);
    }
    
    $width = $height = 0;
    ?>

    <div>
        <div class="upload">
            <h5>Photo associée</h5>
            <img id="wosmpl_upload_viewer" src="<?php echo $img_src;?>" width="150px"  />
            <?php if ($width > 0) { echo " ($width x $height)";} ?>
            <div>
                <input type="hidden" name="wosmpl_partner_pict" id="wosmpl_partner_pict" value="<?php echo $img_file;?>" />

                <input type="file" id="wosml_img_selector" accept="image/png, image/jpeg"/>
                <a class="wosmpl_upload_image_button button" style="display:none;">Envoyer
                </a>
                <a class="wosmpl_remove_image_button button">&times;</a>
            </div>
        </div>
         <div id="wosmpl_partner_challenge">
            <label for="wosmpl_partner_challenge">Défi</label>
            <textarea name="wosmpl_partner_challenge"><?php echo $wosmpl_partner_challenge; ?></textarea>
        </div>
        <div id="wosmpl_partner_phone">
            <label for="wosmpl_partner_phone">Téléphone</label>
            <input name="wosmpl_partner_phone" type="tel" value="<?php echo $wosmpl_partner_phone; ?>" />
            <input type="checkbox" name="wosmpl_partner_phone_visible" value="yes" <?php echo $phone_checked?>/> visible
        </div>
        <div id="wosmpl_partner_email">
            <label for="wosmpl_partner_email">Email</label>
            <input name="wosmpl_partner_email" type="email" value="<?php echo $wosmpl_partner_email; ?>" />
            <input type="checkbox" name="wosmpl_partner_email_visible" value="yes" <?php echo $email_checked?>/> visible
        </div>
        <div id="wosmpl_partner_website">
            <label for="wosmpl_partner_website">Site</label>
            <input name="wosmpl_partner_website" type="text" value="<?php echo $wosmpl_partner_website; ?>" />
            <input type="checkbox" name="wosmpl_partner_website_visible" value="yes" <?php echo $website_checked?>/> visible
        </div>
    </div>
    <?php
}
