Fix: broken canvas

This commit is contained in:
Regis Houssin 2011-09-24 15:57:52 +00:00
parent 77054323c4
commit 96ed2fe994
11 changed files with 490 additions and 549 deletions

View File

@ -28,12 +28,11 @@
abstract class ActionsContactCardCommon abstract class ActionsContactCardCommon
{ {
var $db; var $db;
var $dirmodule;
var $targetmodule; var $targetmodule;
var $canvas; var $canvas;
var $card; var $card;
//! Numero d'erreur Plage 1280-1535
var $errno = 0;
//! Template container //! Template container
var $tpl = array(); var $tpl = array();
//! Object container //! Object container
@ -46,19 +45,66 @@ abstract class ActionsContactCardCommon
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Handler acces base de donnees * @param DoliDB $DB Handler acces base de donnees
* @param string $targetmodule Name of directory of module where canvas is stored * @param string $dirmodule Name of directory of module
* @param string $canvas Name of canvas * @param string $targetmodule Name of directory where canvas is stored
* @param streing $card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsContactCardCommon($DB,$targetmodule,$canvas,$card) function __construct($DB, $dirmodule, $targetmodule, $canvas, $card)
{ {
$this->db = $DB; $this->db = $DB;
$this->targetmodule = $targetmodule; $this->dirmodule = $targetmodule;
$this->canvas = $canvas; $this->targetmodule = $targetmodule;
$this->card = $card; $this->canvas = $canvas;
$this->card = $card;
} }
/**
* Instantiation of DAO class
*
* @return void
*/
private function getInstanceDao()
{
if (! is_object($this->object))
{
$modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
if (file_exists($modelclassfile))
{
// Include dataservice class (model)
$ret = require_once($modelclassfile);
if ($ret)
{
// Instantiate dataservice class (model)
$modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas);
$this->object = new $modelclassname($this->db);
}
}
}
}
/**
* Get object
*
* @param int Object id
* @return object Object loaded
*/
function getObject($id)
{
$ret = $this->getInstanceDao();
if (is_object($this->object) && method_exists($this->object,'fetch'))
{
if (! empty($id)) $this->object->fetch($id);
}
else
{
$object = new Contact($this->db);
if (! empty($id)) $object->fetch($id);
$this->object = $object;
}
}
/** /**
* Load data control * Load data control
@ -66,12 +112,12 @@ abstract class ActionsContactCardCommon
* @param int $id Id of object * @param int $id Id of object
* @return void * @return void
*/ */
function doActions($id) function doActions(&$action)
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
// Creation utilisateur depuis contact // Creation utilisateur depuis contact
if (GETPOST("action") == 'confirm_create_user' && GETPOST("confirm") == 'yes') if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes')
{ {
// Recuperation contact actuel // Recuperation contact actuel
$result = $this->object->fetch($id); $result = $this->object->fetch($id);
@ -110,14 +156,14 @@ abstract class ActionsContactCardCommon
} }
// Creation contact // Creation contact
if ($_POST["action"] == 'add') if ($action == 'add')
{ {
$this->assign_post(); $this->assign_post();
if (! $_POST["name"]) if (! $_POST["name"])
{ {
array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"))); array_push($this->errors,$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'create'; $action = 'create';
} }
if ($_POST["name"]) if ($_POST["name"])
@ -131,12 +177,12 @@ abstract class ActionsContactCardCommon
else else
{ {
$this->errors=$this->object->errors; $this->errors=$this->object->errors;
$_GET["action"] = $_POST["action"] = 'create'; $action = 'create';
} }
} }
} }
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes') if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{ {
$result=$this->object->fetch($id); $result=$this->object->fetch($id);
@ -146,7 +192,7 @@ abstract class ActionsContactCardCommon
$result = $this->object->delete(); $result = $this->object->delete();
if ($result > 0) if ($result > 0)
{ {
Header("Location: index.php"); Header("Location: list.php");
exit; exit;
} }
else else
@ -155,12 +201,18 @@ abstract class ActionsContactCardCommon
} }
} }
if ($_POST["action"] == 'update' && ! $_POST["cancel"]) if ($action == 'update')
{ {
if ($_POST["cancel"])
{
Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
exit;
}
if (empty($_POST["name"])) if (empty($_POST["name"]))
{ {
$this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); $this->error=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'edit'; $action = 'edit';
} }
if (empty($this->error)) if (empty($this->error))
@ -175,55 +227,36 @@ abstract class ActionsContactCardCommon
if ($result > 0) if ($result > 0)
{ {
$this->object->old_name=''; Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$this->object->id);
$this->object->old_firstname=''; exit;
} }
else else
{ {
$this->errors=$this->object->errors; $this->errors=$this->object->errors;
$action = 'edit';
} }
} }
} }
} }
/**
* Return the title of card
*
* @param string $action Type of action
* @return string HTML output
*/
function getTitle($action)
{
global $langs;
$out='';
if ($action == 'view' || $action == 'edit') $out.= $langs->trans("ContactsAddresses");
if ($action == 'create') $out.= $langs->trans("AddContact");
return $out;
}
/** /**
* Set content of ->tpl array, to use into template * Set content of ->tpl array, to use into template
* *
* @param string $action Type of action * @param string $action Type of action
* @return string HTML output * @return string HTML output
*/ */
function assign_values($action='') function assign_values(&$action)
{ {
global $conf, $langs, $user, $canvas; global $conf, $langs, $user, $canvas;
global $form, $formcompany, $objsoc; global $form, $formcompany, $objsoc;
if ($action == 'create' || $action == 'edit') $this->assign_post($action); if ($action == 'add' || $action == 'update') $this->assign_post();
foreach($this->object as $key => $value) foreach($this->object as $key => $value)
{ {
$this->tpl[$key] = $value; $this->tpl[$key] = $value;
} }
$this->tpl['title']=$this->getTitle($action);
$this->tpl['error']=$this->error; $this->tpl['error']=$this->error;
$this->tpl['errors']=$this->errors; $this->tpl['errors']=$this->errors;
@ -289,7 +322,7 @@ abstract class ActionsContactCardCommon
$this->tpl['select_visibility'] = $form->selectarray('priv',$selectarray,$this->object->priv,0); $this->tpl['select_visibility'] = $form->selectarray('priv',$selectarray,$this->object->priv,0);
} }
if ($action == 'view' || $action == 'edit') if ($action == 'view' || $action == 'edit' || $action == 'delete')
{ {
// Emailing // Emailing
if ($conf->mailing->enabled) if ($conf->mailing->enabled)
@ -339,29 +372,8 @@ abstract class ActionsContactCardCommon
else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess"); else $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess");
} }
if ($action == 'view') if ($action == 'view' || $action == 'delete')
{ {
if ($_GET["action"] == 'create_user')
{
// Full firstname and name separated with a dot : firstname.name
include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
$login=dol_buildlogin($this->object->nom, $this->object->prenom);
$generated_password='';
if (! $ldap_sid)
{
$generated_password=getRandomPassword('');
}
$password=$generated_password;
// Create a form array
$formquestion=array(
array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
$this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion,'no');
}
$this->tpl['showrefnav'] = $form->showrefnav($this->object,'id'); $this->tpl['showrefnav'] = $form->showrefnav($this->object,'id');
if ($this->object->socid > 0) if ($this->object->socid > 0)
@ -395,15 +407,35 @@ abstract class ActionsContactCardCommon
$this->tpl['note'] = nl2br($this->object->note); $this->tpl['note'] = nl2br($this->object->note);
} }
if ($action == 'create_user')
{
// Full firstname and name separated with a dot : firstname.name
include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
$login=dol_buildlogin($this->object->nom, $this->object->prenom);
$generated_password='';
if (! $ldap_sid)
{
$generated_password=getRandomPassword('');
}
$password=$generated_password;
// Create a form array
$formquestion=array(
array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password));
$this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion,'no');
}
} }
/** /**
* Assign POST values into object * Assign POST values into object
* *
* @param string $action Action string
* @return string HTML output * @return string HTML output
*/ */
private function assign_post($action) private function assign_post()
{ {
global $langs, $mysoc; global $langs, $mysoc;

View File

@ -30,26 +30,44 @@ include_once(DOL_DOCUMENT_ROOT.'/contact/canvas/actions_contactcard_common.class
class ActionsContactCardDefault extends ActionsContactCardCommon class ActionsContactCardDefault extends ActionsContactCardCommon
{ {
var $db; var $db;
var $dirmodule;
var $targetmodule; var $targetmodule;
var $canvas; var $canvas;
var $card; var $card;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Handler acces base de donnees * @param DoliDB $DB Handler acces base de donnees
* @param string $targetmodule Name of directory of module where canvas is stored * @param string $dirmodule Name of directory of module
* @param string $canvas Name of canvas * @param string $targetmodule Name of directory of module where canvas is stored
* @param string $card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsContactCardDefault($DB,$targetmodule,$canvas,$card) function __construct($DB, $dirmodule, $targetmodule, $canvas, $card)
{ {
$this->db = $DB; $this->db = $DB;
$this->dirmodule = $dirmodule;
$this->targetmodule = $targetmodule; $this->targetmodule = $targetmodule;
$this->canvas = $canvas; $this->canvas = $canvas;
$this->card = $card; $this->card = $card;
} }
/**
* Return the title of card
*/
private function getTitle($action)
{
global $langs;
$out='';
if ($action == 'view') $out.= $langs->trans("Contact");
if ($action == 'edit') $out.= $langs->trans("EditContact");
if ($action == 'create') $out.= $langs->trans("NewContact");
return $out;
}
/** /**
* Assign custom values for canvas * Assign custom values for canvas
@ -57,10 +75,12 @@ class ActionsContactCardDefault extends ActionsContactCardCommon
* @param string $action Type of action * @param string $action Type of action
* @return void * @return void
*/ */
function assign_values($action='') function assign_values(&$action, $id)
{ {
global $conf, $db, $langs, $user; global $conf, $db, $langs, $user;
global $form; global $form;
$ret = $this->getObject($id);
parent::assign_values($action); parent::assign_values($action);
@ -77,15 +97,6 @@ class ActionsContactCardDefault extends ActionsContactCardCommon
$this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'contact'); $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'contact');
$this->tpl['showend']=dol_get_fiche_end(); $this->tpl['showend']=dol_get_fiche_end();
// Confirm delete contact
if ($user->rights->societe->contact->supprimer)
{
if ($_GET["action"] == 'delete')
{
$this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
}
}
$objsoc = new Societe($db); $objsoc = new Societe($db);
$objsoc->fetch($this->object->fk_soc); $objsoc->fetch($this->object->fk_soc);
@ -93,6 +104,14 @@ class ActionsContactCardDefault extends ActionsContactCardCommon
$this->tpl['actionsdone']=show_actions_done($conf,$langs,$db,$objsoc,$this->object,1); $this->tpl['actionsdone']=show_actions_done($conf,$langs,$db,$objsoc,$this->object,1);
} }
else
{
// Confirm delete contact
if ($action == 'delete' && $user->rights->societe->contact->supprimer)
{
$this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$this->object->id,$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
}
}
if ($action == 'list') if ($action == 'list')
{ {

View File

@ -39,9 +39,10 @@ $langs->load("commercial");
$mesg=''; $error=0; $errors=array(); $mesg=''; $error=0; $errors=array();
$action = GETPOST('action'); $action = (GETPOST('action') ? GETPOST('action') : 'view');
$id = GETPOST("id"); $confirm = GETPOST('confirm');
$socid = GETPOST("socid"); $id = GETPOST("id");
$socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$object = new Contact($db); $object = new Contact($db);
@ -52,8 +53,8 @@ $canvas = $object->canvas?$object->canvas:GETPOST("canvas");
if (! empty($canvas)) if (! empty($canvas))
{ {
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
$objcanvas = new Canvas($db,$action); $objcanvas = new Canvas($db, $action);
$objcanvas->getCanvas('contact','contactcard',$canvas); $objcanvas->getCanvas('contact', 'contactcard', $canvas);
} }
// Security check // Security check
@ -69,25 +70,9 @@ $hookmanager->callHooks(array('contactcard'));
* Actions * Actions
*/ */
$parameters=array('id'=>$id); $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
// ---------- start deprecated. Use hook to hook actions.
// If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
// If canvas actions are not defined, we use standard feature.
if (method_exists($objcanvas->control,'doActions'))
{
$objcanvas->doActions($id);
if (! empty($objcanvas->error) || (! empty($objcanvas->errors) && count($objcanvas->errors) > 0))
{
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='edit'; }
}
}
// ---------- end deprecated.
if (empty($reshook)) if (empty($reshook))
{ {
// Cancel // Cancel
@ -98,7 +83,7 @@ if (empty($reshook))
} }
// Creation utilisateur depuis contact // Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
{ {
// Recuperation contact actuel // Recuperation contact actuel
$result = $object->fetch($_GET["id"]); $result = $object->fetch($_GET["id"]);
@ -137,7 +122,7 @@ if (empty($reshook))
} }
// Add contact // Add contact
if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer) if ($action == 'add' && $user->rights->societe->contact->creer)
{ {
$db->begin(); $db->begin();
@ -196,7 +181,7 @@ if (empty($reshook))
} }
} }
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer)
{ {
$result=$object->fetch($_GET["id"]); $result=$object->fetch($_GET["id"]);
@ -215,12 +200,12 @@ if (empty($reshook))
} }
} }
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{ {
if (empty($_POST["name"])) if (empty($_POST["name"]))
{ {
$error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label"))); $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'edit'; $action = 'edit';
} }
if (! count($errors)) if (! count($errors))
@ -287,41 +272,14 @@ if ($socid > 0)
$objsoc->fetch($socid); $objsoc->fetch($socid);
} }
// TODO Mutualize this part of code (same than societe/soc.php and product/fiche.php) if (is_object($objcanvas) && $objcanvas->displayCanvasExists())
if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
{ {
// ----------------------------------------- // -----------------------------------------
// When used with CANVAS // When used with CANVAS
// ----------------------------------------- // -----------------------------------------
if ($action == 'create')
{ $objcanvas->assign_values($action, $id); // Set value for templates
$objcanvas->assign_values($action); // Set value for templates $objcanvas->display_canvas(); // Show template
$objcanvas->display_canvas($action); // Show template
}
else if ($action == 'edit')
{
$objcanvas->control->object=$objcanvas->getObject($id); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl
if (empty($objcanvas->control->object))
{
$object = new Contact($db);
$object->fetch($id,$user);
$objcanvas->control->object=$object;
}
$objcanvas->assign_values($action); // Set value for templates
$objcanvas->display_canvas($action); // Show template
}
else
{
$objcanvas->control->object=$objcanvas->getObject($id); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl
if (empty($objcanvas->control->object))
{
$object = new Contact($db);
$object->fetch($id,$user);
$objcanvas->control->object=$object;
}
$objcanvas->assign_values('view'); // Assign values
$objcanvas->display_canvas('view'); // Show template
}
} }
else else
{ {
@ -332,7 +290,7 @@ else
// Confirm deleting contact // Confirm deleting contact
if ($user->rights->societe->contact->supprimer) if ($user->rights->societe->contact->supprimer)
{ {
if ($_GET["action"] == 'delete') if ($action == 'delete')
{ {
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1); $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
@ -342,7 +300,7 @@ else
/* /*
* Onglets * Onglets
*/ */
if (GETPOST("id") > 0) if ($id > 0)
{ {
// Si edition contact deja existant // Si edition contact deja existant
$object = new Contact($db); $object = new Contact($db);
@ -350,7 +308,7 @@ else
if ($return <= 0) if ($return <= 0)
{ {
dol_print_error('',$object->error); dol_print_error('',$object->error);
$_GET["id"]=0; $id=0;
} }
// Show tabs // Show tabs
@ -361,7 +319,7 @@ else
if ($user->rights->societe->contact->creer) if ($user->rights->societe->contact->creer)
{ {
if (GETPOST("action") == 'create') if ($action == 'create')
{ {
/* /*
* Fiche en mode creation * Fiche en mode creation
@ -549,7 +507,7 @@ else
print "</form>"; print "</form>";
} }
elseif (GETPOST("action") == 'edit' && GETPOST("id")) elseif ($action == 'edit' && ! empty($id))
{ {
/* /*
* Fiche en mode edition * Fiche en mode edition
@ -734,7 +692,7 @@ else
} }
} }
if (GETPOST("id") && GETPOST("action") != 'edit') if (! empty($id) && $action != 'edit')
{ {
$objsoc = new Societe($db); $objsoc = new Societe($db);
@ -744,7 +702,7 @@ else
dol_htmloutput_errors($error,$errors); dol_htmloutput_errors($error,$errors);
if ($_GET["action"] == 'create_user') if ($action == 'create_user')
{ {
// Full firstname and name separated with a dot : firstname.name // Full firstname and name separated with a dot : firstname.name
include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');

View File

@ -32,9 +32,10 @@ class Canvas
var $db; var $db;
var $error; var $error;
var $errors=array(); var $errors=array();
var $actiontype;
var $action; var $dirmodule; // Module directory
var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...) var $targetmodule; // Module concerned by canvas (ex: thirdparty, contact, ...)
var $canvas; // Name of canvas var $canvas; // Name of canvas
var $card; // Tab (sub-canvas) var $card; // Tab (sub-canvas)
@ -49,29 +50,17 @@ class Canvas
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $DB Database handler
* @param string $action Action ('create', 'view', 'edit')
*/ */
function Canvas($DB, $action='view') function __construct($DB, $actiontype='view')
{ {
$this->db = $DB; $this->db = $DB;
$this->action = $action;
if ($this->action == 'add') $this->action='create'; $this->actiontype = $actiontype;
if ($this->action == 'update') $this->action='edit'; if ($this->actiontype == 'add') $this->actiontype='create';
if (empty($this->action)) $this->action='view'; if ($this->actiontype == 'update') $this->actiontype='edit';
if (empty($this->actiontype) || $this->actiontype == 'delete' || $this->actiontype == 'create_user') $this->actiontype='view';
} }
/**
* Set action type
*
* @deprecated Kept for backward compatibility
*/
function setAction($action='view')
{
return $this->action = $action;
}
/** /**
* Initialize properties: ->targetmodule, ->canvas, ->card * Initialize properties: ->targetmodule, ->canvas, ->card
* and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View)
@ -90,17 +79,17 @@ class Canvas
$this->targetmodule = $module; $this->targetmodule = $module;
$this->canvas = $canvas; $this->canvas = $canvas;
$this->card = $card; $this->card = $card;
$dirmodule = $module; $this->dirmodule = $module;
// Correct values if canvas is into an external module // Correct values if canvas is into an external module
if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs)) if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs))
{ {
$this->canvas = $regs[1]; $this->canvas = $regs[1];
$dirmodule = $regs[2]; $this->dirmodule = $regs[2];
} }
// For compatibility // For compatibility
if ($dirmodule == 'thirdparty') { $dirmodule = 'societe'; } if ($this->dirmodule == 'thirdparty') { $this->dirmodule = 'societe'; }
$controlclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php'); $controlclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php');
if (file_exists($controlclassfile)) if (file_exists($controlclassfile))
{ {
// Include actions class (controller) // Include actions class (controller)
@ -109,23 +98,11 @@ class Canvas
// Instantiate actions class (controller) // Instantiate actions class (controller)
$controlclassname = 'Actions'.ucfirst($this->card).ucfirst($this->canvas); $controlclassname = 'Actions'.ucfirst($this->card).ucfirst($this->canvas);
$this->control = new $controlclassname($this->db,$this->targetmodule,$this->canvas,$this->card); $this->control = new $controlclassname($this->db, $this->dirmodule, $this->targetmodule, $this->canvas, $this->card);
} }
// TODO Dao should be declared and used by controller or templates when required only
$modelclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
if (file_exists($modelclassfile))
{
// Include dataservice class (model)
require_once($modelclassfile);
// Instantiate dataservice class (model)
$modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas);
$this->control->object = new $modelclassname($this->db);
}
// Template dir // Template dir
$this->template_dir = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/'); $this->template_dir = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/tpl/');
if (! is_dir($this->template_dir)) if (! is_dir($this->template_dir))
{ {
$this->template_dir=''; $this->template_dir='';
@ -137,89 +114,61 @@ class Canvas
return 1; return 1;
} }
/** /**
* Execute actions * Shared method for canvas to execute actions
* *
* @param id Id of object (may be empty for creation) * @param string $action Action string
* @deprecated Use actions with hooks instead * @param int $id Object id
*/ * @return void
function doActions($id)
{
$out='';
// If function to do actions is overwritten, we use new one
if (method_exists($this->control,'doActions'))
{
$out = $this->control->doActions($id,$this->targetmodule,$this->canvas,$this->card);
$this->errors = ($this->control->errors?$this->control->errors:$this->control->object->errors);
$this->error = ($this->control->error?$this->control->error:$this->control->object->error);
}
return $out;
}
/**
* Get object
*
* @param param1 Param1
* @param param2 Param2
* @param param3 Param3
* @return object Object loaded
*/
function getObject($param1, $param2='', $param3='')
{
if (is_object($this->control->object) && method_exists($this->control->object,'fetch'))
{
$this->control->object->fetch($param1, $param2, $param3);
return $this->control->object;
}
else
{
return 0;
}
}
/**
* Shared method for canvas to assign values for templates
*/ */
function assign_values($action) function doActions(&$action='view', $id=0)
{ {
if (method_exists($this->control,'assign_values')) $this->control->assign_values($action); if (method_exists($this->control,'doActions'))
{
$ret = $this->control->doActions($action, $id);
return $ret;
}
} }
/** /**
* Return the template to display canvas (if it exists) * Shared method for canvas to assign values for templates
*
* @param string $action Action string
* @param int $id Object id
* @return void
*/
function assign_values(&$action='view', $id=0)
{
if (method_exists($this->control,'assign_values')) $this->control->assign_values($action, $id);
}
/**
* Return the template to display canvas (if it exists)
* *
* @param string $mode 'create', ''='view', 'edit', 'list' * @return string Path to display canvas file if it exists, '' otherwise.
* @return string Path to display canvas file if it exists, '' otherwise.
*/ */
function displayCanvasExists($mode='view') function displayCanvasExists()
{ {
$newmode=$mode;
if (empty($newmode)) $newmode='view';
if (empty($this->template_dir)) return 0; if (empty($this->template_dir)) return 0;
//print $this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php'; //print $this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php';
if (file_exists($this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php')) return 1; if (file_exists($this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php')) return 1;
else return 0; else return 0;
} }
/** /**
* Display a canvas page. This will include the template for output. * Display a canvas page. This will include the template for output.
* Variables used by templates may have been defined, loaded before * Variables used by templates may have been defined, loaded before
* into the assign_values function. * into the assign_values function.
* *
* @param string $mode 'create', 'view', 'edit' * @return void
* @param int $id Id of object to show
*/ */
function display_canvas($mode='view',$id=0) function display_canvas()
{ {
global $db, $conf, $langs, $user, $canvas; global $db, $conf, $langs, $user, $canvas;
global $id, $form, $formfile; global $form, $formfile;
//print $this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php';exit; include($this->template_dir.($this->card?$this->card.'_':'').$this->actiontype.'.tpl.php'); // Include native PHP template
include($this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php'); // Include native PHP template
} }
} }

View File

@ -3,7 +3,7 @@
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2008-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2008-2011 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -30,16 +30,18 @@
include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php");
/** \class modBanque /**
\brief Classe de description et activation du module Banque * \class modBanque
* \brief Classe de description et activation du module Banque
*/ */
class modBanque extends DolibarrModules class modBanque extends DolibarrModules
{ {
/** /**
* \brief Constructeur. Definit les noms, constantes et boites * Constructor.
* \param DB handler d'acc<EFBFBD>s base *
* @param DoliDB $DB Database handler
*/ */
function modBanque($DB) function modBanque($DB)
{ {
@ -166,6 +168,7 @@ class modBanque extends DolibarrModules
* Function called when module is enabled. * Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories. * It also creates data directories.
*
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
function init() function init()
@ -184,6 +187,7 @@ class modBanque extends DolibarrModules
* Function called when module is disabled. * Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database. * Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted. * Data directories are not deleted.
*
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
function remove() function remove()

View File

@ -29,6 +29,7 @@
abstract class ActionsCardCommon abstract class ActionsCardCommon
{ {
var $db; var $db;
var $dirmodule;
var $targetmodule; var $targetmodule;
var $canvas; var $canvas;
var $card; var $card;
@ -45,27 +46,74 @@ abstract class ActionsCardCommon
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $DB Database handler
* @param string $targetmodule Name of directory of module where canvas is stored * @param string $dirmodule Name of directory of module
* @param string $canvas Name of canvas * @param string $targetmodule Name of directory where canvas is stored
* @param string $card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardCommon($DB,$targetmodule,$canvas,$card) function __construct($DB, $dirmodule, $targetmodule, $canvas, $card)
{ {
$this->db = $DB; $this->db = $DB;
$this->dirmodule = $dirmodule;
$this->targetmodule = $targetmodule; $this->targetmodule = $targetmodule;
$this->canvas = $canvas; $this->canvas = $canvas;
$this->card = $card; $this->card = $card;
} }
/**
* Instantiation of DAO class
*
* @return void
*/
private function getInstanceDao()
{
if (! is_object($this->object))
{
$modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
if (file_exists($modelclassfile))
{
// Include dataservice class (model)
$ret = require_once($modelclassfile);
if ($ret)
{
// Instantiate dataservice class (model)
$modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas);
$this->object = new $modelclassname($this->db);
}
}
}
}
/**
* Get object
*
* @param int Object id
* @return object Object loaded
*/
function getObject($id)
{
$ret = $this->getInstanceDao();
if (is_object($this->object) && method_exists($this->object,'fetch'))
{
if (! empty($id)) $this->object->fetch($id);
}
else
{
$object = new Societe($this->db);
if (! empty($id)) $object->fetch($id);
$this->object = $object;
}
}
/** /**
* Load data control * Load data control
* *
* @param int $socid Id of third party * @param int $socid Id of third party
* @return void * @return void
*/ */
function doActions($socid) function doActions(&$action)
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
@ -83,78 +131,68 @@ abstract class ActionsCardCommon
// Add new third party // Add new third party
if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
&& ($_POST["action"] == 'add' || $_POST["action"] == 'update')) && ($action == 'add' || $action == 'update'))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
$error=0; $error=0;
if ($_POST["action"] == 'update') if (GETPOST("private") == 1)
{ {
// Load properties of company $this->object->particulier = GETPOST("private");
$this->object->fetch($socid);
}
if ($_REQUEST["private"] == 1) $this->object->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
{ $this->object->nom_particulier = $_POST["nom"];
$this->object->particulier = $_REQUEST["private"]; $this->object->prenom = $_POST["prenom"];
$this->object->civilite_id = $_POST["civilite_id"];
$this->object->nom = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
$this->object->nom_particulier = $_POST["nom"];
$this->object->prenom = $_POST["prenom"];
$this->object->civilite_id = $_POST["civilite_id"];
} }
else else
{ {
$this->object->nom = $_POST["nom"]; $this->object->name = $_POST["nom"];
} }
$this->object->adresse = $_POST["adresse"]; // TODO deprecated $this->object->address = $_POST["adresse"];
$this->object->address = $_POST["adresse"]; $this->object->zip = $_POST["zipcode"];
$this->object->cp = $_POST["zipcode"]; // TODO deprecated $this->object->town = $_POST["town"];
$this->object->zip = $_POST["zipcode"]; $this->object->country_id = $_POST["pays_id"];
$this->object->ville = $_POST["town"]; // TODO deprecated $this->object->state_id = $_POST["departement_id"];
$this->object->town = $_POST["town"]; $this->object->tel = $_POST["tel"];
$this->object->pays_id = $_POST["pays_id"]; // TODO deprecated $this->object->fax = $_POST["fax"];
$this->object->country_id = $_POST["pays_id"]; $this->object->email = trim($_POST["email"]);
$this->object->state_id = $_POST["departement_id"]; $this->object->url = $_POST["url"];
$this->object->tel = $_POST["tel"]; $this->object->idprof1 = $_POST["idprof1"];
$this->object->fax = $_POST["fax"]; $this->object->idprof2 = $_POST["idprof2"];
$this->object->email = trim($_POST["email"]); $this->object->idprof3 = $_POST["idprof3"];
$this->object->url = $_POST["url"]; $this->object->idprof4 = $_POST["idprof4"];
$this->object->siren = $_POST["idprof1"]; $this->object->prefix_comm = $_POST["prefix_comm"];
$this->object->siret = $_POST["idprof2"]; $this->object->code_client = $_POST["code_client"];
$this->object->ape = $_POST["idprof3"]; $this->object->code_fournisseur = $_POST["code_fournisseur"];
$this->object->idprof4 = $_POST["idprof4"]; $this->object->capital = $_POST["capital"];
$this->object->prefix_comm = $_POST["prefix_comm"]; $this->object->gencod = $_POST["gencod"];
$this->object->code_client = $_POST["code_client"]; $this->object->canvas = GETPOST("canvas");
$this->object->code_fournisseur = $_POST["code_fournisseur"];
$this->object->capital = $_POST["capital"];
$this->object->gencod = $_POST["gencod"];
$this->object->canvas = $_REQUEST["canvas"];
$this->object->tva_assuj = $_POST["assujtva_value"]; $this->object->tva_assuj = $_POST["assujtva_value"];
// Local Taxes // Local Taxes
$this->object->localtax1_assuj = $_POST["localtax1assuj_value"]; $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
$this->object->localtax2_assuj = $_POST["localtax2assuj_value"]; $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
$this->object->tva_intra = $_POST["tva_intra"]; $this->object->tva_intra = $_POST["tva_intra"];
$this->object->forme_juridique_code = $_POST["forme_juridique_code"]; $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
$this->object->effectif_id = $_POST["effectif_id"]; $this->object->effectif_id = $_POST["effectif_id"];
if ($_REQUEST["private"] == 1) if (GETPOST("private") == 1)
{ {
$this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid $this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid
} }
else else
{ {
$this->object->typent_id = $_POST["typent_id"]; $this->object->typent_id = $_POST["typent_id"];
} }
$this->object->client = $_POST["client"]; $this->object->client = $_POST["client"];
$this->object->fournisseur = $_POST["fournisseur"]; $this->object->fournisseur = $_POST["fournisseur"];
$this->object->fournisseur_categorie = $_POST["fournisseur_categorie"]; $this->object->fournisseur_categorie = $_POST["fournisseur_categorie"];
$this->object->commercial_id = $_POST["commercial_id"]; $this->object->commercial_id = $_POST["commercial_id"];
$this->object->default_lang = $_POST["default_lang"]; $this->object->default_lang = $_POST["default_lang"];
// Check parameters // Check parameters
if (empty($_POST["cancel"])) if (empty($_POST["cancel"]))
@ -164,27 +202,27 @@ abstract class ActionsCardCommon
$error = 1; $error = 1;
$langs->load("errors"); $langs->load("errors");
$this->error = $langs->trans("ErrorBadEMail",$this->object->email); $this->error = $langs->trans("ErrorBadEMail",$this->object->email);
$_GET["action"] = $_POST["action"]=='add'?'create':'edit'; $action = ($action == 'add' ? 'create' : 'edit');
} }
if (! empty($this->object->url) && ! isValidUrl($this->object->url)) if (! empty($this->object->url) && ! isValidUrl($this->object->url))
{ {
$error = 1; $error = 1;
$langs->load("errors"); $langs->load("errors");
$this->error = $langs->trans("ErrorBadUrl",$this->object->url); $this->error = $langs->trans("ErrorBadUrl",$this->object->url);
$_GET["action"] = $_POST["action"]=='add'?'create':'edit'; $action = ($action == 'add' ? 'create' : 'edit');
} }
if ($this->object->fournisseur && ! $conf->fournisseur->enabled) if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
{ {
$error = 1; $error = 1;
$langs->load("errors"); $langs->load("errors");
$this->error = $langs->trans("ErrorSupplierModuleNotEnabled"); $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
$_GET["action"] = $_POST["action"]=='add'?'create':'edit'; $action = ($action == 'add' ? 'create' : 'edit');
} }
} }
if (! $error) if (! $error)
{ {
if ($_POST["action"] == 'add') if ($action == 'add')
{ {
$this->db->begin(); $this->db->begin();
@ -248,48 +286,44 @@ abstract class ActionsCardCommon
$this->db->rollback(); $this->db->rollback();
$this->errors=$this->object->errors; $this->errors=$this->object->errors;
$_GET["action"]='create'; $action = 'create';
} }
} }
if ($_POST["action"] == 'update') if ($action == 'update')
{ {
if ($_POST["cancel"]) if ($_POST["cancel"])
{ {
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
exit; exit;
} }
$oldsoccanvas = new Canvas($this->db); $oldsoccanvas = dol_clone($this->object);
$oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas);
$result=$oldsoccanvas->control->object->fetch($socid);
// To avoid setting code if third party is not concerned. But if it had values, we keep them. // To avoid setting code if third party is not concerned. But if it had values, we keep them.
if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client)) $this->object->code_client=''; if (empty($this->object->client) && empty($oldsoccanvas->code_client)) $this->object->code_client='';
if (empty($this->object->fournisseur)&& empty($oldsoccanvas->control->object->code_fournisseur)) $this->object->code_fournisseur=''; //var_dump($soccanvas);exit; if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) $this->object->code_fournisseur='';
$result = $this->object->update($socid,$user,1,$oldsoccanvas->control->object->codeclient_modifiable(),$oldsoccanvas->control->object->codefournisseur_modifiable()); $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
if ($result >= 0) if ($result >= 0)
{ {
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid); Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
exit; exit;
} }
else else
{ {
$this->object->id = $socid; $this->object->id = $this->object->id;
$reload = 0; $reload = 0;
$this->errors = $this->object->errors; $this->errors = $this->object->errors;
$_GET["action"]="edit"; $action = "edit";
} }
} }
} }
} }
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes') if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
{ {
$this->object->fetch($socid); $result = $this->object->delete($this->object->id);
$result = $this->object->delete($socid);
if ($result >= 0) if ($result >= 0)
{ {
@ -300,14 +334,14 @@ abstract class ActionsCardCommon
{ {
$reload = 0; $reload = 0;
$this->errors=$this->object->errors; $this->errors=$this->object->errors;
$_GET["action"]=''; $action = '';
} }
} }
/* /*
* Generate document * Generate document
*/ */
if (GETPOST('action') == 'builddoc') // En get ou en post if ($action == 'builddoc') // En get ou en post
{ {
if (is_numeric(GETPOST('model'))) if (is_numeric(GETPOST('model')))
{ {
@ -317,7 +351,6 @@ abstract class ActionsCardCommon
{ {
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
$this->object->fetch($socid);
$this->object->fetch_thirdparty(); $this->object->fetch_thirdparty();
// Define output language // Define output language
@ -345,38 +378,18 @@ abstract class ActionsCardCommon
} }
} }
/**
* Return the title of card
*
* @param string $action Type of action
* @return string HTML output
*/
private function getTitle($action)
{
global $langs;
$out='';
if ($action == 'view') $out.= $langs->trans("Individual");
if ($action == 'edit') $out.= $langs->trans("EditIndividual");
if ($action == 'create') $out.= $langs->trans("NewIndividual");
return $out;
}
/** /**
* Set content of ->tpl array, to use into template * Set content of ->tpl array, to use into template
* *
* @param string $action Type of action * @param string $action Type of action
* @return string HTML output * @return string HTML output
*/ */
function assign_values($action) function assign_values(&$action)
{ {
global $conf, $langs, $user, $mysoc, $canvas; global $conf, $langs, $user, $mysoc, $canvas;
global $form, $formadmin, $formcompany; global $form, $formadmin, $formcompany;
if ($action == 'create' || $action == 'edit') $this->assign_post(); if ($action == 'add' || $action == 'update') $this->assign_post($action);
if ($_GET["type"]=='f') { $this->object->fournisseur=1; } if ($_GET["type"]=='f') { $this->object->fournisseur=1; }
if ($_GET["type"]=='c') { $this->object->client=1; } if ($_GET["type"]=='c') { $this->object->client=1; }
@ -389,8 +402,6 @@ abstract class ActionsCardCommon
$this->tpl[$key] = $value; $this->tpl[$key] = $value;
} }
$this->tpl['title'] = $this->getTitle($action);
$this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors); $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors);
if ($action == 'create') if ($action == 'create')
@ -546,7 +557,6 @@ abstract class ActionsCardCommon
else else
{ {
$head = societe_prepare_head($this->object); $head = societe_prepare_head($this->object);
$title = $this->getTitle($action);
$this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'company'); $this->tpl['showhead']=dol_get_fiche_head($head, 'card', $title, 0, 'company');
$this->tpl['showend']=dol_get_fiche_end(); $this->tpl['showend']=dol_get_fiche_end();
@ -666,27 +676,25 @@ abstract class ActionsCardCommon
global $langs, $mysoc; global $langs, $mysoc;
$this->object->id = $_POST["socid"]; $this->object->id = $_POST["socid"];
$this->object->nom = $_POST["nom"]; $this->object->name = $_POST["nom"];
$this->object->prefix_comm = $_POST["prefix_comm"]; $this->object->prefix_comm = $_POST["prefix_comm"];
$this->object->client = $_POST["client"]; $this->object->client = $_POST["client"];
$this->object->code_client = $_POST["code_client"]; $this->object->code_client = $_POST["code_client"];
$this->object->fournisseur = $_POST["fournisseur"]; $this->object->fournisseur = $_POST["fournisseur"];
$this->object->code_fournisseur = $_POST["code_fournisseur"]; $this->object->code_fournisseur = $_POST["code_fournisseur"];
$this->object->adresse = $_POST["adresse"]; // TODO obsolete
$this->object->address = $_POST["adresse"]; $this->object->address = $_POST["adresse"];
$this->object->zip = $_POST["zipcode"]; $this->object->zip = $_POST["zipcode"];
$this->object->town = $_POST["town"]; $this->object->town = $_POST["town"];
$this->object->pays_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id; $this->object->country_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->country_id;
$this->object->country_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
$this->object->state_id = $_POST["departement_id"]; $this->object->state_id = $_POST["departement_id"];
$this->object->tel = $_POST["tel"]; $this->object->tel = $_POST["tel"];
$this->object->fax = $_POST["fax"]; $this->object->fax = $_POST["fax"];
$this->object->email = $_POST["email"]; $this->object->email = $_POST["email"];
$this->object->url = $_POST["url"]; $this->object->url = $_POST["url"];
$this->object->capital = $_POST["capital"]; $this->object->capital = $_POST["capital"];
$this->object->siren = $_POST["idprof1"]; $this->object->idprof1 = $_POST["idprof1"];
$this->object->siret = $_POST["idprof2"]; $this->object->idprof2 = $_POST["idprof2"];
$this->object->ape = $_POST["idprof3"]; $this->object->idprof3 = $_POST["idprof3"];
$this->object->idprof4 = $_POST["idprof4"]; $this->object->idprof4 = $_POST["idprof4"];
$this->object->typent_id = $_POST["typent_id"]; $this->object->typent_id = $_POST["typent_id"];
$this->object->effectif_id = $_POST["effectif_id"]; $this->object->effectif_id = $_POST["effectif_id"];

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,24 +29,27 @@ include_once(DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php');
*/ */
class ActionsCardCompany extends ActionsCardCommon class ActionsCardCompany extends ActionsCardCommon
{ {
var $targetmodule; var $dirmodule;
var $targetmodule;
var $canvas; var $canvas;
var $card; var $card;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Handler acces base de donnees * @param DoliDB $DB Handler acces base de donnees
* @param string $targetmodule Name of directory of module where canvas is stored * @param string $dirmodule Name of directory of module
* @param string $canvas Name of canvas * @param string $targetmodule Name of directory of module where canvas is stored
* @param string $card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardCompany($DB,$targetmodule,$canvas,$card) function __construct($DB, $dirmodule, $targetmodule, $canvas, $card)
{ {
$this->db = $DB; $this->db = $DB;
$this->targetmodule = $targetmodule; $this->dirmodule = $dirmodule;
$this->canvas = $canvas; $this->targetmodule = $targetmodule;
$this->card = $card; $this->canvas = $canvas;
$this->card = $card;
} }
/** /**
@ -75,9 +78,11 @@ class ActionsCardCompany extends ActionsCardCommon
* @param int $socid Id of object (may be empty for creation) * @param int $socid Id of object (may be empty for creation)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function doActions($socid) function doActions(&$action, $id)
{ {
$return = parent::doActions($socid); $ret = $this->getObject($id);
$return = parent::doActions($action);
return $return; return $return;
} }
@ -88,12 +93,16 @@ class ActionsCardCompany extends ActionsCardCommon
* @param string $action Type of action * @param string $action Type of action
* @return void * @return void
*/ */
function assign_values($action) function assign_values(&$action, $id)
{ {
global $conf, $langs, $user, $mysoc; global $conf, $langs, $user, $mysoc;
global $form, $formadmin, $formcompany; global $form, $formadmin, $formcompany;
$ret = $this->getObject($id);
parent::assign_values($action); parent::assign_values($action);
$this->tpl['title'] = $this->getTitle($action);
$this->tpl['profid1'] = $this->object->siren; $this->tpl['profid1'] = $this->object->siren;
$this->tpl['profid2'] = $this->object->siret; $this->tpl['profid2'] = $this->object->siret;
@ -153,7 +162,7 @@ class ActionsCardCompany extends ActionsCardCommon
else else
{ {
// Confirm delete third party // Confirm delete third party
if ($_GET["action"] == 'delete' || $conf->use_javascript_ajax) if ($action == 'delete')
{ {
$this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,"1,action-delete"); $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,"1,action-delete");
} }
@ -201,7 +210,7 @@ class ActionsCardCompany extends ActionsCardCommon
$socm = new Societe($this->db); $socm = new Societe($this->db);
$socm->fetch($this->object->parent); $socm->fetch($this->object->parent);
$this->tpl['parent_company'] = $socm->getNomUrl(1).' '.($socm->code_client?"(".$socm->code_client.")":""); $this->tpl['parent_company'] = $socm->getNomUrl(1).' '.($socm->code_client?"(".$socm->code_client.")":"");
$this->tpl['parent_company'].= $socm->ville?' - '.$socm->ville:''; $this->tpl['parent_company'].= ($socm->town ? ' - ' . $socm->town : '');
} }
else else
{ {

View File

@ -28,24 +28,27 @@ include_once(DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php');
*/ */
class ActionsCardIndividual extends ActionsCardCommon class ActionsCardIndividual extends ActionsCardCommon
{ {
var $targetmodule; var $dirmodule;
var $targetmodule;
var $canvas; var $canvas;
var $card; var $card;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $DB Handler acces base de donnees * @param DoliDB $DB Handler acces base de donnees
* @param string $targetmodule Name of directory of module where canvas is stored * @param string $dirmodule Name of directory of module
* @param string $canvas Name of canvas * @param string $targetmodule Name of directory of module where canvas is stored
* @param string $card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardIndividual($DB,$targetmodule,$canvas,$card) function __construct($DB, $dirmodule, $targetmodule, $canvas, $card)
{ {
$this->db = $DB; $this->db = $DB;
$this->targetmodule = $targetmodule; $this->dirmodule = $dirmodule;
$this->canvas = $canvas; $this->targetmodule = $targetmodule;
$this->card = $card; $this->canvas = $canvas;
$this->card = $card;
} }
@ -72,12 +75,14 @@ class ActionsCardIndividual extends ActionsCardCommon
/** /**
* Execute actions * Execute actions
* *
* @param int $socid Id of object (may be empty for creation) * @param int $id Id of object (may be empty for creation)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function doActions($socid) function doActions(&$action, $id)
{ {
$return = parent::doActions($socid); $ret = $this->getObject($id);
$return = parent::doActions($action);
return $return; return $return;
} }
@ -88,12 +93,16 @@ class ActionsCardIndividual extends ActionsCardCommon
* @param string $action Type of action * @param string $action Type of action
* @return void * @return void
*/ */
function assign_values($action) function assign_values(&$action, $id)
{ {
global $conf, $langs; global $conf, $langs;
global $form, $formcompany; global $form, $formcompany;
$ret = $this->getObject($id);
parent::assign_values($action); parent::assign_values($action);
$this->tpl['title'] = $this->getTitle($action);
if ($action == 'create' || $action == 'edit') if ($action == 'create' || $action == 'edit')
{ {
@ -102,7 +111,7 @@ class ActionsCardIndividual extends ActionsCardCommon
else else
{ {
// Confirm delete third party // Confirm delete third party
if ($_GET["action"] == 'delete' || $conf->use_javascript_ajax) if ($action == 'delete' || $conf->use_javascript_ajax)
{ {
$this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteAnIndividual"),$langs->trans("ConfirmDeleteIndividual"),"confirm_delete",'',0,"1,action-delete"); $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id,$langs->trans("DeleteAnIndividual"),$langs->trans("ConfirmDeleteIndividual"),"confirm_delete",'',0,"1,action-delete");
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ class DaoThirdPartyIndividual extends Societe
* *
* @param DoliDB $DB Databae handler * @param DoliDB $DB Databae handler
*/ */
function DaoThirdPartyIndividual($DB) function __construct($DB)
{ {
$this->db = $DB; $this->db = $DB;
} }

View File

@ -297,8 +297,7 @@ class Societe extends CommonObject
$this->errors=array(); $this->errors=array();
$result = 0; $result = 0;
$this->name=$this->name?trim($this->name):trim($this->nom); $this->name = trim($this->name);
$this->nom=$this->name; // For backward compatibility
if (! $this->name) if (! $this->name)
{ {
@ -393,34 +392,29 @@ class Societe extends CommonObject
$now=dol_now(); $now=dol_now();
// Clean parameters // Clean parameters
$this->id=$id; $this->id = $id;
$this->name=$this->name?trim($this->name):trim($this->nom); $this->name = trim($this->name);
$this->nom=trim($this->nom); // TODO obsolete $this->address = trim($this->address);
$this->address=$this->address?trim($this->address):trim($this->adresse); $this->zip = trim($this->zip);
$this->adresse=$this->address; // TODO obsolete $this->town = trim($this->town);
$this->zip=$this->zip?trim($this->zip):trim($this->cp); $this->state_id = trim($this->state_id);
$this->cp=$this->zip; // TODO obsolete $this->country_id = trim($this->country_id);
$this->town=$this->town?trim($this->town):trim($this->ville); $this->tel = trim($this->tel);
$this->ville=$this->town; // TODO obsolete $this->fax = trim($this->fax);
$this->state_id=trim($this->state_id); $this->tel = preg_replace("/\s/","",$this->tel);
$this->pays_id=trim($this->pays_id); $this->tel = preg_replace("/\./","",$this->tel);
$this->country_id=trim($this->country_id); $this->fax = preg_replace("/\s/","",$this->fax);
$this->tel=trim($this->tel); $this->fax = preg_replace("/\./","",$this->fax);
$this->fax=trim($this->fax); $this->email = trim($this->email);
$this->tel = preg_replace("/\s/","",$this->tel); $this->url = $this->url?clean_url($this->url,0):'';
$this->tel = preg_replace("/\./","",$this->tel); $this->idprof1 = trim($this->idprof1);
$this->fax = preg_replace("/\s/","",$this->fax); $this->idprof2 = trim($this->idprof2);
$this->fax = preg_replace("/\./","",$this->fax); $this->idprof3 = trim($this->idprof3);
$this->email=trim($this->email); $this->idprof4 = trim($this->idprof4);
$this->url=$this->url?clean_url($this->url,0):''; $this->prefix_comm = trim($this->prefix_comm);
$this->siren=trim($this->siren);
$this->siret=trim($this->siret);
$this->ape=trim($this->ape);
$this->idprof4=trim($this->idprof4);
$this->prefix_comm=trim($this->prefix_comm);
$this->tva_assuj=trim($this->tva_assuj); $this->tva_assuj = trim($this->tva_assuj);
$this->tva_intra=dol_sanitizeFileName($this->tva_intra,''); $this->tva_intra = dol_sanitizeFileName($this->tva_intra,'');
if (empty($this->status)) $this->status = 0; if (empty($this->status)) $this->status = 0;
// Local taxes // Local taxes
@ -477,9 +471,9 @@ class Societe extends CommonObject
$sql .= ",email = ".($this->email?"'".$this->db->escape($this->email)."'":"null"); $sql .= ",email = ".($this->email?"'".$this->db->escape($this->email)."'":"null");
$sql .= ",url = ".($this->url?"'".$this->db->escape($this->url)."'":"null"); $sql .= ",url = ".($this->url?"'".$this->db->escape($this->url)."'":"null");
$sql .= ",siren = '". $this->db->escape($this->siren) ."'"; $sql .= ",siren = '". $this->db->escape($this->idprof1) ."'";
$sql .= ",siret = '". $this->db->escape($this->siret) ."'"; $sql .= ",siret = '". $this->db->escape($this->idprof2) ."'";
$sql .= ",ape = '". $this->db->escape($this->ape) ."'"; $sql .= ",ape = '". $this->db->escape($this->idprof3) ."'";
$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'"; $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null"); $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null");
@ -629,7 +623,7 @@ class Societe extends CommonObject
$sql .= ', s.price_level'; $sql .= ', s.price_level';
$sql .= ', s.tms as date_update'; $sql .= ', s.tms as date_update';
$sql .= ', s.tel, s.fax, s.email, s.url, s.cp as zip, s.ville as town, s.note, s.client, s.fournisseur'; $sql .= ', s.tel, s.fax, s.email, s.url, s.cp as zip, s.ville as town, s.note, s.client, s.fournisseur';
$sql .= ', s.siren, s.siret, s.ape, s.idprof4'; $sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4';
$sql .= ', s.capital, s.tva_intra'; $sql .= ', s.capital, s.tva_intra';
$sql .= ', s.fk_typent as typent_id'; $sql .= ', s.fk_typent as typent_id';
$sql .= ', s.fk_effectif as effectif_id'; $sql .= ', s.fk_effectif as effectif_id';
@ -655,9 +649,9 @@ class Societe extends CommonObject
if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity = ".$conf->entity; if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity = ".$conf->entity;
if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity = ".$conf->entity; if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity = ".$conf->entity;
if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity = ".$conf->entity; if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity = ".$conf->entity;
if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($siren)."' AND s.entity = ".$conf->entity; if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity = ".$conf->entity;
if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($siret)."' AND s.entity = ".$conf->entity; if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity = ".$conf->entity;
if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($ape)."' AND s.entity = ".$conf->entity; if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity = ".$conf->entity;
if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity; if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -680,7 +674,7 @@ class Societe extends CommonObject
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->name = $obj->name; $this->name = $obj->name;
$this->nom = $obj->name; // TODO obsolete $this->nom = $obj->name; // TODO obsolete
$this->ref_ext = $obj->ref_ext; $this->ref_ext = $obj->ref_ext;
$this->ref_int = $obj->ref_int; $this->ref_int = $obj->ref_int;
@ -688,13 +682,13 @@ class Societe extends CommonObject
$this->date_update = $this->db->jdate($obj->date_update); $this->date_update = $this->db->jdate($obj->date_update);
$this->address = $obj->address; $this->address = $obj->address;
$this->adresse = $obj->address; // TODO obsolete $this->adresse = $obj->address; // TODO obsolete
$this->zip = $obj->zip; $this->zip = $obj->zip;
$this->cp = $obj->zip; // TODO obsolete $this->cp = $obj->zip; // TODO obsolete
$this->town = $obj->town; $this->town = $obj->town;
$this->ville = $obj->town;// TODO obsolete $this->ville = $obj->town; // TODO obsolete
$this->pays_id = $obj->fk_pays; // TODO obsolete $this->pays_id = $obj->fk_pays; // TODO obsolete
$this->country_id = $obj->fk_pays; $this->country_id = $obj->fk_pays;
$this->pays_code = $obj->fk_pays?$obj->pays_code:''; // TODO obsolete $this->pays_code = $obj->fk_pays?$obj->pays_code:''; // TODO obsolete
$this->country_code = $obj->fk_pays?$obj->pays_code:''; $this->country_code = $obj->fk_pays?$obj->pays_code:'';
@ -717,11 +711,11 @@ class Societe extends CommonObject
$this->parent = $obj->parent; $this->parent = $obj->parent;
$this->siren = $obj->siren; // TODO obsolete $this->siren = $obj->siren; // TODO obsolete
$this->idprof1 = $obj->siren; $this->idprof1 = $obj->siren;
$this->siret = $obj->siret; // TODO obsolete $this->siret = $obj->siret; // TODO obsolete
$this->idprof2 = $obj->siret; $this->idprof2 = $obj->siret;
$this->ape = $obj->ape; // TODO obsolete $this->ape = $obj->ape; // TODO obsolete
$this->idprof3 = $obj->ape; $this->idprof3 = $obj->ape;
$this->idprof4 = $obj->idprof4; $this->idprof4 = $obj->idprof4;

View File

@ -47,9 +47,9 @@ if ($conf->notification->enabled) $langs->load("mails");
$mesg=''; $error=0; $errors=array(); $mesg=''; $error=0; $errors=array();
$action = GETPOST('action'); $action = (GETPOST('action') ? GETPOST('action') : 'view');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
$socid = GETPOST("socid"); $socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$object = new Societe($db); $object = new Societe($db);
@ -61,8 +61,8 @@ $canvas = $object->canvas?$object->canvas:GETPOST("canvas");
if (! empty($canvas)) if (! empty($canvas))
{ {
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
$objcanvas = new Canvas($db,$action); $objcanvas = new Canvas($db, $action);
$objcanvas->getCanvas('thirdparty','card',$canvas); $objcanvas->getCanvas('thirdparty', 'card', $canvas);
} }
// Security check // Security check
@ -75,12 +75,11 @@ $hookmanager=new HookManager($db);
$hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields')); $hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields'));
/* /*
* Actions * Actions
*/ */
$parameters=array('socid'=>$socid); $parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
$error=$hookmanager->error; $errors=$hookmanager->errors; $error=$hookmanager->error; $errors=$hookmanager->errors;
@ -104,42 +103,33 @@ if (empty($reshook))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
if ($action == 'update') if ($action == 'update') $object->fetch($socid);
{
$object->fetch($socid);
}
if (GETPOST("private") == 1) if (GETPOST("private") == 1)
{ {
$object->particulier = GETPOST("private"); $object->particulier = GETPOST("private");
$object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]); $object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
$object->nom = $object->name; // TODO obsolete $object->nom_particulier = $_POST["nom"];
$object->nom_particulier = $_POST["nom"]; $object->prenom = $_POST["prenom"];
$object->prenom = $_POST["prenom"]; $object->civilite_id = $_POST["civilite_id"];
$object->civilite_id = $_POST["civilite_id"];
} }
else else
{ {
$object->name = $_POST["nom"]; $object->name = $_POST["nom"];
$object->nom = $object->name; // TODO obsolete
} }
$object->address = $_POST["adresse"]; $object->address = $_POST["adresse"];
$object->adresse = $_POST["adresse"]; // TODO obsolete
$object->zip = $_POST["zipcode"]; $object->zip = $_POST["zipcode"];
$object->cp = $_POST["zipcode"]; // TODO obsolete
$object->town = $_POST["town"]; $object->town = $_POST["town"];
$object->ville = $_POST["town"]; // TODO obsolete
$object->pays_id = $_POST["pays_id"];
$object->country_id = $_POST["pays_id"]; $object->country_id = $_POST["pays_id"];
$object->state_id = $_POST["departement_id"]; $object->state_id = $_POST["departement_id"];
$object->tel = $_POST["tel"]; $object->tel = $_POST["tel"];
$object->fax = $_POST["fax"]; $object->fax = $_POST["fax"];
$object->email = trim($_POST["email"]); $object->email = trim($_POST["email"]);
$object->url = trim($_POST["url"]); $object->url = trim($_POST["url"]);
$object->siren = $_POST["idprof1"]; $object->idprof1 = $_POST["idprof1"];
$object->siret = $_POST["idprof2"]; $object->idprof2 = $_POST["idprof2"];
$object->ape = $_POST["idprof3"]; $object->idprof4 = $_POST["idprof3"];
$object->idprof4 = $_POST["idprof4"]; $object->idprof4 = $_POST["idprof4"];
$object->prefix_comm = $_POST["prefix_comm"]; $object->prefix_comm = $_POST["prefix_comm"];
$object->code_client = $_POST["code_client"]; $object->code_client = $_POST["code_client"];
@ -159,11 +149,11 @@ if (empty($reshook))
$object->effectif_id = $_POST["effectif_id"]; $object->effectif_id = $_POST["effectif_id"];
if (GETPOST("private") == 1) if (GETPOST("private") == 1)
{ {
$object->typent_id = 8; // TODO predict another method if the field "special" change of rowid $object->typent_id = 8; // TODO predict another method if the field "special" change of rowid
} }
else else
{ {
$object->typent_id = $_POST["typent_id"]; $object->typent_id = $_POST["typent_id"];
} }
$object->client = $_POST["client"]; $object->client = $_POST["client"];
@ -479,41 +469,14 @@ $formcompany = new FormCompany($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
// TODO Mutualize this part of code (same than product/fiche.php and contact/fiche.php) if (is_object($objcanvas) && $objcanvas->displayCanvasExists())
if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
{ {
// ----------------------------------------- // -----------------------------------------
// When used with CANVAS // When used with CANVAS
// ----------------------------------------- // -----------------------------------------
if ($action == 'create')
{ $objcanvas->assign_values($action, $socid); // Set value for templates
$objcanvas->assign_values($action); // Set value for templates $objcanvas->display_canvas(); // Show template
$objcanvas->display_canvas($action,0); // Show template
}
elseif ($action == 'edit')
{
$objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl
if (empty($objcanvas->control->object))
{
$object = new Societe($db);
$object->fetch($socid);
$objcanvas->control->object=$object;
}
$objcanvas->assign_values($action); // Set value for templates
$objcanvas->display_canvas($action); // Show template
}
else
{
$objcanvas->control->object=$objcanvas->getObject($socid); // TODO: Getting and storing object should be done into assign_values (for template with no code) or into tpl
if (empty($objcanvas->control->object))
{
$object = new Societe($db);
$object->fetch($socid);
$objcanvas->control->object=$object;
}
$objcanvas->assign_values('view');
$objcanvas->display_canvas('view'); // Show template
}
} }
else else
{ {
@ -551,46 +514,42 @@ else
if ($conf->fournisseur->enabled && (GETPOST("type")=='f' || GETPOST("type")=='')) { $object->fournisseur=1; } if ($conf->fournisseur->enabled && (GETPOST("type")=='f' || GETPOST("type")=='')) { $object->fournisseur=1; }
if (GETPOST("private")==1) { $object->particulier=1; } if (GETPOST("private")==1) { $object->particulier=1; }
$object->name=$_POST["nom"]; $object->name = $_POST["nom"];
$object->nom=$_POST["nom"]; // TODO obsolete $object->prenom = $_POST["prenom"];
$object->prenom=$_POST["prenom"]; $object->particulier = $_REQUEST["private"];
$object->particulier=$_REQUEST["private"]; $object->prefix_comm = $_POST["prefix_comm"];
$object->prefix_comm=$_POST["prefix_comm"]; $object->client = $_POST["client"]?$_POST["client"]:$object->client;
$object->client=$_POST["client"]?$_POST["client"]:$object->client; $object->code_client = $_POST["code_client"];
$object->code_client=$_POST["code_client"]; $object->fournisseur = $_POST["fournisseur"]?$_POST["fournisseur"]:$object->fournisseur;
$object->fournisseur=$_POST["fournisseur"]?$_POST["fournisseur"]:$object->fournisseur; $object->code_fournisseur = $_POST["code_fournisseur"];
$object->code_fournisseur=$_POST["code_fournisseur"]; $object->address = $_POST["adresse"];
$object->adresse=$_POST["adresse"]; // TODO obsolete $object->zip = $_POST["zipcode"];
$object->address=$_POST["adresse"]; $object->town = $_POST["town"];
$object->cp=$_POST["zipcode"]; // TODO obsolete $object->state_id = $_POST["departement_id"];
$object->zip=$_POST["zipcode"]; $object->tel = $_POST["tel"];
$object->ville=$_POST["town"]; // TODO obsolete $object->fax = $_POST["fax"];
$object->town=$_POST["town"]; $object->email = $_POST["email"];
$object->state_id=$_POST["departement_id"]; $object->url = $_POST["url"];
$object->tel=$_POST["tel"]; $object->capital = $_POST["capital"];
$object->fax=$_POST["fax"]; $object->gencod = $_POST["gencod"];
$object->email=$_POST["email"]; $object->idprof1 = $_POST["idprof1"];
$object->url=$_POST["url"]; $object->idprof2 = $_POST["idprof2"];
$object->capital=$_POST["capital"]; $object->idprof3 = $_POST["idprof3"];
$object->gencod=$_POST["gencod"]; $object->idprof4 = $_POST["idprof4"];
$object->siren=$_POST["idprof1"]; $object->typent_id = $_POST["typent_id"];
$object->siret=$_POST["idprof2"]; $object->effectif_id = $_POST["effectif_id"];
$object->ape=$_POST["idprof3"];
$object->idprof4=$_POST["idprof4"];
$object->typent_id=$_POST["typent_id"];
$object->effectif_id=$_POST["effectif_id"];
$object->tva_assuj = $_POST["assujtva_value"]; $object->tva_assuj = $_POST["assujtva_value"];
$object->status= $_POST["status"]; $object->status = $_POST["status"];
//Local Taxes //Local Taxes
$object->localtax1_assuj = $_POST["localtax1assuj_value"]; $object->localtax1_assuj = $_POST["localtax1assuj_value"];
$object->localtax2_assuj = $_POST["localtax2assuj_value"]; $object->localtax2_assuj = $_POST["localtax2assuj_value"];
$object->tva_intra=$_POST["tva_intra"]; $object->tva_intra = $_POST["tva_intra"];
$object->commercial_id=$_POST["commercial_id"]; $object->commercial_id = $_POST["commercial_id"];
$object->default_lang=$_POST["default_lang"]; $object->default_lang = $_POST["default_lang"];
$object->logo = dol_sanitizeFileName($_FILES['photo']['name']); $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);