document.php 5.8 KB

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