document.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/adherents/document.php
  22. * \brief Tab for documents linked to third party
  23. * \ingroup societe
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
  31. $langs->load("companies");
  32. $langs->load('other');
  33. $mesg = "";
  34. // Security check
  35. $id = GETPOST('id');
  36. if ($user->societe_id > 0)
  37. {
  38. $id = $user->societe_id;
  39. }
  40. //$result = restrictedArea($user, 'societe', $id);
  41. // Get parameters
  42. $sortfield = GETPOST("sortfield",'alpha');
  43. $sortorder = GETPOST("sortorder",'alpha');
  44. $page = GETPOST("page",'int');
  45. if ($page == -1) { $page = 0 ; }
  46. $offset = $conf->liste_limit * $page ;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. if (! $sortorder) $sortorder="ASC";
  50. if (! $sortfield) $sortfield="name";
  51. $upload_dir = $conf->adherent->dir_output . "/" . get_exdir($id,2,0,1) . '/' . $id;
  52. /*
  53. * Actions
  54. */
  55. // Envoie fichier
  56. if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  57. {
  58. require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
  59. if (create_exdir($upload_dir) >= 0)
  60. {
  61. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  62. if (is_numeric($resupload) && $resupload > 0)
  63. {
  64. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  65. }
  66. else
  67. {
  68. $langs->load("errors");
  69. if ($resupload < 0) // Unknown error
  70. {
  71. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  72. }
  73. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  74. {
  75. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  76. }
  77. else // Known error
  78. {
  79. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  80. }
  81. }
  82. }
  83. }
  84. // Suppression fichier
  85. if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
  86. {
  87. $file = $upload_dir . "/" . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  88. dol_delete_file($file);
  89. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  90. }
  91. /*
  92. * View
  93. */
  94. $form = new Form($db);
  95. $member=new Adherent($db);
  96. $membert=new AdherentType($db);
  97. llxHeader();
  98. if ($id > 0)
  99. {
  100. $result=$member->fetch($id);
  101. $result=$membert->fetch($member->typeid);
  102. if ($result > 0)
  103. {
  104. /*
  105. * Affichage onglets
  106. */
  107. if ($conf->notification->enabled) $langs->load("mails");
  108. $head = member_prepare_head($member);
  109. $html=new Form($db);
  110. dol_fiche_head($head, 'document', $langs->trans("Member"),0,'user');
  111. // Construit liste des fichiers
  112. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  113. $totalsize=0;
  114. foreach($filearray as $key => $file)
  115. {
  116. $totalsize+=$file['size'];
  117. }
  118. print '<table class="border"width="100%">';
  119. // Ref
  120. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  121. print '<td class="valeur">';
  122. print $html->showrefnav($member,'rowid');
  123. print '</td></tr>';
  124. // Login
  125. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  126. {
  127. print '<tr><td>'.$langs->trans("Login").'</td><td class="valeur">'.$member->login.'&nbsp;</td></tr>';
  128. }
  129. // Morphy
  130. print '<tr><td>'.$langs->trans("Nature").'</td><td class="valeur" >'.$member->getmorphylib().'</td>';
  131. /*print '<td rowspan="'.$rowspan.'" align="center" valign="middle" width="25%">';
  132. print $html->showphoto('memberphoto',$member);
  133. print '</td>';*/
  134. print '</tr>';
  135. // Type
  136. print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">'.$membert->getNomUrl(1)."</td></tr>\n";
  137. // Company
  138. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$member->societe.'</td></tr>';
  139. // Civility
  140. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$member->getCivilityLabel().'&nbsp;</td>';
  141. print '</tr>';
  142. // Nom
  143. print '<tr><td>'.$langs->trans("Lastname").'</td><td class="valeur">'.$member->nom.'&nbsp;</td>';
  144. print '</tr>';
  145. // Prenom
  146. print '<tr><td>'.$langs->trans("Firstname").'</td><td class="valeur">'.$member->prenom.'&nbsp;</td>';
  147. print '</tr>';
  148. // Status
  149. print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$member->getLibStatut(4).'</td></tr>';
  150. // Nbre fichiers
  151. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.sizeof($filearray).'</td></tr>';
  152. //Total taille
  153. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  154. print '</table>';
  155. print '</div>';
  156. dol_htmloutput_mesg($mesg,$mesgs);
  157. /*
  158. * Confirmation suppression fichier
  159. */
  160. if ($_GET['action'] == 'delete')
  161. {
  162. $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  163. if ($ret == 'html') print '<br>';
  164. }
  165. // Affiche formulaire upload
  166. $formfile=new FormFile($db);
  167. $formfile->form_attach_new_file(DOL_URL_ROOT.'/adherents/document.php?id='.$id,'',0,0,$user->rights->adherent->creer);
  168. // List of document
  169. $param='&socid='.$societe->id;
  170. $formfile->list_of_documents($filearray,$member,'member',$param, 0, get_exdir($id,2,0,1).'/'.$id.'/');
  171. print "<br><br>";
  172. }
  173. else
  174. {
  175. dol_print_error($db);
  176. }
  177. }
  178. else
  179. {
  180. $langs->load("errors");
  181. print $langs->trans("ErrorRecordNotFound");
  182. }
  183. $db->close();
  184. llxFooter();
  185. ?>