function _events($date_start, $date_end) { global $db, $conf, $langs, $user, $hookmanager; $hookmanager->initHooks(array('agenda')); $pid = GETPOST("projectid", "int", 3); $status = GETPOST("status"); $type = GETPOST("type"); $state_id = GETPOST('state_id'); $maxprint = GETPOST("maxprint") ? GETPOST("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW; //First try with GETPOST(array) (I don't know when it can be an array but why not) $actioncode = GETPOST("actioncode", "array", 3) ? GETPOST("actioncode", "array", 3) : (GETPOST("actioncode") == '0' ? '0' : ''); //If empty then try GETPOST(alpha) (this one works with comm/action/index.php if (empty($actioncode)) { $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : ''); if (!empty($actioncode)) { $actioncode = array($actioncode); } } if (empty($actioncode)) { $actioncode = array(); } $filter = GETPOST("filter", '', 3); $filtert = GETPOST("usertodo", "int", 3) ? GETPOST("usertodo", "int", 3) : GETPOST("filtert", "int", 3); $usergroup = GETPOST("usergroup", "int", 3); $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1; if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) { $filtert = $user->id; } $socid = GETPOST("socid", "int"); $t_start = strtotime($date_start); $t_end = strtotime($date_end); $now = dol_now(); $sql = 'SELECT '; if ($usergroup > 0) { $sql .= " DISTINCT"; } $sql .= ' a.id, a.label,'; $sql .= ' a.datep,'; $sql .= ' a.datep2,'; $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,u.color,a.note,'; $sql .= ' ca.code as type_code, ca.libelle as type_label'; $sql .= ' FROM ' . MAIN_DB_PREFIX . "actioncomm as a"; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_actioncomm as ca ON (a.fk_action = ca.id)'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user u ON (a.fk_user_action=u.rowid )'; if (!empty($conf->global->FULLCALENDAR_FILTER_ON_STATE) && !empty($state_id)) { $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe s ON (s.rowid = a.fk_soc)'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople sp ON (sp.rowid = a.fk_contact)'; } if (!$user->rights->societe->client->voir && !$socid) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; } // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "actioncomm_resources as ar ON (ar.fk_actioncomm = a.id)"; } if ($usergroup > 0) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; } $sql .= ' WHERE 1=1'; $sql .= ' AND a.entity IN (' . getEntity('agenda', 1) . ')'; if ($actioncode) { $sql .= " AND ca.code IN ('" . implode("','", $actioncode) . "')"; } if ($conf->global->DONT_SHOW_AUTO_EVENT && strpos(implode(',', $actioncode), 'AC_OTH_AUTO') == false) { $sql .= " AND ca.code != 'AC_OTH_AUTO'"; } if ($pid) { $sql .= " AND a.fk_project=" . $db->escape($pid); } if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = "******")"; } if ($socid > 0) { $sql .= ' AND a.fk_soc = ' . $socid; } if (!empty($conf->global->FULLCALENDAR_FILTER_ON_STATE) && !empty($state_id)) { $sql .= ' AND (s.fk_departement = ' . $state_id . ' OR sp.fk_departement = ' . $state_id . ')'; } // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) { $sql .= " AND ar.element_type='user'"; } $sql .= " AND\n\t\t\t(\n\t\t\t\t(a.datep2>='" . $db->idate($t_start - 60 * 60 * 24 * 7) . "' AND datep<='" . $db->idate($t_end + 60 * 60 * 24 * 10) . "')\n\t\t\t\tOR\n\t\t\t \t(a.datep BETWEEN '" . $db->idate($t_start - 60 * 60 * 24 * 7) . "' AND '" . $db->idate($t_end + 60 * 60 * 24 * 10) . "')\n\t\t\t) "; if ($type) { $sql .= " AND ca.id = " . $type; } if ($status == '0') { $sql .= " AND a.percent = 0"; } if ($status == '-1') { $sql .= " AND a.percent = -1"; } // Not applicable if ($status == '50') { $sql .= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started if ($status == 'done' || $status == '100') { $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '" . $db->idate($now) . "'))"; } if ($status == 'todo') { $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '" . $db->idate($now) . "'))"; } // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) { $sql .= " AND ("; if ($filtert > 0) { $sql .= "ar.fk_element = " . $filtert; } if ($usergroup > 0) { $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . $usergroup; } $sql .= ")"; } // Sort on date $sql .= ' ORDER BY datep'; $TEvent = array(); if (isset($_REQUEST['DEBUG'])) { print $sql; } $res = $db->query($sql); //var_dump($db); $TSociete = array(); $TContact = array(); $TUser = array(); $TProject = array(); $TEventObject = array(); while ($obj = $db->fetch_object($res)) { $event = new ActionComm($db); $event->fetch($obj->id); $event->fetch_userassigned(); $event->color = $obj->color; $TEventObject[] = $event; } foreach ($TEventObject as &$event) { if ($event->socid > 0 && !isset($TSociete[$event->socid])) { $societe = new Societe($db); $societe->fetch($event->socid); $TSociete[$event->socid] = $societe->getNomUrl(1); } if ($event->contactid > 0 && !isset($TContact[$event->contactid])) { $contact = new Contact($db); $contact->fetch($event->contactid); $TContact[$event->contactid] = $contact->getNomUrl(1); } $TUserassigned = array(); $TColor = array(); if ($event->color && empty($conf->global->FULLCALENDAR_USE_ASSIGNED_COLOR)) { $TColor[] = '#' . $event->color; } if (!empty($conf->global->FULLCALENDAR_SHOW_AFFECTED_USER)) { $userownerid = (int) $event->userownerid; if ($userownerid > 0 && !isset($TUser[$userownerid])) { $u = new User($db); $u->fetch($userownerid); $TUser[$userownerid] = $u; } $TUserassigned[$userownerid] = $TUser[$userownerid]->getNomUrl(1); } if (!empty($conf->global->FULLCALENDAR_SHOW_PROJECT) && $event->fk_project > 0 && !isset($TProject[$event->fk_project])) { $p = new Project($db); $p->fetch($event->fk_project); $TProject[$event->fk_project] = $p->getNomUrl(1); } if (!empty($conf->global->FULLCALENDAR_SHOW_AFFECTED_USER) && !empty($event->userassigned)) { foreach ($event->userassigned as &$ua) { $userid = (int) $ua['id']; if (!isset($TUser[$userid])) { $u = new User($db); $u->fetch($userid); $TUser[$userid] = $u; } if (!isset($TUserassigned[$userid])) { $TUserassigned[] = $TUser[$userid]->getNomUrl(1); } if ($TUser[$userid]->color && !in_array('#' . $TUser[$userid]->color, $TColor)) { $TColor[] = '#' . $TUser[$userid]->color; } } } $editable = false; if ($user->id == $event->userownerid || $user->rights->agenda->allactions->create) { $editable = true; } //background: linear-gradient(to bottom, #1e5799 0%,#2989d8 25%,#207cca 67%,#7db9e8 100%); //$colors = implode(',',$TColor); $colors = ''; $color = ''; if (!empty($TColor)) { $color = $TColor[0]; if (!empty($conf->global->FULLCALENDAR_SHOW_ALL_ASSIGNED_COLOR) && count($TColor) > 1) { $colors = 'linear-gradient(to right '; foreach ($TColor as $c) { $colors .= ',' . $c; } $colors .= ')'; } } $TEvent[] = array('id' => $event->id, 'title' => $event->label, 'allDay' => (bool) $event->fulldayevent, 'start' => empty($event->datep) ? '' : date('Y-m-d H:i:s', (int) $event->datep), 'end' => empty($event->datef) ? '' : date('Y-m-d H:i:s', (int) $event->datef), 'url' => dol_buildpath('/comm/action/card.php?id=' . $event->id, 1), 'editable' => $editable, 'color' => $color, 'isDarkColor' => isDarkColor($color), 'colors' => $colors, 'note' => $event->note, 'statut' => $event->getLibStatut(3), 'fk_soc' => $event->socid, 'fk_contact' => $event->contactid, 'fk_user' => $event->userownerid, 'fk_project' => $event->fk_project, 'societe' => !empty($TSociete[$event->socid]) ? $TSociete[$event->socid] : '', 'contact' => !empty($TContact[$event->contactid]) ? $TContact[$event->contactid] : '', 'user' => !empty($TUserassigned) ? implode(', ', $TUserassigned) : '', 'project' => !empty($TProject[$event->fk_project]) ? $TProject[$event->fk_project] : '', 'more' => ''); } $use_workstation_color = null; if (GETPOST('use_workstation_color')) { $use_workstation_color = 1; } //TODO getCalendarEvents compatbile standard // Complete $eventarray with events coming from external module $parameters = array('use_workstation_color' => $use_workstation_color, 'sql' => $sql); $action = 'getEvents'; $reshook = $hookmanager->executeHooks('updateFullcalendarEvents', $parameters, $TEvent, $action); if (!empty($hookmanager->resArray['eventarray'])) { $TEvent = array_merge($TEvent, $hookmanager->resArray['eventarray']); } return $TEvent; }
/** * Write content of pages * * @param PDF $pdf Object pdf * @param Translate $outputlangs Object langs * @return int 1 */ function _pages(&$pdf, $outputlangs) { global $conf; $height = 3; // height for text separation $pagenb = 1; $y = $this->_pagehead($pdf, $outputlangs, $pagenb); $y++; $pdf->SetFont('', '', 8); $sql = "SELECT s.nom as thirdparty, s.rowid as socid, s.client,"; $sql .= " a.id, a.datep as dp, a.datep2 as dp2,"; $sql .= " a.fk_contact, a.note, a.percent as percent, a.label, a.fk_project,"; $sql .= " c.code, c.libelle,"; $sql .= " u.login"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "user as u, " . MAIN_DB_PREFIX . "actioncomm as a"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid"; $sql .= " WHERE c.id=a.fk_action AND a.fk_user_author = u.rowid"; $sql .= " AND a.datep BETWEEN '" . $this->db->idate(dol_get_first_day($this->year, $this->month, false)) . "'"; $sql .= " AND '" . $this->db->idate(dol_get_last_day($this->year, $this->month, false)) . "'"; $sql .= " AND a.entity = " . $conf->entity; $sql .= " ORDER BY a.datep DESC"; $eventstatic = new ActionComm($this->db); $projectstatic = new Project($this->db); dol_syslog(get_class($this) . "::_page", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; $y0 = $y1 = $y2 = $y3 = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); $eventstatic->id = $obj->id; $eventstatic->percentage = $obj->percentage; $eventstatic->fulldayevent = $obj->fulldayevent; $eventstatic->punctual = $obj->punctual; $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3); // Calculate height of text $text = ''; if (!preg_match('/^' . preg_quote($obj->label) . '/', $obj->note)) { $text = $obj->label . "\n"; } $text .= $obj->note; $text = dol_trunc(dol_htmlentitiesbr_decode($text), 150); // Add status to text $text .= "\n"; $status = dol_htmlentitiesbr_decode($eventstatic->getLibStatut(1, 1)); $text .= $status; if ($obj->fk_project > 0) { $projectstatic->fetch($obj->fk_project); $text .= ($status ? ' - ' : '') . $outputlangs->transnoentitiesnoconv("Project") . ": " . dol_htmlentitiesbr_decode($projectstatic->getNomUrl(0, 'nolink')); } //print 'd'.$text; exit; $nboflines = dol_nboflines($text); $heightlinemax = max(2 * $height, $nboflines * $height); // Check if there is enough space to print record if (1 + $y + $heightlinemax >= $this->page_hauteur - $this->marge_haute) { // We need to break page $pagenb++; $y = $this->_pagehead($pdf, $outputlangs, $pagenb); $y++; $pdf->SetFont('', '', 8); } $y++; // Date $pdf->SetXY($this->marge_gauche, $y); $pdf->MultiCell(22, $height, dol_print_date($this->db->jdate($obj->dp), "day") . "\n" . dol_print_date($this->db->jdate($obj->dp), "hour"), 0, 'L', 0); $y0 = $pdf->GetY(); // Third party $pdf->SetXY(26, $y); $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->thirdparty), 32), 0, 'L', 0); $y1 = $pdf->GetY(); // Action code $code = $obj->code; if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) { if ($code == 'AC_OTH') { $code = 'AC_MANUAL'; } if ($code == 'AC_OTH_AUTO') { $code = 'AC_AUTO'; } } $pdf->SetXY(60, $y); $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Action" . $code)), 32), 0, 'L', 0); $y2 = $pdf->GetY(); // Description of event $pdf->SetXY(106, $y); $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); $y3 = $pdf->GetY(); $i++; } } return 1; }