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 4d85adb9782e22001e17ff07a6535879c413dd4c..6a189c4c7569366c6ae5a1c760eb2c7a6b6ed87e 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 @@ -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 `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` ; \ No newline at end of file +ALTER TABLE `llx_opensurvey_sondage` DROP `origin` ; +ALTER TABLE `llx_opensurvey_sondage` ADD `fk_user_creat` INT( 11 ) UNSIGNED NOT NULL AFTER `nom_admin` ; \ 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 ce4add9e9f50bb56b75b9b7cc21cd34a579dea75..db1231588f31e0a0653962b3727f57ac4a7f6fca 100644 --- a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql +++ b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql @@ -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), diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index 474d7db85f4cd5b9f5326d61b3a26bc1f192c99e..1fac0c16ed8a9c3e22613b96f7f1760fc5abead3 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -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') -{ - print '<input type="text" name="nouvelleadresse" size="40" value="'.$object->mail_admin.'">'; +//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">'; diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 7630cb39e8ec3995381df95e511b4b74a7e6c8eb..a4f81ced81c7c45181599df92a156c0fd460e2da 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -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)."',"; @@ -142,7 +148,7 @@ class Opensurveysondage extends CommonObject //// End call triggers } } - + // Commit or rollback if ($error) { @@ -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; diff --git a/htdocs/opensurvey/fonctions.php b/htdocs/opensurvey/fonctions.php index be7b25005c202c4f6aa2e67134e9da3770a05d9d..c3c80a59b86051431bfecedf264cebf714636232 100644 --- a/htdocs/opensurvey/fonctions.php +++ b/htdocs/opensurvey/fonctions.php @@ -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"]); diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index d5554315194e53a7f9498ee350d28573a58a0ad8..a9b36ca7a1c77377c99447d367682539c4e3bd01 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -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(); } diff --git a/htdocs/opensurvey/public/studs.php b/htdocs/opensurvey/public/studs.php index 9eac7face2c5270ad9da68f284a31c9c7ba4eec1..162643cf1495e60ccd240d3dd5f3d33ebb364bce 100644 --- a/htdocs/opensurvey/public/studs.php +++ b/htdocs/opensurvey/public/studs.php @@ -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)) + if ($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->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(); diff --git a/htdocs/opensurvey/wizard/choix_autre.php b/htdocs/opensurvey/wizard/choix_autre.php index c02fe4822db04f308e351e77a25971e85c0feef8..c00ddf38384891c663c12892786e86f1075865fd 100644 --- a/htdocs/opensurvey/wizard/choix_autre.php +++ b/htdocs/opensurvey/wizard/choix_autre.php @@ -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(); diff --git a/htdocs/opensurvey/wizard/choix_date.php b/htdocs/opensurvey/wizard/choix_date.php index 0d78e5969b0afaa98187e8de66b5ae7e5132e868..3de7d10f8a1753243ca03e2bebd4e69b87e760c7 100644 --- a/htdocs/opensurvey/wizard/choix_date.php +++ b/htdocs/opensurvey/wizard/choix_date.php @@ -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; diff --git a/htdocs/opensurvey/wizard/create_survey.php b/htdocs/opensurvey/wizard/create_survey.php index 6e1927b7f2bf6037443a047c205b6f150cf8d0e6..26411fa18b5c6c00dbf492ba918215c8dca60bf8 100644 --- a/htdocs/opensurvey/wizard/create_survey.php +++ b/htdocs/opensurvey/wizard/create_survey.php @@ -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>';