Boa noite, estou com problemas no código da página 109 (php/mysql).
a função só funciona se eu colocar um include do ajudantes.php no início do html, funciona mas no final retorna erro de Fatal error: Cannot redeclare traduz_prioridade() (previously declared in C:\xampp\htdocs\Tarefas\ajudantes.php:4) in C:\xampp\htdocs\Tarefas\ajudantes.php on line 14.
segue partes do código
ajudantes.php
<?php
function traduz_prioridade($codigo) {
$prioridade = '';
switch ($codigo) {
case 1: $prioridade = 'Baixa'; break;
case 2: $prioridade = 'Média'; break;
case 3: $prioridade = 'Alta'; break;
}
return $prioridade;
}
function traduz_data_para_exibir($data) {
if ($data == "" OR $data == "0000-00-00") {
return "";
}
$objeto_data = DateTime::createFromFormat('Y-m-d', $data);
return $objeto_data->format('d/m/Y');
}
function traduz_data_para_banco($data) {
if ($data == "") {
return "";
}
$dados = explode("/", $data);
$data_banco = "{$dados[2]}-{$dados[1]}-{$dados[0]}";
return $data_banco;
}
?>
e no template.php
<?php include 'ajudantes.php'; ?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gerenciador de tarefas</title>
<form>
<fieldset>
<legend>Nova Tarefa</legend>
<label>
Tarefa:
<input type="text" name="nome"><br><br>
</label>
<label>
Descrição (Opcional):
<textarea name="descricao"></textarea>
</label>
<label>
Prazo (Opcional):
<input type="text" name="prazo" />
</label>
<fieldset>
<legend>Prioridade:</legend>
<label>
<input type="radio" name="prioridade" value="1"checked />Baixa
<input type="radio" name="prioridade" value="2" />Média
<input type="radio" name="prioridade" value="3"/>Alta
</label>
</fieldset>
<label>
Tarefa concluída:
<input type="checkbox" name="concluidda" value="sim" />
</label>
<input type="submit" value="Cadastrar" />
</fieldset>
</form>
<table>
<tr>
<th>Tarefa</th>
<th>Descricao</th>
<th>Prazo</th>
<th>Prioridade</th>
<th>Concluída</th>
</tr>
<?php foreach( $_SESSION['lista_tarefas'] as $tarefa) : ?>
<tr>
<td><?php print $tarefa['nome']; ?></td>
<td><?php print $tarefa['descricao']; ?></td>
<td><?php print $tarefa['prazo']; ?></td>
<td><?php print traduz_prioridade($tarefa['prioridade']); ?></td>
<td><?php print $tarefa['concluidda']; ?></td>
</tr>
<?php endforeach; ?>
</table>