modOpenSurvey.class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <http://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 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. 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. // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
  58. $this->special = 0;
  59. // Name of image file used for this module.
  60. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  61. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  62. $this->picto='opensurvey.png@opensurvey';
  63. // Data directories to create when module is enabled
  64. $this->dirs = array();
  65. //$this->dirs[0] = DOL_DATA_ROOT.'/mymodule;
  66. //$this->dirs[1] = DOL_DATA_ROOT.'/mymodule/temp;
  67. // Dependencies
  68. $this->depends = array(); // List of modules id that must be enabled if this module is enabled
  69. $this->requiredby = array(); // List of modules id to disable if this one is disabled
  70. $this->phpmin = array(4,1); // 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. // Main menu entries
  105. $this->menus = array(); // List of menus to add
  106. $r=0;
  107. /*
  108. $this->menu[$r]=array( 'fk_menu'=>0, // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  109. 'type'=>'top',
  110. 'titre'=>'Surveys',
  111. 'mainmenu'=>'opensurvey',
  112. 'url'=>'/opensurvey/index.php',
  113. 'langs'=>'opensurvey',
  114. 'position'=>200,
  115. '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.
  116. 'perms'=>'$user->rights->opensurvey->read',
  117. 'target'=>'',
  118. 'user'=>0);
  119. $r++;*/
  120. $this->menu[$r]=array( '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
  121. 'type'=>'left',
  122. 'titre'=>'Survey',
  123. 'mainmenu'=>'tools',
  124. 'leftmenu'=>'opensurvey',
  125. 'url'=>'/opensurvey/index.php?mainmenu=tools&leftmenu=opensurvey',
  126. 'langs'=>'opensurvey',
  127. 'position'=>200,
  128. '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.
  129. 'perms'=>'',
  130. 'target'=>'',
  131. 'user'=>0);
  132. $r++;
  133. $this->menu[$r]=array( '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
  134. 'type'=>'left',
  135. 'titre'=>'NewSurvey',
  136. 'mainmenu'=>'tools',
  137. 'leftmenu'=>'opensurvey_new',
  138. 'url'=>'/opensurvey/wizard/index.php',
  139. 'langs'=>'opensurvey',
  140. 'position'=>210,
  141. '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.
  142. 'perms'=>'$user->rights->opensurvey->write',
  143. 'target'=>'',
  144. 'user'=>0);
  145. $r++;
  146. $this->menu[$r]=array( '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
  147. 'type'=>'left',
  148. 'titre'=>'List',
  149. 'mainmenu'=>'tools',
  150. 'leftmenu'=>'opensurvey_list',
  151. 'url'=>'/opensurvey/list.php',
  152. 'langs'=>'opensurvey',
  153. 'position'=>220,
  154. '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.
  155. 'perms'=>'',
  156. 'target'=>'',
  157. 'user'=>0);
  158. $r++;
  159. }
  160. /**
  161. * Function called when module is enabled.
  162. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  163. * It also creates data directories
  164. *
  165. * @param string $options Options when enabling module ('', 'noboxes')
  166. * @return int 1 if OK, 0 if KO
  167. */
  168. function init($options='')
  169. {
  170. // Permissions
  171. $this->remove($options);
  172. $sql = array();
  173. return $this->_init($sql,$options);
  174. }
  175. }