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

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

View File

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