dolibarr 18.0.6
modApi.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
5 * Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29
30
35{
41 public function __construct($db)
42 {
43 global $langs, $conf;
44
45 $this->db = $db;
46
47 // Id for module (must be unique).
48 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49 $this->numero = 2610;
50 // Key text used to identify module (for permissions, menus, etc...)
51 $this->rights_class = 'api';
52
53 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
54 // It is used to group modules in module setup page
55 $this->family = "interface";
56 $this->module_position = '24';
57 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
58 $this->name = preg_replace('/^mod/i', '', get_class($this));
59 // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
60 $this->description = "REST interface";
61 // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
62 $this->version = 'dolibarr';
63 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
64 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65 // Can be enabled / disabled only in the main company with superadmin account
66 $this->core_enabled = 1;
67 // Name of image file used for this module.
68 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
69 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
70 $this->picto = 'technic';
71
72 $this->module_parts = array();
73
74 // Data directories to create when module is enabled.
75 // Example: this->dirs = array("/api/temp");
76 $this->dirs = array('/api/temp');
77
78 // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module.
79 $this->config_page_url = array("index.php@api");
80
81 // Dependencies
82 $this->hidden = false; // A condition to hide module
83 $this->depends = array(); // List of modules id that must be enabled if this module is enabled
84 $this->requiredby = array('modZapier'); // List of modules id to disable if this one is disabled
85 $this->conflictwith = array(); // List of modules id this module is in conflict with
86 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
87 $this->langfiles = array("other");
88
89 // Constants
90 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
91 // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
92 // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
93 // );
94 $this->const = array();
95
96 // Array to add new pages in new tabs
97 // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->rights->api->read:/api/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
98 // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@api:$user->rights->othermodule->read:/api/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
99 // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
100 // where objecttype can be
101 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
102 // 'contact' to add a tab in contact view
103 // 'contract' to add a tab in contract view
104 // 'group' to add a tab in group view
105 // 'intervention' to add a tab in intervention view
106 // 'invoice' to add a tab in customer invoice view
107 // 'invoice_supplier' to add a tab in supplier invoice view
108 // 'member' to add a tab in fundation member view
109 // 'opensurveypoll' to add a tab in opensurvey poll view
110 // 'order' to add a tab in sales order view
111 // 'order_supplier' to add a tab in supplier order view
112 // 'payment' to add a tab in payment view
113 // 'payment_supplier' to add a tab in supplier payment view
114 // 'product' to add a tab in product view
115 // 'propal' to add a tab in propal view
116 // 'project' to add a tab in project view
117 // 'stock' to add a tab in stock view
118 // 'thirdparty' to add a tab in third party view
119 // 'user' to add a tab in user view
120 $this->tabs = array();
121
122 // Dictionaries
123 if (!isset($conf->api->enabled)) {
124 $conf->api = new stdClass();
125 $conf->api->enabled = 0;
126 }
127 $this->dictionaries = array();
128
129 // Boxes
130 // Add here list of php file(s) stored in core/boxes that contains class to show a box.
131 $this->boxes = array(); // List of boxes
132 // Example:
133 //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
134
135 // Permissions
136 $this->rights = array(); // Permission array used by this module
137 $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
138
139 $r = 0;
140
141 // Add here list of permission defined by an id, a label, a boolean and two constant strings.
142 // Example:
143 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
144 $this->rights[$r][1] = 'Generate/modify users API key'; // Permission label
145 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
146 $this->rights[$r][4] = 'apikey'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
147 $this->rights[$r][5] = 'generate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
148 $r++;
149
150
151 // Main menu entries
152 $this->menu = array(); // List of menus to add
153 $r = 0;
154
155 $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=tools',
156 'type'=>'left',
157 'titre'=>'ApiExplorer',
158 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
159 'mainmenu'=>'tools',
160 'leftmenu'=>'devtools_api',
161 'url'=>'/api/index.php/explorer',
162 'langs'=>'modulebuilder',
163 'position'=>100,
164 'perms'=>'1',
165 //'enabled'=>'isModEnabled("api") && preg_match(\'/^(devtools)/\',$leftmenu)',
166 'enabled'=>'isModEnabled("api")',
167 'target'=>'_apiexplorer',
168 'user'=>0);
169
170
171 // Exports
172 $r = 1;
173
174 // Example:
175 // $this->export_code[$r]=$this->rights_class.'_'.$r;
176 // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
177 // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
178 // $this->export_permission[$r]=array(array("facture","facture","export"));
179 // $this->export_fields_array[$r]=array(
180 // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
181 // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
182 // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
183 // 'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
184 // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
185 // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
186 // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
187 //);
188 // $this->export_entities_array[$r]=array(
189 // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
190 // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
191 // 'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",
192 // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
193 // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
194 // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
195 //);
196 // $this->export_sql_start[$r]='SELECT DISTINCT ';
197 // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
198 // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
199 // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
200 // $this->export_sql_order[$r] .=' ORDER BY s.nom';
201 // $r++;
202 }
203
212 public function init($options = '')
213 {
214 $sql = array();
215
216 return $this->_init($sql, $options);
217 }
218
227 public function remove($options = '')
228 {
229 // Remove old constants with entity fields different of 0
230 $sql = array(
231 "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_API'), // API can't be enabled per environment. Why ?
232 "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('API_PRODUCTION_MODE') // Not in production mode by default at activation
233 );
234
235 return $this->_remove($sql, $options);
236 }
237}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Description and activation class for module Api.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123