PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contrat/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 171 lines | 93 code | 37 blank | 41 comment | 20 complexity | 8225d9b4cbaa6e76d0d63eebad768c28 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/contrat/document.php
  23. * \ingroup contrat
  24. * \brief Page des documents joints sur les contrats
  25. */
  26. require ("../main.inc.php");
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.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->load("other");
  33. $langs->load("products");
  34. $langs->load("contracts");
  35. $action = GETPOST('action','alpha');
  36. $confirm = GETPOST('confirm','alpha');
  37. $id = GETPOST('id','int');
  38. $ref = GETPOST('ref','alpha');
  39. // Security check
  40. if ($user->societe_id > 0)
  41. {
  42. unset($_GET["action"]);
  43. $action='';
  44. $socid = $user->societe_id;
  45. }
  46. $result = restrictedArea($user, 'contrat', $id);
  47. // Get parameters
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if ($page == -1) { $page = 0; }
  52. $offset = $conf->liste_limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (! $sortorder) $sortorder="ASC";
  56. if (! $sortfield) $sortfield="name";
  57. $object = new Contrat($db);
  58. $object->fetch($id, $ref);
  59. if ($object->id > 0)
  60. {
  61. $object->fetch_thirdparty();
  62. }
  63. $upload_dir = $conf->contrat->dir_output.'/'.dol_sanitizeFileName($object->ref);
  64. $modulepart='contract';
  65. /*
  66. * Action envoie fichier
  67. */
  68. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  69. {
  70. dol_add_file_process($upload_dir,0,1,'userfile');
  71. }
  72. // Delete
  73. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  74. {
  75. if ($object->id)
  76. {
  77. $langs->load("other");
  78. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  79. $ret=dol_delete_file($file,0,0,0,$object);
  80. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  81. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  82. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  83. exit;
  84. }
  85. }
  86. /*
  87. *
  88. */
  89. $form = new Form($db);
  90. llxHeader();
  91. if ($object->id)
  92. {
  93. $head=contract_prepare_head($object, $user);
  94. dol_fiche_head($head, 'documents', $langs->trans("Contract"), 0, 'contract');
  95. // Construit liste des fichiers
  96. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  97. $totalsize=0;
  98. foreach($filearray as $key => $file)
  99. {
  100. $totalsize+=$file['size'];
  101. }
  102. print '<table class="border" width="100%">';
  103. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  104. // Reference
  105. print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '').'</td></tr>';
  106. // Societe
  107. print '<tr><td>'.$langs->trans("Customer").'</td>';
  108. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  109. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  110. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  111. print '</table>';
  112. print '</div>';
  113. /*
  114. * Confirmation suppression fichier
  115. */
  116. if ($action == 'delete')
  117. {
  118. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  119. if ($ret == 'html') print '<br>';
  120. }
  121. // Affiche formulaire upload
  122. $formfile=new FormFile($db);
  123. $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->contrat->creer,50,$object);
  124. // List of document
  125. $param='&id='.$object->id;
  126. $formfile->list_of_documents($filearray,$object,'contract',$param);
  127. }
  128. else
  129. {
  130. print $langs->trans("UnkownError");
  131. }
  132. llxFooter();
  133. $db->close();
  134. ?>