<script type="text/javascript">
	<!--

	/* ========================================================================
	 * Confirmation de suppression de metabox
	 * ======================================================================== */
	function confirmDelete(slug)
	{
		if(confirm("Supprimer cette metabox?")){
			document.location.href="<?php echo Webcollectivites::get_page_url('webco', array('showModule' => 'dashboard')); ?>&action=delete&slug="+slug;
		};
	}

	-->
</script>
<div class="row-fluid">
    <div class="col-12">
        <div class="alert alert-danger">
            Il n'est actuellement pas possible de modifier le contenu d'une métabox dans ce tableau
        </div>
    </div>
	<div class="col-12 pt-3">
		<table class="wp-list-table widefat fixed striped posts">
			<thead>
				<tr align="center">
					<th style="font-weight: bold" scope="col" class="manage-column column-title column-primary sortable desc pl-3">Titre</th>
					<th style="font-weight: bold" scope="col" class="manage-column">Contenu </br><span style="font-weight: normal;font-size: 75%">(ou nom du fichier contenant le script php à exécuter)</span></th>
					<th style="font-weight: bold" scope="col" class="manage-column">Position Initiale</br><span style="font-weight: normal;font-size: 75%">(n'aura pas d'influence si la box a été déplacée au moins une fois manuellement)</span></th>
					<th style="font-weight: bold" scope="col" class="manage-column">Contenu PHP</th>
					<th style="font-weight: bold" scope="col" class="manage-column">Submit Changes</th>
					<th style="font-weight: bold" scope="col" class="manage-column">Discard Changes</th>
					<th style="font-weight: bold" scope="col" class="manage-column">Delete Metabox</th>
				</tr>
			</thead>
			<tbody>

				<?php

				foreach ($result as $row) {
					?>

					<tr data-slug=<?php echo $row->mtbx_slug ?>>
						<td><input class="edit-title" type="text" name="mtbx_title" value=<?php echo $row->mtbx_title ?>></td>
						<td>
							<textarea class="edit-content" name="mtbx_content" ><?php echo stripslashes($row->mtbx_content) ?></textarea>
						</td>
						<td>
							<select class="edit-position">

								<?php  foreach ($positions as $pos) {
									if ($pos == $row->mtbx_position) {
										echo '<option name="mtbx_position" selected>'.$pos.'</option>';
									} else {
										echo '<option name="mtbx_position">'.$pos.'</option>';
									}

								}?>
							</select>

							<td>
								<?php $isPHP = $row->mtbx_content_isPHP ? 'Oui' : 'Non';?>
								<p data-isPHP=<?php echo $row->mtbx_content_isPHP  ?> > <?php echo $isPHP; ?></p>
							</td>
						</td>

						<!-- //TODO: selection multiple pour suppression/édition -->
							<td></td>
		<!--				<td>-->
		<!--					<a class="edit-mtbx hidden" data-slug=--><?php //echo $row->mtbx_slug ?><!-- style="cursor: pointer;"> <span style="color:#0085ba;" class="dashicons dashicons-edit"></span></a>-->
		<!--				</td>-->
						<td>
							<a class="discard-mtbx hidden" data-slug=<?php echo $row->mtbx_slug ?> style="cursor: pointer;"> <span style="color:red;" class="dashicons dashicons-no"></span></a>
						</td>
						<td><a onclick="confirmDelete('<?php echo $row->mtbx_slug; ?>')" class="delete-mtbx" data-slug=<?php echo $row->mtbx_slug ?> style="cursor: pointer;"> <span style="color:red;" class="dashicons dashicons-trash"></span></a></td>
					</tr>
					<?php }

					?>
				</tbody>
			</table>
	</div>
</div>