add_filter('authentication'); $this->add_script('prototype'); $this->add_script('validation'); } function _filter_authentication() { // Always allow login action if ($this->get_action() == 'login' || $this->get_action() == 'reset') return false; // Check if there is someone logged in $this->current_user = Authentication::authenticated(); // Someone validly logged in if ($this->current_user) return false; // Invalid! Show login $this->action_login(); return true; } function init_engine() { $this->engine = QNEngine::initialize($this->current_user, 'include/data.php'); $this->engine->enable_back(true); $this->engine->enable_proceed(true); } function action_reset() { Authentication::reset(); header('Location: index.php?' . SID); exit(); } function view_qnovo() { $this->init_engine(); $this->engine->view($this); $this->add_style('qnovo'); } function process_previous() { $this->init_engine(); $this->engine->process($this); // Process will goto the next, so we need to goto previous 2 if ($this->engine->back()) $this->engine->goto_previous(2); header('Location: index.php?' . SID); exit; } function process_index() { $this->init_engine(); $this->engine->process($this); header('Location: index.php?' . SID); exit; } function action_login() { if (Authentication::authenticated()) { header('Location: index.php?' . SID); exit; } $this->add_style('login'); $this->view('login'); } function process_login() { $form = new Form($this); // Try to authenticate the user Authentication::authenticate($form->passwd); // Reload of the page will find out if the login was actually valid header('Location: index.php?action=login&' . SID); exit; } function calculate_scores() { return Scores::calculate(QNEngine::instance()->person()->id); } function generate_csv() { $batch = new BatchModel(); $model = new ResultModel(QNEngine::instance()->person()->id, $batch->last()->id); $questions = $model->questions(); natsort($questions); $csv = new CSV(); $csv->add(array_merge(array('ID', 'GROUP', 'ORGANISATION', 'DATE'), $questions)); $user = current_user(); $time = new TimeRegistrationModel($user->id, $batch->last()->id); $row = array($user->id, $user->group()->id, $user->organisation, date('d-m-Y', $time->find_start())); foreach ($questions as $q) { $answer = $model->find_answer($q); $row[] = $answer ? $answer->answer : ''; } $csv->add($row); return $csv->to_csv(); } function finalize() { $engine = QNEngine::instance(); $name = $engine->result('_2_2'); $scores = $this->calculate_scores(); $csv = $this->generate_csv(); $hdrs = array( 'From' => '"ICCN ICMS Web Questionnaire" ', 'Subject' => '[ICMS] Questionnaire from ' . $name->answer); $body = 'The following scores result from a questionnaire filled in by ' . $name->answer . '. You will find the scores below. The attached file is a csv formatted file containing the questionnaire results. This file can be imported (into for example Excel) for further processing.' . "\n\n" . 'PFORS: ' . $scores['pfors'] . "\n" . 'PVERS: ' . $scores['pvers'] . "\n" . 'PTOES: ' . $scores['ptoes'] . "\n" . 'POPLS: ' . $scores['popls'] . "\n" . 'CFORS: ' . $scores['cfors'] . "\n" . 'CVERS: ' . $scores['cvers'] . "\n" . 'CTOES: ' . $scores['ctoes'] . "\n" . 'COPLS: ' . $scores['copls'] . "\n" . 'CCOMS: ' . $scores['ccoms'] . "\n\n"; $mime = new Mail_mime("\n"); $mime->setTXTBody($body); $mime->addAttachment($csv, 'text/plain', 'icms.csv', false); $body = $mime->get(); $hdd = $mime->headers($hdrs); $mail =& Mail::factory('mail'); $mail->send('deridder@iccn.nl', $hdd, $body); } } $controller = new Home(); $controller->run(); // ex:ts=4:noet: ?>