dolibarr  7.0.0-beta
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
27 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
28 
29 
33 class modApi extends DolibarrModules
34 {
40  function __construct($db)
41  {
42  global $langs,$conf;
43 
44  $this->db = $db;
45 
46  // Id for module (must be unique).
47  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
48  $this->numero = 2610;
49  // Key text used to identify module (for permissions, menus, etc...)
50  $this->rights_class = 'api';
51 
52  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
53  // It is used to group modules in module setup page
54  $this->family = "technic";
55  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
56  $this->name = preg_replace('/^mod/i','',get_class($this));
57  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
58  $this->description = "REST interface";
59  // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
60  $this->version = 'dolibarr';
61  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
62  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
63  // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
64  $this->special = 1;
65  // Name of image file used for this module.
66  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
67  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
68  $this->picto='technic';
69 
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,3); // 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  /* Example:
129  if (! isset($conf->api->enabled)) $conf->api->enabled=0; // This is to avoid warnings
130  $this->dictionaries=array(
131  'langs'=>'mylangfile@api',
132  'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
133  'tablib'=>array("Table1","Table2","Table3"), // Label of tables
134  'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields
135  'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
136  'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
137  'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
138  'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
139  'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
140  'tabcond'=>array($conf->api->enabled,$conf->api->enabled,$conf->api->enabled) // Condition to show each dictionary
141  );
142  */
143 
144  // Boxes
145  // Add here list of php file(s) stored in core/boxes that contains class to show a box.
146  $this->boxes = array(); // List of boxes
147  // Example:
148  //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
149 
150  // Permissions
151  $this->rights = array(); // Permission array used by this module
152  $r=0;
153 
154  // Add here list of permission defined by an id, a label, a boolean and two constant strings.
155  // Example:
156  // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
157  // $this->rights[$r][1] = 'Permision label'; // Permission label
158  // $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
159  // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
160  // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
161  // $r++;
162 
163 
164  // Main menu entries
165  $this->menu = array(); // List of menus to add
166  $r=0;
167 
168  // Add here entries to declare new menus
169  //
170  // Example to declare a new Top Menu entry and its Left menu entry:
171  // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
172  // 'type'=>'top', // This is a Top menu entry
173  // 'titre'=>'Api top menu',
174  // 'mainmenu'=>'api',
175  // 'leftmenu'=>'api',
176  // 'url'=>'/api/pagetop.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.
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  // Example to declare a Left Menu entry into an existing Top menu entry:
186  // $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
187  // 'type'=>'left', // This is a Left menu entry
188  // 'titre'=>'Api left menu',
189  // 'mainmenu'=>'xxx',
190  // 'leftmenu'=>'api',
191  // 'url'=>'/api/pagelevel2.php',
192  // 'langs'=>'mylangfile@api', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
193  // 'position'=>100,
194  // '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.
195  // 'perms'=>'1', // Use 'perms'=>'$user->rights->api->level1->level2' if you want your menu with a permission rules
196  // 'target'=>'',
197  // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
198  // $r++;
199 
200 
201  // Exports
202  $r=1;
203 
204  // Example:
205  // $this->export_code[$r]=$this->rights_class.'_'.$r;
206  // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
207  // $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.
208  // $this->export_permission[$r]=array(array("facture","facture","export"));
209  // $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
210  // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
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 }
236 
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
Description and activation class for module Api.
init($options='')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir)
Create tables and keys required by module.