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

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

		$pcConfig = array(
			'main' => array(   
			),
			'clients' => array(   
			),
			'comptes' => array(   
				'code' => array(   
					'parent-table' => 'clients',
					'parent-primary-key' => 'idclient',
					'child-primary-key' => 'idcompte',
					'child-primary-key-index' => 1,
					'tab-label' => 'Comptes <span class="hidden child-label-comptes child-field-caption">(CODE CLIENT)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/folder_user.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(0 => 'CODE CLIENT', 1 => 'N&#176;COMPTE', 2 => 'TITULAIRE', 3 => 'PHONE', 4 => 'VERSEMENTS', 5 => 'RETRAITS', 6 => 'SOLDE', 7 => 'NOTE'),
					'display-field-names' => array(0 => 'code', 1 => 'idcompte', 2 => 'titulaire', 3 => 'phone', 4 => 'versements', 5 => 'retraits', 6 => 'solde', 7 => 'note'),
					'sortable-fields' => array(0 => '`clients1`.`code`', 1 => '`comptes`.`idcompte`', 2 => 3, 3 => 4, 4 => '`comptes`.`versements`', 5 => '`comptes`.`retraits`', 6 => '`comptes`.`solde`', 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-comptes',
					'template-printable' => 'children-comptes-printable',
					'query' => "SELECT IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code', `comptes`.`idcompte` as 'idcompte', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'titulaire', IF(    CHAR_LENGTH(`clients1`.`phone`) || CHAR_LENGTH(`clients1`.`whatsapp`), CONCAT_WS('',   `clients1`.`phone`, ' / ', `clients1`.`whatsapp`), '') as 'phone', REPLACE(FORMAT(`comptes`.`versements`, 0), ',', ' ') as 'versements', REPLACE(FORMAT(`comptes`.`retraits`, 0), ',', ' ') as 'retraits', REPLACE(FORMAT(`comptes`.`solde`, 0), ',', ' ') as 'solde', `comptes`.`note` as 'note' FROM `comptes` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`comptes`.`code` "
				)
			),
			'enregistrements' => array(   
				'code_client' => array(   
					'parent-table' => 'clients',
					'parent-primary-key' => 'idclient',
					'child-primary-key' => 'idenregistrement',
					'child-primary-key-index' => 0,
					'tab-label' => 'Enregistrements <span class="hidden child-label-enregistrements child-field-caption">(CODE CLIENT)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/server_add.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'CODE CLIENT', 2 => 'CLIENT', 3 => 'COMPTE', 4 => 'DOMAINE', 5 => 'POUR', 6 => 'DATE ENREGISTREMENT', 7 => 'DATE EXPIRATION', 8 => 'Statut', 9 => 'NOTE'),
					'display-field-names' => array(1 => 'code_client', 2 => 'client', 3 => 'compte', 4 => 'domaine', 5 => 'pour', 6 => 'date_enregistrement', 7 => 'date_expiration', 8 => 'statut', 9 => 'note'),
					'sortable-fields' => array(0 => '`enregistrements`.`idenregistrement`', 1 => '`clients1`.`code`', 2 => 3, 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`enregistrements`.`date_enregistrement`', 7 => '`enregistrements`.`date_expiration`', 8 => 9, 9 => 10),
					'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-enregistrements',
					'template-printable' => 'children-enregistrements-printable',
					'query' => "SELECT `enregistrements`.`idenregistrement` as 'idenregistrement', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code_client', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'client', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', `enregistrements`.`domaine` as 'domaine', `enregistrements`.`pour` as 'pour', if(`enregistrements`.`date_enregistrement`,date_format(`enregistrements`.`date_enregistrement`,'%d/%m/%Y'),'') as 'date_enregistrement', if(`enregistrements`.`date_expiration`,date_format(`enregistrements`.`date_expiration`,'%d/%m/%Y'),'') as 'date_expiration', `enregistrements`.`statut` as 'statut', `enregistrements`.`note` as 'note' FROM `enregistrements` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`enregistrements`.`code_client` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`enregistrements`.`compte` "
				),
				'compte' => array(   
					'parent-table' => 'comptes',
					'parent-primary-key' => 'idcompte',
					'child-primary-key' => 'idenregistrement',
					'child-primary-key-index' => 0,
					'tab-label' => 'Enregistrements <span class="hidden child-label-enregistrements child-field-caption">(COMPTE)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/server_add.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'CODE CLIENT', 2 => 'CLIENT', 3 => 'COMPTE', 4 => 'DOMAINE', 5 => 'POUR', 6 => 'DATE ENREGISTREMENT', 7 => 'DATE EXPIRATION', 8 => 'Statut', 9 => 'NOTE'),
					'display-field-names' => array(1 => 'code_client', 2 => 'client', 3 => 'compte', 4 => 'domaine', 5 => 'pour', 6 => 'date_enregistrement', 7 => 'date_expiration', 8 => 'statut', 9 => 'note'),
					'sortable-fields' => array(0 => '`enregistrements`.`idenregistrement`', 1 => '`clients1`.`code`', 2 => 3, 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`enregistrements`.`date_enregistrement`', 7 => '`enregistrements`.`date_expiration`', 8 => 9, 9 => 10),
					'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-enregistrements',
					'template-printable' => 'children-enregistrements-printable',
					'query' => "SELECT `enregistrements`.`idenregistrement` as 'idenregistrement', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code_client', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'client', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', `enregistrements`.`domaine` as 'domaine', `enregistrements`.`pour` as 'pour', if(`enregistrements`.`date_enregistrement`,date_format(`enregistrements`.`date_enregistrement`,'%d/%m/%Y'),'') as 'date_enregistrement', if(`enregistrements`.`date_expiration`,date_format(`enregistrements`.`date_expiration`,'%d/%m/%Y'),'') as 'date_expiration', `enregistrements`.`statut` as 'statut', `enregistrements`.`note` as 'note' FROM `enregistrements` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`enregistrements`.`code_client` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`enregistrements`.`compte` "
				)
			),
			'facture' => array(   
				'client' => array(   
					'parent-table' => 'clients',
					'parent-primary-key' => 'idclient',
					'child-primary-key' => 'idfacture',
					'child-primary-key-index' => 0,
					'tab-label' => 'Facture <span class="hidden child-label-facture child-field-caption">(CLIENT)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/calculator_add.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'TYPE', 2 => 'DATE', 3 => 'NUMERO', 4 => 'CLIENT', 5 => 'SOCIETE', 6 => 'NATURE'),
					'display-field-names' => array(1 => 'type', 2 => 'date', 3 => 'numero', 4 => 'client', 5 => 'societe', 6 => 'travaux'),
					'sortable-fields' => array(0 => '`facture`.`idfacture`', 1 => 2, 2 => '`facture`.`date`', 3 => 4, 4 => 5, 5 => '`clients1`.`societe`', 6 => 7),
					'records-per-page' => 10,
					'default-sort-by' => 3,
					'default-sort-direction' => 'desc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-facture',
					'template-printable' => 'children-facture-printable',
					'query' => "SELECT `facture`.`idfacture` as 'idfacture', `facture`.`type` as 'type', if(`facture`.`date`,date_format(`facture`.`date`,'%d/%m/%Y'),'') as 'date', `facture`.`numero` as 'numero', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'client', IF(    CHAR_LENGTH(`clients1`.`societe`), CONCAT_WS('',   `clients1`.`societe`), '') as 'societe', `facture`.`travaux` as 'travaux' FROM `facture` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`facture`.`client` "
				)
			),
			'versements' => array(   
				'code' => array(   
					'parent-table' => 'clients',
					'parent-primary-key' => 'idclient',
					'child-primary-key' => 'idversement',
					'child-primary-key-index' => 0,
					'tab-label' => 'Versements <span class="hidden child-label-versements child-field-caption">(CODE CLIENT)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/coins_add.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'DATE', 2 => 'CODE CLIENT', 3 => 'COMPTE', 4 => 'TITULAIRE', 5 => 'MOTIF', 6 => 'MONTANT', 8 => 'NOTE'),
					'display-field-names' => array(1 => 'date', 2 => 'code', 3 => 'compte', 4 => 'titulaire', 5 => 'motif', 6 => 'montant', 8 => 'note'),
					'sortable-fields' => array(0 => '`versements`.`idversement`', 1 => '`versements`.`date`', 2 => '`clients1`.`code`', 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`versements`.`montant`', 7 => '`versements`.`total_m_versement`', 8 => 9),
					'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-versements',
					'template-printable' => 'children-versements-printable',
					'query' => "SELECT `versements`.`idversement` as 'idversement', if(`versements`.`date`,date_format(`versements`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'titulaire', `versements`.`motif` as 'motif', REPLACE(FORMAT(`versements`.`montant`, 0), ',', ' ') as 'montant', REPLACE(FORMAT(`versements`.`total_m_versement`, 0), ',', ' ') as 'total_m_versement', `versements`.`note` as 'note' FROM `versements` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`versements`.`code` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`versements`.`compte` "
				),
				'compte' => array(   
					'parent-table' => 'comptes',
					'parent-primary-key' => 'idcompte',
					'child-primary-key' => 'idversement',
					'child-primary-key-index' => 0,
					'tab-label' => 'Versements <span class="hidden child-label-versements child-field-caption">(COMPTE)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/coins_add.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'DATE', 2 => 'CODE CLIENT', 3 => 'COMPTE', 4 => 'TITULAIRE', 5 => 'MOTIF', 6 => 'MONTANT', 8 => 'NOTE'),
					'display-field-names' => array(1 => 'date', 2 => 'code', 3 => 'compte', 4 => 'titulaire', 5 => 'motif', 6 => 'montant', 8 => 'note'),
					'sortable-fields' => array(0 => '`versements`.`idversement`', 1 => '`versements`.`date`', 2 => '`clients1`.`code`', 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`versements`.`montant`', 7 => '`versements`.`total_m_versement`', 8 => 9),
					'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-versements',
					'template-printable' => 'children-versements-printable',
					'query' => "SELECT `versements`.`idversement` as 'idversement', if(`versements`.`date`,date_format(`versements`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'titulaire', `versements`.`motif` as 'motif', REPLACE(FORMAT(`versements`.`montant`, 0), ',', ' ') as 'montant', REPLACE(FORMAT(`versements`.`total_m_versement`, 0), ',', ' ') as 'total_m_versement', `versements`.`note` as 'note' FROM `versements` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`versements`.`code` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`versements`.`compte` "
				)
			),
			'retraits' => array(   
				'code' => array(   
					'parent-table' => 'clients',
					'parent-primary-key' => 'idclient',
					'child-primary-key' => 'idretrait',
					'child-primary-key-index' => 0,
					'tab-label' => 'Retraits <span class="hidden child-label-retraits child-field-caption">(CODE CLIENT)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/coins.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'DATE', 2 => 'CODE CLIENT', 3 => 'COMPTE', 4 => 'TITULAIRE', 5 => 'MOTIF', 6 => 'MONTANT', 7 => 'NOTE'),
					'display-field-names' => array(1 => 'date', 2 => 'code', 3 => 'compte', 4 => 'titulaire', 5 => 'motif', 6 => 'montant', 7 => 'note'),
					'sortable-fields' => array(0 => '`retraits`.`idretrait`', 1 => '`retraits`.`date`', 2 => '`clients1`.`code`', 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`retraits`.`montant`', 7 => 8, 8 => '`retraits`.`total_m_retrait`'),
					'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-retraits',
					'template-printable' => 'children-retraits-printable',
					'query' => "SELECT `retraits`.`idretrait` as 'idretrait', if(`retraits`.`date`,date_format(`retraits`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'titulaire', `retraits`.`motif` as 'motif', REPLACE(FORMAT(`retraits`.`montant`, 0), ',', ' ') as 'montant', `retraits`.`note` as 'note', REPLACE(FORMAT(`retraits`.`total_m_retrait`, 0), ',', ' ') as 'total_m_retrait' FROM `retraits` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`retraits`.`code` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`retraits`.`compte` "
				),
				'compte' => array(   
					'parent-table' => 'comptes',
					'parent-primary-key' => 'idcompte',
					'child-primary-key' => 'idretrait',
					'child-primary-key-index' => 0,
					'tab-label' => 'Retraits <span class="hidden child-label-retraits child-field-caption">(COMPTE)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/coins.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'DATE', 2 => 'CODE CLIENT', 3 => 'COMPTE', 4 => 'TITULAIRE', 5 => 'MOTIF', 6 => 'MONTANT', 7 => 'NOTE'),
					'display-field-names' => array(1 => 'date', 2 => 'code', 3 => 'compte', 4 => 'titulaire', 5 => 'motif', 6 => 'montant', 7 => 'note'),
					'sortable-fields' => array(0 => '`retraits`.`idretrait`', 1 => '`retraits`.`date`', 2 => '`clients1`.`code`', 3 => '`comptes1`.`idcompte`', 4 => 5, 5 => 6, 6 => '`retraits`.`montant`', 7 => 8, 8 => '`retraits`.`total_m_retrait`'),
					'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-retraits',
					'template-printable' => 'children-retraits-printable',
					'query' => "SELECT `retraits`.`idretrait` as 'idretrait', if(`retraits`.`date`,date_format(`retraits`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`clients1`.`code`), CONCAT_WS('',   `clients1`.`code`), '') as 'code', IF(    CHAR_LENGTH(`comptes1`.`idcompte`), CONCAT_WS('',   `comptes1`.`idcompte`), '') as 'compte', IF(    CHAR_LENGTH(`clients1`.`prenom`) || CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`prenom`, '   ', `clients1`.`nom`), '') as 'titulaire', `retraits`.`motif` as 'motif', REPLACE(FORMAT(`retraits`.`montant`, 0), ',', ' ') as 'montant', `retraits`.`note` as 'note', REPLACE(FORMAT(`retraits`.`total_m_retrait`, 0), ',', ' ') as 'total_m_retrait' FROM `retraits` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`retraits`.`code` LEFT JOIN `comptes` as comptes1 ON `comptes1`.`idcompte`=`retraits`.`compte` "
				)
			),
			'detail_facture' => array(   
				'factureid' => array(   
					'parent-table' => 'facture',
					'parent-primary-key' => 'idfacture',
					'child-primary-key' => 'dfid',
					'child-primary-key-index' => 0,
					'tab-label' => 'Detail facture <span class="hidden child-label-detail_facture child-field-caption">(NUMERO)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/calculator_edit.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'NUMERO', 2 => 'DESIGNATION', 3 => 'QTE', 4 => 'PRIX UNITAIRE', 5 => 'TOTAL'),
					'display-field-names' => array(1 => 'factureid', 2 => 'designation', 3 => 'quantite', 4 => 'prixunitaire', 5 => 'total'),
					'sortable-fields' => array(0 => '`detail_facture`.`dfid`', 1 => '`facture1`.`idfacture`', 2 => 3, 3 => '`detail_facture`.`quantite`', 4 => '`detail_facture`.`prixunitaire`', 5 => '`detail_facture`.`total`'),
					'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-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', `detail_facture`.`designation` as 'designation', `detail_facture`.`quantite` as 'quantite', `detail_facture`.`prixunitaire` as 'prixunitaire', REPLACE(FORMAT(`detail_facture`.`total`, 0), ',', ' ') as 'total' FROM `detail_facture` LEFT JOIN `facture` as facture1 ON `facture1`.`idfacture`=`detail_facture`.`factureid` "
				)
			),
			'credit' => array(   
				'nom_prenom' => array(   
					'parent-table' => 'creanciers',
					'parent-primary-key' => 'idcreancier',
					'child-primary-key' => 'idcredit',
					'child-primary-key-index' => 0,
					'tab-label' => 'Credit <span class="hidden child-label-credit child-field-caption">(NOM ET PRENOM)</span>',
					'auto-close' => false,
					'table-icon' => 'resources/table_icons/coins_in_hand.png',
					'display-refresh' => true,
					'display-add-new' => true,
					'forced-where' => '',
					'display-fields' => array(1 => 'DATE', 2 => 'NOM ET PRENOM', 3 => 'CREDIT', 4 => 'REMBOURSEMENT', 5 => 'Note'),
					'display-field-names' => array(1 => 'date', 2 => 'nom_prenom', 3 => 'credit', 4 => 'remboursement', 5 => 'note'),
					'sortable-fields' => array(0 => '`credit`.`idcredit`', 1 => '`credit`.`date`', 2 => 3, 3 => '`credit`.`credit`', 4 => '`credit`.`remboursement`', 5 => 6),
					'records-per-page' => 10,
					'default-sort-by' => 1,
					'default-sort-direction' => 'asc',
					'open-detail-view-on-click' => true,
					'display-page-selector' => true,
					'show-page-progress' => true,
					'template' => 'children-credit',
					'template-printable' => 'children-credit-printable',
					'query' => "SELECT `credit`.`idcredit` as 'idcredit', if(`credit`.`date`,date_format(`credit`.`date`,'%d/%m/%Y'),'') as 'date', IF(    CHAR_LENGTH(`creanciers1`.`nom_prenom`) || CHAR_LENGTH(`creanciers1`.`telephone`), CONCAT_WS('',   `creanciers1`.`nom_prenom`, '   -   ', `creanciers1`.`telephone`), '') as 'nom_prenom', REPLACE(FORMAT(`credit`.`credit`, 0), ',', ' ') as 'credit', REPLACE(FORMAT(`credit`.`remboursement`, 0), ',', ' ') as 'remboursement', `credit`.`note` as 'note' FROM `credit` LEFT JOIN `creanciers` as creanciers1 ON `creanciers1`.`idcreancier`=`credit`.`nom_prenom` "
				)
			),
			'creanciers' => 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);
		/************************************************/
	}
