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

/htdocs/societe/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 202 lines | 113 code | 42 blank | 47 comment | 28 complexity | 62598fd92da1a3fefdaaeee4d9190644 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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/societe/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.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. $langs->load("companies");
  31. $langs->load('other');
  32. $action=GETPOST('action');
  33. $confirm=GETPOST('confirm');
  34. $id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  35. $ref = GETPOST('ref', 'alpha');
  36. // Security check
  37. if ($user->societe_id > 0)
  38. {
  39. unset($action);
  40. $socid = $user->societe_id;
  41. }
  42. $result = restrictedArea($user, 'societe', $id, '&societe');
  43. // Get parameters
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if ($page == -1) { $page = 0; }
  48. $offset = $conf->liste_limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="name";
  53. $object = new Societe($db);
  54. if ($id > 0 || ! empty($ref))
  55. {
  56. $result = $object->fetch($id, $ref);
  57. $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
  58. $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id);
  59. }
  60. /*
  61. * Actions
  62. */
  63. // TODO Use an include to mutualize this code for action sendit and confirm_deletefile
  64. // Post file
  65. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  66. {
  67. if ($object->id)
  68. {
  69. dol_add_file_process($upload_dir,0,1,'userfile');
  70. }
  71. }
  72. // Delete file
  73. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  74. {
  75. if ($object->id)
  76. {
  77. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  78. $ret=dol_delete_file($file,0,0,0,$object);
  79. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  80. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  81. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  82. exit;
  83. }
  84. }
  85. /*
  86. * View
  87. */
  88. $form = new Form($db);
  89. llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Files"));
  90. if ($object->id)
  91. {
  92. /*
  93. * Affichage onglets
  94. */
  95. if (! empty($conf->notification->enabled)) $langs->load("mails");
  96. $head = societe_prepare_head($object);
  97. $form=new Form($db);
  98. dol_fiche_head($head, 'document', $langs->trans("ThirdParty"),0,'company');
  99. // Construit liste des fichiers
  100. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  101. $totalsize=0;
  102. foreach($filearray as $key => $file)
  103. {
  104. $totalsize+=$file['size'];
  105. }
  106. print '<table class="border"width="100%">';
  107. // Ref
  108. print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td>';
  109. print '<td colspan="3">';
  110. print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom');
  111. print '</td></tr>';
  112. // Prefix
  113. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  114. {
  115. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  116. }
  117. if ($object->client)
  118. {
  119. print '<tr><td>';
  120. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  121. print $object->code_client;
  122. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  123. print '</td></tr>';
  124. }
  125. if ($object->fournisseur)
  126. {
  127. print '<tr><td>';
  128. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  129. print $object->code_fournisseur;
  130. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  131. print '</td></tr>';
  132. }
  133. // Nbre fichiers
  134. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  135. //Total taille
  136. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  137. print '</table>';
  138. print '</div>';
  139. /*
  140. * Confirmation suppression fichier
  141. */
  142. if ($action == 'delete')
  143. {
  144. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  145. if ($ret == 'html') print '<br>';
  146. }
  147. $formfile=new FormFile($db);
  148. // Show upload form
  149. $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,'',0,0,$user->rights->societe->creer,50,$object);
  150. // List of document
  151. $formfile->list_of_documents($filearray,$object,'societe');
  152. print "<br><br>";
  153. }
  154. else
  155. {
  156. accessforbidden('',0,0);
  157. }
  158. llxFooter();
  159. $db->close();
  160. ?>