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) && config::get('apiCharId'){ |
---|
39 | require_once("class.api.php"); |
---|
40 | $api = new Api(); |
---|
41 | $id = $api->getCharId(plt_name); |
---|
42 | if ($id > 0){ |
---|
43 | setCharacterID($id); |
---|
44 | } |
---|
45 | return '?a=thumb&id='.$id.'&size='.$size; |
---|
46 | |
---|
47 | }*/ |
---|
48 | return '?a=thumb&id='.$this->row_['plt_externalid'].'&size='.$size; |
---|
49 | } |
---|
50 | |
---|
51 | function execQuery() |
---|
52 | { |
---|
53 | if (!$this->qry_->executed_) |
---|
54 | { |
---|
55 | $this->sql_ = 'select * from kb3_pilots plt, kb3_corps crp, kb3_alliances ali |
---|
56 | where crp.crp_id = plt.plt_crp_id |
---|
57 | and ali.all_id = crp.crp_all_id |
---|
58 | and plt.plt_id = '.$this->id_; |
---|
59 | $this->qry_->execute($this->sql_) or die($this->qry_->getErrorMsg()); |
---|
60 | $this->row_ = $this->qry_->getRow(); |
---|
61 | if (!$this->row_) |
---|
62 | $this->valid_ = false; |
---|
63 | else |
---|
64 | $this->valid_ = true; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | function getCorp() |
---|
69 | { |
---|
70 | $this->execQuery(); |
---|
71 | return new Corporation($this->row_['plt_crp_id']); |
---|
72 | } |
---|
73 | |
---|
74 | function exists() |
---|
75 | { |
---|
76 | $this->execQuery(); |
---|
77 | return $this->valid_; |
---|
78 | } |
---|
79 | |
---|
80 | function add($name, $corp, $timestamp) |
---|
81 | { |
---|
82 | $qry = new DBQuery(); |
---|
83 | $qry->execute("select * |
---|
84 | from kb3_pilots |
---|
85 | where plt_name = '".slashfix($name)."'"); |
---|
86 | |
---|
87 | if ($qry->recordCount() == 0) |
---|
88 | { |
---|
89 | $qry->execute("insert into kb3_pilots values ( null, |
---|
90 | '".slashfix($name)."', |
---|
91 | ".$corp->getID().", |
---|
92 | 0, 0, 0, |
---|
93 | date_format( '".$timestamp."', '%Y.%m.%d %H:%i:%s'))"); |
---|
94 | $this->id_ = $qry->getInsertID(); |
---|
95 | } |
---|
96 | else |
---|
97 | { |
---|
98 | $row = $qry->getRow(); |
---|
99 | $this->id_ = $row['plt_id']; |
---|
100 | if ($this->isUpdatable($timestamp) && $row['plt_crp_id'] != $corp->getID()) |
---|
101 | { |
---|
102 | $qry->execute("update kb3_pilots |
---|
103 | set plt_crp_id = ".$corp->getID().", |
---|
104 | plt_updated = date_format( '".$timestamp."', '%Y.%m.%d %H:%i:%s') where plt_id = ".$this->id_); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | return $this->id_; |
---|
109 | } |
---|
110 | |
---|
111 | function isUpdatable($timestamp) |
---|
112 | { |
---|
113 | $qry = new DBQuery(); |
---|
114 | $qry->execute("select plt_id |
---|
115 | from kb3_pilots |
---|
116 | where plt_id = ".$this->id_." |
---|
117 | and ( plt_updated < date_format( '".$timestamp."', '%Y.%m.%d %H:%i') |
---|
118 | or plt_updated is null )"); |
---|
119 | |
---|
120 | return $qry->recordCount() == 1; |
---|
121 | } |
---|
122 | |
---|
123 | function setCharacterID($id) |
---|
124 | { |
---|
125 | $id = intval($id); |
---|
126 | if (!$id) |
---|
127 | { |
---|
128 | return false; |
---|
129 | } |
---|
130 | $qry = new DBQuery(); |
---|
131 | $qry->execute("update kb3_pilots set plt_externalid = ".$id." |
---|
132 | where plt_id = ".$this->id_); |
---|
133 | } |
---|
134 | } |
---|
135 | ?> |
---|