fetch object in include file
This commit is contained in:
parent
73afe1513d
commit
4af26c119f
@ -84,10 +84,7 @@ $extrafields = new ExtraFields($db);
|
|||||||
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
|
|
||||||
// Load object
|
// Load object
|
||||||
if ($id > 0 || ! empty($ref)) {
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$ret = $object->fetch($id, $ref);
|
|
||||||
$ret = $object->fetch_thirdparty();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
|
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
|
||||||
$hookmanager->initHooks(array('ordercard','globalcard'));
|
$hookmanager->initHooks(array('ordercard','globalcard'));
|
||||||
|
|||||||
40
htdocs/core/actions_fetchobject.inc.php
Normal file
40
htdocs/core/actions_fetchobject.inc.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* or see http://www.gnu.org/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file htdocs/core/actions_fetchobject.inc.php
|
||||||
|
* \brief Code for actions on fetching object page
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// $action must be defined
|
||||||
|
// $object must be defined (object is loaded in this file with fetch)
|
||||||
|
// $id or $ref must be defined (object is loaded in this file with fetch)
|
||||||
|
|
||||||
|
if ($id > 0 || ! empty($ref))
|
||||||
|
{
|
||||||
|
$ret = $object->fetch($id,$ref);
|
||||||
|
if ($ret > 0) {
|
||||||
|
$object->fetch_thirdparty();
|
||||||
|
$id=$object->id;
|
||||||
|
} else {
|
||||||
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
$action='';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -76,10 +76,7 @@ $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($co
|
|||||||
$object = new Expedition($db);
|
$object = new Expedition($db);
|
||||||
|
|
||||||
// Load object
|
// Load object
|
||||||
if ($id > 0 || ! empty($ref))
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
{
|
|
||||||
$ret=$object->fetch($id, $ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
|
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
|
||||||
$hookmanager->initHooks(array('expeditioncard','globalcard'));
|
$hookmanager->initHooks(array('expeditioncard','globalcard'));
|
||||||
|
|||||||
@ -49,17 +49,8 @@ $hookmanager->initHooks(array('projectcard','globalcard'));
|
|||||||
|
|
||||||
$object = new Project($db);
|
$object = new Project($db);
|
||||||
$extrafields = new ExtraFields($db);
|
$extrafields = new ExtraFields($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
// Load object
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$ret = $object->fetch($id,$ref);
|
|
||||||
if ($ret > 0) {
|
|
||||||
$object->fetch_thirdparty();
|
|
||||||
$id=$object->id;
|
|
||||||
} else {
|
|
||||||
setEventMessage($object->error, 'errors');
|
|
||||||
$action='';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=GETPOST('socid');
|
$socid=GETPOST('socid');
|
||||||
|
|||||||
@ -41,12 +41,8 @@ $mine = GETPOST('mode')=='mine' ? 1 : 0;
|
|||||||
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
||||||
|
|
||||||
$object = new Project($db);
|
$object = new Project($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$object->fetch($id,$ref);
|
|
||||||
$object->fetch_thirdparty();
|
|
||||||
$id=$object->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=0;
|
$socid=0;
|
||||||
|
|||||||
@ -46,10 +46,10 @@ if ($user->societe_id > 0) $socid=$user->societe_id;
|
|||||||
$result=restrictedArea($user,'projet',$id,'');
|
$result=restrictedArea($user,'projet',$id,'');
|
||||||
|
|
||||||
$object = new Project($db);
|
$object = new Project($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$object->fetch($id,$ref);
|
|
||||||
$object->fetch_thirdparty();
|
if ($id > 0 || ! empty($ref)) {
|
||||||
$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
|
$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -80,21 +80,9 @@ $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
|
|||||||
|
|
||||||
$projectid=$id; // For backward compatibility
|
$projectid=$id; // For backward compatibility
|
||||||
|
|
||||||
$project = new Project($db);
|
$object = new Project($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$ret=$project->fetch($id,$ref);
|
|
||||||
if ($ret > 0)
|
|
||||||
{
|
|
||||||
$projectid=$project->id;
|
|
||||||
$project->fetch_thirdparty();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setEventMessages($project->error, $project->errors, 'errors');
|
|
||||||
$action='';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=0;
|
$socid=0;
|
||||||
@ -116,10 +104,10 @@ $formfile = new FormFile($db);
|
|||||||
$userstatic=new User($db);
|
$userstatic=new User($db);
|
||||||
|
|
||||||
// To verify role of users
|
// To verify role of users
|
||||||
$userAccess = $project->restrictedProjectArea($user);
|
$userAccess = $object->restrictedProjectArea($user);
|
||||||
|
|
||||||
$head=project_prepare_head($project);
|
$head=project_prepare_head($object);
|
||||||
dol_fiche_head($head, 'element', $langs->trans("Project"),0,($project->public?'projectpub':'project'));
|
dol_fiche_head($head, 'element', $langs->trans("Project"),0,($object->public?'projectpub':'project'));
|
||||||
|
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
@ -130,36 +118,36 @@ print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
|
|||||||
// Define a complementary filter for search of next/prev ref.
|
// Define a complementary filter for search of next/prev ref.
|
||||||
if (! $user->rights->projet->all->lire)
|
if (! $user->rights->projet->all->lire)
|
||||||
{
|
{
|
||||||
$projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0);
|
$projectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0);
|
||||||
$project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
|
$object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
|
||||||
}
|
}
|
||||||
print $form->showrefnav($project, 'ref', $linkback, 1, 'ref', 'ref');
|
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
|
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
|
print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
|
||||||
if (! empty($project->thirdparty->id)) print $project->thirdparty->getNomUrl(1);
|
if (! empty($object->thirdparty->id)) print $object->thirdparty->getNomUrl(1);
|
||||||
else print ' ';
|
else print ' ';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Visibility
|
// Visibility
|
||||||
print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
|
print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
|
||||||
if ($project->public) print $langs->trans('SharedProject');
|
if ($object->public) print $langs->trans('SharedProject');
|
||||||
else print $langs->trans('PrivateProject');
|
else print $langs->trans('PrivateProject');
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Statut
|
// Statut
|
||||||
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
|
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
|
||||||
|
|
||||||
// Date start
|
// Date start
|
||||||
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
|
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
|
||||||
print dol_print_date($project->date_start,'day');
|
print dol_print_date($object->date_start,'day');
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
// Date end
|
// Date end
|
||||||
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
|
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
|
||||||
print dol_print_date($project->date_end,'day');
|
print dol_print_date($object->date_end,'day');
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
@ -263,18 +251,18 @@ if ($action=="addelement")
|
|||||||
{
|
{
|
||||||
$tablename = GETPOST("tablename");
|
$tablename = GETPOST("tablename");
|
||||||
$elementselectid = GETPOST("elementselect");
|
$elementselectid = GETPOST("elementselect");
|
||||||
$result=$project->update_element($tablename, $elementselectid);
|
$result=$object->update_element($tablename, $elementselectid);
|
||||||
if ($result<0) {
|
if ($result<0) {
|
||||||
setEventMessage($project->error,'errors');
|
setEventMessage($object->error,'errors');
|
||||||
}
|
}
|
||||||
}elseif ($action == "unlink") {
|
}elseif ($action == "unlink") {
|
||||||
|
|
||||||
$tablename = GETPOST("tablename");
|
$tablename = GETPOST("tablename");
|
||||||
$elementselectid = GETPOST("elementselect");
|
$elementselectid = GETPOST("elementselect");
|
||||||
|
|
||||||
$result = $project->remove_element($tablename, $elementselectid);
|
$result = $object->remove_element($tablename, $elementselectid);
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
setEventMessage($project->error, 'errors');
|
setEventMessage($object->error, 'errors');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +305,7 @@ foreach ($listofreferent as $key => $value)
|
|||||||
|
|
||||||
print_titre($langs->trans($title));
|
print_titre($langs->trans($title));
|
||||||
|
|
||||||
$selectList=$formproject->select_element($tablename,$project->thirdparty->id);
|
$selectList=$formproject->select_element($tablename,$object->thirdparty->id);
|
||||||
if (! $selectList || ($selectList<0))
|
if (! $selectList || ($selectList<0))
|
||||||
{
|
{
|
||||||
setEventMessages($formproject->error,$formproject->errors,'errors');
|
setEventMessages($formproject->error,$formproject->errors,'errors');
|
||||||
@ -352,7 +340,7 @@ foreach ($listofreferent as $key => $value)
|
|||||||
else print '<td width="120"></td>';
|
else print '<td width="120"></td>';
|
||||||
print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
|
print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
$elementarray = $project->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
|
$elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
|
||||||
if (is_array($elementarray) && count($elementarray)>0)
|
if (is_array($elementarray) && count($elementarray)>0)
|
||||||
{
|
{
|
||||||
$var=true;
|
$var=true;
|
||||||
@ -544,32 +532,32 @@ foreach ($listofreferent as $key => $value)
|
|||||||
*/
|
*/
|
||||||
print '<div class="tabsAction">';
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
if ($project->statut > 0)
|
if ($object->statut > 0)
|
||||||
{
|
{
|
||||||
if ($project->thirdparty->prospect || $project->thirdparty->client)
|
if ($object->thirdparty->prospect || $object->thirdparty->client)
|
||||||
{
|
{
|
||||||
if ($key == 'propal' && ! empty($conf->propal->enabled) && $user->rights->propale->creer)
|
if ($key == 'propal' && ! empty($conf->propal->enabled) && $user->rights->propale->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal.php?socid='.$project->thirdparty->id.'&action=create&origin='.$project->element.'&originid='.$project->id.'">'.$langs->trans("AddProp").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal.php?socid='.$object->thirdparty->id.'&action=create&origin='.$object->element.'&originid='.$object->id.'">'.$langs->trans("AddProp").'</a>';
|
||||||
}
|
}
|
||||||
if ($key == 'order' && ! empty($conf->commande->enabled) && $user->rights->commande->creer)
|
if ($key == 'order' && ! empty($conf->commande->enabled) && $user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$project->thirdparty->id.'&action=create&origin='.$project->element.'&originid='.$project->id.'">'.$langs->trans("AddCustomerOrder").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$object->thirdparty->id.'&action=create&origin='.$object->element.'&originid='.$object->id.'">'.$langs->trans("AddCustomerOrder").'</a>';
|
||||||
}
|
}
|
||||||
if ($key == 'invoice' && ! empty($conf->facture->enabled) && $user->rights->facture->creer)
|
if ($key == 'invoice' && ! empty($conf->facture->enabled) && $user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$project->thirdparty->id.'&action=create&origin='.$project->element.'&originid='.$project->id.'">'.$langs->trans("AddCustomerInvoice").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$object->thirdparty->id.'&action=create&origin='.$object->element.'&originid='.$object->id.'">'.$langs->trans("AddCustomerInvoice").'</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($project->thirdparty->fournisseur)
|
if ($object->thirdparty->fournisseur)
|
||||||
{
|
{
|
||||||
if ($key == 'order_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->creer)
|
if ($key == 'order_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?socid='.$project->thirdparty->id.'&action=create&origin='.$project->element.'&originid='.$project->id.'">'.$langs->trans("AddSupplierInvoice").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?socid='.$object->thirdparty->id.'&action=create&origin='.$object->element.'&originid='.$object->id.'">'.$langs->trans("AddSupplierInvoice").'</a>';
|
||||||
}
|
}
|
||||||
if ($key == 'invoice_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->creer)
|
if ($key == 'invoice_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?socid='.$project->thirdparty->id.'&action=create&origin='.$project->element.'&originid='.$project->id.'">'.$langs->trans("AddSupplierOrder").'</a>';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?socid='.$object->thirdparty->id.'&action=create&origin='.$object->element.'&originid='.$object->id.'">'.$langs->trans("AddSupplierOrder").'</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -607,7 +595,7 @@ foreach ($listofreferent as $key => $value)
|
|||||||
{
|
{
|
||||||
$element = new $classname($db);
|
$element = new $classname($db);
|
||||||
|
|
||||||
$elementarray = $project->get_element_list($key, $tablename);
|
$elementarray = $object->get_element_list($key, $tablename);
|
||||||
if (count($elementarray)>0 && is_array($elementarray))
|
if (count($elementarray)>0 && is_array($elementarray))
|
||||||
{
|
{
|
||||||
$var=true;
|
$var=true;
|
||||||
|
|||||||
@ -38,12 +38,8 @@ $mine = ($mode == 'mine' ? 1 : 0);
|
|||||||
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
||||||
|
|
||||||
$object = new Project($db);
|
$object = new Project($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$object->fetch($id,$ref);
|
|
||||||
$object->fetch_thirdparty();
|
|
||||||
$id=$object->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=0;
|
$socid=0;
|
||||||
|
|||||||
@ -36,12 +36,8 @@ $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
|
|||||||
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
||||||
|
|
||||||
$object = new Project($db);
|
$object = new Project($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
|
||||||
{
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
$object->fetch($id,$ref);
|
|
||||||
$object->fetch_thirdparty();
|
|
||||||
$id=$object->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
$socid=0;
|
$socid=0;
|
||||||
|
|||||||
@ -47,12 +47,11 @@ $object = new Project($db);
|
|||||||
$taskstatic = new Task($db);
|
$taskstatic = new Task($db);
|
||||||
$extrafields_project = new ExtraFields($db);
|
$extrafields_project = new ExtraFields($db);
|
||||||
$extrafields_task = new ExtraFields($db);
|
$extrafields_task = new ExtraFields($db);
|
||||||
|
|
||||||
|
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not includ_once
|
||||||
|
|
||||||
if ($id > 0 || ! empty($ref))
|
if ($id > 0 || ! empty($ref))
|
||||||
{
|
{
|
||||||
$object->fetch($id,$ref);
|
|
||||||
$id=$object->id;
|
|
||||||
$ref=$object->ref;
|
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$extralabels_projet=$extrafields_project->fetch_name_optionals_label($object->table_element);
|
$extralabels_projet=$extrafields_project->fetch_name_optionals_label($object->table_element);
|
||||||
$extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
|
$extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user