document.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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@inodbox.com>
  5. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/societe/document.php
  24. * \brief Tab for documents linked to third party
  25. * \ingroup societe
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. $langs->loadLangs(array("companies", "other"));
  33. $action=GETPOST('action','aZ09');
  34. $confirm=GETPOST('confirm');
  35. $id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  36. $ref = GETPOST('ref', 'alpha');
  37. // Security check
  38. if ($user->societe_id > 0)
  39. {
  40. unset($action);
  41. $socid = $user->societe_id;
  42. }
  43. $result = restrictedArea($user, 'societe', $id, '&societe');
  44. // Get parameters
  45. $sortfield = GETPOST("sortfield",'alpha');
  46. $sortorder = GETPOST("sortorder",'alpha');
  47. $page = GETPOST("page",'int');
  48. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  49. $offset = $conf->liste_limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (! $sortorder) $sortorder="ASC";
  53. if (! $sortfield) $sortfield="position_name";
  54. $object = new Societe($db);
  55. if ($id > 0 || ! empty($ref))
  56. {
  57. $result = $object->fetch($id, $ref);
  58. $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
  59. $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty');
  60. }
  61. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  62. $hookmanager->initHooks(array('thirdpartydocument','globalcard'));
  63. /*
  64. * Actions
  65. */
  66. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  67. /*
  68. * View
  69. */
  70. $form = new Form($db);
  71. $title=$langs->trans("ThirdParty").' - '.$langs->trans("Files");
  72. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files");
  73. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  74. llxHeader('',$title,$help_url);
  75. if ($object->id)
  76. {
  77. /*
  78. * Show tabs
  79. */
  80. if (! empty($conf->notification->enabled)) $langs->load("mails");
  81. $head = societe_prepare_head($object);
  82. $form=new Form($db);
  83. dol_fiche_head($head, 'document', $langs->trans("ThirdParty"), -1, 'company');
  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.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  92. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  93. print '<div class="fichecenter">';
  94. print '<div class="underbanner clearboth"></div>';
  95. print '<table class="border centpercent">';
  96. // Prefix
  97. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  98. {
  99. print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  100. }
  101. if ($object->client)
  102. {
  103. print '<tr><td class="titlefield">';
  104. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  105. print $object->code_client;
  106. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  107. print '</td></tr>';
  108. }
  109. if ($object->fournisseur)
  110. {
  111. print '<tr><td class="titlefield">';
  112. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  113. print $object->code_fournisseur;
  114. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  115. print '</td></tr>';
  116. }
  117. // Number of files
  118. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  119. // Total size
  120. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
  121. print '</table>';
  122. print '</div>';
  123. dol_fiche_end();
  124. $modulepart = 'societe';
  125. $permission = $user->rights->societe->creer;
  126. $permtoedit = $user->rights->societe->creer;
  127. $param = '&id=' . $object->id;
  128. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  129. }
  130. else
  131. {
  132. accessforbidden('',0,0);
  133. }
  134. // End of page
  135. llxFooter();
  136. $db->close();