forked from igoryen/Tarboz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
697 lines (614 loc) · 27.4 KB
/
header.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<?php
require_once("config.php");
// echo "dirname DOCUMENT_ROOT: " . dirname($_SERVER['DOCUMENT_ROOT']) . "<br>";
// echo "dirname __FILE__ " . dirname(__FILE__) . "<br>";
// echo "basename __FILE__ : " . basename(__FILE__) . "<br>";
// //$pathInPieces = explode('/', dirname($_SERVER['SCRIPT_NAME']));
// echo "dirname SCRIPT_NAME: " . dirname($_SERVER['SCRIPT_NAME']) . "<br>";
// $pathInPieces = explode('\\', dirname(__FILE__));
// $root = "/" . $pathInPieces[3];
require_once BUSINESS_DIR_USER. 'User.php';
require_once BUSINESS_DIR_USER_LOGIN . 'UserLoginManager.php';
session_start();
$user = isset($_SESSION['user']) ? $_SESSION['user'] : "";
//echo $user->getFirstName();
//echo $_SESSION['user']->getFirstName();
?>
<html>
<head>
<meta charset="UTF-8">
<!--search bar keyboard -->
<link rel="stylesheet" type="text/css" href="plug-in/virtual_keyboard/keyboard.css">
<script type="text/javascript" src="plug-in/virtual_keyboard/keyboard.js" charset="UTF-8"></script>
<!-- End -->
<link rel="stylesheet" type="text/css" href="style/css/style.css"/>
<link rel="shortcut icon" href="images/watermelon8.png"/>
<!-- Extra libraries -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="plug-in/translate/js/jquery.ajaxLoader.js" type="text/javascript"></script>
<script src="plug-in/translate/js/json-jquery.js" type="text/javascript"></script>
<script src="plug-in/translate/js/json-jquery2.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script>
$(document).ready(function(){
//adding a link of forgot pasword the the dialogue box
document.getElementById("forgotpwd").innerHTML="<a href='#'>Forgot Password</a>";
$("#forgotdiv").hide();
//var log_div =document.getElementById("call_it").innerHTML;
$( "#login" ).dialog({ autoOpen: false });
$( "#call_it" ).click(function() {
$("#forgotpwd").show();
//resetting, some of the usertexboxes and the messages
document.getElementById("ftest").innerHTML="";
$('#userlogin').val('');
$('#userpassword').val('');
//resetting the texboxes
if(document.getElementById("call_it").innerHTML=="Login"){
$( "#login" ).dialog( "open" );
}
else{
document.getElementById("call_it").innerHTML="Login";
document.getElementById("user_name").innerHTML="";
window.location="user_test/logout.php";
}
//display profile menu when user login
if($('#user_name').html() =="") {
$('#menu_user_index').css({'display': 'none'});
}
});//end if call_it onlick event
$("#forgotpwd").click(function(){
$("#forgotdiv").show();
$("#login_form").hide();
}); //end of forgotpwd onlick event function
$("#sub").click(function(){
//To keep count of the number of times, requested
$.post("user_test/login.php",
{
userid: $("#userlogin").val(),
password: $("#userpassword").val(),
},
function(data,status){
//this sets the session variable of username inside the variable username
//var username="<?php if(isset($_SESSION['user'])) echo $_SESSION['user']->getFirstName(); ?>"
if(data==1 || data==2){
document.getElementById("ftest").innerHTML="<?php echo LOGIN_SUCCESS; ?>";
document.getElementById("forgotpwd").innerHTML="";
//When username and password is right it will change the text to Logout
document.getElementById("call_it").innerHTML="Logout";
//When Successful it will print the user's name beside the logout
//document.getElementById("user_name").innerHTML=username;
//display profile menu when user login
$('#menu_user_index').css({'display': ''});
//When logged in successful, it will close the window
$( "#login" ).dialog("close");
window.location.reload(true);
}
else {
document.getElementById("ftest").innerHTML="<?php echo LOGIN_FAIL; ?>";
}
});//end of the function(data,status)
});//end of the login button onlick event
$("#new_commentSub").click(function(event){
//var formdata = $("#new_comment").serialize();
//alert(formdata);
if ($('#user_login_status').val() == "N") {
} //end if ($('#user_login_status').val() == "N")
else {
var new_comment = encodeURIComponent($.trim ($('#newComment').val() ));
var comment_entity_id = encodeURIComponent($.trim ($('#commentEntityId').val() ));
$.ajax({
url: "user_test/new_comment.php",
type: "POST",
data: {
newComment: new_comment,
commentEntityId: comment_entity_id
},
success:
function(data, status) {
//alert(data);
if (data.indexOf('succeed') >0) {
$('#add_comment_result').html=$.trim ($('#newComment').val() );
} else if (data.indexOf( 'fail') >0) {
alert(data);
}
window.location.reload(true);
},
error:
function() {
alert("ajax error");
}
}); //end $.ajax()
event.preventDefault();
} //end else
});
$(".editCommentSub").click( function(event) { //edit comment
var this_id = $(this).attr('id');
var edit_id_num = this_id.substring(this_id.indexOf("_")+1);
var textarea_id = "#editCommentText_"+edit_id_num;
var input_hidden_id = "#editCommentId_"+edit_id_num;
//alert("edit id:"+edit_id_num);
//alert("textarea_id: "+textarea_id);
//alert("input_hidden_id: "+input_hidden_id);
//alert("edit comment text: "+$(textarea_id).val());
//alert("edit comment id: "+$(input_hidden_id).val());
var editCommentData = encodeURIComponent($.trim ($(textarea_id).val() ));
var editCommentId = encodeURIComponent($(input_hidden_id).val());
$.ajax({
url: "user_test/edit_comment.php",
type: "POST",
cache: false,
data:
{
editComment : editCommentData,
editCommentId: editCommentId
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
location.reload(true);
} else if (data.indexOf("fail") >0) {
alert(data);
}
}, //end of function(data, status) and success function
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('.deleteComment').click( function (event) {
var delete_comment_id = $(this).attr('id');
//alert("delete comment id: "+delete_comment_id);
var delete_id = delete_comment_id.substring(delete_comment_id.indexOf("_")+1);
//alert("delete id: "+delete_id);
$.ajax({
url: "user_test/delete_comment.php",
type: "POST",
data:
{
deleteCommentId : delete_id
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
location.reload(true);
} else if (data.indexOf("fail") >0) {
alert(data);
}
}, //end of function(data, status) and success function
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('.comment_like').click( function (event) {
//$(this).css({'display': 'none'});
//$(this).next().css({'display': ''})
var this_id = $(this).attr('id');
var user_id = this_id.substring(0,this_id.indexOf("_")); //alert("user id: "+user_id);
var comment_id = this_id.substring(this_id.lastIndexOf("_")+1); //alert("comment id: "+comment_id);
var is_like = "";
//alert("inner text: "+$(this).text());
if($(this).text().trim() == "Like" ){
is_like = "Y";
$(this).text("Unlike");
} else if ($(this).text().trim() == "Unlike") {
is_like = "N";
$(this).text("Like");
}
$.ajax({
url: "user_test/comment_rating.php",
type: "POST",
data: {
commentId : comment_id,
userId : user_id,
isLike : is_like
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
} else if (data.indexOf("fail") >0){
alert(data);
}
},
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('.reportComment').click( function(event) {
if ($(this).next().css('display') == 'none') {
$(this).next().css({'display': 'block'});
} else if ($(this).next().css('display') == 'block') {
$(this).next().css({'display': 'none'});
}
var this_id = $(this).attr('id');
var user_id = this_id.substring(0,this_id.indexOf("_"));
var comment_id = this_id.substring(this_id.lastIndexOf("_")+1);
});
$('button.reportCommentSub').click( function(event) { //add a report
var this_id = $(this).attr('id');
var entity_id = this_id.substring(this_id.indexOf("_")+1);
var entity_for_report = "comment";
var textarea_id = "#reportCommentReason_"+entity_id;
var hidden_id = "#reportCommentBy_"+entity_id;
var report_reason = encodeURIComponent($.trim ($(textarea_id).val() ));
var reported_by = encodeURIComponent($(hidden_id).val()); //alert("reported by: "+reported_by);
$.ajax({
url: "user_test/reporting_comment.php",
type: "POST",
data: {
entityId : entity_id,
entityForReport : entity_for_report,
reportReason : report_reason,
reportedBy: reported_by
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
if(data.indexOf("error")>0 ) {
alert("Mailer error! ");
}
location.reload(true);
} else if (data.indexOf("fail") >0){
alert(data);
}
},
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('button.reportCommentCancel').click( function(event) {
$('.reportComment').next().css({'display': 'none'});
});
$('.entry_like').click( function (event) {
$(this).next().css({'display': 'none'});
$('.entry_dislike').css({'display': 'none'});
//$(this).next().css({'display': ''})
var this_id = $(this).attr('id');
var user_id = this_id.substring(0,this_id.indexOf("_")); //alert("user id: "+user_id);
var entry_id = this_id.substring(this_id.lastIndexOf("_")+1); //alert("entry id: "+entry_id);
var is_like = "";
//alert("inner text: "+$(this).text().trim());
if($(this).text().trim().indexOf("Like") >=0 ){
is_like = "Y";
$(this).text("Unlike");
var like_num = parseInt($('.entry_like_num').html().trim())+1; //alert(like_num);
$('.entry_like_num').text(like_num+" ");
if (parseInt($('.entry_dislike_num').text().trim()) > 0) {
var dislike_num = parseInt($('.entry_dislike_num').text().trim())-1;
$('.entry_dislike_num').text(dislike_num+" ");
}
//$('.entry_like_num').css({'display': 'none'});
} else if ($(this).text().trim() == "Unlike") {
is_like = "N";
$(this).text("Like");
var like_num = parseInt($('.entry_like_num').html().trim())-1; //alert(like_num);
$('.entry_like_num').text(like_num+" ");
var dislike_num = parseInt($('.entry_dislike_num').text().trim())+1;
$('.entry_dislike_num').text(dislike_num+" ");
//$('.entry_like_num').css({'display': ''});
}
$.ajax({
url: "user_test/entry_rating.php",
type: "POST",
data: {
entryId : entry_id,
userId : user_id,
isLike : is_like
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
} else if (data.indexOf("fail") >0){
alert(data);
}
},
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('.entry_dislike').click( function (event) {
$(this).prev().css({'display': 'none'});
$(this).css({'display': 'none'});
var this_id = $(this).attr('id');
var user_id = this_id.substring(0,this_id.indexOf("_")); //alert("user id: "+user_id);
var entry_id = this_id.substring(this_id.lastIndexOf("_")+1); //alert("entry id: "+entry_id);
var is_like = "";
is_like = "N";
//alert("=="+$('.entry_dislike_num').text().trim()+"==");
var dislike_num = 0;
if ($('.entry_dislike_num').text().trim() != "") {
dislike_num = parseInt($('.entry_dislike_num').text().trim())+1;
} else {
dislike_num++;
}
$('.entry_dislike_num').text(dislike_num+" ");
$.ajax({
url: "user_test/entry_rating.php",
type: "POST",
data: {
entryId : entry_id,
userId : user_id,
isLike : is_like
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
} else if (data.indexOf("fail") >0){
alert(data);
}
},
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
//==========Report Entry start=========
$('.reportEntry').click( function(event) {
if ($(this).next().css('display') == 'none') {
$(this).next().css({'display': 'block'});
} else if ($(this).next().css('display') == 'block') {
$(this).next().css({'display': 'none'});
}
var this_id = $(this).attr('id');
var user_id = this_id.substring(0,this_id.indexOf("_"));
var entry_id = this_id.substring(this_id.lastIndexOf("_")+1);
});
$('button.reportEntrySub').click( function(event) { //add a report
var this_id = $(this).attr('id');
var entity_id = this_id.substring(this_id.indexOf("_")+1);
var entity_for_report = "entry";
var textarea_id = "#reportEntryReason_"+entity_id;
var hidden_id = "#reportEntryBy_"+entity_id;
var report_reason = encodeURIComponent($.trim ($(textarea_id).val() ));
var reported_by = encodeURIComponent($(hidden_id).val()); //alert("reported by: "+reported_by);
$.ajax({
url: "user_test/reporting_entry.php",
type: "POST",
data: {
entityId : entity_id,
entityForReport : entity_for_report,
reportReason : report_reason,
reportedBy: reported_by
},
success:
function(data, status) {
//alert(data);
if(data.indexOf("succeed")>0) {
if(data.indexOf("error")>0 ) {
alert("Mailer error! ");
}
location.reload(true);
} else if (data.indexOf("fail") >0){
alert(data);
}
},
error:
function() {
alert("ajax error");
}
});//end $.ajax()*/
event.preventDefault();
});
$('button.reportEntryCancel').click( function(event) {
$('.reportEntry').next().css({'display': 'none'});
});
if($('#user_name').text().trim() !="" && $('#regSuccessMsg').text().indexOf("Thank you for activating your account")>=0) {
window.location.href = "index.php";
}
$('#newComment').focus( function(event) {
//call login panel
$("#forgotpwd").show();
//resetting, some of the usertexboxes and the messages
document.getElementById("ftest").innerHTML="";
$('#userlogin').val('');
$('#userpassword').val('');
//alert("1"+$("#call_it").html());
//resetting the texboxes
if($.trim($("#call_it").html())=="Login"){
$( "#login" ).dialog( "open" );
//alert("use not logged in");
}
//alert("username innerHtml: "+$('#user_name').html());
if($('#user_name').html() =="") {
$('#menu_user_index').css({'display': 'none'});
}
});
//subscribe and unsubscribe
$("#subscribeDialog").dialog({
autoOpen: false
});
$("#subscribeLink").click( function(event) {
$( "#subscribeDialog" ).dialog("open");
});
$("#unsubscribeLink").click( function(event) {
$( "#unsubscribeDialog" ).dialog("open");
});
$("#unsubscribeDialog").dialog({
autoOpen: false
});
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w]{1,4})*$/;
$("#sub_email_id").keydown(function(){
//comparing the above regex to the value in the texbox, if not from the box then send error
if(!emailReg.test($("#sub_email_id").val().trim())){
//fill the textbox label with error
document.getElementById("sub_error").innerHTML="<font color='red' size='2px' family='verdana'>invalid Email</font>";
$("#sub_email").css("border-color","rgba(255,0,0,.6)");
//Disable submit button
$('#submitbtn').prop('disabled', true);
}
else{
document.getElementById("sub_error").innerHTML="<font color='red' size='2px' family='verdana'></font>";
$("#sub_email").css("border-color","rgba(255,0,0,.6)");
//Disable submit button
$('#submitbtn').prop('disabled', false);
}
});
$("#usub_email_id").keydown(function(){
//comparing the above regex to the value in the texbox, if not from the box then send error
if(!emailReg.test($("#usub_email_id").val())){
//fill the textbox label with error
document.getElementById("usub_error").innerHTML="<font color='red' size='2px' family='verdana'>invalid Email</font>";
$("#sub_email").css("border-color","rgba(255,0,0,.6)");
//Disable submit button
$('#usubmitbtn').prop('disabled', true);
}
else{
document.getElementById("usub_error").innerHTML="<font color='red' size='2px' family='verdana'></font>";
$("#usub_email").css("border-color","rgba(255,0,0,.6)");
//Disable submit button
$('#usubmitbtn').prop('disabled', false);
}
});
});
</script>
<script src="treqCreate.js"></script>
<script src="entryDelete.js"></script>
<script src="questionMarkTooltips.js"></script>
<!-- for translator -->
<style>
div.jquery-ajax-loader {
background: #FFFFFF url(img/ajax-loader.gif) no-repeat 50% 50%;
opacity: .6;
width:250px !important;
}
div.showdata{
width:250px;
}
.bgblack{
background: white
}
.bgwhite {
background: #FFFFFF
}
.black {
color:black;
}
.pl10{
padding-left:10px;
}
.width500 {
width:500px;
}
.bdr {
border:1px solid black;
}
</style>
<title>Tarboz</title>
</head>
<body>
<div class="wrapper">
<div>
<input type="hidden" id="direct_create_entry" name="direct_create_entry" value="N" />
</div>
<div id="header">
<div class="header_row">
<div class="table-cell" style="text-align: left; vertical-align: text-top;">
<a href="index.php"><img src="images/logo.png" height="50"></a><br/>
<nav id="navigation">
<a href="index.php" >Home</a> <br/><br/>
<?php if(!isset($_SESSION['user']) ) { ?>
<a href="registration.php">Register</a>
<?php } ?>
<a href="entrycreate.php" id="menu_create_entry" style="display:<?php if(!isset($_SESSION['user']) ) echo 'none'; else echo ''; ?>;">Create an Entry</a><br/><br/>
<!--
<a href="profile.php">Profile</a>
<a href="/Tarboz/userview.php">[user view 2]</a>
-->
<!-- display profile menu when user login -->
<a href="profile.php" style="display:<?php if(!isset($_SESSION['user']) ) echo 'none'; else echo ''; ?>;" id="menu_user_index">Profile</a>
</nav>
</div>
<div class="table-cell" style="width:1000;">
<!--Search bar start-->
<?php require("search.php");?>
<!--Search bar end-->
</div>
<div class="table-cell" style="vertical-align: top;">
<div class="table-row" style="padding-top:3px;">
<button id="call_it" class="login_button"><?php if(!isset($_SESSION['user']) ) { ?>Login<?php } else { ?>Logout<?php } ?></button>
</div>
<div id="user_name" class="table-row" style="padding-top:5px; font-size: 12px;">
<?php
if(isset($_SESSION['user']) ) {
echo "Welcome <a href='profile.php'>".$_SESSION['user']->getFirstName()."</a> !";
}else{
echo "";
}?>
</div>
</div>
<div style="width:100px;" title="Login Window" id="login">
<!--start of the login form div-->
<div id="login_form">
<p>
<input type="text" id="userlogin" placeholder="Username" class="login_input">
</p>
<p>
<input type="password" id="userpassword" placeholder="Password" class="login_input">
</p>
<p>
<div style="margin-left: 0.7em;">
<button class="lw_button" id="sub">Login</button>
<b id="or">or</b>
<a href="registration.php">
<button class="lw_button">Register</button>
</a>
</div>
</p>
<p id="ftest"></p>
<p style="margin-left: 1em;" id="forgotpwd"></p>
</div>
<!---forgot password window-->
<div id="forgotdiv">
Email Address <input type="text" id="forgotemail">
<button id="forgotbtn">Forgot</button>
<p>Please type the email address associated with your account in the above box</p>
</div>
</div>
<!-- <div id="links"><a href="/Tarboz/Views/Login/Index.php">Login</a></div>-->
<!-- A section for resetting the forgot password -->
<?php
//$_GET['security']="0vLalqY93y";
//If the security variable has something, then assign it otherwise keep the variable empty
$reset=(isset($_GET['security']))?$_GET['security']:"";
//Pattern to avoid some weird hackers
$m_reg="/^[a-zA-Z0-9\.\@\(\)]+$/";
//matchin the pattern and checking if the variable is also not empty
if(($reset!="") && preg_match($m_reg,$reset)){
echo $reset;
$userLoginManager = new UserLoginManager();
$logged = $userLoginManager->getLoginReset($reset);
}
if (isset($logged)) {
echo "sent";
}
else {
//echo "fail";
}
?>
</div>
</div><!--"header"-->
<br />