function handle_vote_claim($type, $from, $data, $res) { global $connection; $from->need_level("member"); validate_required($data, 'claim_id', 'vote'); $claim_id = $data['claim_id']; $vote = intval($data['vote']); $textvote = $vote > 0 ? 'pro' : ($vote < 0 ? 'contra' : 'neutrally'); $result = pg_query($connection, 'SELECT author, piece, pieces.index, users.nick FROM claims JOIN pieces ON pieces.id = claims.piece JOIN users ON users.id = author WHERE claims.id = ' . $claim_id); $num = pg_num_rows($result); if ($num == 0) { throw new Exception("Not found such claim."); } $claim = pg_fetch_assoc($result); // Protection from self-voting if (intval($claim['author']) == intval($from->user_id())) { throw new Exception("Not vote for yourself."); } $result = pg_query($connection, 'SELECT COUNT(*) FROM votes WHERE claim = ' . $claim_id . ' AND author = ' . $from->user_id()); $num = intval(pg_fetch_result($result, 0, 0)); if ($num == 0) { pg_query($connection, 'INSERT INTO votes VALUES(' . $claim_id . ',' . $from->user_id() . ',' . $vote . ')'); $res->to_sender(info_msg('You voted „' . $textvote . '“.')); } else { pg_query($connection, 'UPDATE votes SET value = ' . $vote . ' WHERE claim = ' . $claim_id . ' AND author = ' . $from->user_id()); $res->to_sender(info_msg('You changed vote to „' . $textvote . '“.')); } // Recalcing score (vote_balance) $result = pg_query($connection, 'SELECT sum(value) AS score FROM votes WHERE claim = ' . $claim_id); $score = intval(pg_fetch_result($result, 0, 0)); if ($score > 2) { // Getting old owner from db $result = pg_query($connection, 'SELECT owner, users.nick FROM pieces JOIN users ON users.id = pieces.owner WHERE pieces.id = ' . $claim['piece']); $old_owner = pg_fetch_assoc($result); // Updating piece in db pg_query($connection, 'UPDATE pieces SET owner = ' . $claim['author'] . ' WHERE id = ' . $claim['piece']); $res->to_pie($from, array('piece_owner', array('piece_index' => $claim['index'], 'owner' => $claim['nick']))); // Removing claim pg_query($connection, 'DELETE FROM claims WHERE id = ' . $claim_id); $res->to_pie($from, array('claim_remove', array('claim_id' => $claim_id))); $res->to_pie($from, info_msg('Claim by ' . $claim['nick'] . ' for piece #' . $claim['index'] . ' is accepted.')); update_kml($from->pieid); _update_user_reserved($res, $from, $claim['author'], $claim['nick']); _update_user_reserved($res, $from, $old_owner['owner'], $old_owner['nick']); } else { if ($score < -2) { pg_query($connection, 'DELETE FROM claims WHERE id = ' . $claim_id); $msg = array('claim_remove', array('claim_id' => $claim_id)); $res->to_pie($from, $msg); $res->to_pie($from, error_msg('Claim by ' . $claim['nick'] . ' for piece #' . $claim['index'] . ' is dismissed.')); } else { pg_query($connection, 'UPDATE claims SET score = ' . $score . ' WHERE id = ' . $claim_id); $msg = array('claim_update', array('claim_id' => $claim_id, 'vote_balance' => $score)); $res->to_pie($from, $msg); } } }
function update_pies() { global $connection; $result = pg_query($connection, 'SELECT id FROM pies'); if (pg_num_rows($result) == 0) { echo "No cakes to update\n"; return; } while ($pie = pg_fetch_array($result)) { echo " Updating cake " . $pie['id'] . " ...\n"; $index = 1; $result_pieces = pg_query_params($connection, 'SELECT id FROM pieces WHERE pie = $1 ORDER by id', array($pie['id'])); echo " Number of pieces = " . pg_num_rows($result_pieces) . "\n"; while ($piece = pg_fetch_array($result_pieces)) { if (!pg_query_params($connection, 'UPDATE pieces SET index = $1 WHERE id = $2', array($index++, $piece['id']))) { throw new Exception("Failed to update piece " . $piece['id']); } } update_kml($pie['id']); } }
echo $e->getMessage(); ?> </div> <p class="small"> If you are sure there is no error from your side, fill bug at <a href="https://github.com/Foxhind/MapCraft/issues?state=open" target="_blank">github.com/Foxhind/MapCraft/issues</a> and attach your osm file. </p> <p> Failed to create a file. <br /><a href="javascript:history.back();">Back</a> </p> <?php exit; } // Update map update_kml($pie_id); create_map($pie_id); $pie_link = '/pie/' . $pie_id; ?> Done!<br/> Please follow <a href="<?php echo $pie_link; ?> ">this link</a>, if you have not been forwarded automatically. <script type="text/javascript"> window.location = "<?php echo $pie_link; ?> "; </script>
function handle_piece_mass_free($type, $from, $data, $res) { global $connection; $from->need_level('admin'); $indexes = $data['indexes']; $owners = array(); $res->to_pie($from, info_msg("Mass slices update: free slices")); foreach ($indexes as $piece_index) { $piece_id = _find_piece_id($from, $piece_index); if (!pg_query($connection, 'UPDATE pieces SET owner = NULL WHERE id = ' . $piece_id)) { throw new Exception("Failed to free piece #" . $piece_index); } if (!pg_query($connection, 'DELETE FROM claims WHERE piece = ' . $piece_id)) { throw new Exception("Failed to remove claim for piece #" . $piece_index); } $res->to_pie($from, array('piece_owner', array("piece_index" => $piece_index, "owner" => ""))); $res->to_pie($from, info_msg("%s has freed slice #%s", $from->nick(), $piece_index)); _add_piece_info_log($res, $from, $piece_index, $piece_id, "Slice has been freed"); } update_kml($from->pieid); _update_users_claims($res, $from, true); _update_pie_timestamp($from, $connection); }
<input class="btn" type="submit" value="Upload" /> </fieldset> </form> </td> </tr> </table> <?php include '../lib/_footer.php'; exit; } // // THIRD STEP: Apply changes // try { $current->apply_steps($steps, 0); update_kml($current->id); system('curl -s -d "" "' . $hub_full_url . '/api/pie/' . $current->id . '/send_refresh_pie_data" >/dev/null'); echo "Done. Close this window, or return <a href=\"/update/" . $current->id . "\">back</a> to first step."; } catch (Exception $e) { ?> <div id="pageheader" style="background-color: #92836c;">Can't to parse a new cake</div> <div class="error"><?php echo $e->getMessage(); ?> </div> <p class="small"> Updating failed. Please make sure, that you have modified freshest exported version of the file. If you are sure there is no error from your side, fill bug at <a href="https://github.com/Foxhind/MapCraft/issues?state=open" target="_blank">github.com/Foxhind/MapCraft/issues</a> and attach your modified cake</a> </p>