PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fichinter/document.php

https://github.com/asterix14/dolibarr
PHP | 176 lines | 98 code | 39 blank | 39 comment | 17 complexity | 817ba4a6bffbf6d653b79c1d59792458 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  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 2 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/fichinter/document.php
  24. * \ingroup fichinter
  25. * \brief Page des documents joints sur les contrats
  26. */
  27. require("../main.inc.php");
  28. require_once(DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/fichinter.lib.php");
  31. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  32. $langs->load("other");
  33. $langs->load("fichinter");
  34. $langs->load("companies");
  35. $langs->load("interventions");
  36. $fichinterid = GETPOST("id");
  37. $action = GETPOST("action");
  38. // Security check
  39. if ($user->societe_id) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
  41. // Get parameters
  42. $sortfield = GETPOST("sortfield",'alpha');
  43. $sortorder = GETPOST("sortorder",'alpha');
  44. $page = GETPOST("page",'int');
  45. if ($page == -1) { $page = 0; }
  46. $offset = $conf->liste_limit * $page;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. if (! $sortorder) $sortorder="ASC";
  50. if (! $sortfield) $sortfield="name";
  51. $object = new Fichinter($db);
  52. $object->fetch($fichinterid);
  53. $upload_dir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($object->ref);
  54. $modulepart='fichinter';
  55. /*
  56. * Action envoie fichier
  57. */
  58. if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
  59. {
  60. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  61. if (create_exdir($upload_dir) >= 0)
  62. {
  63. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  64. if (is_numeric($resupload) && $resupload > 0)
  65. {
  66. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  67. }
  68. else
  69. {
  70. $langs->load("errors");
  71. if ($resupload < 0) // Unknown error
  72. {
  73. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  74. }
  75. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  76. {
  77. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  78. }
  79. else // Known error
  80. {
  81. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  82. }
  83. }
  84. }
  85. }
  86. /*
  87. *
  88. */
  89. $form = new Form($db);
  90. llxHeader("","",$langs->trans("InterventionCard"));
  91. if ($object->id)
  92. {
  93. $object->fetch_thirdparty();
  94. $soc = new Societe($db);
  95. $soc->fetch($object->societe->id);
  96. if ( $error_msg )
  97. {
  98. echo '<div class="error">'.$error_msg.'</div><br>';
  99. }
  100. if ($action == 'delete')
  101. {
  102. $file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  103. $result=dol_delete_file($file);
  104. //if ($result >= 0) $mesg=$langs->trans("FileWasRemoced");
  105. }
  106. $head=fichinter_prepare_head($object, $user);
  107. dol_fiche_head($head, 'documents', $langs->trans("InterventionCard"), 0, 'intervention');
  108. // Construit liste des fichiers
  109. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  110. $totalsize=0;
  111. foreach($filearray as $key => $file)
  112. {
  113. $totalsize+=$file['size'];
  114. }
  115. print '<table class="border" width="100%">';
  116. // Ref
  117. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>'.$object->ref.'</td></tr>';
  118. // Societe
  119. print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
  120. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  121. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  122. print '</table>';
  123. print '</div>';
  124. // Affiche formulaire upload
  125. $formfile=new FormFile($db);
  126. $formfile->form_attach_new_file(DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id,'',0,0,$user->rights->ficheinter->creer);
  127. // List of document
  128. $param='&id='.$object->id;
  129. $formfile->list_of_documents($filearray,$object,'ficheinter',$param);
  130. }
  131. else
  132. {
  133. print $langs->trans("UnkownError");
  134. }
  135. $db->close();
  136. llxFooter();
  137. ?>