index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2016 Guillaume <guillaume@franciliens.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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 General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file dev/skeletons/skeleton_page.php
  20. * \ingroup mymodule othermodule1 othermodule2
  21. * \brief This file is an example of a php page
  22. * Put here some comments
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  28. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test
  29. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
  30. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test
  31. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
  32. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  33. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  34. if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
  35. // Change this following line to use the correct relative path (../, ../../, etc)
  36. $res=0;
  37. if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
  38. if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
  39. if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
  40. if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  41. if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  42. if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  43. if (! $res) die("Include of main fails");
  44. // Change this following line to use the correct relative path from htdocs
  45. dol_include_once('/module/class/skeleton_class.class.php');
  46. dol_include_once('/adherents/class/adherent.class.php');
  47. require_once('view.php');
  48. // Load traductions files requiredby by page
  49. $langs->load("companies");
  50. $langs->load("other");
  51. // Get parameters
  52. $action = GETPOST('action', 'alpha');
  53. $login = GETPOST('login', 'alpha');
  54. $password = GETPOST('password', 'alpha');
  55. $file = GETPOST('file', 'alpha');
  56. // Get session
  57. session_start();
  58. //----------------------------------------
  59. // Login
  60. //----------------------------------------
  61. $adherent = new Adherent($db);
  62. if ( $action == 'login' )
  63. {
  64. $_SESSION = array();
  65. $adherent->fetch_login($login);
  66. if ( $adherent->login === $login && $adherent->pass === $password
  67. && $adherent->statut == 1 )
  68. {
  69. $_SESSION['login'] = $adherent->login;
  70. }
  71. else
  72. {
  73. paHeader();
  74. print('<p>Bad login/password</p>');
  75. paFooter();
  76. exit(1);
  77. }
  78. }
  79. else if ( $action == 'logout' )
  80. {
  81. $_SESSION = array();
  82. session_destroy();
  83. exit('Au revoir');
  84. }
  85. else if ( isset($_SESSION['login']) )
  86. {
  87. $adherent->fetch_login($_SESSION['login']);
  88. }
  89. else
  90. {
  91. paHeader('Identification');
  92. print '<form method="post" action="">
  93. Utilisateur : <input name="login" type="text" />
  94. Mot de passe : <input name="password" type="password" />
  95. <input name="action" type="submit" value="login" />
  96. </form>';
  97. paFooter();
  98. exit(0);
  99. }
  100. $id = $adherent->id;
  101. $upload_dir = $conf->adherent->dir_output . "/" . get_exdir($id,2,0,1) . '/' . $id . '/';
  102. // Construit liste des fichiers
  103. $files = array();
  104. $handle = opendir($upload_dir);
  105. if($handle)
  106. {
  107. while (false !== ($entry = readdir($handle)))
  108. {
  109. $filepath = $upload_dir.$entry;
  110. if ( is_file($filepath) )
  111. {
  112. $files[$entry] = $filepath;
  113. }
  114. }
  115. closedir($handle);
  116. }
  117. else
  118. {
  119. print('Répertoire non trouvé.');
  120. }
  121. /*******************************************************************
  122. * ACTIONS
  123. *
  124. * Put here all code to do according to value of "action" parameter
  125. ********************************************************************/
  126. if($action == 'Obtenir')
  127. {
  128. if ( isset($files[$file]) )
  129. {
  130. header('Content-Type: application/octet-stream');
  131. header('Content-disposition: attachment; filename="' . basename($file) . '"');
  132. print(file_get_contents($files[$file]));
  133. }
  134. else
  135. {
  136. print($file);
  137. print_r($files);
  138. }
  139. }
  140. else
  141. {
  142. paHeader();
  143. print('Bonjour ' . $_SESSION['login']);
  144. print('<form action="" method="post">
  145. <input type="submit" name="action" value="logout" />
  146. </form>');
  147. print('<h1>Page adhérent</h1>');
  148. print('<h2>Informations</h2>');
  149. print('<p>Nom : '. $adherent->firstname .' '.$adherent->lastname.'</p>');
  150. print('<p>Adresse : '. $adherent->address .', '. $adherent->zip .' '.$adherent->town.'</p>');
  151. print('<p>Date d\'échéance de cotisation : ' .strftime('%F', $adherent->datefin). '</p>');
  152. print('<h2>Documents</h2>');
  153. print('<form method="post" action="">
  154. <select name="file">');
  155. foreach($files as $filename => $filepath)
  156. {
  157. print('<option value=" ' . $filename . ' ">' . $filename . '</option>');
  158. }
  159. print('</select>
  160. <input type="submit" name="action" value="Obtenir" />
  161. </form>');
  162. paFooter();
  163. }
  164. $db->close();
  165. ?>