Newer
Older
* AWIT ZACR - COZA EPP Module
* Copyright (c) 2014, AllWorldIT
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Make sure we not being accssed directly
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
// Our global supported field list
$AWIT_ZACR_SUPPORTED_FIELDS = array(
function awit_zacr_config()
{
// Configuration
$configarray = array(
"description" => "This module is to facilitate displaying of epp messages.",
"version" => "0.1",
"author" => "AllWorldIT",
"language" => "english",
"fields" => array(
// Admin User
"max_items" => array (
"FriendlyName" => "Items Per Page",
"Description" => "Amount of items to list per page",
"Type" => "text", "Size" => "30",
"Default" => "100"
),
)
);
return $configarray;
}
function awit_zacr_get_config_custom_fields()
global $AWIT_ZACR_SUPPORTED_FIELDS;
// Query modules table
$table = "tbladdonmodules";
$fields = "setting,value";
$where = array( 'module' => 'awit_zacr' );
$result = select_query($table,$fields,$where);
// Filter out the settings we need
$custom_fields = array();
while ($row = mysql_fetch_array($result)) {
// Check in our global list
if (in_array($row['setting'],$AWIT_ZACR_SUPPORTED_FIELDS)) {
$custom_fields[$row['setting']] = $row['value'];
}
}
return $custom_fields;
}
function _awit_zacr_getMaxItems()
$customFields = awit_zacr_get_config_custom_fields();
return $customFields['max_items'];
}
// Addon activation
function awit_zacr_activate()
{
// Create Custom DB Table
$result = mysql_query("
CREATE TABLE `mod_awit_zacr_messages` (
`id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`created` DATETIME NOT NULL,
`code` VARCHAR(10) NOT NULL,
`message` TEXT NOT NULL
)
");
// Return Result
if (!$result) {
return array("status" => "error", "description"=>"There was a problem activating the module.");
} else {
return array("status" => "success","description" =>"Open module configuration for configuration options.");
}
}
function awit_zacr_deactivate()
$result = mysql_query("
DROP TABLE `mod_awit_zacr_messages`
return array("status"=>"error","description"=>"There was an error deactivating the module.");
} else {
return array("status"=>"success","description"=>"Module has been deactivated.");
}
}
// Addon output
function awit_zacr_output($vars)
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{
// Check if we have to display all records
if (isset($_POST['button']) && $_POST['button'] == 'Display All') {
$whereClause = '';
} else if (!empty($_POST['date_to']) && !empty($_POST['date_from'])) {
// Default dates
try {
$dateTo = new DateTime($_POST['date_to']);
$dateTo = $dateTo->format('Y-m-d');
$dateFrom = new DateTime($_POST['date_from']);
$dateFrom = $dateFrom->format('Y-m-d');
} catch (Exception $ex) {
// Catching exception against valid date
$dateFrom = new DateTime(date("Y-m-d"));
$dateFrom = $dateFrom->format('Y-m-d');
$dateFrom->modify('+1 day');
$dateTo = $dateTo->format('Y-m-d');
}
$whereClause = "WHERE Date(created) >= Date('".mysql_real_escape_string($dateFrom)."')
AND Date(created) <= Date('".mysql_real_escape_string($dateTo)."')";
}
// Make link to use
$link = $vars['modulelink'];
// Fancy date picker
echo '
<script>
$(function() {
$( "#date_from" ).datepicker({
dateFormat: "yy-mm-dd",
constrainInput: true
});
$( "#date_to" ).datepicker({
dateFormat: "yy-mm-dd",
constrainInput: true
});
// Date search fields
echo "<p>Select a start and end date and hit search.</p>";
echo "<form action='$link' method='post'>";
echo "<input id='date_from' type='text' value='$dateFrom' name='date_from' />";
echo "<input id='date_to' type='text' value='$dateTo' name='date_to' />";
echo "<input type='submit' name='button' value='Search' />";
echo "<input type='submit' name='button' value='Display All' />";
echo "<br /><br />";
$orderClause = 'ORDER BY created DESC';
// Max amount of records to show per page
$recordMax = _awit_zacr_getMaxItems();
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Validation
if (!is_numeric($recordMax)) {
$recordMax = 100;
}
// Setting page number
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else if (isset($_POST['page'])) {
$page = $_POST['page'];
}
// Ensuring valid page number
if ($page < 1) {
$page = 1;
}
// Pagination button handler
if (isset($_POST['prevPage'])) {
// Prev Page
$page = ($page > 1)? ($page - 1) : 1;
} else if (isset($_POST['nextPage'])) {
// Next Page
$page = $page + 1;
}
$recordCurrent = intval(abs($recordMax * $page)) - $recordMax;
$limitClause = "LIMIT $recordCurrent, $recordMax";
// Query the database, getting the total amount of records
$result = mysql_query(sprintf("
mod_awit_zacr_messages
$row = mysql_fetch_array($result);
$totalRecords = $row['cnt'];
$lastPage = ceil($totalRecords / $recordMax);
// Query the database
$result = mysql_query(sprintf("
mod_awit_zacr_messages
%s %s %s
",
$whereClause,
$orderClause,
$limitClause
));
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// Loop through results and genenrate form
$includeForm = 0;
while ($row = mysql_fetch_array($result)) {
// Open form
if (!$includeForm) {
$includeForm = 1;
echo '<div class="tablebg">';
echo '<table id="epp-message-log" class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">';
echo "<tr>";
echo "<th>Timestamp</th>";
echo "<th>Code</th>";
echo "<th>Message</th>";
echo "</tr>";
}
echo "<tr>";
echo "<td>".$row['created']."</td>";
echo "<td>".$row['code']."</td>";
echo "<td>".$row['message']."</td>";
echo "</tr>";
}
// Close form
if ($includeForm) {
echo "<tr><td colspan='5'>";
if ($page >= $lastPage) {
echo "<button name='prevPage'> << Previous Page </button> Page $page";
} else if ($page == 1) {
echo " Page $page <button name='nextPage'> Next Page >> </button>";
} else {
echo "<button name='prevPage'> << Previous Page </button> Page $page";
echo "<button name='nextPage'> Next Page >> </button>";
}
echo "</td></tr>";
echo "</table><br>";
echo "<input type='hidden' name='page' value='$page'>";
echo "</form>";
echo "</div>";
} else {
echo "<p>No logs yet for selected period..</p>";
}
}