Moved "fix" files (which only helps to fix stuff) in own inc/fixes/ folder.
[mailer.git] / inc / pool-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 01/22/2013 *
4  * ===================                          Last change: 01/22/2013 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : pool-functions.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for handling status codes              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen zum Umgang mit Status-Funktionen      *
12  * -------------------------------------------------------------------- *
13  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2016 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         die();
36 } // END - if
37
38 // "Getter" for pool data from given id number
39 // @TODO "Hook" ext-html_mail into this to allow column `html_msg`
40 function getPoolDataFromId ($poolId) {
41         // Init content array
42         $content = array();
43
44         // Search for pool data
45         $result = sqlQueryEscaped('SELECT
46         `id`,
47         `sender`,
48         `subject`,
49         `text`,
50         `receivers`,
51         `payment_id`,
52         `data_type`,
53         `timestamp`,
54         `url`,
55         `target_send`,
56         `cat_id`,
57         `zip`
58 FROM
59         `{?_MYSQL_PREFIX?}_pool`
60 WHERE
61         `id`=%s
62 LIMIT 1',
63                 array(bigintval($poolId)), __FUNCTION__, __LINE__);
64
65         // Is there an entry?
66         if (sqlNumRows($result) == 1) {
67                 // Load data
68                 $content = sqlFetchArray($result);
69         } // END - if
70
71         // Free result
72         sqlFreeResult($result);
73
74         // Return found data
75         return $content;
76 }
77
78 // Update the pool
79 function updatePoolDataById ($poolId, $columnName, $data, $updateMode = NULL, $whereSql = '', $moreSql = '') {
80         // Is update mode set?
81         if (!is_null($updateMode)) {
82                 // Don't allow array as data here
83                 assert(!is_array($data));
84
85                 // Then use this on the column with this mode (mostly counters)
86                 sqlQueryEscaped('UPDATE `{?_MYSQL_PREFIX?}_pool` SET `%s`=`%s`%s%s WHERE `id`=%s' . $whereSql . ' LIMIT 1',
87                         array(
88                                 $columnName,
89                                 $columnName,
90                                 $updateMode,
91                                 $data,
92                                 bigintval($poolId)
93                         ), __FUNCTION__, __LINE__);
94         } elseif (is_array($data)) {
95                 /*
96                  * Update multiple columns, $columnName and $updateMode are being
97                  * ignored as last doesn't work and first is given in $data array.
98                  */
99                 $sql = 'UPDATE `{?_MYSQL_PREFIX?}_pool` SET ';
100                 foreach ($data as $key => $value) {
101                         // Add it
102                         $sql .= sprintf("`%s`='%s',", sqlEscapeString($key), sqlEscapeString($value));
103                 } // END - foreach
104
105                 // Finish SQL
106                 $sql = substr($sql, 0, -1) . $moreSql . ' WHERE `id`=' . bigintval($id) . $whereSql . ' LIMIT 1';
107
108                 // And finally run it
109                 sqlQuery($sql, __FUNCTION__, __LINE__);
110         } else {
111                 // Regular update
112                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `%s`='%s' WHERE `id`=%s" . $whereSql . ' LIMIT 1',
113                         array(
114                                 $columnName,
115                                 $data,
116                                 bigintval($poolId)
117                         ), __FUNCTION__, __LINE__);
118         }
119
120         // Return if it has an affected row
121         return (sqlAffectedRows() == 1);
122 }
123
124 // Insert data into pool and return its insert id
125 function insertDataIntoPool ($data) {
126         // Construct SQL query
127         $sql = 'INSERT INTO `{?_MYSQL_PREFIX?}_pool (`' . implode('`,`', array_map('SQL_ESCAPE', array_keys($data))) . "`) VALUES ('" . implode("','", array_values($data)) . "')";
128
129         // Run the query
130         sqlQuery($sql, __FUNCTION__, __LINE__);
131
132         // Return insert id
133         return getSqlInsertId();
134 }
135
136 // [EOF]
137 ?>