members = lc_opmember::select(array('lc_op_id'=>$entry->id)); foreach ($entry->members as $member) { if ($member->user_id == $r->user->id) { $entry->partofop = true; } } } } $r->set('entries', $listing); } function admin(Request &$r) { $listing = list_content::getInstance()->setType('op')->setConditions(array('where'=>array('paid'=>false)))->getListing($r); foreach ($listing['entries'] as &$entry) { $entry->members = lc_opmember::select(array('lc_op_id'=>$entry->id)); } $r->set('entries', $listing['entries']); } function wallet(Request &$r) { $ops_done = yapeal::complexQuery("SELECT op.*, ot.name AS optype FROM lc_opmember om INNER JOIN lc_op op ON om.lc_op_id = op.id INNER JOIN lc_optype ot ON op.optype_id = ot.id INNER JOIN user_account ua ON ua.user_id = om.user_id WHERE ua.user_id = ? AND op.closed IS NOT NULL GROUP BY om.lc_op_id", array($r->user->id)); $total_waiting = 0; $total_paid = 0; if ($ops_done) { foreach ($ops_done as &$op) { $id = $op->id; $total = yapeal::complexQuery("SELECT SUM(ol.amount*ol.price) AS total FROM lc_oploot ol WHERE ol.lc_op_id = ?", array($id), true); $participants = yapeal::complexQuery("SELECT rc.* FROM lc_opmember om INNER JOIN user_account ua ON ua.user_id = om.user_id INNER JOIN yap_utilRegisteredCharacter rc ON ua.account_id = rc.userID WHERE om.lc_op_id = ? AND isMain = 1 GROUP BY ua.user_id", array($id)); $participantnr = count($participants); $op->total = $total->total; $op->total_earned = $total->total / $participantnr; if ($op->paid) { $total_paid += $op->total_earned; } else { $total_waiting += $op->total_earned; } } } $r->set('ops', $ops_done); $r->set('total_waiting', $total_waiting); $r->set('total_paid', $total_paid); } function payment(Request &$r) { $ops_to_be_paid = yapeal::complexQuery("SELECT op.id, op.name, ol.lc_op_id, SUM(ol.amount*ol.price) as total FROM lc_oploot ol INNER JOIN lc_item it ON ol.item_id = it.id INNER JOIN lc_op op ON ol.lc_op_id = op.id WHERE op.confirmed = true AND op.paid = false GROUP BY ol.lc_op_id", array()); $characters_to_pay = array(); $opstotal = 0; $charactertotal = 0; if ($ops_to_be_paid) { foreach ($ops_to_be_paid as $op) { $id = $op->lc_op_id; $opstotal += $op->total; $participants = yapeal::complexQuery("SELECT rc.* FROM lc_opmember om INNER JOIN user_account ua ON ua.user_id = om.user_id INNER JOIN yap_utilRegisteredCharacter rc ON ua.account_id = rc.userID WHERE om.lc_op_id = ? AND isMain = 1 GROUP BY ua.user_id", array($id)); $participantnr = count($participants); if ($participants) { foreach ($participants as $member) { $characters_to_pay[$member->characterID]['name'] = $member->name; $characters_to_pay[$member->characterID]['payment'] += $op->total/$participantnr; $charactertotal += $op->total/$participantnr; } } } } $r->set('opstopay', $ops_to_be_paid); $r->set('characters', $characters_to_pay); $r->set('chartotal', $charactertotal); $r->set('opstotal', $opstotal); } function paidops(Request &$r) { list_content::getInstance()->setType("op")->setPerPage(25)->setConditions(array('where'=>array('paid'=>1)))->listing($r); } function dopayment(Request &$r) { $ops_to_be_paid = yapeal::complexQuery("SELECT op.name, ol.lc_op_id, SUM(ol.amount*it.price) as total FROM lc_oploot ol INNER JOIN lc_item it ON ol.item_id = it.id INNER JOIN lc_op op ON ol.lc_op_id = op.id WHERE op.confirmed = true AND op.paid = false GROUP BY ol.lc_op_id", array()); if ($ops_to_be_paid) { foreach ($ops_to_be_paid as $op) { $pop = lc_op::from_id($op->lc_op_id); $pop->paid = true; $pop->update(); } } $r->redirect('wormhole/admin'); } function create(Request &$r) { $record = $r->get('record'); if ($r->get('submit')) { $record['notes'] = date($this->dateformat).": Op created
"; $newop = lc_op::from_values($record); $newop->create(); $loot = yapeal::complexQuery("SELECT * FROM lc_item_optype io INNER JOIN lc_item it ON io.lc_item_id = it.id WHERE io.lc_optype_id = ? AND it.currently_buying = 1", array($newop->optype_id)); foreach ($loot as $item) { $lootitem = lc_oploot::from_values(array( 'name' => $item->name, 'item_id' => $item->lc_item_id, 'lc_op_id' => $newop->id, 'amount' => 0, 'price' => $item->price )); $lootitem->create(); } $r->redirect('wormhole'); } $r->set('types', lc_optype::select()); $r->set('cans', yapeal::complexQuery("SELECT oc.id, oc.name FROM lc_opcan oc LEFT JOIN lc_op op ON oc.id = op.opcan_id AND op.paid IS false WHERE op.opcan_id IS NULL ORDER BY oc.name ASC", array())); } function op(Request &$r, $id) { $op = lc_op::from_id($id); $opitems = yapeal::complexQuery("SELECT ol.id, ol.name, IF(ol.amount IS NOT NULL, ol.amount, 0) AS amount, ol.price, it.type_id FROM lc_oploot ol INNER JOIN lc_item it ON ol.item_id = it.id WHERE ol.lc_op_id = ? ORDER BY ol.name ASC", array($op->id)); $total = 0; if ($opitems) { foreach ($opitems as $item) { $total += $item->price * $item->amount; } } $r->set('total', $total); if ($r->get('loot')) { $loot = $r->get('loot'); foreach ($opitems as $item) { if ($item->amount != $loot[$item->id]) { $newitem = lc_oploot::from_id($item->id); $newitem->amount = $loot[$item->id]; $newitem->update(); } } //$op->notes .= date('d-m-Y H:i:s').": ".$r->user->name." modified loot"."
"; $op->update(); } if ($r->get('add_comment')) { $op->notes .= date($this->dateformat)." (".$r->user->name."): ".$r->get('add_comment')."
"; $op->update(); } if (user::check_level(3)) { if ($r->get('addcharacter')) { list($user_id, $character_id, $character_name) = explode('_', $r->get('addcharacter')); $newmember = lc_opmember::from_values(array( 'name' => $character_name, 'character_id' => $character_id, 'lc_op_id' => $id, 'user_id' => $user_id )); $newmember->create(); } if ($r->get('canadjust')) { $op->opcan_id = $r->get('canadjust'); $op->update(); } $r->set('cans', yapeal::complexQuery("SELECT oc.id, oc.name FROM lc_opcan oc LEFT JOIN lc_op op ON oc.id = op.opcan_id AND op.paid IS false WHERE op.opcan_id IS NULL ORDER BY oc.name ASC", array())); $r->set('characters', yapeal::complexQuery("SELECT rc.name, ua.user_id, rc.characterID FROM yap_utilRegisteredCharacter rc INNER JOIN user_account ua ON rc.userID = ua.account_id ORDER BY rc.name", array())); } if ($r->get('loot') || $r->get('comment')) $r->redirect('wormhole/op/'.$id); $can = lc_opcan::from_id($op->opcan_id); $optype = lc_optype::from_id($op->optype_id); $r->set('op', $op); $r->set('can', $can); $r->set('optype', $optype); $opmembers = lc_opmember::select(array('lc_op_id'=>$op->id)); $r->set('members', $opmembers); $partofop = false; foreach ($opmembers as $member) { if ($member->user_id == $r->user->id) { $partofop = true; $r->set('member', $member); } } $r->set('partofop', $partofop); $trueopmembers = yapeal::complexQuery("SELECT rc.* FROM lc_opmember om INNER JOIN user_account ua ON ua.user_id = om.user_id INNER JOIN yap_utilRegisteredCharacter rc ON ua.account_id = rc.userID WHERE om.lc_op_id = ? AND isMain = 1 GROUP BY ua.user_id", array($id)); $r->set('part', (count($trueopmembers)>0)?$total/count($trueopmembers):0); $r->set('loot', $opitems); } function joinop(Request &$r, $opid, $characterID=null) { if (!$characterID) { $characterID = $_SERVER['HTTP_EVE_CHARID']; } $joiner = yapeal::complexQuery("SELECT * FROM yap_utilRegisteredCharacter rc INNER JOIN user_account ua ON rc.userID = ua.account_id WHERE rc.characterID = ? AND ua.user_id = ?", array($characterID, $r->user->id), true); if ($joiner) { $already_joined = lc_opmember::select_one(array('user_id'=>$r->user->id, 'character_id'=>$joiner->characterID, 'lc_op_id' => $opid)); if ($already_joined) { } else { $opmember = lc_opmember::from_values(array( 'user_id' => $r->user->id, 'character_id' => $joiner->characterID, 'lc_op_id' => $opid, 'name' => $joiner->name )); $opmember->create(); $op = lc_op::from_id($opid); $op->notes .= date($this->dateformat).": ".$joiner->name." joined op
"; $op->update(); } $r->redirect('wormhole/op/'.$opid); } else { $r->set('opid', $opid); $r->set('characters', yapeal::complexQuery("SELECT * FROM yap_utilRegisteredCharacter rc INNER JOIN user_account ua ON rc.userID = ua.account_id WHERE ua.user_id = ?", array($r->user->id))); } } function kickop(Request &$r, $opid, $opmemberid) { $member = lc_opmember::from_id($opmemberid); $op = lc_op::from_id($opid); $member->kicked = true; $member->update(); $op->notes .= date($this->dateformat).": ".$member->name." kicked by ".$r->user->name."
"; $op->update(); $r->redirect('wormhole/op/'.$op->id); } function removeop(Request &$r, $opid, $opmemberid) { $member = lc_opmember::from_id($opmemberid); $member->delete(); $r->redirect('wormhole/op/'.$opid); } function closeop(Request &$r, $opid) { $op = lc_op::from_id($opid); $op->closed = date('Y-m-d H:i:s'); $op->notes .= date($this->dateformat).": ".$r->user->name." closed op
"; $op->update(); $r->redirect("wormhole/op/".$op->id); } function confirmop(Request &$r, $opid) { $op = lc_op::from_id($opid); $op->notes .= date($this->dateformat).": ".$r->user->name." confirmed op
"; $op->confirmed = true; $op->update(); $r->redirect("wormhole/admin"); } function easypricing(Request &$r, $optype="all", $order='name') { $conditions = ($optype!="all")?" WHERE io.lc_optype_id = ". mysql_real_escape_string($optype):""; $ordering = " ORDER BY it.".mysql_real_escape_string($order); $items = yapeal::complexQuery("SELECT DISTINCT it.id, it.type_id, it.name, it.price, it.currently_buying FROM lc_item it INNER JOIN lc_item_optype io ON it.id = io.lc_item_id".$conditions.$ordering, array()); if ($r->get('prices') || $r->get('buying')) { $prices = $r->get('prices'); $buying = $r->get('buying'); foreach ($items as &$item) { if ($item->price != $prices[$item->id] || $item->currently_buying != $buying[$item->id]) { $moditem = lc_item::from_id($item->id); $moditem->price = $prices[$item->id]; $moditem->currently_buying = (isset($buying[$item->id]))?true:false; $item->price = $prices[$item->id]; $item->currently_buying = (isset($buying[$item->id]))?true:false; $moditem->update(); } } } $r->set('items', $items); $r->set('optypes', lc_optype::select()); $r->set('currenttype', $optype); $r->set('currentorder', $order); } function pineeds(Request &$r) { $needed = yapeal::complexQuery("SELECT it.name, it.id, it.type_id, it.price, it.currently_buying FROM lc_item it INNER JOIN lc_item_optype io ON it.id = io.lc_item_id WHERE io.lc_optype_id = 5", array()); $r->set('needed', $needed); } } ?>