mo_document.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  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 3 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 mo_document.php
  19. * \ingroup mrp
  20. * \brief Tab for documents linked to Mo
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  30. dol_include_once('/mrp/class/mo.class.php');
  31. dol_include_once('/mrp/lib/mrp_mo.lib.php');
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("mrp", "companies", "other", "mails"));
  34. $action = GETPOST('action', 'aZ09');
  35. $confirm = GETPOST('confirm');
  36. $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
  37. $ref = GETPOST('ref', 'alpha');
  38. // Get parameters
  39. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  40. $sortfield = GETPOST('sortfield', 'aZ09comma');
  41. $sortorder = GETPOST('sortorder', 'aZ09comma');
  42. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  43. if (empty($page) || $page == -1) {
  44. $page = 0;
  45. } // If $page is not defined, or '' or -1
  46. $offset = $limit * $page;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. if (!$sortorder) {
  50. $sortorder = "ASC";
  51. }
  52. if (!$sortfield) {
  53. $sortfield = "name";
  54. }
  55. //if (! $sortfield) $sortfield="position_name";
  56. // Initialize technical objects
  57. $object = new Mo($db);
  58. $extrafields = new ExtraFields($db);
  59. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('modocument', 'globalcard')); // Note that conf->hooks_modules contains array
  61. // Fetch optionals attributes and labels
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. // Load object
  64. 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
  65. if ($id > 0 || !empty($ref)) {
  66. $upload_dir = $conf->mrp->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object);
  67. }
  68. // Security check - Protection if external user
  69. //if ($user->socid > 0) accessforbidden();
  70. //if ($user->socid > 0) $socid = $user->socid;
  71. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  72. $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
  73. $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  74. /*
  75. * Actions
  76. */
  77. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
  78. /*
  79. * View
  80. */
  81. $form = new Form($db);
  82. $formproject = new FormProjets($db);
  83. $title = $langs->trans("Mo").' - '.$langs->trans("Files");
  84. $help_url = '';
  85. //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  86. llxHeader('', $title, $help_url);
  87. if ($object->id) {
  88. /*
  89. * Show tabs
  90. */
  91. $head = moPrepareHead($object);
  92. print dol_get_fiche_head($head, 'document', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  93. // Build file list
  94. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  95. $totalsize = 0;
  96. foreach ($filearray as $key => $file) {
  97. $totalsize += $file['size'];
  98. }
  99. // Object card
  100. // ------------------------------------------------------------
  101. $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  102. $morehtmlref = '<div class="refidno">';
  103. // Ref customer
  104. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  105. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  106. // Thirdparty
  107. $morehtmlref .= $langs->trans('ThirdParty').' : '.(is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  108. // Project
  109. if (!empty($conf->project->enabled)) {
  110. $langs->load("projects");
  111. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  112. if ($permissiontoadd) {
  113. if ($action != 'classify') {
  114. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  115. }
  116. if ($action == 'classify') {
  117. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 1);
  118. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  119. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  120. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  121. $morehtmlref .= $formproject->select_projects($object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  122. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  123. $morehtmlref .= '</form>';
  124. } else {
  125. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_soc, $object->fk_project, 'none', 0, 0, 0, 1);
  126. }
  127. } else {
  128. if (!empty($object->fk_project)) {
  129. $proj = new Project($db);
  130. $proj->fetch($object->fk_project);
  131. $morehtmlref .= ': '.$proj->getNomUrl();
  132. } else {
  133. $morehtmlref .= '';
  134. }
  135. }
  136. }
  137. $morehtmlref .= '</div>';
  138. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  139. print '<div class="fichecenter">';
  140. print '<div class="underbanner clearboth"></div>';
  141. print '<table class="border centpercent tableforfield">';
  142. // Number of files
  143. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  144. // Total size
  145. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
  146. print '</table>';
  147. print '</div>';
  148. print dol_get_fiche_end();
  149. $modulepart = 'mrp';
  150. $permissiontoadd = $user->rights->mrp->write;
  151. $permtoedit = $user->rights->mrp->write;
  152. $param = '&id='.$object->id;
  153. //$relativepathwithnofile='mo/' . dol_sanitizeFileName($object->id).'/';
  154. $relativepathwithnofile = dol_sanitizeFileName($object->ref).'/';
  155. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  156. } else {
  157. accessforbidden('', 0, 1);
  158. }
  159. // End of page
  160. llxFooter();
  161. $db->close();