Skip to content

Commit

Permalink
Added a new feature to disable spying other users’ vote
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgdf committed Jan 3, 2014
1 parent 2b01981 commit 13d4ea4
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 153 deletions.
7 changes: 4 additions & 3 deletions htdocs/install/mysql/migration/3.5.0-3.6.0.sql
Expand Up @@ -18,7 +18,8 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);

ALTER TABLE llx_bookmark ADD COLUMN entity integer DEFAULT 1 NOT NULL;
ALTER TABLE `llx_opensurvey_sondage` ADD `allow_comments` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT 1 AFTER `canedit` ;
ALTER TABLE `llx_opensurvey_sondage` DROP `survey_link_visible` ;
ALTER TABLE `llx_opensurvey_sondage` ADD COLUMN `allow_comments` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT 1 AFTER `canedit` ;
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 `id_sondage_admin` ;
ALTER TABLE `llx_opensurvey_sondage` DROP COLUMN `id_sondage_admin` ;
ALTER TABLE `llx_opensurvey_sondage` ADD COLUMN `allow_spy` TINYINT( 1 ) UNSIGNED NOT NULL AFTER `allow_comments` ;
1 change: 1 addition & 0 deletions htdocs/install/mysql/tables/llx_opensurvey_sondage.sql
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE llx_opensurvey_sondage (
mailsonde varchar(2) DEFAULT '0',
canedit integer 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
Expand Down
5 changes: 3 additions & 2 deletions htdocs/langs/en_US/opensurvey.lang
Expand Up @@ -27,7 +27,7 @@ SelectedDays=Selected days
TheBestChoice=The best choice currently is
TheBestChoices=The best choices currently are
with=with
OpenSurveyHowTo=If you agree to vote in this poll, you have to give your name, choose the values that fit best for you (without paying attention to the choices of the other voters) and validate with the plus button at the end of the line.
OpenSurveyHowTo=If you agree to vote in this poll, you have to give your name, choose the values that fit best for you and validate with the plus button at the end of the line.
InitiatorOfPoll=Initiator of the poll
CommentsOfVoters=Comments of voters
ConfirmRemovalOfPoll=Are you sure you want to remove this poll (and all votes)
Expand Down Expand Up @@ -66,7 +66,8 @@ AddEndHour=Add end hour
votes=vote(s)
NoCommentYet=No comments have been posted for this poll yet
CanEditVotes=Can change vote of others
CanComment=Users can comment in the poll
CanComment=Voters can comment in the poll
CanSeeOthersVote=Voters can see other people's vote
SelectDayDesc=For each selected day, you can choose, or not, meeting hours in the following format :<br>- empty,<br>- "8h", "8H" or "8:00" to give a meeting's start hour,<br>- "8-11", "8h-11h", "8H-11H" or "8:00-11:00" to give a meeting's start and end hour,<br>- "8h15-11h15", "8H15-11H15" or "8:15-11:15" for the same thing but with minutes.
BackToCurrentMonth=Back to current month
PublicLinkToCreateSurvey=Public link to allow everybody to create a survey
Expand Down
12 changes: 11 additions & 1 deletion htdocs/opensurvey/adminstuds.php
Expand Up @@ -88,6 +88,7 @@
$object->date_fin = $expiredate;
$object->canedit = GETPOST('canedit')=='on'?1:0;
$object->allow_comments = GETPOST('cancomment') == 'on' ? true : false;
$object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false;

$res=$object->update($user);
if ($res < 0)
Expand Down Expand Up @@ -176,7 +177,7 @@
// Ref
print '<tr><td width="18%">'.$langs->trans('Ref').'</td>';
print '<td colspan="3">';
print $form->showrefnav($object, 'sondage', $linkback, 1, 'id_sondage', 'id_sondage');
print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage');
print '</td>';
print '</tr>';

Expand Down Expand Up @@ -239,6 +240,15 @@
else print yn($object->allow_comments);
print '</td></tr>';

// Users can see others vote
print '<tr><td>'.$langs->trans('CanSeeOthersVote').'</td><td colspan="2">';
if ($action == 'edit')
{
print '<input type="checkbox" name="canseeothersvote" size="40"'.($object->allow_spy?' checked="true"':'').'">';
}
else print yn($object->allow_spy);
print '</td></tr>';

// Expire date
print '<tr><td>'.$langs->trans('ExpireDate').'</td><td colspan="2">';
if ($action == 'edit') print $form->select_date($expiredate?$expiredate:$object->date_fin,'expire');
Expand Down
14 changes: 12 additions & 2 deletions htdocs/opensurvey/class/opensurveysondage.class.php
Expand Up @@ -57,6 +57,12 @@ class Opensurveysondage extends CommonObject
* @var bool
*/
public $allow_comments;

/**
* Allow users see others vote
* @var bool
*/
public $allow_spy;

/**
* Constructor
Expand Down Expand Up @@ -121,7 +127,7 @@ function create($user, $notrigger=0)
$sql.= " ".(! isset($this->format)?'NULL':"'".$this->db->escape($this->format)."'").",";
$sql.= " ".(! isset($this->mailsonde)?'NULL':"'".$this->db->escape($this->mailsonde)."'").",";
$sql.= " ".(! isset($this->canedit)?'NULL':"'".$this->db->escape($this->canedit)."'")."";

$sql.= ")";

$this->db->begin();
Expand Down Expand Up @@ -189,6 +195,7 @@ function fetch($id,$numsurvey='')
$sql.= " t.mailsonde,";
$sql.= " t.canedit,";
$sql.= " t.allow_comments,";
$sql.= " t.allow_spy,";
$sql.= " t.sujet,";
$sql.= " t.tms";
$sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
Expand All @@ -212,6 +219,7 @@ function fetch($id,$numsurvey='')
$this->mailsonde = $obj->mailsonde;
$this->canedit = $obj->canedit;
$this->allow_comments = $obj->allow_comments;
$this->allow_spy = $obj->allow_spy;
$this->sujet = $obj->sujet;

$this->date_m = $this->db->jdate($obj->tls);
Expand Down Expand Up @@ -261,6 +269,7 @@ function update($user=0, $notrigger=0)
if (isset($this->mailsonde)) $this->mailsonde=trim($this->mailsonde);
$this->canedit = $this->canedit ? 1 : 0;
$this->allow_comments = $this->allow_comments ? 1 : 0;
$this->allow_spy = $this->allow_spy ? 1 : 0;

// Check parameters
// Put here code to add a control on parameters values
Expand All @@ -277,7 +286,8 @@ function update($user=0, $notrigger=0)
$sql.= " format=".(isset($this->format)?"'".$this->db->escape($this->format)."'":"null").",";
$sql.= " mailsonde=".(isset($this->mailsonde)?$this->db->escape($this->mailsonde):"null").",";
$sql.= " canedit=".$this->db->escape($this->canedit).",";
$sql.= " allow_comments=".$this->db->escape($this->allow_comments);
$sql.= " allow_comments=".$this->db->escape($this->allow_comments).",";
$sql.= " allow_spy=".$this->db->escape($this->allow_spy);

$sql.= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";

Expand Down
10 changes: 6 additions & 4 deletions htdocs/opensurvey/fonctions.php
Expand Up @@ -229,7 +229,7 @@ function dol_survey_random($car)
*/
function ajouter_sondage($origin)
{
global $conf, $db;
global $db;

$sondage=dol_survey_random(16);

Expand All @@ -255,13 +255,14 @@ function ajouter_sondage($origin)
}
$canedit=empty($_SESSION['formatcanedit'])?'0':'1';
$allow_comments = empty($_SESSION['allow_comments']) ? 0 : 1;

$allow_spy = empty($_SESSION['allow_spy']) ? 0 : 1;

// Insert survey
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'opensurvey_sondage';
$sql.= '(id_sondage, commentaires, mail_admin, nom_admin, titre, date_fin, format, mailsonde, canedit, allow_comments, origin, sujet)';
$sql.= '(id_sondage, commentaires, mail_admin, nom_admin, titre, date_fin, format, mailsonde, canedit, allow_comments, allow_spy, origin, sujet)';
$sql.= " VALUES ('".$db->escape($sondage)."', '".$db->escape($_SESSION['commentaires'])."', '".$db->escape($_SESSION['adresse'])."', '".$db->escape($_SESSION['nom'])."',";
$sql.= " '".$db->escape($_SESSION['titre'])."', '".$db->idate($date_fin)."', '".$_SESSION['formatsondage']."', '".$db->escape($_SESSION['mailsonde'])."',";
$sql.= " '".$canedit."', '".$allow_comments."', '".$db->escape($origin)."',";
$sql.= " '".$canedit."', '".$allow_comments."', '".$allow_spy."', '".$db->escape($origin)."',";
$sql.= " '".$db->escape($_SESSION['toutchoix'])."'";
$sql.= ")";
dol_syslog($sql);
Expand Down Expand Up @@ -289,6 +290,7 @@ function ajouter_sondage($origin)
unset($_SESSION["canedit"]);
unset($_SESSION["mailsonde"]);
unset($_SESSION['allow_comments']);
unset($_SESSION['allow_spy']);

header("Location: ".$urlback);
exit();
Expand Down
10 changes: 10 additions & 0 deletions htdocs/opensurvey/public/create_survey.php
Expand Up @@ -80,6 +80,12 @@
} else {
$_SESSION['allow_comments'] = false;
}

if (GETPOST('allow_spy') == 'on') {
$_SESSION['allow_spy'] = true;
} else {
$_SESSION['allow_spy'] = false;
}

if (! isValidEmail($adresse)) $erreur_adresse = true;

Expand Down Expand Up @@ -182,6 +188,10 @@

print '<input type="checkbox" name="allow_comments" '.$allow_comments.'> '.$langs->trans('CanComment').'<br />'."\n";

if ($_SESSION['allow_spy']) $allow_spy = "checked";

print '<input type="checkbox" name="allow_spy" '.$allow_spy.'> '.$langs->trans('CanSeeOthersVote').'<br />'."\n";

if (GETPOST('choix_sondage'))
{
if (GETPOST('choix_sondage') == 'date') print '<input type="hidden" name="creation_sondage_date" value="date">';
Expand Down

0 comments on commit 13d4ea4

Please sign in to comment.