-
Notifications
You must be signed in to change notification settings - Fork 2
/
add.class.php
214 lines (197 loc) · 6.09 KB
/
add.class.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
<?php
/**
* [Nulled by DarkGoth - NCP TEAM] - 2015
*/
defined('PHPFOX') or exit('NO DICE!');
/**
*
*
* @copyright [PHPFOX_COPYRIGHT]
* @author Raymond_Benc
* @package Phpfox_Component
* @version $Id: add.class.php 6304 2013-07-19 06:13:17Z Miguel_Espinoza $
*/
class Ad_Component_Controller_Add extends Phpfox_Component
{
/**
* Controller
*/
public function process()
{
Phpfox::isUser(true);
Phpfox::getUserParam('ad.can_create_ad_campaigns', true);
// $aAllCountries = Phpfox::getService('core.country')->get();
$aAllCountries = Phpfox::getService('core.country')->getCountriesAndChildren();
$bIsEdit = false;
$bCompleted = ($this->request()->get('req3') == 'completed' ? true : false);
if (($iId = $this->request()->getInt('id')) && ($aAd = Ad_Service_Ad::instance()->getForEdit($iId)))
{
if ($aAd['user_id'] != Phpfox::getUserId())
{
return Phpfox_Error::display(Phpfox::getPhrase('ad.unable_to_edit_purchase_this_ad'));
}
if (!$bCompleted)
{
$bIsEdit = true;
}
$aAd['country_iso_custom'] = $aAd['country_iso'];
$this->template()
->assign(array(
'aForms' => $aAd,
'aAllCountries' => $aAllCountries
)
);
$this->template()->setHeader(array(
'add.js' => 'module_ad',
'<script type="text/javascript">$Behavior.loadAdJs = function() { $Core.Ad.isEdit = true; $Core.Ad.setCountries(\''. json_encode($aAllCountries) .'\'); }</script>'
)
);
}
if ($bIsEdit)
{
$aValidation = array();
}
else
{
$aValidation = array(
'url_link' => array(
'def' => 'url'
)
);
}
$aValidation['name'] = Phpfox::getPhrase('ad.provide_a_campaign_name');
if (!$bIsEdit)
{
$aValidation['total_view'] = Phpfox::getPhrase('ad.define_how_many_impressions_for_this_ad');
}
$oValidator = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation));
if (($aVals = $this->request()->getArray('val')))
{
if ($oValidator->isValid($aVals))
{
if (isset($aVals['location']))
{
if (Phpfox::getParam('ad.multi_ad'))
{
$aPlan = Ad_Service_Ad::instance()->getPlan( 50 , true );
}
else
{
$aPlan = Ad_Service_Ad::instance()->getPlan($aVals['block_id'], false);
}
$aVals = array_merge($aPlan, $aVals);
}
if ($bIsEdit)
{
if (($iId = Phpfox::getService('ad.process')->updateCustom($aAd['ad_id'], $aVals)))
{
$this->url()->send('ad.manage', null, Phpfox::getPhrase('ad.ad_successfully_updated'));
}
}
else
{
if (($iId = Phpfox::getService('ad.process')->addCustom($aVals)))
{
$this->url()->send('ad.add.completed', array('id' => $iId));
}
}
}
}
$aAge = array();
$iAgeEnd = date('Y')-Phpfox::getParam('user.date_of_birth_start');
$iAgeStart = date('Y')-Phpfox::getParam('user.date_of_birth_end');
for ($iAgeStart; $iAgeStart <= $iAgeEnd; $iAgeStart++)
{
$aAge[$iAgeStart] = $iAgeStart;
}
$iPlacementCount = count((array) Ad_Service_Ad::instance()->getPlacements());
if (!$bCompleted && !$bIsEdit)
{
if ($iPlacementCount)
{
$this->template()->setHeader(array(
'add.js' => 'module_ad',
'<script type="text/javascript">$Behavior.loadAdJs = function() { $Core.Ad.setCountries(\''. json_encode($aAllCountries) .'\'); };</script>'
)
);
}
}
else
{
$aPlan = Ad_Service_Ad::instance()->getPlan($aAd['location'], true);
if (!isset($aPlan['plan_id']))
{
return Phpfox_Error::display(Phpfox::getPhrase('ad.not_a_valid_ad_plan'));
}
// is it free?
$aCosts = unserialize($aPlan['cost']);
$bIsFree = true;
foreach ($aCosts as $sCurrency => $fCost)
{
if ($fCost > 0)
{
$bIsFree = false;
break;
}
}
$this->template()->assign(array('bIsFree' => $bIsFree));
$this->setParam('gateway_data', array(
'item_number' => 'ad|' . $aAd['ad_id'],
'currency_code' => $aPlan['default_currency_id'],
'amount' => $aPlan['is_cpm']? (($aPlan['default_cost'] * $aAd['total_view']) / 1000) : (($aPlan['default_cost'] * $aAd['total_view'])),
'item_name' => $aPlan['title'],
'return' => $this->url()->makeUrl('ad.manage', array('view' => 'pending', 'payment' => 'done')),
'recurring' => '',
'recurring_cost' => '',
'alternative_cost' => '',
'alternative_recurring_cost' => ''
)
);
}
$this->template()->setTitle(($bIsEdit ? Phpfox::getPhrase('ad.updating_an_ad') : Phpfox::getPhrase('ad.creating_an_ad')))
->setBreadcrumb(Phpfox::getPhrase('ad.advertise'), $this->url()->makeUrl('ad'))
->setBreadcrumb(($bIsEdit ? Phpfox::getPhrase('ad.updating_an_ad') : Phpfox::getPhrase('ad.creating_an_ad')), $this->url()->makeUrl('ad.add'), true)
->setPhrase(array(
'ad.select_an_ad_placement',
'ad.there_is_minimum_of_1000_impressions'
)
)
->assign(array(
'aAge' => $aAge,
'bIsEdit' => $bIsEdit,
'sCreateJs' => $oValidator->createJS(),
'sGetJsForm' => $oValidator->getJsForm(),
'bCompleted' => $bCompleted,
'bIsEdit' => $bIsEdit,
'iPlacementCount' => $iPlacementCount,
'aAllCountries' => $aAllCountries
)
)
->setPhrase(array(
'core.you_cannot_write_more_then_limit_characters',
'core.you_have_limit_character_s_left',
'ad.amount_currency_per_1000_impressions',
'ad.amount_currency_per_click'
)
)
->setHeader('cache', array(
'jquery/plugin/jquery.limitTextarea.js' => 'static_script',
// 'colorpicker.js' => 'static_script',
// 'colorpicker.css' => 'style_css',
// 'colorpicker/js/colorpicker.js' => 'static_script',
'add.css' => 'module_ad',
'<script type="text/javascript">$Behavior.setMulti = function(){ oParams[\'ad.multi_ad\'] = ' . (Phpfox::getParam('ad.multi_ad') ? 'true': 'false'). ';};</script>'
)
)
->setFullSite();
}
/**
* Garbage collector. Is executed after this class has completed
* its job and the template has also been displayed.
*/
public function clean()
{
(($sPlugin = Phpfox_Plugin::get('ad.component_controller_add_clean')) ? eval($sPlugin) : false);
}
}
?>