document.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* Copyright (C) 2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2015-2021 Frederic France <frederic.france@free.fr>
  4. * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contact/document.php
  21. * \ingroup contact
  22. * \brief Page with attached files on contact
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.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/lib/contact.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('other', 'companies', 'contact'));
  33. // Get parameters
  34. $id = GETPOST('id', 'int');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $object = new Contact($db);
  38. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  39. $object->getCanvas($id);
  40. $objcanvas = null;
  41. $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
  42. if (!empty($canvas)) {
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  44. $objcanvas = new Canvas($db, $action);
  45. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  46. }
  47. // Get parameters
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
  59. $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
  60. }
  61. if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
  62. $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
  63. }
  64. if (!$sortorder) {
  65. $sortorder = "ASC";
  66. }
  67. if (!$sortfield) {
  68. $sortfield = "name";
  69. }
  70. if ($id > 0) {
  71. $object->fetch($id);
  72. }
  73. $upload_dir = $conf->societe->multidir_output[$object->entity].'/contact/'.dol_sanitizeFileName($object->ref);
  74. $modulepart = 'contact';
  75. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  76. $hookmanager->initHooks(array('contactdocument'));
  77. // Security check
  78. if ($user->socid) {
  79. $socid = $user->socid;
  80. }
  81. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
  82. $permissiontoadd = $user->hasRight('societe', 'contact', 'creer'); // Used by the include of actions_dellink.inc.php
  83. /*
  84. * Actions
  85. */
  86. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  87. /*
  88. * View
  89. */
  90. $form = new Form($db);
  91. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  92. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
  93. $title = $object->lastname;
  94. }
  95. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  96. llxHeader('', $title, $help_url);
  97. if ($object->id) {
  98. $head = contact_prepare_head($object);
  99. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  100. print dol_get_fiche_head($head, 'documents', $title, -1, 'contact');
  101. // Build file list
  102. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  103. $totalsize = 0;
  104. foreach ($filearray as $key => $file) {
  105. $totalsize += $file['size'];
  106. }
  107. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  108. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
  109. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  110. $morehtmlref .= '</a>';
  111. $morehtmlref .= '<div class="refidno">';
  112. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  113. $objsoc = new Societe($db);
  114. $objsoc->fetch($object->socid);
  115. // Thirdparty
  116. if ($objsoc->id > 0) {
  117. $morehtmlref .= $objsoc->getNomUrl(1);
  118. } else {
  119. $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
  120. }
  121. }
  122. $morehtmlref .= '</div>';
  123. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  124. print '<div class="fichecenter">';
  125. print '<div class="underbanner clearboth"></div>';
  126. print '<table class="border tableforfield centpercent">';
  127. // Company
  128. /*
  129. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  130. {
  131. if ($object->socid > 0)
  132. {
  133. $objsoc = new Societe($db);
  134. $objsoc->fetch($object->socid);
  135. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  136. }
  137. else
  138. {
  139. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  140. print $langs->trans("ContactNotLinkedToCompany");
  141. print '</td></tr>';
  142. }
  143. }*/
  144. // Civility
  145. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  146. print $object->getCivilityLabel();
  147. print '</td></tr>';
  148. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  149. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  150. print '</table>';
  151. print '</div>';
  152. print dol_get_fiche_end();
  153. $modulepart = 'contact';
  154. $permissiontoadd = $user->hasRight('societe', 'contact', 'creer');
  155. $permtoedit = $user->hasRight('societe', 'contact', 'creer');
  156. $param = '&id='.$object->id;
  157. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  158. } else {
  159. print $langs->trans("ErrorUnknown");
  160. }
  161. llxFooter();
  162. $db->close();