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

@@ -25,3 +25,4 @@ 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` ;
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,
mail_admin VARCHAR(128),
nom_admin VARCHAR(64),
fk_user_creat INT(11) UNSIGNED NOT NULL,
titre TEXT,
date_fin DATETIME,
format VARCHAR(2),

View File

@@ -211,10 +211,17 @@ if ($action == 'edit')
else print dol_htmlentities($object->titre);
print '</td></tr>';
// Auteur
// Author
print '<tr><td>';
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>';
// Description
@@ -227,13 +234,16 @@ else print dol_nl2br(dol_htmlentities($object->commentaires));
print '</td></tr>';
// EMail
print '<tr><td>'.$langs->trans("EMail") .'</td><td colspan="2">';
if ($action == 'edit')
{
//If linked user, then emails are going to be sent to users' email
if (!$object->fk_user_creat) {
print '<tr><td>'.$langs->trans("EMail") .'</td><td colspan="2">';
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
print '<tr><td>'.$langs->trans('ToReceiveEMailForEachVote').'</td><td colspan="2">';

View File

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

View File

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

View File

@@ -59,8 +59,9 @@ print_fiche_titre($langs->trans("OpenSurveyArea"));
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";
$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.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
// Count total nb of records
$nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -98,7 +99,20 @@ while ($i < min($num,$limit))
$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 ' '.$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');
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
$listofvoters=explode(',',$_SESSION["savevoter"]);
if (! empty($object->mailsonde))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$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));
$result=$cmailfile->sendfile();
if ($result)
if ($object->mailsonde)
{
if ($object->fk_user_creat) {
$userstatic = new User($db);
$userstatic->fetch($object->fk_user_creat);
$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>';
/*
// 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";
llxFooterSurvey();

View File

@@ -105,7 +105,7 @@ $arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css');
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'));
llxFooterSurvey();

View File

@@ -191,7 +191,7 @@ if (GETPOST('reset')) {
* 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'));
exit;

View File

@@ -34,21 +34,20 @@ $langs->load("opensurvey");
// 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
$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)
{
$$var = GETPOST($var);
}
// 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)
{
if (isset($_SESSION[$var])) $_SESSION[$var] = null;
}
// On initialise également les autres variables
$erreur_adresse = false;
$cocheplus = '';
$cochemail = '';
@@ -56,8 +55,6 @@ $cochemail = '';
if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
{
$_SESSION["titre"] = $titre;
$_SESSION["nom"] = $nom;
$_SESSION["adresse"] = $adresse;
$_SESSION["commentaires"] = $commentaires;
if (GETPOST('mailsonde') == 'on') {
@@ -100,9 +97,7 @@ if (GETPOST("creation_sondage_date") || GETPOST("creation_sondage_autre"))
setEventMessage($langs->trans('ErrorOpenSurveyDateFormat'), 'errors');
}
if (! isValidEmail($adresse)) $erreur_adresse = true;
if ($titre && $nom && $adresse && !$erreur_adresse && $testdate)
if ($titre && $testdate)
{
if (! empty($creation_sondage_date))
{
@@ -148,28 +143,6 @@ if (! $_SESSION["titre"] && (GETPOST('creation_sondage_date') || GETPOST('creati
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>'."\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>';