<?php
global $myFirm;
if(!$myUser->can('example','read')) throw new Exception("Vous n'avez pas la permission pour executer cette fonctionnalité",403);
require_once('Contact.class.php');
$contact = Contact::provide();

?>
<div class="container-small">
	<br>
	<label for="label">Composant Card</label>
	<small class="text-muted"> (Span data-type="card")</small>
	<h3>Fiche du contact <span data-type="card" data-show-delay="800" data-action="example_contact_card" data-parameters='<?php echo json_encode(array('id'=>$contact->id)); ?>'><?php echo html_decode_utf8($contact->label); ?></span></h3>
	<br>
	<form class="row" method="POST" enctype="multipart/form-data" id="contactForm" data-action="contact_save" data-id="<?php echo $contact->id; ?>">

		<div class="col-xl-12">
			<label for="label">Libellé</label>
			<small class="text-muted"> (Simple input texte)</small>
			<input type="text" value="<?php echo html_decode_utf8($contact->label); ?>" placeholder="Raison sociale ou nom" class="form-control" id="label" name="label"/>
			<br>
			<label for="phone">Téléphone</label>
			<small class="text-muted"> (Simple input texte)</small>
			<input type="text" value="<?php echo $contact->phone; ?>" placeholder="N° Téléphone" class="form-control" id="phone" name="phone"/>
			<br>
			<label for="birth">Date de naissance</label>
			<small class="text-muted"> (Input data-type="date")</small>
			<input type="text" data-type="date" value="<?php echo $contact->birth!=0?date('d/m/Y',$contact->birth):''; ?>" placeholder="La date de naissance" class="form-control" id="birth" name="birth"/>
			<br>
			<label for="hour">Heure de naissance</label>
			<small class="text-muted"> (Input data-type="hour")</small>
			<input type="text" data-type="hour" value="<?php echo $contact->hour!=0?date('H:i',$contact->hour):''; ?>" data-step="20" placeholder="L'heure de naissance" class="form-control" id="hour" name="hour"/>
			<br>
			<label for="author">Auteur</label>
			<small class="text-muted" data-placement="right" data-tooltip="* data-multiple			:	Autorise l'utilisateur a sélectionner  des entité multiples" data-tooltip="* data-types (default: user) : définis les entité sélectionnables (ex: user,rank)	"> (Input data-type="user")</small>
			<input type="text" data-type="user" data-multiple  data-types="user,rank" value="<?php echo $contact->author; ?>" placeholder="Auteur du contact" class="form-control" id="author" name="author"/>
			<br>
			<label for="picture">Image</label>
			<small class="text-muted"> (Input data-type="image")</small>
			<input type="file" data-type="image" value="<?php echo $contact->picture(); ?>" class="form-control-file" id="picture" name="picture" data-delete="contact_avatar_delete(this)" data-default-src="img/default-avatar.png">
			<br>
			<label for="icon">Icône</label>
			<small class="text-muted"> (Input data-type="icon")</small>
			<span class="icon-chooser contact-icon" id="basic-addon-icon-contact">
            <input id="icon" data-type="icon" name="icon" class="form-control" placeholder="Icône du contact" value="<?php echo !empty($contact->icon) ? $contact->icon : 'fab fa-btc'; ?>" type="text"></span>
			<br>
			<label for="vehicle">Véhicule</label>
			<small class="text-muted" data-placement="right" data-tooltip="* data-depth 			:	nb de profondeur de liste
* data-slug 			:	le slug de la liste mère à afficher
* data-value 			:	la valeur de l'entité  à récup en base
* data-disable-label 	:	cache le label de sous-liste si mentionné">(Select data-type="dictionnary")</small>
			<select data-type="dictionnary" data-slug="vehicles" data-depth="3" data-value="<?php echo $contact->vehicle; ?>" class="form-control select-control" name="vehicle" id="vehicle"></select>



			<label for="vehicle2">Véhicule (tags)</label>
			<small class="text-muted" data-placement="right" data-tooltip="* data-multiple			:	Autorise l'utilisateur a sélectionner  des tag multiples
* data-slug 			:	le slug de la liste mère à afficher">(Select data-type="dictionnary")</small>
			<input type="text" data-type="tag-list" data-slug="vehicles" class="form-control" />


			<label for="country">Pays</label>
			<small class="text-muted">(Select data-type="dictionnary")</small>
			<select data-type="dictionnary" data-slug="countries" data-depth="3" data-id="country" data-value="" class="form-control select-control" name="country" id="country"></select>
			<br>
			<label for="address">Adresse</label>
			<small class="text-muted"> (Input data-type="location")</small>
			<input type="text" data-type="location" data-input-city="#city"  data-input-latitude="#latitude"  value="<?php echo $contact->address; ?>" class="form-control" id="address" name="address"/>
			Ville : <span id="city">...</span><br>
			Latitude : <span id="latitude">...</span>
			<br><br>
			<label for="document">Documents</label>
			<small class="text-muted" data-placement="right" data-tooltip="* data-label 			:	le label affiché dans la zone
* data-delete 			:	méthode de suppression de doc de l'entité 
* data-preview 		:	Affiche l'apercu de l'image si possible
* data-readonly		:       false/true Active désactive la possibilité d'envoyer du fichier
* data-allowed		:	 les extensions de fichier acceptées"> (Div data-type="dropzone")</small>
			<div data-type="dropzone"  data-label="Faites glisser vos documents ici" data-delete="contact_delete_document" data-save="contact_add_document" data-allowed="docx,pdf,txt,jpg,bmp,gif,xlsx,png,iso" class="form-control" id="document" name="document">
				<?php echo json_encode($contact->documents()); ?>
				<!-- Template action custom pour la dropzone -->
				<div class="btn dropzone-custom-button hidden" onclick="alert('Je suis le fichier '+$(this).prev('a').text()+ '. Je vaux '+Math.floor((Math.random() * 10) + 1)+' bitcoins');" title="Une action custom" id="send-offer-button"><i class="fab fa-bitcoin"></i></div>
			</div>
			<br>
			<label for="story">Histoire</label>
			<small class="text-muted"> (Textarea data-type="wysiwyg")</small>
			<textarea data-type="wysiwyg" class="form-control" id="story" name="story"><?php echo $contact->story; ?></textarea>
			<br>
			<label for="login">Login</label>
			<small class="text-muted"> (Simple input texte)</small>
			<input type="text" value="<?php echo $contact->login; ?>" placeholder="Identifiant" class="form-control" id="login" name="login"/>
			<br>
			<label for="password">Password</label>
			<small class="text-muted"> (Input data-type="password")</small>
			<input type="text" data-type="password" data-toggle-event="hover" value="<?php echo $contact->password; ?>" placeholder="Mot de passe" class="form-control" id="password" name="password"/>
			<br>
			<label for="contact">Nom du tuteur :</label>
			<small class="text-muted"> (Div data-type="quickform")</small>
			<div style="display: inline-block;" class="quickform" data-type="quickform" data-title="Ajout rapide de tuteur :" data-loaded="example_quickform_buttons" data-warning="Ajoutez rapidement un tuteur."  data-url="plugin/example/page.quick.example.php"><i class="fas fa-user-plus"></i></div>
			<input type="text" value="" placeholder="Nom du contact" class="form-control" id="contact" name="contact"/>
			<br>
			<label for="label">Donuts</label>
			<small class="text-muted"> (canvas data-type="doughnut")</small>
			<canvas data-type="doughnut" data-values="[1,3,4,7]" data-labels='["fib","on","acci"]' data-colors='["#f39c12","#2980b9","#27ae60"]'></canvas>
			<br>
			<label for="label">Line</label>
			<small class="text-muted"> (canvas data-type="line")</small>
			<canvas data-type="line" data-values="[1,3,4,7]" data-labels='["fib","on","acci"]' data-color='#8e44ad'>Graphique example</canvas>
			<br>
			<label for="label">Bar</label>
			<small class="text-muted"> (canvas data-type="bar")</small>
			<canvas data-type="bar" data-values="[2,3,4,7]" data-labels='["fib","on","acci"]' data-colors='["#f39c12","#2980b9","#27ae60"]'>Graphique example</canvas>
			<br>
			<div>
				<label>Input checkbox</label>
				<small class="text-muted"> (Input data-type="checkbox")</small><br>
				<input type="checkbox" id="checkbox" name="checkbox" data-class="blink_me" data-type="checkbox">
				<label for="checkbox">Ma checkbox 1</label>
			</div>
			<br>
			<div>
				<label>Input radio</label>
				<small class="text-muted"> (Input data-type="radio")</small><br>
				<input type="radio" id="case1" name="my-radio-button" data-type="radio" data-label="Hello"><br>
				<label><input type="radio" id="case2" name="my-radio-button" data-type="radio">Toto</label><br>
				<input type="radio" id="case3" name="my-radio-button" data-type="radio"><label for="case3">Coucou</label><br>
				<input type="radio" name="my-radio-button" data-type="radio"><label>Sans id</label>
			</div>
			<br>
			<label for="label">Tableau d'une liste</label>
			<small class="text-muted"> (div data-type="dictionnary-table")</small>
			<div data-type="dictionnary-table" data-dictionnary="vehicles"></div>
			<br><br>
			<?php if($myFirm->has_plugin('fr.idleman.stripe')) : ?>
				<label for="checkbox">Formulaire de paiement en ligne (via API Stripe)</label>
				<small class="text-muted"> (Div data-type="payment")</small><br>
				<small class="text-muted">Il faut configurer les clés API en config avant de pouvoir réaliser un paiement. (Voir <a href="https://stripe.com/docs/testing#cards" target="_blank">cette page</a> pour des cartes bleues de tests)</small>

				<div data-type="payment" data-action="example_stripe_pay"></div>
			<?php endif; ?>
		</div>
		<div class="col-md-12 text-center noLabel">
			<div class="btn btn-success" onclick="contact_save();"><i class="fas fa-check"></i> Enregistrer</div>
       		<?php if($myUser->can('export', 'read') && $myFirm->has_plugin('fr.idleman.export')) : ?>
			<div style="display: inline-block;" class="offer-btn-export" data-type="export_model" data-callback="contact_export_callback" data-parameters='<?php echo stripslashes(json_encode(array("plugin"=>"example","dataset"=>"contact-sheet","id"=>$contact->id,"destination"=>addslashes('contact'.SLASH.'documents'.SLASH.$contact->id.SLASH)))); ?>'>
				<div class="btn btn-primary"><i class="far fa-file"></i> Export modèle</div>
			</div>
       		<?php endif; ?>

			<br><br>
		</div>
	</form>
</div>