document.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* Copyright (C) 2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2015 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. {
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  43. $objcanvas = new Canvas($db, $action);
  44. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  45. }
  46. // Security check
  47. if ($user->socid) $socid = $user->socid;
  48. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
  49. // Get parameters
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST("sortfield", 'alpha');
  52. $sortorder = GETPOST("sortorder", 'alpha');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) { $page = 0; } // 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)) { $sortfield = $conf->global->MAIN_DOC_SORT_FIELD; }
  59. if (!empty($conf->global->MAIN_DOC_SORT_ORDER)) { $sortorder = $conf->global->MAIN_DOC_SORT_ORDER; }
  60. if (!$sortorder) $sortorder = "ASC";
  61. if (!$sortfield) $sortfield = "name";
  62. if ($id > 0) $object->fetch($id);
  63. $upload_dir = $conf->societe->multidir_output[$object->entity].'/contact/'.dol_sanitizeFileName($object->ref);
  64. $modulepart = 'contact';
  65. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  66. $hookmanager->initHooks(array('contactdocument'));
  67. /*
  68. * Actions
  69. */
  70. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  71. /*
  72. * View
  73. */
  74. $form = new Form($db);
  75. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  76. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
  77. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  78. llxHeader('', $title, $helpurl);
  79. if ($object->id)
  80. {
  81. $head = contact_prepare_head($object);
  82. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  83. print dol_get_fiche_head($head, 'documents', $title, -1, 'contact');
  84. // Build file list
  85. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  86. $totalsize = 0;
  87. foreach ($filearray as $key => $file)
  88. {
  89. $totalsize += $file['size'];
  90. }
  91. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  92. $morehtmlref = '<div class="refidno">';
  93. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  94. {
  95. $objsoc = new Societe($db);
  96. $objsoc->fetch($object->socid);
  97. // Thirdparty
  98. $morehtmlref .= $langs->trans('ThirdParty').' : ';
  99. if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
  100. else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
  101. }
  102. $morehtmlref .= '</div>';
  103. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  104. print '<div class="fichecenter">';
  105. print '<div class="underbanner clearboth"></div>';
  106. print '<table class="border tableforfield centpercent">';
  107. // Company
  108. /*
  109. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  110. {
  111. if ($object->socid > 0)
  112. {
  113. $objsoc = new Societe($db);
  114. $objsoc->fetch($object->socid);
  115. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  116. }
  117. else
  118. {
  119. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  120. print $langs->trans("ContactNotLinkedToCompany");
  121. print '</td></tr>';
  122. }
  123. }*/
  124. // Civility
  125. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  126. print $object->getCivilityLabel();
  127. print '</td></tr>';
  128. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  129. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  130. print '</table>';
  131. print '</div>';
  132. print dol_get_fiche_end();
  133. $modulepart = 'contact';
  134. $permission = $user->rights->societe->contact->creer;
  135. $permtoedit = $user->rights->societe->contact->creer;
  136. $param = '&id='.$object->id;
  137. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  138. } else {
  139. print $langs->trans("ErrorUnknown");
  140. }
  141. llxFooter();
  142. $db->close();