diff options
| author | Zach DeCook <zachdecook@gmail.com> | 2018-11-04 15:13:16 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@gmail.com> | 2018-11-04 15:13:16 -0500 |
| commit | c72140a556834ae9494890f86c42bd967e35cfdd (patch) | |
| tree | b9adbd646d9792bb6c362ef12354c897ae2f81a6 | |
| parent | dc869d779bf211ee5dd167b7fc391879ad400019 (diff) | |
| download | prosongsa-c72140a556834ae9494890f86c42bd967e35cfdd.tar.gz | |
* Favorites: Add ability to "Favorite" a song
| -rw-r--r-- | db/.gitignore | 1 | ||||
| -rwxr-xr-x | index.php | 12 | ||||
| -rw-r--r-- | page.php | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/db/.gitignore b/db/.gitignore new file mode 100644 index 0000000..98e6ef6 --- /dev/null +++ b/db/.gitignore @@ -0,0 +1 @@ +*.db diff --git a/index.php b/index.php index 241cd4a..9664b02 100755 --- a/index.php +++ b/index.php @@ -4,6 +4,18 @@ if ( isset( $_GET['theme'] ) ){ $theme = $_GET['theme']; setcookie( 'theme', $theme, time()+60*60*24*30 ); } +if ($_POST['song'] && $_POST['name']) +{ + $song = str_replace( "'", "", $_POST['song'] ); + $name = str_replace( "'", "", $_POST['name'] ); + $file_db = new SQLite3('db/favs.db'); + $file_db->exec( "CREATE TABLE IF NOT EXISTS favorites ( name TEXT, song TEXT );" ); + $query = "INSERT INTO favorites VALUES( '$name', '$song' );"; + $file_db->exec( $query ); + $file_db = NULL; + setcookie( 'name', $name, time()+60*60*24*356 ); + $_COOKIE['name'] = $name; +} ?> <!-- index.php contains the main html used for creating the page. diff --git a/page.php b/page.php index be629d3..ba30fe1 100644 --- a/page.php +++ b/page.php @@ -180,11 +180,22 @@ function load_song( $number, $transp = 0 ) return renderNavButtons( $number ) . renderEasyTransp( $transp, $number, $songKeys ) + . renderFavorite( $number ) . "<pre>" . $song . "</pre>\n" . renderNavButtons( $number ) . renderSS($suggestedSong, $songKeys, $transp); } +function renderFavorite( $number ) +{ + $number = str_replace( "'", "", $number ); + return "<form method='post'>" + . "<input type='hidden' name='song' value='$number'>" + . "<input name='name' placeholder='your name' value=" . ($_COOKIE['name'] ?? '') . ">" + . "<input type='submit' value='Add to Favorites' class='btn btn-F'>" + . "</form>"; +} + function renderEasyTransp( $transp, $num, $songKeys = array() ) { $s = ''; |
