Debug modulebuilder

This commit is contained in:
Laurent Destailleur
2017-07-11 20:47:49 +02:00
parent cbde99b419
commit ceeb9d7f1b
4 changed files with 198 additions and 79 deletions

View File

@@ -37,9 +37,10 @@ $cancel=GETPOST('cancel','alpha');
$module=GETPOST('module','alpha');
$tab=GETPOST('tab','aZ09');
$tabobj=GETPOST('tabobj','alpha');
$propertykey=GETPOST('propertykey','alpha');
if (empty($module)) $module='initmodule';
if (empty($tab)) $tab='description';
if (empty($tabobj)) $tabobj='newobject';
if (empty($tabobj)) $tabobj='newobjectifnoobj';
$file=GETPOST('file','alpha');
$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
@@ -58,6 +59,7 @@ $FILEFLAG='modulebuilder.txt';
$now=dol_now();
/*
* Actions
*/
@@ -320,6 +322,29 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname)
$tabobj = 'deleteobject';
}
if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
{
if (! $error)
{
$modulelowercase=strtolower($module);
$objectlowercase=strtolower($objectname);
// File of class
$fileforclass = $dirins.'/'.$modulelowercase.'/class/'.$objectlowercase.'.class.php';
// TODO
// File of sql
$fileforsql = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.sql';
$fileforsqlkey = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.key.sql';
// TODO
}
}
if ($dirins && $action == 'generatepackage')
{
$modulelowercase=strtolower($module);
@@ -838,9 +863,11 @@ elseif (! empty($module))
$h++;
$listofobject = dol_dir_list($dir, 'files', 0, '\.txt$');
$firstobjectname='';
foreach($listofobject as $fileobj)
{
$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
if (empty($firstobjectname)) $firstobjectname = $objectname;
$head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj='.$objectname;
$head3[$h][1] = $objectname;
@@ -853,6 +880,12 @@ elseif (! empty($module))
$head3[$h][2] = 'deleteobject';
$h++;
// If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects.
if ($tabobj == 'newobjectifnoobj')
{
if ($firstobjectname) $tabobj=$firstobjectname;
else $tabobj = 'newobject';
}
dol_fiche_head($head3, $tabobj, '', -1, '');
@@ -888,92 +921,168 @@ elseif (! empty($module))
}
else
{
try {
$pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.class.php';
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.class.php';
print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.$pathtoclass.'</strong><br>';
print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong>'.$pathtoapi.'</strong><br>';
print '<span class="fa fa-file"></span> '.$langs->trans("PageForList").' : <strong>'.$pathtolist.'</strong><br>';
print '<span class="fa fa-file"></span> '.$langs->trans("PageForCreateEditView").' : <strong>'.$pathtocard.'</strong><br>';
if ($action == 'deleteproperty')
{
$formconfirm = $form->formconfirm(
$_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey','alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
$langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey','alpha')), 'confirm_deleteproperty', '', 0, 1
);
$result = dol_include_once($pathtoclass);
$tmpobjet = new $tabobj($db);
// Print form confirm
print $formconfirm;
}
$reflector = new ReflectionClass($tabobj);
$properties = $reflector->getProperties(); // Can also use get_object_vars
$propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
//$propstat = $reflector->getStaticProperties();
if ($action != 'editfile' || empty($file))
{
try {
$pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.$pathtoclass.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong>'.$pathtoapi.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print '<span class="fa fa-file"></span> '.$langs->trans("PageForList").' : <strong>'.$pathtolist.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtolist).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print '<span class="fa fa-file"></span> '.$langs->trans("PageForCreateEditView").' : <strong>'.$pathtocard.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtocard).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print load_fiche_titre($langs->trans("Properties"), '', '');
$result = dol_include_once($pathtoclass);
$tmpobjet = new $tabobj($db);
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="initobject">';
print '<input type="hidden" name="tab" value="objects">';
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
$reflector = new ReflectionClass($tabobj);
$properties = $reflector->getProperties(); // Can also use get_object_vars
$propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
//$propstat = $reflector->getStaticProperties();
print '<table class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Property");
print ' (<a href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("Example").'</a>)';
print '</td>';
print '<td>'.$langs->trans("Comment").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td>'.$langs->trans("DefaultValue").'</td>';
print '<td></td>';
print '</tr>';
print '<tr>';
print '<td><input class="text" name="propname" value=""></td>';
print '<td><input class="text" name="propname" value=""></td>';
print '<td><input class="text" name="propname" value=""></td>';
print '<td><input class="text" name="propname" value=""></td>';
print '<td align="center">';
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
print '</td></tr>';
foreach($properties as $propkey => $propval)
{
if ($propval->class == $tabobj)
print load_fiche_titre($langs->trans("Properties"), '', '');
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="initobject">';
print '<input type="hidden" name="tab" value="objects">';
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
print '<table class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Property");
print ' (<a href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("Example").'</a>)';
print '</td>';
print '<td>'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td>'.$langs->trans("Position").'</td>';
print '<td>'.$langs->trans("DefaultValue").'</td>';
print '<td>'.$langs->trans("Index").'</td>';
print '<td>'.$langs->trans("Comment").'</td>';
print '<td></td>';
print '</tr>';
print '<tr>';
print '<td><input class="text" name="propname" value=""></td>';
print '<td><input class="text" name="proplabel" value=""></td>';
print '<td><input class="text" name="proptype" value=""></td>';
print '<td><input class="text" name="propposition" value=""></td>';
print '<td><input class="text" name="propdefault" value=""></td>';
print '<td><input class="text" name="propindex" value=""></td>';
print '<td><input class="text" name="propcomment" value=""></td>';
print '<td align="center">';
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
print '</td></tr>';
$properties = $tmpobjet->fields;
foreach($properties as $propkey => $propval)
{
$propname=$propval->getName();
/* If from Reflection
if ($propval->class == $tabobj)
{
$propname=$propval->getName();
$comment=$propval->getDocComment();
$type=gettype($tmpobjet->$propname);
$default=$propdefault[$propname];
// Discard generic properties
if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue;
// Discard generic properties
if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue;
// Keep or not lines
if (in_array($propname, array('fk_element', 'lines'))) continue;
}*/
// Keep or not lines
if (in_array($propname, array('fk_element', 'lines'))) continue;
$propname=$propkey;
$proplabel=$propval['label'];
$proptype=$propval['type'];
$propposition=$propval['position'];
$propdefault=$propval['default'];
$propindex=$propval['index'];
$propcomment=$propval['comment'];
print '<tr class="oddeven">';
print '<tr class="oddeven"><td>';
print '<td>';
print $propname;
print '</td>';
print '<td>';
print $propval->getDocComment();
print $proplabel;
print '</td>';
print '<td>';
print gettype($tmpobjet->$propname);
print $proptype;
print '</td>';
print '<td>';
print $propdefault[$propname];
print $propposition;
print '</td>';
print '<td>';
print $propdefault;
print '</td>';
print '<td>';
print yn($propindex);
print '</td>';
print '<td>';
print $propcomment;
print '</td>';
print '<td class="center">';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
print '</td>';
print '</tr>';
}
print '</table>';
print '</form>';
}
print '</table>';
catch(Exception $e)
{
print $e->getMessage();
}
}
else
{
$fullpathoffile=dol_buildpath($file, 0);
$content = file_get_contents($fullpathoffile);
// New module
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="savefile">';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
print '<input type="hidden" name="tab" value="'.$tab.'">';
print '<input type="hidden" name="module" value="'.$module.'">';
$doleditor=new DolEditor('editfilecontent', $content, '', '600', 'Full', 'In', true, false, false, 0, '99%');
print $doleditor->Create(1, '', false);
print '<br>';
print '<center>';
print '<input type="submit" class="button" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';
print '</form>';
}
catch(Exception $e)
{
print $e->getMessage();
}
}
}