/**
 * Get getListActionCommType
 *
 * @param	array		$authentication		Array of authentication information
 * @return	mixed
 */
function getListActionCommType($authentication)
{
    global $db, $conf, $langs;
    dol_syslog("Function: getListActionCommType login=" . $authentication['login']);
    if ($authentication['entity']) {
        $conf->entity = $authentication['entity'];
    }
    // Init and check authentication
    $objectresp = array();
    $errorcode = '';
    $errorlabel = '';
    $error = 0;
    $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
    if (!$error) {
        $fuser->getrights();
        if ($fuser->rights->agenda->myactions->read) {
            $cactioncomm = new CActionComm($db);
            $result = $cactioncomm->liste_array('', 'code');
            if ($result > 0) {
                $resultarray = array();
                foreach ($cactioncomm->liste_array as $code => $libeller) {
                    $resultarray[] = array('code' => $code, 'libelle' => $libeller);
                }
                $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'actioncommtypes' => $resultarray);
            } else {
                $error++;
                $errorcode = 'NOT_FOUND';
                $errorlabel = 'Object not found for id=' . $id . ' nor ref=' . $ref . ' nor ref_ext=' . $ref_ext;
            }
        } else {
            $error++;
            $errorcode = 'PERMISSION_DENIED';
            $errorlabel = 'User does not have permission for this request';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
Exemplo n.º 2
0
$fulldayevent = GETPOST('fullday');
$datep = dol_mktime($fulldayevent ? '00' : GETPOST("aphour"), $fulldayevent ? '00' : GETPOST("apmin"), 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear"));
$datef = dol_mktime($fulldayevent ? '23' : GETPOST("p2hour"), $fulldayevent ? '59' : GETPOST("p2min"), $fulldayevent ? '59' : '0', GETPOST("p2month"), GETPOST("p2day"), GETPOST("p2year"));
// Security check
$socid = GETPOST('socid', 'int');
$id = GETPOST('id', 'int');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
if ($user->societe_id && $socid) {
    $result = restrictedArea($user, 'societe', $socid);
}
$error = GETPOST("error");
$donotclearsession = GETPOST('donotclearsession') ? GETPOST('donotclearsession') : 0;
$cactioncomm = new CActionComm($db);
$object = new ActionComm($db);
$contact = new Contact($db);
$extrafields = new ExtraFields($db);
$formfile = new FormFile($db);
$form = new Form($db);
$formfile = new FormFile($db);
$formactions = new FormActions($db);
// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
//var_dump($_POST);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('actioncard', 'globalcard'));
/*
 * Actions
 */
Exemplo n.º 3
0
 print '<td class="liste_titre" align="center">';
 print $form->select_date($dateend, 'dateend', 0, 0, 1, '', 1, 0, 1);
 print '</td>';
 print '<td class="liste_titre"></td>';
 print '<td class="liste_titre"></td>';
 //print '<td class="liste_titre"></td>';
 print '<td class="liste_titre"></td>';
 print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
 print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
 print '</td>';
 print "</tr>\n";
 $contactstatic = new Contact($db);
 $now = dol_now();
 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
 $caction = new CActionComm($db);
 $arraylist = $caction->liste_array(1, 'code', '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0);
 $var = true;
 while ($i < min($num, $limit)) {
     $obj = $db->fetch_object($resql);
     // Discard auto action if option is on
     if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
         $i++;
         continue;
     }
     $var = !$var;
     print "<tr " . $bc[$var] . ">";
     // Action (type)
     print '<td>';
     $actionstatic->id = $obj->id;
     $actionstatic->type_code = $obj->type_code;
 /**
  *  Output list of type of event
  *
  *  @param	string		$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx'
  *  @param  string		$htmlname       Nom champ formulaire
  *  @param	string		$excludetype	Type to exclude
  *  @param	string		$onlyautoornot	Group list by auto events or not: We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
  * 	@return	void
  */
 function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0)
 {
     global $langs, $user, $form;
     if (!is_object($form)) {
         $form = new Form($db);
     }
     require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
     require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
     $caction = new CActionComm($this->db);
     // Suggest a list with manual events or all auto events
     $arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
     array_unshift($arraylist, '&nbsp;');
     // Add empty line at start
     //asort($arraylist);
     if ($selected == 'manual') {
         $selected = 'AC_OTH';
     }
     if ($selected == 'auto') {
         $selected = 'AC_OTH_AUTO';
     }
     print $form->selectarray($htmlname, $arraylist, $selected);
     if ($user->admin && empty($onlyautoornot)) {
         print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
     }
 }
Exemplo n.º 5
0
 /**
  *    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;
     }
 }
Exemplo n.º 6
0
 /**
  *  Output html select list of type of event
  *
  *  @param	string		$selected       Type pre-selected (can be 'manual', 'auto' or 'AC_xxx')
  *  @param  string		$htmlname       Nom champ formulaire
  *  @param	string		$excludetype	A type to exclude ('systemauto', 'system', '')
  *  @param	string		$onlyautoornot	1=Group all type AC_XXX into 1 line AC_MANUAL. 0=Keep details of type
  *  @param	int		    $hideinfohelp	1=Do not show info help
  *  @param  int		    $multiselect    1=Allow multiselect of action type
  * 	@return	void
  */
 function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0)
 {
     global $langs, $user, $form, $conf;
     if (!is_object($form)) {
         $form = new Form($db);
     }
     require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
     require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
     $caction = new CActionComm($this->db);
     // Suggest a list with manual events or all auto events
     $arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
     array_unshift($arraylist, '&nbsp;');
     // Add empty line at start
     //asort($arraylist);
     if ($selected == 'manual') {
         $selected = 'AC_OTH';
     }
     if ($selected == 'auto') {
         $selected = 'AC_OTH_AUTO';
     }
     if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) {
         unset($arraylist['AC_OTH_AUTO']);
     }
     if (!empty($multiselect)) {
         if (!is_array($selected) && !empty($selected)) {
             $selected = explode(',', $selected);
         }
         print $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
     } else {
         print $form->selectarray($htmlname, $arraylist, $selected);
     }
     if ($user->admin && empty($onlyautoornot) && empty($hideinfohelp)) {
         print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
     }
 }
Exemplo n.º 7
0
$langs->load("bills");
$langs->load("orders");
$langs->load("agenda");

$action=GETPOST("action");

// Security check
$socid = GETPOST('socid');
$id = GETPOST('id');
if ($user->societe_id) $socid=$user->societe_id;
// TODO: revoir les droits car pas clair
//$result = restrictedArea($user, 'agenda', $id, 'actioncomm', 'actions', '', 'id');

if (isset($_GET["error"])) $error=$_GET["error"];

$cactioncomm = new CActionComm($db);
$actioncomm = new ActionComm($db);
$contact = new Contact($db);
//var_dump($_POST);

/*
 * Action creation de l'action
 */
if ($action == 'add_action')
{
    $backtopage='';
    if (! empty($_POST["backtopage"])) $backtopage=$_POST["backtopage"];
    if (! $backtopage)
    {
        if ($socid > 0) $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
        else $backtopage=DOL_URL_ROOT.'/comm/action/index.php';
Exemplo n.º 8
0
 /**
  *    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;
     }
 }
Exemplo n.º 9
0
 /**
  *  Output list of type of event
  *
  *  @param	string		$selected        Type pre-selectionne
  *  @param  string		$htmlname        Nom champ formulaire
  * 	@return	void
  */
 function select_type_actions($selected = '', $htmlname = 'actioncode', $active = 1, $idorcode = 'code', $type = '1,2')
 {
     global $langs, $user;
     require_once DOL_DOCUMENT_ROOT . "/comm/action/class/cactioncomm.class.php";
     require_once DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php";
     $caction = new CActionComm($this->db);
     $form = new Form($this->db);
     $arraylist = array();
     $arraylist = $caction->liste_array($active, $idorcode, $type);
     $arraylist[0] = '&nbsp;';
     asort($arraylist);
     print $form->selectarray($htmlname, $arraylist, $selected);
     if ($user->admin) {
         print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
     }
 }
 /**
  *    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;
     }
 }
Exemplo n.º 11
0
         case 'ISO-8859-15':
             $htmlmsg = utf8_encode($htmlmsg);
             $plainmsg = utf8_encode(nl2br($plainmsg));
             break;
         default:
             $plainmsg = nl2br($plainmsg);
     }
     if ($htmlmsg != '') {
         $corps = $htmlmsg;
     } else {
         $corps = $plainmsg;
     }
 }
 imap_close($mbox);
 $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;
Exemplo n.º 12
0
    /**
     *    Output list of type of event
     *    @param      selected        Type pre-selectionne
     *    @param      htmlname        Nom champ formulaire
     */
    function select_type_actions($selected='',$htmlname='actioncode')
    {
        global $langs,$user;

        require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
        require_once(DOL_DOCUMENT_ROOT."/core/class/html.form.class.php");
        $caction=new CActionComm($this->db);
        $form=new Form($this->db);

        $arraylist=$caction->liste_array(1,'code');
        array_unshift($arraylist,'&nbsp;');     // Add empty line at start
        //asort($arraylist);

        print $form->selectarray($htmlname, $arraylist, $selected);
        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
    }
Exemplo n.º 13
0
$langs->load("orders");
$langs->load("agenda");
$action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$contactid = GETPOST('contactid', 'int');
// Security check
$socid = GETPOST('socid', 'int');
$id = GETPOST('id', 'int');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
//$result = restrictedArea($user, 'agenda', $id, 'actioncomm', 'actions', '', 'id');
$error = GETPOST("error");
$mesg = '';
$cactioncomm = new CActionComm($db);
$actioncomm = new ActionComm($db);
$contact = new Contact($db);
//var_dump($_POST);
/*
 * Action creation de l'action
 */
if ($action == 'add_action') {
    $error = 0;
    if (empty($backtopage)) {
        if ($socid > 0) {
            $backtopage = DOL_URL_ROOT . '/societe/agenda.php?socid=' . $socid;
        } else {
            $backtopage = DOL_URL_ROOT . '/comm/action/index.php';
        }
    }