-
Notifications
You must be signed in to change notification settings - Fork 2
/
add.class.php
166 lines (150 loc) · 4.81 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
<?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 6456 2013-08-13 12:47:12Z Raymond_Benc $
*/
class Ad_Component_Controller_Admincp_Add extends Phpfox_Component
{
/**
* Controller
*/
public function process()
{
(($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_add_process__start')) ? eval($sPlugin) : false);
$bIsEdit = false;
$aVals = $this->request()->getArray('val');
$aAllCountries = Phpfox::getService('core.country')->getCountriesAndChildren();
$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>'
)
)->assign(array('aAllCountries' => $aAllCountries));
if (($iId = $this->request()->getInt('id')))
{
if (($aAd = Ad_Service_Ad::instance()->getForEdit($iId)))
{
$bIsEdit = true;
if ($aAd['location'] == 50)
{
$aCustomAd = json_decode($aAd['html_code'], true);
$aAd['c_ad_title'] = $aCustomAd['title'];
$aAd['c_ad_body'] = $aCustomAd['body'];
}
$this->template()->assign('aForms', $aAd);
$this->template()->assign('aAccess', $aAd['user_group']);
if (isset($aAd['countries_list']) && !empty($aAd['countries_list']))
{
$sCountries = implode('_', $aAd['countries_list']);
$aProvinces = array();
if (isset($aAd['province']) && !empty($aAd['province']))
{
foreach ($aAd['province'] as $sProvince)
{
$aProvinces[$sProvince] = true;
}
}
$this->template()->setHeader(array(
'<script type="text/javascript"> $Behavior.toggleSelected = function(){$Core.Ad.toggleSelectedCountries("'.$sCountries.'");$Core.Ad.toggleSelectedProvinces('. json_encode($aProvinces) .');}; </script>'
));
}
else
{
$this->template()->setHeader(array(
'<script type="text/javascript"> $Behavior.toggleSelectedCountries = function(){ $("#country_iso option:eq(0)").attr("selected", "selected"); }; </script>'
));
}
}
}
$aValidation = array(
'type_id' => array(
'title' => Phpfox::getPhrase('ad.select_a_banner_type'),
'def' => 'int'
),
'name' => Phpfox::getPhrase('ad.provide_a_name_for_this_campaign')
);
if (is_array($aVals) && count($aVals) > 0)
{
if (isset($aVals['type_id']))
{
if ($aVals['type_id'] == 1)
{
$aValidation['url_link'] = Phpfox::getPhrase('ad.provide_a_link_for_your_banner');
}
}
}
$oValidator = Phpfox_Validator::instance()->set(array('sFormName' => 'js_form', 'aParams' => $aValidation));
if (is_array($aVals) && count($aVals) > 0)
{
if ($aVals['type_id'] == 2 && empty($aVals['html_code']))
{
Phpfox_Error::set(Phpfox::getPhrase('ad.provide_html_for_your_banner'));
}
if ($oValidator->isValid($aVals))
{
if ($bIsEdit)
{
if (Ad_Service_Process::instance()->update($aAd['ad_id'], $aVals))
{
$this->url()->send('admincp.ad.add', array('id' => $aAd['ad_id']), Phpfox::getPhrase('ad.ad_successfully_updated'));
}
}
else
{
if (Phpfox::getService('ad.process')->add($aVals))
{
$this->url()->send('admincp.ad.add', null, Phpfox::getPhrase('ad.ad_successfully_added'));
}
}
}
if (isset($aVals['user_group']))
{
$this->template()->assign('aAccess', $aVals['user_group']);
}
$this->template()->assign('aForms', $aVals);
}
$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;
}
$this->template()->setTitle(Phpfox::getPhrase('ad.create_new_campaign'))
->setBreadcrumb(Phpfox::getPhrase('ad.create_new_campaign'))
->setPhrase(array(
'ad.min_age_cannot_be_higher_than_max_age'
)
)
->setHeader('cache', array(
'ad.js' => 'module_ad'
)
)
->assign(array(
'aUserGroups' => Phpfox::getService('user.group')->get(),
'aAge' => $aAge,
'bIsEdit' => $bIsEdit,
'sCreateJs' => $oValidator->createJS(),
'sGetJsForm' => $oValidator->getJsForm(),
'aComponents' => Phpfox::getService('admincp.component')->get()
)
);
(($sPlugin = Phpfox_Plugin::get('ad.component_controller_admincp_add_process__end')) ? eval($sPlugin) : false);
}
/**
* 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_admincp_add_clean')) ? eval($sPlugin) : false);
}
}
?>