PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/action/document.php

https://github.com/asterix14/dolibarr
PHP | 240 lines | 154 code | 40 blank | 46 comment | 32 complexity | 669694c17c91d8f7b1774328549b0b35 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-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.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 2 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/comm/action/document.php
  23. * \ingroup agenda
  24. * \brief Page of documents linked to actions
  25. */
  26. require("../../main.inc.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/agenda.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  32. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  33. if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  34. $langs->load("companies");
  35. $langs->load("commercial");
  36. $langs->load("other");
  37. $langs->load("bills");
  38. if (isset($_GET["error"])) $error=$_GET["error"];
  39. $objectid = GETPOST("id");
  40. // Security check
  41. if ($user->societe_id > 0)
  42. {
  43. unset($_GET["action"]);
  44. $action='';
  45. $socid = $user->societe_id;
  46. }
  47. // Get parameters
  48. $sortfield = GETPOST("sortfield",'alpha');
  49. $sortorder = GETPOST("sortorder",'alpha');
  50. $page = GETPOST("page",'int');
  51. if ($page == -1) { $page = 0; }
  52. $offset = $conf->liste_limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (! $sortorder) $sortorder="ASC";
  56. if (! $sortfield) $sortfield="name";
  57. /*
  58. * Action envoie fichier
  59. */
  60. if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  61. {
  62. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  63. // Creation repertoire si n'existe pas
  64. $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
  65. if (create_exdir($upload_dir) >= 0)
  66. {
  67. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
  68. if (is_numeric($resupload) && $resupload > 0)
  69. {
  70. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  71. }
  72. else
  73. {
  74. $langs->load("errors");
  75. if ($resupload < 0) // Unknown error
  76. {
  77. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  78. }
  79. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  80. {
  81. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  82. }
  83. else // Known error
  84. {
  85. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  86. }
  87. }
  88. }
  89. }
  90. /*
  91. * Efface fichier
  92. */
  93. if ($_GET["action"] == 'delete')
  94. {
  95. $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
  96. $file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  97. dol_delete_file($file);
  98. }
  99. /*
  100. * View
  101. */
  102. $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  103. llxHeader('',$langs->trans("Agenda"),$help_url);
  104. if ($objectid > 0)
  105. {
  106. $act = new ActionComm($db);
  107. if ($act->fetch($objectid))
  108. {
  109. $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
  110. $company=new Societe($db);
  111. $company->fetch($act->societe->id);
  112. $act->societe=$company;
  113. $author=new User($db);
  114. $author->fetch($act->author->id);
  115. $act->author=$author;
  116. if ($act->contact->id) $act->fetch_contact($act->contact->id);
  117. $head=actions_prepare_head($act);
  118. dol_fiche_head($head, 'documents', $langs->trans("Action"),0,'action');
  119. // Affichage fiche action en mode visu
  120. print '<table class="border" width="100%"';
  121. // Ref
  122. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">'.$act->id.'</td></tr>';
  123. // Type
  124. print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
  125. // Title
  126. print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
  127. // Location
  128. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
  129. // Societe - contact
  130. print '<tr><td>'.$langs->trans("Company").'</td><td>'.($act->societe->id?$act->societe->getNomUrl(1):$langs->trans("None"));
  131. if ($act->societe->id && $act->type_code == 'AC_TEL')
  132. {
  133. if ($act->societe->fetch($act->societe->id))
  134. {
  135. print "<br>".dol_print_phone($act->societe->tel);
  136. }
  137. }
  138. print '</td>';
  139. print '<td>'.$langs->trans("Contact").'</td>';
  140. print '<td>';
  141. if ($act->contact->id > 0)
  142. {
  143. print $act->contact->getNomUrl(1);
  144. if ($act->contact->id && $act->type_code == 'AC_TEL')
  145. {
  146. if ($act->contact->fetch($act->contact->id))
  147. {
  148. print "<br>".dol_print_phone($act->contact->phone_pro);
  149. }
  150. }
  151. }
  152. else
  153. {
  154. print $langs->trans("None");
  155. }
  156. print '</td></tr>';
  157. // Project
  158. if ($conf->projet->enabled)
  159. {
  160. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
  161. if ($act->fk_project)
  162. {
  163. $project=new Project($db);
  164. $project->fetch($act->fk_project);
  165. print $project->getNomUrl(1);
  166. }
  167. print '</td></tr>';
  168. }
  169. print '</table><br><table class="border" width="100%">';
  170. // Construit liste des fichiers
  171. $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  172. $totalsize=0;
  173. foreach($filearray as $key => $file)
  174. {
  175. $totalsize+=$file['size'];
  176. }
  177. print '<tr><td width="30%" nowrap>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  178. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  179. print '</table>';
  180. print '</div>';
  181. if ($mesg) { print $mesg."<br>"; }
  182. // Affiche formulaire upload
  183. $formfile=new FormFile($db);
  184. $formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create));
  185. // List of document
  186. $param='&id='.$act->id;
  187. $formfile->list_of_documents($filearray,$act,'actions',$param,0,'',$user->rights->agenda->myactions->create);
  188. }
  189. else
  190. {
  191. dol_print_error($db);
  192. }
  193. }
  194. else
  195. {
  196. print $langs->trans("UnkownError");
  197. }
  198. $db->close();
  199. llxFooter();
  200. ?>