document.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  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/contrat/document.php
  24. * \ingroup contrat
  25. * \brief Page des documents joints sur les contrats
  26. */
  27. require ("../main.inc.php");
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. $langs->load("other");
  34. $langs->load("products");
  35. $langs->load("contracts");
  36. $action = GETPOST('action','alpha');
  37. $confirm = GETPOST('confirm','alpha');
  38. $id = GETPOST('id','int');
  39. $ref = GETPOST('ref','alpha');
  40. // Security check
  41. if ($user->societe_id > 0)
  42. {
  43. unset($_GET["action"]);
  44. $action='';
  45. $socid = $user->societe_id;
  46. }
  47. $result = restrictedArea($user, 'contrat', $id);
  48. // Get parameters
  49. $sortfield = GETPOST("sortfield",'alpha');
  50. $sortorder = GETPOST("sortorder",'alpha');
  51. $page = GETPOST("page",'int');
  52. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  53. $offset = $conf->liste_limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (! $sortorder) $sortorder="ASC";
  57. if (! $sortfield) $sortfield="name";
  58. $object = new Contrat($db);
  59. $object->fetch($id, $ref);
  60. if ($object->id > 0)
  61. {
  62. $object->fetch_thirdparty();
  63. }
  64. $upload_dir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($object->ref);
  65. $modulepart='contract';
  66. /*
  67. * Actions
  68. */
  69. include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
  70. /*
  71. *
  72. */
  73. $form = new Form($db);
  74. llxHeader('',$langs->trans("Contract"),"");
  75. if ($object->id)
  76. {
  77. $head=contract_prepare_head($object);
  78. dol_fiche_head($head, 'documents', $langs->trans("Contract"), -1, 'contract');
  79. // Construit liste des fichiers
  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. // Contract card
  87. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  88. $morehtmlref='';
  89. //if (! empty($modCodeContract->code_auto)) {
  90. $morehtmlref.=$object->ref;
  91. /*} else {
  92. $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
  93. $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
  94. }*/
  95. $morehtmlref.='<div class="refidno">';
  96. // Ref customer
  97. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
  98. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
  99. // Ref supplier
  100. $morehtmlref.='<br>';
  101. $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  102. $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
  103. // Thirdparty
  104. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  105. // Project
  106. if (! empty($conf->projet->enabled))
  107. {
  108. $langs->load("projects");
  109. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  110. if ($user->rights->contrat->creer)
  111. {
  112. if ($action != 'classify')
  113. //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  114. $morehtmlref.=' : ';
  115. if ($action == 'classify') {
  116. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  117. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  118. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  119. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  120. $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  121. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  122. $morehtmlref.='</form>';
  123. } else {
  124. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
  125. }
  126. } else {
  127. if (! empty($object->fk_project)) {
  128. $proj = new Project($db);
  129. $proj->fetch($object->fk_project);
  130. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  131. $morehtmlref.=$proj->ref;
  132. $morehtmlref.='</a>';
  133. } else {
  134. $morehtmlref.='';
  135. }
  136. }
  137. }
  138. $morehtmlref.='</div>';
  139. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  140. print '<div class="fichecenter">';
  141. print '<div class="underbanner clearboth"></div>';
  142. print '<table class="border" width="100%">';
  143. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  144. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  145. print '</table>';
  146. print '</div>';
  147. dol_fiche_end();
  148. $modulepart = 'contract';
  149. $permission = $user->rights->contrat->creer;
  150. $permtoedit = $user->rights->contrat->creer;
  151. $param = '&id=' . $object->id;
  152. include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
  153. }
  154. else
  155. {
  156. print $langs->trans("ErrorUnknown");
  157. }
  158. llxFooter();
  159. $db->close();