dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
19  */
20 
28 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
29 
30 
34 class modApi extends DolibarrModules
35 {
41  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  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57  $this->name = preg_replace('/^mod/i','',get_class($this));
58  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59  $this->description = "REST interface";
60  // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
61  $this->version = 'dolibarr';
62  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
63  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64  // Can be enabled / disabled only in the main company with superadmin account
65  $this->core_enabled = 1;
66  // Name of image file used for this module.
67  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
68  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
69  $this->picto='technic';
70 
71  $this->module_parts = array();
72 
73  // Data directories to create when module is enabled.
74  // Example: this->dirs = array("/api/temp");
75  $this->dirs = array('/api/temp');
76 
77  // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module.
78  $this->config_page_url = array("index.php@api");
79 
80  // Dependencies
81  $this->hidden = false; // A condition to hide module
82  $this->depends = array(); // List of modules id that must be enabled if this module is enabled
83  $this->requiredby = array(); // List of modules id to disable if this one is disabled
84  $this->conflictwith = array(); // List of modules id this module is in conflict with
85  $this->phpmin = array(5,4); // Minimum version of PHP required by module
86  $this->langfiles = array("other");
87 
88  // Constants
89  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
90  // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
91  // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
92  // );
93  $this->const = array();
94 
95  // Array to add new pages in new tabs
96  // 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
97  // '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.
98  // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
99  // where objecttype can be
100  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
101  // 'contact' to add a tab in contact view
102  // 'contract' to add a tab in contract view
103  // 'group' to add a tab in group view
104  // 'intervention' to add a tab in intervention view
105  // 'invoice' to add a tab in customer invoice view
106  // 'invoice_supplier' to add a tab in supplier invoice view
107  // 'member' to add a tab in fundation member view
108  // 'opensurveypoll' to add a tab in opensurvey poll view
109  // 'order' to add a tab in customer order view
110  // 'order_supplier' to add a tab in supplier order view
111  // 'payment' to add a tab in payment view
112  // 'payment_supplier' to add a tab in supplier payment view
113  // 'product' to add a tab in product view
114  // 'propal' to add a tab in propal view
115  // 'project' to add a tab in project view
116  // 'stock' to add a tab in stock view
117  // 'thirdparty' to add a tab in third party view
118  // 'user' to add a tab in user view
119  $this->tabs = array();
120 
121  // Dictionaries
122  if (! isset($conf->api->enabled))
123  {
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  $r=0;
138 
139  // Add here list of permission defined by an id, a label, a boolean and two constant strings.
140  // Example:
141  // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
142  // $this->rights[$r][1] = 'Permision label'; // Permission label
143  // $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
144  // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
145  // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
146  // $r++;
147 
148 
149  // Main menu entries
150  $this->menu = array(); // List of menus to add
151  $r=0;
152 
153  // Add here entries to declare new menus
154  //
155  // Example to declare a new Top Menu entry and its Left menu entry:
156  // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
157  // 'type'=>'top', // This is a Top menu entry
158  // 'titre'=>'Api top menu',
159  // 'mainmenu'=>'api',
160  // 'leftmenu'=>'api',
161  // 'url'=>'/api/pagetop.php',
162  // 'langs'=>'mylangfile@api', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
163  // 'position'=>100,
164  // 'enabled'=>'$conf->api->enabled', // Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled.
165  // 'perms'=>'1', // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
166  // 'target'=>'',
167  // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
168  // $r++;
169  //
170  // Example to declare a Left Menu entry into an existing Top menu entry:
171  // $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
172  // 'type'=>'left', // This is a Left menu entry
173  // 'titre'=>'Api left menu',
174  // 'mainmenu'=>'xxx',
175  // 'leftmenu'=>'api',
176  // 'url'=>'/api/pagelevel2.php',
177  // 'langs'=>'mylangfile@api', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
178  // 'position'=>100,
179  // 'enabled'=>'$conf->api->enabled', // Define condition to show or hide menu entry. Use '$conf->api->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
180  // 'perms'=>'1', // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
181  // 'target'=>'',
182  // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
183  // $r++;
184 
185 
186  // Exports
187  $r=1;
188 
189  // Example:
190  // $this->export_code[$r]=$this->rights_class.'_'.$r;
191  // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
192  // $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.
193  // $this->export_permission[$r]=array(array("facture","facture","export"));
194  // $this->export_fields_array[$r]=array(
195  // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
196  // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
197  // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
198  // 'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
199  // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
200  // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
201  // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
202  //);
203  // $this->export_entities_array[$r]=array(
204  // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
205  // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
206  // 'f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",
207  // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
208  // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
209  // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
210  //);
211  // $this->export_sql_start[$r]='SELECT DISTINCT ';
212  // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
213  // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
214  // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
215  // $this->export_sql_order[$r] .=' ORDER BY s.nom';
216  // $r++;
217  }
218 
227  function init($options='')
228  {
229  $sql = array();
230 
231  $result=$this->_load_tables('/api/sql/');
232 
233  return $this->_init($sql, $options);
234  }
235 
244  function remove($options = '')
245  {
246  // Remove old constants with entity fields different of 0
247  $sql = array(
248  "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('MAIN_MODULE_API', 1),
249  "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = ".$this->db->encrypt('API_PRODUCTION_MODE', 1)
250  );
251 
252  return $this->_remove($sql, $options);
253  }
254 }
255 
Class DolibarrModules.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
_remove($array_sql, $options='')
Disable function.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Description and activation class for module Api.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir)
Create tables and keys required by module.