<?php 
global $myUser;
global $conf;
require_once(__DIR__.SLASH.'Notification.class.php');
User::check_access('notification','configure');
$types = array();
?>
<div class="row">
	<div class="col-md-12" id="notification_preference">
		<br>
		<h3>Notifications</h3>
		<div class="clear"></div>
		<hr>
		<p>Dans cette section, vous pouvez créer une notification pour les utilisateurs et types concernés</p>
		


		<div class="row">
			<div class="col-md-6">
				<label for="recipients">Destinataires  </label> <small class="text-muted"> - Laisser vide pour envoyer à tout le monde</small>
				<input type="text" class="form-control" id="recipients" data-type="user" data-multiple>
			</div>
			<div class="col-md-1 mt-4 text-center">
				<span class="font-weight-bold">OU</span>
			</div>
			<div class="col-md-5 mt-4">
				<label for="pinned" class="pointer"><input type="checkbox" class="form-control" id="pinned" data-type="checkbox"> Epingler <small class="text-muted"> - Concerne tout le monde</small> </label> 
				
			</div>
		</div>

		

		

		<div class="row">
			<div class="col-md-6">
				<label for="start">Lancer la notification le  </label> <small class="text-muted"> - Laisser à vide pour envoyer tout de suite</small>
				<input type="text" class="form-control" id="start" data-type="date">
			</div>
			<div class="col-md-6">
				<label for="end">Jusqu'au  </label> <small class="text-muted"> - Par défaut 3 mois</small>
				<input type="text" class="form-control" id="end" data-type="date">
			</div>
		</div>


		<div class="row">
			<div class="col-md-6">
				<label for="type">Type de notification  </label>
				<select class="form-control" id="type">
					<?php foreach(Notification::types() as $slug=>$type): 
						//utilisé pour la recherche par type en bas de page
						$types[$slug] = $type['label'];
					?>
					<option value="<?php echo $slug;?>"><?php echo $type['label']; ?></option>
					<?php endforeach; ?>
				</select>
			</div>
			<div class="col-md-6">
				<label for="label">Sujet  </label>
				<input type="text" class="form-control" id="label">
			</div>
		</div>
		
		
		<textarea class="form-control" id="html" data-type="wysiwyg"></textarea>
		<div class="btn btn-success" onclick="notification_send()"><i class="fas fa-check"></i> Envoyer</div>
	
	</div>
</div>



<div class="row mt-5">
    
    <div class="col-md-12">
    	<h3>Notifications épinglées</h3>
        <select id="filters" data-type="filter" data-label="Recherche" data-join="and" data-function="notification_search">
            <option value="label" data-filter-type="text">Libellé</option>
            <option value="start" data-filter-type="date">Date Début</option>
            <option value="end" data-filter-type="date">Date Fin</option>
            <option value="type" data-filter-type="dictionnary" data-filter-source='<?php echo json_encode($types); ?>'>Type</option>
        </select>
    </div>
</div>
<br/>
<h4 class="results-count"><span></span> Résultat(s)</h4>
<div class="row">
	<!-- search results -->
	<div class="col-xl-12">
		<table id="notifications-pinned" class="table table-striped " data-entity-search="notification_notification_search">
            <thead>
                <tr>
                    <th>#</th>
                    <th data-sortable="type">Type</th>
                    <th data-sortable="label">label</th>
                    <th data-sortable="start">Début</th>
                    <th data-sortable="end">Fin</th>
                    <th >Contenu</th>
                    <th></th>
                </tr>
            </thead>
            
            <tbody>
                <tr data-id="{{id}}" class="hidden">
	                <td>{{id}}</td>
	                <td><i class="{{type.icon}}"></i> {{type.label}}</td>
	                <td>{{label}}</td>
	                <td>{{start}}</td>
	                <td>{{end}}</td>
	                <td>{{html}}</td>
	                <td>
	                    <div class="btn-group btn-group-sm" role="group">
                            <div class="btn btn-danger " onclick="notification_delete(this);"><i class="far fa-trash-alt"></i></div>
	                    </div>
	                </td>
                </tr>
           </tbody>
        </table>

         <!-- Pagination (data-range définit le nombre de pages max affichées avant et après la page courante) -->
       
        <ul class="pagination justify-content-center"  data-range="5">
            <li class="page-item hidden" data-value="{{value}}" title="Voir la page {{label}}" onclick="$(this).parent().find('li').removeClass('active');$(this).addClass('active');notification_notification_search();">
                <span class="page-link">{{label}}</span>
            </li>
        </ul>

	</div>
</div>