1 | <?php |
---|
2 | require_once('class.corp.php'); |
---|
3 | require_once('class.item.php'); |
---|
4 | |
---|
5 | class Pilot |
---|
6 | { |
---|
7 | function Pilot($id = 0) |
---|
8 | { |
---|
9 | $this->id_ = intval($id); |
---|
10 | $this->qry_ = new DBQuery(); |
---|
11 | } |
---|
12 | |
---|
13 | function getID() |
---|
14 | { |
---|
15 | return $this->id_; |
---|
16 | } |
---|
17 | |
---|
18 | function getName() |
---|
19 | { |
---|
20 | $this->execQuery(); |
---|
21 | $pos = strpos($this->row_['plt_name'], "#"); |
---|
22 | if ($pos === false) |
---|
23 | { |
---|
24 | return $this->row_['plt_name']; |
---|
25 | } |
---|
26 | else |
---|
27 | { |
---|
28 | $name = explode("#", $this->row_['plt_name']); |
---|
29 | $item = new Item($name[2]); |
---|
30 | return $item->getName(); |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | function getPortraitURL($size = 64) |
---|
35 | { |
---|
36 | $this->execQuery(); |
---|
37 | //charID api readout - in work, feel free to test |
---|
38 | if ($this->row_['plt_externalid'] == 0) |
---|
39 | { |
---|
40 | require_once("class.api.php"); |
---|
41 | $api = new Api(); |
---|
42 | $id = $api->getCharId($this->getName()); |
---|
43 | if ($id > 0) |
---|
44 | $this->setCharacterID($id); |
---|
45 | |
---|
46 | return '?a=thumb&id='.$id.'&size='.$size; |
---|
47 | |
---|
48 | } |
---|
49 | else |
---|
50 | return '?a=thumb&id='.$this->row_['plt_externalid'].'&size='.$size; |
---|
51 | } |
---|
52 | |
---|
53 | function execQuery() |
---|
54 | { |
---|
55 | if (!$this->qry_->executed_) |
---|
56 | { |
---|
57 | $this->sql_ = 'select * from kb3_pilots plt, kb3_corps crp, kb3_alliances ali |
---|
58 | where crp.crp_id = plt.plt_crp_id |
---|
59 | and ali.all_id = crp.crp_all_id |
---|
60 | and plt.plt_id = '.$this->id_; |
---|
61 | $this->qry_->execute($this->sql_) or die($this->qry_->getErrorMsg()); |
---|
62 | $this->row_ = $this->qry_->getRow(); |
---|
63 | if (!$this->row_) |
---|
64 | $this->valid_ = false; |
---|
65 | else |
---|
66 | $this->valid_ = true; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | function getCorp() |
---|
71 | { |
---|
72 | $this->execQuery(); |
---|
73 | return new Corporation($this->row_['plt_crp_id']); |
---|
74 | } |
---|
75 | |
---|
76 | function exists() |
---|
77 | { |
---|
78 | $this->execQuery(); |
---|
79 | return $this->valid_; |
---|
80 | } |
---|
81 | |
---|
82 | function add($name, $corp, $timestamp) |
---|
83 | { |
---|
84 | $qry = new DBQuery(); |
---|
85 | $qry->execute("select * |
---|
86 | from kb3_pilots |
---|
87 | where plt_name = '".slashfix($name)."'"); |
---|
88 | |
---|
89 | if ($qry->recordCount() == 0) |
---|
90 | { |
---|
91 | $qry->execute("insert into kb3_pilots values ( null, |
---|
92 | '".slashfix($name)."', |
---|
93 | ".$corp->getID().", |
---|
94 | 0, 0, 0, |
---|
95 | date_format( '".$timestamp."', '%Y.%m.%d %H:%i:%s'))"); |
---|
96 | $this->id_ = $qry->getInsertID(); |
---|
97 | } |
---|
98 | else |
---|
99 | { |
---|
100 | $row = $qry->getRow(); |
---|
101 | $this->id_ = $row['plt_id']; |
---|
102 | if ($this->isUpdatable($timestamp) && $row['plt_crp_id'] != $corp->getID()) |
---|
103 | { |
---|
104 | $qry->execute("update kb3_pilots |
---|
105 | set plt_crp_id = ".$corp->getID().", |
---|
106 | plt_updated = date_format( '".$timestamp."', '%Y.%m.%d %H:%i:%s') where plt_id = ".$this->id_); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | return $this->id_; |
---|
111 | } |
---|
112 | |
---|
113 | function isUpdatable($timestamp) |
---|
114 | { |
---|
115 | $qry = new DBQuery(); |
---|
116 | $qry->execute("select plt_id |
---|
117 | from kb3_pilots |
---|
118 | where plt_id = ".$this->id_." |
---|
119 | and ( plt_updated < date_format( '".$timestamp."', '%Y.%m.%d %H:%i') |
---|
120 | or plt_updated is null )"); |
---|
121 | |
---|
122 | return $qry->recordCount() == 1; |
---|
123 | } |
---|
124 | |
---|
125 | function setCharacterID($id) |
---|
126 | { |
---|
127 | $id = intval($id); |
---|
128 | if (!$id) |
---|
129 | { |
---|
130 | return false; |
---|
131 | } |
---|
132 | $qry = new DBQuery(); |
---|
133 | $qry->execute("update kb3_pilots set plt_externalid = ".$id." |
---|
134 | where plt_id = ".$this->id_); |
---|
135 | } |
---|
136 | } |
---|
137 | ?> |
---|