31,003
edits
mNo edit summary |
mNo edit summary |
||
| Line 2: | Line 2: | ||
{{TemplateDocDevEn}} | {{TemplateDocDevEn}} | ||
To create a new module/addon for Dolibarr, there is several steps. This | To create a new module/addon for Dolibarr, there is several steps. This tutorial will describe you each of them to build a module to extend Dolibarr features, like one or several of the following : | ||
* Add new tables in database | * Add new tables in database | ||
* Add your own menu entries | * Add your own menu entries | ||
| Line 15: | Line 15: | ||
= [[File:Art.png]] Create a descriptor of Module (required) = | = [[File:Art.png]] Create a descriptor of Module (required) = | ||
'''When''': Required as soon as an addon is | '''When''': Required as soon as an addon is developed, whatever is its goal. | ||
== Create your module descriptor == | == Create your module descriptor == | ||
| Line 24: | Line 24: | ||
* $this->numero = 10000 by a number of free module (Go to '''Home page -> System Information -> Dolibarr -> Modules''' to know id the list of modules used). | * $this->numero = 10000 by a number of free module (Go to '''Home page -> System Information -> Dolibarr -> Modules''' to know id the list of modules used). | ||
* Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning). | * Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning). | ||
* Create directory /htdocs/ | * Create directory /htdocs/mymodule/ | ||
Your file descriptor for your module is ready. | Your file descriptor for your module is ready. | ||
| Line 31: | Line 31: | ||
Launch Dolibarr and go to page '''Setup->module'''? You must see a new line with your new module and the possibility to activate it or not (browse all the tabs of each category of modules to find it). It's value of $this->special that determines in which tab will be your module. | Launch Dolibarr and go to page '''Setup->module'''? You must see a new line with your new module and the possibility to activate it or not (browse all the tabs of each category of modules to find it). It's value of $this->special that determines in which tab will be your module. | ||
= [[File:Art.png]] Create your SQL tables and the PHP accessor class ( | = [[File:Art.png]] Create your SQL tables and the PHP accessor class (optional) = | ||
'''When''': If your module needs to manage data of its own | '''When''': If your module needs to manage data of its own | ||
| Line 74: | Line 74: | ||
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. | ||
= [[File:Art.png]] Add your own tabs on entities sheets ( | = [[File:Art.png]] Add your own tabs on entities sheets (optional) = | ||
'''When''': To add a tab on an entity (invoices, orders, proposals, member ...) | '''When''': To add a tab on an entity (invoices, orders, proposals, member ...) | ||
| Line 90: | Line 90: | ||
// 'order' to add a tab in customer order view | // 'order' to add a tab in customer order view | ||
// 'product' to add a tab in product view | // 'product' to add a tab in product view | ||
// 'propal' to add a tab in | // 'propal' to add a tab in proposal view | ||
// 'member' to add a tab in | // 'member' to add a tab in foundation member view | ||
</source> | </source> | ||
| Line 112: | Line 112: | ||
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. | ||
= [[File:Art.png]] Create your own PHP screens ( | = [[File:Art.png]] Create your own PHP screens (optional) = | ||
'''When''': If the purpose of your module is to add features that require new screens. | '''When''': If the purpose of your module is to add features that require new screens. | ||
| Line 200: | Line 200: | ||
</source> | </source> | ||
= [[File:Art.png]] Add your own setup page ( | = [[File:Art.png]] Add your own setup page (optional) = | ||
'''When''': If your module need to ask user several parameters. | '''When''': If your module need to ask user several parameters. | ||
| Line 214: | Line 214: | ||
== Test your page == | == Test your page == | ||
Go into page '''Home->Setup->Modules''', you should see a | Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page. | ||
= [[File:Art.png]] Define your entries in menu ( | = [[File:Art.png]] Define your entries in menu (optional) = | ||
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu. | '''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu. | ||
| Line 266: | Line 266: | ||
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok). | Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok). | ||
= [[File:Art.png]] Add your own permissions ( | = [[File:Art.png]] Add your own permissions (optional) = | ||
'''When''': If you want to add new permissions. | '''When''': If you want to add new permissions. | ||
| Line 296: | Line 296: | ||
</source> | </source> | ||
= [[File:Art.png]] Define you own box ( | = [[File:Art.png]] Define you own box (optional) = | ||
'''When''': If your module need to provide one or several new boxes to show on home page. | '''When''': If your module need to provide one or several new boxes to show on home page. | ||
| Line 321: | Line 321: | ||
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 activated. Activate the box and go on home page to see if the box is showing correctly. | ||
= [[File:Art.png]] Define your own export ( | = [[File:Art.png]] 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 provide new predefined database export profiles (for its own tables or for already existing tables of another module). | ||
| Line 332: | Line 332: | ||
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. | ||
= [[File:Art.png]] Define your CSS styles ( | = [[File:Art.png]] Define your CSS styles (optional) = | ||
'''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded). | '''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded). | ||
| Line 347: | Line 347: | ||
Go on home page (index.php). Show the HTML source of the page. | Go on home page (index.php). Show the HTML source of the page. | ||
You should see into the HTML header, a | You should see into the HTML header, a line that declare your style sheet. | ||
= [[File:Art.png]] Define you Javascript functions ( | = [[File:Art.png]] Define you 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 | If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions defined into a javascript file '''mymodule.js''' to be included inside the HTML HEAD section. | ||
To ask Dolibarr that forge this header to include your own javascript file, you must just declare your file inside the module descriptor. | To ask Dolibarr that forge this header to include your own javascript file, you must just declare your file inside the module descriptor. | ||
This feature is not yet available. | This feature is not yet available. | ||
= [[File:Art.png]] Run your own code on any Dolibarr event ( | = [[File:Art.png]] Run your own code on any Dolibarr event (optional) = | ||
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''. | '''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''. | ||