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'");
8 $user_k=$kset->getString('user_k');
13 $comms = getCommanders($K_id);
14 $isComm = isCommander($comms,$user_id);
15 $isSOwner = isSenatOwner($senat_id, $user_id);
17 if (is_array($_POST['node_chosen'])) {
18 $k=$_POST['node_chosen'];
20 else $k[]=$node['node_id'];
21 $db->query("set autocommit=0");
26 $isSenat = hasAncestor(getAncestors($id), $senat_id);
27 if ($isSenat && !($isComm || $isSOwner)){
28 $error.="Sorry, ale v senate mozu Kckovat len obcania.";
30 $userset=$db->query("select node_creator from nodes where node_id='$id'");
32 $acceptor_id=$userset->getString('node_creator');
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'];
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'");
43 $db->query("insert into node_access set given_k='yes',node_id='$id',user_id='$user_id',last_visit=NOW()");
50 $error.=$error_messages['K_SPENT'];
54 $db->query("update users set user_k='$user_k' where user_id='$user_id'");
57 if (!$error) return true;