.
*/
include("./include/include.php");
require_once(FILESYSTEMROOTPATH."jc/include/classes/DefaultLayout.php");
require_once(FILESYSTEMROOTPATH."include/form/AbstractForm.php");
require_once(FILESYSTEMROOTPATH."jc/include/classes/DateTimeSelectField.php");
/**
* Helper classes
*/
class ElectionForm extends AbstractForm {
private $eService;
public function __construct(Layout $layout, IModel $model) {
parent::__construct($layout, $model);
}
public function save(IModel $model) {
$eService = $GLOBALS['ClassFactory']->getElectionsService();
$open = date('Y-m-d H:i:s', strtotime($_POST['open']['year'].'-'.$_POST['open']['month'].'-'.$_POST['open']['day'].' '.$_POST['open']['hours'].':'.$_POST['open']['minutes']));
$close = date('Y-m-d H:i:s',strtotime($_POST['close']['year'].'-'.$_POST['close']['month'].'-'.$_POST['close']['day'].' '.$_POST['close']['hours'].':'.$_POST['close']['minutes']));
$model->setOpen($open);
$model->setClose($close);
if (isset($_POST['published'])){
$model->setPublished('1');
}else{
$model->setPublished('0');
}
$ns = $GLOBALS['ClassFactory']->getNotificationsService();
if( $eService->saveOrUpdate($model) ) {
if($model->getId()==''){
$id = $eService->get_last_id(); //no queries between save!
$ns->create($id, 'Election', $model->getOpen(), $model->getClose());
}else{
$ns->update($model->getId(), 'Election', $model->getOpen(), $model->getClose());
}
$this->layout->redirect('elections1.php');
}else {
$this->layout->echoln("Failed saving");
}
}
}
/**
* End of helper classes
*/
$layout = new DefaultLayout("JC_MANAGE", "./jc/");
$layout->init();
$layout->echoln('Back
');
$eService = $GLOBALS['ClassFactory']->getElectionsService();
$agora_id = $_SESSION['JC_MODULE']['AgoraId'];
//get id if set
if (isset($_GET['id'])){
$id = $_GET['id'];
$election = $eService->load($id);
}
else{
$election = new Elections('');
$election->setAgora_id($agora_id);
}
/*
$postitions = array(
'Chairperson/ Vice-Chairperson of the Agora/EBM',
'Financial Director of AEGEE-Europe',
'Member of Summer University Coordination Team',
'Member of the Audit Commission',
'Member of the Comite Directeur',
'Member of the Juridical Commission',
'Member of the Mediation Commission',
'Member of the Network Commission'
'President of AEGEE-Europe',
'Secretary General of AEGEE-Europe',
'Secretary of the Agora',
'Secretary of the Agora/EBM'
);
*/
$layout->echoln('Current system time (CET): '.date("d-m-Y H:i:s"));
$form = new ElectionForm($layout, $election);
//$tf1 = new SelectField('position', 'Position', $positions);
$tf1 = new TextField('position', 'Position');
$tf1->setExplanation('eg: President of AEGEE-Europe');
$selection = array_combine(range(1,11), range(1,11));
$tf2 = new SelectField('maxVotes', 'Maximum votes', $selection);
$tf2->setExplanation('Number of persons to be elected');
$openfield = new DateTimeSelectField('open','Election Start');
$closefield = new DateTimeSelectField('close','Election End');
$published = new CheckBoxField('published','Published');
$form->addField($tf1->setCompulsory(true));
$form->addField($tf2->setCompulsory(true));
$form->addField($openfield->setCompulsory(true));
$form->addField($closefield->setCompulsory(true));
$form->addField($published);
$form->display();
$layout->page_footer();
?>