Make accountancy pages responsive

This commit is contained in:
Laurent Destailleur
2017-09-05 20:42:34 +02:00
parent 48c526f87d
commit f29a4c1fb1
19 changed files with 172 additions and 70 deletions

View File

@@ -25,22 +25,34 @@
/**
* Save data into a memory area shared by all users, all sessions on server
* Regenerate files .class.php
*
* @param string $destdir Directory
* @param string $module Module name
* @param string $objectname Name of object
* @param string $newmask New mask
* @param string $readdir Directory source (use $destdir when not defined)
* @param string $addfieldentry Array of the field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure')
* @param string $delfieldentry Id of field to remove
* @return int <=0 if KO, >0 if OK
*/
function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='')
function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array() ,$delfieldentry='')
{
global $db, $langs;
if (empty($objectname)) return -1;
if (empty($readdir)) $readdir=$destdir;
// Check parameters
if (count($addfieldentry) > 0)
{
if (! preg_match('/^(integer|date|timestamp|varchar|double)/', $addfieldentry['type']))
{
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null, 'errors');
return -1;
}
}
$pathoffiletoeditsrc=$readdir.'/class/'.strtolower($objectname).'.class.php';
$pathoffiletoedittarget=$destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : '');
if (! dol_is_file($pathoffiletoeditsrc))
@@ -65,10 +77,28 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
// Edit class files
$contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
// Update ->fields (add or remove entries)
if (count($object->fields))
{
if (is_array($addfieldentry) && count($addfieldentry))
{
$name=$addfieldentry['name'];
unset($addfieldentry['name']);
$object->fields[$name]=$addfieldentry;
}
if (! empty($delfieldentry))
{
$name=$delfieldentry;
unset($object->fields[$name]);
}
}
dol_sort_array($object->fields, 'position');
$i=0;
$texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
$texttoinsert = "\t".'// BEGIN MODULEBUILDER PROPERTIES'."\n";
$texttoinsert.= "\t".'/**'."\n";
$texttoinsert.= "\t".' * @var array Array with all fields and their property'."\n";
$texttoinsert.= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n";
$texttoinsert.= "\t".' */'."\n";
$texttoinsert.= "\t".'public $fields=array('."\n";
@@ -77,29 +107,31 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
foreach($object->fields as $key => $val)
{
$i++;
$typephp='';
$texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',";
$texttoinsert.= " 'visible'=>".($val['visible']?$val['visible']:0).",";
$texttoinsert.= " 'enabled'=>".($val['enabled']?$val['enabled']:0).",";
if ($val['position']) $texttoinsert.= " 'position'=>".$val['position'].",";
$texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).",";
$texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).",";
$texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).",";
if ($val['notnull']) $texttoinsert.= " 'notnull'=>".$val['notnull'].",";
if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].",";
if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].",";
if ($val['comment']) $texttoinsert.= " 'comment'=>'".$val['comment']."',";
if ($val['isameasure']) $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',";
if ($val['help']) $texttoinsert.= " 'help'=>'".$val['help']."',";
$texttoinsert.= "),\n";
}
}
$texttoinsert.= "\t".');'."\n";
$texttoinsert.= "\n";
$texttoinsert.= "\t".');'."\n";
if (count($object->fields))
{
foreach($object->fields as $key => $val)
$typetotypephp=array('integer'=>'integer', 'varchar'=>'string');
foreach($object->fields as $key => $val)
{
$i++;
$typephp='';
$texttoinsert.= "\t".'public $'.$key.$typephp.";";
//$typephp=$typetotypephp[$val['type']];
$texttoinsert.= "\t".'public $'.$key.";";
//if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY';
//if ($key == 'entity') $texttoinsert.= ' DEFAULT 1';
//$texttoinsert.= ($val['notnull']?' NOT NULL':'');
@@ -110,6 +142,8 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
$texttoinsert.= "\t".'// END MODULEBUILDER PROPERTIES';
//print($texttoinsert);exit;
$contentclass = preg_replace('/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
dol_mkdir(dirname($pathoffiletoedittarget));