EnTete(); foreach (array('charges', 'produits', 'contributions_volontaires') as $key) { $xml->LesEcritures($key); } $xml->Pied(); $xml->Enregistre(); } } /** * Utilisation d'une classe tres tres tres simple !!! */ class XML { var $exercice; var $join; var $sel; var $where; var $having; var $order; var $out; function __construct($var) { $tableau = unserialize(rawurldecode($var)); $this->exercice = $tableau[0]; $this->join = $tableau[1]; $this->sel = $tableau[2]; $this->where = $tableau[3]; $this->having = $tableau[4]; $this->order = $tableau[5]; $this->out = ''; } function EnTete() { $this->out .= ''."\n"; $this->out .= "\n"; $this->out .= "\n"; $this->out .= ''. utf8_decode(html_entity_decode(_T('asso:cpte_resultat_titre_general'))) ."\n"; $this->out .= ''. $GLOBALS['association_metas']['nom'] ."\n"; $this->out .= ''. sql_asso1champ('exercice', $this->exercice, 'intitule') ."\n"; $this->out .= "\n"; } function LesEcritures($key) { switch ($key) { case 'charges' : $quoi = "SUM(depense) AS valeurs"; break; case 'produits' : $quoi = "SUM(recette) AS valeurs"; break; case 'contributions_volontaires' : $quoi = "SUM(depense) AS charge_evaluee, SUM(recette) AS produit_evalue"; break; } $this->out .= '<'. ucfirst($key) .">\n"; $query = sql_select( "imputation, $quoi, DATE_FORMAT(date, '%Y') AS annee ".$this->sel, // select 'spip_asso_comptes'.$this->join, // from $this->where, // where $this->order, // group by $this->order, // order by '', // limit $this->having .$GLOBALS['association_metas']['classe_'.$key] // having ); $chapitre = ''; $i = 0; while ($data = sql_fetch($query)) { if ($key==='contributions_volontaires') { if ($data['charge_evaluee']>0) { $valeurs = $data['charge_evaluee']; } else { $valeurs = $data['produit_evalue']; } } else { $valeurs = $data['valeurs']; } $new_chapitre = substr($data['code'], 0, 2); if ($chapitre!=$new_chapitre) { if ($chapitre!='') { $this->out .= "\n"; } $this->out .= "\n"; $this->out .= ''. str_replace(array('<','>'), array('<','>'), $new_chapitre) ."\n"; $this->out .= ''. str_replace(array('<','>'), array('<','>'), ($GLOBALS['association_metas']['plan_comptable_prerenseigne']?association_plan_comptable_complet($new_chapitre):sql_getfetsel('intitule','spip_asso_plan',"code='$new_chapitre'"))) ."\n"; $chapitre = $new_chapitre; } $this->out .= "\n"; $this->out .= ''. str_replace(array('<','>'), array('<','>'), $data['code']) ."\n"; $this->out .= ''. str_replace(array('<','>'), array('<','>'), $data['intitule']) ."\n"; $this->out .= "$valeurs\n"; $this->out .= "\n"; } if ($chapitre!='') { $this->out .= "\n"; } $this->out .= ''."\n"; } function Pied() { $this->out .= ''."\n"; } function Enregistre() { $fichier =_DIR_RACINE.'/'._NOM_TEMPORAIRES_ACCESSIBLES.'compte_resultats_'.$this->exercice.'.xml'; $f = fopen($fichier, 'w'); fputs($f, $this->out); fclose($f); header('Content-Type: text/xml'); header('Content-Type: application/xml'); header('Content-Disposition: attachment; filename="'.$fichier.'"'); readfile($fichier); } } ?>