Skip to content

Commit

Permalink
Fix better way to get info for contact/thirdparty on agenda
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 29, 2017
1 parent 2a36166 commit 837afa0
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 22 deletions.
76 changes: 66 additions & 10 deletions htdocs/comm/action/pertype.php
Expand Up @@ -30,10 +30,12 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';


if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
Expand All @@ -55,7 +57,7 @@
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page","int");
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$offset = $limit * $page;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="a.datec";
Expand Down Expand Up @@ -93,7 +95,7 @@
}
else
{
$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode","alpha")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
}
if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);

Expand Down Expand Up @@ -354,7 +356,7 @@
$sql.= ' a.percent,';
$sql.= ' a.fk_user_author,a.fk_user_action,';
$sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
$sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,';
$sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
$sql.= ' ca.code, ca.color';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
Expand Down Expand Up @@ -477,6 +479,8 @@
$event->location=$obj->location;
$event->transparency=$obj->transparency;

$event->fk_project=$obj->fk_project;

$event->socid=$obj->fk_soc;
$event->contactid=$obj->fk_contact;
//$event->societe->id=$obj->fk_soc; // deprecated
Expand Down Expand Up @@ -887,11 +891,37 @@ function show_day_events_pertype($username, $day, $month, $year, $monthshown, $s
}
$cases1[$h][$event->id]['string'].=' - '.$event->label;
$cases1[$h][$event->id]['typecode']=$event->type_code;
if ($event->socid)
$cases1[$h][$event->id]['color']=$color;
if ($event->fk_project > 0)
{
//$cases1[$h][$event->id]['string'].='xxx';
if (empty($cache_project[$event->fk_project]))
{
$tmpproj=new Project($db);
$tmpproj->fetch($event->fk_project);
$cache_project[$event->fk_project]=$tmpproj;
}
$cases1[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$event->fk_project]->title;
}
if ($event->socid > 0)
{
if (empty($cache_thirdparty[$event->socid]))
{
$tmpthirdparty=new Societe($db);
$tmpthirdparty->fetch($event->socid);
$cache_thirdparty[$event->socid]=$tmpthirdparty;
}
$cases1[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name;
}
if ($event->contactid > 0)
{
if (empty($cache_contact[$event->contactid]))
{
$tmpcontact=new Contact($db);
$tmpcontact->fetch($event->contactid);
$cache_contact[$event->contactid]=$tmpcontact;
}
$cases1[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs);
}
$cases1[$h][$event->id]['color']=$color;
}
if ($event->date_start_in_calendar < $c && $dateendtouse > $b)
{
Expand All @@ -907,11 +937,37 @@ function show_day_events_pertype($username, $day, $month, $year, $monthshown, $s
}
$cases2[$h][$event->id]['string'].=' - '.$event->label;
$cases2[$h][$event->id]['typecode']=$event->type_code;
if ($event->socid)
$cases2[$h][$event->id]['color']=$color;
if ($event->fk_project > 0)
{
//$cases2[$h][$event->id]['string'].='xxx';
if (empty($cache_project[$event->fk_project]))
{
$tmpproj=new Project($db);
$tmpproj->fetch($event->fk_project);
$cache_project[$event->fk_project]=$tmpproj;
}
$cases2[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$event->fk_project]->title;
}
if ($event->socid > 0)
{
if (empty($cache_thirdparty[$event->socid]))
{
$tmpthirdparty=new Societe($db);
$tmpthirdparty->fetch($event->socid);
$cache_thirdparty[$event->socid]=$tmpthirdparty;
}
$cases2[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name;
}
if ($event->contactid > 0)
{
if (empty($cache_contact[$event->contactid]))
{
$tmpcontact=new Contact($db);
$tmpcontact->fetch($event->contactid);
$cache_contact[$event->contactid]=$tmpcontact;
}
$cases2[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs);
}
$cases2[$h][$event->id]['color']=$color;
}
}
else
Expand Down
82 changes: 70 additions & 12 deletions htdocs/comm/action/peruser.php
Expand Up @@ -30,10 +30,12 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';


if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
Expand All @@ -55,7 +57,7 @@
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page","int");
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$offset = $limit * $page;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="a.datec";
Expand Down Expand Up @@ -93,9 +95,10 @@
}
else
{
$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
$actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode","alpha")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
}
if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);

$dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth','int'), GETPOST('dateselectday','int'), GETPOST('dateselectyear','int'));
if ($dateselect > 0)
{
Expand Down Expand Up @@ -361,7 +364,7 @@
$sql.= ' a.percent,';
$sql.= ' a.fk_user_author,a.fk_user_action,';
$sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
$sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,';
$sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
$sql.= ' ca.code, ca.color';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
Expand Down Expand Up @@ -485,6 +488,8 @@
$event->location=$obj->location;
$event->transparency=$obj->transparency;

$event->fk_project=$obj->fk_project;

$event->socid=$obj->fk_soc;
$event->contactid=$obj->fk_contact;
//$event->societe->id=$obj->fk_soc; // deprecated
Expand Down Expand Up @@ -873,6 +878,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
global $theme_datacolor; // Array with a list of different we can use (come from theme)
global $cachethirdparties, $cachecontacts, $colorindexused;
global $begin_h, $end_h;
global $cache_project, $cache_thirdparty, $cache_contact;

$cases1 = array(); // Color first half hour
$cases2 = array(); // Color second half hour
Expand Down Expand Up @@ -988,13 +994,39 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'hour');
else $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
}
$cases1[$h][$event->id]['string'].=' - '.$event->label;
if ($event->label) $cases1[$h][$event->id]['string'].=' - '.$event->label;
$cases1[$h][$event->id]['typecode']=$event->type_code;
if ($event->socid)
$cases1[$h][$event->id]['color']=$color;
if ($event->fk_project > 0)
{
//$cases1[$h][$event->id]['string'].='xxx';
if (empty($cache_project[$event->fk_project]))
{
$tmpproj=new Project($db);
$tmpproj->fetch($event->fk_project);
$cache_project[$event->fk_project]=$tmpproj;
}
$cases1[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$event->fk_project]->title;
}
if ($event->socid > 0)
{
if (empty($cache_thirdparty[$event->socid]))
{
$tmpthirdparty=new Societe($db);
$tmpthirdparty->fetch($event->socid);
$cache_thirdparty[$event->socid]=$tmpthirdparty;
}
$cases1[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name;
}
if ($event->contactid > 0)
{
if (empty($cache_contact[$event->contactid]))
{
$tmpcontact=new Contact($db);
$tmpcontact->fetch($event->contactid);
$cache_contact[$event->contactid]=$tmpcontact;
}
$cases1[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs);
}
$cases1[$h][$event->id]['color']=$color;
}
if ($event->date_start_in_calendar < $c && $dateendtouse > $b)
{
Expand All @@ -1008,13 +1040,39 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'hour');
else $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
}
$cases2[$h][$event->id]['string'].=' - '.$event->label;
if ($event->label) $cases2[$h][$event->id]['string'].=' - '.$event->label;
$cases2[$h][$event->id]['typecode']=$event->type_code;
if ($event->socid)
$cases2[$h][$event->id]['color']=$color;
if ($event->fk_project > 0)
{
//$cases2[$h][$event->id]['string'].='xxx';
if (empty($cache_project[$event->fk_project]))
{
$tmpproj=new Project($db);
$tmpproj->fetch($event->fk_project);
$cache_project[$event->fk_project]=$tmpproj;
}
$cases2[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$event->fk_project]->title;
}
if ($event->socid > 0)
{
if (empty($cache_thirdparty[$event->socid]))
{
$tmpthirdparty=new Societe($db);
$tmpthirdparty->fetch($event->socid);
$cache_thirdparty[$event->socid]=$tmpthirdparty;
}
$cases2[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name;
}
if ($event->contactid > 0)
{
if (empty($cache_contact[$event->contactid]))
{
$tmpcontact=new Contact($db);
$tmpcontact->fetch($event->contactid);
$cache_contact[$event->contactid]=$tmpcontact;
}
$cases2[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs);
}
$cases2[$h][$event->id]['color']=$color;
}
}
else
Expand Down

0 comments on commit 837afa0

Please sign in to comment.