PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fourn/commande/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 205 lines | 122 code | 39 blank | 44 comment | 24 complexity | 9f1bda48f238ce678aadacddc0f48a3c 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) 2012 Marcos GarcĂ­a <marcosgdf@gmail.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/fourn/commande/document.php
  23. * \ingroup supplier
  24. * \brief Page de gestion des documents attachees a une commande fournisseur
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  33. $langs->load('orders');
  34. $langs->load('other');
  35. $langs->load('sendings');
  36. $langs->load('companies');
  37. $langs->load('bills');
  38. $langs->load('deliveries');
  39. $langs->load('products');
  40. $langs->load('stocks');
  41. $id = GETPOST('id','int');
  42. $ref = GETPOST('ref', 'alpha');
  43. $action = GETPOST('action','alpha');
  44. $confirm = GETPOST('confirm','alpha');
  45. // Security check
  46. if ($user->societe_id) $socid=$user->societe_id;
  47. $result = restrictedArea($user, 'commande_fournisseur', $id,'');
  48. // Get parameters
  49. $sortfield = GETPOST("sortfield",'alpha');
  50. $sortorder = GETPOST("sortorder",'alpha');
  51. $page = GETPOST("page",'int');
  52. if ($page == -1) { $page = 0; }
  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 CommandeFournisseur($db);
  59. if ($object->fetch($id,$ref) < 0)
  60. {
  61. dol_print_error($db);
  62. exit;
  63. }
  64. $upload_dir = $conf->fournisseur->dir_output.'/commande/'.dol_sanitizeFileName($object->ref);
  65. $object->fetch_thirdparty();
  66. /*
  67. * Actions
  68. */
  69. // Envoi fichier
  70. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  71. {
  72. dol_add_file_process($upload_dir,0,1,'userfile');
  73. }
  74. else if ($action == 'confirm_deletefile' && $confirm == 'yes')
  75. {
  76. if ($object->id > 0)
  77. {
  78. $langs->load("other");
  79. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  80. $ret=dol_delete_file($file,0,0,0,$object);
  81. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  82. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  83. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  84. exit;
  85. }
  86. }
  87. /*
  88. * View
  89. */
  90. $form = new Form($db);
  91. if ($object->id > 0)
  92. {
  93. llxHeader();
  94. $author = new User($db);
  95. $author->fetch($object->user_author_id);
  96. $head = ordersupplier_prepare_head($object);
  97. dol_fiche_head($head, 'documents', $langs->trans('SupplierOrder'), 0, 'order');
  98. // Construit liste des fichiers
  99. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  100. $totalsize=0;
  101. foreach($filearray as $key => $file)
  102. {
  103. $totalsize+=$file['size'];
  104. }
  105. print '<table class="border" width="100%">';
  106. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  107. // Ref
  108. print '<tr><td width="35%">'.$langs->trans("Ref").'</td>';
  109. print '<td colspan="2">';
  110. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  111. print '</td>';
  112. print '</tr>';
  113. // Fournisseur
  114. print '<tr><td>'.$langs->trans("Supplier")."</td>";
  115. print '<td colspan="2">'.$object->thirdparty->getNomUrl(1,'supplier').'</td>';
  116. print '</tr>';
  117. // Statut
  118. print '<tr>';
  119. print '<td>'.$langs->trans("Status").'</td>';
  120. print '<td colspan="2">';
  121. print $object->getLibStatut(4);
  122. print "</td></tr>";
  123. // Date
  124. if ($object->methode_commande_id > 0)
  125. {
  126. print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">';
  127. if ($object->date_commande)
  128. {
  129. print dol_print_date($object->date_commande,"dayhourtext")."\n";
  130. }
  131. print "</td></tr>";
  132. if ($object->methode_commande)
  133. {
  134. print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$object->getInputMethod().'</td></tr>';
  135. }
  136. }
  137. // Auteur
  138. print '<tr><td>'.$langs->trans("AuthorRequest").'</td>';
  139. print '<td colspan="2">'.$author->getNomUrl(1).'</td>';
  140. print '</tr>';
  141. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  142. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  143. print "</table>\n";
  144. print "</div>\n";
  145. /*
  146. * Confirmation suppression fichier
  147. */
  148. if ($action == 'delete')
  149. {
  150. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  151. if ($ret == 'html') print '<br>';
  152. }
  153. // Affiche formulaire upload
  154. $formfile=new FormFile($db);
  155. $formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id,'',0,0,$user->rights->fournisseur->commande->creer,50,$object);
  156. // List of document
  157. $param='&id='.$object->id;
  158. $formfile->list_of_documents($filearray,$object,'commande_fournisseur',$param);
  159. }
  160. else
  161. {
  162. header('Location: index.php');
  163. }
  164. llxFooter();
  165. $db->close();
  166. ?>