load(self::GLOBAL_CONF_SEND_TO_EMAIL);
$emailFrom = $const->load(self::GLOBAL_CONF_EMAIL_FROM);
if (!empty($recipients) && !empty($emailFrom)) {
$emailTemplateHandler = new EmailTemplateHandler;
$template = $emailTemplateHandler->load(self::EMAIL_TEMPLATE);
$templateObject = new stdClass();
foreach ($template as $key => $value) {
$templateObject->$key = $value;
}
if ($templateObject) {
$vars = [
'__STATUS__ ' => $status,
'__TICKETID__' => $ticket_id,
];
$template = $emailTemplateHandler->prepareTemplate($templateObject, $vars);
$mail = new CMailFile(
$template->topic,
$recipients,
$emailFrom,
$template->content,
null,
null,
null,
'',
'',
0,
1
);
// Send Email
$mail->sendfile();
if ($mail->error) {
print_r($mail->error);
exit;
// do something...
dol_syslog('CRON ALERT EMAIL ERROR: ' . $mail->error, LOG_ERR);
}
}
}
}
/**
* Load object in memory from the database
*
* @param int $id Id object
* @param string $ref Ref
* @param string $morewhere More SQL filters (' AND ...')
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function fetchByWarehouse($id, $ref = null, $morewhere = '')
{
$result = $this->fetchCommon($id, $ref, $morewhere);
return $result;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return the status
*
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto, 6=Long label + Picto
* @return string Label of status
*/
public static function LibStatut($status, $mode = 0)
{
// phpcs:enable
global $langs;
global $db;
$statusObj = new Statuses($db);
$statuses = $statusObj::getStatusids($db);
$labelStatus = array();
$labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
$labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
$labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
foreach($statuses as $key => $val){
$labelStatus[$key] = $val;
$labelStatusShort[$key] = $val;
}
$labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
$labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
$labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
$statusType = 'status'.$status;
if ($status == self::STATUS_RECORDED) {
$statusType = 'status6';
}
return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
}
/**
* Function to show lines of extrafields with output datas.
* This function is responsible to output the
and | according to correct number of columns received into $params['colspan'] or according to $display_type
*
* @param Extrafields $extrafields Extrafield Object
* @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield
* @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
* @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
* @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
* @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example.
* @param string $display_type "card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
* @return string String with html content to show
*/
public function showOptionalsRollerstorage($inventory_id, $extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0, $display_type = 'card')
{
global $db, $conf, $langs, $action, $form, $hookmanager;
if (!is_object($form)) {
$form = new Form($db);
}
if (!is_object($extrafields)) {
dol_syslog('Bad parameter extrafields for showOptionals', LOG_ERR);
return 'Bad parameter extrafields for showOptionals';
}
if (!is_array($extrafields->attributes[$this->table_element])) {
dol_syslog("extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
}
$out = '';
$parameters = array();
$reshook = $hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook)) {
if (is_array($extrafields->attributes[$this->table_element]) && key_exists('label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) {
$out .= "\n";
$out .= ' ';
$out .= "\n";
$extrafields_collapse_num = '';
$e = 0;
foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $label) {
// Show only the key field in params
if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) {
continue;
}
// Test on 'enabled' ('enabled' is different than 'list' = 'visibility')
$enabled = 1;
if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key])) {
$enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1, 1, '1');
}
if (empty($enabled)) {
continue;
}
$visibility = 1;
if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key])) {
$visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1, 1, '1');
}
$perms = 1;
if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) {
$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1, 1, '1');
}
if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) {
continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
} elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) {
continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
} elseif ($mode == 'view' && empty($visibility)) {
continue;
}
if (empty($perms)) {
continue;
}
// Load language if required
if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
$langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
}
$colspan = 0;
if (is_array($params) && count($params) > 0 && $display_type == 'card') {
if (array_key_exists('cols', $params)) {
$colspan = $params['cols'];
} elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
$reg = array();
if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
$colspan = $reg[1];
} else {
$colspan = $params['colspan'];
}
}
}
$colspan = intval($colspan);
switch ($mode) {
case "view":
$value = ((!empty($this->array_options) && array_key_exists("options_" . $key . $keysuffix, $this->array_options)) ? $this->array_options["options_" . $key . $keysuffix] : null); // Value may be cleaned or formated later
break;
case "create":
case "edit":
// We get the value of property found with GETPOST so it takes into account:
// default values overwrite, restore back to list link, ... (but not 'default value in database' of field)
$check = 'alphanohtml';
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) {
$check = 'restricthtml';
}
$getposttemp = GETPOST($keyprefix . 'options_' . $key . $keysuffix, $check, 3); // GETPOST can get value from GET, POST or setup of default values overwrite.
// GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix)) {
if (is_array($getposttemp)) {
// $getposttemp is an array but following code expects a comma separated string
$value = implode(",", $getposttemp);
} else {
$value = $getposttemp;
}
} else {
$value = (!empty($this->array_options["options_" . $key]) ? $this->array_options["options_" . $key] : ''); // No GET, no POST, no default value, so we take value of object.
}
//var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value);
break;
}
// Output value of the current field
if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') {
$extrafields_collapse_num = '';
$extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
if (!empty($extrafield_param) && is_array($extrafield_param)) {
$extrafield_param_list = array_keys($extrafield_param['options']);
if (count($extrafield_param_list) > 0) {
$extrafield_collapse_display_value = intval($extrafield_param_list[0]);
if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
$extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
}
}
}
// if colspan=0 or 1, the second column is not extended, so the separator must be on 2 columns
$out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
} else {
$class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
$csstyle = '';
if (is_array($params) && count($params) > 0) {
if (array_key_exists('class', $params)) {
$class .= $params['class'] . ' ';
}
if (array_key_exists('style', $params)) {
$csstyle = $params['style'];
}
}
// add html5 elements
$domData = ' data-element="extrafield"';
$domData .= ' data-targetelement="' . $this->element . '"';
$domData .= ' data-targetid="' . $this->id . '"';
$html_id = (empty($this->id) ? '' : 'extrarow-' . $this->element . '_' . $key . '_' . $this->id);
if ($display_type == 'card') {
if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
$colspan = 0;
}
if ($action == 'selectlines') {
$colspan++;
}
}
// Convert date into timestamp format (value in memory must be a timestamp)
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date'))) {
$datenotinstring = null;
if (array_key_exists('options_' . $key, $this->array_options)) {
$datenotinstring = $this->array_options['options_' . $key];
if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
$datenotinstring = $this->db->jdate($datenotinstring);
}
}
$datekey = $keyprefix . 'options_' . $key . $keysuffix;
$value = (GETPOSTISSET($datekey)) ? dol_mktime(12, 0, 0, GETPOST($datekey . 'month', 'int', 3), GETPOST($datekey . 'day', 'int', 3), GETPOST($datekey . 'year', 'int', 3)) : $datenotinstring;
}
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('datetime'))) {
$datenotinstring = null;
if (array_key_exists('options_' . $key, $this->array_options)) {
$datenotinstring = $this->array_options['options_' . $key];
if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
$datenotinstring = $this->db->jdate($datenotinstring);
}
}
$timekey = $keyprefix . 'options_' . $key . $keysuffix;
$value = (GETPOSTISSET($timekey)) ? dol_mktime(GETPOST($timekey . 'hour', 'int', 3), GETPOST($timekey . 'min', 'int', 3), GETPOST($timekey . 'sec', 'int', 3), GETPOST($timekey . 'month', 'int', 3), GETPOST($timekey . 'day', 'int', 3), GETPOST($timekey . 'year', 'int', 3), 'tzuserrel') : $datenotinstring;
}
// Convert float submited string into real php numeric (value in memory must be a php numeric)
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) {
if (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) {
$value = price2num($value);
} elseif (isset($this->array_options['options_' . $key])) {
$value = $this->array_options['options_' . $key];
}
}
// HTML, text, select, integer and varchar: take into account default value in database if in create mode
if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'varchar', 'select', 'int', 'boolean'))) {
if ($action == 'create') {
$value = (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element]['default'][$key];
}
}
$labeltoshow = $langs->trans($label);
$helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
if ($display_type == 'card') {
$out .= '' : ' ');
} else {
$out .= ($display_type == 'card' ? ' |
' : '');
}
$e++;
}
}
$out .= "\n";
// Add code to manage list depending on others
if (!empty($conf->use_javascript_ajax)) {
$out .= $this->getJSListDependancies();
}
$out .= ' ' . "\n";
}
}
$out .= $hookmanager->resPrint;
return $out;
}
/**
* @param string $type Type for prefix
* @return string Javacript code to manage dependency
*/
public function getJSListDependancies($type = '_extra')
{
$out = '
' . "\n";
return $out;
}
}