myobject_document.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/myobject_document.php
  20. * \ingroup mymodule
  21. * \brief Tab for documents linked to MyObject
  22. */
  23. // Load Dolibarr environment
  24. $res = 0;
  25. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  26. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  27. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  28. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  29. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  30. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  31. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  32. // Try main.inc.php using relative path
  33. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  34. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  35. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  36. if (!$res) die("Include of main fails");
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  41. dol_include_once('/mymodule/class/myobject.class.php');
  42. dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
  43. // Load translation files required by the page
  44. $langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
  45. $action = GETPOST('action', 'aZ09');
  46. $confirm = GETPOST('confirm');
  47. $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
  48. $ref = GETPOST('ref', 'alpha');
  49. // Get parameters
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST("sortfield", 'alpha');
  52. $sortorder = GETPOST("sortorder", 'alpha');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  55. $offset = $liste_limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortorder) $sortorder = "ASC";
  59. if (!$sortfield) $sortfield = "name";
  60. //if (! $sortfield) $sortfield="position_name";
  61. // Initialize technical objects
  62. $object = new MyObject($db);
  63. $extrafields = new ExtraFields($db);
  64. $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  65. $hookmanager->initHooks(array('myobjectdocument', 'globalcard')); // Note that conf->hooks_modules contains array
  66. // Fetch optionals attributes and labels
  67. $extrafields->fetch_name_optionals_label($object->table_element);
  68. // Load object
  69. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  70. //if ($id > 0 || ! empty($ref)) $upload_dir = $conf->mymodule->multidir_output[$object->entity?$object->entity:$conf->entity] . "/myobject/" . dol_sanitizeFileName($object->id);
  71. if ($id > 0 || !empty($ref)) $upload_dir = $conf->mymodule->multidir_output[$object->entity ? $object->entity : $conf->entity]."/myobject/".dol_sanitizeFileName($object->ref);
  72. // Security check - Protection if external user
  73. //if ($user->socid > 0) accessforbidden();
  74. //if ($user->socid > 0) $socid = $user->socid;
  75. //$result = restrictedArea($user, 'mymodule', $object->id);
  76. $permissiontoadd = $user->rights->mymodule->myobject->write; // Used by the include of actions_addupdatedelete.inc.php
  77. /*
  78. * Actions
  79. */
  80. include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  81. /*
  82. * View
  83. */
  84. $form = new Form($db);
  85. $title = $langs->trans("MyObject").' - '.$langs->trans("Files");
  86. $help_url = '';
  87. //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  88. llxHeader('', $title, $help_url);
  89. if ($object->id)
  90. {
  91. /*
  92. * Show tabs
  93. */
  94. $head = myobjectPrepareHead($object);
  95. dol_fiche_head($head, 'document', $langs->trans("MyObject"), -1, $object->picto);
  96. // Build file list
  97. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  98. $totalsize = 0;
  99. foreach ($filearray as $key => $file)
  100. {
  101. $totalsize += $file['size'];
  102. }
  103. // Object card
  104. // ------------------------------------------------------------
  105. $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  106. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  107. print '<div class="fichecenter">';
  108. print '<div class="underbanner clearboth"></div>';
  109. print '<table class="border centpercent tableforfield">';
  110. // Number of files
  111. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  112. // Total size
  113. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  114. print '</table>';
  115. print '</div>';
  116. dol_fiche_end();
  117. $modulepart = 'mymodule';
  118. //$permission = $user->rights->mymodule->myobject->write;
  119. $permission = 1;
  120. //$permtoedit = $user->rights->mymodule->myobject->write;
  121. $permtoedit = 1;
  122. $param = '&id='.$object->id;
  123. //$relativepathwithnofile='myobject/' . dol_sanitizeFileName($object->id).'/';
  124. $relativepathwithnofile = 'myobject/'.dol_sanitizeFileName($object->ref).'/';
  125. include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  126. }
  127. else
  128. {
  129. accessforbidden('', 0, 1);
  130. }
  131. // End of page
  132. llxFooter();
  133. $db->close();