PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/commande/document.php

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