dolibarr  16.0.5
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, 6);
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 
184  // Dictionaries
185  $this->dictionaries = array();
186 
187  // Boxes/Widgets
188  // Add here list of php file(s) stored in zapier/core/boxes that contains class to show a widget.
189  $this->boxes = array(
190  // 0 => array(
191  // 'file' => 'zapierwidget1.php@zapier',
192  // 'note' => 'Widget provided by Zapier',
193  // 'enabledbydefaulton' => 'Home',
194  // ),
195  //1=>array('file'=>'zapierwidget2.php@zapier','note'=>'Widget provided by Zapier'),
196  //2=>array('file'=>'zapierwidget3.php@zapier','note'=>'Widget provided by Zapier')
197  );
198  // Cronjobs (List of cron jobs entries to add when module is enabled)
199  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
200  $this->cronjobs = array(
201  // 0 => array(
202  // 'label' => 'MyJob label',
203  // 'jobtype' => 'method',
204  // 'class' => '/zapier/class/myobject.class.php',
205  // 'objectname' => 'MyObject',
206  // 'method' => 'doScheduledJob',
207  // 'parameters' => '',
208  // 'comment' => 'Comment',
209  // 'frequency' => 2,
210  // 'unitfrequency' => 3600,
211  // 'status' => 0,
212  // 'test' => '$conf->zapier->enabled',
213  // 'priority' => 50,
214  // ),
215  );
216  // Example: $this->cronjobs=array(
217  // 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),
218  // 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)
219  // );
220  // Permissions
221  // Permission array used by this module
222  $this->rights = array();
223 
224  $r = 1;
225  // Permission id (must not be already used)
226  $this->rights[$r][0] = $this->numero + $r;
227  // Permission label
228  $this->rights[$r][1] = 'Read myobject of Zapier';
229  // Permission by default for new user (0/1)
230  $this->rights[$r][3] = 1;
231  // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
232  $this->rights[$r][4] = 'read';
233  // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
234  $this->rights[$r][5] = '';
235  $r++;
236  $this->rights[$r][0] = $this->numero + $r;
237  $this->rights[$r][1] = 'Create/Update myobject of Zapier';
238  $this->rights[$r][3] = 1;
239  $this->rights[$r][4] = 'write';
240  $this->rights[$r][5] = '';
241  $r++;
242  $this->rights[$r][0] = $this->numero + $r;
243  $this->rights[$r][1] = 'Delete myobject of Zapier';
244  $this->rights[$r][3] = 1;
245  $this->rights[$r][4] = 'delete';
246  $this->rights[$r][5] = '';
247 
248  // Main menu entries
249  $this->menu = array(); // List of menus to add
250  $r = 0;
251  }
252 
261  public function init($options = '')
262  {
263  $result = $this->_load_tables('/install/mysql/', 'zapier');
264  if ($result < 0) {
265  return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
266  }
267 
268  // Create extrafields
269  //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
270  //$extrafields = new ExtraFields($this->db);
271  //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
272  //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
273  //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
274  //$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');
275  //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
276 
277  $sql = array();
278 
279  return $this->_init($sql, $options);
280  }
281 
290  public function remove($options = '')
291  {
292  $sql = array();
293  return $this->_remove($sql, $options);
294  }
295 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
DolibarrModules\_load_tables
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Definition: DolibarrModules.class.php:1070
name
$conf db name
Definition: repair.php:122
DolibarrModules\_remove
_remove($array_sql, $options='')
Disable function.
Definition: DolibarrModules.class.php:482
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
modZapier\init
init($options='')
Function called when module is enabled.
Definition: modZapier.class.php:261
modZapier
Description and activation class for module Zapier.
Definition: modZapier.class.php:31
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37
modZapier\__construct
__construct($db)
Constructor.
Definition: modZapier.class.php:38