/
banner-zone.php
362 lines (308 loc) · 13.8 KB
/
banner-zone.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
/*
+---------------------------------------------------------------------------+
| Revive Adserver |
| http://www.revive-adserver.com |
| |
| Copyright: See the COPYRIGHT.txt file. |
| License: GPLv2 or later, see the LICENSE.txt file. |
+---------------------------------------------------------------------------+
*/
// Require the initialisation file
require_once '../../init.php';
// Required files
require_once MAX_PATH . '/www/admin/lib-maintenance-priority.inc.php';
require_once MAX_PATH . '/www/admin/config.php';
require_once MAX_PATH . '/www/admin/lib-statistics.inc.php';
require_once MAX_PATH . '/www/admin/lib-zones.inc.php';
require_once MAX_PATH . '/www/admin/lib-size.inc.php';
require_once MAX_PATH . '/lib/max/other/common.php';
require_once MAX_PATH . '/lib/max/other/html.php';
require_once MAX_PATH . '/lib/max/other/stats.php';
require_once MAX_PATH . '/lib/max/Admin_DA.php';
require_once MAX_PATH . '/lib/OA/Maintenance/Priority.php';
// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_MANAGER);
OA_Permission::enforceAccessToObject('clients', $clientid);
OA_Permission::enforceAccessToObject('campaigns', $campaignid);
OA_Permission::enforceAccessToObject('banners', $bannerid);
OA_Permission::checkSessionToken();
/*-------------------------------------------------------*/
/* Store preferences */
/*-------------------------------------------------------*/
$session['prefs']['inventory_entities'][OA_Permission::getEntityId()]['clientid'] = $clientid;
$session['prefs']['inventory_entities'][OA_Permission::getEntityId()]['campaignid'][$clientid] = $campaignid;
phpAds_SessionDataStore();
// Get input parameters
$advertiserId = MAX_getValue('clientid');
$campaignId = MAX_getValue('campaignid');
$bannerId = MAX_getValue('bannerid');
$aCurrentZones = MAX_getValue('includezone');
$listorder = MAX_getStoredValue('listorder', 'name');
$orderdirection = MAX_getStoredValue('orderdirection', 'up');
$submit = MAX_getValue('submit');
// Initialise some parameters
$pageName = basename($_SERVER['SCRIPT_NAME']);
$tabindex = 1;
$agencyId = OA_Permission::getAgencyId();
$aEntities = array('clientid' => $advertiserId, 'campaignid' => $campaignId, 'bannerid' => $bannerId);
// Process submitted form
if (isset($submit))
{
$dalZones = OA_Dal::factoryDAL('zones');
$prioritise = false;
$error = false;
$aPreviousZones = Admin_DA::getAdZones(array('ad_id' => $bannerId));
$aDeleteZones = array();
// First, remove any zones that should be deleted.
if (!empty($aPreviousZones)) {
$unlinked = 0;
foreach ($aPreviousZones as $aAdZone) {
$zoneId = $aAdZone['zone_id'];
if ((empty($aCurrentZones[$zoneId])) && ($zoneId > 0)) {
// Schedule for deletion
$aDeleteZones[] = $zoneId;
} else {
// Remove this key, because it is already there and does not need to be added again.
unset($aCurrentZones[$zoneId]);
}
}
}
// Unlink zones
if (count($aDeleteZones)) {
$unlinked = $dalZones->unlinkZonesFromBanner($aDeleteZones, $bannerId);
if ($unlinked > 0) {
$prioritise = true;
} elseif ($unlinked == -1) {
$error = true;
}
}
// Link zones
if (count($aCurrentZones)) {
$linked = $dalZones->linkZonesToBanner(array_keys($aCurrentZones), $bannerId);
if (PEAR::isError($linked)
|| $linked == -1) {
$error = $linked;
} elseif($linked > 0) {
$prioritise = true;
}
}
if ($prioritise) {
// Run the Maintenance Priority Engine process
OA_Maintenance_Priority::scheduleRun();
}
// Move on to the next page
if (!$error) {
// Queue confirmation message
$translation = new OX_Translation ();
if ($linked > 0) {
$linked_message = $translation->translate ( $GLOBALS['strXZonesLinked'], array($linked));
}
if ($unlinked > 0) {
$unlinked_message = $translation->translate ( $GLOBALS['strXZonesUnlinked'], array($unlinked));
}
if ($linked > 0 || $unlinked > 0) {
$translated_message = $linked_message. ($linked_message != '' && $unlinked_message != '' ? ', ' : ' ').$unlinked_message;
OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
}
Header("Location: banner-zone.php?clientid={$clientid}&campaignid={$campaignid}&bannerid={$bannerid}");
exit;
}
}
// Display navigation
$aOtherCampaigns = Admin_DA::getPlacements(array('agency_id' => $agencyId));
$aOtherBanners = Admin_DA::getAds(array('placement_id' => $campaignId), false);
MAX_displayNavigationBanner($pageName, $aOtherCampaigns, $aOtherBanners, $aEntities);
// Main code
$aAd = Admin_DA::getAd($bannerId);
$aParams = array('agency_id' => $agencyId);
if ($aAd['type'] == 'txt') {
$aParams['zone_type'] = phpAds_ZoneText;
} else {
$aParams['zone_width'] = $aAd['width'] . ',-1';
$aParams['zone_height'] = $aAd['height'] . ',-1';
}
$aPublishers = Admin_DA::getPublishers($aParams, true);
$aLinkedZones = Admin_DA::getAdZones(array('ad_id' => $bannerId), false, 'zone_id');
echo "
<table border='0' width='100%' cellpadding='0' cellspacing='0'>
<form name='zones' action='$pageName' method='post'>
<input type='hidden' name='clientid' value='$advertiserId'>
<input type='hidden' name='campaignid' value='$campaignId'>
<input type='hidden' name='bannerid' value='$bannerId'>";
MAX_displayZoneHeader($pageName, $listorder, $orderdirection, $aEntities);
if ($error) {
$errorMoreInformation = '';
if (PEAR::isError($error)) {
$errorMoreInformation = $error->getMessage();
}
// Message
echo "<br>";
echo "<div class='errormessage'><img class='errormessage' src='" . OX::assetPath() . "/images/errormessage.gif' align='absmiddle'>";
echo "<span class='tab-r'> {$GLOBALS['strUnableToLinkBanner']}</span><br /><br />";
echo "{$GLOBALS['strErrorLinkingBanner']} <br />" . $errorMoreInformation . "</div><br />";
} else {
echo "<br /><br />";
}
$zoneToSelect = false;
if (!empty($aPublishers)) {
MAX_sortArray($aPublishers, ($listorder == 'id' ? 'publisher_id' : $listorder), $orderdirection == 'up');
$i=0;
//select all checkboxes
$publisherIdList = '';
foreach ($aPublishers as $publisherId => $aPublisher) {
$publisherIdList .= $publisherId . '|';
}
echo"<input type='checkbox' id='selectAllField' onClick='toggleAllZones(\"".$publisherIdList."\");'><label for='selectAllField'>".$strSelectUnselectAll."</label>";
foreach ($aPublishers as $publisherId => $aPublisher) {
$publisherName = $aPublisher['name'];
$aZones = Admin_DA::getZones($aParams + array('publisher_id' => $publisherId), true);
if (!empty($aZones)) {
$zoneToSelect = true;
$bgcolor = ($i % 2 == 0) ? " bgcolor='#F6F6F6'" : '';
$bgcolorSave = $bgcolor;
$allchecked = true;
foreach ($aZones as $zoneId => $aZone) {
if (!isset($aLinkedZones[$zoneId])) {
$allchecked = false;
break;
}
}
$checked = $allchecked ? ' checked' : '';
if ($i > 0) echo "
<tr height='1'>
<td colspan='3' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td>
</tr>";
echo "
<tr height='25'$bgcolor>
<td>
<table>
<tr>
<td> </td>
<td valign='top'><input id='affiliate$publisherId' name='affiliate[$publisherId]' type='checkbox' value='t'$checked onClick='toggleZones($publisherId);' tabindex='$tabindex'> </td>
<td valign='top'><img src='" . OX::assetPath() . "/images/icon-affiliate.gif' align='absmiddle'> </td>
<td><a href='affiliate-edit.php?affiliateid=$publisherId'>".htmlspecialchars($publisherName)."</a> </td>
</tr>
</table>
</td>
<td>$publisherId</td>
<td height='25'> </td>
</tr>";
$tabindex++;
if (!empty($aZones)) {
MAX_sortArray($aZones, ($listorder == 'id' ? 'zone_id' : $listorder), $orderdirection == 'up');
foreach($aZones as $zoneId => $aZone) {
$zoneName = $aZone['name'];
$zoneDescription = $aZone['description'];
$zoneIsActive = (isset($aZone['active']) && $aZone['active'] == 't') ? true : false;
$zoneIcon = MAX_getEntityIcon('zone', $zoneIsActive, $aZone['type']);
$checked = isset($aLinkedZones[$zoneId]) ? ' checked' : '';
$bgcolor = ($checked == ' checked') ? " bgcolor='#d8d8ff'" : $bgcolorSave;
echo "
<tr height='25'$bgcolor>
<td>
<table>
<tr>
<td width='28'> </td>
<td valign='top'><input name='includezone[$zoneId]' id='a$publisherId' type='checkbox' value='t'$checked onClick='toggleAffiliate($publisherId);' tabindex='$tabindex'> </td>
<td valign='top'><img src='$zoneIcon' align='absmiddle'> </td>
<td><a href='zone-edit.php?affiliateid=$publisherId&zoneid=$zoneId'>".htmlspecialchars($zoneName)."</a> </td>
</tr>
</table>
</td>
<td>$zoneId</td>
<td>".htmlspecialchars($zoneDescription)."</td>
</tr>";
}
}
$i++;
}
}
echo "
<tr height='1'><td colspan='3' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td></tr>";
}
if (!$zoneToSelect) {
echo "
<tr height='25' bgcolor='#F6F6F6'>
<td colspan='4'> {$GLOBALS['strNoZonesToLinkToCampaign']}</td>
</tr>
<tr height='1'><td colspan='3' bgcolor='#888888'><img src='" . OX::assetPath() . "/images/break.gif' height='1' width='100%'></td></tr>";
}
echo "
</table>";
echo "
<br /><br />
<input type='submit' name='submit' value='{$GLOBALS['strSaveChanges']}' tabindex='$tabindex'>";
$tabindex++;
echo "
</form>";
/*-------------------------------------------------------*/
/* Form requirements */
/*-------------------------------------------------------*/
?>
<script language='Javascript'>
<!--
affiliates = new Array();
<?php
if (!empty($aPublishersZones)) {
foreach ($aPublishersZones as $publisherId => $aPublishersZone) {
if (!empty($aPublishersZone['children'])) {
$num = count($aPublishersZone['children']);
echo "
affiliates[$publisherId] = $num;";
}
}
}
?>
function toggleAffiliate(affiliateid)
{
var count = 0;
var affiliate;
for (var i=0; i<document.zones.elements.length; i++)
{
if (document.zones.elements[i].name == 'affiliate[' + affiliateid + ']')
affiliate = i;
if (document.zones.elements[i].id == 'a' + affiliateid + '' &&
document.zones.elements[i].checked)
count++;
}
document.zones.elements[affiliate].checked = (count == affiliates[affiliateid]);
}
function toggleZones(affiliateid)
{
var checked
for (var i=0; i<document.zones.elements.length; i++)
{
if (document.zones.elements[i].name == 'affiliate[' + affiliateid + ']')
checked = document.zones.elements[i].checked;
if (document.zones.elements[i].id == 'a' + affiliateid + '')
document.zones.elements[i].checked = checked;
}
}
function toggleAllZones(zonesList)
{
var zonesArray, checked, selectAllField;
selectAllField = document.getElementById('selectAllField');
zonesArray = zonesList.split('|');
for (var i=0; i<document.zones.elements.length; i++) {
if (selectAllField.checked == true) {
document.zones.elements[i].checked = true;
} else {
document.zones.elements[i].checked = false;
}
}
}
//-->
</script>
<?php
/*-------------------------------------------------------*/
/* Store preferences */
/*-------------------------------------------------------*/
$session['prefs'][$pageName]['listorder'] = $listorder;
$session['prefs'][$pageName]['orderdirection'] = $orderdirection;
phpAds_SessionDataStore();
/*-------------------------------------------------------*/
/* HTML framework */
/*-------------------------------------------------------*/
phpAds_PageFooter();
?>