dolibarr  13.0.2
bom.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
3  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
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 
31 {
32  global $langs, $conf;
33 
34  $langs->load("mrp");
35 
36  $h = 0;
37  $head = array();
38 
39  $head[$h][0] = DOL_URL_ROOT."/admin/bom.php";
40  $head[$h][1] = $langs->trans("Settings");
41  $head[$h][2] = 'settings';
42  $h++;
43 
44  $head[$h][0] = dol_buildpath("/admin/bom_extrafields.php", 1);
45  $head[$h][1] = $langs->trans("ExtraFields");
46  $head[$h][2] = 'bom_extrafields';
47  $h++;
48 
49  /*$head[$h][0] = DOL_URL_ROOT."/bom/admin/about.php";
50  $head[$h][1] = $langs->trans("About");
51  $head[$h][2] = 'about';
52  $h++;
53  */
54 
55  // Show more tabs from modules
56  // Entries must be declared in modules descriptor with line
57  //$this->tabs = array(
58  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
59  //); // to add new tab
60  //$this->tabs = array(
61  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
62  //); // to remove a tab
63  complete_head_from_modules($conf, $langs, null, $head, $h, 'bom');
64 
65  return $head;
66 }
67 
68 
69 
70 
77 function bomPrepareHead($object)
78 {
79  global $db, $langs, $conf;
80 
81  $langs->load("mrp");
82 
83  $h = 0;
84  $head = array();
85 
86  $head[$h][0] = DOL_URL_ROOT."/bom/bom_card.php?id=".$object->id;
87  $head[$h][1] = $langs->trans("BOM");
88  $head[$h][2] = 'card';
89  $h++;
90 
91  if (isset($object->fields['note_public']) || isset($object->fields['note_private']))
92  {
93  $nbNote = 0;
94  if (!empty($object->note_private)) $nbNote++;
95  if (!empty($object->note_public)) $nbNote++;
96  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_note.php?id='.$object->id;
97  $head[$h][1] = $langs->trans('Notes');
98  if ($nbNote > 0) $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
99  $head[$h][2] = 'note';
100  $h++;
101  }
102 
103  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
104  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
105  $upload_dir = $conf->bom->dir_output."/bom/".dol_sanitizeFileName($object->ref);
106  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
107  $nbLinks = Link::count($db, $object->element, $object->id);
108  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_document.php?id='.$object->id;
109  $head[$h][1] = $langs->trans('Documents');
110  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
111  $head[$h][2] = 'document';
112  $h++;
113 
114  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id;
115  $head[$h][1] = $langs->trans("Events");
116  $head[$h][2] = 'agenda';
117  $h++;
118 
119  // Show more tabs from modules
120  // Entries must be declared in modules descriptor with line
121  //$this->tabs = array(
122  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
123  //); // to add new tab
124  //$this->tabs = array(
125  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
126  //); // to remove a tab
127  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
128 
129  return $head;
130 }
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Definition: bom.lib.php:77
bomAdminPrepareHead()
Prepare admin pages header.
Definition: bom.lib.php:30
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).