dolibarr 21.0.0-alpha
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
29include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30
31
36{
42 public function __construct($db)
43 {
44 global $langs, $conf;
45
46 $this->db = $db;
47
48 // Id for module (must be unique).
49 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
50 $this->numero = 2610;
51 // Key text used to identify module (for permissions, menus, etc...)
52 $this->rights_class = 'api';
53
54 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
55 // It is used to group modules in module setup page
56 $this->family = "interface";
57 $this->module_position = '24';
58 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59 $this->name = preg_replace('/^mod/i', '', get_class($this));
60 // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
61 $this->description = "REST interface";
62 // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
63 $this->version = 'dolibarr';
64 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
65 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
66 // Can be enabled / disabled only in the main company with superadmin account
67 $this->core_enabled = 1;
68 // Name of image file used for this module.
69 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
70 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
71 $this->picto = 'technic';
72
73 $this->module_parts = array();
74
75 // Data directories to create when module is enabled.
76 // Example: this->dirs = array("/api/temp");
77 $this->dirs = array('/api/temp');
78
79 // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module.
80 $this->config_page_url = array("index.php@api");
81
82 // Dependencies
83 $this->hidden = false; // A condition to hide module
84 $this->depends = array(); // List of modules id that must be enabled if this module is enabled
85 $this->requiredby = array('modZapier'); // List of modules id to disable if this one is disabled
86 $this->conflictwith = array(); // List of modules id this module is in conflict with
87 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
88 $this->langfiles = array("other");
89
90 // Constants
91 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
92 // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
93 // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
94 // );
95 $this->const = array();
96
97 // Array to add new pages in new tabs
98 // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->hasRight('api','read'):/api/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
99 // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@api:$user->hasRight('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.
100 // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
101 // where objecttype can be
102 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
103 // 'contact' to add a tab in contact view
104 // 'contract' to add a tab in contract view
105 // 'group' to add a tab in group view
106 // 'intervention' to add a tab in intervention view
107 // 'invoice' to add a tab in customer invoice view
108 // 'invoice_supplier' to add a tab in supplier invoice view
109 // 'member' to add a tab in foundation member view
110 // 'opensurveypoll' to add a tab in opensurvey poll view
111 // 'order' to add a tab in sales order view
112 // 'order_supplier' to add a tab in supplier order view
113 // 'payment' to add a tab in payment view
114 // 'payment_supplier' to add a tab in supplier payment view
115 // 'product' to add a tab in product view
116 // 'propal' to add a tab in propal view
117 // 'project' to add a tab in project view
118 // 'stock' to add a tab in stock view
119 // 'thirdparty' to add a tab in third party view
120 // 'user' to add a tab in user view
121 $this->tabs = array();
122
123 // Dictionaries
124 if (!isset($conf->api->enabled)) {
125 $conf->api = new stdClass();
126 $conf->api->enabled = 0;
127 }
128 $this->dictionaries = array();
129
130 // Boxes
131 // Add here list of php file(s) stored in core/boxes that contains class to show a box.
132 $this->boxes = array(); // List of boxes
133 // Example:
134 //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
135
136 // Permissions
137 $this->rights = array(); // Permission array used by this module
138 $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled)
139
140 $r = 0;
141
142 // Add here list of permission defined by an id, a label, a boolean and two constant strings.
143 // Example:
144 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
145 $this->rights[$r][1] = 'Generate/modify users API key'; // Permission label
146 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
147 $this->rights[$r][4] = 'apikey'; // In php code, permission will be checked by test if ($user->hasRight('permkey','level1','level2'))
148 $this->rights[$r][5] = 'generate'; // In php code, permission will be checked by test if ($user->hasRight('permkey','level1','level2'))
149 $r++;
150
151
152 // Main menu entries
153 $this->menu = array(); // List of menus to add
154 $r = 0;
155
156 $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=tools',
157 'type'=>'left',
158 'titre'=>'ApiExplorer',
159 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
160 'mainmenu'=>'tools',
161 'leftmenu'=>'devtools_api',
162 'url'=>'/api/index.php/explorer',
163 'langs'=>'modulebuilder',
164 'position'=>100,
165 'perms'=>'1',
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=0, $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:140