PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/modZapier.class.php

http://github.com/Dolibarr/dolibarr
PHP | 314 lines | 96 code | 7 blank | 211 comment | 3 complexity | 660a029e18cb11cf50c753af1196a915 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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. */
  18. /**
  19. * \defgroup zapier Module Zapier
  20. * \brief Zapier module descriptor.
  21. *
  22. * \file htdocs/core/modules/modZapier.class.php
  23. * \ingroup zapier
  24. * \brief Description and activation file for the module Zapier
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  27. /**
  28. * Description and activation class for module Zapier
  29. */
  30. class modZapier extends DolibarrModules
  31. {
  32. /**
  33. * Constructor. Define names, constants, directories, boxes, permissions
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. public function __construct($db)
  38. {
  39. global $langs, $conf;
  40. $this->db = $db;
  41. // Id for module (must be unique).
  42. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  43. $this->numero = 50330;
  44. // Key text used to identify module (for permissions, menus, etc...)
  45. $this->rights_class = 'zapier';
  46. // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
  47. // It is used to group modules by family in module setup page
  48. $this->family = "interface";
  49. // Module position in the family on 2 digits ('01', '10', '20', ...)
  50. $this->module_position = '26';
  51. // 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)
  52. //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
  53. // Module label (no space allowed), used if translation string 'ModuleZapierName' not found (Zapier is name of module).
  54. $this->name = preg_replace('/^mod/i', '', get_class($this));
  55. // Module description, used if translation string 'ModuleZapierDesc' not found (Zapier is name of module).
  56. $this->description = "ZapierDescription";
  57. // Used only if file README.md and README-LL.md not found.
  58. $this->descriptionlong = "Zapier description (Long)";
  59. // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
  60. $this->version = 'development';
  61. //Url to the file with your last numberversion of this module
  62. //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
  63. // Key used in llx_const table to save module status enabled/disabled (where ZAPIERFORDOLIBARR is value of property name of module in uppercase)
  64. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  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 = 'zapier';
  69. // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
  70. $this->module_parts = array(
  71. // Set this to 1 if module has its own trigger directory (core/triggers)
  72. 'triggers' => 1,
  73. // Set this to 1 if module has its own login method file (core/login)
  74. 'login' => 0,
  75. // Set this to 1 if module has its own substitution function file (core/substitutions)
  76. 'substitutions' => 0,
  77. // Set this to 1 if module has its own menus handler directory (core/menus)
  78. 'menus' => 0,
  79. // Set this to 1 if module overwrite template dir (core/tpl)
  80. 'tpl' => 0,
  81. // Set this to 1 if module has its own barcode directory (core/modules/barcode)
  82. 'barcode' => 0,
  83. // Set this to 1 if module has its own models directory (core/modules/xxx)
  84. 'models' => 0,
  85. // Set this to 1 if module has its own theme directory (theme)
  86. 'theme' => 0,
  87. // Set this to relative path of css file if module has its own css file
  88. 'css' => array(
  89. // '/zapier/css/zapier.css.php',
  90. ),
  91. // Set this to relative path of js file if module must load a js on all pages
  92. 'js' => array(
  93. // '/zapier/js/zapier.js.php',
  94. ),
  95. // 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'
  96. 'hooks' => array(
  97. // 'data' => array(
  98. // 'hookcontext1',
  99. // 'hookcontext2',
  100. // ),
  101. // 'entity' => '0',
  102. ),
  103. // Set this to 1 if feature of module are opened to external users
  104. 'moduleforexternal' => 0,
  105. );
  106. // Data directories to create when module is enabled.
  107. // Example: this->dirs = array("/zapier/temp","/zapier/subdir");
  108. $this->dirs = array("/zapier/temp");
  109. // Config pages. Put here list of php page, stored into zapier/admin directory, to use to setup module.
  110. $this->config_page_url = array(
  111. "setup.php@zapier"
  112. );
  113. // Dependencies
  114. // A condition to hide module
  115. $this->hidden = false;
  116. // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
  117. $this->depends = array('modApi');
  118. // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
  119. $this->requiredby = array();
  120. // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
  121. $this->conflictwith = array();
  122. $this->langfiles = array("zapier");
  123. // Minimum version of PHP required by module
  124. //$this->phpmin = array(5, 6);
  125. // Minimum version of Dolibarr required by module
  126. $this->need_dolibarr_version = array(10, 0);
  127. // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  128. $this->warnings_activation = array();
  129. // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  130. $this->warnings_activation_ext = array();
  131. // $this->automatic_activation = array(
  132. // 'FR'=>'ZapierWasAutomaticallyActivatedBecauseOfYourCountryChoice',
  133. // );
  134. // If true, can't be disabled
  135. // $this->always_enabled = true;
  136. // Constants
  137. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  138. // Example: $this->const=array(
  139. // 1 => array('ZAPIERFORDOLIBARR_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
  140. // 2 => array('ZAPIERFORDOLIBARR_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
  141. // );
  142. $this->const = array(
  143. // 1 => array('ZAPIERFORDOLIBARR_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
  144. );
  145. // Some keys to add into the overwriting translation tables
  146. /*$this->overwrite_translation = array(
  147. 'en_US:ParentCompany'=>'Parent company or reseller',
  148. 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
  149. )*/
  150. if (!isset($conf->zapier) || !isset($conf->zapier->enabled)) {
  151. $conf->zapier = new stdClass();
  152. $conf->zapier->enabled = 0;
  153. }
  154. // Array to add new pages in new tabs
  155. $this->tabs = array();
  156. // Example:
  157. // $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
  158. // $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.
  159. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  160. //
  161. // Where objecttype can be
  162. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  163. // 'contact' to add a tab in contact view
  164. // 'contract' to add a tab in contract view
  165. // 'group' to add a tab in group view
  166. // 'intervention' to add a tab in intervention view
  167. // 'invoice' to add a tab in customer invoice view
  168. // 'invoice_supplier' to add a tab in supplier invoice view
  169. // 'member' to add a tab in fundation member view
  170. // 'opensurveypoll' to add a tab in opensurvey poll view
  171. // 'order' to add a tab in customer order view
  172. // 'order_supplier' to add a tab in supplier order view
  173. // 'payment' to add a tab in payment view
  174. // 'payment_supplier' to add a tab in supplier payment view
  175. // 'product' to add a tab in product view
  176. // 'propal' to add a tab in propal view
  177. // 'project' to add a tab in project view
  178. // 'stock' to add a tab in stock view
  179. // 'thirdparty' to add a tab in third party view
  180. // 'user' to add a tab in user view
  181. // Dictionaries
  182. $this->dictionaries = array();
  183. /* Example:
  184. $this->dictionaries=array(
  185. 'langs'=>'mylangfile@zapier',
  186. // List of tables we want to see into dictonnary editor
  187. 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"),
  188. // Label of tables
  189. 'tablib'=>array("Table1","Table2","Table3"),
  190. // Request to select fields
  191. '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'),
  192. // Sort order
  193. 'tabsqlsort'=>array("label ASC","label ASC","label ASC"),
  194. // List of fields (result of select to show dictionary)
  195. 'tabfield'=>array("code,label","code,label","code,label"),
  196. // List of fields (list of fields to edit a record)
  197. 'tabfieldvalue'=>array("code,label","code,label","code,label"),
  198. // List of fields (list of fields for insert)
  199. 'tabfieldinsert'=>array("code,label","code,label","code,label"),
  200. // Name of columns with primary key (try to always name it 'rowid')
  201. 'tabrowid'=>array("rowid","rowid","rowid"),
  202. // Condition to show each dictionary
  203. 'tabcond'=>array($conf->zapier->enabled,$conf->zapier->enabled,$conf->zapier->enabled)
  204. );
  205. */
  206. // Boxes/Widgets
  207. // Add here list of php file(s) stored in zapier/core/boxes that contains class to show a widget.
  208. $this->boxes = array(
  209. // 0 => array(
  210. // 'file' => 'zapierwidget1.php@zapier',
  211. // 'note' => 'Widget provided by Zapier',
  212. // 'enabledbydefaulton' => 'Home',
  213. // ),
  214. //1=>array('file'=>'zapierwidget2.php@zapier','note'=>'Widget provided by Zapier'),
  215. //2=>array('file'=>'zapierwidget3.php@zapier','note'=>'Widget provided by Zapier')
  216. );
  217. // Cronjobs (List of cron jobs entries to add when module is enabled)
  218. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  219. $this->cronjobs = array(
  220. // 0 => array(
  221. // 'label' => 'MyJob label',
  222. // 'jobtype' => 'method',
  223. // 'class' => '/zapier/class/myobject.class.php',
  224. // 'objectname' => 'MyObject',
  225. // 'method' => 'doScheduledJob',
  226. // 'parameters' => '',
  227. // 'comment' => 'Comment',
  228. // 'frequency' => 2,
  229. // 'unitfrequency' => 3600,
  230. // 'status' => 0,
  231. // 'test' => '$conf->zapier->enabled',
  232. // 'priority' => 50,
  233. // ),
  234. );
  235. // Example: $this->cronjobs=array(
  236. // 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),
  237. // 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)
  238. // );
  239. // Permissions
  240. // Permission array used by this module
  241. $this->rights = array();
  242. $r = 1;
  243. // Permission id (must not be already used)
  244. $this->rights[$r][0] = $this->numero + $r;
  245. // Permission label
  246. $this->rights[$r][1] = 'Read myobject of Zapier';
  247. // Permission by default for new user (0/1)
  248. $this->rights[$r][3] = 1;
  249. // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
  250. $this->rights[$r][4] = 'read';
  251. // In php code, permission will be checked by test if ($user->rights->zapier->level1->level2)
  252. $this->rights[$r][5] = '';
  253. $r++;
  254. $this->rights[$r][0] = $this->numero + $r;
  255. $this->rights[$r][1] = 'Create/Update myobject of Zapier';
  256. $this->rights[$r][3] = 1;
  257. $this->rights[$r][4] = 'write';
  258. $this->rights[$r][5] = '';
  259. $r++;
  260. $this->rights[$r][0] = $this->numero + $r;
  261. $this->rights[$r][1] = 'Delete myobject of Zapier';
  262. $this->rights[$r][3] = 1;
  263. $this->rights[$r][4] = 'delete';
  264. $this->rights[$r][5] = '';
  265. // Main menu entries
  266. $this->menu = array(); // List of menus to add
  267. $r = 0;
  268. }
  269. /**
  270. * Function called when module is enabled.
  271. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  272. * It also creates data directories
  273. *
  274. * @param string $options Options when enabling module ('', 'noboxes')
  275. * @return int 1 if OK, 0 if KO
  276. */
  277. public function init($options = '')
  278. {
  279. $result = $this->_load_tables('/zapier/sql/');
  280. if ($result < 0) {
  281. 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')
  282. }
  283. // Create extrafields
  284. //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  285. //$extrafields = new ExtraFields($this->db);
  286. //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
  287. //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
  288. //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
  289. //$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');
  290. //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled');
  291. $sql = array();
  292. return $this->_init($sql, $options);
  293. }
  294. /**
  295. * Function called when module is disabled.
  296. * Remove from database constants, boxes and permissions from Dolibarr database.
  297. * Data directories are not deleted
  298. *
  299. * @param string $options Options when enabling module ('', 'noboxes')
  300. * @return int 1 if OK, 0 if KO
  301. */
  302. public function remove($options = '')
  303. {
  304. $sql = array();
  305. return $this->_remove($sql, $options);
  306. }
  307. }