PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/propal/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 180 lines | 106 code | 32 blank | 42 comment | 21 complexity | e775d4b48da714d4e22f070036d6c90d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-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/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/lib/images.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. $langs->load('compta');
  32. $langs->load('other');
  33. $action = GETPOST('action','alpha');
  34. $confirm = GETPOST('confirm','alpha');
  35. $id = GETPOST('id','int');
  36. $ref = GETPOST('ref','alpha');
  37. // Security check
  38. $socid='';
  39. if (! empty($user->societe_id))
  40. {
  41. $action='';
  42. $socid = $user->societe_id;
  43. }
  44. $result = restrictedArea($user, 'propal', $id);
  45. // Get parameters
  46. $sortfield = GETPOST("sortfield",'alpha');
  47. $sortorder = GETPOST("sortorder",'alpha');
  48. $page = GETPOST("page",'int');
  49. if ($page == -1) { $page = 0; }
  50. $offset = $conf->liste_limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (! $sortorder) $sortorder="ASC";
  54. if (! $sortfield) $sortfield="name";
  55. $object = new Propal($db);
  56. $object->fetch($id,$ref);
  57. if ($object->id > 0)
  58. {
  59. $object->fetch_thirdparty();
  60. }
  61. /*
  62. * Actions
  63. */
  64. // Envoi fichier
  65. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  66. {
  67. if ($object->id > 0)
  68. {
  69. $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
  70. dol_add_file_process($upload_dir,0,1,'userfile');
  71. }
  72. }
  73. // Delete
  74. if ($action == 'confirm_deletefile' && $confirm == 'yes')
  75. {
  76. if ($object->id > 0)
  77. {
  78. $langs->load("other");
  79. $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
  80. $file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  81. $ret=dol_delete_file($file,0,0,0,$object);
  82. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  83. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  84. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  85. exit;
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  92. $form = new Form($db);
  93. if ($object->id > 0)
  94. {
  95. $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref);
  96. $head = propal_prepare_head($object);
  97. dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
  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.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  107. // Ref
  108. print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
  109. print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
  110. print '</td></tr>';
  111. // Ref client
  112. print '<tr><td>';
  113. print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
  114. print $langs->trans('RefCustomer').'</td><td align="left">';
  115. print '</td>';
  116. print '</tr></table>';
  117. print '</td><td colspan="3">';
  118. print $object->ref_client;
  119. print '</td>';
  120. print '</tr>';
  121. // Customer
  122. print "<tr><td>".$langs->trans("Company")."</td>";
  123. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  124. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  125. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  126. print '</table>';
  127. print '</div>';
  128. /*
  129. * Confirmation suppression fichier
  130. */
  131. if ($action == 'delete')
  132. {
  133. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  134. if ($ret == 'html') print '<br>';
  135. }
  136. // Affiche formulaire upload
  137. $formfile=new FormFile($db);
  138. $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->propal->creer,50,$object);
  139. // List of document
  140. $formfile->list_of_documents($filearray,$object,'propal');
  141. }
  142. else
  143. {
  144. print $langs->trans("UnkownError");
  145. }
  146. llxFooter();
  147. $db->close();
  148. ?>