add extrafields on ecm

This commit is contained in:
Frédéric FRANCE 2020-10-02 00:21:13 +02:00
parent 3f1c9999db
commit f057488ae3
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
8 changed files with 143 additions and 45 deletions

View File

@ -23,6 +23,7 @@
*/ */
require '../main.inc.php'; require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
// Load translation files required by the page // Load translation files required by the page
@ -70,6 +71,10 @@ $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_valu
print load_fiche_titre($langs->trans("ECMSetup"), $linkback, 'title_setup'); print load_fiche_titre($langs->trans("ECMSetup"), $linkback, 'title_setup');
print '<br>'; print '<br>';
$head = ecm_admin_prepare_head();
dol_fiche_head($head, 'ecm', $langs->trans("Sendings"), -1, 'ecm');
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';

View File

@ -138,3 +138,38 @@ function ecm_prepare_head_fm($object)
return $head; return $head;
} }
/**
* Return array head with list of tabs to view object informations.
*
* @return array head array with tabs
*/
function ecm_admin_prepare_head()
{
global $langs, $conf;
$langs->load("ecm");
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/admin/ecm.php";
$head[$h][1] = $langs->trans("Setup");
$head[$h][2] = 'ecm';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/admin/ecm_files_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsEcmFiles");
$head[$h][2] = 'attributes_ecm_files';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/admin/ecm_directories_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsEcmDirectories");
$head[$h][2] = 'attributes_ecm_directories';
$h++;
complete_head_from_modules($conf, $langs, null, $head, $h, 'ecm_admin');
complete_head_from_modules($conf, $langs, null, $head, $h, 'ecm_admin', 'remove');
return $head;
}

View File

@ -25,7 +25,7 @@
/** /**
* Class to manage ECM directories * Class to manage ECM directories
*/ */
class EcmDirectory // extends CommonObject class EcmDirectory extends CommonObject
{ {
/** /**
* @var string ID to identify managed object * @var string ID to identify managed object
@ -35,7 +35,7 @@ class EcmDirectory // extends CommonObject
/** /**
* @var string Name of table without prefix where object is stored * @var string Name of table without prefix where object is stored
*/ */
//public $table_element='ecm_directories'; public $table_element='ecm_directories';
/** /**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
@ -345,6 +345,10 @@ class EcmDirectory // extends CommonObject
$this->date_m = $this->db->jdate($obj->date_m); $this->date_m = $this->db->jdate($obj->date_m);
} }
// Retrieve all extrafields for ecm_files
// fetch optionals attributes and labels
$this->fetch_optionals();
$this->db->free($resql); $this->db->free($resql);
return $obj ? 1 : 0; return $obj ? 1 : 0;

View File

@ -403,9 +403,9 @@ class EcmFiles extends CommonObject
$this->src_object_id = $obj->src_object_id; $this->src_object_id = $obj->src_object_id;
} }
// Retrieve all extrafields for invoice // Retrieve all extrafields for ecm_files
// fetch optionals attributes and labels // fetch optionals attributes and labels
// $this->fetch_optionals(); $this->fetch_optionals();
// $this->fetch_lines(); // $this->fetch_lines();

View File

@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by page // Load translation files required by page
$langs->loadLangs(array('ecm', 'companies', 'other')); $langs->loadLangs(array('ecm', 'companies', 'other'));
@ -204,6 +205,16 @@ if ($action == 'update' && !GETPOST('cancel', 'alpha'))
// Fetch was already done // Fetch was already done
$ecmdir->label = dol_sanitizeFileName(GETPOST("label")); $ecmdir->label = dol_sanitizeFileName(GETPOST("label"));
$ecmdir->description = GETPOST("description"); $ecmdir->description = GETPOST("description");
$ret = $extrafields->setOptionalsFromPost(null, $ecmdir);
if ($ret < 0) $error++;
if (!$error) {
// Actions on extra fields
$result = $ecmdir->insertExtraFields();
if ($result < 0) {
setEventMessages($ecmdir->error, $ecmdir->errors, 'errors');
$error++;
}
}
$result = $ecmdir->update($user); $result = $ecmdir->update($user);
if ($result > 0) if ($result > 0)
{ {
@ -266,6 +277,10 @@ if ($action == 'update' && !GETPOST('cancel', 'alpha'))
$form = new Form($db); $form = new Form($db);
$object = new EcmDirectory($db); // Need to create a new one instance $object = new EcmDirectory($db); // Need to create a new one instance
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
if ($module == 'ecm') if ($module == 'ecm')
{ {
@ -415,6 +430,7 @@ print '</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'; print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>';
print dol_print_size($totalsize); print dol_print_size($totalsize);
print '</td></tr>'; print '</td></tr>';
print $object->showOptionals($extrafields, ($action == 'edit' ? 'edit' : 'view'));
print '</table>'; print '</table>';
if ($action == 'edit') if ($action == 'edit')

View File

@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
// Load translation files required by page // Load translation files required by page
$langs->loadLangs(array('ecm', 'companies', 'other', 'users', 'orders', 'propal', 'bills', 'contracts', 'categories')); $langs->loadLangs(array('ecm', 'companies', 'other', 'users', 'orders', 'propal', 'bills', 'contracts', 'categories'));
@ -94,6 +95,10 @@ $filepathtodocument = $relativetodocument.$file->label;
// Try to load object from index // Try to load object from index
$object = new ECMFiles($db); $object = new ECMFiles($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$result = $object->fetch(0, '', $filepathtodocument); $result = $object->fetch(0, '', $filepathtodocument);
if ($result < 0) if ($result < 0)
{ {
@ -148,7 +153,6 @@ if ($action == 'update')
// Now we update index of file // Now we update index of file
$db->begin(); $db->begin();
//print $oldfile.' - '.$newfile; //print $oldfile.' - '.$newfile;
if ($newlabel != $oldlabel) if ($newlabel != $oldlabel)
{ {
@ -181,6 +185,16 @@ if ($action == 'update')
if ($object->id > 0) if ($object->id > 0)
{ {
$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) $error++;
if (!$error) {
// Actions on extra fields
$result = $object->insertExtraFields();
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
// Call update to set the share key // Call update to set the share key
$result = $object->update($user); $result = $object->update($user);
if ($result < 0) if ($result < 0)
@ -365,8 +379,9 @@ if (!empty($object->share))
print '<input type="checkbox" name="shareenabled"'.($object->share ? ' checked="checked"' : '').' /> '; print '<input type="checkbox" name="shareenabled"'.($object->share ? ' checked="checked"' : '').' /> ';
} }
} }
print '</td></tr>'; print '</td>';
print '</tr>';
print $object->showOptionals($extrafields, ($action == 'edit'?'edit':'view'));
print '</table>'; print '</table>';
print '</div>'; print '</div>';

View File

@ -330,3 +330,23 @@ ALTER TABLE llx_bank ADD COLUMN origin_type varchar(64) NULL;
ALTER TABLE llx_bank ADD COLUMN import_key varchar(14); ALTER TABLE llx_bank ADD COLUMN import_key varchar(14);
ALTER TABLE llx_menu MODIFY COLUMN enabled text; ALTER TABLE llx_menu MODIFY COLUMN enabled text;
CREATE TABLE llx_ecm_files_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;
ALTER TABLE llx_ecm_files_extrafields ADD INDEX idx_ecm_files_extrafields (fk_object);
CREATE TABLE llx_ecm_directories_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;
ALTER TABLE llx_ecm_directories_extrafields ADD INDEX idx_ecm_directories_extrafields (fk_object);

View File

@ -50,3 +50,6 @@ ReSyncListOfDir=Resync list of directories
HashOfFileContent=Hash of file content HashOfFileContent=Hash of file content
NoDirectoriesFound=No directories found NoDirectoriesFound=No directories found
FileNotYetIndexedInDatabase=File not yet indexed into database (try to re-upload it) FileNotYetIndexedInDatabase=File not yet indexed into database (try to re-upload it)
ExtraFieldsEcmFiles=Extrafields Ecm Files
ExtraFieldsEcmDirectories=Extrafields Ecm Directories
ECMSetup=ECM Setup