2013-04-09 23:05:50 +02:00
< ? php
/* Copyright ( C ) 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-01-02 16:32:48 +01:00
* Copyright ( C ) 2014 Marcos García < marcosgdf @ gmail . com >
2024-03-19 00:57:44 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2024-10-04 17:27:19 +02:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2013-04-09 23:05:50 +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
*/
/**
2024-01-12 18:06:50 +01:00
* \file htdocs / opensurvey / lib / opensurvey . lib . php
2013-04-09 23:05:50 +02:00
* \ingroup opensurvey
* \brief Functions for module
*/
2014-01-02 16:32:48 +01:00
/**
* Returns an array with the tabs for the " Opensurvey poll " section
* It loads tabs from modules looking for the entity Opensurveyso
2014-07-20 15:27:38 +02:00
*
2014-01-02 16:32:48 +01:00
* @ param Opensurveysondage $object Current viewing poll
2024-10-14 01:59:44 +02:00
* @ return array < array { 0 : string , 1 : string , 2 : string } > Tabs for the opensurvey section
2014-01-02 16:32:48 +01:00
*/
2018-08-15 14:28:34 +02:00
function opensurvey_prepare_head ( Opensurveysondage $object )
{
2014-01-02 16:32:48 +01:00
global $langs , $conf ;
2014-07-20 15:27:38 +02:00
2014-01-02 16:32:48 +01:00
$h = 0 ;
$head = array ();
2014-01-05 07:08:37 +01:00
$head [ 0 ][ 0 ] = 'card.php?id=' . $object -> id_sondage ;
2020-05-17 13:34:16 +02:00
$head [ 0 ][ 1 ] = $langs -> trans ( " Survey " );
2014-01-02 16:32:48 +01:00
$head [ 0 ][ 2 ] = 'general' ;
$h ++ ;
2014-07-20 15:27:38 +02:00
2014-01-05 07:08:37 +01:00
$head [ 1 ][ 0 ] = 'results.php?id=' . $object -> id_sondage ;
2014-01-05 06:45:53 +01:00
$head [ 1 ][ 1 ] = $langs -> trans ( " SurveyResults " );
2022-04-01 19:17:25 +02:00
$nbVotes = $object -> countVotes ();
if ( $nbVotes > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . ( $nbVotes ) . '</span>' ;
}
2014-01-02 16:32:48 +01:00
$head [ 1 ][ 2 ] = 'preview' ;
$h ++ ;
2013-04-09 23:05:50 +02:00
2020-03-23 15:54:02 +01:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'opensurveypoll' );
2014-01-02 16:32:48 +01:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'opensurveypoll' , 'remove' );
2014-01-02 16:32:48 +01:00
return $head ;
}
2013-06-05 16:24:32 +02:00
/**
* Show header for new member
*
* @ param string $title Title
* @ param string $head Head array
* @ param int $disablejs More content into html header
* @ param int $disablehead More content into html header
2024-10-04 17:27:19 +02:00
* @ param string [] | string $arrayofjs Array of complementary js files
* @ param string [] | string $arrayofcss Array of complementary css files
2020-03-20 21:16:52 +01:00
* @ param string $numsondage Num survey
2013-06-05 16:24:32 +02:00
* @ return void
*/
2024-01-12 17:16:53 +01:00
function llxHeaderSurvey ( $title , $head = " " , $disablejs = 0 , $disablehead = 0 , $arrayofjs = [], $arrayofcss = [], $numsondage = '' )
2013-06-05 16:24:32 +02:00
{
2020-03-20 21:16:52 +01:00
global $conf , $langs , $mysoc ;
global $dolibarr_main_url_root ;
2018-08-28 02:58:14 +02:00
2024-01-12 17:16:53 +01:00
// $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
2013-06-05 16:24:32 +02:00
2020-11-07 12:47:42 +01:00
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss , 0 , 1 ); // Show html headers
2020-03-20 21:16:52 +01:00
2020-11-07 12:47:42 +01:00
print '<body id="mainbody" class="publicnewmemberform">' ;
2020-03-20 21:16:52 +01:00
print '<span id="dolpaymentspan"></span>' . " \n " ;
print '<div class="center">' . " \n " ;
2020-04-26 23:06:52 +02:00
print '<form name="formulaire" action="studs.php?sondage=' . urlencode ( $numsondage ) . '#bas" method="POST">' . " \n " ;
2020-03-20 21:16:52 +01:00
print '<input type="hidden" name="sondage" value="' . $numsondage . '"/>' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
print " \n " ;
// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
// Define logo and logosmall
$logosmall = $mysoc -> logo_small ;
$logo = $mysoc -> logo ;
2024-01-12 17:16:53 +01:00
// print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
2020-03-20 21:16:52 +01:00
// Define urllogo
$urllogo = '' ;
$urllogofull = '' ;
2021-02-26 15:27:57 +01:00
if ( ! empty ( $logosmall ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/thumbs/' . $logosmall )) {
2020-03-20 21:16:52 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
2021-02-26 15:27:57 +01:00
} elseif ( ! empty ( $logo ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/' . $logo )) {
2020-03-20 21:16:52 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
2018-06-06 18:07:32 +02:00
}
2020-03-20 21:16:52 +01:00
// Output html code for logo
2021-02-26 15:27:57 +01:00
if ( $urllogo ) {
2020-03-20 21:16:52 +01:00
print '<div class="backgreypublicpayment">' ;
print '<div class="logopublicpayment">' ;
print '<img id="dolpaymentlogo" src="' . $urllogo . '"' ;
print '>' ;
print '</div>' ;
2023-11-27 11:56:32 +01:00
if ( ! getDolGlobalString ( 'MAIN_HIDE_POWERED_BY' )) {
2021-04-15 15:54:54 +02:00
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs -> trans ( " PoweredBy " ) . '<br><img src="' . DOL_URL_ROOT . '/theme/dolibarr_logo.svg" width="80px"></a></div>' ;
2020-03-20 21:16:52 +01:00
}
print '</div>' ;
}
2013-06-05 16:24:32 +02:00
2023-11-27 11:56:32 +01:00
if ( getDolGlobalString ( 'OPENSURVEY_IMAGE_PUBLIC_INTERFACE' )) {
2021-06-19 20:05:25 +02:00
print '<div class="backimagepublicopensurvey">' ;
2023-10-15 18:39:13 +02:00
print '<img id="idOPENSURVEY_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString ( 'OPENSURVEY_IMAGE_PUBLIC_INTERFACE' ) . '">' ;
2021-06-19 20:05:25 +02:00
print '</div>' ;
}
2023-09-20 02:48:35 +02:00
print '<div class="survey_borders"><br><br>' ;
2013-04-09 23:05:50 +02:00
}
2013-06-05 16:24:32 +02:00
/**
* Show footer for new member
*
* @ return void
*/
function llxFooterSurvey ()
{
print '</div>' ;
2020-03-20 21:16:52 +01:00
print '</form>' ;
print '</div>' ;
2013-06-05 16:24:32 +02:00
printCommonFooter ( 'public' );
dol_htmloutput_events ();
print " </body> \n " ;
print " </html> \n " ;
}
2013-04-09 23:05:50 +02:00
/**
* get_server_name
*
* @ return string URL to use
*/
function get_server_name ()
{
2013-04-14 20:05:23 +02:00
global $dolibarr_main_url_root ;
2020-04-10 10:59:32 +02:00
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
2019-06-22 18:06:14 +02:00
//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2013-06-05 16:24:32 +02:00
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2020-04-10 10:59:32 +02:00
$url = $urlwithouturlroot . dol_buildpath ( '/opensurvey/' , 1 );
2013-04-09 23:05:50 +02:00
if ( ! preg_match ( " |/ $ | " , $url )) {
2024-08-07 02:53:45 +02:00
$url .= " / " ;
2013-04-09 23:05:50 +02:00
}
return $url ;
}
/**
* Fonction vérifiant l 'existance et la valeur non vide d' une clé d ' un tableau
*
2024-03-28 21:29:02 +01:00
* @ param string $name Key to test
2024-11-04 12:32:13 +01:00
* @ param ? array < string , null | mixed | mixed [] > $tableau Array in which searching key ( $_POST by default )
2024-03-28 21:29:02 +01:00
* @ return bool True if key exists and return a non empty value
2013-04-09 23:05:50 +02:00
*/
function issetAndNoEmpty ( $name , $tableau = null )
{
if ( $tableau === null ) {
$tableau = $_POST ;
}
2024-08-07 03:05:02 +02:00
return ( isset ( $tableau [ $name ]) && ! empty ( $tableau [ $name ]));
2013-04-09 23:05:50 +02:00
}
/**
* Fonction permettant de générer les URL pour les sondage
*
* @ param string $id L ' identifiant du sondage
* @ param bool $admin True pour générer une URL pour l 'administration d' un sondage , False pour un URL publique
* @ return string L ' url pour le sondage
*/
function getUrlSondage ( $id , $admin = false )
{
if ( $admin === true ) {
2014-01-05 07:08:37 +01:00
$url = get_server_name () . 'results.php?id=' . $id ;
2013-04-09 23:05:50 +02:00
} else {
$url = get_server_name () . '/public/studs.php?sondage=' . $id ;
}
return $url ;
}
2013-06-05 16:24:32 +02:00
/**
* Generate a random id
2013-04-10 12:20:45 +02:00
*
2021-12-08 16:47:46 +01:00
* @ param int $car Length of string to generate key
2015-03-17 00:21:17 +01:00
* @ return string
2013-06-05 16:24:32 +02:00
*/
function dol_survey_random ( $car )
{
$string = " " ;
$chaine = " abcdefghijklmnopqrstuvwxyz123456789 " ;
2024-03-19 00:57:44 +01:00
mt_srand (( int ) (( float ) microtime () * 1000000 ));
2020-04-10 10:59:32 +02:00
for ( $i = 0 ; $i < $car ; $i ++ ) {
2016-03-05 15:01:25 +01:00
$string .= $chaine [ mt_rand () % strlen ( $chaine )];
2013-06-05 16:24:32 +02:00
}
return $string ;
}
/**
* Add a poll
*
* @ return void
*/
2014-01-05 18:40:53 +01:00
function ajouter_sondage ()
2013-06-05 16:24:32 +02:00
{
2014-01-06 05:08:42 +01:00
global $db , $user ;
2014-07-20 15:27:38 +02:00
2014-01-04 15:42:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/opensurvey/class/opensurveysondage.class.php' ;
2013-06-05 16:24:32 +02:00
2020-04-10 10:59:32 +02:00
$sondage = dol_survey_random ( 16 );
2013-06-05 16:24:32 +02:00
2014-01-03 17:44:42 +01:00
$allow_comments = empty ( $_SESSION [ 'allow_comments' ]) ? 0 : 1 ;
2014-01-03 23:30:15 +01:00
$allow_spy = empty ( $_SESSION [ 'allow_spy' ]) ? 0 : 1 ;
2014-07-20 15:27:38 +02:00
2013-06-05 16:24:32 +02:00
// Insert survey
2014-01-04 15:42:44 +01:00
$opensurveysondage = new Opensurveysondage ( $db );
$opensurveysondage -> id_sondage = $sondage ;
2020-09-07 12:04:50 +02:00
$opensurveysondage -> description = $_SESSION [ 'description' ];
2014-01-04 15:42:44 +01:00
$opensurveysondage -> mail_admin = $_SESSION [ 'adresse' ];
$opensurveysondage -> nom_admin = $_SESSION [ 'nom' ];
2020-09-07 12:04:50 +02:00
$opensurveysondage -> title = $_SESSION [ 'title' ];
2014-01-05 18:40:53 +01:00
$opensurveysondage -> date_fin = $_SESSION [ 'champdatefin' ];
2014-01-04 15:42:44 +01:00
$opensurveysondage -> format = $_SESSION [ 'formatsondage' ];
$opensurveysondage -> mailsonde = $_SESSION [ 'mailsonde' ];
$opensurveysondage -> allow_comments = $allow_comments ;
$opensurveysondage -> allow_spy = $allow_spy ;
$opensurveysondage -> sujet = $_SESSION [ 'toutchoix' ];
2014-07-20 15:27:38 +02:00
2014-01-06 05:08:42 +01:00
$res = $opensurveysondage -> create ( $user );
2014-07-20 15:27:38 +02:00
2014-01-06 05:08:42 +01:00
if ( $res < 0 ) {
dol_print_error ( $db );
}
2013-06-05 16:24:32 +02:00
2020-09-07 12:04:50 +02:00
unset ( $_SESSION [ " title " ]);
2013-06-05 16:24:32 +02:00
unset ( $_SESSION [ " nom " ]);
unset ( $_SESSION [ " adresse " ]);
2020-09-07 12:04:50 +02:00
unset ( $_SESSION [ " description " ]);
2013-06-05 16:24:32 +02:00
unset ( $_SESSION [ " mailsonde " ]);
2014-01-03 17:44:42 +01:00
unset ( $_SESSION [ 'allow_comments' ]);
2014-01-03 23:30:15 +01:00
unset ( $_SESSION [ 'allow_spy' ]);
2014-01-04 15:47:47 +01:00
unset ( $_SESSION [ 'toutchoix' ]);
unset ( $_SESSION [ 'totalchoixjour' ]);
unset ( $_SESSION [ 'champdatefin' ]);
2014-07-20 15:27:38 +02:00
2020-04-10 10:59:32 +02:00
$urlback = dol_buildpath ( '/opensurvey/card.php' , 1 ) . '?id=' . $sondage ;
2013-06-05 16:24:32 +02:00
header ( " Location: " . $urlback );
exit ();
2013-04-09 23:05:50 +02:00
}