2
0
forked from Wavyzz/dolibarr

Email and poll author are now retrieved from the logged user

This commit is contained in:
Marcos García de La Fuente
2014-01-06 05:08:42 +01:00
parent b8b7dbbed4
commit e0c7eb545c
10 changed files with 78 additions and 75 deletions

View File

@@ -24,4 +24,5 @@ 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 `id_sondage_admin` ;
ALTER TABLE `llx_opensurvey_sondage` DROP COLUMN `canedit` ; 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` ; ALTER TABLE `llx_opensurvey_sondage` ADD COLUMN `allow_spy` TINYINT( 1 ) UNSIGNED NOT NULL AFTER `allow_comments` ;
ALTER TABLE `llx_opensurvey_sondage` DROP `origin` ; ALTER TABLE `llx_opensurvey_sondage` DROP `origin` ;
ALTER TABLE `llx_opensurvey_sondage` ADD `fk_user_creat` INT( 11 ) UNSIGNED NOT NULL AFTER `nom_admin` ;

View File

@@ -20,6 +20,7 @@ CREATE TABLE llx_opensurvey_sondage (
commentaires text, commentaires text,
mail_admin VARCHAR(128), mail_admin VARCHAR(128),
nom_admin VARCHAR(64), nom_admin VARCHAR(64),
fk_user_creat INT(11) UNSIGNED NOT NULL,
titre TEXT, titre TEXT,
date_fin DATETIME, date_fin DATETIME,
format VARCHAR(2), format VARCHAR(2),

View File

@@ -211,10 +211,17 @@ if ($action == 'edit')
else print dol_htmlentities($object->titre); else print dol_htmlentities($object->titre);
print '</td></tr>'; print '</td></tr>';
// Auteur // Author
print '<tr><td>'; print '<tr><td>';
print $langs->trans("Author") .'</td><td colspan="2">'; print $langs->trans("Author") .'</td><td colspan="2">';
print dol_htmlentities($object->nom_admin); if ($object->fk_user_creat) {
$userstatic = new User($db);
$userstatic->fetch($object->fk_user_creat);
print $userstatic->getLoginUrl(1);
} else {
print dol_htmlentities($object->nom_admin);
}
print '</td></tr>'; print '</td></tr>';
// Description // Description
@@ -227,13 +234,16 @@ else print dol_nl2br(dol_htmlentities($object->commentaires));
print '</td></tr>'; print '</td></tr>';
// EMail // EMail
print '<tr><td>'.$langs->trans("EMail") .'</td><td colspan="2">'; //If linked user, then emails are going to be sent to users' email
if ($action == 'edit') if (!$object->fk_user_creat) {
{ print '<tr><td>'.$langs->trans("EMail") .'</td><td colspan="2">';
print '<input type="text" name="nouvelleadresse" size="40" value="'.$object->mail_admin.'">'; if ($action == 'edit')
{
print '<input type="text" name="nouvelleadresse" size="40" value="'.$object->mail_admin.'">';
}
else print dol_print_email($object->mail_admin);
print '</td></tr>';
} }
else print dol_print_email($object->mail_admin);
print '</td></tr>';
// Receive an email with each vote // Receive an email with each vote
print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td colspan="2">'; print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td colspan="2">';

View File

@@ -44,8 +44,16 @@ class Opensurveysondage extends CommonObject
var $id_sondage; var $id_sondage;
var $commentaires; var $commentaires;
var $mail_admin; var $mail_admin;
var $nom_admin; var $nom_admin;
/**
* Id of user author of the poll
* @var int
*/
public $fk_user_creat;
var $titre; var $titre;
var $date_fin=''; var $date_fin='';
var $format; var $format;
@@ -99,8 +107,7 @@ class Opensurveysondage extends CommonObject
$sql.= "id_sondage,"; $sql.= "id_sondage,";
$sql.= "commentaires,"; $sql.= "commentaires,";
$sql.= "mail_admin,"; $sql.= "fk_user_creat,";
$sql.= "nom_admin,";
$sql.= "titre,"; $sql.= "titre,";
$sql.= "date_fin,"; $sql.= "date_fin,";
$sql.= "format,"; $sql.= "format,";
@@ -112,8 +119,7 @@ class Opensurveysondage extends CommonObject
$sql.= "'".$this->db->escape($this->id_sondage)."',"; $sql.= "'".$this->db->escape($this->id_sondage)."',";
$sql.= " ".(empty($this->commentaires)?'NULL':"'".$this->db->escape($this->commentaires)."'").","; $sql.= " ".(empty($this->commentaires)?'NULL':"'".$this->db->escape($this->commentaires)."'").",";
$sql.= " ".(empty($this->mail_admin)?'NULL':"'".$this->db->escape($this->mail_admin)."'").","; $sql.= " ".$user->id.",";
$sql.= " '".$this->db->escape($this->nom_admin)."',";
$sql.= " '".$this->db->escape($this->titre)."',"; $sql.= " '".$this->db->escape($this->titre)."',";
$sql.= " '".$this->db->idate($this->date_fin)."',"; $sql.= " '".$this->db->idate($this->date_fin)."',";
$sql.= " '".$this->db->escape($this->format)."',"; $sql.= " '".$this->db->escape($this->format)."',";
@@ -142,7 +148,7 @@ class Opensurveysondage extends CommonObject
//// End call triggers //// End call triggers
} }
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error)
{ {
@@ -176,6 +182,7 @@ class Opensurveysondage extends CommonObject
$sql.= " t.commentaires,"; $sql.= " t.commentaires,";
$sql.= " t.mail_admin,"; $sql.= " t.mail_admin,";
$sql.= " t.nom_admin,"; $sql.= " t.nom_admin,";
$sql.= " t.fk_user_creat,";
$sql.= " t.titre,"; $sql.= " t.titre,";
$sql.= " t.date_fin,"; $sql.= " t.date_fin,";
$sql.= " t.format,"; $sql.= " t.format,";
@@ -209,6 +216,7 @@ class Opensurveysondage extends CommonObject
$this->allow_comments = $obj->allow_comments; $this->allow_comments = $obj->allow_comments;
$this->allow_spy = $obj->allow_spy; $this->allow_spy = $obj->allow_spy;
$this->sujet = $obj->sujet; $this->sujet = $obj->sujet;
$this->fk_user_creat = $obj->fk_user_creat;
$this->date_m = $this->db->jdate($obj->tls); $this->date_m = $this->db->jdate($obj->tls);
$ret=1; $ret=1;

View File

@@ -204,7 +204,7 @@ function dol_survey_random($car)
*/ */
function ajouter_sondage() function ajouter_sondage()
{ {
global $db; global $db, $user;
require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php'; require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
@@ -227,7 +227,11 @@ function ajouter_sondage()
$opensurveysondage->allow_spy = $allow_spy; $opensurveysondage->allow_spy = $allow_spy;
$opensurveysondage->sujet = $_SESSION['toutchoix']; $opensurveysondage->sujet = $_SESSION['toutchoix'];
$opensurveysondage->create(null); $res = $opensurveysondage->create($user);
if ($res < 0) {
dol_print_error($db);
}
unset($_SESSION["titre"]); unset($_SESSION["titre"]);
unset($_SESSION["nom"]); unset($_SESSION["nom"]);

View File

@@ -59,8 +59,9 @@ print_fiche_titre($langs->trans("OpenSurveyArea"));
print '<table class="liste">'."\n"; print '<table class="liste">'."\n";
print '<tr class="liste_titre"><td>'. $langs->trans("Ref").'</td><td>'. $langs->trans("Title") .'</td><td>'. $langs->trans("Type") .'</td><td>'. $langs->trans("Author") .'</td><td align="center">'. $langs->trans("ExpireDate") .'</td><td align="center">'. $langs->trans("NbOfVoters") .'</td>'."\n"; print '<tr class="liste_titre"><td>'. $langs->trans("Ref").'</td><td>'. $langs->trans("Title") .'</td><td>'. $langs->trans("Type") .'</td><td>'. $langs->trans("Author") .'</td><td align="center">'. $langs->trans("ExpireDate") .'</td><td align="center">'. $langs->trans("NbOfVoters") .'</td>'."\n";
$sql = "SELECT id_sondage, mail_admin, format, date_fin, titre, nom_admin"; $sql = "SELECT id_sondage, fk_user_creat, u.login, format, date_fin, titre, nom_admin";
$sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p"; $sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p";
$sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
// Count total nb of records // Count total nb of records
$nbtotalofrecords = 0; $nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -98,7 +99,20 @@ while ($i < min($num,$limit))
$type=($obj->format=='A')?'classic':'date'; $type=($obj->format=='A')?'classic':'date';
print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1); 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"); print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate");
print '</td><td>'.dol_htmlentities($obj->nom_admin).'</td>'; print '</td><td>';
// Author
if ($obj->fk_user_creat) {
$userstatic = new User($db);
$userstatic->id = $obj->fk_user_creat;
$userstatic->login = $obj->login;
print $userstatic->getLoginUrl(1);
} else {
print dol_htmlentities($obj->nom_admin);
}
print '</td>';
print '<td align="center">'.dol_print_date($db->jdate($obj->date_fin),'day'); print '<td align="center">'.dol_print_date($db->jdate($obj->date_fin),'day');
if ($db->jdate($obj->date_fin) < time()) { print ' '.img_warning(); } if ($db->jdate($obj->date_fin) < time()) { print ' '.img_warning(); }

View File

@@ -133,18 +133,25 @@ if (isset($_POST["boutonp"]))
$_SESSION["savevoter"]=$nom.','.(empty($_SESSION["savevoter"])?'':$_SESSION["savevoter"]); // Save voter $_SESSION["savevoter"]=$nom.','.(empty($_SESSION["savevoter"])?'':$_SESSION["savevoter"]); // Save voter
$listofvoters=explode(',',$_SESSION["savevoter"]); $listofvoters=explode(',',$_SESSION["savevoter"]);
if (! empty($object->mailsonde)) if ($object->mailsonde)
{ {
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; if ($object->fk_user_creat) {
$cmailfile=new CMailFile("[".MAIN_APPLICATION_TITLE."] ".$langs->trans("Poll").': '.$object->titre, $object->mail_admin, $conf->global->MAIN_MAIL_EMAIL_FROM, $nom." has filled a line.\nYou can find your poll at the link:\n".getUrlSondage($numsondage)); $userstatic = new User($db);
$result=$cmailfile->sendfile(); $userstatic->fetch($object->fk_user_creat);
if ($result)
{ $email = $userstatic->email;
} else {
$email = $object->mail_admin;
} }
else
{ //Linked user may not have an email set
if ($email) {
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$body = $langs->trans('EmailSomeoneVoted', $nom, getUrlSondage($numsondage, true));
$cmailfile=new CMailFile("[".MAIN_APPLICATION_TITLE."] ".$langs->trans("Poll").': '.$object->titre, $email, $conf->global->MAIN_MAIL_EMAIL_FROM, $body);
$result=$cmailfile->sendfile();
} }
} }
} }
@@ -728,21 +735,6 @@ if ($object->allow_comments) {
print '<br><br>'; print '<br><br>';
/*
// 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
$message='';
$url=$urlwithouturlroot.dol_buildpath('/opensurvey/public/studs.php',1).'?sondage='.$numsondage;
$urlvcal='<a href="'.$url.'" target="_blank">'.$url.'</a>';
$message.=img_picto('','object_globe.png').' '.$langs->trans("UrlForSurvey").': '.$urlvcal;
print '<center>'.$message.'</center>';
*/
print '<a name="bas"></a>'."\n"; print '<a name="bas"></a>'."\n";
llxFooterSurvey(); llxFooterSurvey();

View File

@@ -105,7 +105,7 @@ $arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css'); $arrayofcss=array('/opensurvey/css/style.css');
llxHeader('', $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'])) if (empty($_SESSION['titre']))
{ {
dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection')); dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection'));
llxFooterSurvey(); llxFooterSurvey();

View File

@@ -191,7 +191,7 @@ if (GETPOST('reset')) {
* View * View
*/ */
if (! isset($_SESSION['nom']) && ! isset($_SESSION['adresse']) && ! isset($_SESSION['commentaires']) && ! isset($_SESSION['mail'])) if (! isset($_SESSION['commentaires']) && ! isset($_SESSION['mail']))
{ {
dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection')); dol_print_error('', $langs->trans('ErrorOpenSurveyFillFirstSection'));
exit; exit;

View File

@@ -34,21 +34,20 @@ $langs->load("opensurvey");
// On teste toutes les variables pour supprimer l'ensemble des warnings PHP // On teste toutes les variables pour supprimer l'ensemble des warnings PHP
// On transforme en entites html les données afin éviter les failles XSS // On transforme en entites html les données afin éviter les failles XSS
$post_var = array('titre', 'nom', 'adresse', 'commentaires', 'mailsonde', 'creation_sondage_date', 'creation_sondage_autre'); $post_var = array('titre', 'commentaires', 'mailsonde', 'creation_sondage_date', 'creation_sondage_autre');
foreach ($post_var as $var) foreach ($post_var as $var)
{ {
$$var = GETPOST($var); $$var = GETPOST($var);
} }
// On initialise egalement la session car sinon bonjour les warning :-) // On initialise egalement la session car sinon bonjour les warning :-)
$session_var = array('titre', 'nom', 'adresse', 'commentaires', 'mailsonde'); $session_var = array('titre', 'commentaires', 'mailsonde');
foreach ($session_var as $var) foreach ($session_var as $var)
{ {
if (isset($_SESSION[$var])) $_SESSION[$var] = null; if (isset($_SESSION[$var])) $_SESSION[$var] = null;
} }
// On initialise également les autres variables // On initialise également les autres variables
$erreur_adresse = false;
$cocheplus = ''; $cocheplus = '';
$cochemail = ''; $cochemail = '';
@@ -56,8 +55,6 @@ $cochemail = '';
if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre")) if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
{ {
$_SESSION["titre"] = $titre; $_SESSION["titre"] = $titre;
$_SESSION["nom"] = $nom;
$_SESSION["adresse"] = $adresse;
$_SESSION["commentaires"] = $commentaires; $_SESSION["commentaires"] = $commentaires;
if (GETPOST('mailsonde') == 'on') { if (GETPOST('mailsonde') == 'on') {
@@ -100,9 +97,7 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
setEventMessage($langs->trans('ErrorOpenSurveyDateFormat'), 'errors'); setEventMessage($langs->trans('ErrorOpenSurveyDateFormat'), 'errors');
} }
if (! isValidEmail($adresse)) $erreur_adresse = true; if ($titre && $testdate)
if ($titre && $nom && $adresse && !$erreur_adresse && $testdate)
{ {
if (! empty($creation_sondage_date)) if (! empty($creation_sondage_date))
{ {
@@ -148,28 +143,6 @@ if (! $_SESSION["titre"] && (GETPOST('creation_sondage_date') || GETPOST('creati
print '</tr>'."\n"; print '</tr>'."\n";
print '<tr><td>'. $langs->trans("Description") .'</td><td><textarea name="commentaires" rows="7" cols="40">'.$_SESSION["commentaires"].'</textarea></td>'."\n"; print '<tr><td>'. $langs->trans("Description") .'</td><td><textarea name="commentaires" rows="7" cols="40">'.$_SESSION["commentaires"].'</textarea></td>'."\n";
print '</tr>'."\n"; print '</tr>'."\n";
print '<tr><td class="fieldrequired">'. $langs->trans("OpenSurveyYourName") .'</td><td>';
print '<input type="text" name="nom" size="40" maxlength="40" value="'.$_SESSION["nom"].'"></td>'."\n";
if (! $_SESSION["nom"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre')))
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("OpenSurveyYourName")), 'errors');
}
print '</tr>'."\n";
print '<tr><td class="fieldrequired">'. $langs->trans("OpenSurveyYourEMail") .'</td><td>';
print '<input type="text" name="adresse" size="40" maxlength="64" value="'.$_SESSION["adresse"].'"></td>'."\n";
if (!$_SESSION["adresse"] && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre')))
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("OpenSurveyYourEMail")), 'errors');
} elseif ($erreur_adresse && (GETPOST('creation_sondage_date') || GETPOST('creation_sondage_autre')))
{
$langs->load('errors');
setEventMessage($langs->trans("ErrorBadEMail", $adresse), 'errors');
}
print '<tr><td class="fieldrequired">'. $langs->trans("ExpireDate") .'</td><td>'; print '<tr><td class="fieldrequired">'. $langs->trans("ExpireDate") .'</td><td>';