/
bannerclient.php
199 lines (167 loc) · 5.38 KB
/
bannerclient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* @version $Id$
* @package Joomla
* @subpackage Banners
* @copyright Copyright (C) 2005 - 2006 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* @package Joomla
* @subpackage Banners
*/
class BannerClientController
{
function viewBannerClients()
{
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$context = "com_banners.viewbannerclient";
$filter_order = $mainframe->getUserStateFromRequest( "$context.filter_order", 'filter_order', 'a.cid' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$context.filter_order_Dir", 'filter_order_Dir', '' );
$limit = $mainframe->getUserStateFromRequest( 'limit', 'limit', $mainframe->getCfg('list_limit') );
$limitstart = $mainframe->getUserStateFromRequest( "$context.limitstart", 'limitstart', 0 );
$search = $mainframe->getUserStateFromRequest( "$context.search", 'search', '' );
$search = $db->getEscaped( JString::strtolower( $search ) );
$where = array();
if ($search) {
$where[] = "LOWER(a.name) LIKE '%$search%'";
}
$where = ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' );
$orderby = "\n ORDER BY $filter_order $filter_order_Dir, a.cid";
// get the total number of records
$query = "SELECT a.*, count(b.bid) AS bid, u.name AS editor"
. "\n FROM #__bannerclient AS a"
. "\n LEFT JOIN #__banner AS b ON a.cid = b.cid"
. "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"
. $where
. "\n GROUP BY a.cid"
. $orderby
;
$db->setQuery( $query );
$db->query();
$total = $db->getNumRows();
jimport('joomla.presentation.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$rows = $db->loadObjectList();
// table ordering
if ( $filter_order_Dir == 'DESC' ) {
$lists['order_Dir'] = 'ASC';
} else {
$lists['order_Dir'] = 'DESC';
}
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
require_once(JPATH_COM_BANNERS.DS.'views'.DS.'client.php');
BannersViewClients::showClients( $rows, $pageNav, 'com_banners', $lists );
}
/**
* Edit a banner client record
*/
function editBannerClient()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$userId = $user->get ( 'id' );
$cid = JRequest::getVar( 'cid', array(0), 'method', 'array' );
$row =& JTable::getInstance('bannerclient', $db, 'Table');
$row->load( (int) $cid[0] );
// fail if checked out not by 'me'
if ($row->isCheckedOut( $userId )) {
$msg = sprintf( JText::_( 'WARNEDITEDBYPERSON' ), $row->name );
$mainframe->redirect( 'index2.php?option=com_banners&task=listclients', $msg );
}
if ($row->id) {
// do stuff for existing record
$row->checkout( $userId );
} else {
// do stuff for new record
$row->published = 0;
$row->approved = 0;
}
require_once(JPATH_COM_BANNERS.DS.'views'.DS.'client.php');
BannersViewClients::bannerClientForm( $row, 'com_banners' );
}
function saveBannerClient()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$table =& JTable::getInstance('bannerclient', $db, 'Table');
$post = JRequest::get( 'post' );
if (!$table->bind( $post )) {
echo "<script> alert('".$table->getError()."'); window.history.go(-1); </script>\n";
exit();
}
if (!$table->check()) {
echo "<script> alert('".$table->getError()."'); window.history.go(-1); </script>\n";
}
if (!$table->store()) {
echo "<script> alert('".$table->getError()."'); window.history.go(-1); </script>\n";
exit();
}
$table->checkin();
$task = JRequest::getVar( 'task' );
switch ($task) {
case 'applyclient':
$link = 'index2.php?option=com_banners&task=editclient&cid[]='. $table->cid .'&hidemainmenu=1';
break;
case 'saveclient':
default:
$link = 'index2.php?option=com_banners&task=listclients';
break;
}
$mainframe->redirect( $link );
}
function cancelEditClient()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$table =& JTable::getInstance('bannerclient', $db, 'Table');
$table->id = JRequest::getVar( 'cid', 0, 'post', 'int' );
$table->checkin();
$mainframe->redirect( "index2.php?option=com_banners&task=listclients" );
}
function removeBannerClients()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$table =& JTable::getInstance('bannerclient', $db, 'Table');
$msg = '';
for ($i = 0, $n = count( $cid ); $i < $n; $i++)
{
$query = "SELECT COUNT( bid )"
. "\n FROM #__banner"
. "\n WHERE cid = ". (int) $cid[$i]
;
$db->setQuery($query);
if (($count = $db->loadResult()) === null)
{
$msg = $db->getErrorMsg();
}
else if ($count > 0)
{
$msg = JText::_( 'WARNCANNOTDELCLIENTBANNER' );
}
else
{
$table->delete( (int) $cid[$i] );
}
}
$mainframe->redirect( 'index2.php?option=com_banners&task=listclients', $msg, 'error' );
}
}
?>