<?php
	$rdata = array_map('to_utf8', array_map('nl2br', array_map('html_attr_tags_ok', $rdata)));
	$jdata = array_map('to_utf8', array_map('nl2br', array_map('html_attr_tags_ok', $jdata)));
?>
<script>
	$j(function() {
		var tn = 'gestion_transactions';

		/* data for selected record, or defaults if none is selected */
		var data = {
			matricule: <?php echo json_encode($jdata['matricule']); ?>,
			avec_entete: <?php echo json_encode(array('id' => $rdata['avec_entete'], 'value' => $rdata['avec_entete'], 'text' => $jdata['avec_entete'])); ?>,
			rs: <?php echo json_encode($jdata['rs']); ?>,
			nom_prenom: <?php echo json_encode(array('id' => $rdata['nom_prenom'], 'value' => $rdata['nom_prenom'], 'text' => $jdata['nom_prenom'])); ?>,
			adclient: <?php echo json_encode($jdata['adclient']); ?>,
			telclient: <?php echo json_encode($jdata['telclient']); ?>,
			emclient: <?php echo json_encode($jdata['emclient']); ?>,
			raison_sociale: <?php echo json_encode($jdata['raison_sociale']); ?>,
			devise: <?php echo json_encode($jdata['devise']); ?>,
			logo: (<?php echo strlen($jdata['logo']); ?> > 0 ? '<a href="<?php echo $Translation['ImageFolder'] . addslashes(str_replace(array("\r", "\n"), '', $jdata['logo'])); ?>" data-lightbox="gestion_transactions_dv"><img src="thumbnail.php?i=<?php echo urlencode($jdata['logo']); ?>&t=entete&f=logo&v=dv" class="img-thumbnail"></a>' : '<img src="photo.gif" class="img-thumbnail">'),
			description: <?php echo json_encode($jdata['description']); ?>,
			adresse: <?php echo json_encode($jdata['adresse']); ?>,
			telephone: <?php echo json_encode($jdata['telephone']); ?>,
			whatsapp: <?php echo json_encode($jdata['whatsapp']); ?>,
			email: <?php echo json_encode($jdata['email']); ?>,
			site_web: <?php echo json_encode($jdata['site_web']); ?>,
			bp: <?php echo json_encode($jdata['bp']); ?>,
			footer_3: <?php echo json_encode($jdata['footer_3']); ?>,
			notice: <?php echo json_encode($jdata['notice']); ?>,
			signataire: <?php echo json_encode($jdata['signataire']); ?>
		};

		/* initialize or continue using AppGini.cache for the current table */
		AppGini.cache = AppGini.cache || {};
		AppGini.cache[tn] = AppGini.cache[tn] || AppGini.ajaxCache();
		var cache = AppGini.cache[tn];

		/* saved value for avec_entete */
		cache.addCheck(function(u, d) {
			if(u != 'ajax_combo.php') return false;
			if(d.t == tn && d.f == 'avec_entete' && d.id == data.avec_entete.id)
				return { results: [ data.avec_entete ], more: false, elapsed: 0.01 };
			return false;
		});

		/* saved value for avec_entete autofills */
		cache.addCheck(function(u, d) {
			if(u != tn + '_autofill.php') return false;

			for(var rnd in d) if(rnd.match(/^rnd/)) break;

			if(d.mfk == 'avec_entete' && d.id == data.avec_entete.id) {
				$j('#rs' + d[rnd]).html(data.rs);
				$j('#devise' + d[rnd]).html(data.devise);
				$j('#logo' + d[rnd]).html(data.logo);
				$j('#description' + d[rnd]).html(data.description);
				$j('#adresse' + d[rnd]).html(data.adresse);
				$j('#telephone' + d[rnd]).html(data.telephone);
				$j('#whatsapp' + d[rnd]).html(data.whatsapp);
				$j('#email' + d[rnd]).html(data.email);
				$j('#site_web' + d[rnd]).html(data.site_web);
				$j('#bp' + d[rnd]).html(data.bp);
				$j('#footer_3' + d[rnd]).html(data.footer_3);
				$j('#notice' + d[rnd]).html(data.notice);
				$j('#signataire' + d[rnd]).html(data.signataire);
				return true;
			}

			return false;
		});

		/* saved value for nom_prenom */
		cache.addCheck(function(u, d) {
			if(u != 'ajax_combo.php') return false;
			if(d.t == tn && d.f == 'nom_prenom' && d.id == data.nom_prenom.id)
				return { results: [ data.nom_prenom ], more: false, elapsed: 0.01 };
			return false;
		});

		/* saved value for nom_prenom autofills */
		cache.addCheck(function(u, d) {
			if(u != tn + '_autofill.php') return false;

			for(var rnd in d) if(rnd.match(/^rnd/)) break;

			if(d.mfk == 'nom_prenom' && d.id == data.nom_prenom.id) {
				$j('#matricule' + d[rnd]).html(data.matricule);
				$j('#adclient' + d[rnd]).html(data.adclient);
				$j('#telclient' + d[rnd]).html(data.telclient);
				$j('#emclient' + d[rnd]).html(data.emclient);
				$j('#raison_sociale' + d[rnd]).html(data.raison_sociale);
				return true;
			}

			return false;
		});

		cache.start();
	});
</script>

