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