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().'
'; 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; }*/