modOpenSurvey.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /* Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  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. /**
  19. * \defgroup opensurvey Module opensurvey
  20. * \brief Module to OpenSurvey integration.
  21. * \file htdocs/core/modules/modOpenSurvey.class.php
  22. * \ingroup opensurvey
  23. * \brief Description and activation file for the module OpenSurvey
  24. */
  25. include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
  26. /**
  27. * Description and activation class for module opensurvey
  28. */
  29. class modOpenSurvey extends DolibarrModules
  30. {
  31. /**
  32. * Constructor. Define names, constants, directories, boxes, permissions
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. public function __construct($db)
  37. {
  38. global $langs, $conf;
  39. $this->db = $db;
  40. // Id for module (must be unique).
  41. // Use here a free id (See in Home -> System information -> Dolibarr for list of used module id).
  42. $this->numero = 55000;
  43. // Key text used to identify module (for permission, menus, etc...)
  44. $this->rights_class = 'opensurvey';
  45. // Family can be 'crm','financial','hr','projects','product','technic','other'
  46. // It is used to group modules in module setup page
  47. $this->family = "portal";
  48. $this->module_position = '40';
  49. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  50. $this->name = preg_replace('/^mod/i', '', get_class($this));
  51. // Module description used if translation string 'ModuleXXXDesc' not found (XXX is value MyModule)
  52. $this->description = "Module to make online surveys (like Doodle, Studs, Rdvz, ...)";
  53. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  54. $this->version = 'dolibarr';
  55. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  56. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  57. // Name of image file used for this module.
  58. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  59. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  60. $this->picto = 'poll';
  61. // Data directories to create when module is enabled
  62. $this->dirs = array();
  63. //$this->dirs[0] = DOL_DATA_ROOT.'/mymodule;
  64. //$this->dirs[1] = DOL_DATA_ROOT.'/mymodule/temp;
  65. // Dependencies
  66. $this->hidden = false; // A condition to hide module
  67. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  68. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  69. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  70. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  71. $this->need_dolibarr_version = array(3, 4, 0); // Minimum version of Dolibarr required by module
  72. // Constants
  73. $this->const = array(); // List of parameters
  74. // Dictionaries
  75. $this->dictionaries = array();
  76. // Boxes
  77. $this->boxes = array(); // List of boxes
  78. $r = 0;
  79. // Add here list of php file(s) stored in includes/boxes that contains class to show a box.
  80. // Example:
  81. //$this->boxes[$r][1] = "myboxa.php";
  82. //$r++;
  83. //$this->boxes[$r][1] = "myboxb.php";
  84. //$r++;
  85. // Permissions
  86. $this->rights = array(); // Permission array used by this module
  87. $r = 0;
  88. // Add here list of permission defined by an id, a label, a boolean and two constant strings.
  89. // Example:
  90. $this->rights[$r][0] = 55001; // Permission id (must not be already used)
  91. $this->rights[$r][1] = 'Read surveys'; // Permission label
  92. $this->rights[$r][2] = 'r'; // Permission by default for new user (0/1)
  93. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  94. $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  95. $r++;
  96. // Add here list of permission defined by an id, a label, a boolean and two constant strings.
  97. // Example:
  98. $this->rights[$r][0] = 55002; // Permission id (must not be already used)
  99. $this->rights[$r][1] = 'Create/modify surveys'; // Permission label
  100. $this->rights[$r][2] = 'w'; // Permission by default for new user (0/1)
  101. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  102. $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  103. $r++;
  104. // Menus
  105. //-------
  106. $r = 0;
  107. $this->menu[$r] = array(
  108. 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  109. 'type'=>'left',
  110. 'titre'=>'Survey',
  111. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  112. 'mainmenu'=>'tools',
  113. 'leftmenu'=>'opensurvey',
  114. 'url'=>'/opensurvey/index.php?mainmenu=tools&leftmenu=opensurvey',
  115. 'langs'=>'opensurvey',
  116. 'position'=>200,
  117. 'enabled'=>'$conf->opensurvey->enabled', // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
  118. 'perms'=>'$user->rights->opensurvey->read',
  119. 'target'=>'',
  120. 'user'=>0,
  121. );
  122. $r++;
  123. $this->menu[$r] = array(
  124. 'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=opensurvey', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  125. 'type'=>'left',
  126. 'titre'=>'NewSurvey',
  127. 'mainmenu'=>'tools',
  128. 'leftmenu'=>'opensurvey_new',
  129. 'url'=>'/opensurvey/wizard/index.php',
  130. 'langs'=>'opensurvey',
  131. 'position'=>210,
  132. 'enabled'=>'$conf->opensurvey->enabled', // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
  133. 'perms'=>'$user->rights->opensurvey->write',
  134. 'target'=>'',
  135. 'user'=>0,
  136. );
  137. $r++;
  138. $this->menu[$r] = array(
  139. 'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=opensurvey', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  140. 'type'=>'left',
  141. 'titre'=>'List',
  142. 'mainmenu'=>'tools',
  143. 'leftmenu'=>'opensurvey_list',
  144. 'url'=>'/opensurvey/list.php',
  145. 'langs'=>'opensurvey',
  146. 'position'=>220,
  147. 'enabled'=>'$conf->opensurvey->enabled', // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
  148. 'perms'=>'$user->rights->opensurvey->read',
  149. 'target'=>'',
  150. 'user'=>0,
  151. );
  152. $r++;
  153. }
  154. /**
  155. * Function called when module is enabled.
  156. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  157. * It also creates data directories
  158. *
  159. * @param string $options Options when enabling module ('', 'noboxes')
  160. * @return int 1 if OK, 0 if KO
  161. */
  162. public function init($options = '')
  163. {
  164. global $conf, $langs;
  165. $result = $this->_load_tables('/install/mysql/', 'opensurvey');
  166. if ($result < 0) {
  167. 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')
  168. }
  169. // Permissions
  170. $this->remove($options);
  171. $sql = array();
  172. return $this->_init($sql, $options);
  173. }
  174. }