Kyberia v2.0
[mirrors/Kyberia-bloodline.git] / inc / eventz / K.inc
1 <?php
2 /* This program is free software. It comes without any warranty, to
3 * the extent permitted by applicable law. You can redistribute it
4 * and/or modify it under the terms of the Do What The Fuck You Want
5 * To Public License, Version 2, as published by Sam Hocevar. See
6 * http://sam.zoy.org/wtfpl/COPYING for more details. */
7
8
9 function K() {
10 global $db,$node,$error,$error_messages;
11 $user_id=$_SESSION['user_id'];
12 $user_name=$_SESSION['user_name'];
13 $kset=$db->query("select user_k from users where user_id='$user_id'");
14 $kset->next();
15 $user_k=$kset->getString('user_k');
16
17 if (is_array($_POST['node_chosen'])) {
18 $k=$_POST['node_chosen'];
19 }
20 else $k[]=$node['node_id'];
21
22 foreach ($k as $id) {
23 if ($user_k) {
24 $userset=$db->query("select node_creator from nodes where node_id='$id'");
25 $userset->next();
26 $donor_id=$userset->getString('node_creator');
27 /*
28 if ($donor_id==$user_id) {
29 $error.=$error_messages['K_EGOTRIP'];
30 log::log('K',$id,'failed',$donor_id,'egotrippin');
31 }
32
33 else {
34 */
35 $set=$db->query("select * from node_access where node_id='$id' and user_id='$user_id' and given_k='yes'");
36 if ($set->getNumRows()) {
37 $error.=$error_messages['K_GIVEN'];
38 log::log('K',$id,'failed',$donor_id,'already given');
39 }
40 else {
41 --$user_k;
42 $db->query("update nodes set k=k+1 where node_id='$id'");
43 $result=$db->update("update node_access set given_k='yes' where node_id='$id' and user_id='$user_id'");
44 if (!$result) {
45 $db->query("insert into node_access set given_k='yes',node_id='$id',user_id='$user_id',last_visit=NOW()");
46 }
47
48
49 log::log('K',$id,'ok',$donor_id);
50 }
51 // }
52 }
53
54 else {
55 $error.=$error_messages['K_SPENT'];
56 log::log('K',$id,'failed',$donor_id,'zero amount');
57 }
58 }
59
60 $db->query("update users set user_k='$user_k' where user_id='$user_id'");
61
62 if (!$error) return true;
63 else return false;
64 }
65
66 ?>
This page took 0.344521 seconds and 4 git commands to generate.