Exemplo n.º 1
0
$modulepart = 'contract';
/*
 * Actions
 */
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
/*
 * View
 */
$form = new Form($db);
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
llxHeader('', $langs->trans("Agenda"), $help_url);
if ($object->id > 0) {
    $result1 = $object->fetch($id);
    $result2 = $object->fetch_thirdparty();
    $result3 = $object->fetch_contact();
    $result4 = $object->fetch_userassigned();
    $result5 = $object->fetch_optionals($id, $extralabels);
    if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
        dol_print_error($db, $object->error);
        exit;
    }
    if ($object->authorid > 0) {
        $tmpuser = new User($db);
        $res = $tmpuser->fetch($object->authorid);
        $object->author = $tmpuser;
    }
    if ($object->usermodid > 0) {
        $tmpuser = new User($db);
        $res = $tmpuser->fetch($object->usermodid);
        $object->usermod = $tmpuser;
    }
Exemplo n.º 2
0
 $event = new ActionComm($db);
 $event->id = $obj->id;
 $event->datep = $db->jdate($obj->datep);
 // datep and datef are GMT date
 $event->datef = $db->jdate($obj->datep2);
 $event->type_code = $obj->code;
 $event->type_color = $obj->color;
 //$event->libelle=$obj->label;				// deprecated
 $event->label = $obj->label;
 $event->percentage = $obj->percent;
 //$event->author->id=$obj->fk_user_author;	// user id of creator
 $event->authorid = $obj->fk_user_author;
 // user id of creator
 $event->userownerid = $obj->fk_user_action;
 // user id of owner
 $event->fetch_userassigned();
 // This load $event->userassigned
 $event->priority = $obj->priority;
 $event->fulldayevent = $obj->fulldayevent;
 $event->location = $obj->location;
 $event->transparency = $obj->transparency;
 $event->socid = $obj->fk_soc;
 $event->contactid = $obj->fk_contact;
 //$event->societe->id=$obj->fk_soc;			// deprecated
 //$event->contact->id=$obj->fk_contact;		// deprecated
 $event->fk_element = $obj->fk_element;
 $event->elementtype = $obj->elementtype;
 // Defined date_start_in_calendar and date_end_in_calendar property
 // They are date start and end of action but modified to not be outside calendar view.
 if ($event->percentage <= 0) {
     $event->date_start_in_calendar = $event->datep;
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;
}