.
*/
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 CandidatesForm extends AbstractForm {
private $elections_id;
public function __construct(Layout $layout, IModel $model, $elections_id) {
parent::__construct($layout, $model);
$this->elections_id = $elections_id;
}
public function save(IModel $model) {
$cService = $GLOBALS['ClassFactory']->getCandidatesService();
if( $cService->saveOrUpdate($model) ) {
$this->layout->redirect('candidates1.php?eid='.$this->elections_id);
}else {
$this->layout->echoln("Failed saving");
}
}
}
/**
* End of helper classes
*/
$layout = new DefaultLayout("JC_MANAGE", "./jc/");
$layout->init();
$layout->echoln('
Back
');
$cService = $GLOBALS['ClassFactory']->getCandidatesService();
//get elections_id if set
if (isset($_GET['eid'])){
$election_id = $_GET['eid'];
$elections = $GLOBALS['ClassFactory']->getElectionsService()->load($election_id);
}
else{
$layout->redirect('elections1.php');
}
//get id if set
if (isset($_GET['id'])){
$id = $_GET['id'];
$candidate = $cService->load($id);
}
else{
$candidate = new Candidates('');
$candidate->setElection_id($election_id);
}
if (date("Y-m-d H:i:s") > $elections->getOpen()){
$layout->echoln('Elections have opened!');
$layout->echoln('
Back');
}
else
{
$layout->echoln('Candidate for '.$elections->getPosition().'
');
$form = new CandidatesForm($layout, $candidate, $election_id);
$tf1 = new TextField('name', 'Name');
$tf2 = new TextField('surname', 'Surname');
$tf3 = new TextField('link','Link');
$tf3->setExplanation('candidature descrition in zeus');
$form->addField($tf1->setCompulsory(true));
$form->addField($tf2->setCompulsory(true));
$form->addField($tf3);
$form->display();
}
$layout->page_footer();
?>