PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fichinter/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 171 lines | 89 code | 40 blank | 42 comment | 20 complexity | 256674b786241182535b7f78f7fdf7e1 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-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.houssin@capnetworks.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2011-2012 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 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/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/images.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. $langs->load("other");
  34. $langs->load("fichinter");
  35. $langs->load("companies");
  36. $langs->load("interventions");
  37. $id = GETPOST('id','int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action','alpha');
  40. $confirm = GETPOST('confirm','alpha');
  41. // Security check
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  44. // Get parameters
  45. $sortfield = GETPOST('sortfield','alpha');
  46. $sortorder = GETPOST('sortorder','alpha');
  47. $page = GETPOST('page','int');
  48. if ($page == -1) { $page = 0; }
  49. $offset = $conf->liste_limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (! $sortorder) $sortorder="ASC";
  53. if (! $sortfield) $sortfield="name";
  54. $object = new Fichinter($db);
  55. $object->fetch($id, $ref);
  56. $upload_dir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($object->ref);
  57. $modulepart='fichinter';
  58. /*
  59. * Actions
  60. */
  61. if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  62. {
  63. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  64. dol_add_file_process($upload_dir,0,1,'userfile');
  65. }
  66. // Delete
  67. else if ($action == 'confirm_deletefile' && $confirm == 'yes')
  68. {
  69. if ($object->id > 0)
  70. {
  71. $langs->load("other");
  72. $object->fetch_thirdparty();
  73. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  74. $ret=dol_delete_file($file,0,0,0,$object);
  75. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  76. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  77. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  78. exit;
  79. }
  80. }
  81. /*
  82. * View
  83. */
  84. $form = new Form($db);
  85. llxHeader("","",$langs->trans("InterventionCard"));
  86. if ($object->id)
  87. {
  88. $object->fetch_thirdparty();
  89. $head=fichinter_prepare_head($object, $user);
  90. dol_fiche_head($head, 'documents', $langs->trans("InterventionCard"), 0, 'intervention');
  91. // Construit liste des fichiers
  92. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  93. $totalsize=0;
  94. foreach($filearray as $key => $file)
  95. {
  96. $totalsize+=$file['size'];
  97. }
  98. print '<table class="border" width="100%">';
  99. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  100. // Ref
  101. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  102. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  103. print '</td></tr>';
  104. // Societe
  105. print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
  106. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  107. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  108. print '</table>';
  109. print '</div>';
  110. /*
  111. * Confirmation suppression fichier
  112. */
  113. if ($action == 'delete')
  114. {
  115. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  116. if ($ret == 'html') print '<br>';
  117. }
  118. // Affiche formulaire upload
  119. $formfile=new FormFile($db);
  120. $formfile->form_attach_new_file(DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id,'',0,0,$user->rights->ficheinter->creer,50,$object);
  121. // List of document
  122. $param='&id='.$object->id;
  123. $formfile->list_of_documents($filearray,$object,'ficheinter',$param);
  124. }
  125. else
  126. {
  127. print $langs->trans("UnkownError");
  128. }
  129. llxFooter();
  130. $db->close();
  131. ?>