* Copyright (C) 2014 Marcos García * * 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 = ''; if (GETPOST('id')) { $numsondage = GETPOST('id', 'alpha'); } $object=new Opensurveysondage($db); $result=$object->fetch(0, $numsondage); if ($result <= 0) { dol_print_error($db,$object->error); exit; } $expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear')); /* * Actions */ // Delete if ($action == 'delete_confirm') { $result=$object->delete($user,'',$numsondage); 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) { $object->titre = GETPOST('nouveautitre'); $object->commentaires = GETPOST('nouveauxcommentaires'); $object->mail_admin = GETPOST('nouvelleadresse'); $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) { 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'); $resql = $object->addComment($comment, $comment_user); 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); $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 '
'."\n"; print ''; $head = opensurvey_prepare_head($object); print dol_get_fiche_head($head,'general',$langs->trans("Survey"),0,dol_buildpath('/opensurvey/img/object_opensurvey.png',1),1); print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; print ''; print ''; // Type $type=($object->format=="A"||$object->format=="A+")?'classic':'date'; print ''; // Title print ''; // Auteur print ''; // Description print ''; // EMail print ''; // Can edit other votes print ''; // Users can comment print ''; // Users can see others vote print ''; // Expire date print ''; // Link print '
'.$langs->trans('Ref').''; print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage'); print '
'.$langs->trans("Type").''; print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1); print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate").'
'; $adresseadmin=$object->mail_admin; print $langs->trans("Title") .''; if ($action == 'edit') { print ''; } else print $object->titre; print '
'; print $langs->trans("Author") .''; print $object->nom_admin; print '
'.$langs->trans("Description") .''; if ($action == 'edit') { print ''."\n"; } else print dol_nl2br($object->commentaires); print '
'.$langs->trans("EMail") .''; if ($action == 'edit') { print ''; } else print dol_print_email($object->mail_admin); print '
'.$langs->trans('CanEditVotes').''; if ($action == 'edit') { print 'canedit?' checked="true"':'').'">'; } else print yn($object->canedit); print '
'.$langs->trans('CanComment').''; if ($action == 'edit') { print 'allow_comments?' checked="true"':'').'">'; } else print yn($object->allow_comments); print '
'.$langs->trans('CanSeeOthersVote').''; if ($action == 'edit') { print 'allow_spy?' checked="true"':'').'">'; } else print yn($object->allow_spy); print '
'.$langs->trans('ExpireDate').''; if ($action == 'edit') print $form->select_date($expiredate?$expiredate:$object->date_fin,'expire'); else print dol_print_date($object->date_fin,'day'); print '
'.img_picto('','object_globe.png').' '.$langs->trans("UrlForSurvey",'').''; // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current $url=$urlwithouturlroot.dol_buildpath('/opensurvey/public/studs.php',1).'?sondage='.$object->id_sondage; $urllink=''.$url.''; print $urllink; print '
'; if ($action == 'edit') print '

'; print '
'."\n"; dol_fiche_end(); /* * Barre d'actions */ print '
'; if ($action != 'edit') print ''.$langs->trans("Modify") . ''; if ($action != 'edit') print ''.$langs->trans('Delete').''; print '
'; if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"].'?&id='.$numsondage, $langs->trans("RemovePoll"), $langs->trans("ConfirmRemovalOfPoll",$id), 'delete_confirm', '', '', 1); } print '
'; print '
'."\n"; print_fiche_titre($langs->trans("CommentsOfVoters"),'',''); // Comment list $comments = $object->getComments(); if ($comments) { foreach ($comments as $comment) { print ' '.img_picto('', 'delete.png').' '; print $comment->usercomment.': '.dol_nl2br($comment->comment)."
"; } } else { print $langs->trans("NoCommentYet").'
';; } print '
'; // Add comment if ($object->allow_comments) { print $langs->trans("AddACommentForPoll") . '
'; print '
'."\n"; print $langs->trans("Name") .':
'."\n"; print '
'."\n"; if (isset($erreur_commentaire_vide) && $erreur_commentaire_vide=="yes") { print "" . $langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")) . ""; } } print '
'; llxFooterSurvey(); $db->close(); ?>