<?php
// This script and data application were generated by AppGini 5.81
// Download AppGini for free from https://bigprof.com/appgini/download/

	/* Configuration */
	/*************************************/

		$pcConfig = array(
			'main' => array(
			),
			'clients' => array(
			),
			'gestionnaires' => array(
			),
			'partenaires' => array(
			),
			'paiements' => array(
			),
			'emetteurs' => array(
			),
			'bieleteries' => array(
			),
			'tarifs' => array(
				'link_bieleterie' => array(
					'parent-table' => 'bieleteries',
					'parent-primary-key' => 'idbieleterie',
					'child-primary-key' => 'idtarif',
					'child-primary-key-index' => 0,
					'tab-label' => 'BILLETERIES <span class="hidden child-label-tarifs child-field-caption">(Link tarif)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/gei (81).png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(2 => 'Passager', 3 => 'Parcours', 4 => 'Compagnie', 5 => 'Provenance', 6 => 'Emetteur', 7 => 'PNR', 8 => 'Billet N&#176;', 9 => 'Prix achat', 10 => 'Commission', 11 => 'Frais service', 12 => 'Net &#224; payer'),
					'display-field-names' => array(2 => 'passager', 3 => 'parcours', 4 => 'compagnie', 5 => 'provenance', 6 => 'emetteur', 7 => 'pnr', 8 => 'numero', 9 => 'prix_achat', 10 => 'commission', 11 => 'frais_service', 12 => 'total'),
					'sortable-fields' => array(0 => '`tarifs`.`idtarif`', 1 => '`bieleteries1`.`link_tarif`', 2 => '`clients1`.`nom_prenom`', 3 => '`parcours1`.`parcour`', 4 => '`compagnies1`.`compagnie`', 5 => '`provenance1`.`provenance`', 6 => 7, 7 => 8, 8 => 9, 9 => '`tarifs`.`prix_achat`', 10 => '`tarifs`.`commission`', 11 => '`tarifs`.`frais_service`', 12 => '`tarifs`.`total`'),
					'records-per-page' => 10,
					'default-sort-by' => 0,
					'default-sort-direction' => 'asc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-tarifs',
					'template-printable' => 'children-tarifs-printable',
					'query' => "SELECT `tarifs`.`idtarif` as 'idtarif', IF(    CHAR_LENGTH(`bieleteries1`.`link_tarif`), CONCAT_WS('',   `bieleteries1`.`link_tarif`), '') as 'link_bieleterie', IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') as 'passager', IF(    CHAR_LENGTH(`parcours1`.`parcour`), CONCAT_WS('',   `parcours1`.`parcour`), '') as 'parcours', IF(    CHAR_LENGTH(`compagnies1`.`compagnie`), CONCAT_WS('',   `compagnies1`.`compagnie`), '') as 'compagnie', IF(    CHAR_LENGTH(`provenance1`.`provenance`), CONCAT_WS('',   `provenance1`.`provenance`), '') as 'provenance', IF(    CHAR_LENGTH(`clients2`.`nom_prenom`), CONCAT_WS('',   `clients2`.`nom_prenom`), '') as 'emetteur', `tarifs`.`pnr` as 'pnr', `tarifs`.`numero` as 'numero', `tarifs`.`prix_achat` as 'prix_achat', `tarifs`.`commission` as 'commission', `tarifs`.`frais_service` as 'frais_service', `tarifs`.`total` as 'total' FROM `tarifs` LEFT JOIN `bieleteries` as bieleteries1 ON `bieleteries1`.`idbieleterie`=`tarifs`.`link_bieleterie` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`tarifs`.`passager` LEFT JOIN `parcours` as parcours1 ON `parcours1`.`idparcour`=`tarifs`.`parcours` LEFT JOIN `compagnies` as compagnies1 ON `compagnies1`.`idcompagnie`=`tarifs`.`compagnie` LEFT JOIN `provenance` as provenance1 ON `provenance1`.`idprovenance`=`tarifs`.`provenance` LEFT JOIN `emetteurs` as emetteurs1 ON `emetteurs1`.`idemetteur`=`tarifs`.`emetteur` LEFT JOIN `clients` as clients2 ON `clients2`.`matricule_client`=`emetteurs1`.`emetteur` "
				),
			),
			'transferts_argent' => array(
			),
			'colis' => array(
			),
			'envois_colis' => array(
				'link_colis' => array(
					'parent-table' => 'colis',
					'parent-primary-key' => 'idcoli',
					'child-primary-key' => 'idenvois_coli',
					'child-primary-key-index' => 0,
					'tab-label' => 'DESCRIPTIONS <span class="hidden child-label-envois_colis child-field-caption">(Link colis)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/lorry.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(2 => 'Description', 3 => 'Destination', 4 => 'Agence', 5 => 'Ville', 6 => 'Prix unitaire', 7 => 'Quantit&#233;', 8 => 'Net &#224; payer', 9 => 'B&#233;n&#233;ficiaire', 10 => 'T&#233;l&#233;phone b&#233;n&#233;ficiaire', 11 => 'NNI b&#233;n&#233;ficiaire', 12 => 'Date de reception', 13 => 'Statut'),
					'display-field-names' => array(2 => 'description', 3 => 'destination', 4 => 'agence', 5 => 'ville', 6 => 'prix_unitaire', 7 => 'qts', 8 => 'prix_total', 9 => 'beneficiaire', 10 => 'telephone_beneficiaire', 11 => 'nni_beneficiaire', 12 => 'date_reception', 13 => 'statut'),
					'sortable-fields' => array(0 => '`envois_colis`.`idenvois_coli`', 1 => '`colis1`.`link_envoi_colis`', 2 => 3, 3 => '`pays1`.`pays`', 4 => '`agences1`.`agence`', 5 => '`villes1`.`ville`', 6 => '`envois_colis`.`prix_unitaire`', 7 => '`envois_colis`.`qts`', 8 => '`envois_colis`.`prix_total`', 9 => '`clients1`.`nom_prenom`', 10 => '`clients1`.`telephone`', 11 => '`clients1`.`nni`', 12 => '`envois_colis`.`date_reception`', 13 => 14, 14 => 15),
					'records-per-page' => 10,
					'default-sort-by' => false,
					'default-sort-direction' => 'asc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-envois_colis',
					'template-printable' => 'children-envois_colis-printable',
					'query' => "SELECT `envois_colis`.`idenvois_coli` as 'idenvois_coli', IF(    CHAR_LENGTH(`colis1`.`link_envoi_colis`), CONCAT_WS('',   `colis1`.`link_envoi_colis`), '') as 'link_colis', `envois_colis`.`description` as 'description', IF(    CHAR_LENGTH(`pays1`.`pays`), CONCAT_WS('',   `pays1`.`pays`), '') as 'destination', IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') as 'agence', IF(    CHAR_LENGTH(`villes1`.`ville`), CONCAT_WS('',   `villes1`.`ville`), '') as 'ville', `envois_colis`.`prix_unitaire` as 'prix_unitaire', `envois_colis`.`qts` as 'qts', `envois_colis`.`prix_total` as 'prix_total', IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') as 'beneficiaire', IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') as 'telephone_beneficiaire', IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') as 'nni_beneficiaire', if(`envois_colis`.`date_reception`,date_format(`envois_colis`.`date_reception`,'%d/%m/%Y'),'') as 'date_reception', `envois_colis`.`statut` as 'statut', `envois_colis`.`observation` as 'observation' FROM `envois_colis` LEFT JOIN `colis` as colis1 ON `colis1`.`idcoli`=`envois_colis`.`link_colis` LEFT JOIN `pays` as pays1 ON `pays1`.`idpays`=`envois_colis`.`destination` LEFT JOIN `agences` as agences1 ON `agences1`.`idagence`=`envois_colis`.`agence` LEFT JOIN `villes` as villes1 ON `villes1`.`idville`=`envois_colis`.`ville` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`envois_colis`.`beneficiaire` "
				),
			),
			'parc_auto' => array(
			),
			'location_vh' => array(
			),
			'liste_location' => array(
				'link_location' => array(
					'parent-table' => 'location_vh',
					'parent-primary-key' => 'idlocation',
					'child-primary-key' => 'idlocations',
					'child-primary-key-index' => 0,
					'tab-label' => 'LISTE LOCATION VH <span class="hidden child-label-liste_location child-field-caption">(Link location)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/small_car.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(2 => 'Date location', 3 => 'Date fin location', 4 => 'Vehicule', 5 => 'Model', 6 => 'Type', 7 => 'Prix unitaire', 8 => 'Qts', 9 => 'Prix total'),
					'display-field-names' => array(2 => 'date_location', 3 => 'date_fin_location', 4 => 'vehicule', 5 => 'model', 6 => 'type', 7 => 'prix_unitaire', 8 => 'qts', 9 => 'prix_total'),
					'sortable-fields' => array(0 => '`liste_location`.`idlocations`', 1 => '`location_vh1`.`link_liste`', 2 => '`liste_location`.`date_location`', 3 => '`liste_location`.`date_fin_location`', 4 => 5, 5 => '`models2`.`model`', 6 => 7, 7 => '`liste_location`.`prix_unitaire`', 8 => '`liste_location`.`qts`', 9 => '`liste_location`.`prix_total`', 10 => 11),
					'records-per-page' => 10,
					'default-sort-by' => 2,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-liste_location',
					'template-printable' => 'children-liste_location-printable',
					'query' => "SELECT `liste_location`.`idlocations` as 'idlocations', IF(    CHAR_LENGTH(`location_vh1`.`link_liste`), CONCAT_WS('',   `location_vh1`.`link_liste`), '') as 'link_location', if(`liste_location`.`date_location`,date_format(`liste_location`.`date_location`,'%d/%m/%Y'),'') as 'date_location', if(`liste_location`.`date_fin_location`,date_format(`liste_location`.`date_fin_location`,'%d/%m/%Y'),'') as 'date_fin_location', IF(    CHAR_LENGTH(`models1`.`marque`), CONCAT_WS('',   `models1`.`marque`), '') as 'vehicule', IF(    CHAR_LENGTH(`models2`.`model`), CONCAT_WS('',   `models2`.`model`), '') as 'model', `liste_location`.`type` as 'type', `liste_location`.`prix_unitaire` as 'prix_unitaire', `liste_location`.`qts` as 'qts', `liste_location`.`prix_total` as 'prix_total', `liste_location`.`observation` as 'observation' FROM `liste_location` LEFT JOIN `location_vh` as location_vh1 ON `location_vh1`.`idlocation`=`liste_location`.`link_location` LEFT JOIN `parc_auto` as parc_auto1 ON `parc_auto1`.`idparc`=`liste_location`.`vehicule` LEFT JOIN `models` as models1 ON `models1`.`idmodel`=`parc_auto1`.`marque` LEFT JOIN `models` as models2 ON `models2`.`idmodel`=`liste_location`.`model` "
				),
				'vehicule' => array(
					'parent-table' => 'parc_auto',
					'parent-primary-key' => 'idparc',
					'child-primary-key' => 'idlocations',
					'child-primary-key-index' => 0,
					'tab-label' => 'Location vehicule <span class="hidden child-label-liste_location child-field-caption">(Vehicule)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/small_car.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(2 => 'Date location', 3 => 'Date fin location', 4 => 'Vehicule', 5 => 'Model', 6 => 'Type', 7 => 'Prix unitaire', 8 => 'Qts', 9 => 'Prix total'),
					'display-field-names' => array(2 => 'date_location', 3 => 'date_fin_location', 4 => 'vehicule', 5 => 'model', 6 => 'type', 7 => 'prix_unitaire', 8 => 'qts', 9 => 'prix_total'),
					'sortable-fields' => array(0 => '`liste_location`.`idlocations`', 1 => '`location_vh1`.`link_liste`', 2 => '`liste_location`.`date_location`', 3 => '`liste_location`.`date_fin_location`', 4 => 5, 5 => '`models2`.`model`', 6 => 7, 7 => '`liste_location`.`prix_unitaire`', 8 => '`liste_location`.`qts`', 9 => '`liste_location`.`prix_total`', 10 => 11),
					'records-per-page' => 10,
					'default-sort-by' => 2,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-liste_location',
					'template-printable' => 'children-liste_location-printable',
					'query' => "SELECT `liste_location`.`idlocations` as 'idlocations', IF(    CHAR_LENGTH(`location_vh1`.`link_liste`), CONCAT_WS('',   `location_vh1`.`link_liste`), '') as 'link_location', if(`liste_location`.`date_location`,date_format(`liste_location`.`date_location`,'%d/%m/%Y'),'') as 'date_location', if(`liste_location`.`date_fin_location`,date_format(`liste_location`.`date_fin_location`,'%d/%m/%Y'),'') as 'date_fin_location', IF(    CHAR_LENGTH(`models1`.`marque`), CONCAT_WS('',   `models1`.`marque`), '') as 'vehicule', IF(    CHAR_LENGTH(`models2`.`model`), CONCAT_WS('',   `models2`.`model`), '') as 'model', `liste_location`.`type` as 'type', `liste_location`.`prix_unitaire` as 'prix_unitaire', `liste_location`.`qts` as 'qts', `liste_location`.`prix_total` as 'prix_total', `liste_location`.`observation` as 'observation' FROM `liste_location` LEFT JOIN `location_vh` as location_vh1 ON `location_vh1`.`idlocation`=`liste_location`.`link_location` LEFT JOIN `parc_auto` as parc_auto1 ON `parc_auto1`.`idparc`=`liste_location`.`vehicule` LEFT JOIN `models` as models1 ON `models1`.`idmodel`=`parc_auto1`.`marque` LEFT JOIN `models` as models2 ON `models2`.`idmodel`=`liste_location`.`model` "
				),
			),
			'fonctions' => array(
			),
			'agences' => array(
			),
			'villes' => array(
			),
			'banques' => array(
			),
			'type_paiements' => array(
			),
			'compagnies' => array(
			),
			'statuts' => array(
			),
			'visas' => array(
			),
			'oumras' => array(
			),
			'assurances' => array(
			),
			'type_visas' => array(
			),
			'facture' => array(
			),
			'detail_facture' => array(
				'factureid' => array(
					'parent-table' => 'facture',
					'parent-primary-key' => 'idfacture',
					'child-primary-key' => 'dfid',
					'child-primary-key-index' => 0,
					'tab-label' => 'LISTE DES FACTURES <span class="hidden child-label-detail_facture child-field-caption">(Factureid)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/blogs.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(2 => 'Designation', 3 => 'Quantite', 4 => 'Prix unitaire', 5 => 'Total'),
					'display-field-names' => array(2 => 'designation', 3 => 'quantite', 4 => 'prixunitaire', 5 => 'total'),
					'sortable-fields' => array(0 => '`detail_facture`.`dfid`', 1 => '`facture1`.`idfacture`', 2 => '`designations1`.`designation`', 3 => '`detail_facture`.`quantite`', 4 => '`detail_facture`.`prixunitaire`', 5 => '`detail_facture`.`total`'),
					'records-per-page' => 10,
					'default-sort-by' => false,
					'default-sort-direction' => 'asc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-detail_facture',
					'template-printable' => 'children-detail_facture-printable',
					'query' => "SELECT `detail_facture`.`dfid` as 'dfid', IF(    CHAR_LENGTH(`facture1`.`idfacture`), CONCAT_WS('',   `facture1`.`idfacture`), '') as 'factureid', IF(    CHAR_LENGTH(`designations1`.`designation`), CONCAT_WS('',   `designations1`.`designation`), '') as 'designation', `detail_facture`.`quantite` as 'quantite', `detail_facture`.`prixunitaire` as 'prixunitaire', `detail_facture`.`total` as 'total' FROM `detail_facture` LEFT JOIN `facture` as facture1 ON `facture1`.`idfacture`=`detail_facture`.`factureid` LEFT JOIN `designations` as designations1 ON `designations1`.`iddesignation`=`detail_facture`.`designation` "
				),
			),
			'recettes' => array(
			),
			'depenses' => array(
			),
			'caisse' => array(
			),
			'tresorerie_caisse' => array(
			),
			'tresorerie_items' => array(
				'link_out' => array(
					'parent-table' => 'tresorerie_caisse',
					'parent-primary-key' => 'idtresorerie_caisse',
					'child-primary-key' => 'idtresorerie_item',
					'child-primary-key-index' => 0,
					'tab-label' => 'Tresorerie items <span class="hidden child-label-tresorerie_items child-field-caption">(Link out)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/marega.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(0 => 'N&#176; d\'ordre', 2 => 'P. Justificative', 3 => 'Libelles', 4 => 'Montant', 5 => 'Commission agence', 6 => 'Net compagnie'),
					'display-field-names' => array(0 => 'idtresorerie_item', 2 => 'justificatif', 3 => 'libelles', 4 => 'montant', 5 => 'commission_agence', 6 => 'net_compagnie'),
					'sortable-fields' => array(0 => '`tresorerie_items`.`idtresorerie_item`', 1 => '`tresorerie_caisse1`.`link_in`', 2 => 3, 3 => 4, 4 => '`tresorerie_items`.`montant`', 5 => '`tresorerie_items`.`commission_agence`', 6 => '`tresorerie_items`.`net_compagnie`', 7 => 8),
					'records-per-page' => 10,
					'default-sort-by' => 0,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-tresorerie_items',
					'template-printable' => 'children-tresorerie_items-printable',
					'query' => "SELECT `tresorerie_items`.`idtresorerie_item` as 'idtresorerie_item', IF(    CHAR_LENGTH(`tresorerie_caisse1`.`link_in`), CONCAT_WS('',   `tresorerie_caisse1`.`link_in`), '') as 'link_out', `tresorerie_items`.`justificatif` as 'justificatif', `tresorerie_items`.`libelles` as 'libelles', `tresorerie_items`.`montant` as 'montant', `tresorerie_items`.`commission_agence` as 'commission_agence', `tresorerie_items`.`net_compagnie` as 'net_compagnie', `tresorerie_items`.`observations` as 'observations' FROM `tresorerie_items` LEFT JOIN `tresorerie_caisse` as tresorerie_caisse1 ON `tresorerie_caisse1`.`idtresorerie_caisse`=`tresorerie_items`.`link_out` "
				),
			),
			'piece_reglements' => array(
			),
			'autorisation_change' => array(
			),
			'bon_passage' => array(
			),
			'fiches_changes' => array(
			),
			'fiches_changes_items' => array(
				'link_out' => array(
					'parent-table' => 'fiches_changes',
					'parent-primary-key' => 'idfichechange',
					'child-primary-key' => 'idfiche_change_item',
					'child-primary-key-index' => 0,
					'tab-label' => 'LISTE FICHES DE CHANGES <span class="hidden child-label-fiches_changes_items child-field-caption">(Link out)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/marega.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(0 => 'N&#176; d\'ordre', 2 => 'Nom et Pr&#233;nom', 3 => 'N&#176; Identit&#233;', 4 => 'Montant', 5 => 'Devise', 6 => 'Achats', 7 => 'Ventes'),
					'display-field-names' => array(0 => 'idfiche_change_item', 2 => 'nom_prenom', 3 => 'num_identite', 4 => 'montant', 5 => 'devises', 6 => 'achats', 7 => 'ventes'),
					'sortable-fields' => array(0 => '`fiches_changes_items`.`idfiche_change_item`', 1 => '`fiches_changes1`.`link_in`', 2 => '`clients1`.`nom_prenom`', 3 => '`clients1`.`nni`', 4 => '`fiches_changes_items`.`montant`', 5 => '`devise1`.`devise`', 6 => '`fiches_changes_items`.`achats`', 7 => '`fiches_changes_items`.`ventes`', 8 => 9),
					'records-per-page' => 10,
					'default-sort-by' => 0,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-fiches_changes_items',
					'template-printable' => 'children-fiches_changes_items-printable',
					'query' => "SELECT `fiches_changes_items`.`idfiche_change_item` as 'idfiche_change_item', IF(    CHAR_LENGTH(`fiches_changes1`.`link_in`), CONCAT_WS('',   `fiches_changes1`.`link_in`), '') as 'link_out', IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') as 'nom_prenom', IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') as 'num_identite', `fiches_changes_items`.`montant` as 'montant', IF(    CHAR_LENGTH(`devise1`.`devise`), CONCAT_WS('',   `devise1`.`devise`), '') as 'devises', `fiches_changes_items`.`achats` as 'achats', `fiches_changes_items`.`ventes` as 'ventes', `fiches_changes_items`.`observations` as 'observations' FROM `fiches_changes_items` LEFT JOIN `fiches_changes` as fiches_changes1 ON `fiches_changes1`.`idfichechange`=`fiches_changes_items`.`link_out` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`fiches_changes_items`.`nom_prenom` LEFT JOIN `devise` as devise1 ON `devise1`.`iddevise`=`fiches_changes_items`.`devises` "
				),
			),
			'caisse_journaliere' => array(
			),
			'item_caisse_journaliere' => array(
				'link_out' => array(
					'parent-table' => 'caisse_journaliere',
					'parent-primary-key' => 'idcaisse_journaliere',
					'child-primary-key' => 'iditem_caisse_journaliere',
					'child-primary-key-index' => 1,
					'tab-label' => 'Item caisse journaliere <span class="hidden child-label-item_caisse_journaliere child-field-caption">(Link out)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/marega.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'N&#176; Ordre', 2 => 'P. Justificative', 3 => 'Nom et Pr&#233;nom', 4 => 'Destination', 5 => 'Compagnie/Agence', 6 => 'Prix HT', 7 => 'Commission', 8 => 'Prix TTC'),
					'display-field-names' => array(1 => 'iditem_caisse_journaliere', 2 => 'justificatif', 3 => 'nom_prenom', 4 => 'destination', 5 => 'compagnie', 6 => 'prix_ht', 7 => 'commission', 8 => 'prix_ttc'),
					'sortable-fields' => array(0 => '`caisse_journaliere1`.`link_in`', 1 => '`item_caisse_journaliere`.`iditem_caisse_journaliere`', 2 => 3, 3 => 4, 4 => 5, 5 => 6, 6 => '`item_caisse_journaliere`.`prix_ht`', 7 => '`item_caisse_journaliere`.`commission`', 8 => '`item_caisse_journaliere`.`prix_ttc`', 9 => 10),
					'records-per-page' => 10,
					'default-sort-by' => false,
					'default-sort-direction' => 'asc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-item_caisse_journaliere',
					'template-printable' => 'children-item_caisse_journaliere-printable',
					'query' => "SELECT IF(    CHAR_LENGTH(`caisse_journaliere1`.`link_in`), CONCAT_WS('',   `caisse_journaliere1`.`link_in`), '') as 'link_out', `item_caisse_journaliere`.`iditem_caisse_journaliere` as 'iditem_caisse_journaliere', `item_caisse_journaliere`.`justificatif` as 'justificatif', `item_caisse_journaliere`.`nom_prenom` as 'nom_prenom', `item_caisse_journaliere`.`destination` as 'destination', `item_caisse_journaliere`.`compagnie` as 'compagnie', REPLACE(FORMAT(`item_caisse_journaliere`.`prix_ht`, 0), ',', ' ') as 'prix_ht', `item_caisse_journaliere`.`commission` as 'commission', REPLACE(FORMAT(`item_caisse_journaliere`.`prix_ttc`, 0), ',', ' ') as 'prix_ttc', `item_caisse_journaliere`.`observations` as 'observations' FROM `item_caisse_journaliere` LEFT JOIN `caisse_journaliere` as caisse_journaliere1 ON `caisse_journaliere1`.`idcaisse_journaliere`=`item_caisse_journaliere`.`link_out` "
				),
			),
			'models' => array(
			),
			'natures' => array(
			),
			'services' => array(
			),
			'liens' => array(
			),
			'types_client' => array(
			),
			'cartes_fidelite' => array(
			),
			'designations' => array(
			),
			'parcours' => array(
			),
			'pays' => array(
			),
			'provenance' => array(
			),
			'programmes' => array(
			),
			'justificatifs' => array(
			),
			'devise' => array(
			),
			'intermediares' => array(
			),
			'formule' => array(
			),
			'operations' => array(
			),
			'pointages' => array(
				'nom_prenom' => array(
					'parent-table' => 'clients',
					'parent-primary-key' => 'matricule_client',
					'child-primary-key' => 'idpointage',
					'child-primary-key-index' => 0,
					'tab-label' => 'Pointages <span class="hidden child-label-pointages child-field-caption">(Nom prenom)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/timesheet.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'Date', 2 => 'Nom prenom', 3 => 'Agence', 4 => 'Fonction', 5 => 'Arrivee', 6 => 'Depart'),
					'display-field-names' => array(1 => 'date', 2 => 'nom_prenom', 3 => 'agence', 4 => 'fonction', 5 => 'arrivee', 6 => 'depart'),
					'sortable-fields' => array(0 => '`pointages`.`idpointage`', 1 => '`pointages`.`date`', 2 => '`clients1`.`nom_prenom`', 3 => 4, 4 => 5, 5 => '`pointages`.`arrivee`', 6 => '`pointages`.`depart`', 7 => 8),
					'records-per-page' => 10,
					'default-sort-by' => 1,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-pointages',
					'template-printable' => 'children-pointages-printable',
					'query' => "SELECT `pointages`.`idpointage` as 'idpointage', if(`pointages`.`date`,date_format(`pointages`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') as 'nom_prenom', IF(    CHAR_LENGTH(`agences1`.`agence`), CONCAT_WS('',   `agences1`.`agence`), '') as 'agence', IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') as 'fonction', `pointages`.`arrivee` as 'arrivee', `pointages`.`depart` as 'depart', `pointages`.`obs` as 'obs' FROM `pointages` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`pointages`.`nom_prenom` LEFT JOIN `agences` as agences1 ON `agences1`.`idagence`=`clients1`.`agence` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`clients1`.`fonction` "
				),
			),
			'fichiers_partages' => array(
			),
			'note_de_service' => array(
			),
		);

	/*************************************/
	/* End of configuration */


	$currDir = dirname(__FILE__);
	include("{$currDir}/defaultLang.php");
	include("{$currDir}/language.php");
	include("{$currDir}/lib.php");
	@header('Content-Type: text/html; charset=' . datalist_db_encoding);

	handle_maintenance();

	/**
	* dynamic configuration based on current user's permissions
	* $userPCConfig array is populated only with parent tables where the user has access to
	* at least one child table
	*/
	$userPCConfig = array();
	foreach($pcConfig as $pcChildTable => $ChildrenLookups) {
		$permChild = getTablePermissions($pcChildTable);
		if($permChild[2]) { // user can view records of the child table, so proceed to check children lookups
			foreach($ChildrenLookups as $ChildLookupField => $ChildConfig) {
				$permParent = getTablePermissions($ChildConfig['parent-table']);
				if($permParent[2]) { // user can view records of parent table
					$userPCConfig[$pcChildTable][$ChildLookupField] = $pcConfig[$pcChildTable][$ChildLookupField];
					// show add new only if configured above AND the user has insert permission
					if($permChild[1] && $pcConfig[$pcChildTable][$ChildLookupField]['display-add-new']) {
						$userPCConfig[$pcChildTable][$ChildLookupField]['display-add-new'] = true;
					}else{
						$userPCConfig[$pcChildTable][$ChildLookupField]['display-add-new'] = false;
					}
				}
			}
		}
	}

	/* Receive, UTF-convert, and validate parameters */
	$ParentTable = $_REQUEST['ParentTable']; // needed only with operation=show-children, will be validated in the processing code
	$ChildTable = $_REQUEST['ChildTable'];
		if(!in_array($ChildTable, array_keys($userPCConfig))) {
			/* defaults to first child table in config array if not provided */
			$ChildTable = current(array_keys($userPCConfig));
		}
		if(!$ChildTable) { die('<!-- No tables accessible to current user -->'); }
	$SelectedID = strip_tags($_REQUEST['SelectedID']);
	$ChildLookupField = $_REQUEST['ChildLookupField'];
		if(!in_array($ChildLookupField, array_keys($userPCConfig[$ChildTable]))) {
			/* defaults to first lookup in current child config array if not provided */
			$ChildLookupField = current(array_keys($userPCConfig[$ChildTable]));
		}
	$Page = intval($_REQUEST['Page']);
		if($Page < 1) {
			$Page = 1;
		}
	$SortBy = ($_REQUEST['SortBy'] != '' ? abs(intval($_REQUEST['SortBy'])) : false);
		if(!in_array($SortBy, array_keys($userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields']), true)) {
			$SortBy = $userPCConfig[$ChildTable][$ChildLookupField]['default-sort-by'];
		}
	$SortDirection = strtolower($_REQUEST['SortDirection']);
		if(!in_array($SortDirection, array('asc', 'desc'))) {
			$SortDirection = $userPCConfig[$ChildTable][$ChildLookupField]['default-sort-direction'];
		}
	$Operation = strtolower($_REQUEST['Operation']);
		if(!in_array($Operation, array('get-records', 'show-children', 'get-records-printable', 'show-children-printable'))) {
			$Operation = 'get-records';
		}

	/* process requested operation */
	switch($Operation) {
		/************************************************/
		case 'show-children':
			/* populate HTML and JS content with children tabs */
			$tabLabels = $tabPanels = $tabLoaders = '';
			foreach($userPCConfig as $ChildTable => $childLookups) {
				foreach($childLookups as $ChildLookupField => $childConfig) {
					if($childConfig['parent-table'] == $ParentTable) {
						$TableIcon = ($childConfig['table-icon'] ? "<img src=\"{$childConfig['table-icon']}\" border=\"0\" />" : '');
						$tabLabels .= sprintf('<li%s><a href="#panel_%s-%s" id="tab_%s-%s" data-toggle="tab">%s%s</a></li>' . "\n\t\t\t\t\t",($tabLabels ? '' : ' class="active"'), $ChildTable, $ChildLookupField, $ChildTable, $ChildLookupField, $TableIcon, $childConfig['tab-label']);
						$tabPanels .= sprintf('<div id="panel_%s-%s" class="tab-pane%s"><img src="loading.gif" align="top" />%s</div>' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, ($tabPanels ? '' : ' active'), $Translation['Loading ...']);
						$tabLoaders .= sprintf('post("parent-children.php", { ChildTable: "%s", ChildLookupField: "%s", SelectedID: "%s", Page: 1, SortBy: "", SortDirection: "", Operation: "get-records" }, "panel_%s-%s");' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, addslashes($SelectedID), $ChildTable, $ChildLookupField);
					}
				}
			}

			if(!$tabLabels) { die('<!-- no children of current parent table are accessible to current user -->'); }
			?>
			<div id="children-tabs">
				<ul class="nav nav-tabs">
					<?php echo $tabLabels; ?>
				</ul>
				<span id="pc-loading"></span>
			</div>
			<div class="tab-content"><?php echo $tabPanels; ?></div>

			<script>
				$j(function() {
					/* for iOS, avoid loading child tabs in modals */
					var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
					var embedded = ($j('.navbar').length == 0);
					if(iOS && embedded) {
						$j('#children-tabs').next('.tab-content').remove();
						$j('#children-tabs').remove();
						return;
					}

					/* ajax loading of each tab's contents */
					<?php echo $tabLoaders; ?>

					/* show child field caption on tab title in case the same child table appears more than once */
					$j('.child-field-caption').each(function() {
						var clss = $j(this).attr('class').split(/\s+/).reduce(function(rc, cc) {
							return (cc.match(/child-label-.*/) ? '.' + cc : rc);
						}, '');

						// if class occurs more than once, remove .hidden
						if($j(clss).length > 1) $j(clss).removeClass('hidden');
					})
				})
			</script>
			<?php
			break;

		/************************************************/
		case 'show-children-printable':
			/* populate HTML and JS content with children buttons */
			$tabLabels = $tabPanels = $tabLoaders = '';
			foreach($userPCConfig as $ChildTable => $childLookups) {
				foreach($childLookups as $ChildLookupField => $childConfig) {
					if($childConfig['parent-table'] == $ParentTable) {
						$TableIcon = ($childConfig['table-icon'] ? "<img src=\"{$childConfig['table-icon']}\" border=\"0\" />" : '');
						$tabLabels .= sprintf('<button type="button" class="btn btn-default" data-target="#panel_%s-%s" id="tab_%s-%s" data-toggle="collapse">%s %s</button>' . "\n\t\t\t\t\t", $ChildTable, $ChildLookupField, $ChildTable, $ChildLookupField, $TableIcon, $childConfig['tab-label']);
						$tabPanels .= sprintf('<div id="panel_%s-%s" class="collapse"><img src="loading.gif" align="top" />%s</div>' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, $Translation['Loading ...']);
						$tabLoaders .= sprintf('post("parent-children.php", { ChildTable: "%s", ChildLookupField: "%s", SelectedID: "%s", Page: 1, SortBy: "", SortDirection: "", Operation: "get-records-printable" }, "panel_%s-%s");' . "\n\t\t\t\t", $ChildTable, $ChildLookupField, addslashes($SelectedID), $ChildTable, $ChildLookupField);
					}
				}
			}

			if(!$tabLabels) { die('<!-- no children of current parent table are accessible to current user -->'); }
			?>
			<div id="children-tabs" class="hidden-print">
				<div class="btn-group btn-group-lg">
					<?php echo $tabLabels; ?>
				</div>
				<span id="pc-loading"></span>
			</div>
			<div class="vspacer-lg"><?php echo $tabPanels; ?></div>

			<script>
				$j(function() {
					/* for iOS, avoid loading child tabs in modals */
					var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
					var embedded = ($j('.navbar').length == 0);
					if(iOS && embedded) {
						$j('#children-tabs').next('.tab-content').remove();
						$j('#children-tabs').remove();
						return;
					}

					/* ajax loading of each tab's contents */
					<?php echo $tabLoaders; ?>
				})
			</script>
			<?php
			break;

		/************************************************/
		case 'get-records-printable':
		default: /* default is 'get-records' */

			if($Operation == 'get-records-printable') {
				$userPCConfig[$ChildTable][$ChildLookupField]['records-per-page'] = 2000;
			}

			// build the user permissions limiter
			$permissionsWhere = $permissionsJoin = '';
			$permChild = getTablePermissions($ChildTable);
			if($permChild[2] == 1) { // user can view only his own records
				$permissionsWhere = "`$ChildTable`.`{$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key']}`=`membership_userrecords`.`pkValue` AND `membership_userrecords`.`tableName`='$ChildTable' AND LCASE(`membership_userrecords`.`memberID`)='".getLoggedMemberID()."'";
			}elseif($permChild[2] == 2) { // user can view only his group's records
				$permissionsWhere = "`$ChildTable`.`{$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key']}`=`membership_userrecords`.`pkValue` AND `membership_userrecords`.`tableName`='$ChildTable' AND `membership_userrecords`.`groupID`='".getLoggedGroupID()."'";
			}elseif($permChild[2] == 3) { // user can view all records
				/* that's the only case remaining ... no need to modify the query in this case */
			}
			$permissionsJoin = ($permissionsWhere ? ", `membership_userrecords`" : '');

			// build the count query
			$forcedWhere = $userPCConfig[$ChildTable][$ChildLookupField]['forced-where'];
			$query = 
				preg_replace('/^select .* from /i', 'SELECT count(1) FROM ', $userPCConfig[$ChildTable][$ChildLookupField]['query']) .
				$permissionsJoin . " WHERE " .
				($permissionsWhere ? "( $permissionsWhere )" : "( 1=1 )") . " AND " .
				($forcedWhere ? "( $forcedWhere )" : "( 2=2 )") . " AND " .
				"`$ChildTable`.`$ChildLookupField`='" . makeSafe($SelectedID) . "'";
			$totalMatches = sqlValue($query);

			// make sure $Page is <= max pages
			$maxPage = ceil($totalMatches / $userPCConfig[$ChildTable][$ChildLookupField]['records-per-page']);
			if($Page > $maxPage) { $Page = $maxPage; }

			// initiate output data array
			$data = array(
				'config' => $userPCConfig[$ChildTable][$ChildLookupField],
				'parameters' => array(
					'ChildTable' => $ChildTable,
					'ChildLookupField' => $ChildLookupField,
					'SelectedID' => $SelectedID,
					'Page' => $Page,
					'SortBy' => $SortBy,
					'SortDirection' => $SortDirection,
					'Operation' => $Operation
				),
				'records' => array(),
				'totalMatches' => $totalMatches
			);

			// build the data query
			if($totalMatches) { // if we have at least one record, proceed with fetching data
				$startRecord = $userPCConfig[$ChildTable][$ChildLookupField]['records-per-page'] * ($Page - 1);
				$data['query'] = 
					$userPCConfig[$ChildTable][$ChildLookupField]['query'] .
					$permissionsJoin . " WHERE " .
					($permissionsWhere ? "( $permissionsWhere )" : "( 1=1 )") . " AND " .
					($forcedWhere ? "( $forcedWhere )" : "( 2=2 )") . " AND " .
					"`$ChildTable`.`$ChildLookupField`='" . makeSafe($SelectedID) . "'" . 
					($SortBy !== false && $userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields'][$SortBy] ? " ORDER BY {$userPCConfig[$ChildTable][$ChildLookupField]['sortable-fields'][$SortBy]} $SortDirection" : '') .
					" LIMIT $startRecord, {$userPCConfig[$ChildTable][$ChildLookupField]['records-per-page']}";
				$res = sql($data['query'], $eo);
				while($row = db_fetch_row($res)) {
					$data['records'][$row[$userPCConfig[$ChildTable][$ChildLookupField]['child-primary-key-index']]] = $row;
				}
			}else{ // if no matching records
				$startRecord = 0;
			}

			if($Operation == 'get-records-printable') {
				$response = loadView($userPCConfig[$ChildTable][$ChildLookupField]['template-printable'], $data);
			}else{
				$response = loadView($userPCConfig[$ChildTable][$ChildLookupField]['template'], $data);
			}

			// change name space to ensure uniqueness
			$uniqueNameSpace = $ChildTable.ucfirst($ChildLookupField).'GetRecords';
			echo str_replace("{$ChildTable}GetChildrenRecordsList", $uniqueNameSpace, $response);
		/************************************************/
	}
