dolibarr  13.0.2
modZapier.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
26 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 
32 {
38  public function __construct($db)
39  {
40  global $langs, $conf;
41 
42  $this->db = $db;
43  // Id for module (must be unique).
44  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
45  $this->numero = 50330;
46  // Key text used to identify module (for permissions, menus, etc...)
47  $this->rights_class = 'zapier';
48  // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
49  // It is used to group modules by family in module setup page
50  $this->family = "interface";
51  // Module position in the family on 2 digits ('01', '10', '20', ...)
52  $this->module_position = '26';
53  // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
54  //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
55  // Module label (no space allowed), used if translation string 'ModuleZapierName' not found (Zapier is name of module).
56  $this->name = preg_replace('/^mod/i', '', get_class($this));
57  // Module description, used if translation string 'ModuleZapierDesc' not found (Zapier is name of module).
58  $this->description = "ZapierDescription";
59  // Used only if file README.md and README-LL.md not found.
60  $this->descriptionlong = "Zapier description (Long)";
61  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
62  $this->version = 'development';
63  //Url to the file with your last numberversion of this module
64  //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
65  // Key used in llx_const table to save module status enabled/disabled (where ZAPIERFORDOLIBARR is value of property name of module in uppercase)
66  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
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 = 'zapier';
71  // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
72  $this->module_parts = array(
73  // Set this to 1 if module has its own trigger directory (core/triggers)
74  'triggers' => 1,
75  // Set this to 1 if module has its own login method file (core/login)
76  'login' => 0,
77  // Set this to 1 if module has its own substitution function file (core/substitutions)
78  'substitutions' => 0,
79  // Set this to 1 if module has its own menus handler directory (core/menus)
80  'menus' => 0,
81  // Set this to 1 if module overwrite template dir (core/tpl)
82  'tpl' => 0,
83  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
84  'barcode' => 0,
85  // Set this to 1 if module has its own models directory (core/modules/xxx)
86  'models' => 0,
87  // Set this to 1 if module has its own theme directory (theme)
88  'theme' => 0,
89  // Set this to relative path of css file if module has its own css file
90  'css' => array(
91  // '/zapier/css/zapier.css.php',
92  ),
93  // Set this to relative path of js file if module must load a js on all pages
94  'js' => array(
95  // '/zapier/js/zapier.js.php',
96  ),
97  // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context 'all'
98  'hooks' => array(
99  // 'data' => array(
100  // 'hookcontext1',
101  // 'hookcontext2',
102  // ),
103  // 'entity' => '0',
104  ),
105  // Set this to 1 if feature of module are opened to external users
106  'moduleforexternal' => 0,
107  );
108  // Data directories to create when module is enabled.
109  // Example: this->dirs = array("/zapier/temp","/zapier/subdir");
110  $this->dirs = array("/zapier/temp");
111  // Config pages. Put here list of php page, stored into zapier/admin directory, to use to setup module.
112  $this->config_page_url = array(
113  // "setup.php@zapier"
114  );
115  // Dependencies
116  // A condition to hide module
117  $this->hidden = false;
118  // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
119  $this->depends = array('modApi');
120  // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
121  $this->requiredby = array();
122  // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
123  $this->conflictwith = array();
124  $this->langfiles = array("zapier");
125  // Minimum version of PHP required by module
126  //$this->phpmin = array(5, 5);
127  // Minimum version of Dolibarr required by module
128  $this->need_dolibarr_version = array(10, 0);
129  // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
130  $this->warnings_activation = array();
131  // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
132  $this->warnings_activation_ext = array();
133  // $this->automatic_activation = array(
134  // 'FR'=>'ZapierWasAutomaticallyActivatedBecauseOfYourCountryChoice',
135  // );
136  // If true, can't be disabled
137  // $this->always_enabled = true;
138  // Constants
139  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
140  // Example: $this->const=array(
141  // 1 => array('ZAPIERFORDOLIBARR_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
142  // 2 => array('ZAPIERFORDOLIBARR_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
143  // );
144  $this->const = array(
145  // 1 => array('ZAPIERFORDOLIBARR_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
146  );
147  // Some keys to add into the overwriting translation tables
148  /*$this->overwrite_translation = array(
149  'en_US:ParentCompany'=>'Parent company or reseller',
150  'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
151  )*/
152  if (!isset($conf->zapier) || !isset($conf->zapier->enabled)) {
153  $conf->zapier = new stdClass();
154  $conf->zapier->enabled = 0;
155  }
156  // Array to add new pages in new tabs
157  $this->tabs = array();
158  // Example:
159  // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@zapier:$user->rights->zapier->read:/zapier/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
160  // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@zapier:$user->rights->othermodule->read:/zapier/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.
161  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
162  //
163  // Where objecttype can be
164  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
165  // 'contact' to add a tab in contact view
166  // 'contract' to add a tab in contract view
167  // 'group' to add a tab in group view
168  // 'intervention' to add a tab in intervention view
169  // 'invoice' to add a tab in customer invoice view
170  // 'invoice_supplier' to add a tab in supplier invoice view
171  // 'member' to add a tab in fundation member view
172  // 'opensurveypoll' to add a tab in opensurvey poll view
173  // 'order' to add a tab in customer order view
174  // 'order_supplier' to add a tab in supplier order view
175  // 'payment' to add a tab in payment view
176  // 'payment_supplier' to add a tab in supplier payment view
177  // 'product' to add a tab in product view
178  // 'propal' to add a tab in propal view
179  // 'project' to add a tab in project view
180  // 'stock' to add a tab in stock view
181  // 'thirdparty' to add a tab in third party view
182  // 'user' to add a tab in user view
183  // Dictionaries
184  $this->dictionaries = array();
185  /* Example:
186  $this->dictionaries=array(
187  'langs'=>'mylangfile@zapier',
188  // List of tables we want to see into dictonnary editor
189  'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"),
190  // Label of tables
191  'tablib'=>array("Table1","Table2","Table3"),
192  // Request to select fields
193  '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'),
194  // Sort order
195  'tabsqlsort'=>array("label ASC","label ASC","label ASC"),
196  // List of fields (result of select to show dictionary)
197  'tabfield'=>array("code,label","code,label","code,label"),
198  // List of fields (list of fields to edit a record)
199  'tabfieldvalue'=>array("code,label","code,label","code,label"),
200  // List of fields (list of fields for insert)
201  'tabfieldinsert'=>array("code,label","code,label","code,label"),
202  // Name of columns with primary key (try to always name it 'rowid')
203  'tabrowid'=>array("rowid","rowid","rowid"),
204  // Condition to show each dictionary
205  'tabcond'=>array($conf->zapier->enabled,$conf->zapier->enabled,$conf->zapier->enabled)
206  );
207  */
208  // Boxes/Widgets
209  // Add here list of php file(s) stored in zapier/core/boxes that contains class to show a widget.
210  $this->boxes = array(
211  // 0 => array(
212  // 'file' => 'zapierwidget1.php@zapier',
213  // 'note' => 'Widget provided by Zapier',
214  // 'enabledbydefaulton' => 'Home',
215  // ),
216  //1=>array('file'=>'zapierwidget2.php@zapier','note'=>'Widget provided by Zapier'),
217  //2=>array('file'=>'zapierwidget3.php@zapier','note'=>'Widget provided by Zapier')
218  );
219  // Cronjobs (List of cron jobs entries to add when module is enabled)
220  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
221  $this->cronjobs = array(
222  // 0 => array(
223  // 'label' => 'MyJob label',
224  // 'jobtype' => 'method',
225  // 'class' => '/zapier/class/myobject.class.php',
226  // 'objectname' => 'MyObject',
227  // 'method' => 'doScheduledJob',
228  // 'parameters' => '',
229  // 'comment' => 'Comment',
230  // 'frequency' => 2,
231  // 'unitfrequency' => 3600,
232  // 'status' => 0,
233  // 'test' => '$conf->zapier->enabled',
234  // 'priority' => 50,
235  // ),
236  );
237  // Example: $this->cronjobs=array(
238  // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>'$conf->zapier->enabled', 'priority'=>50),
239  // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'$conf->zapier->enabled', 'priority'=>50)
240  // );
241  // Permissions
242  // Permission array used by this module
243  $this->rights = array();
244 
245  $r = 0;
246  // Permission id (must not be already used)
247  $this->rights[$r][0] = $this->numero + $r;
248  // Permission label
249  $this->rights[$r][1] = 'Read myobject of Zapier';
250  // Permission by default for new user (0/1)
251  $this->rights[$r][3] = 1;
252  // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
253  $this->rights[$r][4] = 'read';
254  // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
255  $this->rights[$r][5] = '';
256  $r++;
257  $this->rights[$r][0] = $this->numero + $r;
258  $this->rights[$r][1] = 'Create/Update myobject of Zapier';
259  $this->rights[$r][3] = 1;
260  $this->rights[$r][4] = 'write';
261  $this->rights[$r][5] = '';
262  $r++;
263  $this->rights[$r][0] = $this->numero + $r;
264  $this->rights[$r][1] = 'Delete myobject of Zapier';
265  $this->rights[$r][3] = 1;
266  $this->rights[$r][4] = 'delete';
267  $this->rights[$r][5] = '';
268 
269  // Main menu entries
270  $this->menu = array(); // List of menus to add
271  $r = 0;
272 
273  // Add here entries to declare new menus
274  // $this->menu[$r++]=array(
275  // 'fk_menu' => '', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
276  // 'type' => 'top', // This is a Top menu entry
277  // 'titre' => 'Zapier',
278  // 'mainmenu' => 'zapier',
279  // 'leftmenu' => '',
280  // 'url' => '/zapier/zapierindex.php',
281  // 'langs' => 'zapier@zapier', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
282  // 'position' => 1000+$r,
283  // 'enabled' => '$conf->zapier->enabled', // Define condition to show or hide menu entry. Use '$conf->zapier->enabled' if entry must be visible if module is enabled.
284  // 'perms' => '1', // Use 'perms'=>'$user->rights->zapier->level1->level2' if you want your menu with a permission rules
285  // 'target' => '',
286  // 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both
287  // );
288 
289  /*
290  $this->menu[$r++]=array(
291  'fk_menu'=>'fk_mainmenu=zapier', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
292  'type'=>'left', // This is a Left menu entry
293  'titre'=>'List MyObject',
294  'mainmenu'=>'zapier',
295  'leftmenu'=>'zapier_myobject_list',
296  'url'=>'/zapier/myobject_list.php',
297  'langs'=>'zapier@zapier', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
298  'position'=>1000+$r,
299  'enabled'=>'$conf->zapier->enabled', // Define condition to show or hide menu entry. Use '$conf->zapier->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
300  'perms'=>'1', // Use 'perms'=>'$user->rights->zapier->level1->level2' if you want your menu with a permission rules
301  'target'=>'',
302  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
303  );
304  $this->menu[$r++]=array(
305  'fk_menu'=>'fk_mainmenu=zapier,fk_leftmenu=zapier', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
306  'type'=>'left', // This is a Left menu entry
307  'titre'=>'New MyObject',
308  'mainmenu'=>'zapier',
309  'leftmenu'=>'zapier_myobject_new',
310  'url'=>'/zapier/myobject_page.php?action=create',
311  'langs'=>'zapier@zapier', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
312  'position'=>1000+$r,
313  'enabled'=>'$conf->zapier->enabled', // Define condition to show or hide menu entry. Use '$conf->zapier->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
314  'perms'=>'1', // Use 'perms'=>'$user->rights->zapier->level1->level2' if you want your menu with a permission rules
315  'target'=>'',
316  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
317  );
318  */
319  }
320 
329  public function init($options = '')
330  {
331  $result = $this->_load_tables('/zapier/sql/');
332  if ($result < 0) return -1; // Do not activate module if not allowed errors found on module SQL queries (the _load_table run sql with run_sql with error allowed parameter to 'default')
333 
334  // Create extrafields
335  //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
336  //$extrafields = new ExtraFields($this->db);
337  //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
338  //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
339  //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
340  //$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
341  //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
342  $sql = array();
343  return $this->_init($sql, $options);
344  }
345 
354  public function remove($options = '')
355  {
356  $sql = array();
357  return $this->_remove($sql, $options);
358  }
359 }
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
_remove($array_sql, $options= '')
Disable function.
init($options= '')
Function called when module is enabled.
_init($array_sql, $options= '')
Enables a module.
Description and activation class for module Zapier.
_load_tables($reldir)
Create tables and keys required by module.