PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/htdocs/product/inventory/card.php

http://github.com/Dolibarr/dolibarr
PHP | 425 lines | 207 code | 90 blank | 128 comment | 40 complexity | 60f99b75c3713612ac8aa940ba325db4 MD5 | raw file
  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 <https://www.gnu.org/licenses/>.
 16 */
 17
 18/**
 19 *   	\file       htdocs/product/inventory/card.php
 20 *		\ingroup    inventory
 21 *		\brief      Inventory card
 22 */
 23
 24require '../../main.inc.php';
 25include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
 26include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
 27include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
 28
 29// Load translation files required by the page
 30$langs->loadLangs(array("stocks", "other"));
 31
 32// Get parameters
 33$id = GETPOST('id', 'int');
 34$ref        = GETPOST('ref', 'alpha');
 35$action = GETPOST('action', 'aZ09');
 36$confirm    = GETPOST('confirm', 'alpha');
 37$cancel     = GETPOST('cancel', 'aZ09');
 38$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
 39$backtopage = GETPOST('backtopage', 'alpha');
 40
 41if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
 42{
 43	$result = restrictedArea($user, 'stock', $id);
 44}
 45else
 46{
 47	$result = restrictedArea($user, 'stock', $id, '', 'inventory_advance');
 48}
 49
 50// Initialize technical objects
 51$object = new Inventory($db);
 52$extrafields = new ExtraFields($db);
 53$diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
 54$hookmanager->initHooks(array('inventorycard')); // Note that conf->hooks_modules contains array
 55
 56// Fetch optionals attributes and labels
 57$extrafields->fetch_name_optionals_label($object->table_element);
 58
 59$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
 60
 61// Initialize array of search criterias
 62$search_all = trim(GETPOST("search_all", 'alpha'));
 63$search = array();
 64foreach ($object->fields as $key => $val)
 65{
 66    if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
 67}
 68
 69if (empty($action) && empty($id) && empty($ref)) $action = 'view';
 70
 71// Load object
 72include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
 73
 74// Security check - Protection if external user
 75//if ($user->socid > 0) accessforbidden();
 76//if ($user->socid > 0) $socid = $user->socid;
 77//$result = restrictedArea($user, 'mymodule', $id);
 78
 79if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
 80{
 81	$permissiontoadd = $user->rights->stock->creer;
 82	$permissiontodelete = $user->rights->stock->supprimer;
 83}
 84else
 85{
 86	$permissiontoadd = $user->rights->stock->inventory_advance->write;
 87	$permissiontodelete = $user->rights->stock->inventory_advance->write;
 88}
 89
 90
 91/*
 92 * Actions
 93 */
 94
 95$parameters = array();
 96$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
 97if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 98
 99if (empty($reshook))
100{
101	$error = 0;
102
103	$backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php';
104
105	// Actions cancel, add, update, delete or clone
106	include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
107
108	// Actions when linking object each other
109	include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
110
111	// Actions when printing a doc from card
112	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
113
114	// Actions to send emails
115	/*$triggersendname = 'MYOBJECT_SENTBYMAIL';
116	$autocopy='MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
117	$trackid='myobject'.$object->id;
118	include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';*/
119}
120
121
122
123
124/*
125 * View
126 */
127
128$form = new Form($db);
129
130llxHeader('', $langs->trans('Inventory'), '');
131
132// Example : Adding jquery code
133print '<script type="text/javascript" language="javascript">
134jQuery(document).ready(function() {
135	function init_myfunc()
136	{
137		jQuery("#myid").removeAttr(\'disabled\');
138		jQuery("#myid").attr(\'disabled\',\'disabled\');
139	}
140	init_myfunc();
141	jQuery("#mybutton").click(function() {
142		init_myfunc();
143	});
144});
145</script>';
146
147
148// Part to create
149if ($action == 'create')
150{
151	print load_fiche_titre($langs->trans("NewInventory"), '', 'product');
152
153	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
154	print '<input type="hidden" name="token" value="'.newToken().'">';
155	print '<input type="hidden" name="action" value="add">';
156	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
157
158	dol_fiche_head(array(), '');
159
160	print '<table class="border centpercent tableforfieldcreate">'."\n";
161
162	// Common attributes
163	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
164
165	// Other attributes
166	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
167
168	print '</table>'."\n";
169
170	dol_fiche_end();
171
172	print '<div class="center">';
173	print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
174	print '&nbsp; ';
175	print '<input type="'.($backtopage ? "submit" : "button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
176	print '</div>';
177
178	print '</form>';
179
180	dol_set_focus('input[name="ref"]');
181}
182
183// Part to edit record
184if (($id || $ref) && $action == 'edit')
185{
186	print load_fiche_titre($langs->trans("Inventory"), '', 'product');
187
188	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
189	print '<input type="hidden" name="token" value="'.newToken().'">';
190	print '<input type="hidden" name="action" value="update">';
191	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
192	print '<input type="hidden" name="id" value="'.$object->id.'">';
193
194	dol_fiche_head();
195
196	print '<table class="border centpercent tableforfieldcreate">'."\n";
197
198	// Common attributes
199	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
200
201	// Other attributes
202	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
203
204	print '</table>';
205
206	dol_fiche_end();
207
208	print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
209	print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
210	print '</div>';
211
212	print '</form>';
213}
214
215// Part to show record
216if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
217{
218    $res = $object->fetch_optionals();
219
220    $head = inventoryPrepareHead($object);
221	dol_fiche_head($head, 'card', $langs->trans("Inventory"), -1, 'stock');
222
223	$formconfirm = '';
224
225	// Confirmation to delete
226	if ($action == 'delete') {
227	    $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
228	}
229	// Confirmation to delete line
230	if ($action == 'deleteline')
231	{
232		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
233	}
234
235	// Clone confirmation
236	if ($action == 'clone') {
237		// Create an array for form
238		$formquestion = array();
239		$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMyObject', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
240	}
241
242	// Call Hook formConfirm
243	$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
244	$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
245	if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
246	elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
247
248	// Print form confirm
249	print $formconfirm;
250
251
252	// Object card
253	// ------------------------------------------------------------
254	$linkback = '<a href="'.DOL_URL_ROOT.'/product/inventory/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
255
256	$morehtmlref = '<div class="refidno">';
257	/*
258	// Ref bis
259	$morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', 0, 1);
260	$morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', null, null, '', 1);
261	// Thirdparty
262	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
263	// Project
264	if (! empty($conf->projet->enabled))
265	{
266	    $langs->load("projects");
267	    $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
268	    if ($user->rights->inventory->creer)
269	    {
270	        if ($action != 'classify')
271	        {
272	            $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
273	            if ($action == 'classify') {
274	                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
275	                $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
276	                $morehtmlref.='<input type="hidden" name="action" value="classin">';
277	                $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
278	                $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
279	                $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
280	                $morehtmlref.='</form>';
281	            } else {
282	                $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
283	            }
284	        }
285	    } else {
286	        if (! empty($object->fk_project)) {
287	            $proj = new Project($db);
288	            $proj->fetch($object->fk_project);
289	            $morehtmlref.=$proj->getNomUrl();
290	        } else {
291	            $morehtmlref.='';
292	        }
293	    }
294	}
295	*/
296	$morehtmlref .= '</div>';
297
298
299	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
300
301
302	print '<div class="fichecenter">';
303	print '<div class="fichehalfleft">';
304	print '<div class="underbanner clearboth"></div>';
305	print '<table class="border centpercent tableforfield">'."\n";
306
307	// Common attributes
308	include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
309
310	// Other attributes. Fields from hook formObjectOptions and Extrafields.
311	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
312
313	print '</table>';
314	print '</div>';
315	print '</div>';
316
317	print '<div class="clearboth"></div>';
318
319	dol_fiche_end();
320
321
322	// Buttons for actions
323	if ($action != 'presend' && $action != 'editline') {
324    	print '<div class="tabsAction">'."\n";
325    	$parameters = array();
326    	$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
327    	if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
328
329    	if (empty($reshook))
330    	{
331    	    // Send
332    		if (empty($user->socid)) {
333    			print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
334    		}
335
336        	if ($permissiontoadd)
337    		{
338    			print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'."\n";
339    		}
340    		else
341    		{
342    			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
343    		}
344
345    		if ($permissiontoadd)
346    		{
347    			print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Validate").'</a>'."\n";
348    		}
349    		else
350    		{
351    			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Validate').'</a>'."\n";
352    		}
353
354    		if ($permissiontodelete)
355    		{
356    			print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n";
357    		}
358    		else
359    		{
360    			print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
361    		}
362    	}
363    	print '</div>'."\n";
364	}
365
366
367	// Select mail models is same action as presend
368	if (GETPOST('modelselected')) {
369	    $action = 'presend';
370	}
371
372	if ($action != 'presend')
373	{
374	    print '<div class="fichecenter"><div class="fichehalfleft">';
375	    print '<a name="builddoc"></a>'; // ancre
376
377	    // Documents
378	    /*$objref = dol_sanitizeFileName($object->ref);
379	     $relativepath = $comref . '/' . $comref . '.pdf';
380	     $filedir = $conf->mymodule->dir_output . '/' . $objref;
381	     $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
382	     $genallowed = $user->rights->mymodule->read;	// If you can read, you can build the PDF to read content
383	     $delallowed = $user->rights->mymodule->create;	// If you can create/edit, you can remove a file on card
384	     print $formfile->showdocuments('mymodule', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
385	     */
386
387	    // Show links to link elements
388	    $linktoelem = $form->showLinkToObjectBlock($object, null, array('inventory'));
389	    $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
390
391
392	    print '</div><div class="fichehalfright"><div class="ficheaddleft">';
393
394	    $MAXEVENT = 10;
395
396	    $morehtmlright = '<a href="'.dol_buildpath('/product/inventory/inventory_info.php', 1).'?id='.$object->id.'">';
397	    $morehtmlright .= $langs->trans("SeeAll");
398	    $morehtmlright .= '</a>';
399
400	    // List of actions on element
401	    include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
402	    $formactions = new FormActions($db);
403	    $somethingshown = $formactions->showactions($object, 'inventory', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
404
405	    print '</div></div></div>';
406	}
407
408
409	//Select mail models is same action as presend
410	/*
411	if (GETPOST('modelselected')) $action = 'presend';
412
413	// Presend form
414	$modelmail='inventory';
415	$defaulttopic='InformationMessage';
416	$diroutput = $conf->product->dir_output.'/inventory';
417	$trackid = 'stockinv'.$object->id;
418
419	include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
420	*/
421}
422
423// End of page
424llxFooter();
425$db->close();