PageRenderTime 79ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/tasks/document.php

https://github.com/asterix14/dolibarr
PHP | 207 lines | 121 code | 43 blank | 43 comment | 22 complexity | f5dfc0e40f3fe38e3244b46ef517a4ac 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/tasks/document.php
  19. * \ingroup project
  20. * \brief Page de gestion des documents attachees a une tache d'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."/projet/class/task.class.php");
  25. require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
  26. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  28. $langs->load('projects');
  29. $langs->load('other');
  30. $action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
  31. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  32. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  33. $id = isset($_GET["id"])?$_GET["id"]:'';
  34. // Security check
  35. $socid=0;
  36. if ($user->societe_id > 0) $socid = $user->societe_id;
  37. //$result=restrictedArea($user,'projet',$id,'');
  38. if (!$user->rights->projet->lire) accessforbidden();
  39. // Get parameters
  40. $sortfield = GETPOST("sortfield",'alpha');
  41. $sortorder = GETPOST("sortorder",'alpha');
  42. $page = GETPOST("page",'int');
  43. if ($page == -1) { $page = 0; }
  44. $offset = $conf->liste_limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (! $sortorder) $sortorder="ASC";
  48. if (! $sortfield) $sortfield="name";
  49. $id = $_GET['id'];
  50. $ref= $_GET['ref'];
  51. $task = new Task($db);
  52. if ($task->fetch($id,$ref) > 0)
  53. {
  54. $projectstatic = new Project($db);
  55. $projectstatic->fetch($task->fk_project);
  56. if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
  57. $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($task->ref);
  58. }
  59. else
  60. {
  61. dol_print_error($db);
  62. }
  63. /*
  64. * Actions
  65. */
  66. // Envoi fichier
  67. if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  68. {
  69. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  70. if (create_exdir($upload_dir) >= 0)
  71. {
  72. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  73. if (is_numeric($resupload) && $resupload > 0)
  74. {
  75. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  76. }
  77. else
  78. {
  79. $langs->load("errors");
  80. if ($resupload < 0) // Unknown error
  81. {
  82. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  83. }
  84. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  85. {
  86. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  87. }
  88. else // Known error
  89. {
  90. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  91. }
  92. }
  93. }
  94. }
  95. // Delete
  96. if ($action=='delete')
  97. {
  98. $file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  99. dol_delete_file($file);
  100. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  101. }
  102. /*
  103. * View
  104. */
  105. $form = new Form($db);
  106. $project = new Project($db);
  107. llxHeader('',$langs->trans('Project'));
  108. if ($id > 0 || ! empty($ref))
  109. {
  110. $project = new Project($db);
  111. $project->fetch($task->fk_project);
  112. // To verify role of users
  113. //$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
  114. //$arrayofuseridoftask=$task->getListContactId('internal');
  115. $head = task_prepare_head($task);
  116. dol_fiche_head($head, 'document', $langs->trans("Task"), 0, 'projecttask');
  117. // Files list constructor
  118. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  119. $totalsize=0;
  120. foreach($filearray as $key => $file)
  121. {
  122. $totalsize+=$file['size'];
  123. }
  124. print '<table class="border" width="100%">';
  125. // Ref
  126. print '<tr><td width="30%">';
  127. print $langs->trans("Ref");
  128. print '</td><td colspan="3">';
  129. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  130. $task->next_prev_filter=" fk_projet in (".$projectsListId.")";
  131. print $form->showrefnav($task,'id','',1,'rowid','ref','','');
  132. print '</td>';
  133. print '</tr>';
  134. // Label
  135. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$task->label.'</td></tr>';
  136. // Project
  137. print '<tr><td>'.$langs->trans("Project").'</td><td colspan="3">';
  138. print $projectstatic->getNomUrl(1);
  139. print '</td></tr>';
  140. // Third party
  141. print '<td>'.$langs->trans("Company").'</td><td colspan="3">';
  142. if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
  143. else print '&nbsp;';
  144. print '</td></tr>';
  145. // Files infos
  146. print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  147. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  148. print "</table>\n";
  149. print "</div>\n";
  150. if ($mesg) { print $mesg."<br>"; }
  151. // Affiche formulaire upload
  152. $formfile=new FormFile($db);
  153. $formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/tasks/document.php?id='.$task->id,'',0,0,$user->rights->projet->creer);
  154. // List of document
  155. $param='&id='.$task->id;
  156. $formfile->list_of_documents($filearray,$task,'projet',$param,0,dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($task->ref).'/');
  157. }
  158. else
  159. {
  160. Header('Location: index.php');
  161. }
  162. $db->close();
  163. llxFooter();
  164. ?>