This commit is contained in:
JC Prieto 2025-02-19 18:33:07 +01:00 committed by GitHub
commit 7b669fb051
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 115 additions and 2 deletions

View File

@ -62,6 +62,7 @@ $max_users = GETPOSTINT('max_users');
$url = GETPOST('url', 'alpha');
$confirm = GETPOST('confirm', 'aZ09');
$fk_code_type_resource = GETPOST('fk_code_type_resource', 'aZ09');
$status = GETPOSTINT('status');
// Protection if external user
if ($user->socid > 0) {
@ -218,6 +219,30 @@ if (empty($reshook)) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
if ($action == 'confirm_close') {
$res = $object->fetch($id);
//$object->status=Dolresource::STATUS_CANCELED;
//$object->update($user);
$object->setStatut(Dolresource::STATUS_CANCELED);
$action = '';
}
if ($action == 'confirm_reopen') {
$res = $object->fetch($id);
//$object->status=Dolresource::STATUS_VALIDATED;
//$object->update($user);
$object->setStatut(Dolresource::STATUS_VALIDATED);
$action = '';
}
if ($action == 'confirm_validate') {
$res = $object->fetch($id);
//$object->status=Dolresource::STATUS_VALIDATED;
//$object->update($user);
$object->setStatut(Dolresource::STATUS_VALIDATED);
$action = '';
}
}
@ -463,6 +488,28 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) {
$buttonId = 'action-delete';
}
print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete);
// Back to draft
if ($object->status == $object::STATUS_VALIDATED) {
//print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
}
// Validate
if ($object->status == $object::STATUS_DRAFT) {
if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
} else {
$langs->load("errors");
print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
}
}
if ($permissiontoadd) {
if ($object->status == $object::STATUS_VALIDATED) {
print dolGetButtonAction($langs->trans('Cancel'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$id.'&action=confirm_close&confirm=yes&token='.newToken(), '', $permissiontoadd);
} else {
print dolGetButtonAction($langs->trans('Re-Open'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$id.'&action=confirm_reopen&confirm=yes&token='.newToken(), '', $permissiontoadd);
}
}
}
}
print '</div>';

View File

@ -132,6 +132,11 @@ class Dolresource extends CommonObject
public $cache_code_type_resource;
const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1;
const STATUS_CANCELED = 9;
/**
* Constructor
*
@ -282,6 +287,7 @@ class Dolresource extends CommonObject
$sql .= " t.note_private,";
$sql .= " t.tms as date_modification,";
$sql .= " t.datec as date_creation,";
$sql .= " t.fk_statut as status,";//
$sql .= " ty.label as type_label";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
@ -316,6 +322,7 @@ class Dolresource extends CommonObject
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->date_modification);
$this->type_label = $obj->type_label;
$this->status = $obj->status;//
// Retrieve all extrafield
// fetch optionals attributes and labels
@ -401,6 +408,7 @@ class Dolresource extends CommonObject
$sql .= " fk_code_type_resource=".(isset($this->fk_code_type_resource) ? "'".$this->db->escape($this->fk_code_type_resource)."'" : "null").",";
$sql .= " tms=" . ("'" . $this->db->idate($this->date_modification) . "',");
$sql .= " fk_user_modif=" . (!empty($user->id) ? ((int) $user->id) : "null");
$sql .= " ,fk_statut=".$this->status ." ";//
$sql .= " WHERE rowid=".((int) $this->id);
$this->db->begin();
@ -625,6 +633,7 @@ class Dolresource extends CommonObject
$sql .= " t.fk_code_type_resource,";
$sql .= " t.tms as date_modification,";
$sql .= " t.datec as date_creation,";
$sql .= " t.fk_statut as status,";//
// Add fields from extrafields
if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element]['label'])) {
foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
@ -691,6 +700,7 @@ class Dolresource extends CommonObject
$line->date_modification = $obj->date_modification;
$line->date_creation = $obj->date_creation;
$line->type_label = $obj->type_label;
$line->status = $obj->status;//
// fetch optionals attributes and labels
@ -1010,9 +1020,26 @@ class Dolresource extends CommonObject
* @param int<0,6> $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
* @return string Label of status
*/
public static function getLibStatusLabel(int $status, int $mode = 0)
public function getLibStatusLabel(int $status, int $mode = 0)
{
return '';
global $langs;
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
$this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
$this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
}
$statusType = 'status'.$status;
//if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
if ($status == self::STATUS_CANCELED) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
/**

View File

@ -82,6 +82,11 @@ $search_email = GETPOST("search_email", 'alpha');
$search_max_users = GETPOST("search_max_users", 'alpha');
$search_url = GETPOST("search_url", 'alpha');
$search_status = GETPOST("search_status");
if (empty($search_status)) $search_status=Dolresource::STATUS_VALIDATED;
if ($search_status<0) $search_status='';
$filter = array();
$hookmanager->initHooks(array('resourcelist'));
@ -160,6 +165,11 @@ $arrayfields = array(
'checked' => '0',
'position' => 11
),
't.status' => array(
'label' => $langs->trans("Status"),
'checked' => 1,
'position' => 12
)
);
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
@ -184,6 +194,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$search_url = "";
$toselect = array();
$search_array_options = array();
$search_status='';//
}
$permissiontoread = $user->hasRight('resource', 'read');
@ -252,6 +263,7 @@ $sql .= " t.datec as date_creation, ";
$sql .= " ty.label as type_label, ";
$sql .= " st.nom as state_label, ";
$sql .= " co.label as country_label ";
$sql .= " ,t.fk_statut as status";//
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
@ -312,6 +324,9 @@ if ($search_max_users) {
if ($search_url) {
$sql .= natural_search('t.url', $search_url);
}
if ($search_status) {
$sql .= " AND t.fk_statut = ". $search_status;
}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
@ -409,6 +424,9 @@ if ($search_max_users != '') {
if ($search_url != '') {
$param .= '&search_url='.urlencode($search_url);
}
if ($search_status != '') {
$param .= '&search_status='.urlencode($search_status);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -514,6 +532,13 @@ if (!empty($arrayfields['t.url']['checked'])) {
print '<input type="text" class="flat" name="search_url" value="'.$search_url.'" size="8">';
print '</td>';
}
//
if (!empty($arrayfields['t.status']['checked'])) {
print '<td class="liste_titre">';
print $form->selectarray('search_status', array(0=>'Borrador', 1=>'Validado', 9=>'Cancelado'), $search_status, ' ', 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
//print '<input type="text" class="flat" name="search_status" value="'.$search_status.'" size="6">';
print '</td>';
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
@ -566,6 +591,10 @@ if (!empty($arrayfields['t.max_users']['checked'])) {
if (!empty($arrayfields['t.url']['checked'])) {
print_liste_field_titre($arrayfields['t.url']['label'], $_SERVER["PHP_SELF"], "t.url", "", $param, "", $sortfield, $sortorder);
}
//
if (!empty($arrayfields['t.status']['checked'])) {
print_liste_field_titre($arrayfields['t.status']['label'], $_SERVER["PHP_SELF"], "t.status", "", $param, "", $sortfield, $sortorder);
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Action column
@ -595,6 +624,7 @@ while ($i < $imaxinloop) {
$objectstatic->email = $obj->email;
$objectstatic->max_users = $obj->max_users;
$objectstatic->url = $obj->url;
$objectstatic->status = $obj->status;//
print '<tr class="oddeven">';
@ -674,6 +704,15 @@ while ($i < $imaxinloop) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['t.status']['checked'])) {
print '<td>';
print $objectstatic->getLibStatut(5);
print '</td>';
if (!$i) {
$totalarray['nbfield']++;
}
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';