/**
  *  Output record line into file
  *
  *  @param      array		$array_selected_sorted      Array with list of field to export
  *  @param      resource	$objp                       A record from a fetch with all fields from select
  *  @param      Translate	$outputlangs                Object lang to translate values
  *  @param		array		$array_types				Array with types of fields
  * 	@return		int										<0 if KO, >0 if OK
  */
 function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
 {
     global $conf;
     // Create a format for the column headings
     if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
         $outputlangs->charset_output = 'ISO-8859-1';
         // Because Excel 5 format is ISO
     }
     // Define first row
     $this->col = 0;
     foreach ($array_selected_sorted as $code => $value) {
         if (strpos($code, ' as ') == 0) {
             $alias = str_replace(array('.', '-'), '_', $code);
         } else {
             $alias = substr($code, strpos($code, ' as ') + 4);
         }
         if (empty($alias)) {
             dol_print_error('', 'Bad value for field with code=' . $code . '. Try to redefine export.');
         }
         $newvalue = $objp->{$alias};
         $newvalue = $this->excel_clean($newvalue);
         $typefield = isset($array_types[$code]) ? $array_types[$code] : '';
         // Traduction newvalue
         if (preg_match('/^\\((.*)\\)$/i', $newvalue, $reg)) {
             $newvalue = $outputlangs->transnoentities($reg[1]);
         } else {
             $newvalue = $outputlangs->convToOutputCharset($newvalue);
         }
         if (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i', $newvalue)) {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $formatdate = $this->workbook->addformat();
                 $formatdate->set_num_format('yyyy-mm-dd');
                 //$formatdate->set_num_format(0x0f);
                 $arrayvalue = preg_split('/[.,]/', xl_parse_date($newvalue));
                 //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
                 $newvalue = strval($arrayvalue[0]) . '.' . strval($arrayvalue[1]);
                 // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
                 $this->worksheet->write($this->row, $this->col, $newvalue, PHPExcel_Shared_Date::PHPToExcel($formatdate));
             } else {
                 $newvalue = dol_stringtotime($newvalue);
                 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
                 $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                 $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd');
             }
         } elseif (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/i', $newvalue)) {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $formatdatehour = $this->workbook->addformat();
                 $formatdatehour->set_num_format('yyyy-mm-dd hh:mm:ss');
                 //$formatdatehour->set_num_format(0x0f);
                 $arrayvalue = preg_split('/[.,]/', xl_parse_date($newvalue));
                 //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
                 $newvalue = strval($arrayvalue[0]) . '.' . strval($arrayvalue[1]);
                 // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
                 $this->worksheet->write($this->row, $this->col, $newvalue, $formatdatehour);
             } else {
                 $newvalue = dol_stringtotime($newvalue);
                 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
                 $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                 $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd h:mm:ss');
             }
         } else {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $this->worksheet->write($this->row, $this->col, $newvalue);
             } else {
                 if ($typefield == 'Text' || $typefield == 'TextAuto') {
                     //$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING);
                     $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, (string) $newvalue);
                     $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                     $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@');
                     $this->workbook->getActiveSheet()->getStyle($coord)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
                 } else {
                     $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, $newvalue);
                 }
             }
         }
         $this->col++;
     }
     $this->row++;
     return 0;
 }
Exemplo n.º 2
0
 /**		Return description of module
  *
  * 		@param	Translate	$langs		Object langs
  * 		@return string      			Description of module
  */
 function info($langs)
 {
     global $conf, $mc;
     global $form;
     $langs->load("companies");
     $disabled = !empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity ? ' disabled="disabled"' : '';
     $texte = $langs->trans('GenericNumRefModelDesc') . "<br>\n";
     $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
     $texte .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
     $texte .= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
     $texte .= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
     $texte .= '<table class="nobordernopadding" width="100%">';
     $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("ThirdParty"), $langs->transnoentities("ThirdParty"));
     //$tooltip.=$langs->trans("GenericMaskCodes2");	Not required for third party numbering
     $tooltip .= $langs->trans("GenericMaskCodes3");
     $tooltip .= $langs->trans("GenericMaskCodes4b");
     $tooltip .= $langs->trans("GenericMaskCodes5");
     // Parametrage du prefix customers
     $texte .= '<tr><td>' . $langs->trans("Mask") . ' (' . $langs->trans("CustomerCodeModel") . '):</td>';
     $texte .= '<td align="right">' . $form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="' . $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER . '"' . $disabled . '>', $tooltip, 1, 1) . '</td>';
     $texte .= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button"' . $disabled . '></td>';
     $texte .= '</tr>';
     // Parametrage du prefix suppliers
     $texte .= '<tr><td>' . $langs->trans("Mask") . ' (' . $langs->trans("SupplierCodeModel") . '):</td>';
     $texte .= '<td align="right">' . $form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="' . $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER . '"' . $disabled . '>', $tooltip, 1, 1) . '</td>';
     $texte .= '</tr>';
     $texte .= '</table>';
     $texte .= '</form>';
     return $texte;
 }
 /**		Return description of module
  *
  * 		@param	Translate 		$langs		Object langs
  * 		@return string      			Description of module
  */
 function info($langs)
 {
     global $conf, $mc;
     global $form;
     $langs->load("products");
     $disabled = !empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity ? ' disabled="disabled"' : '';
     $texte = $langs->trans('GenericNumRefModelDesc') . "<br>\n";
     $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
     $texte .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
     $texte .= '<input type="hidden" name="param1" value="BARCODE_STANDARD_PRODUCT_MASK">';
     $texte .= '<table class="nobordernopadding" width="100%">';
     $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode"));
     $tooltip .= $langs->trans("GenericMaskCodes3");
     $tooltip .= $langs->trans("GenericMaskCodes4c");
     $tooltip .= $langs->trans("GenericMaskCodes5");
     // Mask parameter
     //$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("BarCodeModel").'):</td>';
     $texte .= '<tr><td>' . $langs->trans("Mask") . ':</td>';
     $texte .= '<td align="right">' . $form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="' . (!empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK) ? $conf->global->BARCODE_STANDARD_PRODUCT_MASK : '') . '"' . $disabled . '>', $tooltip, 1, 1) . '</td>';
     $texte .= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button"' . $disabled . '></td>';
     $texte .= '</tr>';
     $texte .= '</table>';
     $texte .= '</form>';
     return $texte;
 }
Exemplo n.º 4
0
/**
 * Show footer of company in HTML pages
 *
 * @param   Societe		$fromcompany	Third party
 * @param   Translate	$langs			Output language
 * @return	void
 */
function html_print_paybox_footer($fromcompany,$langs)
{
	global $conf;

	// Juridical status
	$line1="";
	if ($fromcompany->forme_juridique_code)
	{
		$line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
	}
	// Capital
	if ($fromcompany->capital)
	{
		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
	}
	// Prof Id 1
	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
	{
		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
	}
	// Prof Id 2
	if ($fromcompany->idprof2)
	{
		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
	}

	// Second line of company infos
	$line2="";
	// Prof Id 3
	if ($fromcompany->idprof3)
	{
		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
	}
	// Prof Id 4
	if ($fromcompany->idprof4)
	{
		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
	}
	// IntraCommunautary VAT
	if ($fromcompany->tva_intra != '')
	{
		$line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
	}

	print '<br><br><hr>'."\n";
	print '<center><font style="font-size: 10px;">'."\n";
	print $fromcompany->nom.'<br>';
	print $line1.'<br>';
	print $line2;
	print '</font></center>'."\n";
}
Exemplo n.º 5
0
/**
 * 	Return linked objects
 *
 * 	@param	object		$object			Object
 * 	@param	Translate	$outputlangs	Object lang for output
 * 	@return	array   Linked objects
 */
function pdf_getLinkedObjects($object, $outputlangs)
{
    global $hookmanager;
    $linkedobjects = array();
    $object->fetchObjectLinked();
    foreach ($object->linkedObjects as $objecttype => $objects) {
        if ($objecttype == 'propal') {
            $outputlangs->load('propal');
            foreach ($objects as $elementobject) {
                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
                $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
                $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
            }
        } else {
            if ($objecttype == 'commande') {
                $outputlangs->load('orders');
                foreach ($objects as $elementobject) {
                    $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
                    $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' (' . $elementobject->ref_client . ')' : '');
                    $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
                    $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
                }
            } else {
                if ($objecttype == 'contrat') {
                    $outputlangs->load('contracts');
                    foreach ($objects as $elementobject) {
                        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
                        $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
                        $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
                        $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat, 'day', '', $outputlangs);
                    }
                } else {
                    if ($objecttype == 'shipping') {
                        $outputlangs->load('orders');
                        $outputlangs->load('sendings');
                        foreach ($objects as $elementobject) {
                            $elementobject->fetchObjectLinked();
                            $order = $elementobject->linkedObjects['commande'][0];
                            if (!empty($object->linkedObjects['commande'])) {
                                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
                                $linkedobjects[$objecttype]['ref_value'] .= $outputlangs->transnoentities($elementobject->ref);
                                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateSending");
                                $linkedobjects[$objecttype]['date_value'] .= dol_print_date($elementobject->date_delivery, 'day', '', $outputlangs);
                            } else {
                                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
                                $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' (' . $order->ref_client . ')' : '');
                                $linkedobjects[$objecttype]['ref_value'] .= ' / ' . $outputlangs->transnoentities($elementobject->ref);
                                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ' / ' . $outputlangs->transnoentities("DateSending");
                                $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date, 'day', '', $outputlangs);
                                $linkedobjects[$objecttype]['date_value'] .= ' / ' . dol_print_date($elementobject->date_delivery, 'day', '', $outputlangs);
                            }
                        }
                    }
                }
            }
        }
    }
    // For add external linked objects
    if (is_object($hookmanager)) {
        $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs' => $outputlangs);
        $action = '';
        $hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action);
        // Note that $action and $object may have been modified by some hooks
        if (!empty($hookmanager->resArray)) {
            $linkedobjects = $hookmanager->resArray;
        }
    }
    return $linkedobjects;
}
/**
 * 	Send email
 *
 * 	@param	string	$mode					Mode (test | confirm)
 *  @param	string	$oldemail				Old email
 * 	@param	string	$message				Message to send
 * 	@param	string	$total					Total amount of unpayed invoices
 *  @param	string	$userlang				Code lang to use for email output.
 *  @param	string	$oldsalerepresentative	Old sale representative
 * 	@return	int								<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
    } else {
        $allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $newlangs, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
Exemplo n.º 7
0
 /**
  *	Output record line into file
  *
  *  @param     	array		$array_selected_sorted      Array with list of field to export
  *  @param     	resource	$objp                       A record from a fetch with all fields from select
  *  @param     	Translate	$outputlangs    			Object lang to translate values
  *  @param		array		$array_types				Array with types of fields
  * 	@return		int										<0 if KO, >0 if OK
  */
 function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
 {
     global $conf;
     if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) {
         $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
     } else {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $this->col = 0;
     foreach ($array_selected_sorted as $code => $value) {
         if (strpos($code, ' as ') == 0) {
             $alias = str_replace(array('.', '-'), '_', $code);
         } else {
             $alias = substr($code, strpos($code, ' as ') + 4);
         }
         if (empty($alias)) {
             dol_print_error('', 'Bad value for field with key=' . $code . '. Try to redefine export.');
         }
         $newvalue = $outputlangs->convToOutputCharset($objp->{$alias});
         // objp->$alias must be utf8 encoded as any var in memory	// newvalue is now $outputlangs->charset_output encoded
         $typefield = isset($array_types[$code]) ? $array_types[$code] : '';
         // Translation newvalue
         if (preg_match('/^\\((.*)\\)$/i', $newvalue, $reg)) {
             $newvalue = $outputlangs->transnoentities($reg[1]);
         }
         $newvalue = $this->csv_clean($newvalue, $outputlangs->charset_output);
         if (preg_match('/^Select:/i', $typefield, $reg) && ($typefield = substr($typefield, 7))) {
             $array = unserialize($typefield);
             $array = $array['options'];
             $newvalue = $array[$newvalue];
         }
         fwrite($this->handle, $newvalue . $this->separator);
         $this->col++;
     }
     fwrite($this->handle, "\n");
     return 0;
 }
 /**
  * Function called when a Dolibarrr business event is done.
  * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  *
  * @param string		$action		Event action code
  * @param Object		$object     Object
  * @param User			$user       Object user
  * @param Translate		$langs      Object langs
  * @param conf			$conf       Object conf
  * @return int         				<0 if KO, 0 if no triggered ran, >0 if OK
  */
 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
 {
     if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) {
         return 0;
     }
     // Log events is disabled (hidden features)
     $key = 'MAIN_LOGEVENTS_' . $action;
     //dol_syslog("xxxxxxxxxxx".$key);
     if (empty($conf->global->{$key})) {
         return 0;
     }
     // Log events not enabled for this action
     if (empty($conf->entity)) {
         $conf->entity = $entity;
     }
     // forcing of the entity if it's not defined (ex: in login form)
     $date = dol_now();
     // Actions
     if ($action == 'USER_LOGIN') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = "(UserLogged," . $object->login . ")";
         $text .= empty($object->trigger_mesg) ? '' : ' - ' . $object->trigger_mesg;
         $desc = "(UserLogged," . $object->login . ")";
         $desc .= empty($object->trigger_mesg) ? '' : ' - ' . $object->trigger_mesg;
     }
     if ($action == 'USER_LOGIN_FAILED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = $object->trigger_mesg;
         // Message direct
         $desc = $object->trigger_mesg;
         // Message direct
     }
     if ($action == 'USER_LOGOUT') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = "(UserLogoff," . $object->login . ")";
         $desc = "(UserLogoff," . $object->login . ")";
     }
     if ($action == 'USER_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewUserCreated", $object->login);
         $desc = $langs->transnoentities("NewUserCreated", $object->login);
     } elseif ($action == 'USER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("EventUserModified", $object->login);
         $desc = $langs->transnoentities("EventUserModified", $object->login);
     } elseif ($action == 'USER_NEW_PASSWORD') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewUserPassword", $object->login);
         $desc = $langs->transnoentities("NewUserPassword", $object->login);
     } elseif ($action == 'USER_ENABLEDISABLE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         if ($object->statut == 0) {
             $text = $langs->transnoentities("UserEnabled", $object->login);
             $desc = $langs->transnoentities("UserEnabled", $object->login);
         }
         if ($object->statut == 1) {
             $text = $langs->transnoentities("UserDisabled", $object->login);
             $desc = $langs->transnoentities("UserDisabled", $object->login);
         }
     } elseif ($action == 'USER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("UserDeleted", $object->login);
         $desc = $langs->transnoentities("UserDeleted", $object->login);
     } elseif ($action == 'GROUP_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewGroupCreated", $object->name);
         $desc = $langs->transnoentities("NewGroupCreated", $object->name);
     } elseif ($action == 'GROUP_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("GroupModified", $object->name);
         $desc = $langs->transnoentities("GroupModified", $object->name);
     } elseif ($action == 'GROUP_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("GroupDeleted", $object->name);
         $desc = $langs->transnoentities("GroupDeleted", $object->name);
     }
     // If not found
     /*
             else
             {
                 dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return 0;
             }
     */
     // Add entry in event table
     include_once DOL_DOCUMENT_ROOT . '/core/class/events.class.php';
     $event = new Events($this->db);
     $event->type = $action;
     $event->dateevent = $date;
     $event->label = $text;
     $event->description = $desc;
     $event->user_agent = $_SERVER["HTTP_USER_AGENT"];
     $result = $event->create($user);
     if ($result > 0) {
         return 1;
     } else {
         $error = "Failed to insert security event: " . $event->error;
         $this->error = $error;
         dol_syslog(get_class($this) . ": " . $this->error, LOG_ERR);
         return -1;
     }
     return 0;
 }
/**
 * 	Send email
 *
 * 	@param	string	$mode			Mode (test | confirm)
 *  @param	string	$oldemail		Target email
 * 	@param	string	$message		Message to send
 * 	@param	string	$total			Total amount of unpayed invoices
 *  @param	string	$userlang		Code lang to use for email output.
 *  @param	string	$oldtarget		Target name
 *  @param  int		$duration_value	duration value
 * 	@return	int						<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget, $duration_value)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("contracts");
    if ($duration_value) {
        if ($duration_value > 0) {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDuration", $duration_value);
        } else {
            $title = $newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg", $duration_value);
        }
    } else {
        $title = $newlangs->transnoentities("ListOfServicesToExpire");
    }
    $subject = empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT) ? $title : $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email to '" . $oldtarget . "' (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_expire_services_to_customers.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer" . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the services contracted by you that are about to expire." . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    //$allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
    if (!empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_CUSTOMERS_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}
Exemplo n.º 10
0
/**
 *	Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remontee des bugs.
 *	On doit appeler cette fonction quand une erreur technique bloquante est rencontree.
 *	Toutefois, il faut essayer de ne l'appeler qu'au sein de pages php, les classes devant
 *	renvoyer leur erreur par l'intermediaire de leur propriete "error".
 *	@param      db      	Database handler
 *	@param      error		String or array of errors strings to show
 *  @see        dol_htmloutput_errors
 */
function dol_print_error($db = '', $error = '')
{
    global $conf, $langs, $argv;
    global $dolibarr_main_prod;
    $out = '';
    $syslog = '';
    // Si erreur intervenue avant chargement langue
    if (!$langs) {
        require_once DOL_DOCUMENT_ROOT . "/core/class/translate.class.php";
        $langs = new Translate("", $conf);
        $langs->load("main");
    }
    $langs->load("main");
    $langs->load("errors");
    if ($_SERVER['DOCUMENT_ROOT']) {
        $out .= $langs->trans("DolibarrHasDetectedError") . ".<br>\n";
        if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
            $out .= "You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.<br>\n";
        }
        $out .= $langs->trans("InformationToHelpDiagnose") . ":<br>\n";
        $out .= "<b>" . $langs->trans("Date") . ":</b> " . dol_print_date(time(), 'dayhourlog') . "<br>\n";
        $out .= "<b>" . $langs->trans("Dolibarr") . ":</b> " . DOL_VERSION . "<br>\n";
        if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
            $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . $conf->global->MAIN_FEATURES_LEVEL . "<br>\n";
        }
        if (function_exists("phpversion")) {
            $out .= "<b>" . $langs->trans("PHP") . ":</b> " . phpversion() . "<br>\n";
            //phpinfo();       // This is to show location of php.ini file
        }
        $out .= "<b>" . $langs->trans("Server") . ":</b> " . $_SERVER["SERVER_SOFTWARE"] . "<br>\n";
        $out .= "<br>\n";
        $out .= "<b>" . $langs->trans("RequestedUrl") . ":</b> " . $_SERVER["REQUEST_URI"] . "<br>\n";
        $out .= "<b>" . $langs->trans("Referer") . ":</b> " . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '') . "<br>\n";
        $out .= "<b>" . $langs->trans("MenuManager") . ":</b> " . $conf->top_menu . "<br>\n";
        $out .= "<br>\n";
        $syslog .= "url=" . $_SERVER["REQUEST_URI"];
        $syslog .= ", query_string=" . $_SERVER["QUERY_STRING"];
    } else {
        $out .= '> ' . $langs->transnoentities("ErrorInternalErrorDetected") . ":\n" . $argv[0] . "\n";
        $syslog .= "pid=" . getmypid();
    }
    if (is_object($db)) {
        if ($_SERVER['DOCUMENT_ROOT']) {
            $out .= "<b>" . $langs->trans("DatabaseTypeManager") . ":</b> " . $db->type . "<br>\n";
            $out .= "<b>" . $langs->trans("RequestLastAccessInError") . ":</b> " . ($db->lastqueryerror() ? $db->lastqueryerror() : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
            $out .= "<b>" . $langs->trans("ReturnCodeLastAccessInError") . ":</b> " . ($db->lasterrno() ? $db->lasterrno() : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
            $out .= "<b>" . $langs->trans("InformationLastAccessInError") . ":</b> " . ($db->lasterror() ? $db->lasterror() : $langs->trans("ErrorNoRequestInError")) . "<br>\n";
            $out .= "<br>\n";
        } else {
            $out .= '> ' . $langs->transnoentities("DatabaseTypeManager") . ":\n" . $db->type . "\n";
            $out .= '> ' . $langs->transnoentities("RequestLastAccessInError") . ":\n" . ($db->lastqueryerror() ? $db->lastqueryerror() : $langs->trans("ErrorNoRequestInError")) . "\n";
            $out .= '> ' . $langs->transnoentities("ReturnCodeLastAccessInError") . ":\n" . ($db->lasterrno() ? $db->lasterrno() : $langs->trans("ErrorNoRequestInError")) . "\n";
            $out .= '> ' . $langs->transnoentities("InformationLastAccessInError") . ":\n" . ($db->lasterror() ? $db->lasterror() : $langs->trans("ErrorNoRequestInError")) . "\n";
        }
        $syslog .= ", sql=" . $db->lastquery();
        $syslog .= ", db_error=" . $db->lasterror();
    }
    if ($error) {
        $langs->load("errors");
        if (is_array($error)) {
            $errors = $error;
        } else {
            $errors = array($error);
        }
        foreach ($errors as $msg) {
            $msg = $langs->trans($msg);
            if ($_SERVER['DOCUMENT_ROOT']) {
                $out .= "<b>" . $langs->trans("Message") . ":</b> " . $msg . "<br>\n";
            } else {
                $out .= '> ' . $langs->transnoentities("Message") . ":\n" . $msg . "\n";
            }
            $syslog .= ", msg=" . $msg;
        }
    }
    if (empty($dolibarr_main_prod) && $_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_call_file')) {
        xdebug_print_function_stack();
        $out .= '<b>XDebug informations:</b>' . "<br>\n";
        $out .= 'File: ' . xdebug_call_file() . "<br>\n";
        $out .= 'Line: ' . xdebug_call_line() . "<br>\n";
        $out .= 'Function: ' . xdebug_call_function() . "<br>\n";
        $out .= "<br>\n";
    }
    if (empty($dolibarr_main_prod)) {
        print $out;
    } else {
        define("MAIN_CORE_ERROR", 1);
    }
    //else print 'Sorry, an error occured but the parameter $dolibarr_main_prod is defined in conf file so no message is reported to your browser. Please read the log file for error message.';
    dol_syslog("Error " . $syslog, LOG_ERR);
}
Exemplo n.º 11
0
 /**
  *	Output record line into file
  *
  *  @param     	array		$array_selected_sorted      Array with list of field to export
  *  @param     	resource	$objp                       A record from a fetch with all fields from select
  *  @param     	Translate	$outputlangs    			Object lang to translate values
  * 	@return		int										<0 if KO, >0 if OK
  */
 function write_record($array_selected_sorted, $objp, $outputlangs)
 {
     global $conf;
     if (!empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) {
         $outputlangs->charset_output = $conf->global->EXPORT_CSV_FORCE_CHARSET;
     } else {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $this->col = 0;
     foreach ($array_selected_sorted as $code => $value) {
         $alias = str_replace(array('.', '-'), '_', $code);
         if (empty($alias)) {
             dol_print_error('', 'Bad value for field with key=' . $code . '. Try to redefine export.');
         }
         $newvalue = $outputlangs->convToOutputCharset($objp->{$alias});
         // Translation newvalue
         if (preg_match('/^\\((.*)\\)$/i', $newvalue, $reg)) {
             $newvalue = $outputlangs->transnoentities($reg[1]);
         }
         $newvalue = $this->csv_clean($newvalue, $outputlangs->charset_output);
         fwrite($this->handle, $newvalue . $this->separator);
         $this->col++;
     }
     fwrite($this->handle, "\n");
     return 0;
 }
Exemplo n.º 12
0
/**
 *	Returns formated reduction
 *
 *	@param	int			$reduction		Reduction percentage
 *	@param	Translate	$langs			Output language
 *	@return	string						Formated reduction
 */
function dol_print_reduction($reduction, $langs)
{
    $string = '';
    if ($reduction == 100) {
        $string = $langs->transnoentities("Offered");
    } else {
        $string = $reduction . '%';
    }
    return $string;
}
Exemplo n.º 13
0
/**
 * 	Return linked objects
 *
 * 	@param	object		$object			Object
 * 	@param	Translate	$outputlangs	Object lang for output
 *	@param	HookManager	$hookmanager	Hook manager instance
 * 	@return	void
 */
function pdf_getLinkedObjects($object, $outputlangs, $hookmanager = false)
{
    $linkedobjects = array();
    $object->fetchObjectLinked();
    foreach ($object->linkedObjects as $objecttype => $objects) {
        if ($objecttype == 'propal') {
            $outputlangs->load('propal');
            $num = count($objects);
            for ($i = 0; $i < $num; $i++) {
                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
                $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($objects[$i]->ref);
                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
                $linkedobjects[$objecttype]['date_value'] = dol_print_date($objects[$i]->date, 'day', '', $outputlangs);
            }
        } else {
            if ($objecttype == 'commande') {
                $outputlangs->load('orders');
                $num = count($objects);
                for ($i = 0; $i < $num; $i++) {
                    $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
                    $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($objects[$i]->ref) . ($objects[$i]->ref_client ? ' (' . $objects[$i]->ref_client . ')' : '');
                    $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
                    $linkedobjects[$objecttype]['date_value'] = dol_print_date($objects[$i]->date, 'day', '', $outputlangs);
                }
            } else {
                if ($objecttype == 'contrat') {
                    $outputlangs->load('contracts');
                    $num = count($objects);
                    for ($i = 0; $i < $num; $i++) {
                        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
                        $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($objects[$i]->ref);
                        $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
                        $linkedobjects[$objecttype]['date_value'] = dol_print_date($objects[$i]->date_contrat, 'day', '', $outputlangs);
                    }
                }
            }
        }
    }
    // For add external linked objects
    if (is_object($hookmanager)) {
        $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs' => $outputlangs);
        $action = '';
        $hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action);
        // Note that $action and $object may have been modified by some hooks
        if (!empty($hookmanager->resArray)) {
            $linkedobjects = $hookmanager->resArray;
        }
    }
    return $linkedobjects;
}
 /**
  * Function called when a Dolibarrr business event is done.
  * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  *
  * Following properties must be filled:
  *      $object->actiontypecode (translation action code: AC_OTH, ...)
  *      $object->actionmsg (note, long text)
  *      $object->actionmsg2 (label, short text)
  *      $object->sendtoid (id of contact)
  *      $object->socid
  *      Optionnal:
  *      $object->fk_element
  *      $object->elementtype
  *
  * @param string		$action		Event action code
  * @param Object		$object     Object
  * @param User		    $user       Object user
  * @param Translate 	$langs      Object langs
  * @param conf		    $conf       Object conf
  * @return int         				<0 if KO, 0 if no triggered ran, >0 if OK
  */
 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
 {
     // Module not active, we do nothing
     if (empty($conf->agenda->enabled)) {
         return 0;
     }
     $key = 'MAIN_AGENDA_ACTIONAUTO_' . $action;
     // Do not log events not enabled for this action
     if (empty($conf->global->{$key})) {
         return 0;
     }
     $langs->load("agenda");
     // Actions
     if ($action == 'COMPANY_CREATE') {
         $langs->load("other");
         $langs->load("companies");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
         }
         $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->name);
         if (!empty($object->prefix)) {
             $object->actionmsg .= " (" . $object->prefix . ")";
         }
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->socid = $object->id;
     } elseif ($action == 'COMPANY_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("orders");
         if (empty($object->actiontypecode)) {
             $object->actiontypecode = 'AC_OTH_AUTO';
         }
         if (empty($object->actionmsg2)) {
             dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR);
         }
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'CONTRACT_VALIDATE') {
         $langs->load("other");
         $langs->load("contracts");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'PROPAL_VALIDATE') {
         $langs->load("other");
         $langs->load("propal");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'PROPAL_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("propal");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
         $langs->load("other");
         $langs->load("propal");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'PROPAL_CLASSIFY_BILLED') {
         $langs->load("other");
         $langs->load("propal");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
         $langs->load("other");
         $langs->load("propal");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_VALIDATE') {
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_CLOSE') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_CLASSIFY_BILLED') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_CANCEL') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'BILL_VALIDATE') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_UNVALIDATE') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'BILL_PAYED') {
         $langs->load("other");
         $langs->load("bills");
         // Values for this action can't be defined by caller.
         $object->actiontypecode = 'AC_OTH_AUTO';
         $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_CANCEL') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'FICHINTER_CREATE') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionCreatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
     } elseif ($action == 'FICHINTER_VALIDATE') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
     } elseif ($action == 'FICHINTER_MODIFY') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionModifiedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
     } elseif ($action == 'FICHINTER_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'FICHINTER_DELETE') {
         $langs->load("other");
         $langs->load("interventions");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionDeletedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
     } elseif ($action == 'SHIPPING_VALIDATE') {
         $langs->load("other");
         $langs->load("sendings");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ShippingValidated", $object->newref ? $object->newref : $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ShippingValidated", $object->newref ? $object->newref : $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'SHIPPING_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("sendings");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_SUPPLIER_APPROVE') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_SUPPLIER_REFUSE') {
         $langs->load("other");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("bills");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
         $langs->load("other");
         $langs->load("bills");
         $langs->load("orders");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
     } elseif ($action == 'BILL_SUPPLIER_PAYED') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
         $langs->load("other");
         $langs->load("bills");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'MEMBER_VALIDATE') {
         $langs->load("other");
         $langs->load("members");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->newref ? $object->newref : $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'MEMBER_SUBSCRIPTION') {
         $langs->load("other");
         $langs->load("members");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Amount") . ': ' . $object->last_subscription_amount;
         $object->actionmsg .= "\n" . $langs->transnoentities("Period") . ': ' . dol_print_date($object->last_subscription_date_start, 'day') . ' - ' . dol_print_date($object->last_subscription_date_end, 'day');
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'MEMBER_RESILIATE') {
         $langs->load("other");
         $langs->load("members");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'MEMBER_DELETE') {
         $langs->load("other");
         $langs->load("members");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'PROJECT_CREATE') {
         $langs->load("other");
         $langs->load("projects");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("ProjectCreatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Project") . ': ' . $object->ref;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'TASK_CREATE') {
         $langs->load("other");
         $langs->load("projects");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("TaskCreatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Task") . ': ' . $object->ref;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'TASK_MODIFY') {
         $langs->load("other");
         $langs->load("projects");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("TaskModifiedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("TaskModifieddInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Task") . ': ' . $object->ref;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } elseif ($action == 'TASK_DELETE') {
         $langs->load("other");
         $langs->load("projects");
         $object->actiontypecode = 'AC_OTH_AUTO';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("TaskDeletedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Task") . ': ' . $object->ref;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
     } else {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' was ran by " . __FILE__ . " but no handler found for this action.", LOG_WARNING);
         return 0;
     }
     dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
     // Add entry in event table
     $now = dol_now();
     if (isset($_SESSION['listofnames'])) {
         $attachs = $_SESSION['listofnames'];
         if ($attachs && strpos($action, 'SENTBYMAIL')) {
             $object->actionmsg .= "\n" . $langs->transnoentities("AttachedFiles") . ': ' . $attachs;
         }
     }
     require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
     require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
     $contactforaction = new Contact($this->db);
     $societeforaction = new Societe($this->db);
     if ($object->sendtoid > 0) {
         $contactforaction->fetch($object->sendtoid);
     }
     if ($object->socid > 0) {
         $societeforaction->fetch($object->socid);
     }
     // Insertion action
     require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
     $actioncomm = new ActionComm($this->db);
     $actioncomm->type_code = $object->actiontypecode;
     // code of parent table llx_c_actioncomm (will be deprecated)
     $actioncomm->code = 'AC_' . $action;
     $actioncomm->label = $object->actionmsg2;
     $actioncomm->note = $object->actionmsg;
     $actioncomm->datep = $now;
     $actioncomm->datef = $now;
     $actioncomm->durationp = 0;
     $actioncomm->punctual = 1;
     $actioncomm->percentage = -1;
     // Not applicable
     $actioncomm->societe = $societeforaction;
     $actioncomm->contact = $contactforaction;
     $actioncomm->socid = $societeforaction->id;
     $actioncomm->contactid = $contactforaction->id;
     $actioncomm->authorid = $user->id;
     // User saving action
     $actioncomm->userownerid = $user->id;
     // Owner of action
     //$actioncomm->userdone    = $user;	    // User doing action (not used anymore)
     //$actioncomm->userdoneid  = $user->id;	// User doing action (not used anymore)
     $actioncomm->fk_element = $object->id;
     $actioncomm->elementtype = $object->element;
     $ret = $actioncomm->add($user);
     // User qui saisit l'action
     unset($object->actionmsg);
     unset($object->actionmsg2);
     unset($object->actiontypecode);
     // When several action are called on same object, we must be sure to not reuse vallue of first action.
     if ($ret > 0) {
         $_SESSION['LAST_ACTION_CREATED'] = $ret;
         return 1;
     } else {
         $error = "Failed to insert event : " . $actioncomm->error . " " . join(',', $actioncomm->errors);
         $this->error = $error;
         $this->errors = $actioncomm->errors;
         dol_syslog("interface_modAgenda_ActionsAuto.class.php: " . $this->error, LOG_ERR);
         return -1;
     }
     return 0;
 }
Exemplo n.º 15
0
 /**
  * 	Output record line into file
  *
  *  @param      array		$array_selected_sorted      Array with list of field to export
  *  @param      resource	$objp                       A record from a fetch with all fields from select
  *  @param      Translate	$outputlangs                Object lang to translate values
  * 	@return		int										<0 if KO, >0 if OK
  */
 function write_record($array_selected_sorted, $objp, $outputlangs)
 {
     $this->col = 0;
     foreach ($array_selected_sorted as $code => $value) {
         $alias = str_replace(array('.', '-'), '_', $code);
         if (empty($alias)) {
             dol_print_error('', 'Bad value for field with code=' . $code . '. Try to redefine export.');
         }
         $newvalue = $objp->{$alias};
         // Translation newvalue
         if (preg_match('/^\\((.*)\\)$/i', $newvalue, $reg)) {
             $newvalue = $outputlangs->transnoentities($reg[1]);
         }
         $newvalue = $this->tsv_clean($newvalue);
         fwrite($this->handle, $newvalue . $this->separator);
         $this->col++;
     }
     fwrite($this->handle, "\n");
     return 0;
 }
 /**
  *      Function called when a Dolibarrr business event is done.
  *      All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  *
  *      Following properties must be filled:
  *      $object->actiontypecode (translation action code: AC_OTH, ...)
  *      $object->actionmsg (note, long text)
  *      $object->actionmsg2 (label, short text)
  *      $object->sendtoid (id of contact)
  *      $object->socid
  *      Optionnal:
  *      $object->fk_element
  *      $object->elementtype
  *
  *      @param	string		$action		Event action code
  *      @param  Object		$object     Object
  *      @param  User		$user       Object user
  *      @param  Translate	$langs      Object langs
  *      @param  conf		$conf       Object conf
  *      @return int         			<0 if KO, 0 if no triggered ran, >0 if OK
  */
 function run_trigger($action, $object, $user, $langs, $conf)
 {
     $key = 'MAIN_AGENDA_ACTIONAUTO_' . $action;
     //dol_syslog("xxxxxxxxxxx".$key);
     if (empty($conf->agenda->enabled)) {
         return 0;
     }
     // Module not active, we do nothing
     if (empty($conf->global->{$key})) {
         return 0;
     }
     // Log events not enabled for this action
     $ok = 0;
     // Actions
     if ($action == 'COMPANY_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->nom);
         }
         $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->nom);
         if ($object->prefix) {
             $object->actionmsg .= " (" . $object->prefix . ")";
         }
         //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client);
         //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->socid = $object->id;
         $ok = 1;
     } elseif ($action == 'CONTRACT_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("contracts");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_PAYED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_CANCEL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'FICHEINTER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("interventions");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
         $ok = 1;
     } elseif ($action == 'FICHEINTER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("interventions");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         // Parameters $object->sendotid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'SHIPPING_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("sendings");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_SHIP';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $langs->load("orders");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendotid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $langs->load("orders");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_PAYED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_SUBSCRIPTION') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Amount") . ': ' . $object->last_subscription_amount;
         $object->actionmsg .= "\n" . $langs->transnoentities("Period") . ': ' . dol_print_date($object->last_subscription_date_start, 'day') . ' - ' . dol_print_date($object->last_subscription_date_end, 'day');
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
     } elseif ($action == 'MEMBER_RESILIATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     }
     // If not found
     /*
     else
     {
         dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return 0;
     }
     */
     // Add entry in event table
     if ($ok) {
         $now = dol_now();
         require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
         require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
         $contactforaction = new Contact($this->db);
         $societeforaction = new Societe($this->db);
         if ($object->sendtoid > 0) {
             $contactforaction->fetch($object->sendtoid);
         }
         if ($object->socid > 0) {
             $societeforaction->fetch($object->socid);
         }
         // Insertion action
         require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
         $actioncomm = new ActionComm($this->db);
         $actioncomm->type_code = $object->actiontypecode;
         $actioncomm->label = $object->actionmsg2;
         $actioncomm->note = $object->actionmsg;
         $actioncomm->datep = $now;
         $actioncomm->datef = $now;
         $actioncomm->durationp = 0;
         $actioncomm->punctual = 1;
         $actioncomm->percentage = -1;
         // Not applicable
         $actioncomm->contact = $contactforaction;
         $actioncomm->societe = $societeforaction;
         $actioncomm->author = $user;
         // User saving action
         //$actioncomm->usertodo  = $user;	// User affected to action
         $actioncomm->userdone = $user;
         // User doing action
         $actioncomm->fk_element = $object->id;
         $actioncomm->elementtype = $object->element;
         $ret = $actioncomm->add($user);
         // User qui saisit l'action
         if ($ret > 0) {
             return 1;
         } else {
             $error = "Failed to insert : " . $actioncomm->error . " ";
             $this->error = $error;
             dol_syslog("interface_modAgenda_ActionsAuto.class.php: " . $this->error, LOG_ERR);
             return -1;
         }
     }
     return 0;
 }
Exemplo n.º 17
0
 /**
  *  Check if notification are active for couple action/company.
  * 	If yes, send mail and save trace into llx_notify.
  *
  * 	@param	string	$notifcode		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  * 	@param	Object	$object			Object the notification deals on
  *	@return	int						<0 if KO, or number of changes if OK
  */
 function send($notifcode, $object)
 {
     global $user, $conf, $langs, $mysoc, $dolibarr_main_url_root;
     include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     dol_syslog(get_class($this) . "::send notifcode=" . $notifcode . ", object=" . $object->id);
     $langs->load("other");
     // Define $urlwithroot
     $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
     $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
     // This is to use external domain name found into config file
     //$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
     // Define some vars
     $application = $mysoc->name;
     //if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
     $replyto = $conf->notification->email_from;
     $filename = basename($file);
     $mimefile = dol_mimetype($file);
     $object_type = '';
     $link = '';
     $num = 0;
     if (!in_array($notifcode, array('BILL_VALIDATE', 'ORDER_VALIDATE', 'PROPAL_VALIDATE', 'FICHINTER_VALIDATE', 'ORDER_SUPPLIER_VALIDATE', 'ORDER_SUPPLIER_APPROVE', 'ORDER_SUPPLIER_REFUSE', 'SHIPPING_VALIDATE'))) {
         return 0;
     }
     $oldref = empty($object->oldref) ? $object->ref : $object->oldref;
     $newref = empty($object->newref) ? $object->ref : $object->newref;
     // Check notification per third party
     $sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,";
     $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type";
     $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,";
     $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,";
     $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
     $sql .= " " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
     $sql .= " AND n.fk_soc = s.rowid";
     if (is_numeric($notifcode)) {
         $sql .= " AND n.fk_action = " . $notifcode;
     } else {
         $sql .= " AND a.code = '" . $notifcode . "'";
     }
     // New usage
     $sql .= " AND s.rowid = " . $object->socid;
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         if ($num > 0) {
             $i = 0;
             while ($i < $num && !$error) {
                 $obj = $this->db->fetch_object($result);
                 $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">";
                 $notifcodedefid = $obj->adid;
                 if (dol_strlen($obj->email)) {
                     // Set output language
                     $outputlangs = $langs;
                     if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) {
                         $outputlangs = new Translate('', $conf);
                         $outputlangs->setDefaultLang($obj->default_lang);
                     }
                     switch ($notifcode) {
                         case 'BILL_VALIDATE':
                             $link = '/compta/facture.php?facid=' . $object->id;
                             $dir_output = $conf->facture->dir_output;
                             $object_type = 'facture';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref);
                             break;
                         case 'ORDER_VALIDATE':
                             $link = '/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->commande->dir_output;
                             $object_type = 'order';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref);
                             break;
                         case 'PROPAL_VALIDATE':
                             $link = '/comm/propal.php?id=' . $object->id;
                             $dir_output = $conf->propal->dir_output;
                             $object_type = 'propal';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref);
                             break;
                         case 'FICHINTER_VALIDATE':
                             $link = '/fichinter/card.php?id=' . $object->id;
                             $dir_output = $conf->facture->dir_output;
                             $object_type = 'ficheinter';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref);
                             break;
                         case 'ORDER_SUPPLIER_VALIDATE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $object->ref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'ORDER_SUPPLIER_APPROVE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'ORDER_SUPPLIER_REFUSE':
                             $link = '/fourn/commande/card.php?id=' . $object->id;
                             $dir_output = $conf->fournisseur->dir_output . '/commande/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                             $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs));
                             $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                             break;
                         case 'SHIPPING_VALIDATE':
                             $dir_output = $conf->expedition->dir_output . '/sending/';
                             $object_type = 'order_supplier';
                             $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
                             break;
                     }
                     $ref = dol_sanitizeFileName($newref);
                     $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf";
                     if (!dol_is_file($pdf_path)) {
                         // We can't add PDF as it is not generated yet.
                         $filepdf = '';
                     } else {
                         $filepdf = $pdf_path;
                     }
                     $subject = '[' . $application . '] ' . $outputlangs->transnoentitiesnoconv("DolibarrNotification");
                     $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
                     $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
                     $message .= "\n";
                     $message .= $mesg;
                     if ($link) {
                         $message = dol_concatdesc($message, $urlwithroot . $link);
                     }
                     $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1);
                     if ($mailfile->sendfile()) {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
                         $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", " . $obj->cid . ", '" . $obj->type . "', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($obj->email) . "')";
                         if (!$this->db->query($sql)) {
                             dol_print_error($this->db);
                         }
                     } else {
                         $error++;
                         $this->errors[] = $mailfile->error;
                     }
                 } else {
                     dol_syslog("No notification sent for " . $sendto . " because email is empty");
                 }
                 $i++;
             }
         } else {
             dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . $object->socid);
         }
     } else {
         $error++;
         $this->errors[] = $this->db->lasterror();
         return -1;
     }
     // Check notification using fixed email
     if (!$error) {
         foreach ($conf->global as $key => $val) {
             if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
                 continue;
             }
             $threshold = (double) $reg[1];
             if ($object->total_ht <= $threshold) {
                 dol_syslog("A notification is requested for notifcode = " . $notifcode . " but amount = " . $object->total_ht . " so lower than threshold = " . $threshold . ". We discard this notification");
                 continue;
             }
             $param = 'NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_' . $reg[1];
             $sendto = $conf->global->{$param};
             $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
             if ($notifcodedefid <= 0) {
                 dol_print_error($this->db, 'Failed to get id from code');
             }
             $object_type = '';
             $link = '';
             $num++;
             switch ($notifcode) {
                 case 'BILL_VALIDATE':
                     $link = '/compta/facture.php?facid=' . $object->id;
                     $dir_output = $conf->facture->dir_output;
                     $object_type = 'facture';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref);
                     break;
                 case 'ORDER_VALIDATE':
                     $link = '/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->commande->dir_output;
                     $object_type = 'order';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref);
                     break;
                 case 'PROPAL_VALIDATE':
                     $link = '/comm/propal.php?id=' . $object->id;
                     $dir_output = $conf->propal->dir_output;
                     $object_type = 'propal';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref);
                     break;
                 case 'FICHINTER_VALIDATE':
                     $link = '/fichinter/card.php?id=' . $object->id;
                     $dir_output = $conf->facture->dir_output;
                     $object_type = 'ficheinter';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref);
                     break;
                 case 'ORDER_SUPPLIER_VALIDATE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_APPROVE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_APPROVE2':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'ORDER_SUPPLIER_REFUSE':
                     $link = '/fourn/commande/card.php?id=' . $object->id;
                     $dir_output = $conf->fournisseur->dir_output . '/commande/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
                     $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs));
                     $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
                     break;
                 case 'SHIPPING_VALIDATE':
                     $dir_output = $conf->expedition->dir_output . '/sending/';
                     $object_type = 'order_supplier';
                     $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref);
                     break;
             }
             $ref = dol_sanitizeFileName($newref);
             $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf";
             if (!dol_is_file($pdf_path)) {
                 // We can't add PDF as it is not generated yet.
                 $filepdf = '';
             } else {
                 $filepdf = $pdf_path;
             }
             $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification");
             $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
             $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
             $message .= "\n";
             $message .= $mesg;
             if ($link) {
                 $message = dol_concatdesc($message, $urlwithroot . $link);
             }
             // Replace keyword __SUPERVISOREMAIL__
             if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {
                 $newval = '';
                 if ($user->fk_user > 0) {
                     $supervisoruser = new User($this->db);
                     $supervisoruser->fetch($user->fk_user);
                     if ($supervisoruser->email) {
                         $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>');
                     }
                 }
                 dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval);
                 $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
                 $sendto = preg_replace('/^[\\s,]+/', '', $sendto);
                 // Clean start of string
                 $sendto = preg_replace('/[\\s,]+$/', '', $sendto);
                 // Clean end of string
             }
             if ($sendto) {
                 $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1);
                 if ($mailfile->sendfile()) {
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)";
                     $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", null, 'email', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($conf->global->{$param}) . "')";
                     if (!$this->db->query($sql)) {
                         dol_print_error($this->db);
                     }
                 } else {
                     $error++;
                     $this->errors[] = $mailfile->error;
                 }
             }
         }
     }
     if (!$error) {
         return $num;
     } else {
         return -1 * $error;
     }
 }
Exemplo n.º 18
0
 /**
  *  Show top header of page.
  *
  *  @param	PDF			&$pdf     		Object PDF
  *  @param  int			$page	     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
 {
     global $langs;
     // Do not add the BACKGROUND as this is a report
     //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
     $title = $outputlangs->transnoentities("ListOfCustomerPayments");
     $title .= ' - ' . dol_print_date(dol_mktime(0, 0, 0, $this->month, 1, $this->year), "%B %Y", false, $outputlangs, true);
     $pdf->SetFont('', 'B', 12);
     $pdf->SetXY(10, 10);
     $pdf->MultiCell(200, 2, $title, 0, 'C');
     $pdf->SetFont('', '', 10);
     $pdf->SetXY(11, 16);
     $pdf->MultiCell(80, 2, $outputlangs->transnoentities("DateBuild") . " : " . dol_print_date(time(), "day", false, $outputlangs, true), 0, 'L');
     $pdf->SetXY(11, 22);
     $pdf->MultiCell(80, 2, $outputlangs->transnoentities("Page") . " : " . $page, 0, 'L');
     // Title line
     $pdf->SetXY(11, $this->tab_top + 2);
     $pdf->MultiCell(30, 2, 'Date');
     $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
     $pdf->SetXY(42, $this->tab_top + 2);
     $pdf->MultiCell(40, 2, $outputlangs->transnoentities("PaymentMode"), 0, 'L');
     $pdf->line(80, $this->tab_top, 80, $this->tab_top + $this->tab_height + 10);
     $pdf->SetXY(82, $this->tab_top + 2);
     $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Invoice"), 0, 'L');
     $pdf->line(120, $this->tab_top, 120, $this->tab_top + $this->tab_height + 10);
     $pdf->SetXY(122, $this->tab_top + 2);
     $pdf->MultiCell(40, 2, $outputlangs->transnoentities("AmountInvoice"), 0, 'L');
     $pdf->line(160, $this->tab_top, 160, $this->tab_top + $this->tab_height + 10);
     $pdf->SetXY(162, $this->tab_top + 2);
     $pdf->MultiCell(40, 2, $outputlangs->transnoentities("AmountPayment"), 0, 'L');
     $pdf->line(10, $this->tab_top + 10, 200, $this->tab_top + 10);
     $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
 }