PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/receipt_add.php

#
PHP | 192 lines | 133 code | 31 blank | 28 comment | 12 complexity | bffee339d4632e74f6cb3026e41c7549 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-2.0
  1. <?php
  2. /*
  3. GCourrier
  4. Copyright (C) 2005, 2006, 2010 Cliss XXI
  5. This file is part of GCourrier.
  6. GCourrier is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License as
  8. published by the Free Software Foundation, either version 3 of the
  9. License, or (at your option) any later version.
  10. GCourrier is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Affero General Public License for more details.
  14. You should have received a copy of the GNU Affero General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. require('phppdflib/phppdflib.class.php');
  18. require('functions/mail.php');
  19. require('init.php');
  20. //recuperation des donnees
  21. if (get_magic_quotes_gpc()) {
  22. $expediteur = stripcslashes($_POST['expediteur']);
  23. $adresse = stripcslashes($_POST['adresse']);
  24. $codePostal = stripcslashes($_POST['codePostal']." ".$_POST['ville']);
  25. $telephone = stripcslashes($_POST['telephone']);
  26. $destinataire = stripcslashes($_POST['destinataire']);
  27. $adresseDest =stripcslashes( $_POST['adresseDest']);
  28. $codePostalDest= stripcslashes($_POST['codePostalDest']." ".$_POST['villeDest']);
  29. $date = stripcslashes($_POST['date']);
  30. $objet = stripcslashes($_POST['objet']);
  31. $corps = stripcslashes($_POST['corps']);
  32. } else {
  33. $expediteur = $_POST['expediteur'];
  34. $adresse = $_POST['adresse'];
  35. $codePostal = $_POST['codePostal']." ".$_POST['ville'];
  36. $telephone = $_POST['telephone'];
  37. $destinataire = $_POST['destinataire'];
  38. $adresseDest = $_POST['adresseDest'];
  39. $codePostalDest= $_POST['codePostalDest']." ".$_POST['villeDest'];
  40. $date = $_POST['date'];
  41. $objet = $_POST['objet'];
  42. $corps = $_POST['corps'];
  43. }
  44. $pdf = new pdffile;
  45. $pdf->set_default('margin', 0);
  46. $firstpage = $pdf->new_page("letter");
  47. //information expediteur destinataire du document
  48. $param["height"] = 14;
  49. $param["fillcolor"] = $pdf->get_color('black');
  50. $param["font"] = "Helvetica";
  51. $param["rotation"] = 0;
  52. $pdf->draw_text(10, 750, utf8_decode($expediteur), $firstpage, $param);
  53. $param["height"] = 14;
  54. $param["fillcolor"] = $pdf->get_color('black');
  55. $param["font"] = "Helvetica";
  56. $param["rotation"] = 0;
  57. $pdf->draw_text(10, 730, utf8_decode($adresse), $firstpage, $param);
  58. $param["height"] = 14;
  59. $param["fillcolor"] = $pdf->get_color('black');
  60. $param["font"] = "Helvetica";
  61. $param["rotation"] = 0;
  62. $pdf->draw_text(10, 710, utf8_decode($codePostal), $firstpage, $param);
  63. $param["height"] = 14;
  64. $param["fillcolor"] = $pdf->get_color('black');
  65. $param["font"] = "Helvetica";
  66. $param["rotation"] = 0;
  67. $pdf->draw_text(10, 690, utf8_decode($telephone), $firstpage, $param);
  68. $param["height"] = 14;
  69. $param["fillcolor"] = $pdf->get_color('black');
  70. $param["font"] = "Helvetica";
  71. $param["rotation"] = 0;
  72. $pdf->draw_text(400, 670, utf8_decode($destinataire), $firstpage, $param);
  73. $param["height"] = 14;
  74. $param["fillcolor"] = $pdf->get_color('black');
  75. $param["font"] = "Helvetica";
  76. $param["rotation"] = 0;
  77. $pdf->draw_text(400, 650, utf8_decode($adresseDest), $firstpage, $param);
  78. $param["height"] = 14;
  79. $param["fillcolor"] = $pdf->get_color('black');
  80. $param["font"] = "Helvetica";
  81. $param["rotation"] = 0;
  82. $pdf->draw_text(400, 630, utf8_decode($codePostalDest), $firstpage, $param);
  83. $param["height"] = 14;
  84. $param["fillcolor"] = $pdf->get_color('black');
  85. $param["font"] = "Helvetica";
  86. $param["rotation"] = 0;
  87. $pdf->draw_text(400, 590, utf8_decode($date), $firstpage, $param);
  88. $param["height"] = 14;
  89. $param["fillcolor"] = $pdf->get_color('black');
  90. $param["font"] = "Helvetica";
  91. $param["rotation"] = 0;
  92. $pdf->draw_text(10, 550, utf8_decode($objet), $firstpage, $param);
  93. $MARGE_GAUCHE=30;
  94. $x = $MARGE_GAUCHE;
  95. $y = 490;
  96. $debut = 0;
  97. $fin = 0;
  98. for ($i = 0; $i < strlen($corps); $i++) {
  99. if ($corps[$i] == "\r") {
  100. $corps[$i] = '';
  101. $i--;
  102. } elseif ($corps[$i] == '~' or $corps[$i] == "\n") {
  103. $param["height"] = 14;
  104. $param["fillcolor"] = $pdf->get_color('black');
  105. $param["font"] = "Helvetica";
  106. $param["rotation"] = 0;
  107. $pdf->draw_text($x, $y, utf8_decode(substr($corps,$debut,$fin-$debut-1)), $firstpage, $param);
  108. $y-=20;
  109. $x = $MARGE_GAUCHE;
  110. $fin++;
  111. $debut = $fin;
  112. } elseif ($corps[$i] == '|') {
  113. $x+=390;
  114. $corps[$i] = '';
  115. $i--;
  116. } elseif ($corps[$i] == '#') {
  117. $x+=10;
  118. $corps[$i] = '';
  119. $i--;
  120. } else {
  121. $fin++;
  122. }
  123. }
  124. $param["height"] = 14;
  125. $param["fillcolor"] = $pdf->get_color('black');
  126. $param["font"] = "Helvetica";
  127. $param["rotation"] = 0;
  128. $pdf->draw_text($x, $y, utf8_decode(substr($corps,$debut,$fin-$debut)), $firstpage, $param);
  129. /*
  130. header("Content-Disposition: filename=accuseReception.pdf");
  131. header("Content-Type: application/pdf");
  132. $temp = $pdf->generate();
  133. header('Content-Length: ' . strlen($temp));
  134. echo $temp;
  135. */
  136. $mail_id = intval($_POST['mail_id']);
  137. if ($mail_id == 0)
  138. exit("Identifiant de courrier invalide");
  139. $filename = "accuse-courrier_{$mail_id}-" . strftime("%x-%X"). ".pdf";
  140. $path = "accuse/$filename";
  141. $inF = fopen($path, "wn");
  142. fputs($inF, $pdf->generate(0));
  143. fclose($inF);
  144. $attachment_id = mail_attachment_new($mail_id, $path, $filename);
  145. include('templates/header.php');
  146. echo "<p>"
  147. . "<a href='file_view.php/"
  148. . $filename
  149. . "?object=mail&attachment_id={$attachment_id}]'>"
  150. . "Télécharger l'accusé de réception"
  151. . "</a>"
  152. . "</p>";
  153. echo "<p><a href='mail_attachment.php?object_id={$mail_id}'>Voir les pièces jointes du courrier</a></p>";
  154. include('templates/footer.php');
  155. ?>