document.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('other', 'companies', 'contact'));
  32. $id = GETPOST('id', 'int');
  33. $action = GETPOST('action', 'aZ09');
  34. $confirm = GETPOST('confirm', 'alpha');
  35. $object = new Contact($db);
  36. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  37. $object->getCanvas($id);
  38. $objcanvas = null;
  39. $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
  40. if (!empty($canvas)) {
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  42. $objcanvas = new Canvas($db, $action);
  43. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  44. }
  45. // Get parameters
  46. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST('sortfield', 'aZ09comma');
  48. $sortorder = GETPOST('sortorder', 'aZ09comma');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page == -1) {
  51. $page = 0;
  52. } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!empty($conf->global->MAIN_DOC_SORT_FIELD)) {
  57. $sortfield = $conf->global->MAIN_DOC_SORT_FIELD;
  58. }
  59. if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) {
  60. $sortorder = $conf->global->MAIN_DOC_SORT_ORDER;
  61. }
  62. if (!$sortorder) {
  63. $sortorder = "ASC";
  64. }
  65. if (!$sortfield) {
  66. $sortfield = "name";
  67. }
  68. if ($id > 0) {
  69. $object->fetch($id);
  70. }
  71. $upload_dir = $conf->societe->multidir_output[$object->entity].'/contact/'.dol_sanitizeFileName($object->ref);
  72. $modulepart = 'contact';
  73. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  74. $hookmanager->initHooks(array('contactdocument'));
  75. // Security check
  76. if ($user->socid) {
  77. $socid = $user->socid;
  78. }
  79. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
  80. $permissiontoadd = $user->rights->societe->contact->creer; // Used by the include of actions_dellink.inc.php
  81. /*
  82. * Actions
  83. */
  84. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  85. /*
  86. * View
  87. */
  88. $form = new Form($db);
  89. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  90. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
  91. $title = $object->lastname;
  92. }
  93. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  94. llxHeader('', $title, $help_url);
  95. if ($object->id) {
  96. $head = contact_prepare_head($object);
  97. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  98. print dol_get_fiche_head($head, 'documents', $title, -1, 'contact');
  99. // Build file list
  100. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  101. $totalsize = 0;
  102. foreach ($filearray as $key => $file) {
  103. $totalsize += $file['size'];
  104. }
  105. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  106. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
  107. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  108. $morehtmlref .= '</a>';
  109. $morehtmlref .= '<div class="refidno">';
  110. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  111. $objsoc = new Societe($db);
  112. $objsoc->fetch($object->socid);
  113. // Thirdparty
  114. $morehtmlref .= $langs->trans('ThirdParty').' : ';
  115. if ($objsoc->id > 0) {
  116. $morehtmlref .= $objsoc->getNomUrl(1);
  117. } else {
  118. $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
  119. }
  120. }
  121. $morehtmlref .= '</div>';
  122. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  123. print '<div class="fichecenter">';
  124. print '<div class="underbanner clearboth"></div>';
  125. print '<table class="border tableforfield centpercent">';
  126. // Company
  127. /*
  128. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  129. {
  130. if ($object->socid > 0)
  131. {
  132. $objsoc = new Societe($db);
  133. $objsoc->fetch($object->socid);
  134. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  135. }
  136. else
  137. {
  138. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  139. print $langs->trans("ContactNotLinkedToCompany");
  140. print '</td></tr>';
  141. }
  142. }*/
  143. // Civility
  144. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  145. print $object->getCivilityLabel();
  146. print '</td></tr>';
  147. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  148. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  149. print '</table>';
  150. print '</div>';
  151. print dol_get_fiche_end();
  152. $modulepart = 'contact';
  153. $permissiontoadd = $user->rights->societe->contact->creer;
  154. $permtoedit = $user->rights->societe->contact->creer;
  155. $param = '&id='.$object->id;
  156. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  157. } else {
  158. print $langs->trans("ErrorUnknown");
  159. }
  160. llxFooter();
  161. $db->close();