2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2011 CAcert Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 function query_init ($query)
21 return mysql_query($query);
24 function query_getnextrow ($res)
26 $row1 = mysql_fetch_assoc($res);
30 function query_get_number_of_rows ($resultset)
32 return intval(mysql_num_rows($resultset));
35 function get_number_of_assurances ($userid)
37 $res = query_init ("SELECT count(*) AS `list` FROM `notary`
38 WHERE `method` = 'Face to Face Meeting' AND `from`='".intval($userid)."' ");
39 $row = query_getnextrow($res);
41 return intval($row['list']);
44 function get_number_of_assurees ($userid)
46 $res = query_init ("SELECT count(*) AS `list` FROM `notary`
47 WHERE `method` = 'Face to Face Meeting' AND `to`='".intval($userid)."' ");
48 $row = query_getnextrow($res);
50 return intval($row['list']);
53 function get_top_assurer_position ($no_of_assurances)
55 $res = query_init ("SELECT count(*) AS `list` FROM `notary`
56 WHERE `method` = 'Face to Face Meeting'
57 GROUP BY `from` HAVING count(*) > '".intval($no_of_assurances)."'");
58 return intval(query_get_number_of_rows($res)+
1);
61 function get_top_assuree_position ($no_of_assurees)
63 $res = query_init ("SELECT count(*) AS `list` FROM `notary`
64 WHERE `method` = 'Face to Face Meeting'
65 GROUP BY `to` HAVING count(*) > '".intval($no_of_assurees)."'");
66 return intval(query_get_number_of_rows($res)+
1);
69 function get_given_assurances ($userid)
71 $res = query_init ("select * from `notary` where `from`='".intval($userid)."' and `from` != `to` order by `id` asc");
75 function get_received_assurances ($userid)
77 $res = query_init ("select * from `notary` where `to`='".intval($userid)."' and `from` != `to` order by `id` asc ");
81 function get_given_assurances_summary ($userid)
83 $res = query_init ("select count(*) as number,points,awarded,method from notary where `from`='".intval($userid)."' group by points,awarded,method");
87 function get_received_assurances_summary ($userid)
89 $res = query_init ("select count(*) as number,points,awarded,method from notary where `to`='".intval($userid)."' group by points,awarded,method");
93 function get_user ($userid)
95 $res = query_init ("select * from `users` where `id`='".intval($userid)."'");
96 return mysql_fetch_assoc($res);
99 function get_cats_state ($userid)
102 $res = query_init ("select * from `cats_passed` inner join `cats_variant` on `cats_passed`.`variant_id` = `cats_variant`.`id` and `cats_variant`.`type_id` = 1
103 WHERE `cats_passed`.`user_id` = '".intval($userid)."'");
104 return mysql_num_rows($res);
107 function calc_experience ($row,&$points,&$experience,&$sum_experience)
109 if ($row['awarded'] < $row['points'])
110 $apoints +
= $row['points'];
112 $apoints +
= $row['awarded'];
116 $experience = " ";
117 if ($row['method'] == "Face to Face Meeting")
119 $sum_experience = $sum_experience +
2;
125 function calc_assurances ($row,&$points,&$experience,&$sumexperience,&$awarded)
127 $awarded = calc_points($row);
131 $experience = $awarded - 100; // needs to be fixed in the future (limit 50 pts and/or no experience if pts > 100)
137 switch ($row['method'])
139 case 'Thawte Points Transfer':
140 case 'CT Magazine - Germany':
141 case 'Temporary Increase': // Current usage of 'Temporary Increase' may break audit aspects, needs to be reimplemented
142 $awarded=sprintf("<strong style='color: red'>%s</strong>",_("Revoked"));
148 $sumexperience = $sumexperience +
$experience;
152 function show_user_link ($name,$userid)
160 $name = _("Deleted account");
163 $name = "<a href='wot.php?id=9&userid=".intval($userid)."'>$name</a>";
167 function get_assurer_ranking($userid,&$num_of_assurances,&$rank_of_assurer)
169 $num_of_assurances = get_number_of_assurances (intval($userid));
170 $rank_of_assurer = get_top_assurer_position($num_of_assurances);
173 function get_assuree_ranking($userid,&$num_of_assurees,&$rank_of_assuree)
175 $num_of_assurees = get_number_of_assurees (intval($userid));
176 $rank_of_assuree = get_top_assuree_position($num_of_assurees);
180 // ************* html table definitions ******************
182 function output_ranking($userid)
184 get_assurer_ranking($userid,$num_of_assurances,$rank_of_assurer);
185 get_assuree_ranking($userid,$num_of_assurees,$rank_of_assuree);
188 <table align
="center" valign
="middle" border
="0" cellspacing
="0" cellpadding
="0" class="wrapper">
190 <td
class="title"><?
=_("Assurer Ranking")?
></td
>
193 <td
class="DataTD"><?
=sprintf(_("You have made %s assurances which ranks you as the #%s top assurer."), intval($num_of_assurances), intval($rank_of_assurer) )?
></td
>
196 <td
class="DataTD"><?
=sprintf(_("You have received %s assurances which ranks you as the #%s top assuree."), intval($num_of_assurees), intval($rank_of_assuree) )?
></td
>
203 function output_assurances_header($title)
206 <table align
="center" valign
="middle" border
="0" cellspacing
="0" cellpadding
="0" class="wrapper">
208 <td colspan
="7" class="title"><?
=$title?
></td
>
211 <td
class="DataTD"><strong
><?
=_("ID")?
></strong
></td
>
212 <td
class="DataTD"><strong
><?
=_("Date")?
></strong
></td
>
213 <td
class="DataTD"><strong
><?
=_("Who")?
></strong
></td
>
214 <td
class="DataTD"><strong
><?
=_("Points")?
></strong
></td
>
215 <td
class="DataTD"><strong
><?
=_("Location")?
></strong
></td
>
216 <td
class="DataTD"><strong
><?
=_("Method")?
></strong
></td
>
217 <td
class="DataTD"><strong
><?
=_("Experience Points")?
></strong
></td
>
222 function output_assurances_footer($points_txt,$points,$experience_txt,$sumexperience)
226 <td
class="DataTD" colspan
="3"><strong
><?
=$points_txt?
>:</strong
></td
>
227 <td
class="DataTD"><?
=$points?
></td
>
228 <td
class="DataTD"> 
;</td
>
229 <td
class="DataTD"><strong
><?
=$experience_txt?
>:</strong
></td
>
230 <td
class="DataTD"><?
=$sumexperience?
></td
>
237 function output_assurances_row($assuranceid,$date,$when,$name,$awarded,$points,$location,$method,$experience)
244 if ($awarded == $points)
248 if ($when < "2009-09-01")
250 $tdstyle="style='background-color: #ffff80'";
259 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$assuranceid?
><?
=$emclose?
></td
>
260 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$date?
><?
=$emclose?
></td
>
261 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$name?
><?
=$emclose?
></td
>
262 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$awarded?
><?
=$emclose?
></td
>
263 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$location?
><?
=$emclose?
></td
>
264 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$method?
><?
=$emclose?
></td
>
265 <td
class="DataTD" <?
=$tdstyle?
>><?
=$emopen?
><?
=$experience?
><?
=$emclose?
></td
>
270 function output_summary_header()
273 <table align
="center" valign
="middle" border
="0" cellspacing
="0" cellpadding
="0" class="wrapper">
275 <td colspan
="4" class="title"><?
=_("Summary of your Points")?
></td
>
278 <td
class="DataTD"><strong
><?
=_("Description")?
></strong
></td
>
279 <td
class="DataTD"><strong
><?
=_("Points")?
></strong
></td
>
280 <td
class="DataTD"><strong
><?
=_("Countable Points")?
></strong
></td
>
281 <td
class="DataTD"><strong
><?
=_("Remark")?
></strong
></td
>
286 function output_summary_footer()
294 function output_summary_row($title,$points,$points_countable,$remark)
298 <td
class="DataTD"><strong
><?
=$title?
></strong
></td
>
299 <td
class="DataTD"><?
=$points?
></td
>
300 <td
class="DataTD"><?
=$points_countable?
></td
>
301 <td
class="DataTD"><?
=$remark?
></td
>
307 // ************* output given assurances ******************
309 function output_given_assurances_content($userid,&$points,&$sum_experience)
313 $res = get_given_assurances(intval($userid));
314 while($row = mysql_fetch_assoc($res))
316 $fromuser = get_user (intval($row['to']));
317 $apoints = calc_experience ($row,$points,$experience,$sum_experience);
318 $name = show_user_link ($fromuser['fname']." ".$fromuser['lname'],intval($row['to']));
319 output_assurances_row (intval($row['id']),$row['date'],$row['when'],$name,$apoints,intval($row['points']),$row['location'],$row['method']==""?
"":_(sprintf("%s", $row['method'])),$experience);
323 // ************* output received assurances ******************
325 function output_received_assurances_content($userid,&$points,&$sum_experience)
329 $res = get_received_assurances(intval($userid));
330 while($row = mysql_fetch_assoc($res))
332 $fromuser = get_user (intval($row['from']));
333 calc_assurances ($row,$points,$experience,$sum_experience,$awarded);
334 $name = show_user_link ($fromuser['fname']." ".$fromuser['lname'],intval($row['from']));
335 output_assurances_row (intval($row['id']),$row['date'],$row['when'],$name,$awarded,intval($row['points']),$row['location'],$row['method']==""?
"":_(sprintf("%s", $row['method'])),$experience);
339 // ************* output summary table ******************
341 function check_date_limit ($userid,$age)
343 $dob = date("Y-m-d", mktime(0,0,0,date("m"),date("d"),date("Y")-$age));
344 $res = query_init ("select id from `users` where `id`='".$userid."' and `dob` < '$dob'");
345 return intval(query_get_number_of_rows($res));
348 function calc_points($row)
350 $awarded = intval($row['awarded']);
353 if (intval($row['points']) < $awarded)
354 $points = $awarded; // if 'sum of added points' > 100, awarded shows correct value
356 $points = intval($row['points']); // on very old assurances, awarded is '0' instead of correct value
357 switch ($row['method'])
359 case 'Thawte Points Transfer': // revoke all Thawte-points (as per arbitration)
360 case 'CT Magazine - Germany': // revoke c't (only one test-entry)
361 case 'Temporary Increase': // revoke 'temporary increase' (Current usage breaks audit aspects, needs to be reimplemented)
364 case 'Administrative Increase': // ignore AI with 2 points or less (historical for experiance points, now other calculation)
365 if ($points <= 2) // maybe limit to 35/50 pts in the future?
368 case 'Unknown': // to be revoked in the future? limit to max 50 pts?
369 case 'Trusted Third Parties': // to be revoked in the future? limit to max 35 pts?
370 case '': // to be revoked in the future? limit to max 50 pts?
371 case 'Face to Face Meeting': // normal assurances, limit to 35/50 pts in the future?
373 default: // should never happen ... ;-)
376 if ($points < 0) // ignore negative points (bug needs to be fixed)
381 function max_points($userid)
383 return output_summary_content ($userid,0);
386 function output_summary_content($userid,$display_output)
390 $sum_experience_other = 0;
392 $max_experience = 50;
394 $experience_limit_reached_txt = _("Limit reached");
396 if (check_date_limit($userid,18) != 1)
398 $max_experience = 10;
399 $experience_limit_reached_txt = _("Limit given by PoJAM reached");
401 if (check_date_limit($userid,14) != 1)
404 $experience_limit_reached_txt = _("Limit given by PoJAM reached");
407 $res = get_received_assurances_summary($userid);
408 while($row = mysql_fetch_assoc($res))
410 $points = calc_points ($row);
412 if ($points > $max_points) // limit to 100 points, above is experience (needs to be fixed)
414 $sum_experience_other = $sum_experience_other+
($points-$max_points)*intval($row['number']);
415 $points = $max_points;
417 $sum_points +
= $points*intval($row['number']);
420 $res = get_given_assurances_summary($userid);
421 while($row = mysql_fetch_assoc($res))
423 switch ($row['method'])
425 case 'Face to Face Meeting': // count Face to Face only
426 $sum_experience +
= 2*intval($row['number']);
432 if ($sum_points > $max_points)
434 $sum_points_countable = $max_points;
435 $remark_points = _("Limit reached");
439 $sum_points_countable = $sum_points;
440 $remark_points = " ";
442 if ($sum_experience > $max_experience)
444 $sum_experience_countable = $max_experience;
445 $remark_experience = $experience_limit_reached_txt;
449 $sum_experience_countable = $sum_experience;
450 $remark_experience = " ";
453 if ($sum_experience_countable +
$sum_experience_other > $max_experience)
455 $sum_experience_other_countable = $max_experience-$sum_experience_countable;
456 $remark_experience_other = $experience_limit_reached_txt;
460 $sum_experience_other_countable = $sum_experience_other;
461 $remark_experience_other = " ";
464 if ($sum_points_countable < $max_points)
466 if ($sum_experience_countable != 0)
467 $remark_experience = _("Points on hold due to less assurance points");
468 $sum_experience_countable = 0;
469 if ($sum_experience_other_countable != 0)
470 $remark_experience_other = _("Points on hold due to less assurance points");
471 $sum_experience_other_countable = 0;
475 $cats_test_passed = get_cats_state ($userid);
476 if ($cats_test_passed == 0)
478 $issue_points_txt = "<strong style='color: red'>"._("You have to pass the CAcert Assurer Challenge (CATS-Test) to be an Assurer")."</strong>";
479 if ($sum_points_countable < $max_points)
481 $issue_points_txt = "<strong style='color: red'>";
482 $issue_points_txt .= sprintf(_("You need %s assurance points and the passed CATS-Test to be an Assurer"), intval($max_points));
483 $issue_points_txt .= "</strong>";
488 $experience_total = $sum_experience_countable+
$sum_experience_other_countable;
489 $issue_points_txt = "";
490 if ($sum_points_countable == $max_points)
492 if ($experience_total >= 10)
494 if ($experience_total >= 20)
496 if ($experience_total >= 30)
498 if ($experience_total >= 40)
500 if ($experience_total >= 50)
502 if ($issue_points != 0)
503 $issue_points_txt = sprintf(_("You may issue up to %s points"),$issue_points);
507 output_summary_row (_("Assurance Points you received"),$sum_points,$sum_points_countable,$remark_points);
508 output_summary_row (_("Total Experience Points by Assurance"),$sum_experience,$sum_experience_countable,$remark_experience);
509 output_summary_row (_("Total Experience Points (other ways)"),$sum_experience_other,$sum_experience_other_countable,$remark_experience_other);
510 output_summary_row (_("Total Points")," ",$sum_points_countable +
$sum_experience_countable +
$sum_experience_other_countable,$issue_points_txt);
512 return $issue_points;
515 function output_given_assurances($userid)
517 output_assurances_header(_("Assurance Points You Issued"));
518 output_given_assurances_content($userid,$points,$sum_experience);
519 output_assurances_footer(_("Total Points Issued"),$points,_("Total Experience Points"),$sum_experience);
522 function output_received_assurances($userid)
524 output_assurances_header(_("Your Assurance Points"));
525 output_received_assurances_content($userid,$points,$sum_experience);
526 output_assurances_footer(_("Total Assurance Points"),$points,_("Total Experience Points"),$sum_experience);
529 function output_summary($userid)
531 output_summary_header();
532 output_summary_content($userid,1);
533 output_summary_footer();
536 function output_end_of_page()
539 <p
>[ <a href
='javascript:history.go(-1)'><?
=_("Go Back")?
></a
> ]</p
>