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

/htdocs/projet/document.php

https://github.com/asterix14/dolibarr
PHP | 205 lines | 121 code | 42 blank | 42 comment | 31 complexity | 1aabdea399c2155cc0f2f566fdbc81c2 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/projet/document.php
  19. * \ingroup project
  20. * \brief Page de gestion des documents attachees a un projet
  21. */
  22. require('../main.inc.php');
  23. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  24. require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  27. $langs->load('projects');
  28. $langs->load('other');
  29. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  30. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  31. $id = isset($_GET["id"])?$_GET["id"]:'';
  32. // Security check
  33. $socid=0;
  34. if ($user->societe_id > 0) $socid=$user->societe_id;
  35. $result=restrictedArea($user,'projet',$id,'');
  36. // Get parameters
  37. $sortfield = GETPOST("sortfield",'alpha');
  38. $sortorder = GETPOST("sortorder",'alpha');
  39. $page = GETPOST("page",'int');
  40. if ($page == -1) { $page = 0; }
  41. $offset = $conf->liste_limit * $page;
  42. $pageprev = $page - 1;
  43. $pagenext = $page + 1;
  44. if (! $sortorder) $sortorder="ASC";
  45. if (! $sortfield) $sortfield="name";
  46. $id = $_GET['id'];
  47. $ref= $_GET['ref'];
  48. $project = new Project($db);
  49. if (! $project->fetch($_GET['id'],$_GET['ref']) > 0)
  50. {
  51. dol_print_error($db);
  52. exit;
  53. }
  54. /*
  55. * Actions
  56. */
  57. // Envoi fichier
  58. if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  59. {
  60. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  61. $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($project->ref);
  62. if (create_exdir($upload_dir) >= 0)
  63. {
  64. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  65. if (is_numeric($resupload) && $resupload > 0)
  66. {
  67. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  68. }
  69. else
  70. {
  71. $langs->load("errors");
  72. if ($resupload < 0) // Unknown error
  73. {
  74. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  75. }
  76. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  77. {
  78. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  79. }
  80. else // Known error
  81. {
  82. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  83. }
  84. }
  85. }
  86. }
  87. // Delete
  88. if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->projet->supprimer)
  89. {
  90. $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($project->ref);
  91. $file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  92. dol_delete_file($file);
  93. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  94. }
  95. /*
  96. * View
  97. */
  98. llxHeader('',$langs->trans('Project'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
  99. $form = new Form($db);
  100. if ($id > 0 || ! empty($ref))
  101. {
  102. $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref);
  103. $company = new Societe($db);
  104. $company->fetch($project->socid);
  105. if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id);
  106. // To verify role of users
  107. $userAccess = $project->restrictedProjectArea($user);
  108. $head = project_prepare_head($project);
  109. dol_fiche_head($head, 'document', $langs->trans("Project"), 0, ($project->public?'projectpub':'project'));
  110. // Files list constructor
  111. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  112. $totalsize=0;
  113. foreach($filearray as $key => $file)
  114. {
  115. $totalsize+=$file['size'];
  116. }
  117. if ($_GET["action"] == 'delete')
  118. {
  119. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"]."&urlfile=".$_GET['urlfile'],$langs->trans("DeleteAFile"),$langs->trans("ConfirmDeleteAFile"),"confirm_delete",'','',1);
  120. if ($ret == 'html') print '<br>';
  121. }
  122. print '<table class="border" width="100%">';
  123. // Ref
  124. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  125. // Define a complementary filter for search of next/prev ref.
  126. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  127. $project->next_prev_filter=" rowid in (".$projectsListId.")";
  128. print $form->showrefnav($project,'ref','',1,'ref','ref');
  129. print '</td></tr>';
  130. // Label
  131. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
  132. // Company
  133. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  134. if (! empty($project->societe->id)) print $project->societe->getNomUrl(1);
  135. else print '&nbsp;';
  136. print '</td></tr>';
  137. // Visibility
  138. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  139. if ($project->public) print $langs->trans('SharedProject');
  140. else print $langs->trans('PrivateProject');
  141. print '</td></tr>';
  142. // Statut
  143. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
  144. // Files infos
  145. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  146. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  147. print "</table>\n";
  148. print "</div>\n";
  149. if ($mesg) { print $mesg."<br>"; }
  150. // Affiche formulaire upload
  151. $formfile=new FormFile($db);
  152. $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/document.php?id='.$project->id,'',0,0,$user->rights->projet->creer);
  153. // List of document
  154. $param='&id='.$project->id;
  155. $formfile->list_of_documents($filearray,$project,'projet',$param);
  156. }
  157. else
  158. {
  159. Header('Location: index.php');
  160. }
  161. $db->close();
  162. llxFooter();
  163. ?>