} // connect to the database include 'db_conn.php'; // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) { // query db $id = $_GET['id']; $result = mysql_query("SELECT * FROM blog_post WHERE id={$id}") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if ($row) { // get data from db $title = $row['title']; $content = $row['content']; // show form renderPost($id, $title, $content, ''); } else { echo "No results!"; } } else { echo 'Error!'; } ?> <?php // connect to the database include 'db_conn.php'; // check if the form has been submitted. If it has, start to process the form and save it to the database if (isset($_POST['submit'])) { if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id'];
"></textarea> <p>* required</p> <input type="submit" name="submit" value="送出"/> </form> </div> </body> </html> <?php } // connect to the database include 'db_conn.php'; // check if the form has been submitted. If it has, start to process the form and save it to the database if (isset($_POST['submit'])) { // get form data, making sure it is valid $title = $_POST["title"]; $content = $_POST["content"]; // check to make sure both fields are entered if ($title == '' || $content == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; // if either field is blank, display the form again renderPost($title, $content, $error); } else { // save the data to the database mysql_query("INSERT blog_post SET title='{$title}', content='{$content}'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: postlist.php"); } } else { renderPost('', '', ''); }
$out[$c]['html'] = renderItemFilesForm($waka['drafts'][$_REQUEST['u']], 'draft'); $out[$c]['location'] = 'draft_files_form'; $out[$c]['type'] = 'changed'; } } $oldplist = listToArray($_REQUEST['p']); $postcount = count($waka['posts']); for ($p = 0; $p < $postcount; $p++) { for ($p2 = 0; $p2 < count($oldplist); $p2++) { if ($oldplist[$p2] == $waka['posts'][$p]['id']) { array_splice($oldplist, $p2, 1); } } if (strnatcmp($waka['posts'][$p]['dateCreated'], $_REQUEST['d']) > 0) { $c = count($out); $out[$c]['html'] = renderPost($waka['posts'][$p], $waka['users'], $user); $out[$c]['location'] = 'post_' . $waka['posts'][$p]['id']; $out[$c]['type'] = 'new'; } else { if (strnatcmp($waka['posts'][$p]['dateContentTouched'], $_REQUEST['d']) > 0) { $c = count($out); $out[$c]['html'] = renderItemContent($waka['posts'][$p], 'post_' . $waka['posts'][$p]['id']); $out[$c]['location'] = 'post_' . $waka['posts'][$p]['id'] . '_content'; $out[$c]['type'] = 'changed'; if ($user['type'] == 'editor' && userMayEdit($user['email'], $waka['posts'][$p]['users'])) { $c = count($out); $out[$c]['html'] = renderItemContentForm($waka['posts'][$p], 'post_' . $waka['posts'][$p]['id']); $out[$c]['location'] = 'post_' . $waka['posts'][$p]['id'] . '_content_form'; $out[$c]['type'] = 'changed'; } }
function renderWaka($waka) { //print_r($waka['users'][$_REQUEST['u']]['notificationCooldown']); if (isset($waka['users'][$_REQUEST['u']]['type'])) { $user['type'] = $waka['users'][$_REQUEST['u']]['type']; $user['email'] = $waka['users'][$_REQUEST['u']]['email']; } else { $user['type'] = 'public'; $user['email'] = 'public'; } echo '<div class="waka">'; echo '<a href="javascript:switchHead()" style="text-decoration: none;"><span style="float:right; padding-bottom: 7px;">'; if ($user['type'] != 'public') { echo '<small style="margin-bottom: 10px; padding-right: 8px;"><small style="color: #555;"">' . $user['email'] . '</small></small>'; } echo '<img src="img/Apps-system-users-icon.png" style="vertical-align: bottom;"></span></a>'; echo '<div style="clear:both"></div>'; echo '<div class="headwrapper"><div class="head" id="head" style="display:none;">'; echo renderHead($waka, $user); echo '</div></div>'; //starter echo '<div class="starter" id="starter">'; echo renderStarter($waka['starter'], $user); echo '</div>'; //draft form echo '<div class="draft" id="draft"'; if ($user['type'] != 'editor') { echo ' style="display:none"'; } echo '>'; if ($user['type'] == 'editor') { echo renderDraft($waka['drafts'][$_REQUEST['u']], $user); } echo '</div>'; //echo '<hr>'; //posts $waka['posts'] = sortItemsDesc($waka['posts'], 'dateCreated'); $postcount = count($waka['posts']); //$dateread=date("Y-m-d H:i:s"); for ($p = 0; $p < $postcount; $p++) { if (isset($waka['posts'][$p]['users'][$user['email']]) && isset($waka['posts'][$p]['users'][$user['email']]['dateRead'])) { $dateread = $waka['posts'][$p]['users'][$user['email']]['dateRead']; } else { $dateread = "1985-09-02 14:00:01"; } //echo $waka['posts'][$p]['users'][$user['email']]['dateRead'].'<br>'; //echo $waka['posts'][$p]['dateContentTouched'].' : '.$dateread.' -> '.strnatcmp($waka['posts'][$p]['dateContentTouched'],$dateread).'<br>'; //echo $waka['posts'][$p]['dateFilesTouched'].' : '.$dateread.'<br>'; //echo $waka['posts'][$p]['dateImagesTouched'].' : '.$dateread.'<br>'; //echo $waka['posts'][$p]['dateUsersTouched'].' : '.$dateread.'<br>'; echo '<div class="post" id="post_' . $waka['posts'][$p]['id'] . '"'; if (!(strnatcmp($waka['posts'][$p]['dateContentTouched'], $dateread) == -1 && strnatcmp($waka['posts'][$p]['dateFilesTouched'], $dateread) == -1 && strnatcmp($waka['posts'][$p]['dateImagesTouched'], $dateread) == -1)) { echo ' unread="yes"'; } else { echo ' unread="no"'; } echo '>'; echo renderPost($waka['posts'][$p], $waka['users'], $user); echo '</div>'; } echo '</div>'; }