From ea4e7857f2ca2da79cbfb8778c801e8a241e984b Mon Sep 17 00:00:00 2001 From: ommaniya70 Date: Tue, 24 Oct 2023 17:41:04 +0530 Subject: [PATCH] New Files added --- .gitignore | 1 + OtherPages/contactus.php | 95 +++++++++++++++++++++++ OtherPages/login.php | 157 +++++++++++++++++++++++++++++++++++++++ OtherPages/review.php | 109 +++++++++++++++++++++++++++ OtherPages/signup.php | 143 +++++++++++++++++++++++++++++++++++ OtherPages/welcome.php | 39 ++++++++++ Toggle.html | 118 +++++++++++++++++++++++++++++ config.js | 42 +++++++++++ dbconnection.php | 32 ++++++++ index.php | 68 +++++++++++++++++ script.js | 156 ++++++++++++++++++++++++++++++++++++++ selection.css | 90 ++++++++++++++++++++++ selection.js | 102 +++++++++++++++++++++++++ style.css | 148 ++++++++++++++++++++++++++++++++++++ utils.css | 61 +++++++++++++++ 15 files changed, 1361 insertions(+) create mode 100644 .gitignore create mode 100644 OtherPages/contactus.php create mode 100644 OtherPages/login.php create mode 100644 OtherPages/review.php create mode 100644 OtherPages/signup.php create mode 100644 OtherPages/welcome.php create mode 100644 Toggle.html create mode 100644 config.js create mode 100644 dbconnection.php create mode 100644 index.php create mode 100644 script.js create mode 100644 selection.css create mode 100644 selection.js create mode 100644 style.css create mode 100644 utils.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/OtherPages/contactus.php b/OtherPages/contactus.php new file mode 100644 index 0000000..756789b --- /dev/null +++ b/OtherPages/contactus.php @@ -0,0 +1,95 @@ + + + + + + + + + Contact Us + + + + + + + + +
+
+ Contact Us + + + + + + + +
+
+ + + + + + + \ No newline at end of file diff --git a/OtherPages/login.php b/OtherPages/login.php new file mode 100644 index 0000000..da838af --- /dev/null +++ b/OtherPages/login.php @@ -0,0 +1,157 @@ + + + + + + Login + + + + + + + + + + +
+
+ Login +
+ + +
+
+ + +
+
+ + Show Password +
+ + +
+
+ + fetch_assoc(); + + if (password_verify($user_password, $row['PASSWORD'])) { + // Redirect to the welcome page if a matching user is found + + $_SESSION['email_id'] = $email_id; + $_SESSION['loggedin'] = true; + + setcookie("First_Name", $row['FIRST_NAME'], time() + 60 * 60 * 24 * 365, '/'); + setcookie("Last_Name", $row['LAST_NAME'], time() + 60 * 60 * 24 * 365, '/'); + + closeConnection($conn); + header("Location: ../index.php"); + exit(); + } else { + // Invalid email or password + $usr_err_msg = "Invalid Email or Password !!"; + } + } + ?> + + + diff --git a/OtherPages/review.php b/OtherPages/review.php new file mode 100644 index 0000000..854fce5 --- /dev/null +++ b/OtherPages/review.php @@ -0,0 +1,109 @@ + + + + + + + + Review Us + + + + + + + + +
+
+ Review Us + + + + + +
+
+ + + + + \ No newline at end of file diff --git a/OtherPages/signup.php b/OtherPages/signup.php new file mode 100644 index 0000000..60b2189 --- /dev/null +++ b/OtherPages/signup.php @@ -0,0 +1,143 @@ + + + + + + Sign Up Page + + + + + +
+
+ Sign Up + + + + +
+ + +
+ +
+ + Male + Female +
+ + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/OtherPages/welcome.php b/OtherPages/welcome.php new file mode 100644 index 0000000..1be2844 --- /dev/null +++ b/OtherPages/welcome.php @@ -0,0 +1,39 @@ + + + + + Welcome + + + +

Welcome, User!

+ + + +
+ +
+ + + + \ No newline at end of file diff --git a/Toggle.html b/Toggle.html new file mode 100644 index 0000000..25544e8 --- /dev/null +++ b/Toggle.html @@ -0,0 +1,118 @@ + + + + + + Switch Button + + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..c9637bf --- /dev/null +++ b/config.js @@ -0,0 +1,42 @@ +const apiKeyData = [ + 'pub_31554370e11a6e70b4b2e4a91f27bad8a6828', + 'pub_31571add825b1d3e10c9f35e0079f6328d806', + 'pub_3157975aa5dfc81c57e1e121f7aaa49af4ce2', + 'pub_31580bbb6ba933bead156cf87510ee0aad428', + 'pub_31581573ab6880c5f0ae18d6222bf1d779099', + 'pub_315828bef552eff31127d1ef65ad0c1af6b61', + 'pub_31583a41e1d8b22b6a6163b17887f24f78339', + 'pub_31585e4453cb3f957356bcd3a5762886bc6d0', + 'pub_31617ef633d57ed52d4bf6e7f08e17740e1de', + 'pub_316194ef4c55a469201683e8a35ff44b9a487', + 'pub_31620dd02ae2700eb3acaa4669988d65ae000', + 'pub_31621668a5c7168c716b068fb7f3fe43a90cf', + 'pub_31622c261979ab968e1ee9e265281073322ae', + 'pub_31623a3427a984b872db8d780316935285eee', + 'pub_316240ed15a9eba2cec320215e8c72a7572bd', + 'pub_316265dee848e75eec918f4d1ca03e9916655', + 'pub_31627e33577f37445df2f37e5a8867dd94aa8', + 'pub_31628b0dc9d42dc3ef579a68c92b30b02bace', + 'pub_316294b354db64a154c4d8c70d02601fb2f13', + 'pub_31630ca4a9b58795e3c25382e81eef7d61885', + 'pub_316313df70c0362201587a55f202e52845ead', + 'pub_31632ab8c04a7d95513a74fa171c6e70334d5', + 'pub_316332a3e9288280f849b27f4b0d074e169c9', + 'pub_31634187b76f8f2892eb941c7b2606d979a1a', + 'pub_316354226103164584e4f29b1b55a78193bc7', + 'pub_3163688629520e7eed0681fe2499602349005', + 'pub_31637dc17c3297cdd806571ceb21bf7f98e49', + 'pub_316381054bd4d3f4eafe577dbfa73505f0809', + 'pub_31639d6a1f9c447aa342ab8bbafa539f18968', + 'pub_316407f568fddf00d598805f4760c749c3040', + 'pub_3164119889a214fcbce9112e0f527974d91c2', + 'pub_31643413c23c5c9cdb53a6f72f184e724583d', + 'pub_316445b45a0f2cbf58d30957d6d0c4f0998aa', + 'pub_316454f5a8ccf45f6bddcc58c05dc7f94fe87', + 'pub_316477a155b985b58907514e0c3ca1e1b4669', + 'pub_31648a61ea844598a93110a856ee4c82693cf', + 'pub_3164997c65a8eba4ef12d3b3e22c0ce80ac38', + 'pub_31650e077a52447585ece890c9324e239a391', + 'pub_31651a37d1f40e1da897fa72c86d5fc2319ca', + 'pub_31652adc57f4d29c04d572b2df28993453182' +]; \ No newline at end of file diff --git a/dbconnection.php b/dbconnection.php new file mode 100644 index 0000000..4601765 --- /dev/null +++ b/dbconnection.php @@ -0,0 +1,32 @@ +close(); + } + + function isExists($conn, $emailId, $table_name) + { + $emailId = mysqli_real_escape_string($conn, $emailId); // Sanitize input + $query = "SELECT EMAIL_ID FROM $table_name WHERE EMAIL_ID = '$emailId'"; + $result = mysqli_query($conn, $query); + + if ($result) { + return mysqli_num_rows($result) > 0; + } else { + return false; + } + } +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..5d6a4dc --- /dev/null +++ b/index.php @@ -0,0 +1,68 @@ + + + + + + + + + + News + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..ce7f7ce --- /dev/null +++ b/script.js @@ -0,0 +1,156 @@ +let url = 'https://newsapi.org/v2/top-headlines?'; +let API_KEY = apiKeyData[3]; +let api_key_tracker = 0; +let nextPageId = undefined; + +async function fetchNews(category,requiredArticles=5,json=[]) { + localStorage.removeItem("newsArticles"); + loadBtn = document.querySelector("#loadMoreBtn"); + let result = await fetch(`https://newsdata.io/api/1/news?apikey=` + API_KEY + `&country=in&language=en&category=`+category); + let response_code = result.status; + let data = await result.json(); + console.log("FetchNews : ",data); + console.log(data.status); + console.log("Om : ",response_code); + + if(response_code == 429){ + console.log("failure !!"); + api_key_tracker = (api_key_tracker + 1) % 42; + API_KEY = apiKeyData[api_key_tracker]; + fetchNews(category); + } + else if(response_code == 422){ + document.write("Something Went Wrong !!"); + } + + else{ + if(data.nextPage != null){ + nextPageId = data.nextPage; + loadBtn.innerHTML = "Load More"; + loadBtn.setAttribute("style", "display : block"); + } + else{ + loadBtn.setAttribute("style","display : none"); + nextPageId = undefined; + } + + data = data.results; + let noOfArticles = 0; + for(let i=0; i 0) && nextPageId != undefined){ + loadMoreNews(category,requiredArticles-noOfArticles,json); + } + else{ + toLocalStorage(json); + fillNews(); + } + } +} + +function fillNews() { + let data = JSON.parse(localStorage.getItem("newsArticles")); + + document.getElementById("main").innerHTML = ''; + for (let i = 0; i < data.length; i++) { + for (let j = 0; j < data[i].length; j++) { + let creatorDetails = data[i][j].creator; + + if (creatorDetails == null) + creatorDetails = `Anonymous • `+ data[i][j].pubDate.slice(0, 10); + else + creatorDetails = ``+data[i][j].creator+` • `+ data[i][j].pubDate.slice(0, 10); + + // Id for news card elements + let news_article_id = data[i][j].article_id; + + document.getElementById("main").innerHTML += + `
+
+
`+creatorDetails+`
+
+

`+ data[i][j].title + `

+
+
+

`+ data[i][j].description.slice(0,200) + `...` + `

+
+
+
+ News-Image +
+
` + } + } +} + +function toLocalStorage(data) { + let storedData = localStorage.getItem("newsArticles"); + + if (storedData === null) { + // If no data exists, create a new array and store it in localStorage + localStorage.setItem("newsArticles", JSON.stringify([data])); + } else { + // If data exists, parse it, update the array, and store it back + let existingData = JSON.parse(storedData); + existingData.push(data); + localStorage.setItem("newsArticles", JSON.stringify(existingData)); + console.log(JSON.parse(localStorage.getItem("newsArticles"))) + } +} + +async function loadMoreNews(category,requiredArticles=5,json=[]) { + let loadBtn = document.querySelector("#loadMoreBtn"); + loadBtn.innerHTML = "Loading"; + + let result = await fetch(`https://newsdata.io/api/1/news?apikey=` + API_KEY + `&country=in&language=en&category=`+category+`&page=`+nextPageId); + let response_code = result.status; + let data = await result.json(); + + if(response_code == 429){ + console.log("failure !!"); + api_key_tracker = (api_key_tracker + 1) % 42; + API_KEY = apiKeyData[api_key_tracker]; + loadMoreNews(category,requiredArticles,json); + } + else if(response_code == 422){ + document.write("Something Went Wrong !!"); + } + else{ + console.log("Load More data : ",data); + if(data.nextPage != null){ + nextPageId = data.nextPage; + loadBtn.setAttribute("style", "display : block"); + loadBtn.innerHTML = "Load More"; + } + else{ + nextPageId = undefined; + loadBtn.setAttribute("style","display : none"); + } + + data = data.results; + console.log("Main : ",data); + + let noOfArticles = 0; + for(let i=0; i 0) && nextPageId != undefined){ + loadMoreNews(category,requiredArticles-noOfArticles,json); + } + else{ + toLocalStorage(json); + fillNews(); + } + console.log(noOfArticles); + } +} + +fetchNews("Business"); \ No newline at end of file diff --git a/selection.css b/selection.css new file mode 100644 index 0000000..e31b555 --- /dev/null +++ b/selection.css @@ -0,0 +1,90 @@ +#categoryDiv { + display: flex; + width: 80%; + margin: auto; + margin-top: 20px; + overflow: hidden; + overflow-x: scroll; + border: none; + border-bottom: 1px solid rgba(128, 128, 128, 0.345); + position: relative; + /* border: 2px solid gray; */ +} + +#categoryDiv::-webkit-scrollbar { + display: none; +} + +.category-item { + margin-left: 35px; + cursor: pointer; + font-size: 17px; + font-weight: 600; + padding-bottom: 12px; + position: relative; + top: 2px; +} + +#plus-icon { + margin-right: -15px; + font-size: 20px; + cursor: pointer; +} + +.switch { + display: inline-block; + background-color: gray; + height: 32px; + width: 55px; + border-radius: 20px; + display: flex; + align-items: center; + justify-content: flex-start; + cursor: pointer; +} + +.switch>div { + background-color: white; + height: 20px; + width: 20px; + border-radius: 50%; + margin-left: 7px; + transition: 0.2s ease-in-out; +} + +.categoryDivToggle { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 20px; +} + +.categoryDivToggle>div { + margin-left: 20px; + font-size: 22px; + font-weight: 600; + letter-spacing: 0.3px; +} + +#categorySelectionBox { + width: 30%; + height: 600px; + border: 1px solid rgba(128, 128, 128, 0.395); + background-color: white; + border-radius: 9px; + padding: 15px 45px 20px 45px; + overflow: hidden; + overflow-y: scroll; + display: none; + position: absolute; + margin-left: calc((100vw - 347px)/2); + margin-top: calc((70vh - 500px)/2); + z-index: 3; +} + +#saveBtn { + margin: auto; + margin-top: 30px; + width: 80%; + display: block; +} \ No newline at end of file diff --git a/selection.js b/selection.js new file mode 100644 index 0000000..11147c7 --- /dev/null +++ b/selection.js @@ -0,0 +1,102 @@ +let category = ['News', 'Cricket', 'Ahmedabad', 'Football', 'Business', 'Entertainment', 'Technology', 'Lifestyle', 'Religion', 'Politics', 'World', 'Agriculture', 'Education', 'Crime', 'Astro', 'Mumbai', 'Delhi', 'Benguluru', 'Kolkata', 'Hydrabad'] + +let toggleVar = [true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]; + +let currentCategory = null; + +// Retrive data of userpreference +if (localStorage.getItem("userPreference_Category") != null) + toggleVar = JSON.parse(localStorage.getItem("userPreference_Category")); + + +function toggle(i, set = false) { + if (set == false) { + if (toggleVar[i] == false) { + document.querySelectorAll(".switch")[i].children[0].style.marginLeft = "28px"; + document.querySelectorAll(".switch")[i].style.backgroundColor = "rgb(254,64,102)"; + toggleVar[i] = true; + } + else { + document.querySelectorAll(".switch")[i].children[0].removeAttribute("style"); + document.querySelectorAll(".switch")[i].removeAttribute("style"); + toggleVar[i] = false; + } + } + else { + if (toggleVar[i] == false) { + document.querySelectorAll(".switch")[i].children[0].removeAttribute("style"); + document.querySelectorAll(".switch")[i].removeAttribute("style"); + } + else { + document.querySelectorAll(".switch")[i].children[0].style.marginLeft = "28px"; + document.querySelectorAll(".switch")[i].style.backgroundColor = "rgb(254,64,102)"; + } + } +} + +function savePreference() { + console.log("Save : "+toggleVar); + + let isFalseAll = toggleVar.every(item => item === false); + if (isFalseAll === true) + toggleVar[0] = true; + + localStorage.setItem("userPreference_Category", JSON.stringify(toggleVar)); + + document.getElementById("categoryDiv").innerHTML = ""; + document.getElementById("categoryDiv").innerHTML = `
`; + for(let i=0; i` + category[i] + `` + } + } + if(currentCategory == null || toggleVar[currentCategory.slice(9)] == false){ + currentCategory = document.getElementsByClassName("category-item")[0].getAttribute("id"); + } + + console.log(toggleVar); + focusCategory(currentCategory); + // console.log(toggleVar) + // console.log("updated : ",currentCategory); + showHideCategorySelectionBox(false); // It will hide the selection box + +} + +function focusCategory(category_id) { + if (currentCategory == null) + document.getElementById(category_id).setAttribute("style", "border-bottom : 4px solid red; color : rgb(212, 28, 64)"); + else { + document.getElementById(currentCategory).removeAttribute("style"); + document.getElementById(category_id).setAttribute("style", "border-bottom : 4px solid red; color : rgb(212, 28, 64)"); + currentCategory = category_id; + } + console.log("focus : ",currentCategory) +} + +function showHideCategorySelectionBox(show=true){ + // Reset Toggle buttons + for (let i = 0; i < category.length; i++) + toggle(i, true); //Reset toggle buttons as per user preference + + if(show == true) + document.getElementById("categorySelectionBox").setAttribute("style","display : block"); + else + document.getElementById("categorySelectionBox").setAttribute("style","display : none"); +} + +// For adding toggle buttons +document.getElementById("categorySelectionBox").innerHTML = ``; +for (let i = 0; i < category.length; i++) { + document.getElementById("categorySelectionBox").innerHTML += + `
+
`+ category[i] + `
+
+
+
+
` +} +document.getElementById("categorySelectionBox").innerHTML += `
`; + +savePreference(); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..dd65455 --- /dev/null +++ b/style.css @@ -0,0 +1,148 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap'); + +*{ + margin: 0; + padding: 0; + box-sizing: border-box; + font-family: 'Poppins', sans-serif; +} + +.navbar{ + height: 80px; + background-color: white; + display: flex; + justify-content: space-around; + align-items: center; + /* background: linear-gradient(to right, rgba(106, 17, 203, 0.9), rgba(37, 117, 252, 0.9)); */ + position: sticky; + top: 0; +} + +.logo{ + font-size: 30px; + font-weight: 700; + color: rgb(254,64,102); + cursor: pointer; +} + +.nav-links{ + width: 40%; +} + +.nav-links > ul{ + display: flex; + justify-content: space-evenly; +} + +.nav-links > ul > li{ + list-style: none; +} + +.nav-links > ul > li > a{ + color: rgb(97,93,93); + text-decoration: none; + font-size: 17px; + font-weight: 700; + position: relative; +} + +.nav-links > ul > li > a::after{ + content: ''; + width: 100%; + height: 5px; + background-color: rgb(255, 128, 0); + position: absolute; + left: 0; + bottom: -9px; + transform: scaleX(0); + transition: transform 0.3s ease-in-out; + transform-origin: right; +} + +.nav-links > ul > li > a:hover::after{ + transform: scaleX(1); + transform-origin: left; +} + +.nav-links > ul > li > a:hover{ + color: black; +} + +.btn{ + width: 120px; + height: 43px; + font-size: 17px; + font-weight: 700; + letter-spacing: 1.2px; + border: none; + background-color: rgb(254,64,102); + color: white; + border-radius: 40px; + cursor: pointer; +} + +.btn:hover{ + background-color: rgb(212, 28, 64); +} + +#main{ + width: 80%; + margin: auto; + margin-top: 50px; + margin-bottom: 50px; +} + +.news-card{ + width: 100%; + height: 280px; + display: flex; + padding: 0px 20px; + border: 1px solid rgba(128, 128, 128, 0.397); + border-radius: 8px; + margin-bottom: 30px; +} + +.news-card-left{ + width: 75%; + margin-right: 25px; +} + +.news-provider-info{ + margin: 25px 0px 5px 15px; +} + +.news-title{ + margin-left: 15px; +} + +.news-description{ + margin: 15px 15px 0px 15px; +} + +.news-title > p{ + font-size: 23px; + font-weight: 600; +} + +.news-description > p{ + font-size: 15px; +} + +.news-card-right{ + width: 25%; + padding: 25px 0px; +} + +.news-image{ + width: 100%; + height: 100%; + border-radius: 8px; +} + +#loadMoreBtn{ + display : none; + margin: auto; + margin-bottom: 30px; + width: 170px; + height: 48px; +} \ No newline at end of file diff --git a/utils.css b/utils.css new file mode 100644 index 0000000..d066855 --- /dev/null +++ b/utils.css @@ -0,0 +1,61 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap'); + + * { + margin: 0; + padding: 0; + box-sizing: border-box; + font-family: 'Poppins', sans-serif; + } + + .main { + display: flex; + width: 100vw; + height: 100vh; + justify-content: center; + align-items: center; + } + + form { + display: flex; + flex-direction: column; + border: 1px solid rgba(128, 128, 128, 0.39); + padding: 25px 40px; + border-radius: 10px; + } + + form > span:nth-child(1) { + display: block; + margin: auto; + margin-bottom: 20px; + font-size: 30px; + font-weight: 600; + } + + .inputFields { + width: 98%; + height: 49px; + padding: 20px 15px; + border-radius: 8px; + margin-bottom: 20px; + border: none; + outline: none; + background-color: #eeeeee; + font-size: 16px; + } + + .btn{ + width: 120px; + height: 43px; + font-size: 17px; + font-weight: 700; + letter-spacing: 1.2px; + border: none; + background-color: rgb(254,64,102); + color: white; + border-radius: 40px; + cursor: pointer; + } + + .btn:hover{ + background-color: rgb(212, 28, 64); + } \ No newline at end of file