';
print '| '.$ref.' | ';
print ''.$label.' | ';
+ print ''.$action->type.' | ';
print ''.dol_print_date($action->datep,'dayhour');
if ($action->datef)
{
@@ -243,15 +247,16 @@ class FormActions
/**
* Output html select list of type of event
*
- * @param string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx')
- * @param string $htmlname Name of select field
- * @param string $excludetype A type to exclude ('systemauto', 'system', '')
- * @param integer $onlyautoornot 1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type
- * @param int $hideinfohelp 1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
- * @param int $multiselect 1=Allow multiselect of action type
- * @return void
+ * @param array|string $selected Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'). Can be an array too.
+ * @param string $htmlname Name of select field
+ * @param string $excludetype A type to exclude ('systemauto', 'system', '')
+ * @param integer $onlyautoornot 1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type
+ * @param int $hideinfohelp 1=Do not show info help, 0=Show, -1=Show+Add info to tell how to set default value
+ * @param int $multiselect 1=Allow multiselect of action type
+ * @param int $nooutput 1=No output
+ * @return string
*/
- function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0, $hideinfohelp=0, $multiselect=0)
+ function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
{
global $langs,$user,$form,$conf;
@@ -271,20 +276,26 @@ class FormActions
if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
+ $out='';
+
if (! empty($multiselect))
{
- if(!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
- print $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
+ if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
+ $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
}
else
{
- print $form->selectarray($htmlname, $arraylist, $selected);
+ $out.=$form->selectarray($htmlname, $arraylist, $selected);
}
if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
{
- print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
+ $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
}
+
+ if ($nooutput) return $out;
+ else print $out;
+ return '';
}
}
diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php
index f1ec7edae73..742bc1a0231 100644
--- a/htdocs/core/class/html.formprojet.class.php
+++ b/htdocs/core/class/html.formprojet.class.php
@@ -44,7 +44,7 @@ class FormProjets
}
/**
- * Output a combo list with projects qualified for a third party
+ * Output a combo list with projects qualified for a third party / user
*
* @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
* @param int $selected Id project preselected
@@ -58,9 +58,10 @@ class FormProjets
* @param int $mode 0 for HTML mode and 1 for JSON mode
* @param string $filterkey Key to filter
* @param int $nooutput No print output. Return it only.
+ * @param int $forceaddid Force to add project id in list, event if not qualified
* @return string Return html content
*/
- function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0)
+ function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0)
{
global $langs,$conf,$form;
@@ -122,9 +123,10 @@ class FormProjets
* @param int $mode 0 for HTML mode and 1 for array return (to be used by json_encode for example)
* @param string $filterkey Key to filter
* @param int $nooutput No print output. Return it only.
+ * @param int $forceaddid Force to add project id in list, event if not qualified
* @return int Nb of project if OK, <0 if KO
*/
- function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0)
+ function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0)
{
global $user,$conf,$langs;
@@ -143,6 +145,7 @@ class FormProjets
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
}
+
// Search all projects
$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public';
$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php
index 8cec7459bd5..b4205a5d997 100644
--- a/htdocs/core/lib/company.lib.php
+++ b/htdocs/core/lib/company.lib.php
@@ -930,177 +930,17 @@ function show_addresses($conf,$langs,$db,$object,$backtopage='')
* @param Conf $conf Object conf
* @param Translate $langs Object langs
* @param DoliDB $db Object db
- * @param Adherent|Societe $object Object third party or member
+ * @param Adherent|Societe $filterobj Object third party or member
* @param Contact $objcon Object contact
* @param int $noprint Return string but does not output it
* @param int $actioncode Filter on actioncode
* @return mixed Return html part or void if noprint is 1
*/
-function show_actions_todo($conf,$langs,$db,$object,$objcon='',$noprint=0,$actioncode='')
+function show_actions_todo($conf,$langs,$db,$filterobj,$objcon='',$noprint=0,$actioncode='')
{
global $bc,$user,$conf;
- // Check parameters
- if (! is_object($object)) dol_print_error('','BadParameter');
-
- $now=dol_now('tzuser');
- $out='';
-
- if (! empty($conf->agenda->enabled))
- {
- require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
- $actionstatic=new ActionComm($db);
- $userstatic=new User($db);
- $contactstatic = new Contact($db);
-
- $out.="\n";
- $out.='';
- $out.='';
- if($conf->global->AGENDA_USE_EVENT_TYPE) $out.='| ';
- else $out.=' | ';
- if (get_class($object) == 'Societe') $out.='';
- $out.=$langs->trans("ActionsToDoShort");
- if (get_class($object) == 'Societe') $out.='';
- $out.=' | ';
-
- if($conf->global->AGENDA_USE_EVENT_TYPE) {
- $out.='';
- $out.=$langs->trans("Type");
- $out.=' | ';
- $out.='';
- } else {
- $out.=' | ';
- }
-
- $out.=' | ';
- $out.=' ';
-
- $sql = "SELECT a.id, a.label,";
- $sql.= " a.datep as dp,";
- $sql.= " a.datep2 as dp2,";
- $sql.= " a.percent,";
- $sql.= " a.fk_user_author, a.fk_contact,";
- $sql.= " a.fk_element, a.elementtype,";
- $sql.= " c.code as acode, c.libelle,";
- $sql.= " u.login, u.rowid";
- if (get_class($object) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
- if (get_class($object) == 'Adherent') $sql.= ", m.lastname, m.firstname";
- $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
- if (get_class($object) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
- if (get_class($object) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
- $sql.= " WHERE u.rowid = a.fk_user_author";
- $sql.= " AND a.entity IN (".getEntity('agenda', 1).")";
- if (get_class($object) == 'Adherent')
- {
- $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
- if (! empty($object->id)) $sql.= " AND a.fk_element = ".$object->id;
- }
- if (get_class($object) == 'Societe' && $object->id) $sql.= " AND a.fk_soc = ".$object->id;
- if (! empty($objcon->id)) $sql.= " AND a.fk_contact = ".$objcon->id;
- if (! empty($actioncode)) $sql.= " AND c.code='".$actioncode."' ";
- $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
- $sql.= " ORDER BY a.datep DESC, a.id DESC";
-
- dol_syslog("company.lib::show_actions_todo", LOG_DEBUG);
- $result=$db->query($sql);
- if ($result)
- {
- $i = 0 ;
- $num = $db->num_rows($result);
- $var=true;
-
- if ($num)
- {
- while ($i < $num)
- {
- $var = !$var;
-
- $obj = $db->fetch_object($result);
- $actionstatic->fetch($obj->id);
- $datep=$db->jdate($obj->dp);
- $datep2=$db->jdate($obj->dp2);
-
- $out.="";
-
- // Date
- $out.='| ';
- $out.=dol_print_date($datep,'dayhour');
- if ($datep2 && $datep2 != $datep)
- {
- $tmpa=dol_getdate($datep,true);
- $tmpb=dol_getdate($datep2,true);
- if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out.='-'.dol_print_date($datep2,'hour');
- else $out.='-'.dol_print_date($datep2,'dayhour');
- }
- $out.=" | \n";
-
- // Picto warning
- $out.='';
- if ($obj->percent >= 0 && $datep && $datep < ($now - ($conf->global->MAIN_DELAY_ACTIONS_TODO *60*60*24)) ) $out.=' '.img_warning($langs->trans("Late"));
- else $out.=' ';
- $out.=' | ';
-
- $actionstatic->type_code=$obj->acode;
- $transcode=$langs->trans("Action".$obj->acode);
- $libelle=($transcode!="Action".$obj->acode?$transcode:$obj->libelle);
- //$actionstatic->libelle=$libelle;
- $actionstatic->libelle=$obj->label;
- $actionstatic->id=$obj->id;
- //$out.=''.$actionstatic->getNomUrl(1,16).' | ';
-
- // Title of event
- //$out.=''.dol_trunc($obj->label,40).' | ';
- $out.=''.$actionstatic->getNomUrl(1,120).' | ';
-
- if($conf->global->AGENDA_USE_EVENT_TYPE) {
- $out.= '';
- $out.=$actionstatic->type;
- $out.=' | ';
- }
- // Contact pour cette action
- if (empty($objcon->id) && $obj->fk_contact > 0)
- {
- $contactstatic->lastname=$obj->lastname;
- $contactstatic->firstname=$obj->firstname;
- $contactstatic->id=$obj->fk_contact;
- $out.=''.$contactstatic->getNomUrl(1,'',10).' | ';
- }
- else
- {
- $out.=' | ';
- }
-
- $out.='';
- //$userstatic->id=$obj->fk_user_author;
- //$userstatic->login=$obj->login;
- //$out.=$userstatic->getLoginUrl(1);
- $userstatic->fetch($obj->fk_user_author);
- $out.=$userstatic->getNomUrl(1);
- $out.=' | ';
-
- // Statut
- $out.=''.$actionstatic->LibStatut($obj->percent,3).' | ';
-
- $out.=" \n";
- $i++;
- }
- }
- else
- {
- // Aucun action a faire
-
- }
- $db->free($result);
- }
- else
- {
- dol_print_error($db);
- }
- $out.=" \n";
-
- $out.=" \n";
- }
+ $out = show_actions_done($conf,$langs,$db,$filterobj,$objcon,1,$actioncode, 'todo');
if ($noprint) return $out;
else print $out;
@@ -1112,19 +952,21 @@ function show_actions_todo($conf,$langs,$db,$object,$objcon='',$noprint=0,$actio
* @param Conf $conf Object conf
* @param Translate $langs Object langs
* @param DoliDB $db Object db
- * @param Adherent|Societe $object Object third party or member
+ * @param Adherent|Societe $filterobj Object third party or member
* @param Contact $objcon Object contact
* @param int $noprint Return string but does not output it
* @param string $actioncode Filter on actioncode
+ * @param string $donetodo Filter on avent 'done' or 'todo' or ''=nofilter.
* @return mixed Return html part or void if noprint is 1
* TODO change function to be able to list event linked to an object.
*/
-function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0, $actioncode='')
+function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done')
{
global $bc,$user,$conf;
+ global $form;
// Check parameters
- if (! is_object($object)) dol_print_error('','BadParameter');
+ if (! is_object($filterobj)) dol_print_error('','BadParameter');
$out='';
$histo=array();
@@ -1142,20 +984,22 @@ function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0,
$sql.= " a.fk_user_author, a.fk_contact,";
$sql.= " c.code as acode, c.libelle,";
$sql.= " u.login, u.rowid as user_id";
- if (get_class($object) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
- if (get_class($object) == 'Adherent') $sql.= ", m.lastname, m.firstname";
+ if (get_class($filterobj) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
+ if (get_class($filterobj) == 'Adherent') $sql.= ", m.lastname, m.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
- if (get_class($object) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
- if (get_class($object) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
+ if (get_class($filterobj) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
+ if (get_class($filterobj) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
$sql.= " WHERE u.rowid = a.fk_user_author";
$sql.= " AND a.entity IN (".getEntity('agenda', 1).")";
- if (get_class($object) == 'Societe' && $object->id) $sql.= " AND a.fk_soc = ".$object->id;
- if (get_class($object) == 'Adherent') $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
- if (get_class($object) == 'Adherent' && $object->id) $sql.= " AND a.fk_element = ".$object->id;
+ if (get_class($filterobj) == 'Societe' && $filterobj->id) $sql.= " AND a.fk_soc = ".$filterobj->id;
+ if (get_class($filterobj) == 'Project' && $filterobj->id) $sql.= " AND a.fk_project = ".$filterobj->id;
+ if (get_class($filterobj) == 'Adherent') $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
+ if (get_class($filterobj) == 'Adherent' && $filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
if (is_object($objcon) && $objcon->id) $sql.= " AND a.fk_contact = ".$objcon->id;
if (!empty($actioncode)) $sql.= " AND c.code='".$actioncode."' ";
- $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
+ if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
+ if ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
$sql.= " ORDER BY a.datep DESC, a.id DESC";
dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
@@ -1168,23 +1012,31 @@ function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0,
while ($i < $num)
{
$obj = $db->fetch_object($resql);
+
+ //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
+ //if ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
+ $tododone='';
+ if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) $tododone='todo';
+
$histo[$numaction]=array(
- 'type'=>'action',
- 'id'=>$obj->id,
- 'datestart'=>$db->jdate($obj->dp),
- 'dateend'=>$db->jdate($obj->dp2),
- 'note'=>$obj->label,
- 'percent'=>$obj->percent,
- 'acode'=>$obj->acode,
- 'libelle'=>$obj->libelle,
- 'userid'=>$obj->user_id,
- 'login'=>$obj->login,
- 'contact_id'=>$obj->fk_contact,
- 'lastname'=>$obj->lastname,
- 'firstname'=>$obj->firstname,
- 'fk_element'=>$obj->fk_element,
- 'elementtype'=>$obj->elementtype
+ 'type'=>'action',
+ 'tododone'=>$tododone,
+ 'id'=>$obj->id,
+ 'datestart'=>$db->jdate($obj->dp),
+ 'dateend'=>$db->jdate($obj->dp2),
+ 'note'=>$obj->label,
+ 'percent'=>$obj->percent,
+ 'acode'=>$obj->acode,
+ 'libelle'=>$obj->libelle,
+ 'userid'=>$obj->user_id,
+ 'login'=>$obj->login,
+ 'contact_id'=>$obj->fk_contact,
+ 'lastname'=>$obj->lastname,
+ 'firstname'=>$obj->firstname,
+ 'fk_element'=>$obj->fk_element,
+ 'elementtype'=>$obj->elementtype
);
+
$numaction++;
$i++;
}
@@ -1199,7 +1051,7 @@ function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0,
{
$langs->load("mails");
- // Recherche histo sur mailing
+ // Add also event from emailings. TODO This should be replaced by an automatic event
$sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
$sql.= " 'AC_EMAILING' as acode,";
$sql.= " u.rowid as user_id, u.login"; // User that valid action
@@ -1222,6 +1074,7 @@ function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0,
$obj = $db->fetch_object($resql);
$histo[$numaction]=array(
'type'=>'mailing',
+ 'tododone'=>'done',
'id'=>$obj->id,
'datestart'=>$db->jdate($obj->da),
'dateend'=>$db->jdate($obj->da),
@@ -1258,49 +1111,79 @@ function show_actions_done($conf, $langs, $db, $object, $objcon='', $noprint=0,
$orderstatic=new Commande($db);
$facturestatic=new Facture($db);
+ $out.=' |