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

/htdocs/comm/propal/document.php

https://github.com/asterix14/dolibarr
PHP | 211 lines | 130 code | 39 blank | 42 comment | 26 complexity | e7e4b94a18f760cb8381f9eca309f93e MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2004 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-2011 Regis Houssin <regis@dolibarr.fr>
  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 2 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/comm/propal/document.php
  22. * \ingroup propale
  23. * \brief Page de gestion des documents attaches a une proposition commerciale
  24. */
  25. require("../../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  30. $langs->load('compta');
  31. $langs->load('other');
  32. $action = GETPOST('action');
  33. $confirm = GETPOST('confirm');
  34. $id = GETPOST('id');
  35. $ref = GETPOST('ref');
  36. // Security check
  37. if ($user->societe_id)
  38. {
  39. $action='';
  40. $socid = $user->societe_id;
  41. }
  42. $result = restrictedArea($user, 'propale', $id, 'propal');
  43. // Get parameters
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if ($page == -1) { $page = 0; }
  48. $offset = $conf->liste_limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (! $sortorder) $sortorder="ASC";
  52. if (! $sortfield) $sortfield="name";
  53. $object = new Propal($db);
  54. /*
  55. * Actions
  56. */
  57. // Envoi fichier
  58. if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  59. {
  60. if ($object->fetch($id))
  61. {
  62. $object->fetch_thirdparty();
  63. $upload_dir = $conf->propale->dir_output . "/" . dol_sanitizeFileName($object->ref);
  64. if (create_exdir($upload_dir) >= 0)
  65. {
  66. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  67. if (is_numeric($resupload) && $resupload > 0)
  68. {
  69. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  70. }
  71. else
  72. {
  73. $langs->load("errors");
  74. if ($resupload < 0) // Unknown error
  75. {
  76. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  77. }
  78. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  79. {
  80. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  81. }
  82. else // Known error
  83. {
  84. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  85. }
  86. }
  87. }
  88. }
  89. }
  90. // Delete
  91. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  92. {
  93. if ($object->fetch($id))
  94. {
  95. $object->fetch_thirdparty();
  96. $upload_dir = $conf->propale->dir_output . "/" . dol_sanitizeFileName($object->ref);
  97. $file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  98. dol_delete_file($file,0,0,0,$object);
  99. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  100. }
  101. }
  102. /*
  103. * View
  104. */
  105. llxHeader();
  106. $form = new Form($db);
  107. if ($id > 0 || ! empty($ref))
  108. {
  109. if ($object->fetch($id,$ref))
  110. {
  111. $object->fetch_thirdparty();
  112. $upload_dir = $conf->propale->dir_output.'/'.dol_sanitizeFileName($object->ref);
  113. $head = propal_prepare_head($object);
  114. dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
  115. // Construit liste des fichiers
  116. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  117. $totalsize=0;
  118. foreach($filearray as $key => $file)
  119. {
  120. $totalsize+=$file['size'];
  121. }
  122. print '<table class="border"width="100%">';
  123. $linkback='<a href="'.DOL_URL_ROOT.'/comm/propal.php'."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder".'">'.$langs->trans("BackToList").'</a>';
  124. // Ref
  125. print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
  126. print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
  127. print '</td></tr>';
  128. // Ref client
  129. print '<tr><td>';
  130. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  131. print $langs->trans('RefCustomer').'</td><td align="left">';
  132. print '</td>';
  133. print '</tr></table>';
  134. print '</td><td colspan="3">';
  135. print $object->ref_client;
  136. print '</td>';
  137. print '</tr>';
  138. // Customer
  139. print "<tr><td>".$langs->trans("Company")."</td>";
  140. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></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>';
  144. print '</div>';
  145. dol_htmloutput_mesg($mesg,$mesgs);
  146. /*
  147. * Confirmation suppression fichier
  148. */
  149. if ($action == 'delete')
  150. {
  151. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  152. if ($ret == 'html') print '<br>';
  153. }
  154. // Affiche formulaire upload
  155. $formfile=new FormFile($db);
  156. $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id,'',0,0,$user->rights->propale->creer);
  157. // List of document
  158. $param='&id='.$object->id;
  159. $formfile->list_of_documents($filearray,$object,'propal',$param);
  160. }
  161. else
  162. {
  163. dol_print_error($db);
  164. }
  165. }
  166. else
  167. {
  168. print $langs->trans("UnkownError");
  169. }
  170. $db->close();
  171. llxFooter();
  172. ?>