2013-04-09 23:05:50 +02:00
< ? php
2014-03-26 16:02:22 +01:00
/* Copyright ( C ) 2013 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
2024-03-13 00:31:21 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2013-04-09 23:05:50 +02:00
*
2013-04-19 15:02:53 +02:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2013-04-09 23:05:50 +02:00
*/
/**
2014-01-15 18:20:24 +01:00
* \defgroup opensurvey Module opensurvey
2013-04-09 23:05:50 +02:00
* \brief Module to OpenSurvey integration .
2013-08-22 16:49:23 +02:00
* \file htdocs / core / modules / modOpenSurvey . class . php
2013-04-09 23:05:50 +02:00
* \ingroup opensurvey
2021-03-20 13:55:43 +01:00
* \brief Description and activation file for the module OpenSurvey
2013-04-09 23:05:50 +02:00
*/
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . " /core/modules/DolibarrModules.class.php " ;
2013-04-09 23:05:50 +02:00
/**
* Description and activation class for module opensurvey
*/
class modOpenSurvey extends DolibarrModules
{
/**
* Constructor . Define names , constants , directories , boxes , permissions
*
* @ param DoliDB $db Database handler
*/
2020-10-31 14:32:18 +01:00
public function __construct ( $db )
{
2013-04-09 23:05:50 +02:00
$this -> db = $db ;
// Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used module id).
$this -> numero = 55000 ;
// Key text used to identify module (for permission, menus, etc...)
$this -> rights_class = 'opensurvey' ;
// Family can be 'crm','financial','hr','projects','product','technic','other'
// It is used to group modules in module setup page
2016-01-13 13:37:24 +01:00
$this -> family = " portal " ;
2018-10-06 11:57:53 +02:00
$this -> module_position = '40' ;
2013-04-09 23:05:50 +02:00
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
2019-01-27 11:55:16 +01:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2013-04-09 23:05:50 +02:00
// Module description used if translation string 'ModuleXXXDesc' not found (XXX is value MyModule)
2013-12-29 19:30:11 +01:00
$this -> description = " Module to make online surveys (like Doodle, Studs, Rdvz, ...) " ;
2013-04-09 23:05:50 +02:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
2020-09-18 04:30:24 +02:00
$this -> picto = 'poll' ;
2013-04-09 23:05:50 +02:00
// Data directories to create when module is enabled
$this -> dirs = array ();
//$this->dirs[0] = DOL_DATA_ROOT.'/mymodule;
//$this->dirs[1] = DOL_DATA_ROOT.'/mymodule/temp;
// Dependencies
2020-04-10 10:59:32 +02:00
$this -> hidden = false ; // A condition to hide module
$this -> depends = array (); // List of module class names as string that must be enabled if this module is enabled
$this -> requiredby = array (); // List of module ids to disable if this one is disabled
$this -> conflictwith = array (); // List of module class names as string this module is in conflict with
2022-09-27 20:48:47 +02:00
$this -> phpmin = array ( 7 , 0 ); // Minimum version of PHP required by module
2020-04-10 10:59:32 +02:00
$this -> need_dolibarr_version = array ( 3 , 4 , 0 ); // Minimum version of Dolibarr required by module
2013-04-09 23:05:50 +02:00
// Constants
2020-04-10 10:59:32 +02:00
$this -> const = array (); // List of parameters
2013-04-09 23:05:50 +02:00
2014-02-10 01:30:48 +01:00
// Dictionaries
2020-10-31 14:32:18 +01:00
$this -> dictionaries = array ();
2013-04-09 23:05:50 +02:00
// Boxes
2020-04-10 10:59:32 +02:00
$this -> boxes = array (); // List of boxes
$r = 0 ;
2013-04-09 23:05:50 +02:00
// Add here list of php file(s) stored in includes/boxes that contains class to show a box.
// Example:
//$this->boxes[$r][1] = "myboxa.php";
//$r++;
//$this->boxes[$r][1] = "myboxb.php";
//$r++;
// Permissions
2020-04-10 10:59:32 +02:00
$this -> rights = array (); // Permission array used by this module
2024-05-30 13:37:17 +02:00
$r = 0 ;
2013-04-09 23:05:50 +02:00
// Add here list of permission defined by an id, a label, a boolean and two constant strings.
// Example:
2020-04-10 10:59:32 +02:00
$this -> rights [ $r ][ 0 ] = 55001 ; // Permission id (must not be already used)
$this -> rights [ $r ][ 1 ] = 'Read surveys' ; // Permission label
$this -> rights [ $r ][ 2 ] = 'r' ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 3 ] = 0 ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 4 ] = 'read' ; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
2013-04-09 23:05:50 +02:00
$r ++ ;
2013-06-05 16:24:32 +02:00
// Add here list of permission defined by an id, a label, a boolean and two constant strings.
// Example:
2020-04-10 10:59:32 +02:00
$this -> rights [ $r ][ 0 ] = 55002 ; // Permission id (must not be already used)
$this -> rights [ $r ][ 1 ] = 'Create/modify surveys' ; // Permission label
$this -> rights [ $r ][ 2 ] = 'w' ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 3 ] = 0 ; // Permission by default for new user (0/1)
$this -> rights [ $r ][ 4 ] = 'write' ; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
2013-04-09 23:05:50 +02:00
$r ++ ;
2020-10-31 14:32:18 +01:00
// Menus
//-------
$r = 0 ;
$this -> menu [ $r ] = array (
2024-03-13 00:31:21 +01:00
'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
'type' => 'left' ,
'titre' => 'Survey' ,
2021-02-06 17:18:00 +01:00
'prefix' => img_picto ( '' , $this -> picto , 'class="paddingright pictofixedwidth"' ),
2024-03-13 00:31:21 +01:00
'mainmenu' => 'tools' ,
'leftmenu' => 'opensurvey' ,
2024-06-12 15:44:54 +02:00
'url' => '/opensurvey/list.php?mainmenu=tools&leftmenu=opensurvey' ,
2024-03-13 00:31:21 +01:00
'langs' => 'opensurvey' ,
'position' => 200 ,
2024-06-12 15:44:54 +02:00
'enabled' => 'isModEnabled("opensurvey")' , // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
'perms' => '$user->hasRight("opensurvey", "read")' ,
2024-03-13 00:31:21 +01:00
'target' => '' ,
'user' => 0 ,
2020-10-31 14:32:18 +01:00
);
$r ++ ;
$this -> menu [ $r ] = array (
2024-03-13 00:31:21 +01:00
'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
'type' => 'left' ,
'titre' => 'NewSurvey' ,
'mainmenu' => 'tools' ,
'leftmenu' => 'opensurvey_new' ,
'url' => '/opensurvey/wizard/index.php' ,
'langs' => 'opensurvey' ,
'position' => 210 ,
2024-06-12 15:44:54 +02:00
'enabled' => 'isModEnabled("opensurvey")' , // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
'perms' => '$user->hasRight("opensurvey", "write")' ,
2024-03-13 00:31:21 +01:00
'target' => '' ,
'user' => 0 ,
2020-10-31 14:32:18 +01:00
);
$r ++ ;
$this -> menu [ $r ] = array (
2024-03-13 00:31:21 +01:00
'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
'type' => 'left' ,
'titre' => 'List' ,
'mainmenu' => 'tools' ,
'leftmenu' => 'opensurvey_list' ,
'url' => '/opensurvey/list.php' ,
'langs' => 'opensurvey' ,
'position' => 220 ,
2024-06-12 15:44:54 +02:00
'enabled' => 'isModEnabled("opensurvey")' , // Define condition to show or hide menu entry. Use '$conf->NewsSubmitter->enabled' if entry must be visible if module is enabled.
'perms' => '$user->hasRight("opensurvey", "read")' ,
2024-03-13 00:31:21 +01:00
'target' => '' ,
'user' => 0 ,
2020-10-31 14:32:18 +01:00
);
$r ++ ;
}
2013-04-09 23:05:50 +02:00
/**
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories
*
2020-10-31 14:32:18 +01:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2013-04-09 23:05:50 +02:00
* @ return int 1 if OK , 0 if KO
*/
2020-10-31 14:32:18 +01:00
public function init ( $options = '' )
{
2022-05-08 15:18:34 +02:00
$result = $this -> _load_tables ( '/install/mysql/' , 'opensurvey' );
2022-04-05 19:14:00 +02:00
if ( $result < 0 ) {
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')
}
2020-10-31 14:32:18 +01:00
// Permissions
$this -> remove ( $options );
2013-12-29 19:30:11 +01:00
2020-10-31 14:32:18 +01:00
$sql = array ();
2013-04-09 23:05:50 +02:00
2020-10-31 14:32:18 +01:00
return $this -> _init ( $sql , $options );
}
2013-04-09 23:05:50 +02:00
}