Merge branch '6.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur
2017-07-24 21:04:07 +02:00
8 changed files with 156 additions and 100 deletions

View File

@@ -360,7 +360,7 @@ if ($dirins && $action == 'confirm_delete')
if ($dirins && $action == 'confirm_deleteobject' && $objectname)
{
if (preg_match('/\s/', $objectname))
if (preg_match('/[^a-z0-9]/i', $objectname))
{
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
@@ -604,7 +604,11 @@ if ($action == 'savefile' && empty($cancel))
// Enable module
if ($action == 'set' && $user->admin)
{
$param='module='.$module;
$param='';
if ($module) $param.='&module='.$module;
if ($tab) $param.='&tab='.$tab;
if ($tabobj) $param.='&tabobj='.$tabobj;
$value = GETPOST('value','alpha');
$resarray = activateModule($value);
if (! empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors');
@@ -635,7 +639,11 @@ if ($action == 'set' && $user->admin)
// Disable module
if ($action == 'reset' && $user->admin)
{
$param='module='.$module;
$param='';
if ($module) $param.='&module='.$module;
if ($tab) $param.='&tab='.$tab;
if ($tabobj) $param.='&tabobj='.$tabobj;
$value = GETPOST('value','alpha');
$result=unActivateModule($value);
if ($result) setEventMessages($result, null, 'errors');
@@ -844,7 +852,11 @@ elseif (! empty($module))
$modulelowercase=strtolower($module);
$const_name = 'MAIN_MODULE_'.strtoupper($module);
$param='&tab='.$tab.'&module='.$module;
$param='';
if ($tab) $param.= '&tab='.$tab;
if ($module) $param.='&module='.$module;
if ($tabobj) $param.='&tabobj='.$tabobj;
$urltomodulesetup='<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
$linktoenabledisable='';
if (! empty($conf->global->$const_name)) // If module is already activated
@@ -1256,9 +1268,10 @@ elseif (! empty($module))
print '<td class="center">'.$langs->trans("NotNull").'</td>';
//print '<td>'.$langs->trans("DefaultValue").'</td>';
print '<td class="center">'.$langs->trans("DatabaseIndex").'</td>';
print '<td class="right">'.$langs->trans("Position").'</td>';
print '<td class="right">'.$langs->trans("Enabled").'</td>';
print '<td class="right">'.$langs->trans("Visible").'</td>';
print '<td class="right">'.$langs->trans("Position").'</td>';
print '<td class="right">'.$langs->trans("IsAMeasure").'</td>';
print '<td class="center">'.$langs->trans("SearchAll").'</td>';
print '<td>'.$langs->trans("Comment").'</td>';
print '<td></td>';
@@ -1270,9 +1283,10 @@ elseif (! empty($module))
print '<td class="center"><input class="text" size="2" name="propnotnull" value=""></td>';
//print '<td><input class="text" name="propdefault" value=""></td>';
print '<td class="center"><input class="text" size="2" name="propindex" value=""></td>';
print '<td class="right"><input class="text right" size="2" name="propposition" value=""></td>';
print '<td class="center"><input class="text" size="2" name="propenabled" value=""></td>';
print '<td class="center"><input class="text" size="2" name="propvisible" value=""></td>';
print '<td class="right"><input class="text right" size="2" name="propposition" value=""></td>';
print '<td class="center"><input class="text" size="2" name="propisameasure" value=""></td>';
print '<td class="center"><input class="text" size="2" name="propsearchall" value=""></td>';
print '<td><input class="text" name="propcomment" value=""></td>';
print '<td align="center">';
@@ -1300,13 +1314,14 @@ elseif (! empty($module))
$propname=$propkey;
$proplabel=$propval['label'];
$proptype=$propval['type'];
$propposition=$propval['position'];
$propnotnull=$propval['notnull'];
$propsearchall=$propval['searchall'];
//$propdefault=$propval['default'];
$propindex=$propval['index'];
$propposition=$propval['position'];
$propenabled=$propval['enabled'];
$propvisible=$propval['visible'];
$propisameasure=$propval['isameasure'];
$propcomment=$propval['comment'];
print '<tr class="oddeven">';
@@ -1329,14 +1344,17 @@ elseif (! empty($module))
print '<td class="center">';
print $propindex?'X':'';
print '</td>';
print '<td align="right">';
print $propposition;
print '</td>';
print '<td class="center">';
print $propenabled?$propenabled:'';
print '</td>';
print '<td class="center">';
print $propvisible?$propvisible:'';
print '</td>';
print '<td align="right">';
print $propposition;
print '<td class="center">';
print $propisameasure?$propisameasure:'';
print '</td>';
print '<td class="center">';
print $propsearchall?'X':'';

View File

@@ -58,21 +58,34 @@ class MyObject extends CommonObject
public $picto = 'myobject';
/**
* 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed,
* 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed)
* 'notnull' if not null in database
* 'index' if we want an index in database
* 'position' is the sort order of field
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button
* 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
* 'comment' is not used. You can store here any text of your choice.
*/
// BEGIN MODULEBUILDER PROPERTIES
/**
* @var array Array with all fields and their property
*/
public $fields=array(
'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'visible'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity'=>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>true, 'index'=>true, 'visible'=>0, 'position'=>20),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'visible'=>1, 'searchall'=>1),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'visible'=>-1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'visible'=>-1, 'position'=>500),
'status'=>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'visible'=>1, 'position'=>1000),
'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>true, 'index'=>true, 'position'=>20),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
'qty' =>array('type'=>'double(24,8)', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'searchall'=>0, 'isameasure'=>1),
'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1),
);
// END MODULEBUILDER PROPERTIES
// If this object has a subtable with lines

View File

@@ -110,6 +110,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook))
{
$error=0;
if ($cancel)
{
if ($action != 'addlink')
@@ -125,19 +127,11 @@ if (empty($reshook))
// Action to add record
if ($action == 'add' && ! empty($user->rights->mymodule->create))
{
if ($cancel)
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1);
header("Location: ".$urltogo);
exit;
}
$error=0;
foreach ($object->fields as $key => $val)
{
if (in_array($key, array('entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields
$object->$key=GETPOST($key,'alpha');
if (in_array($key, array('entity', 'datec', 'tms'))) continue;
if ($val['notnull'] && $object->$key == '')
{
$error++;
@@ -172,20 +166,20 @@ if (empty($reshook))
// Action to update record
if ($action == 'update' && ! empty($user->rights->mymodule->create))
{
$error=0;
$object->prop1=GETPOST("field1");
$object->prop2=GETPOST("field2");
if (empty($object->ref))
{
$error++;
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors');
}
foreach ($object->fields as $key => $val)
{
$object->$key=GETPOST($key,'alpha');
if (in_array($key, array('entity', 'datec', 'tms'))) continue;
if ($val['notnull'] && $object->$key == '')
{
$error++;
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
}
}
if (! $error)
{
$result=$object->update($user);
$result=$object->updateCommon($user);
if ($result > 0)
{
$action='view';
@@ -207,7 +201,7 @@ if (empty($reshook))
// Action to delete
if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete))
{
$result=$object->delete($user);
$result=$object->deleteCommon($user);
if ($result > 0)
{
// Delete OK
@@ -267,7 +261,7 @@ if ($action == 'create')
print '<table class="border centpercent">'."\n";
foreach($object->fields as $key => $val)
{
if (in_array($key, array('rowid', 'entity', 'datec', 'tms'))) continue;
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue;
print '<tr><td';
print ' class="titlefieldcreate';
if ($val['notnull']) print ' fieldrequired';

View File

@@ -227,7 +227,7 @@ foreach ($search_array_options as $key => $val)
$tmpkey=preg_replace('/search_options_/','',$key);
$typ=$extrafields->attribute_type[$tmpkey];
$mode=0;
if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
if (in_array($typ, array('int','double','real'))) $mode=1; // Search on a numeric
if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
{
$sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
@@ -363,7 +363,7 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
print '<tr class="liste_titre">';
foreach($object->fields as $key => $val)
{
if (in_array($key, array('datec','tms','status'))) continue;
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
@@ -399,7 +399,7 @@ print $hookmanager->resPrint;
// Rest of fields search
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('datec','tms','status'))) continue;
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
@@ -418,7 +418,7 @@ print '</tr>'."\n";
print '<tr class="liste_titre">';
foreach($object->fields as $key => $val)
{
if (in_array($key, array('datec','tms','status'))) continue;
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
@@ -445,7 +445,7 @@ print $hookmanager->resPrint;
// Rest of fields title
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('datec','tms','status'))) continue;
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
@@ -476,7 +476,7 @@ while ($i < min($num, $limit))
print '<tr class="oddeven">';
foreach($object->fields as $key => $val)
{
if (in_array($key, array('datec','tms','status'))) continue;
if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
@@ -488,6 +488,11 @@ while ($i < min($num, $limit))
else print $obj->$key;
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
$totalarray['val']['t.'.$key] += $obj->$key;
}
}
}
// Extra fields
@@ -505,6 +510,11 @@ while ($i < min($num, $limit))
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey;
$totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey;
}
}
}
}
@@ -515,18 +525,23 @@ while ($i < min($num, $limit))
// Rest of fields
foreach($object->fields as $key => $val)
{
if (! in_array($key, array('datec','tms','status'))) continue;
if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue;
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
if (! empty($arrayfields['t.'.$key]['checked']))
{
print '<td'.($align?' class="'.$align.'"':'').'>';
if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour');
elseif ($key == 'status') print '<td align="center">'.$object->getLibStatut(3).'</td>';
elseif ($key == 'status') print $object->getLibStatut(3);
else print $obj->$key;
print '</td>';
if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure']))
{
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
$totalarray['val']['t.'.$key] += $obj->$key;
}
}
}
// Action column
@@ -546,22 +561,23 @@ while ($i < min($num, $limit))
}
// Show total line
if (isset($totalarray['totalhtfield']))
if (isset($totalarray['pos']))
{
print '<tr class="liste_total">';
$i=0;
while ($i < $totalarray['nbfield'])
{
$i++;
if ($i == 1)
if (! empty($totalarray['pos'][$i])) print '<td align="right">'.price($totalarray['val'][$totalarray['pos'][$i]]).'</td>';
else
{
if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
if ($i == 1)
{
if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
}
print '<td></td>';
}
elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
else print '<td></td>';
}
print '</tr>';
}

View File

@@ -19,8 +19,10 @@ CREATE TABLE llx_myobject(
-- BEGIN MODULEBUILDER FIELDS
entity INTEGER DEFAULT 1 NOT NULL,
label VARCHAR(255),
datec DATETIME NOT NULL,
qty INTEGER,
status INTEGER,
date_creation DATETIME NOT NULL,
tms TIMESTAMP NOT NULL,
status INTEGER
import_key VARCHAR(14)
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;