diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 541a94cb925..0a6c0381e90 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -81,6 +81,8 @@ class ActionComm extends CommonObject
// Ical
var $icalname;
var $icalcolor;
+
+ var $actions=array();
/**
@@ -243,7 +245,7 @@ class ActionComm extends CommonObject
$sql.= " a.priority, a.fulldayevent, a.location,";
$sql.= " c.id as type_id, c.code as type_code, c.libelle,";
$sql.= " s.nom as socname,";
- $sql.= " u.firstname, u.name";
+ $sql.= " u.firstname, u.name as lastname";
$sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
@@ -266,32 +268,34 @@ class ActionComm extends CommonObject
$type_libelle=($transcode!="Action".$obj->type_code?$transcode:$obj->libelle);
$this->type = $type_libelle;
- $this->label = $obj->label;
- $this->datep = $this->db->jdate($obj->datep);
- $this->datef = $this->db->jdate($obj->datep2);
+ $this->label = $obj->label;
+ $this->datep = $this->db->jdate($obj->datep);
+ $this->datef = $this->db->jdate($obj->datep2);
- $this->datec = $this->db->jdate($obj->datec);
- $this->datem = $this->db->jdate($obj->datem);
+ $this->datec = $this->db->jdate($obj->datec);
+ $this->datem = $this->db->jdate($obj->datem);
- $this->note = $obj->note;
- $this->percentage = $obj->percentage;
+ $this->note = $obj->note;
+ $this->percentage = $obj->percentage;
- $this->author->id = $obj->fk_user_author;
- $this->usermod->id = $obj->fk_user_mod;
+ $this->author->id = $obj->fk_user_author;
+ $this->author->firstname = $obj->firstname;
+ $this->author->lastname = $obj->lastname;
+ $this->usermod->id = $obj->fk_user_mod;
- $this->usertodo->id = $obj->fk_user_action;
- $this->userdone->id = $obj->fk_user_done;
- $this->priority = $obj->priority;
- $this->fulldayevent = $obj->fulldayevent;
- $this->location = $obj->location;
+ $this->usertodo->id = $obj->fk_user_action;
+ $this->userdone->id = $obj->fk_user_done;
+ $this->priority = $obj->priority;
+ $this->fulldayevent = $obj->fulldayevent;
+ $this->location = $obj->location;
- $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working
- $this->societe->id = $obj->fk_soc;
- $this->contact->id = $obj->fk_contact;
- $this->fk_project = $obj->fk_project;
+ $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working
+ $this->societe->id = $obj->fk_soc;
+ $this->contact->id = $obj->fk_contact;
+ $this->fk_project = $obj->fk_project;
- $this->fk_element = $obj->fk_element;
- $this->elementtype = $obj->elementtype;
+ $this->fk_element = $obj->fk_element;
+ $this->elementtype = $obj->elementtype;
}
$this->db->free($resql);
return 1;
@@ -385,6 +389,50 @@ class ActionComm extends CommonObject
}
}
+ /**
+ * Load all objects with filters
+ * @param socid Filter by thirdparty
+ * @param filter Other filter
+ */
+ function getActions($socid=0, $fk_element=0, $elementtype='', $filter='')
+ {
+ global $conf, $langs;
+
+ $sql = "SELECT a.id";
+ $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
+ $sql.= " WHERE a.entity = ".$conf->entity;
+ if ($socid) $sql.= " AND a.fk_soc = ".$socid;
+ if ($elementtype!='')
+ {
+ if ($elementtype == 'project') $sql.= ' AND a.fk_project = '.$fk_element;
+ else $sql.= " AND a.fk_element = ".$fk_element." AND a.elementtype = '".$elementtype."'";
+ }
+ if ($filter) $sql.= $filter;
+
+ dol_syslog("ActionComm::fetchAll sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+
+ if ($num)
+ {
+ for($i=0;$i<$num;$i++)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $this->fetch($obj->id);
+ $this->actions[$i] = $this;
+ }
+ }
+ $this->db->free($resql);
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ return -1;
+ }
+ }
/**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php
index 377d3247c6d..c933971ce0c 100644
--- a/htdocs/core/class/html.formactions.class.php
+++ b/htdocs/core/class/html.formactions.class.php
@@ -103,59 +103,48 @@ class FormActions
{
global $langs,$conf,$user;
global $bc;
-
- $sql = 'SELECT a.id, a.datep as da, a.label, a.note,';
- $sql.= ' u.login';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a, '.MAIN_DB_PREFIX.'user as u';
- $sql.= ' WHERE a.fk_user_author = u.rowid';
- if ($socid) $sql .= ' AND a.fk_soc = '.$socid;
- if ($typeelement == 'project') $sql.= ' AND a.fk_project = '.$object->id;
- else $sql.= " AND a.fk_element = ".$object->id." AND a.elementtype = '".$typeelement."'";
-
- dol_syslog("FormActions::showactions sql=".$sql);
- $resql = $this->db->query($sql);
- if ($resql)
+
+ require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
+
+ $actioncomm = new ActionComm($this->db);
+ $actioncomm->getActions($socid, $object->id, $typeelement);
+
+ $num = count($actioncomm->actions);
+ if ($num)
{
- $num = $this->db->num_rows($resql);
- if ($num)
- {
- if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
- if ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
- if ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
- if ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
- if ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
- if ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
- if ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
-
- print_titre($title);
-
- $i = 0; $total = 0; $var=true;
- print '
';
- print '| '.$langs->trans('Ref').' | '.$langs->trans('Date').' | '.$langs->trans('Action').' | '.$langs->trans('By').' |
';
- print "\n";
-
- while ($i < $num)
- {
- $objp = $this->db->fetch_object($resql);
- $var=!$var;
- print '';
- print '| '.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.' | ';
- print ''.dol_print_date($this->db->jdate($objp->da),'day').' | ';
- print ''.dol_trunc($objp->label,32).' | ';
- print ''.$objp->login.' | ';
- print '
';
- $i++;
- }
- print '
';
- }
-
- return $num;
- }
- else
- {
- dol_print_error($this->db);
- return -1;
+ if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
+ if ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
+ if ($typeelement == 'propal') $title=$langs->trans('ActionsOnPropal');
+ if ($typeelement == 'order') $title=$langs->trans('ActionsOnOrder');
+ if ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') $title=$langs->trans('ActionsOnOrder');
+ if ($typeelement == 'project') $title=$langs->trans('ActionsOnProject');
+ if ($typeelement == 'shipping') $title=$langs->trans('ActionsOnShipping');
+
+ print_titre($title);
+
+ $total = 0; $var=true;
+ print '';
+ print '| '.$langs->trans('Ref').' | '.$langs->trans('Date').' | '.$langs->trans('Action').' | '.$langs->trans('By').' |
';
+ print "\n";
+
+ foreach($actioncomm->actions as $action)
+ {
+ $var=!$var;
+ print '';
+ print '| '.$action->getNomUrl(1).' | ';
+ print ''.dol_print_date($action->datep,'day').' | ';
+ print ''.dol_trunc($action->label,32).' | ';
+ $userstatic = new User($this->db);
+ $userstatic->id = $action->author->id;
+ $userstatic->prenom = $action->author->firstname;
+ $userstatic->nom = $action->author->lastname;
+ print ''.$userstatic->getNomUrl(1).' | ';
+ print '
';
+ }
+ print '
';
}
+
+ return $num;
}