NEW Use lang selector when using a field key 'lang' in modulebuilder

This commit is contained in:
Laurent Destailleur 2021-08-18 01:54:13 +02:00
parent ddf425f73e
commit 82db3ae1a9
9 changed files with 37 additions and 24 deletions

View File

@ -53,13 +53,11 @@ if ($action == 'add' && !empty($permissiontoadd)) {
foreach ($object->fields as $key => $val) {
if ($object->fields[$key]['type'] == 'duration') {
if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') {
continue; // The field was not submited to be edited
continue; // The field was not submited to be saved
}
} else {
if (!GETPOSTISSET($key)) {
if ($key != 'lang' || !GETPOSTISSET($key.'object')) {
continue; // The field was not submited to be edited
}
continue; // The field was not submited to be saved
}
}
// Ignore special fields
@ -90,7 +88,7 @@ if ($action == 'add' && !empty($permissiontoadd)) {
$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
} else {
if ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
$value = GETPOST($key, 'aZ09');
} else {
$value = GETPOST($key, 'alphanohtml');
}
@ -158,7 +156,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
// Check if field was submited to be edited
if ($object->fields[$key]['type'] == 'duration') {
if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) {
continue; // The field was not submited to be edited
continue; // The field was not submited to be saved
}
} elseif ($object->fields[$key]['type'] == 'boolean') {
if (!GETPOSTISSET($key)) {
@ -167,9 +165,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
}
} else {
if (!GETPOSTISSET($key)) {
if ($key != 'lang' || !GETPOSTISSET($key.'object')) {
continue; // The field was not submited to be edited
}
continue; // The field was not submited to be saved
}
}
// Ignore special fields
@ -178,7 +174,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
}
if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
if (!in_array(abs($val['visible']), array(1, 3, 4))) {
continue; // Only 1 and 3 and 4 that are case to update
continue; // Only 1 and 3 and 4, that are cases to update
}
}
@ -208,7 +204,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
} else {
if ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
$value = GETPOST($key, 'aZ09');
} else {
$value = GETPOST($key, 'alphanohtml');
}
@ -303,6 +299,8 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
setEventMessages($object->error, null, 'errors');
}
}
$action = '';
}
// Remove a line
@ -334,11 +332,13 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
}
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Action validate object
@ -374,6 +374,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Action close object
@ -404,6 +405,7 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Action setdraft object
@ -414,6 +416,7 @@ if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Action reopen object
@ -444,6 +447,7 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
$action = '';
}
// Action clone object
@ -462,6 +466,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd))
} else {
$newid = $result;
}
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
exit;
} else {

View File

@ -8170,7 +8170,7 @@ abstract class CommonObject
} else {
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) {
$return .= '<!-- Show thumb -->';
$return .= '<img class="photo photowithmargin maxwidth150onsmartphone" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
$return .= '<img class="photo photowithmargin maxwidth150onsmartphone maxwidth200" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
} else {
$return .= '<!-- Show original file -->';
$return .= '<img class="photo photowithmargin" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';

View File

@ -272,7 +272,7 @@ class FormTicket
print '</td></tr>';
}
//Categories
// Categories
if ($conf->categorie->enabled) {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
@ -441,6 +441,7 @@ class FormTicket
print '<tr><td>';
print $langs->trans("AssignedTo");
print '</td><td>';
print img_picto('', 'user', 'class="pictofixedwidth"');
print $form->select_dolusers(GETPOST('fk_user_assign', 'int'), 'fk_user_assign', 1);
print '</td>';
print '</tr>';

View File

@ -80,7 +80,7 @@ foreach ($object->fields as $key => $val) {
} elseif ($val['type'] == 'price') {
$value = price2num(GETPOST($key));
} elseif ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
$value = GETPOST($key, 'aZ09');
} else {
$value = GETPOST($key, 'alphanohtml');
}
@ -89,7 +89,7 @@ foreach ($object->fields as $key => $val) {
} else {
if ($key == 'lang') {
print img_picto('', 'language', 'class="pictofixedwidth"');
print $formadmin->select_language($value, $key.'object', 0, null, 1, 0, 0, 'minwidth300', 2);
print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
} else {
print $object->showInputField($val, $key, $value, '', '', '', 0);
}

View File

@ -19,6 +19,7 @@
* $action
* $conf
* $langs
* $form
*/
// Protection to avoid direct call of template
@ -80,7 +81,7 @@ foreach ($object->fields as $key => $val) {
} elseif ($val['type'] == 'price') {
$value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key);
} elseif ($key == 'lang') {
$value = GETPOSTISSET($key.'object', 'aZ09')?GETPOST($key.'object', 'aZ09'):$object->lang;
$value = GETPOSTISSET($key, 'aZ09') ? GETPOST($key, 'aZ09') : $object->lang;
} else {
$value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key;
}
@ -90,7 +91,7 @@ foreach ($object->fields as $key => $val) {
} else {
if ($key == 'lang') {
print img_picto('', 'language', 'class="pictofixedwidth"');
print $formadmin->select_language($value, $key.'object', 0, null, 1, 0, 0, 'minwidth300', 2);
print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
} else {
print $object->showInputField($val, $key, $value, '', '', '', 0);
}

View File

@ -101,7 +101,8 @@ class KnowledgeRecord extends CommonObject
*/
public $fields=array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>5, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"),
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'visible'=>5, 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object"),
'lang' => array('type'=>'varchar(6)', 'label'=>'Language', 'enabled'=>'1', 'position'=>51, 'notnull'=>0, 'visible'=>1),
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
@ -114,8 +115,7 @@ class KnowledgeRecord extends CommonObject
'answer' => array('type'=>'html', 'label'=>'Solution', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>3, 'csslist'=>'tdoverflow300'),
//'url' => array('type'=>'varchar(255)', 'label'=>'URL', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflow200', 'help'=>'UrlForInfoPage'),
'fk_c_ticket_category' => array('type'=>'integer:CTicketCategory:ticket/class/cticketcategory.class.php', 'label'=>'GroupOfTicket', 'enabled'=>'$conf->ticket->enabled', 'position'=>512, 'notnull'=>0, 'visible'=>-1, 'help'=>'YouCanLinkArticleToATicketCategory'),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Valid'),),
'lang' => array('type'=>'varchar(6)', 'label'=>'Language', 'enabled'=>'1', 'position'=>51, 'notnull'=>0, 'visible'=>1),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated'),),
);
public $rowid;
public $ref;

View File

@ -373,13 +373,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if ($object->status == $object::STATUS_VALIDATED) {
print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes', '', $permissiontoadd);
}
if ($object->status == $object::STATUS_VALIDATED && $permissiontovalidate) {
if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && $permissiontovalidate) {
print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit', '', $permissiontoadd);
}
// Validate
if ($object->status == $object::STATUS_DRAFT) {
if ((empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) && $permissiontovalidate) {
print dolGetButtonAction($langs->trans('ValidateReply'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes', '', $permissiontoadd);
print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes', '', $permissiontoadd);
} else {
$langs->load("errors");
//print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes', '', 0);

View File

@ -462,7 +462,7 @@ foreach ($object->fields as $key => $val) {
print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth125', 1);
} elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
if ($key == 'lang') {
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth300', 2);
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
} else {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
}

View File

@ -533,7 +533,13 @@ foreach ($object->fields as $key => $val) {
} elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
} elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
if ($key == 'lang') {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($db);
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
} else {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
}
} elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
print '<div class="nowrap">';
print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));