*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file htdocs/opensurvey/adminstuds.php
* \ingroup opensurvey
* \brief Page to edit survey
*/
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");
require_once(DOL_DOCUMENT_ROOT."/opensurvey/fonctions.php");
// Security check
if (!$user->admin) accessforbidden();
// Initialisation des variables
$action=GETPOST('action');
$numsondage = $numsondageadmin = '';
if (GETPOST('sondage'))
{
if (strlen(GETPOST('sondage')) == 24) // recuperation du numero de sondage admin (24 car.) dans l'URL
{
$numsondageadmin=GETPOST("sondage",'alpha');
$numsondage=substr($numsondageadmin, 0, 16);
}
else
{
$numsondageadmin='';
$numsondage=GETPOST("sondage",'alpha');
}
}
$object=new Opensurveysondage($db);
$expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
/*
* Actions
*/
// Delete
if ($action == 'delete_confirm')
{
$result=$object->delete($user,'',$numsondageadmin);
header('Location: '.dol_buildpath('/opensurvey/list.php',1));
exit();
}
// Update
if ($action == 'update')
{
$error=0;
if (! GETPOST('nouveautitre'))
{
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Title")),'errors');
$error++;
$action = 'edit';
}
if (! $error)
{
$res=$object->fetch(0,$numsondageadmin);
if ($res < 0) dol_print_error($db,$object->error);
}
if (! $error)
{
$object->titre = GETPOST('nouveautitre');
$object->commentaires = GETPOST('nouveauxcommentaires');
$object->mail_admin = GETPOST('nouvelleadresse');
$object->date_fin = $expiredate;
$object->survey_link_visible = GETPOST('survey_link_visible')=='on'?1:0;
$object->canedit = GETPOST('canedit')=='on'?1:0;
$res=$object->update($user);
if ($res < 0)
{
setEventMessage($object->error,'errors');
$action='edit';
}
}
}
// Add comment
if (GETPOST('ajoutcomment'))
{
$error=0;
if (! GETPOST('comment'))
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Comment")),'errors');
}
if (! GETPOST('commentuser'))
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("User")),'errors');
}
if (! $error)
{
$comment = GETPOST("comment");
$comment_user = GETPOST('commentuser');
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
$sql.= " VALUES ('".$db->escape($numsondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
$resql = $db->query($sql);
dol_syslog("sql=".$sql);
if (! $resql)
{
$err |= COMMENT_INSERT_FAILED;
}
}
}
// Delete comment
$idcomment=GETPOST('deletecomment','int');
if ($idcomment)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.$idcomment;
$resql = $db->query($sql);
}
/*
* View
*/
$form=new Form($db);
$result=$object->fetch(0,$numsondage);
if ($result <= 0)
{
print $langs->trans("ErrorRecordNotFound");
llxFooter();
exit;
}
$arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css');
llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);
// Define format of choices
$toutsujet=explode(",",$object->sujet);
$listofanswers=array();
foreach ($toutsujet as $value)
{
$tmp=explode('@',$value);
$listofanswers[]=array('label'=>$tmp[0],'format'=>($tmp[1]?$tmp[1]:'checkbox'));
}
$toutsujet=str_replace("@"," ",$toutsujet);
$toutsujet=str_replace("°","'",$toutsujet);
print '