function ordonnanceur_link_event(&$Task)
{
    global $db, $user;
    dol_include_once('/comm/action/class/actioncomm.class.php');
    foreach ($Task['tasks'] as &$task) {
        $t_start = $task['time_estimated_start'];
        $t_end = $task['time_estimated_end'];
        $res = $db->query("SELECT id FROM " . MAIN_DB_PREFIX . "actioncomm WHERE elementtype='project_task' AND fk_element=" . (int) $task['id']);
        $TUserAssigned = array();
        foreach ($task['TUser'] as $idContact => $u) {
            if ($u['selected']) {
                $TUserAssigned[] = array('id' => $idContact);
            }
        }
        if ($obj = $db->fetch_object($res)) {
            $a = new ActionComm($db);
            $a->fetch($obj->id);
            $a->datep = $t_start;
            $a->datef = $t_end;
            $a->durationp = $task['planned_workload'] * 3600;
            $a->label = $task['ref'] . ' ' . $task['label'];
            $a->progress = $task['progress'];
            $a->fk_project = $task['fk_projet'];
            $a->userassigned = $TUserAssigned;
            $a->socid = $task['fk_soc'];
            $a->update($user);
            //  print "update ".$a->id.'<br />';
        } else {
            $a = new ActionComm($db);
            $a->datep = $t_start;
            $a->datef = $t_end;
            $a->userownerid = $user->id;
            $a->type_code = 'AC_OTH_AUTO';
            $a->label = $task['ref'] . ' ' . $task['label'];
            $a->elementtype = 'project_task';
            $a->fk_element = $task['id'];
            $a->fk_project = $task['fk_projet'];
            $a->progress = $task['progress'];
            $a->durationp = $task['planned_workload'] * 3600;
            $a->userassigned = $TUserAssigned;
            $a->socid = $task['fk_soc'];
            $a->add($user);
        }
    }
}
/**
 * Create ActionComm
 *
 * @param	array		$authentication		Array of authentication information
 * @param	ActionComm	$actioncomm		    $actioncomm
 * @return	array							Array result
 */
function updateActionComm($authentication, $actioncomm)
{
    global $db, $conf, $langs;
    $now = dol_now();
    dol_syslog("Function: updateActionComm login="******"Actioncomm id is mandatory.";
    }
    if (!$error) {
        $objectfound = false;
        $object = new ActionComm($db);
        $result = $object->fetch($actioncomm['id']);
        if (!empty($object->id)) {
            $objectfound = true;
            $object->datep = $actioncomm['datep'];
            $object->datef = $actioncomm['datef'];
            $object->type_code = $actioncomm['type_code'];
            $object->societe->id = $actioncomm['socid'];
            $object->fk_project = $actioncomm['projectid'];
            $object->note = $actioncomm['note'];
            $object->contact->id = $actioncomm['contactid'];
            $object->usertodo->id = $actioncomm['usertodo'];
            $object->userdone->id = $actioncomm['userdone'];
            $object->label = $actioncomm['label'];
            $object->percentage = $actioncomm['percentage'];
            $object->priority = $actioncomm['priority'];
            $object->fulldayevent = $actioncomm['fulldayevent'];
            $object->location = $actioncomm['location'];
            $object->fk_element = $actioncomm['fk_element'];
            $object->elementtype = $actioncomm['elementtype'];
            //Retreive all extrafield for actioncomm
            // fetch optionals attributes and labels
            $extrafields = new ExtraFields($db);
            $extralabels = $extrafields->fetch_name_optionals_label('actioncomm', true);
            foreach ($extrafields->attribute_label as $key => $label) {
                $key = 'options_' . $key;
                $object->array_options[$key] = $actioncomm[$key];
            }
            $db->begin();
            $result = $object->update($fuser);
            if ($result <= 0) {
                $error++;
            }
        }
        if (!$error && $objectfound) {
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $object->id);
        } elseif ($objectfound) {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $object->error;
        } else {
            $error++;
            $errorcode = 'NOT_FOUND';
            $errorlabel = 'Actioncomm id=' . $actioncomm['id'] . ' cannot be found';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
        $a->userownerid = GETPOST('fk_user') ? GETPOST('fk_user') : $user->id;
        $a->type_code = GETPOST('type_code') ? GETPOST('type_code') : 'AC_OTH';
        $a->socid = GETPOST('fk_soc');
        $a->contactid = GETPOST('fk_contact');
        $a->fk_project = GETPOST('fk_project', 'int');
        $a->percentage = -1;
        // Non applicable
        $moreParams = GETPOST('moreParams');
        $moreParams = explode(',', $moreParams);
        $TParam = array();
        foreach ($moreParams as $param) {
            $a->_[$param] = GETPOST($param);
        }
        //var_dump($conf->global->FULLCALENDAR_SHOW_THIS_HOURS,GETPOST('date'),$a);exit;
        $res = $a->add($user);
        $a->update($user);
        print $res;
        break;
}
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