Works on canvas integration in third party module
This commit is contained in:
parent
0578acf414
commit
f604e7eaac
@ -31,6 +31,8 @@
|
||||
|
||||
class Canvas
|
||||
{
|
||||
var $db;
|
||||
|
||||
var $card;
|
||||
var $canvas;
|
||||
var $module;
|
||||
@ -68,6 +70,22 @@ class Canvas
|
||||
return $this->control->assign_post();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set action type
|
||||
*/
|
||||
function setAction($action='view')
|
||||
{
|
||||
return $this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data control
|
||||
*/
|
||||
function loadControl($socid)
|
||||
{
|
||||
return $this->control->loadControl($socid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch object values
|
||||
* @param id Element id
|
||||
@ -78,14 +96,15 @@ class Canvas
|
||||
}
|
||||
|
||||
/**
|
||||
* Load canvas
|
||||
* Get card and canvas type
|
||||
* @param card Type of card
|
||||
* @param canvas Name of canvas (ex: default@mymodule)
|
||||
*/
|
||||
function load_canvas($card,$canvas)
|
||||
function getCanvas($card,$canvas)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$error='';
|
||||
$this->card = $card;
|
||||
|
||||
if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs))
|
||||
@ -102,7 +121,8 @@ class Canvas
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->module.'.'.$this->canvas.'.class.php'))
|
||||
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->module.'.'.$this->canvas.'.class.php') &&
|
||||
file_exists(DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->card.'.'.$this->canvas.'.class.php'))
|
||||
{
|
||||
// Include model class
|
||||
$modelclassfile = DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->module.'.'.$this->canvas.'.class.php';
|
||||
@ -112,32 +132,10 @@ class Canvas
|
||||
$controlclassfile = DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->card.'.common.class.php';
|
||||
include_once($controlclassfile);
|
||||
|
||||
// Template dir
|
||||
$this->template_dir = DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $langs->trans('CanvasIsInvalid');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load controller
|
||||
* @param action Type of action
|
||||
*/
|
||||
function load_control($action='null')
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$this->action = $action;
|
||||
|
||||
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->card.'.'.$this->canvas.'.class.php'))
|
||||
{
|
||||
// Include canvas controller class
|
||||
$controlclassfile = DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/'.$this->card.'.'.$this->canvas.'.class.php';
|
||||
include_once($controlclassfile);
|
||||
|
||||
|
||||
// Instantiate canvas controller class
|
||||
$controlclassname = ucfirst($this->card).ucfirst($this->canvas);
|
||||
$this->control = new $controlclassname($this->db);
|
||||
@ -146,22 +144,22 @@ class Canvas
|
||||
$modelclassname = ucfirst($this->module).ucfirst($this->canvas);
|
||||
$this->control->object = new $modelclassname($this->db);
|
||||
|
||||
// Canvas
|
||||
$this->control->canvas = $canvas;
|
||||
|
||||
// Template dir
|
||||
$this->template_dir = DOL_DOCUMENT_ROOT.'/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/';
|
||||
|
||||
// Need smarty
|
||||
$this->smarty = $this->object->smarty;
|
||||
$this->smarty = $this->control->smarty;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $langs->trans('CanvasIsInvalid');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load actions
|
||||
*/
|
||||
function load_actions($socid)
|
||||
{
|
||||
return $this->control->load_actions($socid);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,14 +27,18 @@
|
||||
* \class CardCommon
|
||||
* \brief Classe permettant la gestion des tiers par defaut
|
||||
*/
|
||||
class CardCommon extends Canvas
|
||||
class CardCommon
|
||||
{
|
||||
var $db;
|
||||
|
||||
//! Numero d'erreur Plage 1280-1535
|
||||
var $errno = 0;
|
||||
//! Template container
|
||||
var $tpl = array();
|
||||
//! Object container
|
||||
var $object;
|
||||
//! Canvas
|
||||
var $canvas;
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
@ -335,12 +339,11 @@ class CardCommon extends Canvas
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge les actions
|
||||
* Load data control
|
||||
*/
|
||||
function load_actions($socid)
|
||||
function loadControl($socid)
|
||||
{
|
||||
global $conf, $user, $langs;
|
||||
global $canvas;
|
||||
|
||||
if ($_POST["getcustomercode"])
|
||||
{
|
||||
@ -362,9 +365,7 @@ class CardCommon extends Canvas
|
||||
$error=0;
|
||||
|
||||
if ($_POST["action"] == 'update')
|
||||
{
|
||||
$this->load_control();
|
||||
|
||||
{
|
||||
// Load properties of company
|
||||
$this->object->fetch($socid);
|
||||
}
|
||||
@ -534,8 +535,7 @@ class CardCommon extends Canvas
|
||||
}
|
||||
|
||||
$oldsoccanvas = new Canvas($this->db);
|
||||
$oldsoccanvas->load_canvas('card',$canvas);
|
||||
$oldsoccanvas->load_control();
|
||||
$oldsoccanvas->getCanvas('card',$this->canvas);
|
||||
$result=$oldsoccanvas->fetch($socid);
|
||||
|
||||
// To not set code if third party is not concerned. But if it had values, we keep them.
|
||||
@ -563,23 +563,20 @@ class CardCommon extends Canvas
|
||||
|
||||
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->societe->supprimer)
|
||||
{
|
||||
$soccanvas = new Canvas($this->db);
|
||||
$soccanvas->load_canvas('card',$canvas);
|
||||
$soccanvas->load_control();
|
||||
$soccanvas->fetch($socid);
|
||||
$this->object->fetch($socid);
|
||||
|
||||
$result = $soccanvas->control->object->delete($socid);
|
||||
$result = $this->object->delete($socid);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soccanvas->control->object->nom."");
|
||||
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$this->object->nom."");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$reload = 0;
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans($soccanvas->control->object->error);
|
||||
$mesg=$langs->trans($this->object->error);
|
||||
$_GET["action"]='';
|
||||
}
|
||||
}
|
||||
@ -597,11 +594,8 @@ class CardCommon extends Canvas
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
|
||||
|
||||
$soccanvas = new Canvas($this->db);
|
||||
$soccanvas->load_canvas('card',$canvas);
|
||||
$soccanvas->load_control();
|
||||
$soccanvas->fetch($socid);
|
||||
$soccanvas->control->object->fetch_thirdparty();
|
||||
$this->object->fetch($socid);
|
||||
$this->object->fetch_thirdparty();
|
||||
|
||||
/*if ($_REQUEST['model'])
|
||||
{
|
||||
@ -613,13 +607,13 @@ class CardCommon extends Canvas
|
||||
$outputlangs = $langs;
|
||||
$newlang='';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$soccanvas->object->default_lang;
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
|
||||
if (! empty($newlang))
|
||||
{
|
||||
$outputlangs = new Translate("",$conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$result=thirdparty_doc_create($this->db, $soccanvas->control->object->id, '', $_REQUEST['model'], $outputlangs);
|
||||
$result=thirdparty_doc_create($this->db, $this->object->id, '', $_REQUEST['model'], $outputlangs);
|
||||
if ($result <= 0)
|
||||
{
|
||||
dol_print_error($this->db,$result);
|
||||
@ -627,7 +621,7 @@ class CardCommon extends Canvas
|
||||
}
|
||||
else
|
||||
{
|
||||
Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$soccanvas->control->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
|
||||
Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,13 +29,18 @@
|
||||
*/
|
||||
class CardDefault extends CardCommon
|
||||
{
|
||||
var $db;
|
||||
|
||||
//! Canvas
|
||||
var $canvas;
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
* @param DB Handler acces base de donnees
|
||||
*/
|
||||
function CardDefault($DB)
|
||||
{
|
||||
$this->db = $DB;
|
||||
$this->db = $DB;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,11 +60,11 @@ class CardDefault extends CardCommon
|
||||
}
|
||||
|
||||
/**
|
||||
* Load actions
|
||||
* Load data control
|
||||
*/
|
||||
function load_actions($socid)
|
||||
function loadControl($socid)
|
||||
{
|
||||
$return = parent::load_actions($socid);
|
||||
$return = parent::loadControl($socid);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@
|
||||
*/
|
||||
class ThirdPartyDefault extends Societe
|
||||
{
|
||||
var $db;
|
||||
|
||||
//! Numero d'erreur Plage 1280-1535
|
||||
var $errno = 0;
|
||||
|
||||
@ -43,7 +45,7 @@ class ThirdPartyDefault extends Societe
|
||||
|
||||
/**
|
||||
* Lecture des donnees dans la base
|
||||
* @param id Product id
|
||||
* @param id Element id
|
||||
* @param action Type of action
|
||||
*/
|
||||
function fetch($id='', $action='')
|
||||
|
||||
@ -29,6 +29,11 @@
|
||||
*/
|
||||
class CardIndividual extends CardCommon
|
||||
{
|
||||
var $db;
|
||||
|
||||
//! Canvas
|
||||
var $canvas;
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
* @param DB Handler acces base de donnees
|
||||
@ -55,11 +60,11 @@ class CardIndividual extends CardCommon
|
||||
}
|
||||
|
||||
/**
|
||||
* Load actions
|
||||
* Load data control
|
||||
*/
|
||||
function load_actions($socid)
|
||||
function loadControl($socid)
|
||||
{
|
||||
$return = parent::load_actions($socid);
|
||||
$return = parent::loadControl($socid);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@ -33,8 +33,8 @@ class ThirdPartyIndividual extends Societe
|
||||
var $errno = 0;
|
||||
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
* \param DB Handler acces base de donnees
|
||||
* Constructeur de la classe
|
||||
* @param DB Handler acces base de donnees
|
||||
*/
|
||||
function ThirdPartyIndividual($DB)
|
||||
{
|
||||
|
||||
@ -1592,15 +1592,14 @@ else
|
||||
//if ($_REQUEST["private"]==1) $_GET["canvas"] = 'individual'; To switch to other canvas, we must use another value for canvas
|
||||
|
||||
$soccanvas = new Canvas($db);
|
||||
$soccanvas->load_canvas('card',$canvas);
|
||||
$soccanvas->getCanvas('card',$canvas);
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
$soccanvas->load_control();
|
||||
$soccanvas->load_actions($socid);
|
||||
$soccanvas->loadControl($socid);
|
||||
|
||||
/*
|
||||
* View
|
||||
@ -1620,9 +1619,10 @@ else
|
||||
* Sheet mode creation
|
||||
*/
|
||||
if ($user->rights->societe->creer)
|
||||
{
|
||||
$soccanvas->load_control('create');
|
||||
|
||||
{
|
||||
// Set action type
|
||||
$soccanvas->setAction(GETPOST("action"));
|
||||
|
||||
$title = $soccanvas->getTitle();
|
||||
print_fiche_titre($title);
|
||||
|
||||
@ -1644,7 +1644,8 @@ else
|
||||
* Company Fact Mode edition
|
||||
*/
|
||||
|
||||
$soccanvas->load_control('edit');
|
||||
// Set action type
|
||||
$soccanvas->setAction(GETPOST("action"));
|
||||
|
||||
$title = $soccanvas->getTitle();
|
||||
print_fiche_titre($title);
|
||||
@ -1676,18 +1677,18 @@ else
|
||||
* Company Fact Sheet mode visu
|
||||
*/
|
||||
|
||||
$soccanvas->load_control('view');
|
||||
|
||||
$soc->id = $socid;
|
||||
// Set action type
|
||||
$soccanvas->setAction('view');
|
||||
|
||||
$result=$soccanvas->fetch($socid);
|
||||
if ($result < 0)
|
||||
{
|
||||
dol_print_error($db,$soccanvas->error);
|
||||
dol_print_error($db,$soccanvas->control->object->error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$head = societe_prepare_head($soccanvas->control->object);
|
||||
$title = $soccanvas->getTitle('view');
|
||||
$title = $soccanvas->getTitle();
|
||||
|
||||
dol_fiche_head($head, 'company', $title, 0, 'company');
|
||||
|
||||
@ -1706,17 +1707,17 @@ else
|
||||
|
||||
if ($user->rights->societe->creer)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action=edit&canvas='.$canvas.'">'.$langs->trans("Modify").'</a>';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&action=edit&canvas='.$canvas.'">'.$langs->trans("Modify").'</a>';
|
||||
}
|
||||
|
||||
if ($user->rights->societe->contact->creer)
|
||||
{
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$soc->id.'&action=create&canvas='.$canvas.'">'.$langs->trans("AddContact").'</a>';
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$socid.'&action=create&canvas='.$canvas.'">'.$langs->trans("AddContact").'</a>';
|
||||
}
|
||||
|
||||
if ($user->rights->societe->supprimer)
|
||||
{
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$soc->id.'&action=delete&canvas='.$canvas.'">'.$langs->trans('Delete').'</a>';
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'&action=delete&canvas='.$canvas.'">'.$langs->trans('Delete').'</a>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
@ -1730,14 +1731,14 @@ else
|
||||
/*
|
||||
* Documents generes
|
||||
*/
|
||||
$filedir=$conf->societe->dir_output.'/'.$soc->id;
|
||||
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$soc->id;
|
||||
$filedir=$conf->societe->dir_output.'/'.$socid;
|
||||
$urlsource=$_SERVER["PHP_SELF"]."?socid=".$socid;
|
||||
$genallowed=$user->rights->societe->creer;
|
||||
$delallowed=$user->rights->societe->supprimer;
|
||||
|
||||
$var=true;
|
||||
|
||||
$somethingshown=$formfile->show_documents('company',$soc->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$soc->default_lang);
|
||||
$somethingshown=$formfile->show_documents('company',$socid,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$soccanvas->control->object->default_lang);
|
||||
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
@ -1748,10 +1749,10 @@ else
|
||||
print '<br>';
|
||||
|
||||
// Contacts list
|
||||
$result=show_contacts($conf,$langs,$db,$soc);
|
||||
$result=show_contacts($conf,$langs,$db,$soccanvas->control->object);
|
||||
|
||||
// Projects list
|
||||
$result=show_projects($conf,$langs,$db,$soc);
|
||||
$result=show_projects($conf,$langs,$db,$soccanvas->control->object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user