get_image_link fix
[mirrors/Kyberia-bloodline.git] / wwwroot / inc / eventz / F.inc
1 <?php
2 function F() {
3 global $db,$node,$error,$error_messages;
4 $user_id=$_SESSION['user_id'];
5 $user_name=$_SESSION['user_name'];
6 $kset=$db->query("select user_k from users where user_id='$user_id'");
7 $kset->next();
8 $user_k=$kset->getString('user_k');
9
10 // XXX hard-coded
11 $senat_id = 876611;
12 $K_id = 1961061;
13 $comms = getCommanders($K_id);
14 $isComm = isCommander($comms,$user_id);
15 $isSOwner = isSenatOwner($senat_id, $user_id);
16
17 if (is_array($_POST['node_chosen'])) {
18 $k=$_POST['node_chosen'];
19 }
20 else $k[]=$node['node_id'];
21 $db->query("set autocommit=0");
22
23 foreach ($k as $id) {
24
25 if ($user_k) {
26 $isSenat = hasAncestor(getAncestors($id), $senat_id);
27 if ($isSenat && !($isComm || $isSOwner)){
28 $error.="Sorry, ale v senate mozu Kckovat len obcania.";
29 }else{
30 $userset=$db->query("select node_creator from nodes where node_id='$id'");
31 $userset->next();
32 $acceptor_id=$userset->getString('node_creator');
33
34 $set=$db->query("select * from node_access where node_id='$id' and user_id='$user_id' and given_k='yes'");
35 if ($set->getNumRows()) {
36 $error.=$error_messages['K_GIVEN'];
37 }else{
38 --$user_k;
39 $db->query("update nodes set k=k-1 where node_id='$id'");
40 $db->query("insert into I set node_id='$id'");
41 $result=$db->update("update node_access set given_k='yes' where node_id='$id' and user_id='$user_id'");
42 if (!$result) {
43 $db->query("insert into node_access set given_k='yes',node_id='$id',user_id='$user_id',last_visit=NOW()");
44 }
45 }
46 }
47 }
48
49 else {
50 $error.=$error_messages['K_SPENT'];
51 }
52 }
53
54 $db->query("update users set user_k='$user_k' where user_id='$user_id'");
55 $db->query("commit");
56
57 if (!$error) return true;
58 else return false;
59 }
60
61 ?>
This page took 1.753155 seconds and 4 git commands to generate.