dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.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 <https://www.gnu.org/licenses/>.
17 */
18
28require_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29
34{
40 public function __construct($db)
41 {
42 global $langs, $conf;
43
44 $this->db = $db;
45 // Id for module (must be unique).
46 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
47 $this->numero = 50330;
48 // Key text used to identify module (for permissions, menus, etc...)
49 $this->rights_class = 'zapier';
50 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
51 // It is used to group modules by family in module setup page
52 $this->family = "interface";
53 // Module position in the family on 2 digits ('01', '10', '20', ...)
54 $this->module_position = '26';
55 // 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)
56 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
57 // Module label (no space allowed), used if translation string 'ModuleZapierName' not found (Zapier is name of module).
58 $this->name = preg_replace('/^mod/i', '', get_class($this));
59 // Module description, used if translation string 'ModuleZapierDesc' not found (Zapier is name of module).
60 $this->description = "ZapierDescription";
61 // Used only if file README.md and README-LL.md not found.
62 $this->descriptionlong = "Zapier description (Long)";
63 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
64 $this->version = 'development';
65 //Url to the file with your last numberversion of this module
66 //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
67 // Key used in llx_const table to save module status enabled/disabled (where ZAPIERFORDOLIBARR is value of property name of module in uppercase)
68 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
69 // Name of image file used for this module.
70 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
71 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
72 $this->picto = 'zapier';
73 // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
74 $this->module_parts = array(
75 // Set this to 1 if module has its own trigger directory (core/triggers)
76 'triggers' => 1,
77 // Set this to 1 if module has its own login method file (core/login)
78 'login' => 0,
79 // Set this to 1 if module has its own substitution function file (core/substitutions)
80 'substitutions' => 0,
81 // Set this to 1 if module has its own menus handler directory (core/menus)
82 'menus' => 0,
83 // Set this to 1 if module overwrite template dir (core/tpl)
84 'tpl' => 0,
85 // Set this to 1 if module has its own barcode directory (core/modules/barcode)
86 'barcode' => 0,
87 // Set this to 1 if module has its own models directory (core/modules/xxx)
88 'models' => 0,
89 // Set this to 1 if module has its own theme directory (theme)
90 'theme' => 0,
91 // Set this to relative path of css file if module has its own css file
92 'css' => array(
93 // '/zapier/css/zapier.css.php',
94 ),
95 // Set this to relative path of js file if module must load a js on all pages
96 'js' => array(
97 // '/zapier/js/zapier.js.php',
98 ),
99 // 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'
100 'hooks' => array(
101 // 'data' => array(
102 // 'hookcontext1',
103 // 'hookcontext2',
104 // ),
105 // 'entity' => '0',
106 ),
107 // Set this to 1 if feature of module are opened to external users
108 'moduleforexternal' => 0,
109 );
110 // Data directories to create when module is enabled.
111 // Example: this->dirs = array("/zapier/temp","/zapier/subdir");
112 $this->dirs = array("/zapier/temp");
113 // Config pages. Put here list of php page, stored into zapier/admin directory, to use to setup module.
114 $this->config_page_url = array(
115 "setup.php@zapier"
116 );
117 // Dependencies
118 // A condition to hide module
119 $this->hidden = false;
120 // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...))
121 $this->depends = array('modApi');
122 // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
123 $this->requiredby = array();
124 // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
125 $this->conflictwith = array();
126 $this->langfiles = array("zapier");
127 // Minimum version of PHP required by module
128 //$this->phpmin = array(7, 0);
129 // Minimum version of Dolibarr required by module
130 $this->need_dolibarr_version = array(10, 0);
131 // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
132 $this->warnings_activation = array();
133 // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
134 $this->warnings_activation_ext = array();
135 // $this->automatic_activation = array(
136 // 'FR'=>'ZapierWasAutomaticallyActivatedBecauseOfYourCountryChoice',
137 // );
138 // If true, can't be disabled
139 // $this->always_enabled = true;
140 // Constants
141 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
142 // Example: $this->const=array(
143 // 1 => array('ZAPIERFORDOLIBARR_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
144 // 2 => array('ZAPIERFORDOLIBARR_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
145 // );
146 $this->const = array(
147 // 1 => array('ZAPIERFORDOLIBARR_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
148 );
149 // Some keys to add into the overwriting translation tables
150 /*$this->overwrite_translation = array(
151 'en_US:ParentCompany'=>'Parent company or reseller',
152 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
153 )*/
154 if (!isset($conf->zapier) || !isset($conf->zapier->enabled)) {
155 $conf->zapier = new stdClass();
156 $conf->zapier->enabled = 0;
157 }
158 // Array to add new pages in new tabs
159 $this->tabs = array();
160 // Example:
161 // $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
162 // $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.
163 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
164 //
165 // Where objecttype can be
166 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
167 // 'contact' to add a tab in contact view
168 // 'contract' to add a tab in contract view
169 // 'group' to add a tab in group view
170 // 'intervention' to add a tab in intervention view
171 // 'invoice' to add a tab in customer invoice view
172 // 'invoice_supplier' to add a tab in supplier invoice view
173 // 'member' to add a tab in foundation member view
174 // 'opensurveypoll' to add a tab in opensurvey poll view
175 // 'order' to add a tab in sales order view
176 // 'order_supplier' to add a tab in supplier order view
177 // 'payment' to add a tab in payment view
178 // 'payment_supplier' to add a tab in supplier payment view
179 // 'product' to add a tab in product view
180 // 'propal' to add a tab in propal view
181 // 'project' to add a tab in project view
182 // 'stock' to add a tab in stock view
183 // 'thirdparty' to add a tab in third party view
184 // 'user' to add a tab in user view
185
186 // Dictionaries
187 $this->dictionaries = array();
188
189 // Boxes/Widgets
190 // Add here list of php file(s) stored in zapier/core/boxes that contains class to show a widget.
191 $this->boxes = array(
192 // 0 => array(
193 // 'file' => 'zapierwidget1.php@zapier',
194 // 'note' => 'Widget provided by Zapier',
195 // 'enabledbydefaulton' => 'Home',
196 // ),
197 //1=>array('file'=>'zapierwidget2.php@zapier','note'=>'Widget provided by Zapier'),
198 //2=>array('file'=>'zapierwidget3.php@zapier','note'=>'Widget provided by Zapier')
199 );
200 // Cronjobs (List of cron jobs entries to add when module is enabled)
201 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
202 $this->cronjobs = array(
203 // 0 => array(
204 // 'label' => 'MyJob label',
205 // 'jobtype' => 'method',
206 // 'class' => '/zapier/class/myobject.class.php',
207 // 'objectname' => 'MyObject',
208 // 'method' => 'doScheduledJob',
209 // 'parameters' => '',
210 // 'comment' => 'Comment',
211 // 'frequency' => 2,
212 // 'unitfrequency' => 3600,
213 // 'status' => 0,
214 // 'test' => '$conf->zapier->enabled',
215 // 'priority' => 50,
216 // ),
217 );
218 // Example: $this->cronjobs=array(
219 // 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),
220 // 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)
221 // );
222 // Permissions
223 // Permission array used by this module
224 $this->rights = array();
225
226 $r = 1;
227 // Permission id (must not be already used)
228 $this->rights[$r][0] = $this->numero + $r;
229 // Permission label
230 $this->rights[$r][1] = 'Read myobject of Zapier';
231 // Permission by default for new user (0/1)
232 $this->rights[$r][3] = 0;
233 // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
234 $this->rights[$r][4] = 'read';
235 // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
236 $this->rights[$r][5] = '';
237 $r++;
238 $this->rights[$r][0] = $this->numero + $r;
239 $this->rights[$r][1] = 'Create/Update myobject of Zapier';
240 $this->rights[$r][3] = 0;
241 $this->rights[$r][4] = 'write';
242 $this->rights[$r][5] = '';
243 $r++;
244 $this->rights[$r][0] = $this->numero + $r;
245 $this->rights[$r][1] = 'Delete myobject of Zapier';
246 $this->rights[$r][3] = 0;
247 $this->rights[$r][4] = 'delete';
248 $this->rights[$r][5] = '';
249
250 // Main menu entries
251 $this->menu = array(); // List of menus to add
252 $r = 0;
253 }
254
263 public function init($options = '')
264 {
265 $result = $this->_load_tables('/install/mysql/', 'zapier');
266 if ($result < 0) {
267 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')
268 }
269
270 // Create extrafields
271 //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
272 //$extrafields = new ExtraFields($this->db);
273 //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
274 //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
275 //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
276 //$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');
277 //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
278
279 $sql = array();
280
281 return $this->_init($sql, $options);
282 }
283
292 public function remove($options = '')
293 {
294 $sql = array();
295 return $this->_remove($sql, $options);
296 }
297}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module Zapier.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152