root/donation/files/lib/acp/form/DonationAddForm.class.php @ 108

Revision 108, 3.6 kB (checked in by d0nut, 5 years ago)
  • first effort: all packages are installable
  • second effort: the concept works
  • what follows: the implementation ;)
Line 
1<?php
2require_once(WCF_DIR.'lib/acp/form/ACPForm.class.php');
3require_once(WCF_DIR.'lib/acp/form/UserOptionListForm.class.php');
4
5/**
6 * acp: donation add
7 *
8 * @author      Torben Brodt
9 * @package     de.easy-coding.wcf.donation
10 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
11 */
12class DonationAddForm extends UserOptionListForm {
13        public $templateName = 'donationAdd';
14       
15        // data
16        public $donationID, $system, $timestamp, $userID, $username, $amount, $message;
17       
18        /**
19         * @see Page::show()
20         */
21        public function show() {
22                // enable menu item
23                WCFACP::getMenu()->setActiveMenuItem('wcf.acp.menu.link.content.donation');
24
25                parent::show();
26        }
27       
28        /**
29         * @see Page::readParameters()
30         */
31        public function readParameters() {
32                parent::readParameters();
33        }
34
35        /**
36         * @see Form::readFormParameters()
37         */
38        public function readFormParameters() {
39                parent::readFormParameters();
40                               
41                if (isset($_POST['donationID']))        $this->donationID       = intval($_POST['donationID']);
42                if (isset($_POST['system']))            $this->system           = $_POST['system'];
43                if (isset($_POST['timestamp']))         $this->timestamp        = $_POST['timestamp'];
44                if (isset($_POST['userID']))            $this->userID           = intval($_POST['userID']);
45                if (isset($_POST['username']))          $this->username         = $_POST['username'];
46                if (isset($_POST['amount']))            $this->amount           = floatval($_POST['amount']);
47                if (isset($_POST['message']))           $this->message          = $_POST['message'];
48        }
49       
50        /**
51         * @see Form::validate()
52         */
53        public function validate() {
54                               
55        }
56
57        /**
58         * Create the data of an new game.
59         */
60        public function save() {
61                $time = $this->timestamp; //TODO: convert in int
62                if ($this->action == 'add'){
63                        $sql = "INSERT INTO     wcf".WCF_N."_donation
64                                                (donationID, system, timestamp, userID, username, amount, message)
65                                VALUES          (       
66                                                        ".$this->donationID.",
67                                                        '".escapeString($this->system)."',
68                                                        ".$time.",
69                                                        ".$this->userID.",
70                                                        '".escapeString($this->username)."',
71                                                        ".$this->amount.",
72                                                        '".escapeString($this->message)."'
73                                                )";
74                } else {
75                        $sql = "UPDATE          wcf".WCF_N."_donation
76                                SET             
77                                                donationID=".$this->donationID.",
78                                                system='".escapeString($this->system)."',
79                                                timestamp='".$time."',
80                                                userID=".$this->userID.",
81                                                username='".escapeString($this->username)."',
82                                                amount=".$this->amount.",
83                                                message='".escapeString($this->message)."',
84                                WHERE           donationID = ".$this->donationID;
85                }
86               
87                WCF::getDB()->sendQuery($sql);
88
89                // forward to list page
90                header('Location: index.php?page=DonationList&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED);
91                exit;
92               
93        }
94       
95        /**
96         * @see Page::readData()
97         */
98        public function readData() {
99                parent::readData();
100               
101                if(!empty($this->donationID)) {
102                        $sql = "SELECT          system,
103                                                timestamp,
104                                                userID,
105                                                username,
106                                                amount,
107                                                message
108                                FROM            wcf".WCF_N."_donation
109                                WHERE           donationID = ".$this->donationID;
110
111                        $row = WCF::getDB()->getFirstRow($sql);
112                        $this->system = $row['system'];
113                        $this->timestamp = date('Y-m-d', $row['timestamp']); // TODO: convert
114                        $this->userID = $row['userID'];
115                        $this->username = $row['username'];
116                        $this->amount = $row['amount'];
117                        $this->message = $row['message'];
118                }
119        }
120
121        /**
122         * @see Page::assignVariables()
123         */
124        public function assignVariables() {
125                parent::assignVariables();
126
127                WCF::getTPL()->assign(array(
128                        'donationID'    => $this->donationID,
129                        'system'        => $this->system,
130                        'timestamp'     => $this->timestamp,
131                        'userID'        => $this->userID,
132                        'username'      => $this->username,
133                        'amount'        => $this->amount,
134                        'message'       => $this->message
135                ));
136        }
137}
138?>
Note: See TracBrowser for help on using the browser.