Пример #1
0
 public function CreateTournament($request)
 {
     $mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token']);
     if (!valid_id($mundane_id)) {
         return NoAuthorization();
     }
     logtrace("CreateTournament() :1", $request);
     $this->Tournament->clear();
     $this->Tournament->kingdom_id = $request['KingdomId'];
     $this->Tournament->park_id = $request['ParkId'];
     $this->Tournament->event_calendardetail_id = $request['EventCalendarDetailId'];
     $detail = new yapo($this->db, DB_PREFIX . 'event_calendardetail');
     $detail->event_calendardetail_id = $request['EventCalendarDetailId'];
     if ($detail->find()) {
         $this->Tournament->event_id = $detail->event_id;
     } else {
         if (valid_id($request['EventCalendarDetailId'])) {
             return InvalidParameter();
         }
     }
     $this->Tournament->name = $request['Name'];
     $this->Tournament->description = strip_tags($request['Description'], "<p><br><ul><li><b><i>");
     $this->Tournament->date_time = $request['When'];
     $this->Tournament->save();
     return Success($this->Tournament->tournament_id);
 }
Пример #2
0
 public function RemoveAttendance($request)
 {
     logtrace("Attendance->RemoveAttendance()", $request);
     if ($this->AttendanceAuthority($request) === false) {
         return NoAuthorization();
     }
     $this->attendance->clear();
     $this->attendance->attendance_id = $request['AttendanceId'];
     if (!valid_id($request['AttendanceId']) || !$this->attendance->find()) {
         return InvalidParameter();
     }
     $this->attendance->delete();
     return Success($this->attendance->attendance_id);
 }
Пример #3
0
 public function GetKingdomParkAverages($request)
 {
     if (strlen($request['ReportFromDate']) == 0) {
         $request['ReportFromDate'] = 'curdate()';
     }
     if (strlen($request['AverageWeeks']) == 0 && strlen($request['AverageMonths']) == 0) {
         $request['AverageWeeks'] = 26;
     }
     if (strlen($request['KingdomId']) == 0) {
         $request['KingdomId'] = '0';
     }
     if ($request['NativePopulace']) {
         $native_populace .= "m.park_id = a.park_id and";
     }
     if ($request['Waivered']) {
         $waivered_peeps = "m.waivered = 1 and";
     }
     if (strlen($request['AverageWeeks']) > 0) {
         $per_period = mysql_real_escape_string($request['AverageWeeks']) . ' week';
     } else {
         $per_period = mysql_real_escape_string($request['AverageMonths']) . ' month';
     }
     $sql = "select \n\t\t\t\t\t\tcount(mundanesbyweek.mundane_id) attendance_count, p.park_id, p.name\n\t\t\t\t\tfrom \n\t\t\t\t\t\t" . DB_PREFIX . "park p\n\t\t\t\t\t\t\tleft join\n\t\t\t\t\t\t\t\t(select \n\t\t\t\t\t\t\t\t\t\ta.mundane_id, week(a.date,3) as week, a.park_id\n\t\t\t\t\t\t\t\t\tfrom " . DB_PREFIX . "attendance a\n\t\t\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "mundane m on a.mundane_id = m.mundane_id\n\t\t\t\t\t\t\t\t\twhere \n\t\t\t\t\t\t\t\t\t\t{$native_populace}\n\t\t\t\t\t\t\t\t\t\t{$waivered_peeps}\n\t\t\t\t\t\t\t\t\t\tdate > adddate(curdate(), interval -{$per_period}) \n\t\t\t\t\t\t\t\t\t\tand a.kingdom_id = '" . mysql_real_escape_string($request['KingdomId']) . "' \n\t\t\t\t\t\t\t\t\t\tand a.mundane_id > 0\n\t\t\t\t\t\t\t\t\tgroup by year(date), week(date,3), mundane_id) mundanesbyweek\n\t\t\t\t\t\t\t\ton p.park_id = mundanesbyweek.park_id\n\t\t\t\t\twhere p.kingdom_id = '" . mysql_real_escape_string($request['KingdomId']) . "' and p.active = 'Active'\n\t\t\t\t\tgroup by park_id\n\t\t\t\t\torder by name";
     logtrace('Report: GetKingdomParkAverages', array($request, $sql));
     $r = $this->db->query($sql);
     $response = array('Status' => Success(), 'KingdomParkAveragesSummary' => '');
     if ($r === false) {
         $response['Status'] = InvalidParameter();
     } else {
         $report = array();
         do {
             $report[] = array('AttendanceCount' => $r->attendance_count, 'ParkId' => $r->park_id, 'ParkName' => $r->name, 'Title' => $r->title, 'ParkTitleId' => $r->parktitle_id);
         } while ($r->next());
         $response['KingdomParkAveragesSummary'] = $report;
     }
     return $response;
 }
Пример #4
0
 public function EditAward($request)
 {
     if (($mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token'])) > 0 && Ork3::$Lib->authorization->HasAuthority($mundane_id, AUTH_ADMIN, 0, AUTH_EDIT)) {
         $this->log->Write('Award', $mundane_id, LOG_EDIT, $request);
         $this->award->clear();
         $this->award->award_id = $request['AwardId'];
         if ($this->kingdomaward->find()) {
             $this->award->name = $request['Name'];
             $this->award->is_ladder = $request['IsLadder'];
             $this->award->is_title = $request['IsTitle'];
             $this->award->title_class = $request['TitleClass'];
             $this->award->peerage = $request['Peerage'];
             $this->award->award->save();
         } else {
             return InvalidParameter();
         }
     } else {
         return NoAuthorization();
     }
 }
Пример #5
0
 public function RemoveAward($request)
 {
     logtrace("RemoveAward()", $request);
     $mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token']);
     $awards = new yapo($this->db, DB_PREFIX . 'awards');
     $awards->clear();
     $awards->awards_id = $request['AwardsId'];
     if (valid_id($request['AwardsId']) && $awards->find()) {
         $mundane = $this->player_info($awards->mundane_id);
         if (valid_id($mundane_id) && Ork3::$Lib->authorization->HasAuthority($mundane_id, AUTH_PARK, $mundane['ParkId'], AUTH_EDIT)) {
             $awards->delete();
         } else {
             return NoAuthorization();
         }
     } else {
         return InvalidParameter();
     }
 }
Пример #6
0
 public function add_auth_h($request)
 {
     logtrace('add_auth_h', $request);
     $this->auth->clear();
     $this->auth->mundane_id = $request['MundaneId'];
     switch ($request['Type']) {
         case AUTH_PARK:
             $this->auth->park_id = $request['Id'];
             break;
         case AUTH_KINGDOM:
             $this->auth->kingdom_id = $request['Id'];
             break;
         case AUTH_EVENT:
             $this->auth->event_id = $request['Id'];
             break;
         case AUTH_UNIT:
             $this->auth->unit_id = $request['Id'];
             break;
         case AUTH_ADMIN:
             break;
         default:
             $response = InvalidParameter(null, "Unrecognized Type.");
             return $response;
     }
     $this->auth->role = $request['Role'];
     $this->auth->modified = date('Y-m-d H:i:s');
     $this->auth->save();
     return Success($this->auth->authorization_id);
 }
Пример #7
0
 public function add_member_h($request)
 {
     logtrace("add_member_h", $request);
     $this->unit->clear();
     $this->unit->type = 'Company';
     $this->unit->unit_id = $request['UnitId'];
     if ($this->unit->find()) {
         $this->members->clear();
         $this->members->unit_id = $request['UnitId'];
         $this->members->mundane_id = $request['MundaneId'];
         $this->members->active = 'Active';
         if ($this->members->find()) {
             return InvalidParameter('Player is already an active member of this company.');
         }
         $this->members->clear();
         $this->members->mundane_id = $request['MundaneId'];
         $this->members->unit_id = $request['UnitId'];
         $this->members->active = 'Retired';
         if ($this->members->find()) {
             $this->members->active = 'Active';
             $this->members->save();
             return Success($this->members->unit_mundane_id);
         }
     }
     $this->members->clear();
     $this->members->unit_id = $request['UnitId'];
     $this->members->mundane_id = $request['MundaneId'];
     $this->members->role = $request['Role'];
     $this->members->title = $request['Title'];
     $this->members->active = $request['Active'];
     $this->members->save();
     return Success($this->members->unit_mundane_id);
 }
Пример #8
0
 public function record_transaction($trn, $splits, $trx_date = null)
 {
     logtrace('record_transaction', array($trn, $splits, $trx_date));
     $trx_date = is_null($trx_date) ? date('Y-m-d') : date('Y-m-d', strtotime($trx_date));
     $authority = false;
     foreach ($splits as $s => $split) {
         $authority |= $this->has_account_authority($trn['RecordedBy'], $split['AccountId']);
         $this->account->clear();
         $this->account->account_id = $split['AccountId'];
         if (!$this->account->find()) {
             return InvalidParameter(print_r(array($split['AccountId'], true)));
         } else {
             $splits[$s]['AccountType'] = $this->account->type;
         }
     }
     if (!$authority) {
         return NoAuthorization(print_r(array($trn['RecordedBy'], $split['AccountId']), true));
     }
     $this->transaction->clear();
     $this->transaction->recorded_by = $trn['RecordedBy'];
     $this->transaction->date_created = date("Y-m-d H:i:s");
     $this->transaction->description = $trn['Description'];
     $this->transaction->memo = $trn['Memo'];
     $this->transaction->transaction_date = $trx_date;
     $this->transaction->save();
     $debit = 0.0;
     $credit = 0.0;
     foreach ($splits as $s => $split) {
         $this->split->clear();
         $this->split->transaction_id = $this->transaction->transaction_id;
         $this->split->account_id = $split['AccountId'];
         $this->split->is_dues = $split['IsDues'];
         $this->split->src_mundane_id = $split['SrcMundaneId'];
         $this->split->dues_through = strlen($split['DuesThrough']) > 0 ? $split['DuesThrough'] : null;
         $this->split->amount = round($split['DrCr'] == $this->dr_cr_sign_convention($split['AccountType'], $split['Amount']) ? $split['Amount'] : -$split['Amount'], 3);
         $this->split->save();
         if ($this->dr_cr_sign_convention($split['AccountType'], $split['Amount']) == TreasuryDrCr::Dr) {
             $debit += $this->split->amount;
         } else {
             $credit += $this->split->amount;
         }
     }
     if (abs($debit - $credit) > 0.005) {
         $this->account->clear();
         $this->account->account_id = $this->split->account_id;
         $this->account->find();
         $k = $this->account->kingdom_id;
         $idt = $this->DetermineAuthType() . '_id';
         $id = $this->account->{$idt};
         $this->account->clear();
         $this->account->kingdom_id = $k;
         $this->account->{$idt} = $id;
         $this->account->type = TreasuryAccountType::Imbalance;
         if ($this->account->find()) {
             $this->split->clear();
             $this->split->transaction_id = $this->transaction->transaction_id;
             $this->split->account_id = $split['AccountId'];
             $this->split->is_dues = 0;
             $this->split->src_mundane_id = $split['SrcMundaneId'];
             $this->split->amount = $credit - $debit;
             $this->split->save();
         } else {
             // crap
             return InvalidParameter('Canno record split.');
         }
     }
 }
Пример #9
0
 public function WaffleKingdom($request, $waffle)
 {
     $response = [];
     if (($mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token'])) > 0 && Ork3::$Lib->authorization->HasAuthority($mundane_id, AUTH_ADMIN, 0, AUTH_EDIT)) {
         $this->log->Write('Kingdom', $mundane_id, 'Active' == $waffle ? LOG_RESTORE : LOG_RETIRE, $request);
         $this->kingdom->clear();
         $this->kingdom->kingdom_id = $request['KingdomId'];
         if ($this->kingdom->find()) {
             $this->kingdom->active = $waffle;
             $this->kingdom->save();
             $response = Success();
         } else {
             $response = InvalidParameter(NULL, 'Problem processing request.');
         }
     } else {
         $response = NoAuthorization();
     }
     return $response;
 }
Пример #10
0
 public function SetEvent($request)
 {
     $mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token']);
     if (valid_id($mundane_id) && Ork3::$Lib->authorization->HasAuthority($mundane_id, AUTH_EVENT, $request['EventId'], AUTH_EDIT)) {
         $this->event->clear();
         $this->event->event_id = $request['EventId'];
         $response = array();
         if (valid_id($request['EventId']) && $this->event->find()) {
             if (is_numeric($request['KingdomId'])) {
                 $this->event->kingdom_id = $request['KingdomId'];
             }
             if (is_numeric($request['ParkId'])) {
                 $this->event->park_id = $request['ParkId'];
                 $p = Ork3::$Lib->park->GetParkShortInfo(array('ParkId' => $request['ParkId']));
                 if ($p['Status']['Status'] != 0) {
                     return $p['Status'];
                 } else {
                     $this->event->kingdom_id = $p['KingdomId'];
                 }
             }
             if (is_numeric($request['MundaneId'])) {
                 $this->event->mundane_id = $request['MundaneId'];
             }
             if (is_numeric($request['UnitId'])) {
                 $this->event->unit_id = $request['UnitId'];
             }
             if (trimlen($request['Name'])) {
                 $this->event->name = $request['Name'];
             }
             $this->event->save();
             Ork3::$Lib->heraldry->SetEventHeraldry($request);
             logtrace("SetEvent", array($request, $this->event));
             return Success();
         } else {
             return InvalidParameter('Event Id is not a valid id.');
         }
     } else {
         return NoAuthorization();
     }
 }
Пример #11
0
 public function SetEventHeraldry($request)
 {
     if (($mundane_id = Ork3::$Lib->authorization->IsAuthorized($request['Token'])) > 0 && Ork3::$Lib->authorization->HasAuthority($mundane_id, AUTH_EVENT, $request['EventId'], AUTH_EDIT)) {
         $this->event->clear();
         $this->event->event_id = $request['EventId'];
         if ($this->event->find()) {
             $request = $this->fetch_url_heraldry($request);
             $this->store_heraldry($request, DIR_EVENT_HERALDRY, 5, 'event');
             $this->event->save();
             return Success();
         } else {
             return InvalidParameter();
         }
     } else {
         return NoAuthorization();
     }
 }