diff --git a/ChangeLog b/ChangeLog
index d6ae2f76959..cbca688c6c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,7 +30,8 @@ For users:
- New: Can define a different clicktodial setup per user.
- New: Add option INVOICE_CAN_NEVER_BE_REMOVED.
- New: Enhance agenda module to reach RFC2445 (add busy information).
-- First change to prepare feature click to print for PDF.
+- New: Add module Opensurvey.
+- First change to prepare feature "click to print" (IPP) for PDF.
For translators:
- Update language files.
diff --git a/htdocs/core/modules/modOpenSurvey.class.php b/htdocs/core/modules/modOpenSurvey.class.php
new file mode 100755
index 00000000000..e9385442a85
--- /dev/null
+++ b/htdocs/core/modules/modOpenSurvey.class.php
@@ -0,0 +1,224 @@
+
+ *
+ * Licensed under the GNU GPL v3 or higher (See file gpl-3.0.html)
+ */
+
+/**
+ * \defgroup opensurvey Module OpenSurvey
+ * \brief Module to OpenSurvey integration.
+ */
+
+/**
+ * \file htdocs/opensurvey/core/modules/modOpenSurvey.class.php
+ * \ingroup opensurvey
+ * \brief Description and activation file for module OpenSurvey
+ */
+include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
+
+
+/**
+ * Description and activation class for module opensurvey
+ */
+class modOpenSurvey extends DolibarrModules
+{
+
+ /**
+ * Constructor. Define names, constants, directories, boxes, permissions
+ *
+ * @param DoliDB $db Database handler
+ */
+ function __construct($db)
+ {
+ global $langs,$conf;
+
+ $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
+ $this->family = "projects";
+ // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
+ $this->name = preg_replace('/^mod/i','',get_class($this));
+ // Module description used if translation string 'ModuleXXXDesc' not found (XXX is value MyModule)
+ $this->description = "Module to integrate a survey (like Doodle, Studs, Rdvz, ...)";
+ // 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);
+ // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
+ $this->special = 0;
+ // 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'
+ $this->picto='opensurvey.png@opensurvey';
+
+ // 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;
+
+ // Config pages. Put here list of php page names stored in admin directory used to setup module
+ $this->config_page_url = array("index.php@opensurvey");
+
+ // Dependencies
+ $this->depends = array(); // List of modules id that must be enabled if this module is enabled
+ $this->requiredby = array(); // List of modules id to disable if this one is disabled
+ $this->phpmin = array(4,1); // Minimum version of PHP required by module
+ $this->need_dolibarr_version = array(2,4); // Minimum version of Dolibarr required by module
+
+ // Constants
+ $this->const = array(); // List of parameters
+
+ // Dictionnaries
+ $this->dictionnaries=array();
+
+ // Boxes
+ $this->boxes = array(); // List of boxes
+ $r=0;
+
+ // 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
+ $this->rights = array(); // Permission array used by this module
+ $r=0;
+
+ // Add here list of permission defined by an id, a label, a boolean and two constant strings.
+ // Example:
+ $this->rights[$r][0] = 55000; // 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] = 'survey'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+ $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+ $r++;
+
+ // Add here list of permission defined by an id, a label, a boolean and two constant strings.
+ // Example:
+ $this->rights[$r][0] = 55001; // 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] = 'survey'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+ $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
+ $r++;
+
+
+ // Main menu entries
+ $this->menus = array(); // List of menus to add
+ $r=0;
+
+ $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
+ 'type'=>'top',
+ 'titre'=>'Surveys',
+ 'mainmenu'=>'opensurvey',
+ 'url'=>'/opensurvey/index.php',
+ 'langs'=>'opensurvey@opensurvey',
+ 'position'=>200,
+ '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.
+ 'perms'=>'$user->rights->opensurvey->survey->read',
+ 'target'=>'',
+ 'user'=>0);
+ $r++;
+
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=opensurvey', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+ 'type'=>'left',
+ 'titre'=>'Survey',
+ 'mainmenu'=>'opensurvey',
+ 'leftmenu'=>'opensurvey',
+ 'url'=>'/opensurvey/index.php?mainmenu=opensurvey&leftmenu=opensurvey',
+ 'langs'=>'opensurvey@opensurvey',
+ 'position'=>200,
+ '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.
+ 'perms'=>'',
+ 'target'=>'',
+ 'user'=>0);
+ $r++;
+
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=opensurvey,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'=>'opensurvey',
+ 'leftmenu'=>'opensurvey_new',
+ 'url'=>'/opensurvey/public/index.php?origin=dolibarr',
+ 'langs'=>'opensurvey@opensurvey',
+ 'position'=>210,
+ '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.
+ 'perms'=>'',
+ 'target'=>'_blank',
+ 'user'=>0);
+ $r++;
+
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=opensurvey,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'=>'opensurvey',
+ 'leftmenu'=>'opensurvey_list',
+ 'url'=>'/opensurvey/list.php',
+ 'langs'=>'opensurvey@opensurvey',
+ 'position'=>220,
+ '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.
+ 'perms'=>'',
+ 'target'=>'',
+ 'user'=>0);
+ $r++;
+ }
+
+ /**
+ * 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
+ *
+ * @param string $options Options when enabling module ('', 'noboxes')
+ * @return int 1 if OK, 0 if KO
+ */
+ function init($options='')
+ {
+ $sql = array();
+
+ $result=$this->load_tables();
+
+ return $this->_init($sql,$options);
+ }
+
+ /**
+ * Function called when module is disabled.
+ * Remove from database constants, boxes and permissions from Dolibarr database.
+ * Data directories are not deleted
+ *
+ * @param string $options Options when enabling module ('', 'noboxes')
+ * @return int 1 if OK, 0 if KO
+ */
+ function remove($options='')
+ {
+ $sql = array();
+
+ return $this->_remove($sql,$options);
+ }
+
+
+ /**
+ * Create tables and keys required by module
+ * Files mymodule.sql and mymodule.key.sql with create table and create keys
+ * commands must be stored in directory /mymodule/sql/
+ * This function is called by this->init.
+ *
+ * @return int <=0 if KO, >0 if OK
+ */
+ function load_tables()
+ {
+ return $this->_load_tables('/opensurvey/sql/');
+ }
+}
+
+?>
diff --git a/htdocs/opensurvey/admin/index.php b/htdocs/opensurvey/admin/index.php
new file mode 100755
index 00000000000..02c6a5ea125
--- /dev/null
+++ b/htdocs/opensurvey/admin/index.php
@@ -0,0 +1,62 @@
+
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/opensurvey/admin/index.php
+ * \ingroup opensurvey
+ * \brief Setup page of opensurvey
+ */
+
+require_once('../../main.inc.php');
+require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
+
+// Security check
+if (!$user->admin) accessforbidden();
+
+
+
+
+/*
+ * View
+ */
+
+$langs->load("opensurvey@opensurvey");
+llxHeader();
+
+print_fiche_titre($langs->trans("OpenSurveyArea"));
+
+echo $langs->trans("OpenSurveyNothingToSetup").' '."\n";
+
+// Link
+print img_picto('','object_globe.png').' '.$langs->trans("PublicLinkToCreateSurvey").': ';
+
+// Define $urlwithroot
+$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
+//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
+
+$url=$urlwithouturlroot.dol_buildpath('/opensurvey/public/index.php',1);
+$urllink=''.$url.' ';
+print $urllink;
+
+
+llxFooter();
+
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/opensurvey/adminstuds.php b/htdocs/opensurvey/adminstuds.php
new file mode 100755
index 00000000000..d3547a4ac51
--- /dev/null
+++ b/htdocs/opensurvey/adminstuds.php
@@ -0,0 +1,352 @@
+
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/opensurvey/adminstuds.php
+ * \ingroup opensurvey
+ * \brief Page to edit survey
+ */
+
+require_once('../main.inc.php');
+require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php");
+require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
+
+
+// Security check
+if (!$user->admin) accessforbidden();
+
+
+// Initialisation des variables
+$action=GETPOST('action');
+$numsondage = $numsondageadmin = '';
+if (GETPOST('sondage'))
+{
+ if (strlen(GETPOST('sondage')) == 24) // recuperation du numero de sondage admin (24 car.) dans l'URL
+ {
+ $numsondageadmin=GETPOST("sondage",'alpha');
+ $numsondage=substr($numsondageadmin, 0, 16);
+ }
+ else
+ {
+ $numsondageadmin='';
+ $numsondage=GETPOST("sondage",'alpha');
+ }
+}
+
+$object=new Opensurveysondage($db);
+
+$expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
+
+
+
+/*
+ * Actions
+ */
+
+
+// Delete
+if ($action == 'delete_confirm')
+{
+ $result=$object->delete($user,'',$numsondageadmin);
+
+ header('Location: '.dol_buildpath('/opensurvey/list.php',1));
+ exit();
+}
+
+// Update
+if ($action == 'update')
+{
+ $error=0;
+
+ if (! GETPOST('nouveautitre'))
+ {
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Title")),'errors');
+ $error++;
+ $action = 'edit';
+ }
+
+ if (! $error)
+ {
+ $res=$object->fetch(0,$numsondageadmin);
+ if ($res < 0) dol_print_error($db,$object->error);
+ }
+
+ if (! $error)
+ {
+ $object->titre = GETPOST('nouveautitre');
+ $object->commentaires = GETPOST('nouveauxcommentaires');
+ $object->mail_admin = GETPOST('nouvelleadresse');
+ $object->date_fin = $expiredate;
+ $object->survey_link_visible = GETPOST('survey_link_visible')=='on'?1:0;
+ $object->canedit = GETPOST('canedit')=='on'?1:0;
+
+ $res=$object->update($user);
+ if ($res < 0)
+ {
+ setEventMessage($object->error,'errors');
+ $action='edit';
+ }
+ }
+}
+
+
+// Add comment
+if (GETPOST('ajoutcomment'))
+{
+ $error=0;
+
+ if (! GETPOST('comment'))
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Comment")),'errors');
+ }
+ if (! GETPOST('commentuser'))
+ {
+ $error++;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("User")),'errors');
+ }
+
+ if (! $error)
+ {
+ $comment = GETPOST("comment");
+ $comment_user = GETPOST('commentuser');
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
+ $sql.= " VALUES ('".$db->escape($numsondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
+ $resql = $db->query($sql);
+ dol_syslog("sql=".$sql);
+ if (! $resql)
+ {
+ $err |= COMMENT_INSERT_FAILED;
+ }
+ }
+}
+
+// Delete comment
+$idcomment=GETPOST('deletecomment','int');
+if ($idcomment)
+{
+ $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.$idcomment;
+ $resql = $db->query($sql);
+}
+
+
+/*
+ * View
+ */
+
+$form=new Form($db);
+
+$result=$object->fetch(0,$numsondage);
+if ($result <= 0)
+{
+ print $langs->trans("ErrorRecordNotFound");
+ llxFooter();
+ exit;
+}
+
+$arrayofjs=array();
+$arrayofcss=array('/opensurvey/css/style.css');
+llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);
+
+
+// Define format of choices
+$toutsujet=explode(",",$object->sujet);
+$listofanswers=array();
+foreach ($toutsujet as $value)
+{
+ $tmp=explode('@',$value);
+ $listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox'));
+}
+$toutsujet=str_replace("@"," ",$toutsujet);
+$toutsujet=str_replace("°","'",$toutsujet);
+
+
+print '
'."\n";
+
+dol_fiche_end();
+
+
+/*
+ * Barre d'actions
+ */
+print '';
+
+if ($action == 'delete')
+{
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?&sondage='.$numsondageadmin, $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll",$id), 'delete_confirm', '', '', 1);
+}
+
+
+
+print ' ';
+
+
+print ''."\n";
+
+print_fiche_titre($langs->trans("CommentsOfVoters"),'','');
+
+// Comment list
+$sql = 'SELECT id_comment, usercomment, comment';
+$sql.= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
+$sql.= " WHERE id_sondage='".$db->escape($numsondage)."'";
+$sql.= " ORDER BY id_comment";
+$resql = $db->query($sql);
+$num_rows=$db->num_rows($resql);
+if ($num_rows > 0)
+{
+ $i = 0;
+ while ( $i < $num_rows)
+ {
+ $obj=$db->fetch_object($resql);
+ print ' '.img_picto('', 'delete.png').' ';
+ print $obj->usercomment.' : '.dol_nl2br($obj->comment)." ";
+ $i++;
+ }
+}
+else
+{
+ print $langs->trans("NoCommentYet").' ';;
+}
+
+print ' ';
+
+// Add comment
+print $langs->trans("AddACommentForPoll") . ' ';
+print ' '."\n";
+print $langs->trans("Name") .' : '."\n";
+print ' '."\n";
+if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") {
+ print "" . $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")) . " ";
+}
+
+print ' ';
+
+llxFooterSurvey();
+
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/opensurvey/adminstuds_preview.php b/htdocs/opensurvey/adminstuds_preview.php
new file mode 100755
index 00000000000..7e7bb6a6967
--- /dev/null
+++ b/htdocs/opensurvey/adminstuds_preview.php
@@ -0,0 +1,1062 @@
+
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/opensurvey/admin_studs_preview.php
+ * \ingroup opensurvey
+ * \brief Page to preview votes of a survey
+ */
+
+$res=0;
+require_once('../main.inc.php');
+require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php");
+require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
+
+
+// Security check
+if (!$user->admin) accessforbidden();
+
+
+// Init vars
+$action=GETPOST('action');
+$numsondageadmin=GETPOST("sondage");
+$numsondage=substr($numsondageadmin, 0, 16);
+
+$object=new Opensurveysondage($db);
+$object->fetch(0,$numsondageadmin);
+$nblignes=count($object->fetch_lines());
+
+
+/*
+ * Actions
+ */
+
+$nbcolonnes = substr_count($object->sujet, ',') + 1;
+
+// Add vote
+if (isset($_POST["boutonp"]) || isset($_POST["boutonp_x"]))
+{
+ if (GETPOST('nom'))
+ {
+ $erreur_prenom = false;
+
+ $nouveauchoix = '';
+ for ($i=0;$i<$nbcolonnes;$i++)
+ {
+ if (isset($_POST["choix$i"]) && $_POST["choix$i"] == '1')
+ {
+ $nouveauchoix.="1";
+ }
+ else if (isset($_POST["choix$i"]) && $_POST["choix$i"] == '2')
+ {
+ $nouveauchoix.="2";
+ }
+ else { // sinon c'est 0
+ $nouveauchoix.="0";
+ }
+ }
+
+ $nom=substr(GETPOST("nom"),0,64);
+
+ // Check if vote already exists
+ $sql = 'SELECT id_users, nom';
+ $sql.= ' FROM '.MAIN_DB_PREFIX."opensurvey_user_studs';
+ $sql.= ' WHERE id_sondage='".$db->escape($numsondage)."' AND nom = '".$db->escape($nom)."'";
+ $sql.= ' ORDER BY id_users';
+ $resql = $db->query($sql);
+ $num_rows = $db->num_rows($resql);
+ if ($num_rows > 0)
+ {
+ setEventMessage($langs->trans("VoteNameAlreadyExists"),'errors');
+ $error++;
+ }
+ else
+ {
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_user_studs (nom, id_sondage, reponses)';
+ $sql.= " VALUES ('".$db->escape($nom)."', '".$db->escape($numsondage)."','".$db->escape($nouveauchoix)."')";
+ $resql=$db->query($sql);
+ if (! $resql) dol_print_error($db);
+ }
+ }
+}
+
+// Update vote
+$testmodifier = false;
+$testligneamodifier = false;
+$ligneamodifier = -1;
+for ($i=0; $i<$nblignes; $i++)
+{
+ if (isset($_POST['modifierligne'.$i]))
+ {
+ $ligneamodifier=$i;
+ $testligneamodifier=true;
+ }
+
+ //test pour voir si une ligne est a modifier
+ if (isset($_POST['validermodifier'.$i]))
+ {
+ $modifier=$i;
+ $testmodifier=true;
+ }
+}
+if ($testmodifier)
+{
+ //var_dump($_POST);exit;
+ $nouveauchoix = '';
+ for ($i = 0; $i < $nbcolonnes; $i++)
+ {
+ //var_dump($_POST["choix$i"]);
+ if (isset($_POST["choix$i"]) && $_POST["choix$i"] == '1')
+ {
+ $nouveauchoix.="1";
+ }
+ else if (isset($_POST["choix$i"]) && $_POST["choix$i"] == '2')
+ {
+ $nouveauchoix.="2";
+ }
+ else { // sinon c'est 0
+ $nouveauchoix.="0";
+ }
+ }
+
+ $idtomodify=$_POST["idtomodify".$modifier];
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_user_studs";
+ $sql.= " SET reponses = '".$db->escape($nouveauchoix)."'";
+ $sql.= " WHERE id_users = '".$db->escape($idtomodify)."'";
+
+ dol_syslog("sql=".$sql);
+ $resql = $db->query($sql);
+ if (! $resql) dol_print_error($db);
+}
+
+// Add column (not for date)
+if (GETPOST("ajoutercolonne") && GETPOST('nouvellecolonne') && ($object->format == "A" || $object->format == "A+"))
+{
+ $nouveauxsujets=$object->sujet;
+
+ //on rajoute la valeur a la fin de tous les sujets deja entrés
+ $nouveauxsujets.=',';
+ $nouveauxsujets.=str_replace(array(",","@"), " ", $_POST["nouvellecolonne"]).(empty($_POST["typecolonne"])?'':'@'.$_POST["typecolonne"]);
+
+ //mise a jour avec les nouveaux sujets dans la base
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
+ $sql.= " SET sujet = '".$db->escape($nouveauxsujets)."'";
+ $sql.= " WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog("sql=".$sql);
+ $resql = $db->query($sql);
+ if (! $resql) dol_print_error($db);
+}
+
+// Add column (with format date)
+if (isset($_POST["ajoutercolonne"]) && ($object->format == "D" || $object->format == "D+"))
+{
+ $nouveauxsujets=$object->sujet;
+
+ if (isset($_POST["nouveaujour"]) && $_POST["nouveaujour"] != "vide" &&
+ isset($_POST["nouveaumois"]) && $_POST["nouveaumois"] != "vide" &&
+ isset($_POST["nouvelleannee"]) && $_POST["nouvelleannee"] != "vide") {
+
+ $nouvelledate=dol_mktime(0, 0, 0, $_POST["nouveaumois"], $_POST["nouveaujour"], $_POST["nouvelleannee"]);
+
+ if (isset($_POST["nouvelleheuredebut"]) && $_POST["nouvelleheuredebut"]!="vide"){
+ $nouvelledate.="@";
+ $nouvelledate.=$_POST["nouvelleheuredebut"];
+ $nouvelledate.="h";
+
+ if ($_POST["nouvelleminutedebut"]!="vide") {
+ $nouvelledate.=$_POST["nouvelleminutedebut"];
+ }
+ }
+
+ if (isset($_POST["nouvelleheurefin"]) && $_POST["nouvelleheurefin"]!="vide"){
+ $nouvelledate.="-";
+ $nouvelledate.=$_POST["nouvelleheurefin"];
+ $nouvelledate.="h";
+
+ if ($_POST["nouvelleminutefin"]!="vide") {
+ $nouvelledate.=$_POST["nouvelleminutefin"];
+ }
+ }
+
+ if($_POST["nouvelleheuredebut"] == "vide" || (isset($_POST["nouvelleheuredebut"]) && isset($_POST["nouvelleheurefin"]) && (($_POST["nouvelleheuredebut"] < $_POST["nouvelleheurefin"]) || (($_POST["nouvelleheuredebut"] == $_POST["nouvelleheurefin"]) && ($_POST["nouvelleminutedebut"] < $_POST["nouvelleminutefin"]))))) {
+ $erreur_ajout_date = false;
+ } else {
+ $erreur_ajout_date = "yes";
+ }
+
+ //on rajoute la valeur dans les valeurs
+ $datesbase = explode(",",$object->sujet);
+ $taillebase = sizeof($datesbase);
+
+ //recherche de l'endroit de l'insertion de la nouvelle date dans les dates deja entrées dans le tableau
+ if ($nouvelledate < $datesbase[0]) {
+ $cleinsertion = 0;
+ } elseif ($nouvelledate > $datesbase[$taillebase-1]) {
+ $cleinsertion = count($datesbase);
+ } else {
+ for ($i = 0; $i < count($datesbase); $i++) {
+ $j = $i + 1;
+ if ($nouvelledate > $datesbase[$i] && $nouvelledate < $datesbase[$j]) {
+ $cleinsertion = $j;
+ }
+ }
+ }
+
+ array_splice($datesbase, $cleinsertion, 0, $nouvelledate);
+ $cle = array_search($nouvelledate, $datesbase);
+ $dateinsertion = '';
+ for ($i = 0; $i < count($datesbase); $i++) {
+ $dateinsertion.=",";
+ $dateinsertion.=$datesbase[$i];
+ }
+
+ $dateinsertion = substr("$dateinsertion", 1);
+
+ //mise a jour avec les nouveaux sujets dans la base
+ if (isset($erreur_ajout_date) && !$erreur_ajout_date)
+ {
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
+ $sql.= " SET sujet = '".$db->escape($dateinsertion)."'";
+ $sql.= " WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog("sql=".$sql);
+ $resql = $db->query($sql);
+ if (! $resql) dol_print_error($db);
+
+ if ($nouvelledate > strtotime($object->date_fin))
+ {
+ $date_fin=$nouvelledate+200000;
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'opensurvey_sondage';
+ $sql.= " SET date_fin = '".$db->escape($date_fin)."'";
+ $sql.= " WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog("sql=".$sql);
+ $resql = $db->query($sql);
+ if (! $resql) dol_print_error($db);
+ }
+ }
+
+ $adresseadmin = $object->mail_admin;
+ }
+ else
+ {
+ $erreur_ajout_date="yes";
+ }
+}
+
+// Delete line
+for ($i = 0; $i < $nblignes; $i++)
+{
+ if (isset($_POST["effaceligne$i"]) || isset($_POST['effaceligne'.$i.'_x']))
+ {
+ $compteur=0;
+
+ // Loop on each answer
+ $compteur = 0;
+ $sql ="SELECT id_users, nom, id_sondage, reponses";
+ $sql.=" FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
+ $sql.=" WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog('sql='.$sql);
+ $resql=$db->query($sql);
+ if (! $resql) dol_print_error($db);
+ $num=$db->num_rows($resql);
+ while ($compteur < $num)
+ {
+ $obj=$db->fetch_object($resql);
+
+ if ($compteur==$i)
+ {
+ $sql2 = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_user_studs';
+ $sql2.= ' WHERE id_users = '.$db->escape($obj->id_users);
+ $resql2 = $db->query($sql2);
+ }
+
+ $compteur++;
+ }
+ }
+}
+
+// Delete column
+for ($i = 0; $i < $nbcolonnes; $i++)
+{
+ if ((isset($_POST["effacecolonne$i"]) || isset($_POST['effacecolonne'.$i.'_x'])) && $nbcolonnes > 1)
+ {
+ $db->begin();
+
+ $toutsujet = explode(",",$object->sujet);
+ $j = 0;
+ $nouveauxsujets = '';
+
+ //parcours de tous les sujets actuels
+ while (isset($toutsujet[$j]))
+ {
+ //si le sujet n'est pas celui qui a été effacé alors on concatene
+ if ($i != $j)
+ {
+ if (! empty($nouveauxsujets)) $nouveauxsujets .= ',';
+ $nouveauxsujets .= $toutsujet[$j];
+ }
+
+ $j++;
+ }
+
+ // Mise a jour des sujets dans la base
+ $sql = 'UPDATE '.MAIN_DB_PREFIX."opensurvey_sondage";
+ $sql.= " SET sujet = '".$db->escape($nouveauxsujets)."' WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog("sql=".$sql);
+ $resql = $db->query($sql);
+ if (! $resql) dol_print_error($db);
+
+ // Clean current answer to remove deleted columns
+ $compteur = 0;
+ $sql ="SELECT id_users, nom, id_sondage, reponses";
+ $sql.=" FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
+ $sql.=" WHERE id_sondage = '".$db->escape($numsondage)."'";
+ dol_syslog('sql='.$sql);
+ $resql=$db->query($sql);
+ if (! $resql)
+ {
+ dol_print_error($db);
+ exit;
+ }
+ $num=$db->num_rows($resql);
+ while ($compteur < $num)
+ {
+ $obj=$db->fetch_object($resql);
+
+ $newcar = '';
+ $ensemblereponses = $obj->reponses;
+
+ // parcours de toutes les réponses actuelles
+ for ($j = 0; $j < $nbcolonnes; $j++)
+ {
+ $car=substr($ensemblereponses, $j, 1);
+ //si les reponses ne concerne pas la colonne effacée, on concatene
+ if ($i != $j) {
+ $newcar .= $car;
+ }
+ }
+
+ // mise a jour des reponses utilisateurs dans la base
+ $sql2 = 'UPDATE '.MAIN_DB_PREFIX.'opensurvey_user_studs';
+ $sql2.= " SET reponses = '".$db->escape($newcar)."'";
+ $sql2.= " WHERE id_users = '".$db->escape($obj->id_users)."'";
+ //print $sql2;
+ dol_syslog('sql='.$sql2);
+ $resql2 = $db->query($sql2);
+
+ $compteur++;
+ }
+
+ $db->commit();
+ }
+}
+
+
+
+/*
+ * View
+ */
+
+$form=new Form($db);
+
+$result=$object->fetch(0,$numsondage);
+if ($result <= 0)
+{
+ print $langs->trans("ErrorRecordNotFound");
+ llxFooter();
+ exit;
+}
+
+$arrayofjs=array();
+$arrayofcss=array('/opensurvey/css/style.css');
+llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);
+
+
+// Define format of choices
+$toutsujet=explode(",",$object->sujet);
+$listofanswers=array();
+foreach ($toutsujet as $value)
+{
+ $tmp=explode('@',$value);
+ $listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox'));
+}
+$toutsujet=str_replace("@"," ",$toutsujet);
+$toutsujet=str_replace("°","'",$toutsujet);
+
+
+print ''."\n";
+
+$head = array();
+
+$head[0][0] = 'adminstuds.php?sondage='.$object->id_sondage_admin;
+$head[0][1] = $langs->trans("Card");
+$head[0][2] = 'general';
+$h++;
+
+$head[1][0] = 'adminstuds_preview.php?sondage='.$object->id_sondage_admin;
+$head[1][1] = $langs->trans("SurveyResults").'/'.$langs->trans("Preview");
+$head[1][2] = 'preview';
+$h++;
+
+print dol_get_fiche_head($head,'preview',$langs->trans("Survey"),0,dol_buildpath('/opensurvey/img/object_opensurvey.png',1),1);
+
+
+print '';
+
+$linkback = ''.$langs->trans("BackToList").' ';
+
+// Ref
+print ''.$langs->trans('Ref').' ';
+print '';
+print $form->showrefnav($object, 'sondage', $linkback, 1, 'id_sondage_admin', 'id_sondage_admin');
+print ' ';
+print ' ';
+
+// Type
+$type=($object->format=="A"||$object->format=="A+")?'classic':'date';
+print ''.$langs->trans("Type").' ';
+print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1);
+print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate").' ';
+
+// Link
+print ''.img_picto('','object_globe.png').' '.$langs->trans("UrlForSurvey",'').' ';
+
+// Define $urlwithroot
+$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
+//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
+
+$url=$urlwithouturlroot.dol_buildpath('/opensurvey/public/studs.php',1).'?sondage='.$numsondage;
+$urlvcal=''.$url.' ';
+print $urlvcal;
+
+
+print '
';
+
+dol_fiche_end();
+
+print ' '."\n";
+
+print '';
+
+
+showlogo();
+
+
+// Add form to add a field
+if (GETPOST('ajoutsujet'))
+{
+ //on recupere les données et les sujets du sondage
+ print ''."\n";
+ print ' ';
+ print ' ';
+
+ print ''."\n";
+ print " "."\n";
+
+ // Add new column
+ if ($object->format=="A"||$object->format=="A+")
+ {
+ print $langs->trans("AddNewColumn") .' : ';
+ print $langs->trans("Title").' ';
+ $tmparray=array('checkbox'=>$langs->trans("CheckBox"),'yesno'=>$langs->trans("YesNoList"),'foragainst'=>$langs->trans("PourContreList"));
+ print $langs->trans("Type").' '.$form->selectarray("typecolonne", $tmparray, GETPOST('typecolonne')).' ';
+ print ' ';
+ print ' ';
+ print ' ';
+ print ' '."\n";
+ }
+ else
+ {
+ //ajout d'une date avec creneau horaire
+ //print _("You can add a new scheduling date to your poll. If you just want to add a new hour to an existant date, put the same date and choose a new hour.") .' '."\n";
+ print $langs->trans("AddADate") .' : '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ for ($i=1;$i<32;$i++){
+ print ''.$i.' '."\n";
+ }
+ print ' '."\n";
+
+ print ' '."\n";
+ print ' '."\n";
+ for($i = 1; $i < 13; $i++) {
+ print ''.strftime('%B', mktime(0, 0, 0, $i)).' '."\n";
+ }
+ print ' '."\n";
+
+
+ print ' '."\n";
+ print ' '."\n";
+ for ($i = date("Y"); $i < (date("Y") + 5); $i++) {
+ print ''.$i.' '."\n";
+ }
+ print ' '."\n";
+ print ' '. $langs->trans("AddStartHour") .' : '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ for ($i = 0; $i < 24; $i++) {
+ print ''.$i.' H '."\n";
+ }
+ print ' '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ print '00 '."\n";
+ print '15 '."\n";
+ print '30 '."\n";
+ print '45 '."\n";
+ print ' '."\n";
+ print ' '. $langs->trans("AddEndHour") .' : '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ for ($i = 0; $i < 24; $i++) {
+ print ''.$i.' H '."\n";
+ }
+ print ' '."\n";
+ print ' '."\n";
+ print ' '."\n";
+ print '00 '."\n";
+ print '15 '."\n";
+ print '30 '."\n";
+ print '45 '."\n";
+ print ' '."\n";
+
+ print ' ';
+ print' '."\n";
+ print ' ';
+ print ' ';
+ }
+
+ print ''."\n";
+ print ' '."\n";
+ print '
'."\n";
+
+ exit;
+}
+
+
+print $langs->trans("PollAdminDesc",img_picto('','cancel.png@opensurvey'),img_picto('','add-16.png@opensurvey')).' ';
+
+print ' '."\n";
+
+//affichage du titre du sondage
+$titre=str_replace("\\","",$object->titre);
+print ''.$titre.' '."\n";
+
+//affichage du nom de l'auteur du sondage
+print $langs->trans("InitiatorOfPoll") .' : '.$object->nom_admin.' '."\n";
+
+//affichage des commentaires du sondage
+if ($object->commentaires)
+{
+ print ' '.$langs->trans("Description") .' : '."\n";
+ $commentaires=dol_nl2br($object->commentaires);
+ print $commentaires;
+ print ' '."\n";
+}
+
+print '
'."\n";
+
+
+$nbcolonnes=substr_count($object->sujet,',')+1;
+
+print ' '."\n";
+print ' ';
+
+print ' '."\n";
+print '
'."\n";
+
+//debut de l'affichage de résultats
+print '
'."\n";
+
+//reformatage des données des sujets du sondage
+$toutsujet=explode(",",$object->sujet);
+$toutsujet=str_replace("°","'",$toutsujet);
+
+print ''."\n";
+print ' '."\n";
+print ' '."\n";
+
+//boucle pour l'affichage des boutons de suppression de colonne
+for ($i = 0; isset($toutsujet[$i]); $i++) {
+ print ' '."\n";
+}
+
+print ' '."\n";
+
+
+// Show choice titles
+if ($object->format=="D"||$object->format=="D+")
+{
+ //affichage des sujets du sondage
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ //affichage des années
+ $colspan=1;
+ for ($i=0;$i'.strftime("%Y", $current).''."\n";
+ $colspan=1;
+ }
+ }
+
+ print 'id_sondage_admin.'">'.$langs->trans("Add").' '."\n";
+ print ' '."\n";
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ //affichage des mois
+ $colspan = 1;
+ for ($i = 0; $i < count($toutsujet); $i++) {
+ $cur = intval($toutsujet[$i]); // intval() est utiliser pour supprimer le suffixe @* qui déplaît logiquement à strftime()
+
+ if (isset($toutsujet[$i+1]) === false) {
+ $next = false;
+ } else {
+ $next = intval($toutsujet[$i+1]);
+ }
+
+ if ($next && dol_print_date($cur, "%B") == dol_print_date($next, "%B") && dol_print_date($cur, "%Y") == dol_print_date($next, "%Y")){
+ $colspan++;
+ } else {
+ print ''.dol_print_date($cur, "%B").' '."\n";
+
+ $colspan=1;
+ }
+ }
+
+ print 'id_sondage_admin.'">'.$langs->trans("Add").' '."\n";
+ print ' '."\n";
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ //affichage des jours
+ $colspan = 1;
+ for ($i = 0; $i < count($toutsujet); $i++) {
+ $cur = intval($toutsujet[$i]);
+ if (isset($toutsujet[$i+1]) === false) {
+ $next = false;
+ } else {
+ $next = intval($toutsujet[$i+1]);
+ }
+ if ($next && dol_print_date($cur, "%a %e") == dol_print_date($next,"%a %e") && dol_print_date($cur, "%B") == dol_print_date($next, "%B")) {
+ $colspan++;
+ } else {
+ print ''.dol_print_date($cur, "%a %e").' '."\n";
+
+ $colspan=1;
+ }
+ }
+
+ print 'id_sondage_admin.'">'.$langs->trans("Add").' '."\n";
+ print ' '."\n";
+
+ //affichage des horaires
+ if (strpos($object->sujet,'@') !== false) {
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ for ($i = 0; isset($toutsujet[$i]); $i++) {
+ $heures=explode('@', $toutsujet[$i]);
+ if (isset($heures[1])) {
+ print ''.$heures[1].' '."\n";
+ } else {
+ print ' '."\n";
+ }
+ }
+
+ print 'id_sondage_admin.'">'.$langs->trans("Add").' '."\n";
+ print ' '."\n";
+ }
+}
+else
+{
+ //affichage des sujets du sondage
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ for ($i = 0; isset($toutsujet[$i]); $i++)
+ {
+ $tmp=explode('@',$toutsujet[$i]);
+ print ''.$tmp[0].' '."\n";
+ }
+
+ print ''.img_picto('',dol_buildpath('/opensurvey/img/add-16.png',1),'',1).' '."\n";
+ print ' '."\n";
+}
+
+
+// Loop on each answer
+$sumfor = array();
+$sumagainst = array();
+$compteur = 0;
+$sql ="SELECT id_users, nom, id_sondage, reponses";
+$sql.=" FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
+$sql.=" WHERE id_sondage = '".$db->escape($numsondage)."'";
+dol_syslog('sql='.$sql);
+$resql=$db->query($sql);
+if (! $resql)
+{
+ dol_print_error($db);
+ exit;
+}
+$num=$db->num_rows($resql);
+while ($compteur < $num)
+{
+ $obj=$db->fetch_object($resql);
+
+ $ensemblereponses = $obj->reponses;
+
+ print ''."\n";
+ print ' '."\n";
+
+ // Name
+ $nombase=str_replace("°","'",$obj->nom);
+ print ''.$nombase.' '."\n";
+
+ // si la ligne n'est pas a changer, on affiche les données
+ if (! $testligneamodifier)
+ {
+ for ($i = 0; $i < $nbcolonnes; $i++)
+ {
+ $car = substr($ensemblereponses, $i, 1);
+ //print 'xx'.$i."-".$car.'-'.$listofanswers[$i]['format'].'zz';
+
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
+ {
+ if (((string) $car) == "1") print 'OK '."\n";
+ else print 'KO '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
+ {
+ if (((string) $car) == "1") print ''.$langs->trans("Yes").' '."\n";
+ else if (((string) $car) == "0") print ''.$langs->trans("No").' '."\n";
+ else print ' '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (! isset($sumagainst[$i])) $sumagainst[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ if (((string) $car) == "0") $sumagainst[$i]++;
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
+ {
+ if (((string) $car) == "1") print ''.$langs->trans("For").' '."\n";
+ else if (((string) $car) == "0") print ''.$langs->trans("Against").' '."\n";
+ else print ' '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (! isset($sumagainst[$i])) $sumagainst[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ if (((string) $car) == "0") $sumagainst[$i]++;
+ }
+ }
+ }
+ else
+ {
+ //sinon on remplace les choix de l'utilisateur par une ligne de checkbox pour recuperer de nouvelles valeurs
+ if ($compteur == $ligneamodifier)
+ {
+ for ($i = 0; $i < $nbcolonnes; $i++)
+ {
+ $car = substr($ensemblereponses, $i, 1);
+ print '';
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
+ {
+ print ' ';
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
+ {
+ $arraychoice=array('2'=>' ','0'=>$langs->trans("No"),'1'=>$langs->trans("Yes"));
+ print $form->selectarray("choix".$i, $arraychoice, $car);
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
+ {
+ $arraychoice=array('2'=>' ','0'=>$langs->trans("Against"),'1'=>$langs->trans("For"));
+ print $form->selectarray("choix".$i, $arraychoice, $car);
+ }
+ print ' '."\n";
+ }
+ }
+ else
+ {
+ for ($i = 0; $i < $nbcolonnes; $i++)
+ {
+ $car = substr($ensemblereponses, $i, 1);
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
+ {
+ if (((string) $car) == "1") print 'OK '."\n";
+ else print 'KO '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
+ {
+ if (((string) $car) == "1") print ''.$langs->trans("For").' '."\n";
+ else if (((string) $car) == "0") print ''.$langs->trans("Against").' '."\n";
+ else print ' '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (! isset($sumagainst[$i])) $sumagainst[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ if (((string) $car) == "0") $sumagainst[$i]++;
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
+ {
+ if (((string) $car) == "1") print ''.$langs->trans("For").' '."\n";
+ else if (((string) $car) == "0") print ''.$langs->trans("Against").' '."\n";
+ else print ' '."\n";
+ // Total
+ if (! isset($sumfor[$i])) $sumfor[$i] = 0;
+ if (! isset($sumagainst[$i])) $sumagainst[$i] = 0;
+ if (((string) $car) == "1") $sumfor[$i]++;
+ if (((string) $car) == "0") $sumagainst[$i]++;
+ }
+ }
+ }
+ }
+
+ //a la fin de chaque ligne se trouve les boutons modifier
+ if ($compteur != $ligneamodifier)
+ {
+ print ' '."\n";
+ }
+
+ //demande de confirmation pour modification de ligne
+ for ($i = 0; $i < $nblignes; $i++)
+ {
+ if (isset($_POST["modifierligne".$i]))
+ {
+ if ($compteur == $i)
+ {
+ print '';
+ print ' ';
+ print ' ';
+ print ' '."\n";
+ }
+ }
+ }
+
+ $compteur++;
+ print ' '."\n";
+}
+
+// Add line to add new record
+if (empty($testligneamodifier))
+{
+ print ''."\n";
+ print ' '."\n";
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+
+ for ($i = 0; $i < $nbcolonnes; $i++)
+ {
+ print '';
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
+ {
+ print ' ';
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno')
+ {
+ $arraychoice=array('2'=>' ','0'=>$langs->trans("No"),'1'=>$langs->trans("Yes"));
+ print $form->selectarray("choix".$i, $arraychoice);
+ }
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst')
+ {
+ $arraychoice=array('2'=>' ','0'=>$langs->trans("Against"),'1'=>$langs->trans("For"));
+ print $form->selectarray("choix".$i, $arraychoice);
+ }
+ print ' '."\n";
+ }
+
+ // Affichage du bouton de formulaire pour inscrire un nouvel utilisateur dans la base
+ print ' '."\n";
+ print ' '."\n";
+}
+
+// Select value of best choice (for checkbox columns only)
+$nbofcheckbox=0;
+for ($i=0; $i < $nbcolonnes + 1; $i++)
+{
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')))
+ $nbofcheckbox++;
+ if (isset($sumfor[$i]))
+ {
+ if ($i == 0) {
+ $meilleurecolonne = $sumfor[$i];
+ }
+ if (isset($sumfor[$i]) && $sumfor[$i] > $meilleurecolonne){
+ $meilleurecolonne = $sumfor[$i];
+ }
+ }
+}
+
+
+// Show line total
+print ''."\n";
+print ' '."\n";
+print ''. $langs->trans("Total") .' '."\n";
+for ($i = 0; $i < $nbcolonnes; $i++)
+{
+ $showsumfor = isset($sumfor[$i])?$sumfor[$i]:'';
+ $showsumagainst = isset($sumagainst[$i])?$sumagainst[$i]:'';
+ if (empty($showsumfor)) $showsumfor = 0;
+ if (empty($showsumagainst)) $showsumagainst = 0;
+
+ print '';
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst'))) print $showsumfor;
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'yesno') print $langs->trans("Yes").': '.$showsumfor.' '.$langs->trans("No").': '.$showsumagainst;
+ if (! empty($listofanswers[$i]['format']) && $listofanswers[$i]['format'] == 'foragainst') print $langs->trans("For").': '.$showsumfor.' '.$langs->trans("Against").': '.$showsumagainst;
+ print ' '."\n";
+}
+print ' ';
+// Show picto winner
+if ($nbofcheckbox >= 2)
+{
+ print ''."\n";
+ print ' '."\n";
+ print ' '."\n";
+ for ($i = 0; $i < $nbcolonnes; $i++) {
+ if (empty($listofanswers[$i]['format']) || ! in_array($listofanswers[$i]['format'],array('yesno','foragainst')) && isset($sumfor[$i]) && isset($meilleurecolonne) && $sumfor[$i] == $meilleurecolonne)
+ {
+ print ' '."\n";
+ } else {
+ print ' '."\n";
+ }
+ }
+ print ' '."\n";
+}
+
+// S'il a oublié de remplir un nom
+if ((isset($_POST["boutonp"]) || isset($_POST["boutonp_x"])) && $_POST["nom"] == "") {
+ print ''."\n";
+ print "" . _("Enter a name !") . " \n";
+ print ' '."\n";
+}
+
+if (isset($erreur_prenom) && $erreur_prenom) {
+ print ''."\n";
+ print "" . _("The name you've chosen already exist in this poll!") . " \n";
+ print ' '."\n";
+}
+
+if (isset($erreur_injection) && $erreur_injection) {
+ print ''."\n";
+ print "" . _("Characters \" ' < et > are not permitted") . " \n";
+ print ' '."\n";
+}
+
+if (isset($erreur_ajout_date) && $erreur_ajout_date) {
+ print ''."\n";
+ print "" . _("The date is not correct !") . " \n";
+ print ' '."\n";
+}
+
+//fin du tableau
+print '
'."\n";
+print '
'."\n";
+
+
+$toutsujet = explode(",", $object->sujet);
+
+$compteursujet = 0;
+$meilleursujet = '';
+for ($i = 0; $i < $nbcolonnes; $i++) {
+ if (isset($sumfor[$i]) === true && isset($meilleurecolonne) === true && $sumfor[$i] == $meilleurecolonne){
+ $meilleursujet.=", ";
+
+ if ($object->format == "D" || $object->format == "D+") {
+ $meilleursujetexport = $toutsujet[$i];
+
+ if (strpos($toutsujet[$i], '@') !== false) {
+ $toutsujetdate = explode("@", $toutsujet[$i]);
+ $meilleursujet .= dol_print_date($toutsujetdate[0],'daytext'). ' ('.dol_print_date($toutsujetdate[0],'%A').')' . ' - ' . $toutsujetdate[1];
+ } else {
+ $meilleursujet .= dol_print_date($toutsujet[$i],'daytext'). ' ('.dol_print_date($toutsujet[$i],'%A').')';
+ }
+ }
+ else
+ {
+ $tmps=explode('@',$toutsujet[$i]);
+ $meilleursujet .= $tmps[0];
+ }
+
+ $compteursujet++;
+ }
+}
+
+//adaptation pour affichage des valeurs
+$meilleursujet = substr("$meilleursujet", 1);
+$meilleursujet = str_replace("°", "'", $meilleursujet);
+
+// Show best choice
+if ($nbofcheckbox >= 2)
+{
+ $vote_str = $langs->trans('votes');
+ print ''."\n";
+
+ if (isset($meilleurecolonne) && $compteursujet == "1") {
+ print " " . $langs->trans('TheBestChoice') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ". \n";
+ } elseif (isset($meilleurecolonne)) {
+ print " " . $langs->trans('TheBestChoices') . " : $meilleursujet " . $langs->trans("with") . " $meilleurecolonne " . $vote_str . ". \n";
+ }
+ print '
'."\n";
+}
+
+print ' '."\n";
+
+llxFooterSurvey();
+
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php
new file mode 100644
index 00000000000..7cdfd1e4c7e
--- /dev/null
+++ b/htdocs/opensurvey/class/opensurveysondage.class.php
@@ -0,0 +1,512 @@
+
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file dev/skeletons/opensurveysondage.class.php
+ * \ingroup mymodule othermodule1 othermodule2
+ * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
+ * Initialy built by build_class_from_table on 2013-03-10 00:32
+ */
+
+// Put here all includes required by your class file
+require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
+//require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
+//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
+
+
+/**
+ * Put here description of your class
+ */
+class Opensurveysondage extends CommonObject
+{
+ var $db; //!< To store db handler
+ var $error; //!< To return error code (or message)
+ var $errors=array(); //!< To return several error codes (or messages)
+ var $element='opensurvey_sondage'; //!< Id that identify managed objects
+ var $table_element='opensurvey_sondage'; //!< Name of table without prefix where object is stored
+
+ var $id;
+
+ var $id_sondage;
+ var $commentaires;
+ var $mail_admin;
+ var $nom_admin;
+ var $titre;
+ var $id_sondage_admin;
+ var $date_fin='';
+ var $format;
+ var $mailsonde;
+ var $survey_link_visible;
+ var $canedit;
+
+
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDb $db Database handler
+ */
+ function __construct($db)
+ {
+ $this->db = $db;
+ return 1;
+ }
+
+
+ /**
+ * Create object into database
+ *
+ * @param User $user User that creates
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, Id of created object if OK
+ */
+ function create($user, $notrigger=0)
+ {
+ global $conf, $langs;
+ $error=0;
+
+ // Clean parameters
+
+ if (isset($this->id_sondage)) $this->id_sondage=trim($this->id_sondage);
+ if (isset($this->commentaires)) $this->commentaires=trim($this->commentaires);
+ if (isset($this->mail_admin)) $this->mail_admin=trim($this->mail_admin);
+ if (isset($this->nom_admin)) $this->nom_admin=trim($this->nom_admin);
+ if (isset($this->titre)) $this->titre=trim($this->titre);
+ if (isset($this->id_sondage_admin)) $this->id_sondage_admin=trim($this->id_sondage_admin);
+ if (isset($this->format)) $this->format=trim($this->format);
+ if (isset($this->mailsonde)) $this->mailsonde=trim($this->mailsonde);
+ if (isset($this->survey_link_visible)) $this->survey_link_visible=trim($this->survey_link_visible);
+ if (isset($this->canedit)) $this->canedit=trim($this->canedit);
+
+
+
+ // Check parameters
+ // Put here code to add control on parameters values
+
+ // Insert request
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
+
+ $sql.= "id_sondage,";
+ $sql.= "commentaires,";
+ $sql.= "mail_admin,";
+ $sql.= "nom_admin,";
+ $sql.= "titre,";
+ $sql.= "id_sondage_admin,";
+ $sql.= "date_fin,";
+ $sql.= "format,";
+ $sql.= "mailsonde,";
+ $sql.= "survey_link_visible,";
+ $sql.= "canedit";
+ $sql.= ") VALUES (";
+
+ $sql.= " ".(! isset($this->id_sondage)?'NULL':"'".$this->id_sondage."'").",";
+ $sql.= " ".(! isset($this->commentaires)?'NULL':"'".$this->db->escape($this->commentaires)."'").",";
+ $sql.= " ".(! isset($this->mail_admin)?'NULL':"'".$this->db->escape($this->mail_admin)."'").",";
+ $sql.= " ".(! isset($this->nom_admin)?'NULL':"'".$this->db->escape($this->nom_admin)."'").",";
+ $sql.= " ".(! isset($this->titre)?'NULL':"'".$this->db->escape($this->titre)."'").",";
+ $sql.= " ".(! isset($this->id_sondage_admin)?'NULL':"'".$this->id_sondage_admin."'").",";
+ $sql.= " ".(! isset($this->date_fin) || dol_strlen($this->date_fin)==0?'NULL':$this->db->idate($this->date_fin)).",";
+ $sql.= " ".(! isset($this->format)?'NULL':"'".$this->db->escape($this->format)."'").",";
+ $sql.= " ".(! isset($this->mailsonde)?'NULL':"'".$this->mailsonde."'").",";
+ $sql.= " ".(! isset($this->survey_link_visible)?'NULL':"'".$this->survey_link_visible."'").",";
+ $sql.= " ".(! isset($this->canedit)?'NULL':"'".$this->canedit."'")."";
+
+ $sql.= ")";
+
+ $this->db->begin();
+
+ dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+
+ if (! $error)
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."opensurvey_sondage");
+
+ if (! $notrigger)
+ {
+ // Uncomment this and change MYOBJECT to your own tag if you
+ // want this action calls a trigger.
+
+ //// Call triggers
+ //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ //$interface=new Interfaces($this->db);
+ //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
+ //if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ //// End call triggers
+ }
+ }
+
+ // Commit or rollback
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return $this->id;
+ }
+ }
+
+
+ /**
+ * Load object in memory from the database
+ *
+ * @param int $id Id object
+ * @param string $numsurvey Ref of survey (admin or not)
+ * @return int <0 if KO, >0 if OK
+ */
+ function fetch($id,$numsurvey='')
+ {
+ global $langs;
+
+ $sql = "SELECT";
+ //$sql.= " t.rowid,";
+ $sql.= " t.id_sondage,";
+ $sql.= " t.commentaires,";
+ $sql.= " t.mail_admin,";
+ $sql.= " t.nom_admin,";
+ $sql.= " t.titre,";
+ $sql.= " t.id_sondage_admin,";
+ $sql.= " t.date_fin,";
+ $sql.= " t.format,";
+ $sql.= " t.mailsonde,";
+ $sql.= " t.survey_link_visible,";
+ $sql.= " t.canedit,";
+ $sql.= " t.sujet,";
+ $sql.= " t.tms";
+ $sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
+ if ($id > 0) $sql.= " WHERE t.rowid = ".$id;
+ else if (strlen($numsurvey) == 16) $sql.= " WHERE t.id_sondage = '".$numsurvey."'";
+ else $sql.= " WHERE t.id_sondage_admin = '".$numsurvey."'";
+
+ dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ if ($this->db->num_rows($resql))
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ //$this->id = $obj->rowid;
+ $this->ref = $obj->id_sondage_admin;
+
+ $this->id_sondage = $obj->id_sondage;
+ $this->commentaires = $obj->commentaires;
+ $this->mail_admin = $obj->mail_admin;
+ $this->nom_admin = $obj->nom_admin;
+ $this->titre = $obj->titre;
+ $this->id_sondage_admin = $obj->id_sondage_admin;
+ $this->date_fin = $this->db->jdate($obj->date_fin);
+ $this->format = $obj->format;
+ $this->mailsonde = $obj->mailsonde;
+ $this->survey_link_visible = $obj->survey_link_visible;
+ $this->canedit = $obj->canedit;
+ $this->sujet = $obj->sujet;
+
+ $this->date_m = $this->db->jdate($obj->tls);
+ $ret=1;
+ }
+ else $ret=0;
+
+ $this->db->free($resql);
+ }
+ else
+ {
+ $this->error="Error ".$this->db->lasterror();
+ dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
+ $ret=-1;
+ }
+
+ return $ret;
+ }
+
+
+ /**
+ * Update object into database
+ *
+ * @param User $user User that modifies
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function update($user=0, $notrigger=0)
+ {
+ global $conf, $langs;
+ $error=0;
+
+ // Clean parameters
+
+ if (isset($this->id_sondage)) $this->id_sondage=trim($this->id_sondage);
+ if (isset($this->commentaires)) $this->commentaires=trim($this->commentaires);
+ if (isset($this->mail_admin)) $this->mail_admin=trim($this->mail_admin);
+ if (isset($this->nom_admin)) $this->nom_admin=trim($this->nom_admin);
+ if (isset($this->titre)) $this->titre=trim($this->titre);
+ if (isset($this->id_sondage_admin)) $this->id_sondage_admin=trim($this->id_sondage_admin);
+ if (isset($this->format)) $this->format=trim($this->format);
+ if (isset($this->mailsonde)) $this->mailsonde=trim($this->mailsonde);
+ if (isset($this->survey_link_visible)) $this->survey_link_visible=trim($this->survey_link_visible);
+ if (isset($this->canedit)) $this->canedit=trim($this->canedit);
+
+
+ // Check parameters
+ // Put here code to add a control on parameters values
+
+ // Update request
+ $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
+
+ $sql.= " id_sondage='".(isset($this->id_sondage)?$this->id_sondage:"null")."',";
+ $sql.= " commentaires=".(isset($this->commentaires)?"'".$this->db->escape($this->commentaires)."'":"null").",";
+ $sql.= " mail_admin=".(isset($this->mail_admin)?"'".$this->db->escape($this->mail_admin)."'":"null").",";
+ $sql.= " nom_admin=".(isset($this->nom_admin)?"'".$this->db->escape($this->nom_admin)."'":"null").",";
+ $sql.= " titre=".(isset($this->titre)?"'".$this->db->escape($this->titre)."'":"null").",";
+ $sql.= " id_sondage_admin='".(isset($this->id_sondage_admin)?$this->id_sondage_admin:"null")."',";
+ $sql.= " date_fin=".(dol_strlen($this->date_fin)!=0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
+ $sql.= " format=".(isset($this->format)?"'".$this->db->escape($this->format)."'":"null").",";
+ $sql.= " mailsonde=".(isset($this->mailsonde)?$this->mailsonde:"null").",";
+ $sql.= " survey_link_visible=".(isset($this->survey_link_visible)?$this->survey_link_visible:"null").",";
+ $sql.= " canedit=".(isset($this->canedit)?$this->canedit:"null")."";
+
+ //$sql.= " WHERE rowid=".$this->id;
+ $sql.= " WHERE id_sondage_admin='".$this->id_sondage_admin."'";
+
+ $this->db->begin();
+
+ dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Uncomment this and change MYOBJECT to your own tag if you
+ // want this action calls a trigger.
+
+ //// Call triggers
+ //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ //$interface=new Interfaces($this->db);
+ //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
+ //if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ //// End call triggers
+ }
+ }
+
+ // Commit or rollback
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that deletes
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @param string $numsondageadmin Num sondage to delete
+ * @return int <0 if KO, >0 if OK
+ */
+ function delete($user, $notrigger=0, $numsondageadmin)
+ {
+ global $conf, $langs;
+ $error=0;
+
+ $this->db->begin();
+
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Uncomment this and change MYOBJECT to your own tag if you
+ // want this action calls a trigger.
+
+ //// Call triggers
+ //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ //$interface=new Interfaces($this->db);
+ //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
+ //if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ //// End call triggers
+ }
+ }
+
+ if (! $error)
+ {
+
+ $sql='DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage_admin = '".$numsondageadmin."'";
+ dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ $sql='DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage_admin = '".$numsondageadmin."'";
+ dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
+ $resql=$this->db->query($sql);
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
+ $sql.= " WHERE id_sondage_admin = '".$numsondageadmin."'";
+
+ dol_syslog(get_class($this)."::delete sql=".$sql);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ }
+
+ // Commit or rollback
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+ /**
+ * Return array of lines
+ *
+ * @return array Array of lines
+ */
+ function fetch_lines()
+ {
+ $ret=array();
+ $sql = "SELECT id_users, nom, reponses FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
+ $sql.= " WHERE id_sondage = '".$this->id_sondage."'";
+ $resql=$this->db->query($sql);
+
+ if ($resql)
+ {
+ $num=$this->db->num_rows($resql);
+ $i=0;
+ while ($i < $num)
+ {
+ $obj=$this->db->fetch_object($resql);
+ $tmp=array('id_users'=>$obj->id_users, 'nom'=>$obj->nom, 'reponses'=>$obj->reponses);
+
+ $ret[]=$tmp;
+ $i++;
+ }
+ }
+ else dol_print_error($this->db);
+
+ $this->lines=$ret;
+
+ return $this->lines;
+ }
+
+ /**
+ * Load an object from its id and create a new one in database
+ *
+ * @param int $fromid Id of object to clone
+ * @return int New id of clone
+ */
+ function createFromClone($fromid)
+ {
+ global $user,$langs;
+
+ $error=0;
+
+ $object=new Opensurveysondage($this->db);
+
+ $this->db->begin();
+
+ // Load source object
+ $object->fetch($fromid);
+ $object->id=0;
+ $object->statut=0;
+
+ // Clear fields
+ // ...
+
+ // Create clone
+ $result=$object->create($user);
+
+ // Other options
+ if ($result < 0)
+ {
+ $this->error=$object->error;
+ $error++;
+ }
+
+ if (! $error)
+ {
+
+
+ }
+
+ // End
+ if (! $error)
+ {
+ $this->db->commit();
+ return $object->id;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ function initAsSpecimen()
+ {
+ $this->id=0;
+
+ $this->id_sondage='';
+ $this->commentaires='';
+ $this->mail_admin='';
+ $this->nom_admin='';
+ $this->titre='';
+ $this->id_sondage_admin='';
+ $this->date_fin='';
+ $this->format='';
+ $this->mailsonde='';
+ $this->survey_link_visible='';
+ $this->canedit=0;
+ }
+
+}
+?>
diff --git a/htdocs/opensurvey/css/style.css b/htdocs/opensurvey/css/style.css
new file mode 100644
index 00000000000..be8e05df4c1
--- /dev/null
+++ b/htdocs/opensurvey/css/style.css
@@ -0,0 +1,532 @@
+/* Copyright (C) 2004-2013 Laurent Destailleur
+ * Copyright (C) 2006 Rodolphe Quiedeville
+ * Copyright (C) 2007-2012 Regis Houssin
+ * Copyright (C) 2011 Philippe Grand
+ * Copyright (C) 2012 Juanjo Menent
+ *
+ * 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
+ * along with this program. If not, see .
+ */
+
+.survey_invitation
+{
+ font-color: #445566;
+ font-weight: bold;
+}
+
+.corps {
+font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+font-size: 14px;
+margin: auto;
+padding: 20px;
+overflow-x: auto;
+border: 2px solid #999999;
+background-color: #fff;
+box-shadow: 2px 2px 2px #F5F5F5;
+-moz-border-radius: 10px;
+border-radius: 10px;
+}
+
+
+.index_date, .index_sondage {
+float: left;
+width: 50%;
+text-align: center;
+}
+
+.orange {
+color: #fef4e9;
+border: solid 1px #da7c0c;
+background: #f78d1d;
+background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
+background: -moz-linear-gradient(top, #faa51a, #f47a20);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
+}
+.orange:active {
+color: #fcd3a5;
+background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
+background: -moz-linear-gradient(top, #f47a20, #faa51a);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
+}
+.orange:hover {
+background: #f47c20;
+background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
+background: -moz-linear-gradient(top, #f88e11, #f06015);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
+}
+
+
+.blue {
+color: #d9eef7;
+border: solid 1px #0076a3;
+background: #0095cd;
+background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
+background: -moz-linear-gradient(top, #00adee, #0078a5);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
+}
+.blue:active {
+color: #80bed6;
+background: -webkit-gradient(linear, left top, left bottom, from(#0078a5), to(#00adee));
+background: -moz-linear-gradient(top, #0078a5, #00adee);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0078a5', endColorstr='#00adee');
+}
+.blue:hover {
+background: #007ead;
+background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
+background: -moz-linear-gradient(top, #0095cc, #00678e);
+filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0095cc', endColorstr='#00678e');
+}
+
+
+/*
+==========================================================================
+
+Université de Strasbourg - Direction Informatique
+Auteur : Guilhem BORGHESI
+Création : Février 2008
+
+borghesi@unistra.fr
+
+Ce logiciel est régi par la licence CeCILL-B soumise au droit français et
+respectant les principes de diffusion des logiciels libres. Vous pouvez
+utiliser, modifier et/ou redistribuer ce programme sous les conditions
+de la licence CeCILL-B telle que diffusée par le CEA, le CNRS et l'INRIA
+sur le site "http://www.cecill.info".
+
+Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+pris connaissance de la licence CeCILL-B, et que vous en avez accepté les
+termes. Vous pouvez trouver une copie de la licence dans le fichier LICENCE.
+
+==========================================================================
+
+Université de Strasbourg - Direction Informatique
+Author : Guilhem BORGHESI
+Creation : Feb 2008
+
+borghesi@unistra.fr
+
+This software is governed by the CeCILL-B license under French law and
+abiding by the rules of distribution of free software. You can use,
+modify and/ or redistribute the software under the terms of the CeCILL-B
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info".
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-B license and that you accept its terms. You can
+find a copy of this license in the file LICENSE.
+
+==========================================================================
+*/
+
+/*
+Le fichier style.css est le fichier de style de studs. Il se trouve à la racine
+du répertoire studs. Il contient toutes les mises en forme des fichiers PHP
+de Studs.
+*/
+/*bandeau de titre*/
+div.bandeau{
+ line-height:35px;
+ text-align:center;
+ background-color: #0b419b;
+ color:white;
+ vertical-align:middle;
+ font-size:35px;
+ font-family:arial;
+ padding:8px;
+ height:35px;
+ position:static;
+ top:6px;
+ left:6px;
+ right:6px;
+
+}
+div.logo{
+ height:64px;
+ float:right;
+ top:8px;
+ right:8px;
+ margin-left: 0;
+ margin-right:0;
+ margin-bottom:auto;
+}
+/*Sous bandeau avec bouton de navigation*/
+div.bandeautitre{
+ height:17px;
+ font-size:14px;
+ font-weight:bold;
+ text-align:center;
+ vertical-align:middle;
+ font-family:arial;
+ padding:3px;
+ position:static;
+ top:57px;
+ left:6px;
+ right:6px;
+}
+div.sousbandeau{
+ height:17px;
+ background-color: #DDDDDD;
+ font-size:11px;
+ color:black;
+ vertical-align:middle;
+ font-family:arial;
+ padding:3px;
+ position:static;
+ top:80px;
+ left:6px;
+ right:6px;
+}
+/*bandeau de pied*/
+div.surbandeaupied{
+ background-color: #0077DD;
+ position:absolute;
+ bottom:30px;
+ left:6px;
+ right:6px;
+ height:6px;
+}
+div.bandeaupied{
+ text-align:center;
+ background-color: #0b419b;
+ color:white;
+ font-size:11px;
+ font-family:arial;
+ padding:6px;
+ position:fixed;
+ bottom:6px;
+ left:6px;
+ right:6px;
+ margin:2px;
+}
+div.surbandeaupiedmobile{
+ background-color: #0077DD;
+ position:static;
+ bottom:32px;
+ left:6px;
+ right:6px;
+ height:6px;
+}
+div.bandeaupiedmobile{
+ text-align:center;
+ background-color: #0b419b;
+ color:white;
+ font-size:11px;
+ font-family:arial;
+ padding:6px;
+ position:static;
+}
+/*les boutons se trouvant dans le sousbandeau*/
+div.sousbandeau a, div.sousbandeau span.sousbandeaulangue a {
+ background-color: #0b419b;
+ height:16px;
+ padding: 2px 6px 2px 6px;
+ vertical-align:middle;
+ text-align:center;
+ margin-left:10px;
+ margin-right:10px;
+ font-family:arial;
+ color:white;
+ font-size:10px;
+ text-decoration:none;
+}
+span.sousbandeaulangue {
+ margin-left:6px;
+ margin-right:6px;
+ float:right;
+}
+/*corps de la page index.php*/
+div.corps{
+ font-size:12px;
+ font-family:arial;
+ position:static;
+ padding:15px;
+}
+div.corps table{
+ font-family:arial;
+ font-size:12px;
+ font-weight:bold;
+}
+div.corpscentre{
+ font-size:12px;
+ font-family:arial;
+ text-align:center;
+ position:absolute;
+ top:150px;
+ margin-right:10%;
+ margin-left:10%;
+ width:80%;
+}
+/*affichage des jours*/
+div.jourschoisis {
+ background-color: #DDD;
+ padding:10px;
+ text-align: center;
+ position:static;
+ left:700px;
+ top:170px;
+ font-size:12px;
+ width:100%;
+}
+/*presenation des pages*/
+div.bodydate {
+ padding:10px;
+ font-family:arial;
+ font-size:12px;
+ text-align:center;
+ position:static;
+ top:330px;
+ left:20px;
+ right:20px;
+}
+div.bodydate table{
+ font-family:arial;
+ font-size:12px;
+ font-weight:bold;
+}
+/*cadre de commentaires*/
+div.presentationdate {
+ width:100%;
+ font-family:arial;
+ text-align:center;
+ font-size:12px;
+ border-top:1px solid;
+ border-bottom:1px solid;
+ border-left: none;
+ border-right: none;
+ border-color:#969696;
+ position:static;
+ top:110px;
+ margin-top:10px;
+}
+div.presentationdatefin {
+ width:40%;
+ padding:10px;
+ font-family:arial;
+ text-align:center;
+ font-size:12px;
+ border-width:1px;
+ border-style:solid;
+ margin-top: 10px;
+ margin-left: 30%;
+ margin-right: 30%;
+ position:static;
+}
+/*cadre principal de studs.php*/
+div.cadre {
+ padding:10px;
+ font-family:arial;
+ font-size:12px;
+ position:static;
+ top:235px;
+ text-align:center;
+ margin:0 auto;
+}
+/*la table des résultats dans l'affichage de sondage*/
+div.cadre table.resultats {
+ text-align: center;
+ margin:0 auto;
+}
+td.nom {
+ min-width: 160px;
+}
+td.vide {
+ min-width: 60px;
+}
+div.cadre td {
+ height:21px;
+}
+/*case de tableau OK dans affichage de sondage*/
+div.cadre td.ok {
+ background-color: #66FF99;
+ font-size:12px;
+ text-align:center;
+}
+/*Case de tableau NON dans affichage de sondage*/
+div.cadre td.non {
+ background-color: #FF7777;
+ min-width: 60px;
+}
+/*Case de tableau VIDE dans affichage de sondage*/
+div.cadre td.vide {
+ background-color: #DDDDDD;
+ text-align:center;
+}
+/*Case de tableau contenant les noms dans affichage de sondage*/
+div.cadre td.nom {
+ background-color: #DDDDDD;
+ font-size:12px;
+ text-align:center;
+}
+div.cadre td.casevide {
+ background-color: white;
+ text-align:center;
+}
+/*les cases contenant les sommes de chaque colonne dans l'affichage de calendrier*/
+div.cadre td.somme {
+ font-weight: bold;
+ font-size:14px;
+}
+
+/*Case de tableau SUJET dans affichage de sondage*/
+div.cadre td.sujet, div.cadre td.jour, div.cadre td.heure {
+ border: 2px;
+ background-color: #DDDDDD;
+ font-size:14px;
+ padding:1px 5px;
+}
+
+div.cadre td.annee {
+ border: 2px;
+ background-color: #969696;
+ font-weight: bold;
+ font-size:14px;
+ padding:1px 5px;
+}
+div.cadre td.mois {
+ border: 2px;
+ background-color: #C0C0C0;
+ font-weight: bold;
+ font-size:14px;
+ padding:1px 5px;
+}
+
+/*affichage du calendrier*/
+div.calendrier {
+ padding:10px;
+ background-color: #AAA;
+ width:490px;
+ font-size:12px;
+ font-family:arial;
+ margin-left: 30%;
+ margin-right: 30%;
+ position:static;
+}
+/*jour de la semaine dans calendrier*/
+div.calendrier td.joursemaine {
+ width:65px;
+ text-align: center;
+ font-family:arial;
+ font-size:14px;
+ border: 2px;
+ background-color: white;
+}
+div.calendrier td.jourwe {
+ width:65px;
+ text-align: center;
+ font-family:arial;
+ font-size:14px;
+ border: 2px;
+ background-color: #C0C0C0;
+}
+/*jour avant le premier jour du mois dans calendrier*/
+div.calendrier td.avant {
+ width:65px;
+ text-align: center;
+ border: 2px;
+ font-family:arial;
+ font-size:13px;
+ background-color: #DDDDDD;
+}
+/*jour libre dans calendrier*/
+div.calendrier td.libre {
+ width:65px;
+ text-align: center;
+ border: 2px;
+ background-color: #66FF99;
+}
+/*jour deja selectionné dans calendrier*/
+div.calendrier td.choisi {
+ width:65px;
+ text-align: center;
+ border: 2px;
+ background-color: #0077DD;
+}
+/* Le paragraphe de fin */
+p.affichageresultats{
+ text-align: center;
+ font-family:arial;
+ font-size:13px;
+}
+
+div.comment{
+ width:100%;
+}
+
+div.comment span.usercomment{
+ font-weight:bold;
+}
+
+a.affichageexport{
+ text-align: center;
+ font-family:arial;
+ font-size:10px;
+ margin-left:10px;
+ text-decoration: none;
+}
+div.titregestionadmin{
+ text-align: center;
+ font-weight:bold;
+ font-size:18px;
+ padding:10px;
+}
+
+
+.bouton {
+ width: 65px;
+ border:0px;
+ padding:0px 0 0 0;
+ margin:0px;
+ cursor:pointer;
+ font-family:arial;
+ font-size:13px;
+}
+/*les boutons pour choisir un jour non selectionné*/
+.ON {
+ background-color: #BBBBCC;
+}
+
+/*les boutons pour deselectionner un jour deja choisi*/
+.OFF {
+ background-color: #AAFFAA;
+}
+
+div.nouveau_sondage a {
+ text-decoration: none;
+}
+div.nouveau_sondage span img {
+ vertical-align: middle;
+ border: 0px;
+}
+div.nouveau_sondage span {
+ margin-left: 20px;
+}
+
+div.error, div.addcomment {
+ text-align:center;
+ border: 1px;
+ font-family: arial;
+ font-size: 13px;
+}
+ul.exports {
+ text-align:center;
+ list-style-type : none ;
+}
+li.error {
+ color: red;
+}
+
+.half {
+ -moz-transform:scale(0.5);
+ -webkit-transform:scale(0.5);
+ transform:scale(0.5);
+}
diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php
new file mode 100755
index 00000000000..6068ca965f1
--- /dev/null
+++ b/htdocs/opensurvey/fonctions.php
@@ -0,0 +1,292 @@
+
+ *
+* 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
+* along with this program. If not, see .
+*/
+
+/**
+ * \file htdocs/opensurvey/fonction.php
+ * \ingroup opensurvey
+ * \brief Functions for module
+ */
+
+
+
+/**
+ * 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
+ * @param array $arrayofjs Array of complementary js files
+ * @param array $arrayofcss Array of complementary css files
+ * @return void
+ */
+function llxHeaderSurvey($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
+{
+ global $user, $conf, $langs, $mysoc;
+
+ top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
+ print '';
+
+ showlogo();
+
+ print '';
+}
+
+/**
+ * Show footer for new member
+ *
+ * @return void
+ */
+function llxFooterSurvey()
+{
+ print '
';
+
+ printCommonFooter('public');
+
+ dol_htmloutput_events();
+
+ print "\n";
+ print "