Work on modulebuilder
This commit is contained in:
parent
ff9a62e519
commit
a630e665d9
@ -280,7 +280,7 @@ interface Database
|
|||||||
/**
|
/**
|
||||||
* Create a table into database
|
* Create a table into database
|
||||||
*
|
*
|
||||||
* @param string $table Nom de la table
|
* @param string $table Name of table
|
||||||
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
|
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
|
||||||
* @param string $primary_key Nom du champ qui sera la clef primaire
|
* @param string $primary_key Nom du champ qui sera la clef primaire
|
||||||
* @param string $type Type de la table
|
* @param string $type Type de la table
|
||||||
@ -291,6 +291,14 @@ interface Database
|
|||||||
*/
|
*/
|
||||||
function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null);
|
function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop a table into database
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function DDLDropTable($table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of available charset that can be used to store data in database
|
* Return list of available charset that can be used to store data in database
|
||||||
*
|
*
|
||||||
|
|||||||
@ -863,6 +863,22 @@ class DoliDBMssql extends DoliDB
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop a table into database
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function DDLDropTable($table)
|
||||||
|
{
|
||||||
|
$sql = "DROP TABLE ".$table;
|
||||||
|
|
||||||
|
if (! $this->query($sql))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a pointer of line with description of a table or field
|
* Return a pointer of line with description of a table or field
|
||||||
*
|
*
|
||||||
|
|||||||
@ -629,7 +629,7 @@ class DoliDBMysqli extends DoliDB
|
|||||||
/**
|
/**
|
||||||
* Create a table into database
|
* Create a table into database
|
||||||
*
|
*
|
||||||
* @param string $table Nom de la table
|
* @param string $table Name of table
|
||||||
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
|
* @param array $fields Tableau associatif [nom champ][tableau des descriptions]
|
||||||
* @param string $primary_key Nom du champ qui sera la clef primaire
|
* @param string $primary_key Nom du champ qui sera la clef primaire
|
||||||
* @param string $type Type de la table
|
* @param string $type Type de la table
|
||||||
@ -702,13 +702,28 @@ class DoliDBMysqli extends DoliDB
|
|||||||
$sql .= ",".implode(',',$sqlk);
|
$sql .= ",".implode(',',$sqlk);
|
||||||
$sql .=") engine=".$type;
|
$sql .=") engine=".$type;
|
||||||
|
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
if(! $this->query($sql))
|
||||||
if(! $this -> query($sql))
|
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop a table into database
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function DDLDropTable($table)
|
||||||
|
{
|
||||||
|
$sql = "DROP TABLE ".$table;
|
||||||
|
|
||||||
|
if (! $this->query($sql))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a pointer of line with description of a table or field
|
* Return a pointer of line with description of a table or field
|
||||||
*
|
*
|
||||||
|
|||||||
@ -999,6 +999,22 @@ class DoliDBPgsql extends DoliDB
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop a table into database
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function DDLDropTable($table)
|
||||||
|
{
|
||||||
|
$sql = "DROP TABLE ".$table;
|
||||||
|
|
||||||
|
if (! $this->query($sql))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a user to connect to database
|
* Create a user to connect to database
|
||||||
*
|
*
|
||||||
|
|||||||
@ -945,6 +945,22 @@ class DoliDBSqlite3 extends DoliDB
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop a table into database
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function DDLDropTable($table)
|
||||||
|
{
|
||||||
|
$sql = "DROP TABLE ".$table;
|
||||||
|
|
||||||
|
if (! $this->query($sql))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a pointer of line with description of a table or field
|
* Return a pointer of line with description of a table or field
|
||||||
*
|
*
|
||||||
|
|||||||
@ -89,3 +89,6 @@ TryToUseTheModuleBuilder=If you have knowledge in SQL and PHP, you can try to us
|
|||||||
SeeTopRightMenu=See <span class="fa fa-bug"></span> on the top right menu
|
SeeTopRightMenu=See <span class="fa fa-bug"></span> on the top right menu
|
||||||
AddLanguageFile=Add language file
|
AddLanguageFile=Add language file
|
||||||
YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages")
|
YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages")
|
||||||
|
DropTableIfEmpty=(Delete table if empty)
|
||||||
|
TableDoesNotExists=The table %s does not exists
|
||||||
|
TableDropped=Table %s deleted
|
||||||
@ -371,6 +371,51 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && ! empty($tabobj))
|
||||||
|
{
|
||||||
|
$objectname = $tabobj;
|
||||||
|
|
||||||
|
$arrayoftables=array();
|
||||||
|
if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
|
||||||
|
if ($action == 'droptableextrafields') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
|
||||||
|
|
||||||
|
foreach($arrayoftables as $tabletodrop)
|
||||||
|
{
|
||||||
|
$nb = -1;
|
||||||
|
$sql="SELECT COUNT(*) as nb FROM ".$tabletodrop;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
if ($obj)
|
||||||
|
{
|
||||||
|
$nb = $obj->nb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE')
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($nb == 0)
|
||||||
|
{
|
||||||
|
$resql=$db->DDLDropTable($tabletodrop);
|
||||||
|
//var_dump($resql);
|
||||||
|
setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
|
||||||
|
}
|
||||||
|
elseif ($nb > 0)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
|
if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
|
||||||
{
|
{
|
||||||
$objectname = $tabobj;
|
$objectname = $tabobj;
|
||||||
@ -1515,6 +1560,7 @@ elseif (! empty($module))
|
|||||||
print '<br>';
|
print '<br>';
|
||||||
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra?'':'<strike>').$pathtosqlextra.($realpathtosqlextra?'':'</strike>').'</strong>';
|
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra?'':'<strike>').$pathtosqlextra.($realpathtosqlextra?'':'</strike>').'</strong>';
|
||||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
||||||
|
print ' <a href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=droptableextrafields">'.$langs->trans("DropTableIfEmpty").'</a>';
|
||||||
//print ' <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
|
//print ' <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey?'':'<strike>').$pathtosqlkey.($realpathtosqlkey?'':'</strike>').'</strong>';
|
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey?'':'<strike>').$pathtosqlkey.($realpathtosqlkey?'':'</strike>').'</strong>';
|
||||||
|
|||||||
@ -230,7 +230,6 @@ class modMyModule extends DolibarrModules
|
|||||||
|
|
||||||
// Add here entries to declare new menus
|
// Add here entries to declare new menus
|
||||||
|
|
||||||
// Example to declare a new Top Menu entry and its Left menu entry:
|
|
||||||
/* BEGIN MODULEBUILDER TOPMENU */
|
/* 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
|
$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
|
'type'=>'top', // This is a Top menu entry
|
||||||
@ -247,7 +246,6 @@ class modMyModule extends DolibarrModules
|
|||||||
|
|
||||||
/* END MODULEBUILDER TOPMENU */
|
/* END MODULEBUILDER TOPMENU */
|
||||||
|
|
||||||
// Example to declare a Left Menu entry into an existing Top menu entry:
|
|
||||||
/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
|
/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
|
||||||
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule', // '' 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
|
$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule', // '' 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'=>'left', // This is a Left menu entry
|
'type'=>'left', // This is a Left menu entry
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user