From 5e933880cf2896d27dc8208c15cc8f0e8329360c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=B5=E9=96=8E=E5=82=91?= Date: Tue, 31 May 2016 10:59:45 +0800 Subject: [PATCH] Replies implementation(tested on local machine) Changed the icon directory(now under main directory) To do list: -stuff in comment.php aren't exactly aligned --- .DS_Store | Bin 8196 -> 6148 bytes comment.php | 95 ++++++++++++++++++++++ dbconnect.php | 2 + icons/delete.png => delete.png | Bin header.php | 26 ++++++ home.php | 60 +++++++------- search.php | 144 +++++++++++++++------------------ style.css | 44 ++++++---- 8 files changed, 244 insertions(+), 127 deletions(-) create mode 100644 comment.php rename icons/delete.png => delete.png (100%) create mode 100644 header.php diff --git a/.DS_Store b/.DS_Store index 41e1cef57433e5ce703156cc3d5b7a088bb9f409..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 105 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGpJ516q~502;ws^0>w5KPGg_gAhnpCgF}!R pBnTAa1`@77th%xAJM(0I8AV3M$)+;eJWLRCKt?lcj^~-f3;-`E4{!hg literal 8196 zcmeHLUuYaf82`R&n(n0kCTY@KuBINXwSTzkT{LM!wO*2IQf*6vm*kSP8uxCu$>QGb zdAoPlT7nT2MO0K&@I`F=Qz;6*DCmm_TD1r&R%lUQeDg_AAH*lW+1Z4%2 zH~amWnf=XgXZRKXu)m}w0Kx#EP!*D|rsfJo*hO7dLcT^Ak>UZIY{e;LO*^~HH&6r! z1PBBO1PBBO1PELo2+*A^ic;s^m)4*S5C{;sArTPgLzJqJNng%M=^Y)^cqstM22y*4 z`jiKFF;QP8eK{wk7fNHw>;e5y^ivF!;be~rcalk8&Pgf50cAL#KQsCn3VO3sT-0+1 zOiCHF0RjO6%MlQt%}OvJ2R2wW`TIZFf@wHzJboEND;icdu2NVNm32+LdEEo)8M~5p zRk!5ytHop9lcDKZzdx+HGYkC@+cp>bYIe-fD^t96z_wh~u=HY8=<$qUX?CUGE?Js$ zJT1q|7@9jX#oLC9dYM9pRZAZ;93yL(hI@)pQP>pkIDNV+(Hn~<;(KRf(bI`|&mFO7 zcURZ!EdNGPHtp>0J2Fw2eP;g6x88o|?7N?zmoT7zl)#21uzXpIi8-A}=j?o;%Bu=7 z(;-kY;6|J^b<+brcR zvNY#ZGgl&Kz0Wk$#-qA3?&>F9(VKMaqC4O@jvEv!bW^-VU~{zK8n)$(=|zVmW9Qbi zMK*8UvAb)}T^HA`ThCbwYt57ec&0vD5x7pMPENNp!-VdzEHjNh{nOU>&t zsy*Dn_=n1Ijh1u7)`XAdS;Fn%PDME;^aDkmTB&By@D|2ZWyGPS$sx9}?TkBYF?fu52sc2*LzDvnGg|unx<>Y*5nSkqg#`4+2P_6>VO#Rhe4R6Pr`xK7lXbJbVoo;9Ix^m*FS)8GeI5;7|Aq0U0*o8eEGlxCw8<&3H53g1hlH zjAH`#U=sUq08@AvM{x`%a1wK9VjgWQ;A8kSzJRad8+Zoi@jZMWKf+JtszM7i9jYQA zb@4N5YKiFodJAQ)M8wG8hN0B|Ld45!1pS&@Hng_+eC%7?&m~(}%_fgPk|7>*7MS62 zvzCqY#$TVF2Hy2Bm4rt z!td}m5v&n8Zp3zs5Wza}R@{y|aTmt08+&js_ToOG*8v>DgLogNafE1=A);l8XgZ$2 z8GHnb=wb;gIERnp6Zj-PMYMYnU&5F16?}aO;SMe#+}T>f} zZ);bv7G|z?rk2x1%e1X&8gqgCwMz+}t_1=s@{~xIT|NmM{6^s!e5Fl`!B7hC4 zbgG{gSMRVDxptK5LsUf(esfZKA=G&3I7u%ZC+Vl-o^O;~MNHC{b5fFq%76YNAh`d7 L``=^UjothUJpl~? diff --git a/comment.php b/comment.php new file mode 100644 index 0000000..7b66c0a --- /dev/null +++ b/comment.php @@ -0,0 +1,95 @@ +"; +if(isset($_POST['view_reply_parent'])) +{ +$_SESSION['view_reply_parent'] = $_POST['view_reply_parent']; +} +$parent_id = $_SESSION['view_reply_parent']; +if(isset($_POST['submit_comment'])) +{ + try + { + $uid = $_SESSION['user']; + $msg = $_POST['comment']; + $time = date('Y/m/d H:i:s'); + $insert = "INSERT INTO comments(cmt,uid,cmt_time,parent_id) VALUES(?,?,?,?)"; + $stmt = $conn->prepare($insert); + $stmt->bindValue(1,$msg); + $stmt->bindValue(2,$uid); + $stmt->bindValue(3,$time); + $stmt->bindValue(4,$parent_id); + $stmt->execute(); + ?> + + ";//refresh the page + } + catch(Exception $e) + { + die(var_dump($e)); + } +} + +//display the parent message +$sql_select = "SELECT msg_id,msg, username,msg_time,uid + FROM messages, users + WHERE messages.uid = users.user_id AND messages.msg_id = $parent_id"; +$res=$conn->prepare($sql_select); +$res->execute(); +?> + + + + + fetch(PDO::FETCH_OBJ)) + { + echo ""; + echo ""; + echo ""; + echo ""; + } + echo "
MessageByTime
".$row -> msg."".$row -> username."".$row -> msg_time."

"; + +//display the replys to that message + +$sql_select = "SELECT cmt,cmt_id,username,cmt_time + FROM comments + INNER JOIN messages ON $parent_id=comments.parent_id AND parent_id = messages.msg_id + INNER JOIN users ON users.user_id = comments.uid + ORDER BY cmt_time DESC "; +$res=$conn->prepare($sql_select); +$res->execute(); +if($res->rowCount()!=0) +{ +?> + + + + + fetch(PDO::FETCH_OBJ)) + { + echo ""; + echo ""; + echo ""; + echo ""; + } + echo "
RepliesByTime
".$row -> cmt."".$row -> username."".$row -> cmt_time."
"; +} +else +{ + echo "
"; + echo "

No replies here

"; + echo "
"; +} +?> +
+ + "; ?> +
+ +
+
+Go Back \ No newline at end of file diff --git a/dbconnect.php b/dbconnect.php index 0b25f09..b83133a 100644 --- a/dbconnect.php +++ b/dbconnect.php @@ -1,9 +1,11 @@ setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);//sql injection prevention } catch(Exception $e){ die(var_dump($e)); diff --git a/icons/delete.png b/delete.png similarity index 100% rename from icons/delete.png rename to delete.png diff --git a/header.php b/header.php new file mode 100644 index 0000000..ec7293f --- /dev/null +++ b/header.php @@ -0,0 +1,26 @@ + + + + + +Welcome - <?php echo $userRow['email']; ?> + + + + \ No newline at end of file diff --git a/home.php b/home.php index dba0b0c..9dad9a4 100644 --- a/home.php +++ b/home.php @@ -1,8 +1,5 @@ query($sql_select); $userRow=$res->fetch(PDO::FETCH_BOTH); -if(isset($_POST["delete_action"])) +if(isset($_POST["delete_action"]))//deleting message part { if($_POST["delete_action"]=="delete") { @@ -25,9 +22,6 @@ $stmt = $conn->prepare($sql_del); $stmt->bindValue(1,$_POST["del_msg_id"]); $stmt->execute(); - ?> - - - - - - -Welcome - <?php echo $userRow['email']; ?> - - - -

Bulletin Board

@@ -81,6 +57,7 @@ By Time Delete + Replies fetch(PDO::FETCH_OBJ)) { @@ -95,20 +72,43 @@ "; + echo ""; + } + else + { + echo ""; + echo "
"; + echo ""; + echo "
"; + } + } echo ""; } @@ -141,7 +141,7 @@ ?> "; + echo "";//refresh the page } catch(Exception $e) { diff --git a/search.php b/search.php index 7f445d0..e8116bb 100644 --- a/search.php +++ b/search.php @@ -1,95 +1,79 @@ - - - - -Welcome - <?php echo $userRow['email']; ?> - - - - -
- Search Results of '".$_POST['message_target']."'"; - ?> -
- -query($sql_search); - if(count($result) > 0) - { - ?> - - - - - - fetch(PDO::FETCH_OBJ)) + echo "
"; + echo "

Search Results of '".$_POST['message_target']."'

"; + echo "
"; + try { - echo ""; - echo ""; - echo ""; - if($_SESSION['user']==$row->uid) + $sequence = '%'.$_POST['message_target'].'%'; + $search = "SELECT msg_id,msg, username,msg_time,uid + FROM messages, users + WHERE messages.uid = users.user_id AND msg LIKE ? + ORDER BY `messages`.`msg_time` DESC"; + $stmt = $conn->prepare($search); + $stmt->bindValue(1,$sequence,PDO::PARAM_STR); + $stmt->execute(); + if($stmt->rowCount()!=0) { - ?> - - + echo "
"; + echo "

".$stmt->rowCount()." results:

"; + echo "
"; + ?> +
MessageByTimeDelete
".$row -> msg."".$row -> username."".$row -> msg_time." -
-
+ + + + fetch(PDO::FETCH_OBJ)) + { + echo ""; + echo ""; + echo ""; + if($_SESSION['user']==$row->uid) + { + ?> + + + "; + } + } + echo "
MessageByTimeDelete
".$row -> msg."".$row -> username."".$row -> msg_time." +
+
"; } - else + else { - echo ""; + echo "
"; + echo "

No results!
Please review your input !

"; + echo "
"; } } - echo ""; + catch(Exception $e) + { + die(var_dump($e)); + } } else { - echo "No message here ! be the first !"; -} - - } - catch(Exception $e) - { - die(var_dump($e)); - } + echo "
"; + echo "

Error on search !
Please make sure that you had entered a valid input !

"; + echo "
"; } ?> Go Back \ No newline at end of file diff --git a/style.css b/style.css index 3c382bf..f6fec3c 100644 --- a/style.css +++ b/style.css @@ -147,17 +147,16 @@ textarea#msg_search_box{ } button#msg_submit{ border: 2px solid #fafafa; -width: 20%; - margin-left:40px; - height:45px; - background:#3e94ec; - background:-moz-linear-gradient(top, #595959 , #515151); - border-radius:3px; - color:#f9f9f9; - font-family:Verdana, Geneva, sans-serif; - font-size:18px; - font-weight:bolder; - text-transform:uppercase; +width: 30%; +height:45px; +background:#3e94ec; +background:-moz-linear-gradient(top, #595959 , #515151); +border-radius:3px; +color:#f9f9f9; +font-family:Verdana, Geneva, sans-serif; +font-size:25px; +font-weight:bolder; +text-transform:uppercase; } button#msg_search{ border: 2px solid #fafafa; @@ -173,7 +172,20 @@ button#msg_search{ font-weight:bolder; text-transform:uppercase; } - +button#view_replies +{ + border:0; + font-size: 25px; + color:#4e5066; + background: transparent; +} +button#view_replies:hover +{ + border:0; + font-size: 25px; + color:#fafafa; + background: transparent; +} /* css for home page */ /* imported table style */ @@ -191,7 +203,7 @@ body { div.table-title { display: block; margin-left:40px; - max-width: 600px; + max-width: 1000px; padding:5px; width: 100%; } @@ -203,7 +215,6 @@ div.table-title { font-style:normal; font-family: "Roboto", helvetica, arial, sans-serif; text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); - text-transform:uppercase; } @@ -213,7 +224,6 @@ div.table-title { background: white; border-radius:3px; border-collapse: collapse; - height: 320px; margin-left:40px; width: 70%; padding:5px; @@ -228,7 +238,7 @@ th { border-right: 1px solid #343a45; font-size:23px; font-weight: 100; - padding:24px; + padding:10px; text-align:left; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); vertical-align:middle; @@ -345,7 +355,7 @@ button#del_btn } a#back_to_home { - margin-left: 40px; + margin-left: 45px; color: #fafafa; font-size: 30px; font-weight: 400;