mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Debug v20
This commit is contained in:
parent
42b0fa2e88
commit
57bb4cd7e4
|
|
@ -460,10 +460,10 @@ function dolGetListOfObjectClasses($destdir)
|
|||
}
|
||||
|
||||
/**
|
||||
* Function to check if comment begin an end exist in modMyModule class
|
||||
* Function to check if comment BEGIN and END exists in modMyModule class
|
||||
*
|
||||
* @param string $file Filename or path
|
||||
* @param int $number 0 = For Menus,1 = For permissions, 2 = For Dictionaries
|
||||
* @param int $number 0 = For Menus, 1 = For permissions, 2 = For Dictionaries
|
||||
* @return int 1 if OK , -1 if KO
|
||||
*/
|
||||
function checkExistComment($file, $number)
|
||||
|
|
@ -475,10 +475,12 @@ function checkExistComment($file, $number)
|
|||
$content = file_get_contents($file);
|
||||
if ($number === 0) {
|
||||
$ret = 0;
|
||||
if (strpos($content, '/* BEGIN MODULEBUILDER TOPMENU MYOBJECT */') !== false) {
|
||||
if (strpos($content, '/* BEGIN MODULEBUILDER TOPMENU MYOBJECT */') !== false
|
||||
|| strpos($content, '/* BEGIN MODULEBUILDER TOPMENU */') !== false) {
|
||||
$ret++;
|
||||
}
|
||||
if (strpos($content, '/* END MODULEBUILDER TOPMENU MYOBJECT */') !== false) {
|
||||
if (strpos($content, '/* END MODULEBUILDER TOPMENU MYOBJECT */') !== false
|
||||
|| strpos($content, '/* END MODULEBUILDER TOPMENU */') !== false) {
|
||||
$ret++;
|
||||
}
|
||||
if (strpos($content, '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */') !== false) {
|
||||
|
|
@ -844,29 +846,43 @@ function deletePropsAndPermsFromDoc($file, $objectname)
|
|||
/**
|
||||
* Search a string and return all lines needed from file. Does not include line $start nor $end
|
||||
*
|
||||
* @param string $file file for searching
|
||||
* @param string $start start line if exist
|
||||
* @param string $end end line if exist
|
||||
* @return string return the content needed
|
||||
* @param string $file file for searching
|
||||
* @param string $start start line if exist
|
||||
* @param string $end end line if exist
|
||||
* @param string $excludestart Ignore if start line is $excludestart
|
||||
* @param int $includese Include start and end line
|
||||
* @return string Return the lines between first line with $start and $end. "" if not found.
|
||||
*/
|
||||
function getFromFile($file, $start, $end)
|
||||
function getFromFile($file, $start, $end, $excludestart = '', $includese = 0)
|
||||
{
|
||||
$i = 1;
|
||||
$keys = array();
|
||||
$lines = file($file);
|
||||
// Search for start and end lines
|
||||
foreach ($lines as $i => $line) {
|
||||
if (strpos($line, $start) !== false) {
|
||||
// Copy lines until the end on array
|
||||
while (($line = $lines[++$i]) !== false) {
|
||||
if (strpos($line, $end) !== false) {
|
||||
break;
|
||||
|
||||
//$lines = file(dol_osencode($file));
|
||||
$fhandle = fopen(dol_osencode($file), 'r');
|
||||
if ($fhandle) {
|
||||
// Search for start and end lines
|
||||
//foreach ($lines as $i => $line) {
|
||||
while ($line = fgets($fhandle)) {
|
||||
if (strpos($line, $start) !== false && (empty($excludestart) || strpos($line, $excludestart) === false)) {
|
||||
if ($includese) {
|
||||
$keys[] = $line;
|
||||
}
|
||||
$keys[] = $line;
|
||||
// Copy lines until we reach the end
|
||||
while (($line = fgets($fhandle)) !== false) {
|
||||
if (strpos($line, $end) !== false) {
|
||||
if ($includese) {
|
||||
$keys[] = $line;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$keys[] = $line;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose($fhandle);
|
||||
|
||||
$content = implode("", $keys);
|
||||
return $content;
|
||||
}
|
||||
|
|
@ -1093,10 +1109,10 @@ function removeObjectFromApiFile($file, $objects, $objectname)
|
|||
|
||||
/**
|
||||
* @param string $file path of filename
|
||||
* @param array<int,array{fk_menu:string,type:string,titre:string,mainmenu:string,leftmenu:string,url:string,langs:string,position:int,enabled:int,perms:string,target:string,user:int}> $menus all menus for module
|
||||
* @param array<int,array{commentgroup:string,fk_menu:string,type:string,titre:string,mainmenu:string,leftmenu:string,url:string,langs:string,position:int,enabled:int,perms:string,target:string,user:int}> $menus all menus for module
|
||||
* @param mixed|null $menuWantTo menu get for do actions
|
||||
* @param int|null $key key for the concerned menu
|
||||
* @param int<-1,2> $action for specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object)
|
||||
* @param int<-1,2> $action for specify what action (0 = delete perm, 1 = add perm, 2 = update perm, -1 = when we delete object)
|
||||
* @return int<-1,1> 1 if OK, -1 if KO
|
||||
*/
|
||||
function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
|
||||
|
|
@ -1106,6 +1122,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
|
|||
if (!file_exists($file)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($action == 0 && !empty($key)) {
|
||||
// delete menu manually
|
||||
array_splice($menus, array_search($menus[$key], $menus), 1);
|
||||
|
|
@ -1144,19 +1161,23 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
|
|||
$errors++;
|
||||
}
|
||||
if (!$errors) {
|
||||
// delete All LEFT Menus
|
||||
$beginMenu = '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */';
|
||||
$endMenu = '/* END MODULEBUILDER LEFTMENU MYOBJECT */';
|
||||
$allMenus = getFromFile($file, $beginMenu, $endMenu);
|
||||
dolReplaceInFile($file, array($allMenus => ''));
|
||||
// delete All LEFT Menus (except for commented template MYOBJECT)
|
||||
$beginMenu = '/* BEGIN MODULEBUILDER LEFTMENU';
|
||||
$excludeBeginMenu = '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT';
|
||||
$endMenu = '/* END MODULEBUILDER LEFTMENU';
|
||||
$protection = 0;
|
||||
while ($protection <= 1000 && $allMenus = getFromFile($file, $beginMenu, $endMenu, $excludeBeginMenu, 1)) {
|
||||
$protection++;
|
||||
dolReplaceInFile($file, array($allMenus => ''));
|
||||
}
|
||||
|
||||
//prepare each menu and stock them in string
|
||||
// forge the menu code in a string
|
||||
$str_menu = "";
|
||||
foreach ($menus as $index => $menu) {
|
||||
$menu['position'] = "1000 + \$r";
|
||||
if ($menu['type'] === 'left') {
|
||||
$start = "\t\t".'/* LEFTMENU '.strtoupper($menu['titre']).' */';
|
||||
$end = "\t\t".'/* END LEFTMENU '.strtoupper($menu['titre']).' */';
|
||||
$start = "\t\t".'/* BEGIN MODULEBUILDER LEFTMENU '.strtoupper(empty($menu['object']) ? $menu['titre'] : $menu['object']).' */';
|
||||
$end = "\t\t".'/* END MODULEBUILDER LEFTMENU '.strtoupper(empty($menu['object']) ? $menu['titre'] : $menu['object']).' */';
|
||||
|
||||
$val_actuel = $menu;
|
||||
$next_val = empty($menus[$index + 1]) ? null : $menus[$index + 1];
|
||||
|
|
@ -1176,6 +1197,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
|
|||
$str_menu .= "\t\t\t 'perms' => '".dol_escape_php($menu['perms'], 1)."',\n";
|
||||
$str_menu .= "\t\t\t 'target' => '".dol_escape_php($menu['target'], 1)."',\n";
|
||||
$str_menu .= "\t\t\t 'user' => ".((int) $menu['user']).",\n";
|
||||
$str_menu .= "\t\t\t 'object' => '".dol_escape_php($menu['object'], 1)."',\n";
|
||||
$str_menu .= "\t\t);\n";
|
||||
|
||||
if (is_null($next_val) || $val_actuel['leftmenu'] !== $next_val['leftmenu']) {
|
||||
|
|
@ -1184,7 +1206,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
|
|||
}
|
||||
}
|
||||
|
||||
dolReplaceInFile($file, array($beginMenu => $beginMenu."\n".$str_menu."\n"));
|
||||
dolReplaceInFile($file, array('/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */' => $str_menu."\n\t\t/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */"));
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1057,7 +1057,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||
dol_mkdir($destdir.'/scripts');
|
||||
dol_mkdir($destdir.'/sql');
|
||||
|
||||
// Scan dir class to find if an object with same name already exists.
|
||||
// Scan dir class to find if an object with the same name already exists.
|
||||
if (!$error) {
|
||||
$dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
|
||||
$alreadyfound = false;
|
||||
|
|
@ -1072,7 +1072,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||
}
|
||||
}
|
||||
|
||||
// If we must reuse a table for properties, define $stringforproperties
|
||||
// If we must reuse an existing table for properties, define $stringforproperties
|
||||
$stringforproperties = '';
|
||||
$tablename = GETPOST('initfromtablename', 'alpha');
|
||||
if ($tablename) {
|
||||
|
|
@ -1479,38 +1479,41 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||
'langs'=>'mymodule@mymodule',
|
||||
'position'=>1000+\$r,
|
||||
'enabled'=>'isModEnabled(\"mymodule\")',
|
||||
'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
|
||||
'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
|
||||
'target'=>'',
|
||||
'user'=>2,
|
||||
'object'=>'MyObject'
|
||||
);
|
||||
\$this->menu[\$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
|
||||
'type'=>'left',
|
||||
'titre'=>'List MyObject',
|
||||
'mainmenu'=>'mymodule',
|
||||
'leftmenu'=>'mymodule_myobject_list',
|
||||
'url'=>'/mymodule/myobject_list.php',
|
||||
'langs'=>'mymodule@mymodule',
|
||||
'position'=>1000+\$r,
|
||||
'enabled'=>'isModEnabled(\"mymodule\")',
|
||||
'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
|
||||
'target'=>'',
|
||||
'user'=>2,
|
||||
\$this->menu[\$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
|
||||
'type'=>'left',
|
||||
'titre'=>'List MyObject',
|
||||
'mainmenu'=>'mymodule',
|
||||
'leftmenu'=>'mymodule_myobject_list',
|
||||
'url'=>'/mymodule/myobject_list.php',
|
||||
'langs'=>'mymodule@mymodule',
|
||||
'position'=>1000+\$r,
|
||||
'enabled'=>'isModEnabled(\"mymodule\")',
|
||||
'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
|
||||
'target'=>'',
|
||||
'user'=>2,
|
||||
'object'=>'MyObject'
|
||||
);
|
||||
\$this->menu[\$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
|
||||
'type'=>'left',
|
||||
'titre'=>'New MyObject',
|
||||
'mainmenu'=>'mymodule',
|
||||
'leftmenu'=>'mymodule_myobject_new',
|
||||
'url'=>'/mymodule/myobject_card.php?action=create',
|
||||
'langs'=>'mymodule@mymodule',
|
||||
'position'=>1000+\$r,
|
||||
'enabled'=>'isModEnabled(\"mymodule\")',
|
||||
'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"write\")',
|
||||
'target'=>'',
|
||||
'user'=>2
|
||||
);\n";
|
||||
\$this->menu[\$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
|
||||
'type'=>'left',
|
||||
'titre'=>'New MyObject',
|
||||
'mainmenu'=>'mymodule',
|
||||
'leftmenu'=>'mymodule_myobject_new',
|
||||
'url'=>'/mymodule/myobject_card.php?action=create',
|
||||
'langs'=>'mymodule@mymodule',
|
||||
'position'=>1000+\$r,
|
||||
'enabled'=>'isModEnabled(\"mymodule\")',
|
||||
'perms'=>'".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "write")' : '1')."',
|
||||
'target'=>'',
|
||||
'user'=>2,
|
||||
'object'=>'MyObject'
|
||||
);";
|
||||
$stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
|
||||
$stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
|
||||
$stringtoadd = preg_replace('/myobject/', strtolower($objectname), $stringtoadd);
|
||||
|
|
@ -1545,7 +1548,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||
$warning++;
|
||||
setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), basename($moduledescriptorfile)), null, 'warnings');
|
||||
} else {
|
||||
$arrayofreplacement = array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */');
|
||||
$arrayofreplacement = array('/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */' => '/* BEGIN MODULEBUILDER LEFTMENU '.strtoupper($objectname).' */'.$stringtoadd."\n\t\t".'/* END MODULEBUILDER LEFTMENU '.strtoupper($objectname).' */'."\n\t\t".'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */');
|
||||
dolReplaceInFile($moduledescriptorfile, $arrayofreplacement);
|
||||
}
|
||||
}
|
||||
|
|
@ -3345,7 +3348,7 @@ if ($module == 'initmodule') {
|
|||
|
||||
print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
|
||||
|
||||
print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
|
||||
print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="" autofocus>';
|
||||
print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
|
||||
print '</form>';
|
||||
} elseif (!empty($module)) {
|
||||
|
|
@ -4057,7 +4060,7 @@ if ($module == 'initmodule') {
|
|||
|
||||
print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
|
||||
|
||||
print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
|
||||
print '<input type="text" name="objectname" value="" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'" autofocus>';
|
||||
print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
|
||||
print '</form>';
|
||||
} else {
|
||||
|
|
@ -5402,7 +5405,7 @@ if ($module == 'initmodule') {
|
|||
print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
|
||||
if ($menu['titre'] != 'Module'.$module.'Name') {
|
||||
print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode((string) ($i)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)).'">'.img_edit().'</a>';
|
||||
print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletemenu&token='.newToken().'&menukey='.urlencode((string) ($i - 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)).'">'.img_delete().'</a>';
|
||||
print '<a class="deletefielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletemenu&token='.newToken().'&menukey='.urlencode((string) ($i - 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'">'.img_delete().'</a>';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ class modMyModule extends DolibarrModules
|
|||
|
||||
// Add here entries to declare new menus
|
||||
|
||||
/* BEGIN MODULEBUILDER TOPMENU MYOBJECT */
|
||||
/* BEGIN MODULEBUILDER TOPMENU */
|
||||
$this->menu[$r++] = array(
|
||||
'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
'type'=>'top', // This is a Top menu entry
|
||||
|
|
@ -325,7 +325,7 @@ class modMyModule extends DolibarrModules
|
|||
'target'=>'',
|
||||
'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
|
||||
);
|
||||
/* END MODULEBUILDER TOPMENU MYOBJECT */
|
||||
/* END MODULEBUILDER TOPMENU */
|
||||
|
||||
/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */
|
||||
/*
|
||||
|
|
@ -343,6 +343,7 @@ class modMyModule extends DolibarrModules
|
|||
'perms'=>'$user->hasRight("mymodule", "myobject", "read")',
|
||||
'target'=>'',
|
||||
'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
|
||||
'object'=>'MyObject'
|
||||
);
|
||||
$this->menu[$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
|
|
@ -357,6 +358,7 @@ class modMyModule extends DolibarrModules
|
|||
'perms'=>'$user->hasRight("mymodule", "myobject", "write")'
|
||||
'target'=>'',
|
||||
'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
|
||||
'object'=>'MyObject'
|
||||
);
|
||||
$this->menu[$r++]=array(
|
||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||
|
|
@ -371,6 +373,7 @@ class modMyModule extends DolibarrModules
|
|||
'perms'=>'$user->hasRight("mymodule", "myobject", "read")'
|
||||
'target'=>'',
|
||||
'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
|
||||
'object'=>'MyObject'
|
||||
);
|
||||
*/
|
||||
/* END MODULEBUILDER LEFTMENU MYOBJECT */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user