diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index 895f2869b48..8e0092a73c0 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -35,6 +35,7 @@ ALTER TABLE llx_product_customer_price ADD COLUMN localtax2_type varchar(10) NO ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0' after localtax1_tx; ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx; +ALTER TABLE llx_opensurvey_sondage ADD COLUMN status integer DEFAULT 1 after date_fin; ALTER TABLE llx_expedition ADD COLUMN billed smallint DEFAULT 0; diff --git a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql index b728702db79..5ea2183758a 100644 --- a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql +++ b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql @@ -24,6 +24,7 @@ CREATE TABLE llx_opensurvey_sondage ( fk_user_creat integer NOT NULL, titre TEXT NOT NULL, date_fin DATETIME NOT NULL, + status integer DEFAULT 1, format VARCHAR(2) NOT NULL, -- 'A' = Text choice (choices are saved into sujet field), 'D' = Date choice (choices are saved into sujet field), 'F' = Form survey mailsonde tinyint NOT NULL DEFAULT 0, allow_comments tinyint NOT NULL DEFAULT 1, diff --git a/htdocs/langs/en_US/opensurvey.lang b/htdocs/langs/en_US/opensurvey.lang index 4ae116d4c33..bc90d1488e3 100644 --- a/htdocs/langs/en_US/opensurvey.lang +++ b/htdocs/langs/en_US/opensurvey.lang @@ -62,5 +62,5 @@ ErrorOpenSurveyOneChoice=Enter at least one choice ErrorOpenSurveyDateFormat=Date must have the format YYYY-MM-DD ErrorInsertingComment=There was an error while inserting your comment MoreChoices=Enter more choices for the voters -SurveyExpiredInfo=The voting time of this poll has expired. +SurveyExpiredInfo=The poll has been closed or voting delay has expired. EmailSomeoneVoted=%s has filled a line.\nYou can find your poll at the link: \n%s diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index c419a804210..ce941a680c7 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -35,6 +35,8 @@ if (!$user->rights->opensurvey->read) accessforbidden(); // Initialisation des variables $action=GETPOST('action'); +$cancel=GETPOST('cancel'); + $numsondage = ''; if (GETPOST('id')) { @@ -58,98 +60,119 @@ $expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GE * Actions */ +$parameters = array('id' => $numsondage); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -// Delete -if ($action == 'delete_confirm') +if (empty($reshook)) { - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); + if ($cancel) $action=''; + + // Delete + if ($action == 'delete_confirm') + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $result=$object->delete($user,'',$numsondage); + + header('Location: '.dol_buildpath('/opensurvey/list.php',1)); + exit(); + } + + // Close + if ($action == 'close') + { + $object->status = Opensurveysondage::STATUS_CLOSED; + $object->update(); + } + + // Reopend + if ($action == 'reopen') + { + $object->status = Opensurveysondage::STATUS_VALIDATED; + $object->update(); + } + + // Update + if ($action == 'update') + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $error=0; + + if (! GETPOST('nouveautitre')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); + $error++; + $action = 'edit'; + } + + if (! $error) + { + $object->titre = GETPOST('nouveautitre'); + $object->commentaires = GETPOST('nouveauxcommentaires'); + $object->mail_admin = GETPOST('nouvelleadresse'); + $object->date_fin = $expiredate; + $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false; + $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false; + $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false; + + $res=$object->update($user); + if ($res < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action='edit'; + } + } + } - $result=$object->delete($user,'',$numsondage); - - header('Location: '.dol_buildpath('/opensurvey/list.php',1)); - exit(); -} - -// Update -if ($action == 'update') -{ - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); - - $error=0; - - if (! GETPOST('nouveautitre')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); - $error++; - $action = 'edit'; - } - - if (! $error) - { - $object->titre = GETPOST('nouveautitre'); - $object->commentaires = GETPOST('nouveauxcommentaires'); - $object->mail_admin = GETPOST('nouvelleadresse'); - $object->date_fin = $expiredate; - $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false; - $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false; - $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false; - - $res=$object->update($user); - if ($res < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $action='edit'; - } - } -} - - -// Add comment -if (GETPOST('ajoutcomment')) -{ - $error=0; - - if (! GETPOST('comment')) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); - } - if (! GETPOST('commentuser')) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors'); - } - - if (! $error) - { - $comment = GETPOST("comment"); - $comment_user = GETPOST('commentuser'); - - $resql = $object->addComment($comment, $comment_user); - - if (! $resql) - { - setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors'); - } - } -} - -// Delete comment -$idcomment=GETPOST('deletecomment','int'); -if ($idcomment) -{ - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); - - $resql = $object->deleteComment($idcomment); -} - -if ($action == 'edit') { - - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); + // Add comment + if (GETPOST('ajoutcomment')) + { + $error=0; + + if (! GETPOST('comment')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); + } + if (! GETPOST('commentuser')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors'); + } + + if (! $error) + { + $comment = GETPOST("comment"); + $comment_user = GETPOST('commentuser'); + + $resql = $object->addComment($comment, $comment_user); + + if (! $resql) + { + setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors'); + } + } + } + + // Delete comment + $idcomment=GETPOST('deletecomment','int'); + if ($idcomment) + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $resql = $object->deleteComment($idcomment); + } + + if ($action == 'edit') { + + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + } } @@ -196,7 +219,7 @@ print '
| '.$langs->trans('Ref').' | '; +print '||||
| '.$langs->trans('Ref').' | '; print ''; print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage'); print ' | '; @@ -219,6 +242,12 @@ if ($action == 'edit') else print dol_htmlentities($object->titre); print '|||
| '; +print $langs->trans("Status") .' | '; +print $object->getLibStatut(4); +print ' | |||
| '.$langs->trans("Description") .' | ';
if ($action == 'edit')
@@ -326,7 +355,11 @@ dol_fiche_end();
if ($action == 'edit')
{
- print '';
+ print ' ';
+ print '';
+ print ' ';
+ print '';
+ print ' ';
}
print ''."\n";
@@ -340,9 +373,20 @@ print '';
if ($action != 'edit' && $user->rights->opensurvey->write) {
- //Modify button
- print ''.$langs->trans("Modify") . '';
+ //Modify button
+ print ''.$langs->trans("Modify") . '';
+ if ($object->status == Opensurveysondage::STATUS_VALIDATED)
+ {
+ //Close button
+ print ''.$langs->trans("Close") . '';
+ }
+ if ($object->status == Opensurveysondage::STATUS_CLOSED)
+ {
+ //Opened button
+ print ''.$langs->trans("ReOpen") . '';
+ }
+
//Delete button
print ''.$langs->trans('Delete').'';
}
diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php
index c3be8fc4793..aaf5028fd8f 100644
--- a/htdocs/opensurvey/class/opensurveysondage.class.php
+++ b/htdocs/opensurvey/class/opensurveysondage.class.php
@@ -56,6 +56,7 @@ class Opensurveysondage extends CommonObject
var $titre;
var $date_fin='';
+ var $status=1;
var $format;
var $mailsonde;
@@ -73,6 +74,22 @@ class Opensurveysondage extends CommonObject
*/
public $allow_spy;
+
+ /**
+ * Draft status (not used)
+ */
+ const STATUS_DRAFT = 0;
+ /**
+ * Validated/Opened status
+ */
+ const STATUS_VALIDATED = 1;
+ /**
+ * Closed
+ */
+ const STATUS_CLOSED = 2;
+
+
+
/**
* Constructor
*
@@ -115,6 +132,7 @@ class Opensurveysondage extends CommonObject
$sql.= "fk_user_creat,";
$sql.= "titre,";
$sql.= "date_fin,";
+ $sql.= "status,";
$sql.= "format,";
$sql.= "mailsonde,";
$sql.= "allow_comments,";
@@ -127,6 +145,7 @@ class Opensurveysondage extends CommonObject
$sql.= " ".$user->id.",";
$sql.= " '".$this->db->escape($this->titre)."',";
$sql.= " '".$this->db->idate($this->date_fin)."',";
+ $sql.= " ".$this->status.",";
$sql.= " '".$this->db->escape($this->format)."',";
$sql.= " ".$this->db->escape($this->mailsonde).",";
$sql.= " ".$this->db->escape($this->allow_comments).",";
@@ -190,6 +209,7 @@ class Opensurveysondage extends CommonObject
$sql.= " t.fk_user_creat,";
$sql.= " t.titre,";
$sql.= " t.date_fin,";
+ $sql.= " t.status,";
$sql.= " t.format,";
$sql.= " t.mailsonde,";
$sql.= " t.allow_comments,";
@@ -217,6 +237,7 @@ class Opensurveysondage extends CommonObject
$this->nom_admin = $obj->nom_admin;
$this->titre = $obj->titre;
$this->date_fin = $this->db->jdate($obj->date_fin);
+ $this->status = $obj->status;
$this->format = $obj->format;
$this->mailsonde = $obj->mailsonde;
$this->allow_comments = $obj->allow_comments;
@@ -274,6 +295,7 @@ class Opensurveysondage extends CommonObject
$sql.= " nom_admin=".(isset($this->nom_admin)?"'".$this->db->escape($this->nom_admin)."'":"null").",";
$sql.= " titre=".(isset($this->titre)?"'".$this->db->escape($this->titre)."'":"null").",";
$sql.= " date_fin=".(dol_strlen($this->date_fin)!=0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
+ $sql.= " status=".(isset($this->status)?"'".$this->db->escape($this->status)."'":"null").",";
$sql.= " format=".(isset($this->format)?"'".$this->db->escape($this->format)."'":"null").",";
$sql.= " mailsonde=".(isset($this->mailsonde)?$this->db->escape($this->mailsonde):"null").",";
$sql.= " allow_comments=".$this->db->escape($this->allow_comments).",";
@@ -428,12 +450,13 @@ class Opensurveysondage extends CommonObject
$this->id=0;
$this->id_sondage='';
- $this->commentaires='';
+ $this->commentaires='Comment of the specimen survey';
$this->mail_admin='';
$this->nom_admin='';
- $this->titre='';
- $this->date_fin='';
- $this->format='';
+ $this->titre='This is a specimen survey';
+ $this->date_fin=dol_now()+3600*24*10;
+ $this->status=1;
+ $this->format='classic';
$this->mailsonde='';
}
@@ -518,10 +541,74 @@ class Opensurveysondage extends CommonObject
$this->mail_admin = trim($this->mail_admin);
$this->nom_admin = trim($this->nom_admin);
$this->titre = trim($this->titre);
+ $this->status = trim($this->status);
$this->format = trim($this->format);
$this->mailsonde = ($this->mailsonde ? 1 : 0);
$this->allow_comments = ($this->allow_comments ? 1 : 0);
$this->allow_spy = ($this->allow_spy ? 1 : 0);
$this->sujet = trim($this->sujet);
}
+
+
+ /**
+ * Return status label of Order
+ *
+ * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+ * @return string Libelle
+ */
+ function getLibStatut($mode)
+ {
+ return $this->LibStatut($this->status,$mode);
+ }
+
+ /**
+ * Return label of status
+ *
+ * @param int $status Id statut
+ * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+ * @return string Label of status
+ */
+ function LibStatut($status,$mode)
+ {
+ global $langs, $conf;
+
+ //print 'x'.$status.'-'.$billed;
+ if ($mode == 0)
+ {
+ if ($status==self::STATUS_DRAFT) return $langs->trans('Draft');
+ if ($status==self::STATUS_VALIDATED) return $langs->trans('Opened').$billedtext;
+ if ($status==self::STATUS_CLOSED) return $langs->trans('Closed');
+ }
+ elseif ($mode == 1)
+ {
+ if ($status==self::STATUS_DRAFT) return $langs->trans('Draft');
+ if ($status==self::STATUS_VALIDATED) return $langs->trans('Opened').$billedtext;
+ if ($status==self::STATUS_CLOSED) return $langs->trans('Closed');
+ }
+ elseif ($mode == 2)
+ {
+ if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
+ if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened'),'statut1').' '.$langs->trans('Opened').$billedtext;
+ if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6').' '.$langs->trans('Closed');
+ }
+ elseif ($mode == 3)
+ {
+ if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0');
+ if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened').$billedtext,'statut1');
+ if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6');
+ }
+ elseif ($mode == 4)
+ {
+ if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
+ if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened').$billedtext,'statut1').' '.$langs->trans('Opened').$billedtext;
+ if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6').' '.$langs->trans('Closed');
+ }
+ elseif ($mode == 5)
+ {
+ if ($status==self::STATUS_DRAFT) return ''.$langs->trans('Draft').' '.img_picto($langs->trans('Draft'),'statut0');
+ if ($status==self::STATUS_VALIDATED) return ''.$langs->trans('Opened').$billedtext.' '.img_picto($langs->trans('Opened').$billedtext,'statut1');
+ if ($status==self::STATUS_CLOSED) return ''.$langs->trans('Closed').' '.img_picto($langs->trans('Closed'),'statut6');
+ }
+ }
+
}
diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php
index b440b5ee43e..aed5610bee0 100644
--- a/htdocs/opensurvey/list.php
+++ b/htdocs/opensurvey/list.php
@@ -25,6 +25,7 @@
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/class/opensurveysondage.class.php");
// Security check
if (!$user->rights->opensurvey->read) accessforbidden();
@@ -68,6 +69,7 @@ if (GETPOST('button_removefilter'))
*/
$form=new Form($db);
+$opensurvey_static = new Opensurveysondage($db);
$now = dol_now();
@@ -96,6 +98,7 @@ print_liste_field_titre($langs->trans("Type"));
print_liste_field_titre($langs->trans("Author"), $_SERVER["PHP_SELF"], "u.".$fieldtosortuser,$param,"","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("NbOfVoters"));
print_liste_field_titre($langs->trans("ExpireDate"), $_SERVER["PHP_SELF"], "p.date_fin",$param,"",'align="center"',$sortfield,$sortorder);
+print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "p.status",$param,"",'align="center"',$sortfield,$sortorder);
print_liste_field_titre('');
print ' | '; print ' | '; $arraystatus=array(''=>' ','expired'=>$langs->trans("Expired"),'opened'=>$langs->trans("Opened")); print ' | '. $form->selectarray('status', $arraystatus, $status).' | '; +print ''; print ' | '; $searchpitco=$form->showFilterAndCheckAddButtons(0); print $searchpitco; print ' | '; print ''."\n"; -$sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.titre, p.nom_admin,"; +$sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.status, p.titre, p.nom_admin,"; $sql.= " u.login, u.firstname, u.lastname"; $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"; @@ -150,6 +154,9 @@ while ($i < min($num,$limit)) } else dol_print_error($db); + $opensurvey_static->id=$obj->id_sondage; + $opensurvey_static->status=$obj->status; + $var=!$var; print '
| '; @@ -176,11 +183,13 @@ while ($i < min($num,$limit)) print ' | '; print''.$nbuser.' | '."\n"; - + print ''.dol_print_date($db->jdate($obj->date_fin),'day'); if ($db->jdate($obj->date_fin) < time()) { print ' ('.$langs->trans("Expired").')'; } print ' | '; + print''.$opensurvey_static->getLibStatut(5).' | '."\n"; + print''."\n"; print ' |
| '.$langs->trans('Ref').' | '; +print '|||
| '.$langs->trans('Ref').' | '; print ''; print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage'); print ' | '; diff --git a/htdocs/public/opensurvey/studs.php b/htdocs/public/opensurvey/studs.php index 33bd1ba1373..834f17b8b2c 100644 --- a/htdocs/public/opensurvey/studs.php +++ b/htdocs/public/opensurvey/studs.php @@ -46,7 +46,7 @@ if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); $nblignes=$object->fetch_lines(); //If the survey has not yet finished, then it can be modified -$canbemodified = (empty($object->date_fin) || $object->date_fin > dol_now()); +$canbemodified = ((empty($object->date_fin) || $object->date_fin > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED); /*||