Moved creation of surveys to the function Opensurveysondage::create

This commit is contained in:
Marcos García de La Fuente 2014-01-04 15:42:44 +01:00
parent b9ec6ad637
commit 3590e3d7b6
2 changed files with 53 additions and 35 deletions

View File

@ -51,6 +51,9 @@ class Opensurveysondage extends CommonObject
var $format;
var $mailsonde;
var $canedit;
public $origin;
public $sujet;
/**
* Allow comments on this poll
@ -89,16 +92,18 @@ class Opensurveysondage extends CommonObject
// Clean parameters
if (isset($this->id_sondage)) $this->id_sondage=trim($this->id_sondage);
if (isset($this->commentaires)) $this->commentaires=trim($this->commentaires);
if (isset($this->mail_admin)) $this->mail_admin=trim($this->mail_admin);
if (isset($this->nom_admin)) $this->nom_admin=trim($this->nom_admin);
if (isset($this->titre)) $this->titre=trim($this->titre);
if (isset($this->format)) $this->format=trim($this->format);
if (isset($this->mailsonde)) $this->mailsonde=trim($this->mailsonde);
if (isset($this->canedit)) $this->canedit=trim($this->canedit);
$this->id_sondage = trim($this->id_sondage);
$this->commentaires = trim($this->commentaires);
$this->mail_admin = trim($this->mail_admin);
$this->nom_admin = trim($this->nom_admin);
$this->titre = trim($this->titre);
$this->format = trim($this->format);
$this->mailsonde = ($this->mailsonde ? 1 : 0);
$this->canedit = ($this->canedit ? 1 : 0);
$this->allow_comments = ($this->allow_comments ? 1 : 0);
$this->allow_spy = ($this->allow_spy ? 1 : 0);
$this->origin = trim($this->origin);
$this->sujet = trim($this->sujet);
// Check parameters
// Put here code to add control on parameters values
@ -114,21 +119,29 @@ class Opensurveysondage extends CommonObject
$sql.= "date_fin,";
$sql.= "format,";
$sql.= "mailsonde,";
$sql.= "canedit";
$sql.= "canedit,";
$sql.= "allow_comments,";
$sql.= "allow_spy,";
$sql.= "origin,";
$sql.= "sujet";
$sql.= ") VALUES (";
$sql.= " ".(! isset($this->id_sondage)?'NULL':"'".$this->db->escape($this->id_sondage)."'").",";
$sql.= " ".(! isset($this->commentaires)?'NULL':"'".$this->db->escape($this->commentaires)."'").",";
$sql.= " ".(! isset($this->mail_admin)?'NULL':"'".$this->db->escape($this->mail_admin)."'").",";
$sql.= " ".(! isset($this->nom_admin)?'NULL':"'".$this->db->escape($this->nom_admin)."'").",";
$sql.= " ".(! isset($this->titre)?'NULL':"'".$this->db->escape($this->titre)."'").",";
$sql.= " ".(! isset($this->date_fin) || dol_strlen($this->date_fin)==0?'NULL':$this->db->idate($this->date_fin)).",";
$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->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.= " '".$this->db->escape($this->titre)."',";
$sql.= " '".$this->db->idate($this->date_fin)."',";
$sql.= " '".$this->db->escape($this->format)."',";
$sql.= " ".$this->db->escape($this->mailsonde).",";
$sql.= " ".$this->db->escape($this->canedit).",";
$sql.= " ".$this->db->escape($this->allow_comments).",";
$sql.= " ".$this->db->escape($this->allow_spy).",";
$sql.= " '".$this->db->escape($this->origin)."',";
$sql.= " '".$this->db->escape($this->sujet)."'";
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
@ -137,8 +150,6 @@ class Opensurveysondage extends CommonObject
if (! $error)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."opensurvey_sondage");
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you

View File

@ -230,6 +230,8 @@ function dol_survey_random($car)
function ajouter_sondage($origin)
{
global $db;
require_once DOL_DOCUMENT_ROOT.'/opensurvey/class/opensurveysondage.class.php';
$sondage=dol_survey_random(16);
@ -253,20 +255,27 @@ function ajouter_sondage($origin)
if (is_numeric($date_fin) === false) {
$date_fin = time()+15552000;
}
$canedit=empty($_SESSION['formatcanedit'])?'0':'1';
$canedit=empty($_SESSION['caneditsondage']) ? 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, 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."', '".$allow_spy."', '".$db->escape($origin)."',";
$sql.= " '".$db->escape($_SESSION['toutchoix'])."'";
$sql.= ")";
dol_syslog($sql);
$resql=$db->query($sql);
$opensurveysondage = new Opensurveysondage($db);
$opensurveysondage->id_sondage = $sondage;
$opensurveysondage->commentaires = $_SESSION['commentaires'];
$opensurveysondage->mail_admin = $_SESSION['adresse'];
$opensurveysondage->nom_admin = $_SESSION['nom'];
$opensurveysondage->titre = $_SESSION['titre'];
$opensurveysondage->date_fin = $date_fin;
$opensurveysondage->format = $_SESSION['formatsondage'];
$opensurveysondage->mailsonde = $_SESSION['mailsonde'];
$opensurveysondage->canedit = $canedit;
$opensurveysondage->allow_comments = $allow_comments;
$opensurveysondage->allow_spy = $allow_spy;
$opensurveysondage->origin = $origin;
$opensurveysondage->sujet = $_SESSION['toutchoix'];
$opensurveysondage->create(null);
if ($origin == 'dolibarr') $urlback=dol_buildpath('/opensurvey/adminstuds_preview.php',1).'?id='.$sondage;
else
@ -279,8 +288,6 @@ function ajouter_sondage($origin)
$url=$urlwithouturlroot.dol_buildpath('/opensurvey/public/studs.php',1).'?sondage='.$sondage;
$urlback=$url;
//var_dump($urlback);exit;
}
unset($_SESSION["titre"]);