Qual: Uniformize code for canvas for product with canvas of thirdparty, contact, etc...

This commit is contained in:
Laurent Destailleur 2011-09-10 18:51:39 +00:00
parent 65c2d93a29
commit 54d16f4b82
7 changed files with 532 additions and 459 deletions

View File

@ -77,7 +77,7 @@ class Canvas
* and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View) * and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View)
* *
* @param module Name of target module (thirdparty, contact, ...) * @param module Name of target module (thirdparty, contact, ...)
* @param card Type of card (ex: card, info, contactcard, ...) * @param card Type of card (ex: 'card', 'info', 'contactcard', ...) or '' for a list page
* @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule) * @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule)
*/ */
function getCanvas($module, $card, $canvas) function getCanvas($module, $card, $canvas)
@ -161,7 +161,7 @@ class Canvas
} }
/** /**
* get object * Get object
* *
* @param param1 Param1 * @param param1 Param1
* @param param2 Param2 * @param param2 Param2
@ -224,7 +224,7 @@ class Canvas
/** /**
* Return the template to display canvas (if it exists) * Return the template to display canvas (if it exists)
* *
* @param mode 'create', ''='view', 'edit' * @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($mode='view')
@ -232,8 +232,8 @@ class Canvas
$newmode=$mode; $newmode=$mode;
if (empty($newmode)) $newmode='view'; 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.'_'.$newmode.'.tpl.php'; //print $this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php';
if (file_exists($this->template_dir.$this->card.'_'.$newmode.'.tpl.php')) return 1; if (file_exists($this->template_dir.($this->card?$this->card.'_':'').$newmode.'.tpl.php')) return 1;
else return 0; else return 0;
} }
@ -242,16 +242,16 @@ class Canvas
* 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 mode 'create', 'view', 'edit' * @param string $mode 'create', 'view', 'edit'
* @param id Id of object to show * @param int $id Id of object to show
*/ */
function display_canvas($mode='view',$id=0) function display_canvas($mode='view',$id=0)
{ {
global $db, $conf, $langs, $user, $canvas; global $db, $conf, $langs, $user, $canvas;
global $id, $form, $formfile; global $id, $form, $formfile;
//print $this->template_dir.$this->card.'_'.$mode.'.tpl.php';exit; //print $this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php';exit;
include($this->template_dir.$this->card.'_'.$mode.'.tpl.php'); // Include native PHP template include($this->template_dir.($this->card?$this->card.'_':'').$mode.'.tpl.php'); // Include native PHP template
} }
} }

View File

@ -52,7 +52,7 @@ abstract class CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE ref = '".$this->ref."'"; $sql.= " WHERE ref = '".$this->ref."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog("CommonObject::verifyNumRef sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::verifyNumRef sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -62,7 +62,7 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog("CommonObject::verifyNumRef ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::verifyNumRef ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
@ -80,19 +80,19 @@ abstract class CommonObject
{ {
global $user,$conf,$langs; global $user,$conf,$langs;
dol_syslog("CommonObject::add_contact $fk_socpeople, $type_contact, $source"); dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source");
// Check parameters // Check parameters
if ($fk_socpeople <= 0) if ($fk_socpeople <= 0)
{ {
$this->error=$langs->trans("ErrorWrongValueForParameter","1"); $this->error=$langs->trans("ErrorWrongValueForParameter","1");
dol_syslog("CommonObject::add_contact ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR);
return -1; return -1;
} }
if (! $type_contact) if (! $type_contact)
{ {
$this->error=$langs->trans("ErrorWrongValueForParameter","2"); $this->error=$langs->trans("ErrorWrongValueForParameter","2");
dol_syslog("CommonObject::add_contact ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR);
return -2; return -2;
} }
@ -126,7 +126,7 @@ abstract class CommonObject
$sql.= $this->db->idate($datecreate); $sql.= $this->db->idate($datecreate);
$sql.= ", 4, '". $id_type_contact . "' "; $sql.= ", 4, '". $id_type_contact . "' ";
$sql.= ")"; $sql.= ")";
dol_syslog("CommonObject::add_contact sql=".$sql); dol_syslog(get_class($this)."::add_contact sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -200,7 +200,7 @@ abstract class CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
$sql.= " WHERE rowid =".$rowid; $sql.= " WHERE rowid =".$rowid;
dol_syslog("CommonObject::delete_contact sql=".$sql); dol_syslog(get_class($this)."::delete_contact sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if (! $notrigger) if (! $notrigger)
@ -218,7 +218,7 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog("CommonObject::delete_contact error=".$this->error, LOG_ERR); dol_syslog(get_class($this)."::delete_contact error=".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
@ -243,7 +243,7 @@ abstract class CommonObject
$sql.= " WHERE element_id =".$this->id; $sql.= " WHERE element_id =".$this->id;
$sql.= " AND fk_c_type_contact IN (".$listId.")"; $sql.= " AND fk_c_type_contact IN (".$listId.")";
dol_syslog("CommonObject::delete_linked_contact sql=".$sql); dol_syslog(get_class($this)."::delete_linked_contact sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 1; return 1;
@ -251,7 +251,7 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog("CommonObject::delete_linked_contact error=".$this->error, LOG_ERR); dol_syslog(get_class($this)."::delete_linked_contact error=".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
@ -288,7 +288,7 @@ abstract class CommonObject
if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
$sql.=" ORDER BY t.name ASC"; $sql.=" ORDER BY t.name ASC";
dol_syslog("CommonObject::liste_contact sql=".$sql); dol_syslog(get_class($this)."::liste_contact sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -440,7 +440,7 @@ abstract class CommonObject
$sql.= " AND tc.active = 1"; $sql.= " AND tc.active = 1";
if ($status) $sql.= " AND ec.statut = ".$status; if ($status) $sql.= " AND ec.statut = ".$status;
dol_syslog("CommonObject::getIdContact sql=".$sql); dol_syslog(get_class($this)."::getIdContact sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -453,7 +453,7 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("CommonObject::getIdContact ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::getIdContact ".$this->error, LOG_ERR);
return null; return null;
} }
@ -606,7 +606,7 @@ abstract class CommonObject
$sql.= $field." = '".$value."'"; $sql.= $field." = '".$value."'";
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog("CommonObject::updateObjectField sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::updateObjectField sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -632,7 +632,7 @@ abstract class CommonObject
if (! $this->table_element) if (! $this->table_element)
{ {
dol_print_error('',"CommonObject::load_previous_next_ref was called on objet with property table_element not defined", LOG_ERR); dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined", LOG_ERR);
return -1; return -1;
} }
@ -720,7 +720,7 @@ abstract class CommonObject
{ {
if (! $this->table_element) if (! $this->table_element)
{ {
dol_syslog("CommonObject::setProject was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
@ -729,7 +729,7 @@ abstract class CommonObject
else $sql.= ' SET fk_projet = NULL'; else $sql.= ' SET fk_projet = NULL';
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
dol_syslog("CommonObject::setProject sql=".$sql); dol_syslog(get_class($this)."::setProject sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->fk_project = $projectid; $this->fk_project = $projectid;
@ -754,7 +754,7 @@ abstract class CommonObject
{ {
if (! $this->table_element) if (! $this->table_element)
{ {
dol_syslog("CommonObject::setDocModel was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
@ -766,7 +766,7 @@ abstract class CommonObject
// if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; // if ($this->element == 'facture') $sql.= " AND fk_statut < 2";
// if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; // if ($this->element == 'propal') $sql.= " AND fk_statut = 0";
dol_syslog("CommonObject::setDocModel sql=".$sql); dol_syslog(get_class($this)."::setDocModel sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -791,12 +791,12 @@ abstract class CommonObject
{ {
if (! $this->table_element_line) if (! $this->table_element_line)
{ {
dol_syslog("CommonObject::line_order was called on objet with property table_element_line not defined",LOG_ERR); dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR);
return -1; return -1;
} }
if (! $this->fk_element) if (! $this->fk_element)
{ {
dol_syslog("CommonObject::line_order was called on objet with property fk_element not defined",LOG_ERR); dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR);
return -1; return -1;
} }
@ -1042,7 +1042,7 @@ abstract class CommonObject
{ {
if (! $this->table_element) if (! $this->table_element)
{ {
dol_syslog("CommonObject::update_note was called on objet with property table_element not defined", LOG_ERR); dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR);
return -1; return -1;
} }
@ -1058,7 +1058,7 @@ abstract class CommonObject
} }
$sql.= " WHERE rowid =". $this->id; $sql.= " WHERE rowid =". $this->id;
dol_syslog("CommonObject::update_note sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::update_note sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->note = $note; $this->note = $note;
@ -1067,7 +1067,7 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("CommonObject::update_note error=".$this->error, LOG_ERR); dol_syslog(get_class($this)."::update_note error=".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
@ -1081,7 +1081,7 @@ abstract class CommonObject
{ {
if (! $this->table_element) if (! $this->table_element)
{ {
dol_syslog("CommonObject::update_note_public was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::update_note_public was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
@ -1089,7 +1089,7 @@ abstract class CommonObject
$sql.= " SET note_public = '".$this->db->escape($note_public)."'"; $sql.= " SET note_public = '".$this->db->escape($note_public)."'";
$sql.= " WHERE rowid =". $this->id; $sql.= " WHERE rowid =". $this->id;
dol_syslog("CommonObject::update_note_public sql=".$sql); dol_syslog(get_class($this)."::update_note_public sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->note_public = $note_public; $this->note_public = $note_public;
@ -1130,7 +1130,7 @@ abstract class CommonObject
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
if ($exclspec) $sql.= ' AND product_type <> 9'; if ($exclspec) $sql.= ' AND product_type <> 9';
dol_syslog("CommonObject::update_price sql=".$sql); dol_syslog(get_class($this)."::update_price sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1194,7 +1194,7 @@ abstract class CommonObject
$sql .= ' WHERE rowid = '.$this->id; $sql .= ' WHERE rowid = '.$this->id;
//print "xx".$sql; //print "xx".$sql;
dol_syslog("CommonObject::update_price sql=".$sql); dol_syslog(get_class($this)."::update_price sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1203,14 +1203,14 @@ abstract class CommonObject
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("CommonObject::update_price error=".$this->error,LOG_ERR); dol_syslog(get_class($this)."::update_price error=".$this->error,LOG_ERR);
return -1; return -1;
} }
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("CommonObject::update_price error=".$this->error,LOG_ERR); dol_syslog(get_class($this)."::update_price error=".$this->error,LOG_ERR);
return -1; return -1;
} }
} }
@ -1236,7 +1236,7 @@ abstract class CommonObject
$sql.= ", '".$this->element."'"; $sql.= ", '".$this->element."'";
$sql.= ")"; $sql.= ")";
dol_syslog("CommonObject::add_object_linked sql=".$sql); dol_syslog(get_class($this)."::add_object_linked sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->db->commit(); $this->db->commit();
@ -1293,7 +1293,7 @@ abstract class CommonObject
} }
//print $sql; //print $sql;
dol_syslog("CommonObject::fetchObjectLink sql=".$sql); dol_syslog(get_class($this)."::fetchObjectLink sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1382,72 +1382,24 @@ abstract class CommonObject
$sql.= " SET fk_statut = ".$statut; $sql.= " SET fk_statut = ".$statut;
$sql.= " WHERE rowid=".$elementId; $sql.= " WHERE rowid=".$elementId;
dol_syslog("CommonObject::setStatut sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::setStatut sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql)
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog("CommonObject::setStatut ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::setStatut ".$this->error, LOG_ERR);
return -1; return -1;
} }
return 1; return 1;
} }
/**
* Fetch field list
*/
function getFieldList()
{
global $conf, $langs;
$this->field_list = array();
$sql = "SELECT rowid, name, alias, title, align, sort, search, enabled, rang";
$sql.= " FROM ".MAIN_DB_PREFIX."c_field_list";
$sql.= " WHERE element = '".$this->fieldListName."'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " ORDER BY rang ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$fieldlist = array();
$obj = $this->db->fetch_object($resql);
$fieldlist["id"] = $obj->rowid;
$fieldlist["name"] = $obj->name;
$fieldlist["alias"] = $obj->alias;
$fieldlist["title"] = $langs->trans($obj->title);
$fieldlist["align"] = $obj->align;
$fieldlist["sort"] = $obj->sort;
$fieldlist["search"] = $obj->search;
$fieldlist["enabled"] = verifCond($obj->enabled);
$fieldlist["order"] = $obj->rang;
array_push($this->field_list,$fieldlist);
$i++;
}
$this->db->free($resql);
}
else
{
dol_print_error($db,$sql);
}
}
/** /**
* Load type of canvas of an object if it exists * Load type of canvas of an object if it exists
* *
* @param id Record id * @param int $id Record id
* @param ref Record ref * @param string $ref Record ref
* @return int <0 if KO, 0 if nothing done, >0 if OK * @return int <0 if KO, 0 if nothing done, >0 if OK
*/ */
function getCanvas($id=0,$ref='') function getCanvas($id=0,$ref='')

View File

@ -36,25 +36,35 @@ class ActionsCardProduct extends Product
//! Template container //! Template container
var $tpl = array(); var $tpl = array();
// List of fiels for action=list
var $field_list =array();
/** /**
* \brief Constructeur de la classe * Constructor
* \param DB Handler acces base de donnees *
* \param id Id produit (0 par defaut) * @param DoliDB $DB Handler acces base de donnees
* @param string $targmetmodule Name of directory of module where canvas is stored
* @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardProduct($DB=0, $id=0, $user=0) function ActionsCardIndividual($DB,$targetmodule,$canvas,$card)
{ {
$this->db = $DB; $this->db = $DB;
$this->id = $id ; $this->targetmodule = $targetmodule;
$this->user = $user; $this->canvas = $canvas;
$this->module = "produit"; $this->card = $card;
$this->canvas = "default";
$this->name = "default"; $this->name = "product";
$this->definition = "Product canvas (défaut)"; $this->definition = "Product canvas (défaut)";
$this->fieldListName = "product_default"; $this->fieldListName = "product_default";
$this->next_prev_filter = "canvas='default'"; $this->next_prev_filter = "canvas='default'";
} }
/**
* Return the title of card
*/
function getTitle() function getTitle()
{ {
global $langs; global $langs;
@ -179,8 +189,65 @@ class ActionsCardProduct extends Product
$this->tpl['fiche_end']=dol_get_fiche_end(); $this->tpl['fiche_end']=dol_get_fiche_end();
} }
if ($action == 'list')
{
$this->LoadListDatas($GLOBALS['limit'], $GLOBALS['offset'], $GLOBALS['sortfield'], $GLOBALS['sortorder']);
} }
}
/**
* Fetch field list
*/
function getFieldList()
{
global $conf, $langs;
$this->field_list = array();
$sql = "SELECT rowid, name, alias, title, align, sort, search, enabled, rang";
$sql.= " FROM ".MAIN_DB_PREFIX."c_field_list";
$sql.= " WHERE element = '".$this->fieldListName."'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " ORDER BY rang ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$fieldlist = array();
$obj = $this->db->fetch_object($resql);
$fieldlist["id"] = $obj->rowid;
$fieldlist["name"] = $obj->name;
$fieldlist["alias"] = $obj->alias;
$fieldlist["title"] = $langs->trans($obj->title);
$fieldlist["align"] = $obj->align;
$fieldlist["sort"] = $obj->sort;
$fieldlist["search"] = $obj->search;
$fieldlist["enabled"] = verifCond($obj->enabled);
$fieldlist["order"] = $obj->rang;
array_push($this->field_list,$fieldlist);
$i++;
}
$this->db->free($resql);
}
else
{
dol_print_error($db,$sql);
}
}
/** /**
* Fetch datas list * Fetch datas list
*/ */
@ -188,6 +255,8 @@ class ActionsCardProduct extends Product
{ {
global $conf, $langs; global $conf, $langs;
$this->getFieldList();
$this->list_datas = array(); $this->list_datas = array();
//$_GET["sall"] = 'LL'; //$_GET["sall"] = 'LL';

View File

@ -36,28 +36,40 @@ class ActionsCardService extends Product
//! Template container //! Template container
var $tpl = array(); var $tpl = array();
// List of fiels for action=list
var $field_list =array();
/** /**
* \brief Constructeur de la classe * Constructor
* \param DB Handler acces base de donnees *
* \param id Id service (0 par defaut) * @param DoliDB $DB Handler acces base de donnees
* @param string $targmetmodule Name of directory of module where canvas is stored
* @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardService($DB=0, $id=0, $user=0) function ActionsCardIndividual($DB,$targetmodule,$canvas,$card)
{ {
$this->db = $DB; $this->db = $DB;
$this->id = $id ; $this->targetmodule = $targetmodule;
$this->user = $user; $this->canvas = $canvas;
$this->card = $card;
$this->module = "service"; $this->module = "service";
$this->canvas = "service";
$this->name = "service"; $this->name = "service";
$this->definition = "Services canvas"; $this->definition = "Services canvas";
$this->fieldListName = "product_service"; $this->fieldListName = "product_service";
$this->next_prev_filter = "canvas='service'"; $this->next_prev_filter = "canvas='service'";
} }
/**
* Return the title of card
*/
function getTitle() function getTitle()
{ {
return 'Services'; global $langs;
return $langs->trans("Products");
} }
/** /**
@ -72,8 +84,9 @@ class ActionsCardService extends Product
} }
/** /**
* \brief Assigne les valeurs pour les templates * Assign custom values for canvas (for example into this->tpl to be used by templates)
* \param object object *
* @param action Type of action
*/ */
function assign_values($action='') function assign_values($action='')
{ {
@ -156,6 +169,62 @@ class ActionsCardService extends Product
$this->tpl['fiche_end']=dol_get_fiche_end(); $this->tpl['fiche_end']=dol_get_fiche_end();
} }
if ($action == 'list')
{
$this->LoadListDatas($GLOBALS['limit'], $GLOBALS['offset'], $GLOBALS['sortfield'], $GLOBALS['sortorder']);
}
}
/**
* Fetch field list
*/
private function getFieldList()
{
global $conf, $langs;
$this->field_list = array();
$sql = "SELECT rowid, name, alias, title, align, sort, search, enabled, rang";
$sql.= " FROM ".MAIN_DB_PREFIX."c_field_list";
$sql.= " WHERE element = '".$this->fieldListName."'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " ORDER BY rang ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$fieldlist = array();
$obj = $this->db->fetch_object($resql);
$fieldlist["id"] = $obj->rowid;
$fieldlist["name"] = $obj->name;
$fieldlist["alias"] = $obj->alias;
$fieldlist["title"] = $langs->trans($obj->title);
$fieldlist["align"] = $obj->align;
$fieldlist["sort"] = $obj->sort;
$fieldlist["search"] = $obj->search;
$fieldlist["enabled"] = verifCond($obj->enabled);
$fieldlist["order"] = $obj->rang;
array_push($this->field_list,$fieldlist);
$i++;
}
$this->db->free($resql);
}
else
{
dol_print_error($db,$sql);
}
} }
/** /**
@ -165,6 +234,8 @@ class ActionsCardService extends Product
{ {
global $conf; global $conf;
$this->getFieldList();
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
$sql.= ' p.fk_product_type, p.tms as datem,'; $sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell as statut, p.seuil_stock_alerte'; $sql.= ' p.duration, p.tosell as statut, p.seuil_stock_alerte';

View File

@ -105,15 +105,10 @@ if ($conf->categorie->enabled && GETPOST('catid'))
$htmlother=new FormOther($db); $htmlother=new FormOther($db);
$html=new Form($db); $html=new Form($db);
if (! empty($objcanvas->template_dir)) if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
{ {
$classname = 'ActionsCard'.ucfirst($canvas); $objcanvas->assign_values('list'); // This must contains code to load data (must call LoadListDatas($limit, $offset, $sortfield, $sortorder))
include_once(DOL_DOCUMENT_ROOT.'/product/canvas/'.$canvas.'/actions_card_'.$canvas.'.class.php'); $objcanvas->display_canvas('list'); // This is code to show template
$object = new $classname($db);
$object->getFieldList();
$object->LoadListDatas($limit, $offset, $sortfield, $sortorder);
$title = $object->getTitle();
} }
else else
{ {
@ -134,53 +129,52 @@ else
{ {
$texte = $langs->trans("ProductsAndServices"); $texte = $langs->trans("ProductsAndServices");
} }
}
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
$sql.= ' p.fk_product_type, p.tms as datem,'; $sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,'; $sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' MIN(pfp.unitprice) as minsellprice'; $sql.= ' MIN(pfp.unitprice) as minsellprice';
$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p'; $sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
// We'll need this table joined to the select in order to filter by categ // We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp"; if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
$sql.= ') '; $sql.= ') ';
//if ($fourn_id > 0) // The DISTINCT is used to avoid duplicate from this link //if ($fourn_id > 0) // The DISTINCT is used to avoid duplicate from this link
//{ //{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
//} //}
$sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')'; $sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
if ($sall) if ($sall)
{ {
$sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%')"; $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%')";
} }
# if the type is not 1, we show all products (type = 0,2,3) # if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type)) if (dol_strlen($type))
{ {
if ($type == 1) $sql.= " AND p.fk_product_type = '1'"; if ($type == 1) $sql.= " AND p.fk_product_type = '1'";
else $sql.= " AND p.fk_product_type <> '1'"; else $sql.= " AND p.fk_product_type <> '1'";
} }
if ($sref) $sql.= " AND p.ref like '%".$sref."%'"; if ($sref) $sql.= " AND p.ref like '%".$sref."%'";
if ($sbarcode) $sql.= " AND p.barcode like '%".$sbarcode."%'"; if ($sbarcode) $sql.= " AND p.barcode like '%".$sbarcode."%'";
if ($snom) $sql.= " AND p.label like '%".$db->escape($snom)."%'"; if ($snom) $sql.= " AND p.label like '%".$db->escape($snom)."%'";
if (isset($tosell) && dol_strlen($tosell) > 0) $sql.= " AND p.tosell = ".$db->escape($tosell); if (isset($tosell) && dol_strlen($tosell) > 0) $sql.= " AND p.tosell = ".$db->escape($tosell);
if (isset($tobuy) && dol_strlen($tobuy) > 0) $sql.= " AND p.tobuy = ".$db->escape($tobuy); if (isset($tobuy) && dol_strlen($tobuy) > 0) $sql.= " AND p.tobuy = ".$db->escape($tobuy);
if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
if ($catid) $sql.= " AND cp.fk_categorie = ".$catid; if ($catid) $sql.= " AND cp.fk_categorie = ".$catid;
if ($search_categ) $sql.= " AND cp.fk_categorie = ".$search_categ; if ($search_categ) $sql.= " AND cp.fk_categorie = ".$search_categ;
if ($fourn_id > 0) $sql.= " AND pf.fk_soc = ".$fourn_id; if ($fourn_id > 0) $sql.= " AND pf.fk_soc = ".$fourn_id;
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,"; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
$sql.= " p.fk_product_type, p.tms,"; $sql.= " p.fk_product_type, p.tms,";
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte"; $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
//if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
$sql.= $db->order($sortfield,$sortorder); $sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1 ,$offset); $sql.= $db->plimit($limit + 1 ,$offset);
dol_syslog("sql=".$sql); dol_syslog("sql=".$sql);
$resql = $db->query($sql) ; $resql = $db->query($sql) ;
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -470,10 +464,11 @@ if ($resql)
print "</table>"; print "</table>";
print '</form>'; print '</form>';
} }
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
}
} }

View File

@ -36,10 +36,11 @@ class ActionsCardDefault extends ActionsCardCommon
/** /**
* Constructor * Constructor
* @param DB Handler acces base de donnees *
* @param targmetmodule Name of directory of module where canvas is stored * @param DoliDB $DB Handler acces base de donnees
* @param canvas Name of canvas * @param string $targmetmodule Name of directory of module where canvas is stored
* @param card Name of tab (sub-canvas) * @param string $canvas Name of canvas
* @param string $card Name of tab (sub-canvas)
*/ */
function ActionsCardDefault($DB,$targetmodule,$canvas,$card) function ActionsCardDefault($DB,$targetmodule,$canvas,$card)
{ {
@ -66,14 +67,6 @@ class ActionsCardDefault extends ActionsCardCommon
} }
/**
* Assigne les valeurs POST dans l'objet
*/
function assign_post()
{
parent::assign_post();
}
/** /**
* Execute actions * Execute actions
* @param Id of object (may be empty for creation) * @param Id of object (may be empty for creation)

View File

@ -35,10 +35,11 @@ class ActionsCardIndividual extends ActionsCardCommon
/** /**
* Constructor * Constructor
* @param DB Handler acces base de donnees *
* @param targetmodule Name of directory of module where canvas is stored * @param DoliDB $DB Handler acces base de donnees
* @param canvas Name of canvas * @param string $targmetmodule Name of directory of module where canvas is stored
* @param 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 ActionsCardIndividual($DB,$targetmodule,$canvas,$card)
{ {
@ -66,14 +67,6 @@ class ActionsCardIndividual extends ActionsCardCommon
} }
/**
* Assigne les valeurs POST dans l'objet
*/
function assign_post()
{
parent::assign_post();
}
/** /**
* Execute actions * Execute actions
* @param Id of object (may be empty for creation) * @param Id of object (may be empty for creation)