template_dir = $SMARTY['orig']; $tpl->compile_dir = $SMARTY['comp']; // Connect to the database @mysql_connect($db_host, $db_user, $db_password) or die('not connected'); // Select the database $dbc = @mysql_select_db($db_name) or die ('no database selected'); // Continue session session_start(); // Check session if(!$_SESSION['user_id']) { header("Location: index.php"); } // Switch state switch($_GET['state']) { // Friends case "friends": // Hey, can you figure this part out? Hint: create a friends table break; // Display posts default: // Check if user is signed in if($_SESSION['user_id']) { $tpl->assign('signedin', true); } // If the submit button has been pressed if(isset($_POST['submit'])) { // Check for a status if(empty($_POST['status'])) { $error['status'] = 'Required field'; } // If there are no errors, insert the user into the database if(sizeof($error) == 0) { // Insert user into the database $sql = "INSERT INTO status ( status_id, user_id, status, statusdate ) VALUES ( null, '{$_SESSION['user_id']}', '{$_POST['status']}', NOW() )"; $result = mysql_query($sql); } else { // Assign errors $tpl->assign('error', $error); } } // Assign first and last name $tpl->assign('firstname', $_SESSION['firstname']); $tpl->assign('lastname', $_SESSION['lastname']); // Get all posts for this user $sql = "SELECT status_id, status, DATE_FORMAT(statusdate, '%M %d, %Y') AS formatteddate FROM status WHERE user_id = '{$_SESSION['user_id']}' ORDER BY statusdate DESC"; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $posts[] = array( 'status_id' => $row['status_id'], 'status' => $row['status'], 'statusdate' => $row['formatteddate'] ); } $tpl->assign('posts', $posts); // Display template $tpl->display('admin.tpl'); break; } ?>