/** * Add an action/event into database * @param user Object user making action * @param notrigger 1 = disable triggers, 0 = enable triggers * @return int Id of created event, < 0 if KO */ function add($user, $notrigger = 0) { global $langs, $conf; $now = dol_now(); // Clean parameters $this->label = dol_trunc(trim($this->label), 128); $this->location = dol_trunc(trim($this->location), 128); $this->note = dol_htmlcleanlastbr(trim($this->note)); if (empty($this->percentage)) { $this->percentage = 0; } if (empty($this->priority)) { $this->priority = 0; } if (empty($this->fulldayevent)) { $this->fuldayevent = 0; } if (empty($this->punctual)) { $this->punctual = 0; } if ($this->percentage > 100) { $this->percentage = 100; } if ($this->percentage == 100 && !$this->dateend) { $this->dateend = $this->date; } if ($this->datep && $this->datef) { $this->durationp = $this->datef - $this->datep; } if ($this->date && $this->dateend) { $this->durationa = $this->dateend - $this->date; } if ($this->datep && $this->datef && $this->datep > $this->datef) { $this->datef = $this->datep; } if ($this->date && $this->dateend && $this->date > $this->dateend) { $this->dateend = $this->date; } if ($this->fk_project < 0) { $this->fk_project = 0; } if ($this->elementtype == 'facture') { $this->elementtype = 'invoice'; } if ($this->elementtype == 'commande') { $this->elementtype = 'order'; } if ($this->elementtype == 'contrat') { $this->elementtype = 'contract'; } if (!$this->type_id && $this->type_code) { # Get id from code $cactioncomm = new CActionComm($this->db); $result = $cactioncomm->fetch($this->type_code); if ($result > 0) { $this->type_id = $cactioncomm->id; } else { if ($result == 0) { $this->error = 'Failed to get record with code AC_OTH from dictionnary "type of events"'; return -1; } else { $this->error = $cactioncomm->error; return -1; } } } // Check parameters if (!$this->type_id) { $this->error = "ErrorWrongParameters"; return -1; } $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm"; $sql .= "(datec,"; $sql .= "datep,"; $sql .= "datep2,"; $sql .= "datea,"; $sql .= "datea2,"; $sql .= "durationp,"; $sql .= "durationa,"; $sql .= "fk_action,"; $sql .= "fk_soc,"; $sql .= "fk_project,"; $sql .= "note,"; $sql .= "fk_contact,"; $sql .= "fk_user_author,"; $sql .= "fk_user_action,"; $sql .= "fk_user_done,"; $sql .= "label,percent,priority,fulldayevent,location,punctual,"; $sql .= "fk_element,"; $sql .= "elementtype,"; $sql .= "entity"; $sql .= ") VALUES ("; $sql .= "'" . $this->db->idate($now) . "',"; $sql .= (strval($this->datep) != '' ? "'" . $this->db->idate($this->datep) . "'" : "null") . ","; $sql .= (strval($this->datef) != '' ? "'" . $this->db->idate($this->datef) . "'" : "null") . ","; $sql .= (strval($this->date) != '' ? "'" . $this->db->idate($this->date) . "'" : "null") . ","; $sql .= (strval($this->dateend) != '' ? "'" . $this->db->idate($this->dateend) . "'" : "null") . ","; $sql .= ($this->durationp >= 0 && $this->durationp != '' ? "'" . $this->durationp . "'" : "null") . ","; $sql .= ($this->durationa >= 0 && $this->durationa != '' ? "'" . $this->durationa . "'" : "null") . ","; $sql .= " '" . $this->type_id . "',"; $sql .= ($this->societe->id > 0 ? " '" . $this->societe->id . "'" : "null") . ","; $sql .= ($this->fk_project > 0 ? " '" . $this->fk_project . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->note) . "',"; $sql .= ($this->contact->id > 0 ? "'" . $this->contact->id . "'" : "null") . ","; $sql .= ($user->id > 0 ? "'" . $user->id . "'" : "null") . ","; $sql .= ($this->usertodo->id > 0 ? "'" . $this->usertodo->id . "'" : "null") . ","; $sql .= ($this->userdone->id > 0 ? "'" . $this->userdone->id . "'" : "null") . ","; $sql .= "'" . $this->db->escape($this->label) . "','" . $this->percentage . "','" . $this->priority . "','" . $this->fulldayevent . "','" . $this->db->escape($this->location) . "','" . $this->punctual . "',"; $sql .= ($this->fk_element ? $this->fk_element : "null") . ","; $sql .= ($this->elementtype ? "'" . $this->elementtype . "'" : "null") . ","; $sql .= $conf->entity; $sql .= ")"; dol_syslog("ActionComm::add sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "actioncomm", "id"); if (!$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('ACTION_CREATE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } $this->db->commit(); return $this->id; } else { $this->error = $this->db->lasterror() . ' sql=' . $sql; $this->db->rollback(); return -1; } }
} $object->transparency = $transparency; // We set transparency on event (even if we can also store it on each user, standard says this property is for event) if (!empty($conf->global->AGENDA_ENABLE_DONEBY)) { if (GETPOST("doneby")) { $object->userdoneid = GETPOST("doneby", "int"); } } // Check parameters if (!GETPOST('actioncode') > 0) { $error++; $donotclearsession = 1; $action = 'edit'; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); } else { $result = $cactioncomm->fetch(GETPOST('actioncode')); } if (empty($object->userownerid)) { $error++; $donotclearsession = 1; $action = 'edit'; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors'); } // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) { $error++; } if (!$error) { $db->begin(); $result = $object->update($user);
/** * Add an action/event into database. * $this->type_id OR $this->type_code must be set. * * @param User $user Object user making action * @param int $notrigger 1 = disable triggers, 0 = enable triggers * @return int Id of created event, < 0 if KO */ function add($user, $notrigger = 0) { global $langs, $conf, $hookmanager; $error = 0; $now = dol_now(); // Check parameters if (empty($this->userownerid)) { $this->errors[] = 'ErrorPropertyUserowneridNotDefined'; return -1; } // Clean parameters $this->label = dol_trunc(trim($this->label), 128); $this->location = dol_trunc(trim($this->location), 128); $this->note = dol_htmlcleanlastbr(trim($this->note)); if (empty($this->percentage)) { $this->percentage = 0; } if (empty($this->priority) || !is_numeric($this->priority)) { $this->priority = 0; } if (empty($this->fulldayevent)) { $this->fulldayevent = 0; } if (empty($this->punctual)) { $this->punctual = 0; } if (empty($this->transparency)) { $this->transparency = 0; } if ($this->percentage > 100) { $this->percentage = 100; } //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date; if (!empty($this->datep) && !empty($this->datef)) { $this->durationp = $this->datef - $this->datep; } // deprecated //if (! empty($this->date) && ! empty($this->dateend)) $this->durationa=($this->dateend - $this->date); if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) { $this->datef = $this->datep; } //if (! empty($this->date) && ! empty($this->dateend) && $this->date > $this->dateend) $this->dateend=$this->date; if (!isset($this->fk_project) || $this->fk_project < 0) { $this->fk_project = 0; } if ($this->elementtype == 'facture') { $this->elementtype = 'invoice'; } if ($this->elementtype == 'commande') { $this->elementtype = 'order'; } if ($this->elementtype == 'contrat') { $this->elementtype = 'contract'; } if (!is_array($this->userassigned) && !empty($this->userassigned)) { $tmpid = $this->userassigned; $this->userassigned = array(); $this->userassigned[$tmpid] = array('id' => $tmpid); } if (is_object($this->contact) && $this->contact->id > 0 && !($this->contactid > 0)) { $this->contactid = $this->contact->id; } // For backward compatibility. Using this->contact->xx is deprecated $userownerid = $this->userownerid; $userdoneid = $this->userdoneid; // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...). if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) { $this->userassigned = array($userownerid => array('id' => $userownerid)); } if (!$this->type_id || !$this->type_code) { $key = empty($this->type_id) ? $this->type_code : $this->type_id; // Get id from code $cactioncomm = new CActionComm($this->db); $result = $cactioncomm->fetch($key); if ($result > 0) { $this->type_id = $cactioncomm->id; $this->type_code = $cactioncomm->code; } else { if ($result == 0) { $this->error = 'Failed to get record with id ' . $this->type_id . ' code ' . $this->type_code . ' from dictionary "type of events"'; return -1; } else { $this->error = $cactioncomm->error; return -1; } } } // Check parameters if (!$this->type_id) { $this->error = "ErrorWrongParameters"; return -1; } $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm"; $sql .= "(datec,"; $sql .= "datep,"; $sql .= "datep2,"; $sql .= "durationp,"; // deprecated $sql .= "fk_action,"; $sql .= "code,"; $sql .= "fk_soc,"; $sql .= "fk_project,"; $sql .= "note,"; $sql .= "fk_contact,"; $sql .= "fk_user_author,"; $sql .= "fk_user_action,"; $sql .= "fk_user_done,"; $sql .= "label,percent,priority,fulldayevent,location,punctual,"; $sql .= "transparency,"; $sql .= "fk_element,"; $sql .= "elementtype,"; $sql .= "entity"; $sql .= ") VALUES ("; $sql .= "'" . $this->db->idate($now) . "',"; $sql .= (strval($this->datep) != '' ? "'" . $this->db->idate($this->datep) . "'" : "null") . ","; $sql .= (strval($this->datef) != '' ? "'" . $this->db->idate($this->datef) . "'" : "null") . ","; $sql .= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '' ? "'" . $this->durationp . "'" : "null") . ","; // deprecated $sql .= (isset($this->type_id) ? $this->type_id : "null") . ","; $sql .= (isset($this->type_code) ? " '" . $this->type_code . "'" : "null") . ","; $sql .= (isset($this->socid) && $this->socid > 0 ? " '" . $this->socid . "'" : "null") . ","; $sql .= (isset($this->fk_project) && $this->fk_project > 0 ? " '" . $this->fk_project . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->note) . "',"; $sql .= (isset($this->contactid) && $this->contactid > 0 ? "'" . $this->contactid . "'" : "null") . ","; $sql .= (isset($user->id) && $user->id > 0 ? "'" . $user->id . "'" : "null") . ","; $sql .= ($userownerid > 0 ? "'" . $userownerid . "'" : "null") . ","; $sql .= ($userdoneid > 0 ? "'" . $userdoneid . "'" : "null") . ","; $sql .= "'" . $this->db->escape($this->label) . "','" . $this->percentage . "','" . $this->priority . "','" . $this->fulldayevent . "','" . $this->db->escape($this->location) . "','" . $this->punctual . "',"; $sql .= "'" . $this->transparency . "',"; $sql .= (!empty($this->fk_element) ? $this->fk_element : "null") . ","; $sql .= (!empty($this->elementtype) ? "'" . $this->elementtype . "'" : "null") . ","; $sql .= $conf->entity; $sql .= ")"; dol_syslog(get_class($this) . "::add", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "actioncomm", "id"); // Now insert assignedusers if (!$error) { foreach ($this->userassigned as $key => $val) { if (!is_array($val)) { $val = array('id' => $val); } $sql = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql .= " VALUES(" . $this->id . ", 'user', " . $val['id'] . ", " . (empty($val['mandatory']) ? '0' : $val['mandatory']) . ", " . (empty($val['transparency']) ? '0' : $val['transparency']) . ", " . (empty($val['answer_status']) ? '0' : $val['answer_status']) . ")"; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = $this->db->lasterror(); } //var_dump($sql);exit; } } if (!$error) { $action = 'create'; // Actions on extra fields (by external module or standard code) // TODO le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('actioncommdao')); $parameters = array('actcomm' => $this->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } else { if ($reshook < 0) { $error++; } } } if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('ACTION_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error) { $this->db->commit(); return $this->id; } else { $this->db->rollback(); return -1; } } else { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; } }
{ $error=1; $action = 'create'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd")).'</div>'; } // Initialisation objet cactioncomm if (! $_POST["actioncode"]) { $error=1; $action = 'create'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Type")).'</div>'; } else { $result=$cactioncomm->fetch($_POST["actioncode"]); } // Initialisation objet actioncomm $actioncomm->type_id = $cactioncomm->id; $actioncomm->type_code = $cactioncomm->code; $actioncomm->priority = isset($_POST["priority"])?$_POST["priority"]:0; $actioncomm->fulldayevent = $_POST["fullday"]?1:0; $actioncomm->location = isset($_POST["location"])?$_POST["location"]:''; $actioncomm->label = trim($_POST["label"]); if (! $_POST["label"]) { if ($_POST["actioncode"] == 'AC_RDV' && $contact->getFullName($langs)) { $actioncomm->label = $langs->transnoentitiesnoconv("TaskRDVWith",$contact->getFullName($langs)); }
/** * Add an action/event into database * * @param User $user Object user making action * @param int $notrigger 1 = disable triggers, 0 = enable triggers * @return int Id of created event, < 0 if KO */ function add($user, $notrigger = 0) { global $langs, $conf, $hookmanager; $error = 0; $now = dol_now(); // Clean parameters $this->label = dol_trunc(trim($this->label), 128); $this->location = dol_trunc(trim($this->location), 128); $this->note = dol_htmlcleanlastbr(trim($this->note)); if (empty($this->percentage)) { $this->percentage = 0; } if (empty($this->priority) || !is_numeric($this->priority)) { $this->priority = 0; } if (empty($this->fulldayevent)) { $this->fulldayevent = 0; } if (empty($this->punctual)) { $this->punctual = 0; } if (empty($this->transparency)) { $this->transparency = 0; } if ($this->percentage > 100) { $this->percentage = 100; } //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date; if (!empty($this->datep) && !empty($this->datef)) { $this->durationp = $this->datef - $this->datep; } //if (! empty($this->date) && ! empty($this->dateend)) $this->durationa=($this->dateend - $this->date); if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) { $this->datef = $this->datep; } //if (! empty($this->date) && ! empty($this->dateend) && $this->date > $this->dateend) $this->dateend=$this->date; if (!isset($this->fk_project) || $this->fk_project < 0) { $this->fk_project = 0; } if ($this->elementtype == 'facture') { $this->elementtype = 'invoice'; } if ($this->elementtype == 'commande') { $this->elementtype = 'order'; } if ($this->elementtype == 'contrat') { $this->elementtype = 'contract'; } if (!$this->type_id && $this->type_code) { // Get id from code $cactioncomm = new CActionComm($this->db); $result = $cactioncomm->fetch($this->type_code); if ($result > 0) { $this->type_id = $cactioncomm->id; $this->code = $cactioncomm->code; } else { if ($result == 0) { $this->error = 'Failed to get record with code ' . $this->type_code . ' from dictionary "type of events"'; return -1; } else { $this->error = $cactioncomm->error; return -1; } } } // Check parameters if (!$this->type_id) { $this->error = "ErrorWrongParameters"; return -1; } $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm"; $sql .= "(datec,"; $sql .= "datep,"; $sql .= "datep2,"; $sql .= "durationp,"; $sql .= "fk_action,"; $sql .= "code,"; $sql .= "fk_soc,"; $sql .= "fk_project,"; $sql .= "note,"; $sql .= "fk_contact,"; $sql .= "fk_user_author,"; $sql .= "fk_user_action,"; $sql .= "fk_user_done,"; $sql .= "label,percent,priority,fulldayevent,location,punctual,"; $sql .= "transparency,"; $sql .= "fk_element,"; $sql .= "elementtype,"; $sql .= "entity"; $sql .= ") VALUES ("; $sql .= "'" . $this->db->idate($now) . "',"; $sql .= (strval($this->datep) != '' ? "'" . $this->db->idate($this->datep) . "'" : "null") . ","; $sql .= (strval($this->datef) != '' ? "'" . $this->db->idate($this->datef) . "'" : "null") . ","; $sql .= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '' ? "'" . $this->durationp . "'" : "null") . ","; $sql .= (isset($this->type_id) ? $this->type_id : "null") . ","; $sql .= (isset($this->code) ? " '" . $this->code . "'" : "null") . ","; $sql .= (isset($this->societe->id) && $this->societe->id > 0 ? " '" . $this->societe->id . "'" : "null") . ","; $sql .= (isset($this->fk_project) && $this->fk_project > 0 ? " '" . $this->fk_project . "'" : "null") . ","; $sql .= " '" . $this->db->escape($this->note) . "',"; $sql .= (isset($this->contact->id) && $this->contact->id > 0 ? "'" . $this->contact->id . "'" : "null") . ","; $sql .= (isset($user->id) && $user->id > 0 ? "'" . $user->id . "'" : "null") . ","; $sql .= (isset($this->usertodo->id) && $this->usertodo->id > 0 ? "'" . $this->usertodo->id . "'" : "null") . ","; $sql .= (isset($this->userdone->id) && $this->userdone->id > 0 ? "'" . $this->userdone->id . "'" : "null") . ","; $sql .= "'" . $this->db->escape($this->label) . "','" . $this->percentage . "','" . $this->priority . "','" . $this->fulldayevent . "','" . $this->db->escape($this->location) . "','" . $this->punctual . "',"; $sql .= "'" . $this->transparency . "',"; $sql .= (!empty($this->fk_element) ? $this->fk_element : "null") . ","; $sql .= (!empty($this->elementtype) ? "'" . $this->elementtype . "'" : "null") . ","; $sql .= $conf->entity; $sql .= ")"; dol_syslog(get_class($this) . "::add sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "actioncomm", "id"); // Actions on extra fields (by external module or standard code) $hookmanager->initHooks(array('actioncommdao')); $parameters = array('actcomm' => $this->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } else { if ($reshook < 0) { $error++; } } if (!$error && !$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('ACTION_CREATE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { $this->db->commit(); return $this->id; } else { $this->db->rollback(); return -1; } } else { $this->db->rollback(); $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::add " . $this->error, LOG_ERR); return -1; } }
$actioncomm = new ActionComm($db); $cactioncomm = new CActionComm($db); // Initialisation objet actioncomm $usertodo = $user; $actioncomm->usertodo = $usertodo; if (GETPOST('reference_fk_socid', 'int') > 0) { $societe = new Societe($db); $societe->fetch(GETPOST('reference_fk_socid', 'int')); $actioncomm->societe = $societe; } if ($conf->global->CODE_ACTIONCOMM_WEBMAIL) { $cactioncomm_code = $conf->global->CODE_ACTIONCOMM_WEBMAIL; } else { $cactioncomm_code = "AC_OTH"; } $result = $cactioncomm->fetch($cactioncomm_code); $actioncomm->type_id = $cactioncomm->id; $actioncomm->type_code = $cactioncomm->code; $actioncomm->priority = 0; $actioncomm->fulldayevent = 0; $actioncomm->location = ''; $from = $header->from; // On utilise l'objet du mail $actioncomm->label = trim(preg_replace('/<.*>|"/', '', @iconv_mime_decode(imap_utf8($header->subject)))); // ou a défaut le label "Envoi de mail de %expediteur%" if (!$actioncomm->label) { $lblfrom = @iconv_mime_decode(imap_utf8($from[0]->personal)) . " [" . $from[0]->mailbox . "@" . $from[0]->host . "]"; $actioncomm->label = $langs->transnoentitiesnoconv("MailFrom", $lblfrom); } else { $actioncomm->label = $langs->transnoentitiesnoconv("Mail ") . $actioncomm->label; }
// Clean parameters $datep = dol_mktime($fulldayevent ? '00' : $_POST["aphour"], $fulldayevent ? '00' : $_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef = dol_mktime($fulldayevent ? '23' : $_POST["p2hour"], $fulldayevent ? '59' : $_POST["p2min"], $fulldayevent ? '59' : '0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); // Check parameters if (!$datef && $_POST["percentage"] == 100) { $error++; $action = 'create'; $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->trans("DateEnd")) . '</div>'; } // Initialisation objet cactioncomm if (!$_POST["actioncode"]) { $error++; $action = 'create'; $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->trans("Type")) . '</div>'; } else { $result = $cactioncomm->fetch($_POST["actioncode"]); } if ($cactioncomm->type == 2) { if ($_POST["percentage"] == 100) { $datef = dol_now(); } else { $datef = ''; } } // Check parameters if (!$datef && $_POST["percentage"] == 100) { $error = 1; $action = 'create'; $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->trans("DateEnd")) . '</div>'; } // Initialisation objet actioncomm