Changes

Jump to navigation Jump to search
Line 82: Line 82:  
=== Test your .sql files ===
 
=== Test your .sql files ===
   −
Once the files ready, you can return to Dolibarr to disable the module, drop those tables in database and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs.
+
Once the files ready, you can return to Dolibarr to disable the module, drop those tables in the database and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs.
    
=== Generate the PHP DAO class ===
 
=== Generate the PHP DAO class ===
Line 96: Line 96:  
A file '''out.tablename_script.php''' has been generated and contains a sample code to use the class for each of the 4 CRUD methods.
 
A file '''out.tablename_script.php''' has been generated and contains a sample code to use the class for each of the 4 CRUD methods.
   −
'''Since Dolibarr 6.0, the file dev/skeletons/build_class_from_table.php is no more provided. To build a class from a table you should use the ModuleBuilder modules provided as standard module.'''
+
'''Since Dolibarr 6.0, the file dev/skeletons/build_class_from_table.php is no more provided. To build a class from a table you should use the ModuleBuilder modules provided as a standard module.'''
    
== The tab management (optional) ==
 
== The tab management (optional) ==
Line 114: Line 114:  
The table should contain a list of strings, each string representing a new tab.  
 
The table should contain a list of strings, each string representing a new tab.  
 
The format of the string consisting of 5 parts separated by ":"
 
The format of the string consisting of 5 parts separated by ":"
* Part 1: The element type (objecttype) where the tab should appear is a value from the following:
+
* Part 1: The element type (object type) where the tab should appear is a value from the following:
 
{{TemplateModuleTabs}}
 
{{TemplateModuleTabs}}
 
* Part 2: A code to identify tab to add (start with +) or to remove (start with -)
 
* Part 2: A code to identify tab to add (start with +) or to remove (start with -)
Line 120: Line 120:  
* Part 4: The name of the file "*.lang" which contains correspondence between the code translation and language to display. If this name is followed with @mymodule, Dolibarr will search translation file "*.lang" within the module, so htdocs/mymodule/langs/code_CODE/mylangfile.lang, otherwise Dolibarr will look for file htdocs/langs/code_CODE/mylangfile.lang  
 
* Part 4: The name of the file "*.lang" which contains correspondence between the code translation and language to display. If this name is followed with @mymodule, Dolibarr will search translation file "*.lang" within the module, so htdocs/mymodule/langs/code_CODE/mylangfile.lang, otherwise Dolibarr will look for file htdocs/langs/code_CODE/mylangfile.lang  
 
* Part 5: A condition to test if tab must be visible. Put 1 to be always visible.
 
* Part 5: A condition to test if tab must be visible. Put 1 to be always visible.
* Part 6: The url of the page to display when you click on the tab. The __ID__ string will be replaced automatically by the Id of the element concerned.
+
* Part 6: The URL of the page to display when you click on the tab. The __ID__ string will be replaced automatically by the Id of the element concerned.
    
To feed the contents of the tab with data from the database, see the next chapter.
 
To feed the contents of the tab with data from the database, see the next chapter.
    
=== Show tabs navigation into your own pages ===
 
=== Show tabs navigation into your own pages ===
'''When''': To show all standard tabs of an object (produit, tiers, etc.) on your page.
+
'''When''': To show all standard tabs of an object (product, tiers, etc.) on your page.
    
You must follow these steps :
 
You must follow these steps :
Line 148: Line 148:  
'''2. Create and load the object to show into your tab'''
 
'''2. Create and load the object to show into your tab'''
   −
Create an instance of object of the correct class and load object from the database by using the fetch method of object in providing to this method the id you get from url (ie : /mytab.php?id=1).
+
Create an instance of an object of the correct class and load object from the database by using the fetch method of an object in providing to this method the id you get from URL (ie : /mytab.php?id=1).
    
''Example :''
 
''Example :''
Line 160: Line 160:  
'''3. Get a list of all tabs to show for your object type'''
 
'''3. Get a list of all tabs to show for your object type'''
   −
Use function XXX_prepare_head($obj), where XXX is name of object. This will return an array with all definition of tab entries to show. The parameter to put into this method is the instance of object you want tabs.
+
Use function XXX_prepare_head($obj), where XXX is name of object. This will return an array with all definition of tab entries to show. The parameter to put into this method is the instance of an object you want tabs.
    
The resulting array has the following structure
 
The resulting array has the following structure
Line 225: Line 225:  
It's in the main.inc.php file that is loaded technical environment variables and permissions. The following variables are objects positioned in this file:
 
It's in the main.inc.php file that is loaded technical environment variables and permissions. The following variables are objects positioned in this file:
   −
* $user    Objet that contains the characteristics of the user + his permissions.
+
* $user    Object that contains the characteristics of the user + his permissions.
* $conf    Objet that contains Dolibarr configuration.
+
* $conf    Object that contains Dolibarr configuration.
* $db      Objet that contains an opened connection handler to the database.
+
* $db      Object that contains an opened connection handler to the database.
* $langs  Objet that contains the user's language.
+
* $langs  Object that contains the user's language.
    
Then enter your code to display the page.
 
Then enter your code to display the page.
Line 245: Line 245:     
=== Add some fields into existing forms ===
 
=== Add some fields into existing forms ===
You may want to provide a module that add more fields into forms (input and view) of some elements.  
+
You may want to provide a module that adds more fields into forms (input and view) of some elements.  
   −
A heavy solution (but not so bad) may be to replace all pages used to create element (this means to disable the "New element" menu entry and adding yours, and disable tab that shows element to replace with a tab that is your own full page (copied/pasted from original) to do same than original page but modified to add your fields and stored added data into your own table). Go to menu [[#Define your entries in menu (optional)]] and [[#The tab management (optional)]] if this solution suits you (this solution is more powerful since you can change everything you want into page).  
+
A heavy solution (but not so bad) may be to replace all pages used to create element (this means to disable the "New element" menu entry and adding yours, and disable tab that shows element to replace with a tab that is your own full page (copied/pasted from original) to do same than original page but modified to add your fields and stored added data into your own table). Go to menu [[#Define your entries in the menu (optional)]] and [[#The tab management (optional)]] if this solution suits you (this solution is more powerful since you can change everything you want into the page).  
    
We will describe here another solution, that works only to "add fields" at end of existing fields, using the element "category" as an example but you can convert this tutorial for invoice, proposal ...
 
We will describe here another solution, that works only to "add fields" at end of existing fields, using the element "category" as an example but you can convert this tutorial for invoice, proposal ...
Line 264: Line 264:     
=== Database access ===
 
=== Database access ===
If you need to edit some data in database inside you own table, use the PHP class generated before.
+
If you need to edit some data in the database inside your own table, use the PHP class generated before.
    
If you to make access to tables with no dedicated PHP class available, this is always possible (for example if you want to get a list of records with a particular join or filter). In this case, this is a code samples to follow:
 
If you to make access to tables with no dedicated PHP class available, this is always possible (for example if you want to get a list of records with a particular join or filter). In this case, this is a code samples to follow:
Line 338: Line 338:     
=== Modify the descriptor file of your module ===
 
=== Modify the descriptor file of your module ===
Then, within the descriptor file of your module, modify the variable '''config_page_url''' to set name of this PHP page.
+
Then, within the descriptor file of your module, modify the variable '''config_page_url''' to set the name of this PHP page.
 
If the page is in the directory '''admin/''', then the path is not required, e.g. like this:
 
If the page is in the directory '''admin/''', then the path is not required, e.g. like this:
 
<source lang="php">
 
<source lang="php">
Line 355: Line 355:     
=== Define your menu entries ===
 
=== Define your menu entries ===
For this, you must define into the module descriptor, the array this->menu that declare all menus added by your module.
+
For this, you must define into the module descriptor, the array this->menu that declares all menus added by your module.
 
This array contains entries that will appear once your module is activated.
 
This array contains entries that will appear once your module is activated.
 
The example module descriptor file '''modMyModule.class.php''' contains an example to declare a top menu and also its left menu entries.
 
The example module descriptor file '''modMyModule.class.php''' contains an example to declare a top menu and also its left menu entries.
Line 397: Line 397:  
</source>
 
</source>
   −
To show menu or not depending on a permission, modify property '''perms''' in array. See chapter on permissions later to see how to add permissions.
+
To show the menu or not depending on a permission, modify property '''perms''' in the array. See chapter on permissions later to see how to add permissions.
    
=== Test your menu entries ===
 
=== Test your menu entries ===
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).
+
Disable and re-enable your module under the Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).
    
== Add your own permissions (optional) ==
 
== Add your own permissions (optional) ==
Line 424: Line 424:     
Into $this->rights[$r][0], put a permission id not already used (See into menu '''System info''' on a working installation of Dolibarr to know list of id already used by standard modules.
 
Into $this->rights[$r][0], put a permission id not already used (See into menu '''System info''' on a working installation of Dolibarr to know list of id already used by standard modules.
Into $this->rights[$r][3], put 1 if this permission must be granted automatically by default to any new created user.
+
Into $this->rights[$r][3], put 1 if this permission must be granted automatically by default to any newly created user.
 
Into $this->rights[$r][1], put a label by default for permission (This label will be used if no translation can be found into the file '''admin.lang''').
 
Into $this->rights[$r][1], put a label by default for permission (This label will be used if no translation can be found into the file '''admin.lang''').
 
Into $this->rights[$r][4] and $this->rights[$r][5], put an action and subaction string without spaces. You will be able to test if a user has the permission in your PHP source code with the sequence:
 
Into $this->rights[$r][4] and $this->rights[$r][5], put an action and subaction string without spaces. You will be able to test if a user has the permission in your PHP source code with the sequence:
Line 432: Line 432:  
</source>
 
</source>
   −
== Define you own box (optional) ==
+
== Define your own box (optional) ==
'''When''': If your module need to provide one or several new boxes to show on home page.
+
'''When''': If your module needs to provide one or several new boxes to show on home page.
    
=== Define your box ===
 
=== Define your box ===
Line 455: Line 455:  
Go into menu '''Home - Setup - Boxes'''.
 
Go into menu '''Home - Setup - Boxes'''.
   −
Your boxes must appear in the list of boxes you can activated. Activate the box and go on home page to see if the box is showing correctly.
+
Your boxes must appear in the list of boxes you can activate. Activate the box and go on the home page to see if the box is showing correctly.
    
== Define your own export (optional) ==
 
== Define your own export (optional) ==
'''When''': If your module provide new predefined database export profiles (for its own tables or for already existing tables of another module).
+
'''When''': If your module provides new predefined database export profiles (for its own tables or for already existing tables of another module).
    
=== Define export ===
 
=== Define export ===
Line 465: Line 465:  
=== Test your export ===
 
=== Test your export ===
 
Go into menu Tools -> Export. Your export will appear in the list of available predefined exports (if your module is enabled).
 
Go into menu Tools -> Export. Your export will appear in the list of available predefined exports (if your module is enabled).
Choose it, you must see list of all possible fields defined in the export arrays.
+
Choose it, you must see a list of all possible fields defined in the export arrays.
 
Choose on field and try to build an export file. If ok, try again with all fields.
 
Choose on field and try to build an export file. If ok, try again with all fields.
   Line 485: Line 485:  
Disable and enable your module.
 
Disable and enable your module.
   −
Go on home page (index.php). Show the HTML source of the page.
+
Go on the home page (index.php). Show the HTML source of the page.
   −
You should see into the HTML header, a line that declare your style sheet.
+
You should see into the HTML header, a line that declares your style sheet.
    
== Add your Javascript functions (optional) ==
 
== Add your Javascript functions (optional) ==
 
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
 
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
   −
If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions, defined into your javascript file '''htdocs/mymodule/js/mymodule.js''', included into the HTML HEAD section.
+
If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions, defined into your javascript file '''htdocs/mymodule/js/mymodule.js''', included into the HTML HEAD section.
 
To ask Dolibarr that forge this header to include your own javascript file, you must just provide it to the llxHeader() function called by your page.
 
To ask Dolibarr that forge this header to include your own javascript file, you must just provide it to the llxHeader() function called by your page.
   Line 508: Line 508:     
== Insert your code inside Dolibarr hooks positions (optional) ==
 
== Insert your code inside Dolibarr hooks positions (optional) ==
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See previous chapter for adding code during a business event).
+
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See the previous chapter for adding code during a business event).
    
See page [[Hooks_system]].
 
See page [[Hooks_system]].
Line 514: Line 514:     
== Add your own numbering rules ==
 
== Add your own numbering rules ==
'''When''': When you need a new rule for generated ref of elements that is not covered by existing rules.
+
'''When''': When you need a new rule for generated ref of elements that are not covered by existing rules.
    
See page [[Create numbering module]].
 
See page [[Create numbering module]].
15

edits

Navigation menu