ソースを参照

chatroom and follower completed

Kent 5 年 前
コミット
9663fd63fd

+ 230 - 2
src/comment.php

@@ -3,6 +3,22 @@ include_once 'auth.php';
 //Get information of local data storage from auth.php
 $userAccountName = $_SESSION['login']; 
 $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/"; 
+if (!file_exists($dataStorage)){
+	//如果使用者是第一次使用 TeaBag,幫他開個新資料夾,並創建用家資料檔
+	mkdir($dataStorage,0777,true);
+	file_put_contents($dataStorage . "userdata.json",'{"username":"' . $userAccountName .'",
+	  "accountCreationTime":"' . time() . '",
+	  "invitedByUser":"Admin",
+	  "permissionLevel":3,
+	  "banned":false
+	}');
+	include_once("functions/createUserDirectories.php");
+}
+date_default_timezone_set("Asia/Hong_Kong");
+$time = date("Y-m-d H:m:s");
+
+include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
+$userIcon = getUserIconPath();
 
 ?>
 <html>
@@ -13,6 +29,65 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 <link rel="stylesheet" href="script/tocas/tocas.css">
 <script src="script/tocas/tocas.js"></script>
 <script src="script/jquery.min.js"></script>
+<script>
+var activeChat = "";
+
+function showChat(id) {
+	
+  var x = document.getElementById("chatPop");
+  if (x.style.visibility === "hidden") {
+    x.style.visibility = "visible";
+  } else if(activeChat == id){
+    x.style.visibility = "hidden";
+  }
+  activeChat = id;
+  refresh();
+  document.getElementById("chatTarget").innerHTML = activeChat;
+} 
+
+function update() {
+  var xhttp = new XMLHttpRequest();
+  xhttp.onreadystatechange = function() {
+    if (this.readyState == 4 && this.status == 200) {
+		document.getElementById("chatHistory").innerHTML = this.responseText;
+    }
+  };
+  var touser = activeChat;
+  var fromuser = "<?php  echo $_SESSION['login'];?>";
+  var myText = document.getElementById("message").value;
+  if(myText != "" && myText != null)
+  {
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser+"&message="+myText);
+  }
+  document.getElementById("message").value = "";
+  
+  var objDiv = document.getElementById("chatHistory");
+  objDiv.scrollTop = objDiv.scrollHeight;
+}
+
+
+
+function refresh() {
+	var xhttp = new XMLHttpRequest();
+	xhttp.onreadystatechange = function() {
+	if (this.readyState == 4 && this.status == 200) {
+			document.getElementById("chatHistory").innerHTML = this.responseText;
+		}
+	};
+	
+	var touser = activeChat;
+	var fromuser = "<?php echo $_SESSION['login']; ?>";
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser);
+	
+}
+
+setInterval(refresh,1000);
+
+</script>
 <style>
 .extrapadding{
 	padding-left:10%;
@@ -48,6 +123,36 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 .linebreak{
 	white-space: pre-wrap;
 }
+
+.chatroomWindow{
+	visibility: hidden;
+	width:320px !important;
+	height:500px !important;
+	padding:5px !important;
+	position:fixed;
+	bottom:0;
+	right:0;
+	z-index: 99 !important;
+	border-style: solid;
+	border-width: 1px;
+	background-color: white;
+}
+
+
+.chathistory{
+	width:305px !important;
+	height:300px !important;
+	padding:5px !important;
+	border: 1px solid #000;
+	overflow-y: scroll;
+}
+
+.typing {
+	border: 1px solid #000;
+	padding:5px !important;
+	width:305px !important;
+}
+
 </style>
 </head>
 	<body>
@@ -55,7 +160,7 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 		<a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
 		<a class="item" href="home.php"><i class="home icon"></i> Following</a>
 		<a class="item" href="index.php"><i class="user outline icon"></i>Timeline</a>
-		<a class="item"><i class="mail outline icon"></i>Notification</a>
+		<a class="item" href="fdlist.php"><i class="users outline icon"></i>Friend List</a>
 		<a class="active item"><i class="comments outline icon"></i>Post Comment</a>
 		<div class="right item removePadding">
 		<div class="ts icon tiny input">
@@ -65,10 +170,114 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 		<a class="item" href="logout.php"><i class="log out icon"></i>Logout</a>
 		</div>
 	</div>
+	
+	<div class="ts container" style="padding-top:12px;">
+	<div class="ts grid">
+    <div class="four wide column">
+		<div class="ts teabag card">
+			<div class="image">
+				<img src="<?php echo $userIcon;?>" style="max-width:300px;">
+			</div>
+			<div class="content">
+				<div class="ts comments">
+					<div class="comment">
+						<div class="avatar">
+							<img src="<?php echo $userIcon; ?>">
+						</div>
+						<div class="content">
+							<a class="author"><?php include_once("functions/getUserName.php");?></a>
+							<div class="text">@<?php echo $_SESSION['login']; ?></div>
+						</div>
+					</div>
+				</div>
+				<button class="ts basic mini button" onClick='$("#changeIconDiv").slideToggle();'>Change Icon</button>
+				<div id="changeIconDiv" style="display:none;">
+					<iframe src="uploadIcon.php">
+					
+					</iframe>
+				</div>
+			</div>
+		</div>
+		<!-- Advertisment -->
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+			<?php 
+				include_once("loadads.php");
+				$adspath = initAds();
+				echo '<img class="ts fluid image" src="'. $adspath .'"/>';
+			?>
+			
+		</div>
+		<!-- Chatroom List--> 
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+		<?php
+		$query = "select * from following where followerName = '".$_SESSION['login']. "'";
+		include_once("requestDB.php"); //Handle all Database access, see the query command below
+		$followerResult = query($query,"teabag");
+		foreach ($followerResult as $chat){
+			echo '
+			<div class="ts nopadding comments">
+				<div class="comment selectable" id='.$chat["targetName"].' onClick="showChat(this.id)">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">'.$chat["targetName"].'</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				</div>
+				';
+		}	
+				?>
+<!--
+			<div class="ts nopadding comments">
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小白</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小綠</a>
+						<div class="inline text">
+							10分鐘前在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment icon"></i> 留言
+							</a>
+						</div>
+					</div>
+				</div>
+			</div>
+-->
+		</div>
+	</div>
+    <div class="twelve wide column">
 	<div id="comments" class="ts container">
 		
 	</div>
-	<div class="ts container" style="padding-top:12px;">
 	<?php
 	//Echo comemnt box
 	
@@ -110,6 +319,25 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 			}
 		});
 	</script>
+	
+	</div>
+</div>
+
+</div>
+
+<div class="chatroomWindow" id="chatPop">
+<script>
+refresh();
+</script>
+<div id="chatHistory" class="chathistory"></div>
+<form name="message" method="post">
+	<a id="chatTarget" class="author"></a><br/>
+	<textarea rows="4" placeholder="Write something here to chat!" name="message" cols="40" class="typing" id="message"></textarea>
+	<input type="button" onclick="update()" class="ts primary fluid button" value="Send">
+</form>
+</div>
+
+
 	</body>
 </html>
 

+ 354 - 0
src/fdList.php

@@ -0,0 +1,354 @@
+<?php
+include_once 'auth.php';
+//Get information of local data storage from auth.php
+$userAccountName = $_SESSION['login']; //使用者登入名稱,不可重複
+$dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/"; //使用者個人資料資料夾
+if (!file_exists($dataStorage)){
+	//如果使用者是第一次使用 TeaBag,幫他開個新資料夾,並創建用家資料檔
+	mkdir($dataStorage,0777,true);
+	file_put_contents($dataStorage . "userdata.json",'{"username":"' . $userAccountName .'",
+	  "accountCreationTime":"' . time() . '",
+	  "invitedByUser":"Admin",
+	  "permissionLevel":3,
+	  "banned":false
+	}');
+	include_once("functions/createUserDirectories.php");
+}
+date_default_timezone_set("Asia/Hong_Kong");
+$time = date("Y-m-d H:m:s");
+
+include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
+$userIcon = getUserIconPath();
+
+?>
+<html>
+<head>
+
+<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+<title>TeaBag.tw</title>
+<link rel="stylesheet" href="script/tocas/tocas.css">
+<script src="script/tocas/tocas.js"></script>
+<script src="script/jquery.min.js"></script>
+<script>
+var activeChat = "";
+
+function showChat(id) {
+	
+  var x = document.getElementById("chatPop");
+  if (x.style.visibility === "hidden") {
+    x.style.visibility = "visible";
+  } else if(activeChat == id){
+    x.style.visibility = "hidden";
+  }
+  activeChat = id;
+  refresh();
+  document.getElementById("chatTarget").innerHTML = activeChat;
+} 
+
+function update() {
+  var xhttp = new XMLHttpRequest();
+  xhttp.onreadystatechange = function() {
+    if (this.readyState == 4 && this.status == 200) {
+		document.getElementById("chatHistory").innerHTML = this.responseText;
+    }
+  };
+  var touser = activeChat;
+  var fromuser = "<?php  echo $_SESSION['login'];?>";
+  var myText = document.getElementById("message").value;
+  if(myText != "" && myText != null)
+  {
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser+"&message="+myText);
+  }
+  document.getElementById("message").value = "";
+  
+  var objDiv = document.getElementById("chatHistory");
+  objDiv.scrollTop = objDiv.scrollHeight;
+}
+
+
+
+function refresh() {
+	var xhttp = new XMLHttpRequest();
+	xhttp.onreadystatechange = function() {
+	if (this.readyState == 4 && this.status == 200) {
+			document.getElementById("chatHistory").innerHTML = this.responseText;
+		}
+	};
+	
+	var touser = activeChat;
+	var fromuser = "<?php echo $_SESSION['login']; ?>";
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser);
+	
+}
+
+setInterval(refresh,1000);
+
+</script>
+<style>
+.extrapadding{
+	padding-left:10%;
+	padding-right:10%;
+}
+.removePadding{
+	padding:0px !important;
+}
+.active.item{
+	color:#4287f5 !important;
+	font-weight: bold !important;
+}
+.postAvator{
+	height:50px !important;
+	padding-right:25px;
+}
+.teabag.card{
+	max-width:350px;
+}
+.nopadding{
+	padding:0px !important;
+}
+.selectable{
+	cursor:pointer;
+	padding:5px !important;
+}
+.selectable:hover{
+	background-color:#f2f2f2 !important;
+}
+.online{
+	color: #88db99;
+}
+.linebreak{
+	white-space: pre-wrap;
+}
+
+.chatroomWindow{
+	visibility: hidden;
+	width:320px !important;
+	height:500px !important;
+	padding:5px !important;
+	position:fixed;
+	bottom:0;
+	right:0;
+	z-index: 99 !important;
+	border-style: solid;
+	border-width: 1px;
+	background-color: white;
+}
+
+
+.chathistory{
+	width:305px !important;
+	height:300px !important;
+	padding:5px !important;
+	border: 1px solid #000;
+	overflow-y: scroll;
+}
+
+.typing {
+	border: 1px solid #000;
+	padding:5px !important;
+	width:305px !important;
+}
+</style>
+</head>
+<body>
+<div class="ts tabbed menu extrapadding">
+	<a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
+    <a class="item" href="home.php"><i class="home icon"></i> Following</a>
+    <a class="item" href="index.php"><i class="user outline icon"></i>Timeline</a>
+	<a class="active item" href="fdList.php"><i class="users outline icon"></i>Friend List</a>
+	<div class="right item removePadding">
+	<div class="ts icon tiny input">
+		<input type="text" placeholder="Search...">
+		<i class="circular search link icon"></i>
+	</div>
+	<a class="item" href="logout.php"><i class="log out icon"></i>Logout</a>
+	</div>
+</div>
+<div class="ts container">
+<div class="ts grid">
+    <div class="four wide column">
+		<div class="ts teabag card">
+			<div class="image">
+				<img src="<?php echo $userIcon;?>" style="max-width:300px;">
+			</div>
+			<div class="content">
+				<div class="ts comments">
+					<div class="comment">
+						<div class="avatar">
+							<img src="<?php echo $userIcon; ?>">
+						</div>
+						<div class="content">
+							<a class="author"><?php include_once("functions/getUserName.php");?></a>
+							<div class="text">@<?php echo $_SESSION['login']; ?></div>
+						</div>
+					</div>
+				</div>
+				<button class="ts basic mini button" onClick='$("#changeIconDiv").slideToggle();'>Change Icon</button>
+				<div id="changeIconDiv" style="display:none;">
+					<iframe src="uploadIcon.php">
+					
+					</iframe>
+				</div>
+			</div>
+		</div>
+		<!-- Advertisment -->
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+			<?php 
+				include_once("loadads.php");
+				$adspath = initAds();
+				echo '<img class="ts fluid image" src="'. $adspath .'"/>';
+			?>
+			
+		</div>
+		<!-- Chatroom List--> 
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+		<?php
+		$query = "select * from following where followerName = '".$_SESSION['login']. "'";
+		include_once("requestDB.php"); //Handle all Database access, see the query command below
+		$followerResult = query($query,"teabag");
+		foreach ($followerResult as $chat){
+			echo '
+			<div class="ts nopadding comments">
+				<div class="comment selectable" id='.$chat["targetName"].' onClick="showChat(this.id)">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">'.$chat["targetName"].'</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				</div>
+				';
+		}	
+				?>
+<!--
+			<div class="ts nopadding comments">
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小白</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小綠</a>
+						<div class="inline text">
+							10分鐘前在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment icon"></i> 留言
+							</a>
+						</div>
+					</div>
+				</div>
+			</div>
+-->
+		</div>
+	</div>
+    <div class="twelve wide column">
+<?php
+			if (filesize("root.inf") > 0){
+				//Use the special path instead.
+				$rootPath = trim(file_get_contents("root.inf"));
+			}
+			$databasePath = $rootPath . "whitelist.config";			
+			$h = fopen($databasePath, "r");
+			$userlist = [];
+			while (($buffer = fgets($h, 4096)) !== false) {
+				array_push($userlist, '"'.explode(",",$buffer)[0].'"');
+			}
+			unset($userlist[ array_search('"'.$_SESSION['login'].'"',$userlist)]);
+			$userListString = implode(",",$userlist);
+
+			$query1 = "select * from following where followerName = '".$_SESSION['login']."' and targetname in (".$userListString.")";
+			include_once("requestDB.php"); //Handle all Database access, see the query command below
+			include_once("getUserImage.php");
+			$followerResult = query($query1,"teabag");
+			?>
+			<div class="ts segment">
+				<div class="field">
+					<label>Followed</label>
+					<?php
+					foreach ($followerResult as $follower){
+						echo '
+						<div class="ts card">
+								<div class="header"><img class="ts image postAvator" src="' . getUserIconPathByUsername($follower["targetName"]) .'" style="margin-right:-20px;width:80px;height:80px;">' . $follower["targetName"] . '
+						<a href="unfollow.php?target='.$follower["targetName"].'">Unfollow</a>		
+						</div>
+						</div>
+						';
+						unset($userlist[ array_search('"'.$follower["targetName"].'"',$userlist)]);
+					}
+			?>
+				</div>
+			</div>
+			<div class="ts segment">
+				<div class="field">
+					<label>Not Followed</label>
+					<?php
+					foreach ($userlist as $user){
+						echo '
+						<div class="ts card">
+								<div class="header"><img class="ts image postAvator" src="' . getUserIconPathByUsername(trim($user,'"')) .'" style="margin-right:-20px;width:80px;height:80px;">' . trim($user,'"') . '
+								<a href="follow.php?target='.trim($user,'"').'">Follow</a>
+								</div>
+						</div>
+						';
+					}
+			
+?>
+				</div>
+			</div>
+			
+	</div>
+</div>
+
+</div>
+
+<div class="chatroomWindow" id="chatPop">
+<script>
+refresh();
+</script>
+<div id="chatHistory" class="chathistory"></div>
+<form name="message" method="post">
+	<a id="chatTarget" class="author"></a><br/>
+	<textarea rows="4" placeholder="Write something here to chat!" name="message" cols="40" class="typing" id="message"></textarea>
+	<input type="button" onclick="update()" class="ts primary fluid button" value="Send">
+</form>
+</div>
+
+
+<script>
+
+function refreshPage(){
+	window.location.reload();
+}
+</script>
+</body>
+</html>

+ 26 - 0
src/follow.php

@@ -0,0 +1,26 @@
+<?php
+include_once(__DIR__ . "/auth.php");
+include_once("requestDB.php");
+	queryw("INSERT INTO `following` (`followerName`, `targetName`, `banned`, `followDate`) VALUES ('" . $_SESSION['login'] . "', '" . $_GET["target"] . "',0, CURRENT_TIMESTAMP)","teabag");
+header("Location: fdList.php");
+
+/*
+$conn = mysqli_connect("localhost","root","","message");
+if($conn->connect_error)
+{
+	echo "Unable to connect to database";
+	exit;
+}
+
+//$sql = "INSERT INTO `message` (`user`, `datetime`, `messgae`, `id`) VALUES ('".$_SESSION['login']."', current_timestamp(), '".$_POST[message]."', NULL);";
+
+$stmt = $conn->prepare("INSERT INTO `message` (`user`, `datetime`, `messgae`, `id`) VALUES (?, current_timestamp(),?, NULL);");
+$stmt->bind_param("ss", $_SESSION['login'], $_POST[message]);
+$stmt->execute();
+
+$stmt->close();
+$conn->close();
+
+header("Location: index.php");
+*/
+?>

+ 26 - 0
src/getChatHistory.php

@@ -0,0 +1,26 @@
+<?php
+session_start();
+include_once("requestDB.php"); 
+if(isset($_POST['message']))
+{
+	$sql = "INSERT INTO `chat` (`fromuser`, `touser`, `content`, `sendtime`) 
+		VALUES ( '"
+		.$_POST['fromuser']."','"
+		.$_POST['touser']."','"
+		.$_POST['message']
+		. "',CURRENT_TIMESTAMP)";
+	queryw($sql, "teabag");
+}
+
+
+
+$chatsql = "select * from chat where 
+	(touser='" . $_POST['fromuser'] . "' and fromuser='".$_POST['touser']."') or 
+	(touser='" . $_POST['touser'] . "' and fromuser='".$_POST['fromuser']."')  ORDER BY sendtime";
+$chatdata = query($chatsql,"teabag");
+foreach ($chatdata as $chat){
+
+		echo '<a>'.$chat['fromuser']."(".$chat['sendtime']."):</a><br/>".$chat['content']."<br/>";		
+
+}
+?>

+ 226 - 2
src/home.php

@@ -3,6 +3,22 @@ include_once 'auth.php';
 //Get information of local data storage from auth.php
 $userAccountName = $_SESSION['login']; 
 $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/"; 
+if (!file_exists($dataStorage)){
+	//如果使用者是第一次使用 TeaBag,幫他開個新資料夾,並創建用家資料檔
+	mkdir($dataStorage,0777,true);
+	file_put_contents($dataStorage . "userdata.json",'{"username":"' . $userAccountName .'",
+	  "accountCreationTime":"' . time() . '",
+	  "invitedByUser":"Admin",
+	  "permissionLevel":3,
+	  "banned":false
+	}');
+	include_once("functions/createUserDirectories.php");
+}
+date_default_timezone_set("Asia/Hong_Kong");
+$time = date("Y-m-d H:m:s");
+
+include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
+$userIcon = getUserIconPath();
 
 ?>
 <html>
@@ -13,6 +29,65 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 <link rel="stylesheet" href="script/tocas/tocas.css">
 <script src="script/tocas/tocas.js"></script>
 <script src="script/jquery.min.js"></script>
+<script>
+var activeChat = "";
+
+function showChat(id) {
+	
+  var x = document.getElementById("chatPop");
+  if (x.style.visibility === "hidden") {
+    x.style.visibility = "visible";
+  } else if(activeChat == id){
+    x.style.visibility = "hidden";
+  }
+  activeChat = id;
+  refresh();
+  document.getElementById("chatTarget").innerHTML = activeChat;
+} 
+
+function update() {
+  var xhttp = new XMLHttpRequest();
+  xhttp.onreadystatechange = function() {
+    if (this.readyState == 4 && this.status == 200) {
+		document.getElementById("chatHistory").innerHTML = this.responseText;
+    }
+  };
+  var touser = activeChat;
+  var fromuser = "<?php  echo $_SESSION['login'];?>";
+  var myText = document.getElementById("message").value;
+  if(myText != "" && myText != null)
+  {
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser+"&message="+myText);
+  }
+  document.getElementById("message").value = "";
+  
+  var objDiv = document.getElementById("chatHistory");
+  objDiv.scrollTop = objDiv.scrollHeight;
+}
+
+
+
+function refresh() {
+	var xhttp = new XMLHttpRequest();
+	xhttp.onreadystatechange = function() {
+	if (this.readyState == 4 && this.status == 200) {
+			document.getElementById("chatHistory").innerHTML = this.responseText;
+		}
+	};
+	
+	var touser = activeChat;
+	var fromuser = "<?php echo $_SESSION['login']; ?>";
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser);
+	
+}
+
+setInterval(refresh,1000);
+
+</script>
 <style>
 .extrapadding{
 	padding-left:10%;
@@ -51,6 +126,37 @@ $dataStorage = $sysConfigDir . '/userdata/' .  $_SESSION['login'] . "/";
 a{
 	cursor:pointer;
 }
+
+.chatroomWindow{
+	visibility: hidden;
+	width:320px !important;
+	height:500px !important;
+	padding:5px !important;
+	position:fixed;
+	bottom:0;
+	right:0;
+	z-index: 99 !important;
+	border-style: solid;
+	border-width: 1px;
+	background-color: white;
+}
+
+
+.chathistory{
+	width:305px !important;
+	height:300px !important;
+	padding:5px !important;
+	border: 1px solid #000;
+	overflow-y: scroll;
+}
+
+.typing {
+	border: 1px solid #000;
+	padding:5px !important;
+	width:305px !important;
+}
+
+
 </style>
 </head>
 	<body>
@@ -58,7 +164,7 @@ a{
 		<a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
 		<a class="active item" href="home.php"><i class="home icon"></i> Following</a>
 		<a class="item" href="index.php"><i class="user outline icon"></i>Timeline</a>
-		<a class="item"><i class="mail outline icon"></i>Notification</a>
+		<a class="item" href="fdList.php"><i class="users outline icon"></i>Friend List</a>
 		<div class="right item removePadding">
 		<div class="ts icon tiny input">
 			<input type="text" placeholder="Search...">
@@ -68,6 +174,109 @@ a{
 		</div>
 	</div>
 	<div class="ts container">
+	<div class="ts grid">
+    <div class="four wide column">
+		<div class="ts teabag card">
+			<div class="image">
+				<img src="<?php echo $userIcon;?>" style="max-width:300px;">
+			</div>
+			<div class="content">
+				<div class="ts comments">
+					<div class="comment">
+						<div class="avatar">
+							<img src="<?php echo $userIcon; ?>">
+						</div>
+						<div class="content">
+							<a class="author"><?php include_once("functions/getUserName.php");?></a>
+							<div class="text">@<?php echo $_SESSION['login']; ?></div>
+						</div>
+					</div>
+				</div>
+				<button class="ts basic mini button" onClick='$("#changeIconDiv").slideToggle();'>Change Icon</button>
+				<div id="changeIconDiv" style="display:none;">
+					<iframe src="uploadIcon.php">
+					
+					</iframe>
+				</div>
+			</div>
+		</div>
+		<!-- Advertisment -->
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+			<?php 
+				include_once("loadads.php");
+				$adspath = initAds();
+				echo '<img class="ts fluid image" src="'. $adspath .'"/>';
+			?>
+			
+		</div>
+		<!-- Chatroom List--> 
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+		<?php
+		$query = "select * from following where followerName = '".$_SESSION['login']. "'";
+		include_once("requestDB.php"); //Handle all Database access, see the query command below
+		$followerResult = query($query,"teabag");
+		foreach ($followerResult as $chat){
+			echo '
+			<div class="ts nopadding comments">
+				<div class="comment selectable" id='.$chat["targetName"].' onClick="showChat(this.id)">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">'.$chat["targetName"].'</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				</div>
+				';
+		}	
+				?>
+<!--
+			<div class="ts nopadding comments">
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小白</a>
+						<div class="inline text">
+							現時在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment online icon"></i> 打開聊天室
+							</a>
+						</div>
+					</div>
+				</div>
+				<div class="comment selectable">
+					<a class="avatar">
+						<img src="img/dummy.png">
+					</a>
+					<div class="content">
+						<a class="author">小綠</a>
+						<div class="inline text">
+							10分鐘前在線
+						</div>
+						<div class="middoted actions">
+							<a>
+								<i class="comment icon"></i> 留言
+							</a>
+						</div>
+					</div>
+				</div>
+			</div>
+-->
+		</div>
+	</div>
+    <div class="twelve wide column">
 		<?php
 			//Show all the other's post in this page
 			include_once("requestDB.php"); //Handle all Database access, see the query command below
@@ -106,6 +315,21 @@ a{
 			}
 		?>
 	</div>
-	<br><br><br><br><br>
+	</div>
+</div>
+
+</div>
+
+<div class="chatroomWindow" id="chatPop">
+<script>
+refresh();
+</script>
+<div id="chatHistory" class="chathistory"></div>
+<form name="message" method="post">
+	<a id="chatTarget" class="author"></a><br/>
+	<textarea rows="4" placeholder="Write something here to chat!" name="message" cols="40" class="typing" id="message"></textarea>
+	<input type="button" onclick="update()" class="ts primary fluid button" value="Send">
+</form>
+</div>
 	</body>
 </html>

+ 119 - 7
src/index.php

@@ -29,6 +29,65 @@ $userIcon = getUserIconPath();
 <link rel="stylesheet" href="script/tocas/tocas.css">
 <script src="script/tocas/tocas.js"></script>
 <script src="script/jquery.min.js"></script>
+<script>
+var activeChat = "";
+
+function showChat(id) {
+	
+  var x = document.getElementById("chatPop");
+  if (x.style.visibility === "hidden") {
+    x.style.visibility = "visible";
+  } else if(activeChat == id){
+    x.style.visibility = "hidden";
+  }
+  activeChat = id;
+  refresh();
+  document.getElementById("chatTarget").innerHTML = activeChat;
+} 
+
+function update() {
+  var xhttp = new XMLHttpRequest();
+  xhttp.onreadystatechange = function() {
+    if (this.readyState == 4 && this.status == 200) {
+		document.getElementById("chatHistory").innerHTML = this.responseText;
+    }
+  };
+  var touser = activeChat;
+  var fromuser = "<?php  echo $_SESSION['login'];?>";
+  var myText = document.getElementById("message").value;
+  if(myText != "" && myText != null)
+  {
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser+"&message="+myText);
+  }
+  document.getElementById("message").value = "";
+  
+  var objDiv = document.getElementById("chatHistory");
+  objDiv.scrollTop = objDiv.scrollHeight;
+}
+
+
+
+function refresh() {
+	var xhttp = new XMLHttpRequest();
+	xhttp.onreadystatechange = function() {
+	if (this.readyState == 4 && this.status == 200) {
+			document.getElementById("chatHistory").innerHTML = this.responseText;
+		}
+	};
+	
+	var touser = activeChat;
+	var fromuser = "<?php echo $_SESSION['login']; ?>";
+	xhttp.open("POST", "getChatHistory.php", true);
+	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xhttp.send("touser="+touser+"&fromuser="+fromuser);
+	
+}
+
+setInterval(refresh,1000);
+
+</script>
 <style>
 .extrapadding{
 	padding-left:10%;
@@ -64,6 +123,35 @@ $userIcon = getUserIconPath();
 .linebreak{
 	white-space: pre-wrap;
 }
+
+.chatroomWindow{
+	visibility: hidden;
+	width:320px !important;
+	height:500px !important;
+	padding:5px !important;
+	position:fixed;
+	bottom:0;
+	right:0;
+	z-index: 99 !important;
+	border-style: solid;
+	border-width: 1px;
+	background-color: white;
+}
+
+
+.chathistory{
+	width:305px !important;
+	height:300px !important;
+	padding:5px !important;
+	border: 1px solid #000;
+	overflow-y: scroll;
+}
+
+.typing {
+	border: 1px solid #000;
+	padding:5px !important;
+	width:305px !important;
+}
 </style>
 </head>
 <body>
@@ -71,7 +159,7 @@ $userIcon = getUserIconPath();
 	<a class="item" href="index.php"><img src="img/minilogo.png" style="height:25px;"></a>
     <a class="item" href="home.php"><i class="home icon"></i> Following</a>
     <a class="active item" href="index.php"><i class="user outline icon"></i>Timeline</a>
-	<a class="item"><i class="mail outline icon"></i>Notification</a>
+	<a class="item" href="fdList.php"><i class="users outline icon"></i>Friend List</a>
 	<div class="right item removePadding">
 	<div class="ts icon tiny input">
 		<input type="text" placeholder="Search...">
@@ -118,14 +206,19 @@ $userIcon = getUserIconPath();
 		</div>
 		<!-- Chatroom List--> 
 		<div class="ts segment" style='height:300px; overflow-y:auto;'>
-<!--
+<?php
+		$query = "select * from following where followerName = '".$_SESSION['login']. "'";
+		include_once("requestDB.php"); //Handle all Database access, see the query command below
+		$followerResult = query($query,"teabag");
+		foreach ($followerResult as $chat){
+			echo '
 			<div class="ts nopadding comments">
-				<div class="comment selectable">
+				<div class="comment selectable" id="'.$chat["targetName"].'"onClick="showChat(this.id)">
 					<a class="avatar">
 						<img src="img/dummy.png">
 					</a>
 					<div class="content">
-						<a class="author">小白</a>
+						<a class="author">'.$chat["targetName"].'</a>
 						<div class="inline text">
 							現時在線
 						</div>
@@ -136,6 +229,11 @@ $userIcon = getUserIconPath();
 						</div>
 					</div>
 				</div>
+				</div>
+				';
+		}	
+				?>
+				<!--
 				<div class="comment selectable">
 					<a class="avatar">
 						<img src="img/dummy.png">
@@ -152,10 +250,11 @@ $userIcon = getUserIconPath();
 						</div>
 					</div>
 				</div>
-			</div>
+				
+			
 -->
+			</div>
 		</div>
-	</div>
     <div class="twelve wide column">
 		<div class="ts text container">
 		<div class="ts segment">
@@ -170,7 +269,7 @@ $userIcon = getUserIconPath();
 			</div>
 		</div>
 		<?php
-			include_once("requestDB.php"); //Handle all Database access, see the query command below
+			 //include_once("requestDB.php"); //Handle all Database access, see the query command below
 			$postData = query("select * from post where username='" . $_SESSION['login'] . "' ORDER BY postid DESC","teabag");
 			foreach ($postData as $post){
 				echo '
@@ -193,6 +292,19 @@ $userIcon = getUserIconPath();
 </div>
 
 </div>
+
+<div class="chatroomWindow" id="chatPop">
+<script>
+refresh();
+</script>
+<div id="chatHistory" class="chathistory"></div>
+<form name="message" method="post">
+	<a id="chatTarget" class="author"></a><br/>
+	<textarea rows="4" placeholder="Write something here to chat!" name="message" cols="40" class="typing" id="message"></textarea>
+	<input type="button" onclick="update()" class="ts primary fluid button" value="Send">
+</form>
+</div>
+
 <script>
 
 function refreshPage(){

+ 2 - 0
src/regi.php

@@ -22,6 +22,7 @@ if (filesize("root.inf") > 0){
 $databasePath = $rootPath . "whitelist.config";
 $content = "";
 $regexists = false;
+/*
 if (file_exists($databasePath)){
 	include_once("auth.php");
 	//If the user is able to continues to proceed, that means the user has right to use this system
@@ -30,6 +31,7 @@ if (file_exists($databasePath)){
 }else{
 	//There is no user registration yet. Create one
 }
+*/
 //See if this page is requested for command.
 $errormsg = "";
 if (isset($_POST['act']) && $_POST['act'] != ""){

+ 27 - 0
src/unfollow.php

@@ -0,0 +1,27 @@
+<?php
+include_once(__DIR__ . "/auth.php");
+include_once("requestDB.php");
+echo $sql = "DELETE FROM `following` where followername =  '" . $_SESSION['login'] . "'and targetname =  '" . $_GET["target"] . "'";
+	queryw($sql,"teabag");
+header("Location: fdList.php");
+
+/*
+$conn = mysqli_connect("localhost","root","","message");
+if($conn->connect_error)
+{
+	echo "Unable to connect to database";
+	exit;
+}
+
+//$sql = "INSERT INTO `message` (`user`, `datetime`, `messgae`, `id`) VALUES ('".$_SESSION['login']."', current_timestamp(), '".$_POST[message]."', NULL);";
+
+$stmt = $conn->prepare("INSERT INTO `message` (`user`, `datetime`, `messgae`, `id`) VALUES (?, current_timestamp(),?, NULL);");
+$stmt->bind_param("ss", $_SESSION['login'], $_POST[message]);
+$stmt->execute();
+
+$stmt->close();
+$conn->close();
+
+header("Location: index.php");
+*/
+?>

+ 1 - 0
src/userdata/cookieseeds/1574841740.auth

@@ -0,0 +1 @@
+b5aefe827d903272a394b2f5d82f66b459b73057bcada772906be8fdb98a3ae94883ba547d3144072bfd40b035b8b7fb1801bdd36199f409f1da321ccfb53240

+ 1 - 0
src/userdata/cookieseeds/1574845128.auth

@@ -0,0 +1 @@
+99707cae78a8be5c248361242f45562dde3afc004a6c6cefca6cc28d2fa79830073794e50728dd866e9c98b741d0496167b7340e4afb48f1d966693651e7b861

+ 1 - 0
src/userdata/cookieseeds/1574845983.auth

@@ -0,0 +1 @@
+983cd09d23bf294a414ee00a47651a04a5cc707134593125940c9575d05b0f7a83aa8dc6fa4268bb1590462bec2c296a7835bc733878dae4846a0114838f7e7e

+ 1 - 0
src/userdata/userdata/xxxabc/user/profile/displayname.inf

@@ -0,0 +1 @@
+xxxabc

+ 6 - 0
src/userdata/userdata/xxxabc/userdata.json

@@ -0,0 +1,6 @@
+{"username":"xxxabc",
+	  "accountCreationTime":"1574672328",
+	  "invitedByUser":"Admin",
+	  "permissionLevel":3,
+	  "banned":false
+	}

+ 2 - 0
src/userdata/whitelist.config

@@ -1,2 +1,4 @@
 kent,D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB
 admin,C7AD44CBAD762A5DA0A452F9E854FDC1E0E7A52A38015F23F3EAB1D80B931DD472634DFAC71CD34EBC35D16AB7FB8A90C81F975113D6C7538DC69DD8DE9077EC
+xxxabc,D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB
+xdxd,D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB