123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- require_once('../controller/validator.php');
- require_once('../controller/formparser.php');
- require_once('../controller/forms.php');
- require_once('../controller/util.php');
- require_once('../templates/templates.php');
- require_once('../controller/generateform.php');
- $KEY_SIZE = 15; // max. 32
- $FOLDER_SIZE = 10; // max. 32
- function generateKeys ($email, $title) {
- global $KEY_SIZE;
- global $FOLDER_SIZE;
- $date = new DateTime();
- $input = $date->format("c").$email.$title;
- $sha = hash("sha256", $input);
- $key = array();
- $folder = array();
- $i = 0;
- for (; $i < $KEY_SIZE; $i++) {
- $key[] = $sha[$i];
- }
- for ($j = 0;$j < $FOLDER_SIZE; $j++ ) {
- $folder[] = $sha[$i+$j];
- }
- return [implode("", $key), implode("", $folder)];
- }
- if (empty($_POST)) {
- generateCreateForm();
- } else {
- proccessRequest($_POST);
- }
- function generateCreateForm () {
- $template = getTemplate('create_form.html');
- $context = array('post_url' => '../app/create_form.php');
- $template = parseTemplate($template, $context);
- echo $template;
- }
- function proccessRequest ($data) {
- try {
- Validator::check(['email', 'title', 'description','thanks'], $data);
- Validator::check(['formSource'], $_FILES);
- $from = array();
- $form['email'] = Validator::email($data['email']);
- $form['title'] = Validator::str($data['title']);
- $form['description'] = Validator::str($data['description']);
- $form['thanks'] = Validator::str($data['thanks']);
- $upload = Validator::file($_FILES['formSource'], 'txt');
- $formSource = file_get_contents($upload['tmp_name']);
- $reader = new SourceReader($formSource);
- $parser = new Parser($reader);
- $form['questions'] = $parser->parse();
- $keys = generateKeys($form['email'], $form['title']);
- $form['id'] = $keys[1];
- $html = generateFormHTML($form);
- storeNewForm($form, $keys, $formSource);
- $id = $keys[1];
- $link = generateURI("/forms/viewer.php?id=$id");
- $context = ['link'=> htmlspecialchars($link), 'secret'=>$keys[0], 'title'=>$form['title']];
- $success = getTemplate('created_successful.html');
- echo parseTemplate($success, $context);
- } catch (Exception $e) {
- echo 'Os dados do formulários são inválidos! Certifique-se que todos os dados foram enviados e estão no formato correto: '.$e->getMessage().'<br/>';
- return;
- }
- }
- /*function saveHTML ($title, $folder,$html) {
- $date = new DateTime();
- $cleanTitle = cleanTitle($title);
- $datePart = $date->format("Y-m-j");
- $filePath = "$dateart-$cleanTitle-$folder.html";
- file_put_contents('../forms/'.$filePath, $html);
- return $filePath;
- }*/
|