ציטוט:
נכתב במקור על ידי meshuga
איזה קוד שמת?....
בטוח לא את שלי כי שלי היה עובד לך.....או שלא הבנת נכון איך להשתמש שם בIDים
ד"א
תאריכים תמיד הכי טוב לשמור בתור linuxtime (השניות) כי אז אתה יכול לקחת מה שאתה רוצה כמה שאתה רוצה (אם בא לך שעה יש שעה אם שניה וכו' וכו').....
|
זה הקוד:
PHP קוד:
<?php
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "tbftbf") {
//First let's recompile that line with the pipe symbols so we can reinsert it
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['articles'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
$data = file('articles.txt');
$data[$id] = $line;
//the next line makes sure the $data array starts at the beginning
reset($data);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('articles.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "<div class=\"content\"><b>הכתבה נערכה</b>\n";
echo " | <a href=\"$PHP_SELF\">חזור לעמוד הראשי</a></div><BR><BR>\n";
exit;
} else {
$data = file('articles.txt');
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "<div class=\"content\"><b>סיסמה שגויה</b>\n";
echo " | <a href=\"$PHP_SELF?action=edit&id=$key\">חזור</a></div><BR><BR>\n";
exit;
}
}
}
if($action == "edit") {
$data = file('articles.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
//the next line is to reverse the process of turning the end of lines into breaking returns
$articles = str_replace("<BR>","\r\n",$pieces[2]);
echo "<div id=\"content\"><h2><u>ערוך כתבה</u></h2></div><BR>\n";
echo "<div class=\"content\"><FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
echo "שם:<BR>\n";
echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
echo "תוכן הכתבה:<BR>\n";
echo "<TEXTAREA NAME=\"articles\" COLS=\"40\" ROWS=\"5\">".$articles."</TEXTAREA><BR><BR>\n";
echo "סיסמה:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\" שמור \"><BR>\n";
echo "</FORM></div>\n";
exit;
}
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "tbftbf") {
$data = file('articles.txt');
//this next line will remove the single articles item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('articles.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "<div class=\"content\"><b>הכתבה נמחקה</b>\n";
echo " | <a href=\"$PHP_SELF\">חזור לעמוד הראשי</a></div><BR><BR>\n";
exit;
} else {
$data = file('articles.txt');
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "<div class=\"content\"><b>סיסמה שגויה</b>\n";
echo " | <a href=\"$PHP_SELF?action=edit&id=$key\">חזור</a></div><BR><BR>\n";
exit;
}
}
}
if($action == "delete") {
echo "<div id=\"content\"><h2><u>מחיקת כתבה</u></h2></div>\n";
$data = file('articles.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
echo "<div class=\"content\">" . $pieces[2] . "<BR>" . "<b>נשלח על ידי " . $pieces[1] . " ב " . $pieces[0] . "</b>\n";
echo "<BR><BR>\n";
echo "אם אתה בטוח שברצונך למחוק את הכתבה, הקלד את הסיסמה ומחק:<BR><BR>\n";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
echo "סיסמה:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\" מחק \"><BR>\n";
echo "</FORM></div>\n";
exit;
}
echo "<div id=\"content\"><h2><u>כתבות נוכחיות</u></h2></div>\n";
$data = file('articles.txt');
$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "<BR><div class=\"content\">" . $pieces[2] . "<BR>" . "<b>נשלח על ידי " . $pieces[1] . " ב " . $pieces[0] . "</b>\n";
echo " (<a href=\"$PHP_SELF?action=delete&id=$key\">מחק</a>\n";
echo " | <a href=\"$PHP_SELF?action=edit&id=$key\">ערוך</a>)\n";
echo "<BR><HR><BR><BR></div>\n";
}
?>
ובקשר לזמן, שמרתי (בהוספת כתבה) ככה:
PHP קוד:
$line = date("d.m.y")