forked from owen2/date2knight
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreportlib.php
More file actions
171 lines (153 loc) · 5.56 KB
/
Copy pathreportlib.php
File metadata and controls
171 lines (153 loc) · 5.56 KB
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
<?php
function canDoIt($a, $b)
{
$resultA = mysql_query("SELECT gender,seeks FROM profile WHERE id=$a");
$resultB = mysql_query("SELECT gender,seeks FROM profile WHERE id=$b");
$rowA = mysql_fetch_assoc($resultA);
$rowB = mysql_fetch_assoc($resultB);
return ($rowA['gender'] & $rowB['seeks']) && ($rowA['seeks'] & $rowB['gender']);
}
function getTopDates($personAID, $limit=10)
{
$result = mysql_query("SELECT paid FROM profile WHERE id=$personAID");
$row = mysql_fetch_array($result);
if ($row['paid'] != 1)
return false; //NO STEALING THE RESULTS, It's creepy. Yeah you, stumme.
$result = mysql_query("SELECT count(*) FROM response WHERE profile_id=$personAID");
$count = mysql_fetch_row($result);
if ($count[0] == 0)
return false;
$matchlist = array();
$results = mysql_query("SELECT id FROM `profile` WHERE `id` <> " . $personAID . " AND validated= 1;");
while ($personB = mysql_fetch_assoc($results))
{
$score = getScore($personAID, $personB['id']);
//if (canDoIt($personAID, $personB['id']))
if ($score != -1) { // taken quiz
$matchlist[$personB['id']] = $score;
}
}
asort($matchlist);
$retlist = array();
$tail = array();
// Accumulate $limit/2 lovematches and store rest sorted in $tail
$count = 0;
foreach ($matchlist as $key => $value) {
if ($count < ($limit/2) && canDoIt($personAID,$key)) {
$count = $count + 1;
$retlist[$key] = $value;
}else {
$tail[$key] = $value;
}
}
$lovers = count($retlist); // number of love matches
// fill up rest of $retlist up to $limit with friend mathces
$count = 0;
foreach ($tail as $key => $value) {
if (($count+$lovers) == ($limit+1)){
break;
}
$retlist[$key] = $value;
$count = $count + 1;
}
return $retlist;
}
function printReport($id)
{
$result = mysql_query("SELECT * FROM `profile` WHERE `id` = '$id' AND `validated` = '1';");
if (!$result)
die(mysql_error());
$profile = mysql_fetch_array($result);
$firstName = $profile['firstname'];
$lastName = $profile['lastname'];
$email = $profile['email'];
$box = $profile['box'];
$bio = $profile['bio'];
$phone = $profile['phone'];
$dates = getTopDates($id);
echo '<h1>';
echo $firstName . ' ' . $lastName . "<br />Mailbox " . $box;
echo '</h1>';
if ($dates != '') {
foreach ($dates as $date_id => $score) {
showMiniProfile($date_id,$id,$score);
echo '<br class="reset-float" />';
}
}
echo '<br><br> <p>Scores: ♥♥♥♥♥ and ☯☯☯☯☯ are the best ratings possible. ☯☯☯ and above are considered good matches. The lowest possible score shows no ♥ or ☯.</p>
';
}
function showMiniProfile($id,$source_id, $score)
{
$result = mysql_query("SELECT * FROM `profile` WHERE `id` = '$id' AND `validated` = '1';");
if (!$result)
die(mysql_error());
$profile = mysql_fetch_array($result);
$firstName = $profile['firstname'];
$lastName = $profile['lastname'];
$email = $profile['email'];
$box = $profile['box'];
$bio = $profile['bio'];
$phone = $profile['phone'];
$profileImage = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?r=x&d=mm";
$valid = $profile['validated'];
$paid = $profile['paid'];
if (!canDoIt($source_id, $id))
$char = "☯";
else
$char = "♥";
?>
<div class="mini-profile stackleft">
<img src="<?php echo($profileImage); ?>" alt="" class="stackleft mp-avatar">
<div class="stackleft">
<h3><?php echo("$firstName $lastName ");printHearts($score,$char); ?></h3>
<p><?php echo($bio);?></p>
<p><?php echo("$phone - Box $box");?></p>
<p><a href="mailto:<?php echo($email);?>"><?php echo($email);?></a></p>
</div>
</div>
<?php
}
function getScore($a, $b)
{
// This function will fail if questions were changed while people
// were filling out/had already filled out quiz
$resultA = mysql_query("SELECT `answer` FROM `response` WHERE `profile_id`='$a' ORDER BY `question_id`");
$resultB = mysql_query("SELECT `answer` FROM `response` WHERE `profile_id`='$b' ORDER BY `question_id`");
$sum = 0;
if (mysql_num_rows($resultB) == 0) {
return -1;
}
while (($rowA = mysql_fetch_array($resultA)) && ($rowB = mysql_fetch_array($resultB))) {
$sum += pow(abs($rowA[0] - $rowB[0]),2);
}
echo(mysql_error());
return sqrt($sum);
}
function printHearts($score, $char)
{
$h5 = 10;
$h4 = 13;
$h3 = 15;
$h2 = 20;
$h1 = 25;
//Whole hearts
if ($score < $h5) echo($char);
if ($score < $h4) echo($char);
if ($score < $h3) echo($char);
if ($score < $h2) echo($char);
if ($score < $h1) echo($char);
//half hearts
$half = ($h5 + $h4) / 2.;
if ($score <= $half and $score >= $h5) echo('<span style="color:#888">'. $char .'</span>');
$half = ($h4 + $h3) / 2.;
if ($score <= $half and $score >= $h4) echo('<span style="color:#888">'. $char .'</span>');
$half = ($h3 + $h2) / 2.;
if ($score <= $half and $score >= $h3) echo('<span style="color:#888">'. $char .'</span>');
$half = ($h2 + $h1) / 2.;
if ($score <= $half and $score >= $h2) echo('<span style="color:#888">'. $char .'</span>');
if ($score >= $h1) echo('<span style="color:#888">'. $char .'</span>');
//Numbers
//echo("(". round($score, 4) .")" );
}
?>