From 8d966756073a158859b8c4ef8c46b99930a8e178 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?=
 <marcosgdf@gmail.com>
Date: Sun, 5 Jan 2014 09:08:42 +0100
Subject: [PATCH] Force logged user to create surveys and applied Dolibarr
 style to poll creation wizard

---
 htdocs/core/modules/modOpenSurvey.class.php     |  6 +++---
 htdocs/install/mysql/migration/3.5.0-3.6.0.sql  |  3 ++-
 .../mysql/tables/llx_opensurvey_sondage.sql     |  1 -
 .../class/opensurveysondage.class.php           |  4 ----
 htdocs/opensurvey/fonctions.php                 | 17 ++---------------
 htdocs/opensurvey/public/choix_autre.php        | 14 ++++----------
 htdocs/opensurvey/public/choix_date.php         | 13 ++++---------
 htdocs/opensurvey/public/create_survey.php      | 13 ++++---------
 htdocs/opensurvey/public/index.php              |  8 ++------
 9 files changed, 21 insertions(+), 58 deletions(-)

diff --git a/htdocs/core/modules/modOpenSurvey.class.php b/htdocs/core/modules/modOpenSurvey.class.php
index cb174d2df9e..98830509bd7 100644
--- a/htdocs/core/modules/modOpenSurvey.class.php
+++ b/htdocs/core/modules/modOpenSurvey.class.php
@@ -157,12 +157,12 @@ class modOpenSurvey extends DolibarrModules
 								'titre'=>'NewSurvey',
 								'mainmenu'=>'opensurvey',
 								'leftmenu'=>'opensurvey_new',
-								'url'=>'/opensurvey/public/index.php?origin=dolibarr',
+								'url'=>'/opensurvey/public/index.php',
 								'langs'=>'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',
+								'perms'=>'$user->rights->opensurvey->write',
+								'target'=>'',
 								'user'=>0);
 		$r++;
 
diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
index ffd906c0299..4d85adb9782 100755
--- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
+++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
@@ -23,4 +23,5 @@ ALTER TABLE  `llx_opensurvey_sondage` DROP COLUMN `survey_link_visible` ;
 ALTER TABLE  `llx_opensurvey_sondage` DROP INDEX  `idx_id_sondage_admin` ;
 ALTER TABLE  `llx_opensurvey_sondage` DROP COLUMN `id_sondage_admin` ;
 ALTER TABLE  `llx_opensurvey_sondage` DROP COLUMN `canedit` ;
-ALTER TABLE  `llx_opensurvey_sondage` ADD COLUMN `allow_spy` TINYINT( 1 ) UNSIGNED NOT NULL AFTER  `allow_comments` ;
\ No newline at end of file
+ALTER TABLE  `llx_opensurvey_sondage` ADD COLUMN `allow_spy` TINYINT( 1 ) UNSIGNED NOT NULL AFTER  `allow_comments` ;
+ALTER TABLE  `llx_opensurvey_sondage` DROP  `origin` ;
\ No newline at end of file
diff --git a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql
index b697b0bc4ff..ce4add9e9f5 100644
--- a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql
+++ b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql
@@ -26,7 +26,6 @@ CREATE TABLE llx_opensurvey_sondage (
        mailsonde varchar(2) DEFAULT '0',
        allow_comments TINYINT(1) unsigned NOT NULL DEFAULT 1,
 	   allow_spy TINYINT(1) unsigned NOT NULL DEFAULT 1,
-       origin VARCHAR(64),
        tms TIMESTAMP,
 	   sujet TEXT
 ) ENGINE=InnoDB;
diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php
index e67591ffa61..5d532fead5b 100644
--- a/htdocs/opensurvey/class/opensurveysondage.class.php
+++ b/htdocs/opensurvey/class/opensurveysondage.class.php
@@ -51,7 +51,6 @@ class Opensurveysondage extends CommonObject
 	var $format;
 	var $mailsonde;
 	
-	public $origin;
 	public $sujet;
 
 	/**
@@ -108,7 +107,6 @@ class Opensurveysondage extends CommonObject
 		$sql.= "mailsonde,";
 		$sql.= "allow_comments,";
 		$sql.= "allow_spy,";
-		$sql.= "origin,";
 		$sql.= "sujet";
         $sql.= ") VALUES (";
 
@@ -122,7 +120,6 @@ class Opensurveysondage extends CommonObject
 		$sql.= " ".$this->db->escape($this->mailsonde).",";
 		$sql.= " ".$this->db->escape($this->allow_comments).",";
 		$sql.= " ".$this->db->escape($this->allow_spy).",";
-		$sql.= " '".$this->db->escape($this->origin)."',";
 		$sql.= " '".$this->db->escape($this->sujet)."'";
 		
 		$sql.= ")";
@@ -497,7 +494,6 @@ class Opensurveysondage extends CommonObject
 		$this->mailsonde = ($this->mailsonde ? 1 : 0);
 		$this->allow_comments = ($this->allow_comments ? 1 : 0);
 		$this->allow_spy = ($this->allow_spy ? 1 : 0);
-		$this->origin = trim($this->origin);
 		$this->sujet = trim($this->sujet);
 	}
 }
diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php
index 5106242963a..437f851d67b 100644
--- a/htdocs/opensurvey/fonctions.php
+++ b/htdocs/opensurvey/fonctions.php
@@ -218,7 +218,6 @@ function dol_survey_random($car)
 /**
  * Add a poll
  *
- * @param	string	$origin		Origin of poll creation
  * @return	void
  */
 function ajouter_sondage($origin)
@@ -264,24 +263,10 @@ function ajouter_sondage($origin)
 	$opensurveysondage->mailsonde = $_SESSION['mailsonde'];
 	$opensurveysondage->allow_comments = $allow_comments;
 	$opensurveysondage->allow_spy = $allow_spy;
-	$opensurveysondage->origin = $origin;
 	$opensurveysondage->sujet = $_SESSION['toutchoix'];
 	
 	$opensurveysondage->create(null);
 
-	if ($origin == 'dolibarr') $urlback=dol_buildpath('/opensurvey/results.php',1).'?id='.$sondage;
-	else
-	{
-		// 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='.$sondage;
-
-		$urlback=$url;
-	}
-
 	unset($_SESSION["titre"]);
 	unset($_SESSION["nom"]);
 	unset($_SESSION["adresse"]);
@@ -292,6 +277,8 @@ function ajouter_sondage($origin)
 	unset($_SESSION['toutchoix']);
 	unset($_SESSION['totalchoixjour']);
 	unset($_SESSION['champdatefin']);
+	
+	$urlback=dol_buildpath('/opensurvey/card.php',1).'?id='.$sondage;
 
 	header("Location: ".$urlback);
 	exit();
diff --git a/htdocs/opensurvey/public/choix_autre.php b/htdocs/opensurvey/public/choix_autre.php
index 4785a2b6e28..d28f0621f8a 100644
--- a/htdocs/opensurvey/public/choix_autre.php
+++ b/htdocs/opensurvey/public/choix_autre.php
@@ -22,8 +22,6 @@
  *	\brief      Page to create a new survey (choice selection)
  */
 
-define("NOLOGIN",1);		// This means this output page does not require to be logged.
-define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
 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");
@@ -33,9 +31,6 @@ $erreur = false;
 $testdate = true;
 $date_selected = '';
 
-$origin=GETPOST('origin','alpha');
-
-
 
 /*
  * Action
@@ -103,7 +98,7 @@ if (isset($_POST["confirmecreation"]) || isset($_POST["confirmecreation_x"]))
 		$_SESSION["formatsondage"]="A";
 
 		// Add into database
-		ajouter_sondage($origin);
+		ajouter_sondage();
 	} else {
 		$_POST["fin_sondage_autre"] = 'ok';
 	}
@@ -120,7 +115,7 @@ $form=new Form($db);
 
 $arrayofjs=array();
 $arrayofcss=array('/opensurvey/css/style.css');
-llxHeaderSurvey($langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
+llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
 
 if (empty($_SESSION['titre']) || empty($_SESSION['nom']) || empty($_SESSION['adresse']))
 {
@@ -134,9 +129,8 @@ if (empty($_SESSION['titre']) || empty($_SESSION['nom']) || empty($_SESSION['adr
 //On prépare les données pour les inserer dans la base
 
 print '<form name="formulaire" action="#bas" method="POST" onkeypress="javascript:process_keypress(event)">'."\n";
-print '<input type="hidden" name="origin" value="'.dol_escape_htmltag($origin).'">';
 
-print '<div class="bandeautitre">'. $langs->trans("CreatePoll")." (2 / 2)" .'</div>'."\n";
+print_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
 
 print '<div class=corps>'."\n";
 print '<br>'. $langs->trans("PollOnChoice") .'<br><br>'."\n";
@@ -211,7 +205,7 @@ print '<a name=bas></a>'."\n";
 print '<br><br><br>'."\n";
 print '</div>'."\n";
 
-llxFooterSurvey();
+llxFooter();
 
 $db->close();
 ?>
\ No newline at end of file
diff --git a/htdocs/opensurvey/public/choix_date.php b/htdocs/opensurvey/public/choix_date.php
index 4e51a91450b..a60d7af6ca6 100644
--- a/htdocs/opensurvey/public/choix_date.php
+++ b/htdocs/opensurvey/public/choix_date.php
@@ -22,15 +22,11 @@
  *	\brief      Page to create a new survey (date selection)
  */
 
-define("NOLOGIN",1);		// This means this output page does not require to be logged.
-define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
 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");
 
-$origin=GETPOST('origin','alpha');
-
 
 /*
  * Actions
@@ -63,7 +59,7 @@ if (GETPOST('confirmation') || GETPOST('confirmation_x'))
 	else dol_print_error('','array not defined');
 
 	$_SESSION["toutchoix"]=substr("$choixdate",1);
-	ajouter_sondage($origin);
+	ajouter_sondage();
 }
 
 // Reset days
@@ -93,7 +89,7 @@ if (! isset($_SESSION['nom']) && ! isset($_SESSION['adresse']) && ! isset($_SESS
 
 $arrayofjs=array();
 $arrayofcss=array('/opensurvey/css/style.css');
-llxHeaderSurvey($langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
+llxHeader('', $langs->trans("OpenSurvey"), "", '', 0, 0, $arrayofjs, $arrayofcss);
 
 //nombre de cases par défaut
 if (! isset($_SESSION["nbrecaseshoraires"]))
@@ -221,9 +217,8 @@ else
 
 //Debut du formulaire et bandeaux de tete
 print '<form name="formulaire" action="choix_date.php" method="POST" onkeypress="javascript:process_keypress(event)">'."\n";
-print '<input type="hidden" name="origin" value="'.dol_escape_htmltag($origin).'">';
 
-print '<div class="bandeautitre">'. $langs->trans("CreatePoll")." (2 / 2)" .'</div>'."\n";
+print_fiche_titre($langs->trans("CreatePoll").' (2 / 2)');
 
 //affichage de l'aide pour les jours
 print '<div class="bodydate">'."\n";
@@ -594,7 +589,7 @@ print '</form>'."\n";
 print '<br><br><br><br>'."\n";
 print '</center></div>'."\n";
 
-llxFooterSurvey();
+llxFooter();
 
 $db->close();
 ?>
\ No newline at end of file
diff --git a/htdocs/opensurvey/public/create_survey.php b/htdocs/opensurvey/public/create_survey.php
index 505adbee1d3..850a87b9dbd 100644
--- a/htdocs/opensurvey/public/create_survey.php
+++ b/htdocs/opensurvey/public/create_survey.php
@@ -22,8 +22,6 @@
  *	\brief      Page to create a new survey
  */
 
-define("NOLOGIN",1);		// This means this output page does not require to be logged.
-define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
 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");
@@ -108,21 +106,18 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre") || GET
 
 $arrayofjs=array();
 $arrayofcss=array('/opensurvey/css/style.css');
-llxHeaderSurvey($langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
-
-
-print '<div class="bandeautitre">'. $langs->trans("CreatePoll").' (1 / 2)' .'</div>'."\n";
+llxHeader('', $langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
 
+print_fiche_titre($langs->trans("CreatePoll").' (1 / 2)');
 
 //debut du formulaire
 print '<form name="formulaire" action="create_survey.php" method="POST" onkeypress="javascript:process_keypress(event)">'."\n";
 print '<input type="hidden" name="origin" value="'.dol_escape_htmltag($origin).'">';
 
 print '<div class=corps>'."\n";
-print '<br>'. $langs->trans("YouAreInPollCreateArea") .'<br><br>'."\n";
 
 //Affichage des différents champs textes a remplir
-print '<table>'."\n";
+print '<table class="border" width="100%">'."\n";
 
 print '<tr><td class="fieldrequired">'. $langs->trans("PollTitle") .'</td><td><input type="text" name="titre" size="40" maxlength="80" value="'.$_SESSION["titre"].'"></td>'."\n";
 if (! $_SESSION["titre"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre') || GETPOST('creation_sondage_date_x') || GETPOST('creation_sondage_autre_x')))
@@ -201,7 +196,7 @@ print '<br><br><br>'."\n";
 print '</div>'."\n";
 print '</form>'."\n";
 
-llxFooterSurvey();
+llxFooter();
 
 $db->close();
 ?>
diff --git a/htdocs/opensurvey/public/index.php b/htdocs/opensurvey/public/index.php
index f78a40fa351..cc4693c76a3 100644
--- a/htdocs/opensurvey/public/index.php
+++ b/htdocs/opensurvey/public/index.php
@@ -22,11 +22,7 @@
 //if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
 //if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1'); // If there is no menu to show
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
 if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
-define("NOLOGIN",1);		// This means this output page does not require to be logged.
-define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
 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");
@@ -43,7 +39,7 @@ $langs->load("opensurvey");
 
 $arrayofjs=array();
 $arrayofcss=array('/opensurvey/css/style.css');
-llxHeaderSurvey($langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
+llxHeader('', $langs->trans("OpenSurvey"), "", 0, 0, $arrayofjs, $arrayofcss);
 
 print '<center>
 <form name="formulaire" action="create_survey.php" method="POST">
@@ -56,7 +52,7 @@ print '<p>'.$langs->trans("OrganizeYourMeetingEasily").'</p>
 </div>
 </form></center>';
 
-llxFooterSurvey();
+llxFooter();
 
 $db->close();
 ?>
-- 
GitLab