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/**
19 *  \file       mo_note.php
20 *  \ingroup    mrp
21 *  \brief      Card with notes on Mo
22 */
23
24// Load Dolibarr environment
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
28
29dol_include_once('/mrp/class/mo.class.php');
30dol_include_once('/mrp/lib/mrp_mo.lib.php');
31
32// Load translation files required by the page
33$langs->loadLangs(array("mrp", "companies"));
34
35// Get parameters
36$id = GETPOST('id', 'int');
37$ref        = GETPOST('ref', 'alpha');
38$action = GETPOST('action', 'aZ09');
39$cancel     = GETPOST('cancel', 'aZ09');
40$backtopage = GETPOST('backtopage', 'alpha');
41
42// Initialize technical objects
43$object = new Mo($db);
44$extrafields = new ExtraFields($db);
45$diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
46$hookmanager->initHooks(array('monote', 'globalcard')); // Note that conf->hooks_modules contains array
47
48// Fetch optionals attributes and labels
49$extrafields->fetch_name_optionals_label($object->table_element);
50
51// Load object
52include 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
53if ($id > 0 || !empty($ref)) {
54	$upload_dir = $conf->mrp->multidir_output[$object->entity]."/".$object->id;
55}
56
57// Security check - Protection if external user
58//if ($user->socid > 0) accessforbidden();
59//if ($user->socid > 0) $socid = $user->socid;
60$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
61$result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
62
63$permissionnote = $user->rights->mrp->write;	// Used by the include of actions_setnotes.inc.php
64
65
66
67/*
68 * Actions
69 */
70
71include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
72
73
74/*
75 * View
76 */
77
78$form = new Form($db);
79$formproject = new FormProjets($db);
80
81//$help_url='EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes';
82$help_url = '';
83llxHeader('', $langs->trans('Mo'), $help_url);
84
85if ($id > 0 || !empty($ref)) {
86	$object->fetch_thirdparty();
87
88	$head = moPrepareHead($object);
89
90	print dol_get_fiche_head($head, 'note', $langs->trans("ManufacturingOrder"), -1, $object->picto);
91
92	// Object card
93	// ------------------------------------------------------------
94	$linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
95
96	$morehtmlref = '<div class="refidno">';
97	// Ref customer
98	//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
99	//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
100	// Thirdparty
101	$morehtmlref .= $langs->trans('ThirdParty').' : '.(is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
102	// Project
103	if (!empty($conf->projet->enabled)) {
104		$langs->load("projects");
105		$morehtmlref .= '<br>'.$langs->trans('Project').' ';
106		if ($permissiontoadd) {
107			if ($action != 'classify') {
108				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
109			}
110			if ($action == 'classify') {
111				//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 1);
112				$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
113				$morehtmlref .= '<input type="hidden" name="action" value="classin">';
114				$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
115				$morehtmlref .= $formproject->select_projects($object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
116				$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
117				$morehtmlref .= '</form>';
118			} else {
119				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_soc, $object->fk_project, 'none', 0, 0, 0, 1);
120			}
121		} else {
122			if (!empty($object->fk_project)) {
123				$proj = new Project($db);
124				$proj->fetch($object->fk_project);
125				$morehtmlref .= ' : '.$proj->getNomUrl();
126			} else {
127				$morehtmlref .= '';
128			}
129		}
130	}
131	$morehtmlref .= '</div>';
132
133	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
134
135
136	print '<div class="fichecenter">';
137	print '<div class="underbanner clearboth"></div>';
138
139
140	$cssclass = "titlefield";
141	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
142
143	print '</div>';
144
145	print dol_get_fiche_end();
146}
147
148// End of page
149llxFooter();
150$db->close();
151