$error_messages['dod'] = '<div class="err-msg">Invalid date of death specified.</div>';
        $dod = false;
    } else {
        if ($dob && $dod_submitted && $dod < $dob) {
            // It is okay to submit dod without dob
            $error_messages['dod'] = '<div class="err-msg">Date of death <em>must</em> occur after date of birth</div>';
        } else {
            $default_values['dod'] = array('day' => (int) $form_dod['day'], 'month' => (int) $form_dod['month'], 'year' => (int) $form_dod['year']);
        }
    }
    if (empty($error_messages)) {
        $new_id = save_person_in_db($default_values);
        if (!$new_id) {
            print_error();
        } else {
            redirect_to(url_for_id('person-view.php', $new_id));
        }
    }
}
page_header('Add Person');
?>
		<br>
		<h1>Add New Director</h1>
		<form action="<?php 
echo 'addDirector.php';
?>
" method="POST">
			<?php 
if (isset($error_messages['name'])) {
    echo $error_messages['name'];
}
Example #2
0
        } else {
            $default_values['dod'] = array('day' => (int) $form_dod['day'], 'month' => (int) $form_dod['month'], 'year' => (int) $form_dod['year']);
        }
    }
    // Check for proper type input
    if (!in_array($form['type'], array('actor', 'director'), true)) {
        $error_messages['type'] = '<div class="err-msg">Invalid type specified.</div>';
    } else {
        $default_values['type'] = (string) $form['type'];
    }
    if (empty($error_messages)) {
        $new_id = save_person_in_db($default_values);
        if (!$new_id) {
            error_500();
        } else {
            redirect_to(url_for_id(PERSON_VIEW, $new_id));
        }
    }
}
page_header('Add Person');
?>
		<p><h3>New person information</h3></p>
		<form action="<?php 
echo PERSON_ADD;
?>
" method="POST">
			<?php 
if (isset($error_messages['name'])) {
    echo $error_messages['name'];
}
?>
        for ($i = 0; $i < sizeof($genres); $i++) {
            $key = ":g{$i}";
            $genres_insert_sql .= ",(:mid, {$key})";
            $genre_args[$key] = trim($genres[$i]);
        }
        if (!empty($genre_args)) {
            $count = 1;
            $genres_insert_sql = str_replace('VALUES,', 'VALUES', $genres_insert_sql, $count);
            $genre_args[':mid'] = $saved;
            $stmt = $dbh->prepare($genres_insert_sql);
            $stmt->execute($genre_args);
        }
    }
}
if (false !== $saved) {
    redirect_to(url_for_id('viewMovie.php', $saved));
}
page_header('Add a Movie');
?>
<br>
<h1>Add a Movie</h1>
<?php 
if ($error) {
    echo '<strong><font color="red">' . $error . '</font></strong><br>';
}
?>
<form method="post">
Title: <input type="text" name="title"><br>
Year: <select name="year">
	<?php 
for ($i = date('Y'); $i >= 1800; $i--) {
/**
 * Returns and HTML anchor tag for the given inputs
 * @param $url - url to link to
 * @param $id - parameter to submit as an 'id' GET parameter
 * @param $target
 * @param $text
 */
function hyperlink($url, $id, $text, $target = NULL)
{
    $a = '<a href="' . url_for_id($url, $id) . '"';
    if ($target) {
        $a .= ' target="_blank"';
    }
    $a .= ">{$text}</a>";
    return $a;
}
    $box = '<select name="' . $name . '">';
    foreach ($values as $value) {
        $box .= '<option value="' . $value[$key_col] . '">' . $value[$display_col] . '</option>';
    }
    $box .= '</select>';
    return $box;
}
if (isset($_POST['submit'])) {
    $mode = $_POST['mode'];
    if (!in_array($mode, array('director'))) {
        die('Invalid mode.');
    }
    $sql = 'INSERT INTO MovieDirector (mid, did) VALUES(:mid, :did)';
    $stmt = $dbh->prepare($sql);
    $stmt->execute(array(':mid' => $_POST['movie'], ':did' => $_POST['director']));
    redirect_to(url_for_id('viewMovie.php', $_POST['movie']));
} else {
    $movie_sql = 'SELECT CONCAT(title, " (", year, ")") as title, id FROM Movie ORDER BY title';
    //$actor_sql = 'SELECT Actor.id, CONCAT(Actor.first, " ", Actor.last, " (", dob, ")") as Name FROM Actor ORDER BY Actor.first, Actor.last';
    $director_sql = 'SELECT Director.id, CONCAT(Director.first, " ", Director.last, " (", dob, ")") as Name FROM Director ORDER BY Director.first, Director.last';
    $stmt = $dbh->prepare($movie_sql);
    $stmt->execute();
    $movies = $stmt->fetchAll(PDO::FETCH_ASSOC);
    /*
    	$stmt = $dbh->prepare( $actor_sql );
    	$stmt->execute();
    	$actors = $stmt->fetchAll( PDO::FETCH_ASSOC );
    */
    $stmt = $dbh->prepare($director_sql);
    $stmt->execute();
    $directors = $stmt->fetchAll(PDO::FETCH_ASSOC);
Example #6
0
        for ($i = 0; $i < sizeof($genres); $i++) {
            $key = ":g{$i}";
            $genres_insert_sql .= ",(:mid, {$key})";
            $genre_args[$key] = trim($genres[$i]);
        }
        if (!empty($genre_args)) {
            $count = 1;
            $genres_insert_sql = str_replace('VALUES,', 'VALUES', $genres_insert_sql, $count);
            $genre_args[':mid'] = $saved;
            $stmt = $dbh->prepare($genres_insert_sql);
            $stmt->execute($genre_args);
        }
    }
}
if (false !== $saved) {
    redirect_to(url_for_id(MOVIE_VIEW, $saved));
}
page_header('Add a Movie');
?>
<h3>Add a Movie</h3>
<?php 
if ($error) {
    echo '<strong>' . $error . '</strong>';
}
?>
<form method="post">
Title: <input type="text" name="title"><br>
Year: <select name="year">
	<?php 
for ($i = date('Y'); $i >= 1800; $i--) {
    echo '<option value="' . $i . ' ">' . $i . '</option>';
			<html>
				<head><title>CS143 Project 1C - Movie Database</title></head>
				<body>
					<p>You have already submitted a review!</p>
					<?php 
            echo hyperlink('viewMovie.php', (int) $review['id'], 'Go back');
            ?>
				</body>
			</html>
		<?php 
            die;
        }
        // Otherwise process the data
        $sth = $dbh->prepare('INSERT INTO Review(name, time, mid, rating, comment) VALUES (:name, NOW(), :id, :rating, :comment)');
        $sth->execute(array(':name' => (string) $review['name'], ':id' => (int) $review['id'], ':rating' => min(5, max(0, (int) $review['rating'])), ':comment' => (string) $review['comment']));
        redirect_to(url_for_id('viewMovie.php', (int) $review['id']));
    }
}
page_header('New Review');
?>
		<form action="<?php 
echo 'review.php';
?>
" method="POST">
			<p>You are reviewing <strong><?php 
echo hyperlink('viewMovie.php', $movie['id'], $movie['title'], '_blank');
?>
</strong></p>
			Your name: <input type="text" name="review[name]">
			<br>
			Rating:
Example #8
0
			<html>
				<head><title>CS143 Project 1C - Movie Database</title></head>
				<body>
					<p>You have already submitted a review!</p>
					<?php 
            echo hyperlink(MOVIE_VIEW, (int) $review['id'], 'Go back');
            ?>
				</body>
			</html>
		<?php 
            die;
        }
        // Otherwise process the data
        $sth = $dbh->prepare('INSERT INTO Review(name, time, mid, rating, comment) VALUES (:name, NOW(), :id, :rating, :comment)');
        $sth->execute(array(':name' => (string) $review['name'], ':id' => (int) $review['id'], ':rating' => min(5, max(0, (int) $review['rating'])), ':comment' => (string) $review['comment']));
        redirect_to(url_for_id(MOVIE_VIEW, (int) $review['id']));
    }
}
page_header('New Review');
?>
		<form action="<?php 
echo REVIEW_FORM;
?>
" method="POST">
			<p>You are reviewing <strong><?php 
echo hyperlink(MOVIE_VIEW, $movie['id'], $movie['title'], '_blank');
?>
</strong></p>
			Your name: <input type="text" name="review[name]">
			<br>
			Rating:
Example #9
0
if (isset($_POST['submit'])) {
    $mode = $_POST['mode'];
    if (!in_array($mode, array('director', 'actor'))) {
        die('Invalid mode.');
    }
    if ($mode == 'director') {
        $sql = 'INSERT INTO MovieDirector (mid, did) VALUES(:mid, :did)';
        $stmt = $dbh->prepare($sql);
        $stmt->execute(array(':mid' => $_POST['movie'], ':did' => $_POST['director']));
    } else {
        // Adding an actor, then
        $sql = 'INSERT INTO MovieActor (mid, aid, role) VALUES(:mid, :aid, :role)';
        $stmt = $dbh->prepare($sql);
        $stmt->execute(array(':mid' => $_POST['movie'], ':aid' => $_POST['actor'], ':role' => $_POST['role']));
    }
    redirect_to(url_for_id(MOVIE_VIEW, $_POST['movie']));
} else {
    $movie_sql = 'SELECT CONCAT(title, " (", year, ")") as title, id FROM Movie ORDER BY title';
    $actor_sql = 'SELECT Actor.id, CONCAT(Actor.first, " ", Actor.last, " (", dob, ")") as Name FROM Actor ORDER BY Actor.first, Actor.last';
    $director_sql = 'SELECT Director.id, CONCAT(Director.first, " ", Director.last, " (", dob, ")") as Name FROM Director ORDER BY Director.first, Director.last';
    $stmt = $dbh->prepare($movie_sql);
    $stmt->execute();
    $movies = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $stmt = $dbh->prepare($actor_sql);
    $stmt->execute();
    $actors = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $stmt = $dbh->prepare($director_sql);
    $stmt->execute();
    $directors = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
page_header('Add Relation');