-
Notifications
You must be signed in to change notification settings - Fork 4
/
profile.php
994 lines (751 loc) · 44.9 KB
/
profile.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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
<?php
ob_start();
session_start();
$title = "Profile";
include 'init.php';
$do = isset($_GET['do']) ? $_GET['do'] : 'show';
$userID = isset($_GET['userID']) && is_numeric($_GET['userID']) ? intval($_GET['userID']):0 ;
if($do == "show"){
$getUser = $conn->prepare("SELECT * FROM users WHERE userID = ?");
$getUser->execute(array($userID));
$info = $getUser->fetch();
$count = $getUser->rowCount();
if($count > 0){
if($_SERVER["REQUEST_METHOD"] == "POST"){
$user = $_SESSION["id"];
$target = $info["userID"];
$value = $_POST["rate"];
$check = getAllFrom("*","rating","WHERE user = $user AND target = $target");
if(count($check) == 0){
$stmt = $conn->prepare("INSERT INTO rating (user, target, value) VALUES (:zuser, :ztarget, :zval)");
$stmt->execute(array(
"zuser" => $user,
"ztarget" => $target,
"zval"=> $value,
));
}
else{
$stmt = $conn->prepare("UPDATE rating SET value = $value WHERE user = $user AND target = $target");
$stmt->execute();
}
}
?>
<div class="w3-container w3-margin-bottom w3-margin" style="min-height: -webkit-fill-available;">
<?php
if(isset($_SESSION["success"]) && !empty($_SESSION["success"])){ ?>
<div class="success-msg w3-margin w3-center">
<?php
echo $_SESSION["success"];
$_SESSION["success"] = "";
?>
</div>
<?php } ?>
<!-- The Grid -->
<div class="w3-row">
<!-- Left Column -->
<div class="w3-col m3 w3-margin-bottom">
<!-- Profile -->
<div class="w3-card w3-round w3-white">
<div class="w3-container info-panel">
<h4 class="w3-center w3-text-dark-grey"><?php echo $info["username"] ?></h4>
<p class="w3-center">
<?php
if(!empty(trim($info["image"]))){
echo "<img class='w3-border w3-circle' src='uploads/profile_pictures/" . $info["image"] . "' style='height:106px;width:106px; cursor:pointer' alt='Avatar' onclick='onClick(this)' />";
}
else {
echo "<img class='w3-circle' src='uploads/profile_pictures/user.png' style='height:106px;width:106px' alt='' />";
}
?>
</p>
<?php
if(isset($_SESSION["id"])){
if($_SESSION["id"] != $info["userID"]){
?>
<div class="w3-container">
<div class="w3-center w3-margin-bottom">
<a href="messages.php?target=<?php echo $info["username"] ?>" class="w3-button w3-teal w3-round"><i class="fa fa-fw fa-paper-plane"></i>Message</a>
</div>
<div class="w3-center">
<?php $user1 = $info["userID"];
$user2 = $_SESSION["id"];
$flist = getAllFrom("*","follower","WHERE followerID = '$user2' AND userID = '$user1'");
if(count($flist) > 0){
echo '<a href="' . $func . 'update.php?u=unsub&userID=' . $user1 . '&followerID=' . $user2 . '" class="w3-button w3-light-grey w3-text-teal w3-round">' . lang("UNSUB") .'</a>';
}
else{
echo '<a href="' . $func . 'update.php?u=sub&userID=' . $user1 . '&followerID=' . $user2 . '" class="w3-button w3-teal w3-round">' . lang("SUBSCRIBE") .'</a>';
}
?>
</div>
</div>
<?php
}
}
else {
echo "<div class='w3-center alert alert-info'>";
echo "<a href='login.php' >" . lang("LOG-OR-SIGN") . "</a>";
echo "</div>";
}
?>
<hr>
<p class="w3-text-dark-grey">
<i class="fa fa-id-card fa-fw w3-margin-right w3-text-theme w3-darkcyan"></i>
<strong>
<?php
if(!empty(trim($info["fullname"])))
echo $info["fullname"];
?>
</strong>
</p>
<p class="w3-text-dark-grey">
<i class="fa fa-home fa-fw w3-margin-right w3-darkcyan"></i>
<strong>
<?php
if(!empty(trim($info["wilaya"])))
echo $info["wilaya"];
?>
</strong>
</p>
<p class="w3-text-dark-grey">
<i class="fa fa-birthday-cake fa-fw w3-margin-right w3-darkcyan"></i>
<strong>
<?php
if(!empty(trim($info["birthDate"]) && $info["birthDate"] != "0000-00-00" ))
echo date("d-m-Y",strtotime($info["birthDate"]));
?>
</strong>
</p>
<p class="w3-text-dark-grey">
<i class="fa fa-phone fa-fw w3-margin-right w3-darkcyan"></i>
<strong>
<?php
if(!empty(trim($info["telephone"]) && $info["telephone"] != "0" ))
echo $info["telephone"];
?>
</strong>
</p>
<?php
if(isset($_SESSION["id"])){
if($_SESSION["id"] == $info["userID"]){
echo '<a class="w3-button w3-round w3-teal edit-btn w3-center" style = "margin-bottom: 10px;padding: 5px; display" href="profile.php?do=modify&userID='.$_SESSION["id"].'">'. lang("EDIT2") .'</a>';
}
}
$stmt = $conn->prepare("SELECT follower.*, users.username as user, users.image as img FROM follower INNER JOIN users ON users.userID = follower.userID WHERE follower.followerID = ? ORDER BY follower.follow_date DESC");
$stmt-> execute(array($info["userID"]));
$following = $stmt->fetchAll();
$folCount1 = $stmt->rowCount();
?>
</div>
</div>
<br>
<!-- Accordion -->
<div class="w3-card w3-round">
<div class="w3-white">
<button onclick="myFunction('Demo1')" class="w3-button w3-block w3-teal w3-left-align"><?php echo lang("FOLLOWERS") . " ( " . $folCount1 . " )" ?>
</button>
<div id="Demo1" class="w3-hide w3-container" style="padding:10px;">
<?php
if(!empty($following)){
foreach($following as $follower){
echo "<a class='w3-margin-bottom' href='profile.php?do=show&userID=".$follower["userID"] . "' style='text-decoration: none; margin-bottom:10px;'>";
if(!empty(trim($follower["img"]))){
echo '<img src="uploads/profile_pictures/' . $follower["img"] .'" class="w3-left w3-circle w3-margin-right" style="width:20px; height:20px;">';
}
else {
echo "<img src='uploads/profile_pictures/user.png' alt='' class='w3-left w3-circle w3-margin-right' style='width:20px' />";
}
echo '<span class="w3-large">'. $follower["user"] . '</span><br>';
echo "</a>";
?>
<?php }
}
$stmt = $conn->prepare("SELECT follower.*, users.username as user, users.image as img FROM follower INNER JOIN users ON users.userID = follower.followerID WHERE follower.userID = ? ORDER BY follower.follow_date DESC");
$stmt-> execute(array($info["userID"]));
$following = $stmt->fetchAll();
$folCount2 = $stmt->rowCount();
?>
</div>
<button onclick="myFunction('Demo2')" class="w3-button w3-block w3-teal w3-left-align"><?php echo lang("FOLLOWING") . " ( " . $folCount2 . " )" ?></button>
<div id="Demo2" class="w3-hide w3-container" style="padding:10px;">
<?php
if(!empty($following)){
foreach($following as $follower){
echo "<a href='profile.php?do=show&userID=".$follower["followerID"] . "' style='text-decoration: none; margin-bottom:3px;'>";
if(!empty(trim($follower["img"]))){
echo '<img src="uploads/profile_pictures/' . $follower["img"] .'" class="w3-left w3-circle w3-margin-right" style="width:20px; height:20px;">';
}
else {
echo "<img src='uploads/profile_pictures/user.png' alt='' class='w3-left w3-circle w3-margin-right' style='width:20px' />";
}
echo '<span class="w3-large">'. $follower["user"] . '</span><br>';
echo "</a>";
?>
<?php }
} ?>
</div>
<button onclick="myFunction('Demo3')" class="w3-button w3-block w3-teal w3-left-align"><?php echo lang("RATING") . " ( " . countItems("*","rating",true,"target",$info["userID"]) . " )" ?></button>
<div id="Demo3" class="w3-hide w3-container w3-center" style="padding:10px;">
<?php
$average = getAverage($info["userID"]);
if($average["average"] != 0.0000){
?>
<span class="fa fa-star <?php if($average["average"] >= 1) echo "checked" ?> "></span>
<span class="fa fa-star <?php if($average["average"] >= 2) echo "checked" ?>"></span>
<span class="fa fa-star <?php if($average["average"] >= 3) echo "checked" ?>"></span>
<span class="fa fa-star <?php if($average["average"] >= 4) echo "checked" ?>"></span>
<span class="fa fa-star <?php if($average["average"] == 5) echo "checked" ?>"></span>
<br>
<p><?php echo number_format((float)$average["average"], 2) . " " . lang("AVERAGE-MSG") . " " . count(getAllFrom("*","rating","WHERE target = ". $info["userID"])) . " " . lang("REVIEWS") ?>.</p>
<div class="w3-row w3-nowrap">
<div class="w3-quarter">
<div>5 <span class="w3-hide-medium"><?php echo lang("STAR") ?></span></div>
</div>
<div class="w3-half">
<div class="bar-container">
<div class="bar-5 w3-teal" style="width:<?php echo (int)(countValues($info["userID"], 5))/count(getAllFrom("*","rating","WHERE target = ". $info["userID"]))*100 ?>%"></div>
</div>
</div>
<div class="w3-quarter">
<div><?php echo countValues($info["userID"], 5) ?></div>
</div>
<div class="w3-quarter">
<div>4 <span class="w3-hide-medium"><?php echo lang("STAR") ?></span></div>
</div>
<div class="w3-half">
<div class="bar-container">
<div class="bar-4 w3-green" style="width:<?php echo (int)(countValues($info["userID"], 4))/count(getAllFrom("*","rating","WHERE target = ". $info["userID"]))*100 ?>%"></div>
</div>
</div>
<div class="w3-quarter">
<div><?php echo countValues($info["userID"], 4) ?></div>
</div>
<div class="w3-quarter">
<div>3 <span class="w3-hide-medium"><?php echo lang("STAR") ?></span></div>
</div>
<div class="w3-half">
<div class="bar-container">
<div class="bar-3 w3-blue" style="width:<?php echo (int)(countValues($info["userID"], 3))/count(getAllFrom("*","rating","WHERE target = ". $info["userID"]))*100 ?>%"></div>
</div>
</div>
<div class="w3-quarter">
<div><?php echo countValues($info["userID"], 3) ?></div>
</div>
<div class="w3-quarter">
<div>2 <span class="w3-hide-medium"><?php echo lang("STAR") ?></span></div>
</div>
<div class="w3-half">
<div class="bar-container">
<div class="bar-2" style="width:<?php echo (int)(countValues($info["userID"], 2))/count(getAllFrom("*","rating","WHERE target = ". $info["userID"]))*100 ?>%"></div>
</div>
</div>
<div class="w3-quarter">
<div><?php echo countValues($info["userID"], 2) ?></div>
</div>
<div class="w3-quarter">
<div>1 <span class="w3-hide-medium"><?php echo lang("STAR") ?></span></div>
</div>
<div class="w3-half">
<div class="bar-container">
<div class="bar-1 w3-red" style="width:<?php echo (int)(countValues($info["userID"], 1))/count(getAllFrom("*","rating","WHERE target = ". $info["userID"]))*100 ?>%"></div>
</div>
</div>
<div class="w3-quarter">
<div><?php echo countValues($info["userID"], 1) ?></div>
</div>
</div>
<?php
}
else {
echo "<div class='alert alert-danger w3-center'>" . lang("NO-RATING") . "</div>";
}
?>
<?php
if(isset($_SESSION["username"])){
if($_SESSION["id"] != $info["userID"]){
?>
<a href="javascript:void(0)" class="w3-margin w3-small w3-teal w3-left w3-button w3-round" onclick="document.getElementById('id01').style.display='block'">
<i class="fa fa-star"></i>
<?php echo lang("RATE") ?>
</a>
<?php
}
}
?>
</div>
</div>
</div>
<br>
<!-- Interests -->
<div class="w3-card w3-round w3-white w3-hide-small">
<div class="w3-container">
<p class="w3-center"><?php echo lang("INTERESTS") ; ?></p>
<p>
<?php
$interests = explode(" ",$info["interests"]);
if(!empty(trim($info["interests"]))){
foreach($interests as $interest){
if(!empty(trim($interest))){
$interest = strtolower($interest);
echo "<a href='tags.php?tag={$interest}' class='w3-tag w3-small w3-teal' style='margin:3px;'>" . "#" . $interest . "</a>";
}
}
}
else {
echo lang("NO-INTERESTS") . " !";
}
?>
</p>
</div>
</div>
<br>
<!-- Posts -->
<?php
$userSubjects = getAllFrom("*","subject","WHERE userID = " . $info["userID"]);
if(!empty($userSubjects)){ ?>
<div class="w3-white">
<div class="w3-container w3-padding w3-teal">
<h4><?php echo lang("POSTS") . $info["username"] ?></h4>
</div>
<ul class="w3-ul w3-hoverable w3-white">
<?php foreach($userSubjects as $subject){ ?>
<a class="w3-hover-grey" href="subject.php?subID=<?php echo $subject["subID"] ?>" >
<li class="w3-padding-16">
<span class="w3-large"><?php echo $subject["title"] ?></span>
<br>
<span class="w3-text-grey"><?php echo date("m-d-Y", strtotime($subject["sub_date"])) ?></span>
</li>
</a>
<?php }
echo "</ul>";
echo "</div>";
}
?>
<!-- End Left Column -->
</div>
<!-- Modal for full size images on click-->
<div id="modal01" class="w3-modal w3-black" style="padding-top:0" >
<span class="w3-button w3-black w3-xxlarge w3-display-topright" onclick="this.parentElement.style.display='none'">×</span>
<div class="w3-modal-content w3-animate-zoom w3-center w3-transparent w3-padding-64">
<img id="img01" class="w3-image">
<p id="caption"></p>
</div>
</div>
<!-- Middle Column -->
<div class="w3-col m9">
<?php
if(isset($_SESSION["id"])){
if($_SESSION["id"] == $info["userID"]){ ?>
<div class="w3-row-padding w3-margin-bottom">
<div class="w3-col m12">
<div class="w3-card w3-round w3-white">
<div class="w3-container w3-padding w3-center">
<a href="newad.php" class="w3-button w3-round w3-theme w3-teal"><i class="fa fa-plus"></i><?php echo lang("NEW-AD") ?></a>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<div class="w3-row-padding w3-card w3-round w3-white w3-margin-left w3-margin-right" style="min-height:297px">
<?php
if(isset($_SESSION["id"])){
if($_SESSION["id"] == $info["userID"])
$userItems = getAllFrom("*","items","WHERE userID = " . $info["userID"], "ORDER BY add_date DESC");
else
$userItems = getAllFrom("*","items","WHERE pending = 1 AND userID = " . $info["userID"], "ORDER BY add_date DESC");
}
else
$userItems = getAllFrom("*","items","WHERE pending = 1 AND userID = " . $info["userID"], "ORDER BY add_date DESC");
if(!empty($userItems)){
?>
<h4 class="w3-margin w3-text-dark-grey"><?php echo lang("LATEST-ADS") . $info["username"] . "..." ?></h4>
<?php
foreach($userItems as $item){
?>
<div class="w3-third w3-margin-bottom w3-center" id="<?php echo $item["itemID"] ?>">
<div class="w3-border w3-hover-shadow w3-animate-zoom">
<div class="w3-display-container" >
<div class="img-container">
<?php
if(!empty(trim($item["image"]))){ ?>
<img class="" src="uploads/items_images/<?php echo $item["image"] ?>" style="width:100%">
<?php
}
else{
echo '<img src="uploads/items_images/ads.png" style="width:100%">';
}
?>
</div>
<?php
if( $item["pending"] == "0")
echo '<span class="w3-tag w3-display-topleft w3-teal">'. lang("PENDING") .'</span>';
else if(strtotime($item["add_date"]) > strtotime('- 7 days')){
echo '<span class="w3-tag w3-display-topleft w3-teal">'. lang("NEW") .'</span>';
}
else if($item["pending"] == 1)
?>
<span class="w3-tag w3-display-topright w3-teal"><?php echo $item["status"] ?> /5</span>
<h4 class="w3-padding w3-nowrap"><?php echo $item["item_name"] ?></h4>
<p class="w3-text-teal"><i class="fa fa-tag fa-fw"></i><b><?php echo $item["price"] ?> DA</b></p>
<p class="w3-opacity w3-nowrap"><?php echo proDate($item["add_date"]) ?></p>
<div class="w3-display-middle w3-display-hover">
<a href="showAd.php?itemID=<?php echo $item["itemID"] ?>" class="w3-button w3-teal"><?php echo lang("FULL-DETAILS") ?> <i class="fa fa-plus-circle"></i></a>
</div>
</div>
<div class="w3-row">
<?php
$citem = $item["itemID"];
if(isset($_SESSION["id"])) $user = $_SESSION["id"];
$list = getAllFrom("*","likes","WHERE itemID = '$citem' AND userID = '$user'");
if(count($list) > 0){ ?>
<a href="<?php echo $func ?>update.php?u=rlike&itemID=<?php echo $item["itemID"] ?>&userID=<?php echo $user ?>"><div class="w3-third w3-text-teal w3-padding w3-hover-teal w3-nowrap"><i class="fa fa-fw fa-check"></i><?php echo countItems("*","likes",true,"itemID",$item["itemID"]) ?> <span class="w3-hide-large w3-hide-medium"><?php echo lang("LIKED") ?></span>
</div>
</a>
<?php
}
else { ?>
<a href="<?php echo $func ?>update.php?u=alike&itemID=<?php echo $item["itemID"] ?>&userID=<?php echo $user ?>">
<div class="w3-third w3-text-grey w3-padding w3-hover-teal w3-nowrap"><i class="far fa-fw fa-thumbs-up"></i><?php echo countItems("*","likes",true,"itemID",$item["itemID"]) ?> <span class="w3-hide-large w3-hide-medium"><?php echo lang("LIKE") ?></span>
</div>
</a>
<?php
}
?>
<div class="w3-third w3-text-grey w3-padding w3-nowrap"><i class="fa fa-fw fa-eye"></i><?php echo countItems("*","user_likes",true,"itemID",$item["itemID"]) ?><span class="w3-hide-large w3-hide-medium"><?php echo lang("VIEWS") ?></span></div>
<a href="showAd.php?itemID=<?php echo $item["itemID"] ?>#demo"><div class="w3-third w3-text-grey w3-padding w3-hover-teal w3-nowrap"><i class="fa fa-fw fa-comments"></i> <?php echo countItems("comID","comments",true,"itemID",$item["itemID"]) ?><span class="w3-hide-large w3-hide-medium"><?php echo lang("COMMENTS") ?></span> </div></a>
</div>
</div>
</div>
<?php }
}
else {
echo '<h4 class="w3-margin w3-text-dark-grey w3-center">' . lang("NO-ADS") . " !" . '</h4>';
}
?>
</div>
<?php
if(isset($_SESSION["id"])){
if($_SESSION["id"] == $info["userID"]){
$stmt = $conn->prepare("SELECT likes.*, items.*, users.userID FROM likes INNER JOIN items ON likes.itemID = items.itemID INNER JOIN users ON users.userID = likes.userID WHERE likes.userID = " . $info["userID"] . " AND items.userID != users.userID ORDER BY like_date DESC");
$stmt->execute();
$likedAds = $stmt->fetchAll();
if(!empty($likedAds)){
?>
<div class="w3-row-padding w3-card w3-round w3-white w3-margin-left w3-margin-right w3-margin-top" style="min-height:297px">
<h4 class="w3-margin w3-text-teal"><?php echo lang("LIKED-ADS") . "..." ?></h4>
<?php
foreach($likedAds as $item){
?>
<div class="w3-third w3-margin-bottom w3-center" id="<?php echo $item["itemID"] ?>">
<div class="w3-border w3-hover-shadow w3-animate-zoom">
<div class="w3-display-container" >
<div class="img-container">
<?php
if(!empty(trim($item["image"]))){ ?>
<img class="" src="uploads/items_images/<?php echo $item["image"] ?>" style="width:100%">
<?php
}
else{
echo '<img src="uploads/items_images/ads.png" style="width:100%">';
}
?>
</div>
<?php
if( $item["pending"] == "0")
echo '<span class="w3-tag w3-display-topleft w3-teal">'. lang("PENDING") .'</span>';
else if(strtotime($item["add_date"]) > strtotime('- 7 days')){
echo '<span class="w3-tag w3-display-topleft w3-teal">'. lang("NEW") .'</span>';
}
else if($item["pending"] == 1)
?>
<span class="w3-tag w3-display-topright w3-teal"><?php echo $item["status"] ?> /5</span>
<h4 class="w3-padding w3-nowrap"><?php echo $item["item_name"] ?></h4>
<p class="w3-text-teal"><i class="fa fa-tag fa-fw"></i><b><?php echo $item["price"] ?> DA</b></p>
<p class="w3-opacity w3-nowrap"><?php echo date("Y-m-d", strtotime($item["add_date"])) ?></p>
<div class="w3-display-middle w3-display-hover">
<a href="showAd.php?itemID=<?php echo $item["itemID"] ?>" class="w3-button w3-teal"><?php echo lang("FULL-DETAILS") ?> <i class="fa fa-plus-circle"></i></a>
</div>
</div>
<div class="w3-row">
<?php
$citem = $item["itemID"];
if(isset($_SESSION["id"])) $user = $_SESSION["id"];
$list = getAllFrom("*","likes","WHERE itemID = '$citem' AND userID = '$user'");
if(count($list) > 0){ ?>
<a href="<?php echo $func ?>update.php?u=rlike&itemID=<?php echo $item["itemID"] ?>&userID=<?php echo $user ?>"><div class="w3-third w3-text-teal w3-padding w3-hover-teal w3-nowrap"><i class="fa fa-fw fa-check"></i><?php echo countItems("*","likes",true,"itemID",$item["itemID"]) ?>
</div>
</a>
<?php
}
else { ?>
<a href="<?php echo $func ?>update.php?u=alike&itemID=<?php echo $item["itemID"] ?>&userID=<?php echo $user ?>">
<div class="w3-third w3-text-grey w3-padding w3-hover-teal w3-nowrap"><i class="far fa-fw fa-thumbs-up"></i><?php echo countItems("*","likes",true,"itemID",$item["itemID"]) ?>
</div>
</a>
<?php
}
?>
<div class="w3-third w3-text-grey w3-padding w3-nowrap"><i class="fa fa-fw fa-eye"></i><?php echo countItems("*","user_likes",true,"itemID",$item["itemID"]) ?></div>
<a href="showAd.php?itemID=<?php echo $item["itemID"] ?>#demo"><div class="w3-third w3-text-grey w3-padding w3-hover-teal w3-nowrap"><i class="fa fa-fw fa-comments"></i><?php echo countItems("comID","comments",true,"itemID",$item["itemID"]) ?></div></a>
</div>
</div>
</div>
<?php }
?>
</div>
<?php
}
}
}
?>
<!-- End Middle Column -->
</div>
<!-- End Grid -->
</div>
<div id="id01" class="w3-modal" style="z-index:4">
<form action="<?php echo $_SERVER["PHP_SELF"] ?>?userID=<?php echo $info["userID"] ?>" method="post" enctype="multipart/form-data">
<div class="w3-modal-content w3-animate-zoom" style="width:400px">
<div class="w3-container w3-teal">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-teal w3-right w3-xlarge"><i class="fa fa-times"></i></span>
<h2><?php echo lang("RATING2") . $_SESSION["username"] ?></h2>
</div>
<div class="w3-panel">
<div class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="text">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="text">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="text">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="text">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="text">1 star</label>
</div>
</div>
<div class="w3-section w3-padding">
<input type="submit" class="w3-button w3-teal" value="<?php echo lang("RATE") ?>">
</div>
</div>
</form>
</div>
</div>
<?php
}
else
{ ?>
<div class="w3-container" style="min-height: -webkit-fill-available;">
<div class='alert-msg w3-center w3-container w3-margin-left w3-margin-right' style='margin-top:70px'><?php echo lang("USER-NOT-EXIST") ?>
</div>
</div>
<?php
}
}
else if ($do == "modify"){
if($_SESSION["id"] == $_GET["userID"]){
if($_SERVER["REQUEST_METHOD"] === "POST") {
$formErrors = array();
$picName = $_FILES["image"]["name"];
$picSize = $_FILES["image"]["size"];
$picTmp = $_FILES["image"]["tmp_name"];
$picType = $_FILES["image"]["type"];
$id = $_POST["userid"];
$user = filter_var($_POST["username"],FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"],FILTER_SANITIZE_STRING);
$fullname = filter_var($_POST["fullname"],FILTER_SANITIZE_STRING);
$telephone = 0 . filter_var($_POST["telephone"],FILTER_SANITIZE_NUMBER_INT);
if(!empty($_POST["birth_date"])){
$birth = $_POST["birth_date"];
$birth = date("Y-m-d", strtotime($birth));
}
else
$birth = date("00-00-0000");
$wilaya = filter_var($_POST["wilaya"],FILTER_SANITIZE_STRING);
$interests = filter_var($_POST["interests"],FILTER_SANITIZE_STRING);
$pass = sha1($_POST["password"]);
// Treating password
$allowedExt = array("jpeg","png","jpg","");
$avExt = explode(".",$picName);
$extension = strtolower(end($avExt));
if(empty(trim($_FILES["image"]["name"])) && !in_array($extension, $allowedExt)){
$formErrors[] = lang("NOT-ALLOWED-EXT");
}
if($picSize > 4194304) lang("BIG-SIZE");
// Validation
if(strlen($user) < 5) $formErrors[] = lang('STRLEN') ;
if(strlen($user) > 30) $formErrors[] = lang('STRLEN1') ;
if(empty(trim($user))) $formErrors[] = lang('USERERROR') ;
if($pass != $_POST["oldpassword"]) $formErrors[] = lang('PASS-ERROR') ;
if(empty($email)) $formErrors[] = lang('EMAILERROR') ;
if(empty(trim($fullname))) $formErrors[] = lang('FULLNAMERROR') ;
// Update
if(empty($formErrors)){
$stmt2 = $conn->prepare("SELECT username FROM users WHERE username = ? AND userID != ?");
$stmt2->execute(array($user,$id));
$cpt = $stmt2->rowCount();
if($cpt == 0){
$stmt3 = $conn->prepare("SELECT email FROM users WHERE email = ? AND userID != ?");
$stmt3->execute(array($email,$id));
$cpt3 = $stmt2->rowCount();
if($cpt == 0){
if(!empty(trim($picName))){
$image = rand(0,100000) . "_" . $picName ;
}
else
{
$image = $_SESSION["image"];
}
move_uploaded_file($picTmp, "uploads/profile_pictures/" . $image) ;
$stmt = $conn->prepare("UPDATE users SET username = ?, email = ?, fullname = ?, password = ?, image = ?, telephone = ?, birthDate = ?, wilaya = ?, interests = ? WHERE userID = ?");
$stmt->execute(array($user,$email,$fullname,$pass,$image,$telephone,$birth,$wilaya,$interests,$id));
if($stmt){
$_SESSION["image"] = $image;
$_SESSION["interests"] = $interests;
header("location: profile.php?do=show&userID=". $_SESSION["id"]);
exit();
}
}
else {
$failMsg = "<div class='alert-msg w3-container w3-center'>" . lang("EMAIL-EXIST") . "</div>";
}
}
else{
$failMsg = "<div class='alert-msg w3-container w3-center'>" . lang("USER-EXIST") . "</div>";
}
}
}
$userID = isset($_GET['userID']) && is_numeric($_GET['userID']) ? intval($_GET['userID']):0 ;
// Select data
$stmt = $conn->prepare("SELECT * FROM users WHERE userID = ? LIMIT 1");
// execute query
$stmt->execute(array($userID));
// Fetch the data
$row = $stmt->fetch();
$count = $stmt->rowCount();
if($count > 0){
?>
<div class="w3-container w3-content w3-margin-bottom">
<form class="form-horizontal w3-card w3-white w3-margin-top" action="" method="post" enctype="multipart/form-data">
<h1 class="w3-center w3-text-dark-grey"><?php echo lang('EDIT') ?></h1>
<input type="hidden" name="userid" value="<?php echo $userID ?>"> <!-- to get user's ID -->
<div class="w3-row-padding ">
<!-- Profile pic -->
<div class="form-group form-group-lg w3-margin-bottom w3-center">
<div class="image-upload">
<label for="file-input">
<?php
if(!empty(trim($row["image"]))){
echo "<img class='profile-pic img-responsive img-thumbnail img-circle' src='uploads/profile_pictures/" . $row["image"] . "' alt='' />";
}
else {
echo "<img class='profile-pic img-responsive img-thumbnail img-circle' src='uploads/profile_pictures/user.png' alt='' />";
}
?>
</label>
<input id="file-input" type="file" name="image" class="form-control"/>
</div>
<?php
if(!empty($formErrors)){
foreach ($formErrors as $error){
echo "<div class='alert alert-danger container text-center'>" . $error . "</div>" ;
}
}
if(isset($failMsg)){
echo $failMsg;
}
?>
</div>
<hr>
<div class="w3-half w3-padding">
<!-- Username -->
<div class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("USERNAME") ?></label>
<input type="text" name="username" class="w3-input w3-text-grey " autocomplete="off" value="<?php echo $row['username'] ?>" required="required">
</div>
<!-- E-mail -->
<div class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("EMAIL") ?></label>
<input type="email" name="email" class="w3-input w3-text-grey" value="<?php echo $row['email'] ?>" required="required">
</div>
<!-- Full name -->
<div class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("FULLNAME") ?></label>
<input type="text" name="fullname" class="w3-input w3-text-grey" value="<?php echo $row['fullname'] ?>" required="required">
</div>
</div>
<div class="w3-half w3-padding">
<!-- Telephone -->
<div class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("PHONE-NUM") ?></label>
<input type="tel" id="phone" name="telephone" class="w3-input w3-text-grey" value="<?php echo $row['telephone'] ?>" >
</div>
<!-- Birth -->
<div class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("BIRTH-DATE") ?></label>
<input type="date" name="birth_date" class="w3-input w3-text-grey" value="<?php echo $row['birthDate'] ?>" >
</div>
<!-- WILAYA -->
<p class="form-group form-group-lg w3-margin-bottom w3-padding">
<label class="w3-label w3-darkcyan"><?php echo lang("WILAYA") ?></label>
<select class="w3-select w3-text-grey w3-border" name="wilaya">
<option value=""></option>
<?php
$stmt1 = $conn->prepare("SELECT * FROM wilayas");
$stmt1->execute();
$cats = $stmt1->fetchAll();
foreach($cats as $cat){ ?>
<option value = '<?php echo $cat["wilaya"] ?>' <?php if($row["wilaya"] == $cat["wilaya"] ){ echo "selected"; } ?> ><?php echo $cat["wilaya"] ?></option>
<?php }
?>
</select>
</p>
</div>
<p class="form-group form-group-lg w3-margin-bottom w3-padding w3-center">
<label class="w3-label w3-darkcyan"><?php echo lang("INTERESTS") ?></label>
<input class="w3-input w3-padding-16 w3-text-grey w3-border" name="interests" maxlength="800" placeholder="<?php echo lang("INTERESTS") ?>" value="<?php if(!empty(trim($row["interests"]))) echo $row["interests"] ; ?>" >
</p>
</div>
<hr>
<!-- SAVE -->
<div class="form-group form-group-lg w3-center">
<a href="javascript:void(0)" class="w3-large w3-margin w3-button w3-teal w3-button w3-round" onclick="document.getElementById('id01').style.display='block'">
<i class="fa fa-fw fa-save"></i>
<?php echo " " . lang("SAVE") ?>
</a>
</div>
<div id="id01" class="w3-modal" style="z-index:4">
<div class="w3-modal-content w3-animate-zoom">
<div class="w3-container w3-padding w3-teal">
<span onclick="document.getElementById('id01').style.display='none'"
class="w3-button w3-teal w3-right w3-large"><i class="fa fa-times"></i></span>
<h4 class="w3-center"><?php echo lang("ENTER-PASSWORD") ?></h4>
</div>
<div class="w3-panel">
<!-- Password -->
<div class="w3-center form-group form-group-lg w3-margin-bottom w3-padding">
<input type="password" name="password" class="w3-input w3-text-grey" autocomplete="new-password" placeholder="<?php echo lang("PASSWORD-CONFIRM")?>" >
<input type="hidden" name="oldpassword" value="<?php echo $row['password'] ?>" >
</div>
<div class="w3-section w3-center">
<input type="submit" class="w3-button w3-teal w3-large" value="<?php echo lang('CONFIRM') ?>">
</div>
</div>
</div>
</div>
</form>
</div>
<?php
}
}
else {
header("location: main.php");
exit();
}
}
include $tmp . 'footer.php';
ob_end_flush();
?>