Index: trunk/extensions/ContributionReporting/cc-reporting.php |
— | — | @@ -1,4 +1,6 @@ |
2 | 2 | <?php |
| 3 | + |
| 4 | +//handle request |
3 | 5 | if(isset ($_REQUEST['load'])){ |
4 | 6 | handleLoad(); |
5 | 7 | } |
— | — | @@ -6,9 +8,11 @@ |
7 | 9 | handleSubmit(); |
8 | 10 | } |
9 | 11 | |
| 12 | +//handle load |
10 | 13 | function handleLoad(){ |
11 | 14 | $cc_id = randomCookie(); |
12 | 15 | |
| 16 | + //already have a cookie? use it, else set randomly generated one |
13 | 17 | if(isset($_COOKIE['cc-cookie'])){ |
14 | 18 | $cc_id = $_COOKIE['cc-cookie']; |
15 | 19 | } |
— | — | @@ -17,22 +21,28 @@ |
18 | 22 | setcookie('cc-cookie', $cc_id, time() + (60 * 60 * 24 * 300), '/', "payments.wikimedia.org"); |
19 | 23 | } |
20 | 24 | |
| 25 | + //add into DB |
21 | 26 | $cc_id = addslashes($cc_id); |
22 | 27 | $utm_src = isset($_REQUEST['utm_src']) ? |
23 | 28 | addslashes($_REQUEST['utm_src']) : "unknown"; |
24 | 29 | $sql = "INSERT IGNORE INTO cc-track (cookie_id, utm_src, contribs) VALUES ('$cc_id','$utm_src', 0)"; |
25 | 30 | } |
26 | 31 | |
| 32 | +//handle submit |
27 | 33 | function handleSubmit(){ |
| 34 | + |
| 35 | + //for people with cookies turned off, track them via "NULL" cookie |
28 | 36 | $cc_id = "NULL"; |
29 | 37 | if(isset($_COOKIE['cc-cookie'])){ |
30 | 38 | $cc_id = $_COOKIE['cc-cookie']; |
31 | 39 | } |
32 | 40 | |
| 41 | + //update in DB |
33 | 42 | $cc_id = addslashes($cc_id); |
34 | 43 | $sql = "UPDATE cc-track SET contribs=contribs+1 WHERE cookie_id = '$cc_id'"; |
35 | 44 | } |
36 | 45 | |
| 46 | +//random cookie |
37 | 47 | function randomCookie(){ |
38 | 48 | return md5(mt_rand() + time()); |
39 | 49 | } |
\ No newline at end of file |
Index: trunk/extensions/ContributionReporting/cc-reporting.js |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | sendReq("cc-reporting.php?load=1&utm_src=" + document.payment.utm_source.value); |
5 | 5 | } |
6 | 6 | |
| 7 | +//replace "validate_form" call with this |
7 | 8 | submitForm = function(){ |
8 | 9 | sendReq("cc-reporting.php?submit=1&utm_src="+ document.payment.utm_source.value); |
9 | 10 | return validate_form(document.payment); |