Branch
Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
import from branch patchwork13-0.1 on SourceForge.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?PHP
if (isset ($_POST['a'])) {
$id = $_POST['id'];
$author = $_POST['author'];
$title = $_POST['title'];
$text = $_POST['text'];
mysql_connect ('mysql4-p', 'p133991rw', '$*3_Ah7') ||
die ('Could not connect: ' . mysql_error ());
mysql_select_db ('p133991_pw13') ||
die ('Could not select database');
if ($_POST['a'] === 'Ajouter') {
$query = ("INSERT INTO `news` ( `id` , `author` , `title` , `text` ) ".
"VALUES ( $id, '$author', '$title', '$text' )");
($result = mysql_query($query)) ||
die ('Query failed: ' . mysql_error ());
}
else if ($_POST['a'] === 'Modifier') {
$query = ("UPDATE `news` SET `author`='$author' , `title`='$title'".
" , `text`='$text' WHERE `id`=$id");
($result = mysql_query($query)) ||
die ('Query failed: ' . mysql_error ());
}
else if ($_POST['a'] === 'Supprimer') {
}
else
die ("Unknown action");
echo `./generate-news`;
echo '<hr>'."\n";
}
function print_news_form ($row)
{
echo '<table width="100%"><tr>'."\n";
echo '<td style="newsdate" align="left">'.$row['date'].'</td>'."\n";
echo '<td align="right">'."\n";
echo '<span class="prop">author</span> ';
echo $row['author'].'<br>'."\n";
echo '<span class="prop">id</span> ';
echo $row['id']."\n";
echo '</td>'."\n";
echo '</tr></table>'."\n";
echo '<FORM action="'.$PHP_SELF.'" method="POST">'."\n";
echo '<input name="id" type="hidden" value="'.$row['id'].'">'."\n";
echo '<input name="author" type="hidden" value="'.$row['author'].'">'."\n";
echo '<input name="title" type="text" value="'.$row['title'].'"'."\n";
echo ' style="width:100%"><br>'."\n";
echo '<textarea name="text" rows=10 cols=60'."\n";
echo ' style="width:100%;">'.$row['text'].'</textarea><br>'."\n";
echo '<table width="100%"><tr>'."\n";
if ($row['new']) {
echo '<td align="right" width="100%">'."\n";
echo '<input name="a" type="submit" value="Ajouter">'."\n";
echo '</td>'."\n";
}
else {
echo '<td align="left" width="50%">'."\n";
echo '<input name="a" type="submit" value="Supprimer">'."\n";
echo '</td>'."\n";
echo '<td align="right" width="50%">'."\n";
echo '<input name="a" type="submit" value="Modifier">'."\n";
echo '</td>'."\n";
}
echo '</table>'."\n";
echo '</FORM>'."\n";
echo '<br><br><br><br><br><br><br>'."\n";
echo ''."\n";
}
mysql_connect ('mysql4-p', 'p133991ro', '99#o)u[') ||
die ('Could not connect: ' . mysql_error ());
mysql_select_db ('p133991_pw13') ||
die ('Could not select database');
/* get max id */
($result = mysql_query ("SELECT id FROM news ORDER BY id DESC LIMIT 1")) ||
die ('Query failed: ' . mysql_error ());
if ($line = mysql_fetch_array ($result))
$new_id = $line[0] + 1;
else
$new_id = 1;
echo '<center style="width:100%">'."\n";
echo '<div style="width:100%">'."\n";
echo "\n";
/* add news */
$new_news = array ('new' => true,
'id' => $new_id,
'author' => $_SERVER["PHP_AUTH_USER"],
'title' => '',
'text' => '',
'date' => '');
print_news_form ($new_news);
echo "<br> <hr> <br><br><br><br><br><br>\n";
/* read news */
($result = mysql_query("SELECT id, date, modified, author, title, text".
" FROM news ORDER BY id DESC LIMIT 10")) ||
die ('Query failed: ' . mysql_error ());
while ($line = mysql_fetch_array ($result, MYSQL_ASSOC))
print_news_form ($line);
echo '</div>';
echo '</center>';
?>