PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/siou/odb_commun/inc-pdf-attestations.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 167 lines | 139 code | 18 blank | 10 comment | 23 complexity | 6a79bc1eb7ba360945b999e352cf447f MD5 | raw file
  1. <?php
  2. include_once('inc-html.php');
  3. include_once('inc-odb.php');
  4. $tBddConf=getBddConf();
  5. mysql_connect($tBddConf['host'], $tBddConf['user'], $tBddConf['pass']) or die('Connection impossible<br/>'.mysql_error());
  6. mysql_select_db($tBddConf['bdd']) or die('Base inaccessible<br/>'.mysql_error());
  7. $where='';
  8. $pdfG='attestations_';
  9. $groupe=$_REQUEST['groupe'];
  10. if($groupe==2) {
  11. $andDelib = " and delib1='Admissible' and delib2 = 'Oral' and delib3 = 'Passable'";
  12. $titre="Attestations 2&egrave;me groupe";
  13. $pdfG.=getRewriteString("groupe2");
  14. } elseif($groupe==1) {
  15. $andDelib = " and delib1='Admissible' and delib2 != 'Oral' and delib2 != 'Reserve'";
  16. $titre="Attestations 1er groupe";
  17. $pdfG.=getRewriteString("groupe1");
  18. } else die((KO." - Numero de groupe [$groupe] incorrect<br/>".__FILE__));
  19. $deliberation=$groupe+1;
  20. $annee=$_REQUEST['annee'];
  21. if($annee=='') $annee=date('Y');
  22. $limit=$_REQUEST['limit'];
  23. if($limit=='') $limit=0;
  24. $jury=$_REQUEST['jury'];
  25. if($jury>0) {
  26. $andDelib.=" AND jury='$jury'";
  27. //$tRefEta=getReferentiel('etablissement');
  28. $pdfG.='_'.getRewriteString("jury $jury");
  29. $titre.=" jury";
  30. }
  31. $date_delib=trim($_REQUEST['date_delib']);
  32. $tTmp=explode('/',$date_delib);
  33. $jour=(int)$tTmp[0];
  34. $mois=(int)$tTmp[1];
  35. $annee=(int)$tTmp[2];
  36. if(!checkdate($mois,$jour,$annee)) die("<b>[KO]</b> La date <b>$date_delib</b> est incorrecte, veuillez recommencer.");
  37. setlocale(LC_TIME, 'fr_FR','fr_BE.UTF8','fr_FR.UTF8');
  38. $sDateDelib=html_entity_decode(utf8_decode(strftime("%A %d %B %Y", mktime(0, 0, 0, $mois, $jour, $annee))));
  39. $date_attestation=trim($_REQUEST['date_attestation']);
  40. $tTmp=explode('/',$date_attestation);
  41. $jour=(int)$tTmp[0];
  42. $mois=(int)$tTmp[1];
  43. $annee=(int)$tTmp[2];
  44. if(!checkdate($mois,$jour,$annee)) die("<b>[KO]</b> La date <b>$date_attestation</b> est incorrecte, veuillez recommencer.");
  45. setlocale(LC_TIME, 'fr_FR','fr_BE.UTF8','fr_FR.UTF8');
  46. $sDateAttestation=html_entity_decode(utf8_decode(strftime("%A %d %B %Y", mktime(0, 0, 0, $mois, $jour, $annee))));
  47. //die($sDateConvoc);
  48. $sql = "select can.id_table, sex.sexe, pre.prefixe, nom, prenoms, ldn, pays, if(ne_le='0000-00-00',if(ne_en='0000',concat('vers ',ne_vers),concat('en ',ne_en)),DATE_FORMAT(ne_le, 'le %d/%m/%Y')) ddn, delib$deliberation delib, moyenne, ser.serie, ser.libelle libSerie, jury, eta.etablissement centre\n"
  49. . " from odb_decisions decis, odb_ref_etablissement eta, odb_ref_pays pays, odb_ref_sexe sex, odb_ref_serie ser, odb_repartition rep, odb_candidats can\n"
  50. . " left join odb_ref_prefixe pre on pre.id=can.prefixe\n"
  51. . " where rep.id_table=can.id_table and decis.id_table=rep.id_table\n"
  52. . " and decis.annee=$annee and can.annee=$annee and rep.annee=$annee\n"
  53. . ' and sex.id=can.sexe and can.serie=ser.id and can.nationalite=pays.id and rep.id_etablissement=eta.id '
  54. . "$andDelib\n"
  55. . " order by jury, ser.serie, id_table".
  56. " limit $limit, 2000";
  57. //die("<pre>$sql");
  58. $result=odb_query($sql,__FILE__,__LINE__);
  59. $pdf_dir='contrib/ezpdf/';
  60. include $pdf_dir.'class.ezpdf.php'; // inclusion du code de la bibliothque
  61. $pdf =& new Cezpdf('A4','portrait'); // 595.28 x 841.89
  62. $pdf->selectFont($pdf_dir.'fonts/Helvetica.afm');
  63. $options=array('b'=>'Helvetica-Bold.afm');
  64. $family='Helvetica';
  65. $pdf->setFontFamily($family,$options);
  66. $pdf->setStrokeColor(0,0,0);
  67. $pdf->setLineStyle(1,'round','round');
  68. $width=$pdf->ez['pageWidth'];
  69. $height=$pdf->ez['pageHeight'];
  70. $colonnes=array('id_table','sexe','prefixe','nom','prenoms','ldn','pays','ddn','delib','moyenne','serie','libSerie','jury','centre');
  71. $colonnes2=array('id_table','candidat','ldn','ddn','delib','moyenne','serie','libSerie','jury','centre');
  72. while($row=mysql_fetch_array($result)) {
  73. foreach($colonnes as $col) $$col=utf8_decode(stripslashes($row[$col]));
  74. if($sexe=='M') {
  75. $civ='M.';
  76. $e='';
  77. }
  78. else {
  79. $civ='Mlle';
  80. $e='e'; // pour mettre des mots au feminin si c'est une candidate
  81. }
  82. $prefixe=strtolower($prefixe);
  83. $candidat="$civ $prefixe <b>$nom</b> $prenoms";
  84. if(supprimeAccents(utf8_encode($pays))!='Benin') $ldn.=" ($pays)";
  85. $delib=ucfirst(str_replace('abien','Assez bien',str_replace('tbien','Tr&egrave;s bien',strtolower($delib))));
  86. if($delib=='Passable') {
  87. if($groupe==1) $eme='er';
  88. else $eme='&egrave;me';
  89. $delib="<b>$delib</b> ($groupe$eme groupe)";
  90. }
  91. else $delib="<b>$delib</b>";
  92. foreach($colonnes2 as $col) $tAttestation[$jury][$serie][$id_table][$col]=html_entity_decode($$col);
  93. }
  94. ksort($tAttestation);
  95. foreach($tAttestation as $jury=>$t1) {
  96. ksort($t1);
  97. foreach($t1 as $serie=>$t2) {
  98. ksort($t2);
  99. foreach($t2 as $id_table=>$t3) {
  100. foreach($colonnes2 as $col) $$col=$t3[$col];
  101. $pdf->addDestination(getRewriteString($candidat),'FitH');
  102. if($iPage>0)
  103. $iPage=$pdf->newPage();
  104. else $iPage=1;
  105. $extra='';
  106. $sommaire.=html_entity_decode("<c:ilink:".getRewriteString($candidat).">".str_pad($id_table,13,'0',STR_PAD_LEFT)." - jury $jury, s&eacute;rie $serie - $candidat ($delib)</c:ilink>\n");
  107. $pdf->addText(420,700,20,"<b>$serie</b>");
  108. $pdf->addText(350,680,14,$libSerie);
  109. $pdf->addText(160,550,14,$candidat);
  110. $pdf->addText(160,525,14,$ldn);
  111. $pdf->addText(160,500,14,$ddn);
  112. $pdf->addText(400,410,20,"<b>$serie</b>");
  113. $pdf->addText(120,390,14,$sDateDelib); $pdf->addText(400,390,14,$centre);
  114. $pdf->addText(170,365,13,$id_table); $pdf->addText(350,365,14,$delib);
  115. $pdf->addText(370,340,14,$sDateAttestation);
  116. //$pdf->ezSetY(800);
  117. //foreach($colonnes2 as $col) $pdf->ezText(html_entity_decode("$col ".$$col));
  118. }
  119. }
  120. }
  121. $pdf->ezInsertMode(1,1,'before');
  122. $pdf->ezNewPage();
  123. $pdf->ezText(html_entity_decode($titre),12);
  124. $pdf->ezText($sommaire,8);
  125. $pdf->ezInsertMode(0);
  126. $infos=array('Title'=>html_entity_decode($titre),'Author'=>'SIOU / Office du Bac','CreationDate'=>date("d/m/Y"));
  127. $pdf->addInfo($infos);
  128. // do the output, this is my standard testing output code, adding ?d=1
  129. // to the url puts the pdf code to the screen in raw form, good for
  130. // checking
  131. // for parse errors before you actually try to generate the pdf file.
  132. if(isset($_REQUEST['d'])) $d=$_REQUEST['d'];
  133. if (isset($d) && $d){
  134. $pdfcode = $pdf->output(1);
  135. $pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode));
  136. echo '<html><body>';
  137. echo trim($pdfcode);
  138. echo '</body></html>';
  139. } else {
  140. //$pdf->ezStream();
  141. $pdfcode = $pdf->ezOutput();
  142. $pdf_fic="pdf/siou-".date('Y')."_$pdfG.pdf";
  143. $fp=fopen($pdf_fic,'wb');
  144. fwrite($fp,$pdfcode);
  145. fclose($fp);
  146. echo "<A HREF='$pdf_fic'>Cliquez ici pour lire le fichier $pdf_fic</a>\n";
  147. echo "<script>document.location='$pdf_fic'</script>";
  148. }
  149. ?>