Cheetah
ChPmtDetails.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  function checkHttps ($s)
11  {
12  return empty($s) || substr(CH_WSB_URL_ROOT, 0, 5) == 'https';
13  }
14 }
15 
17 {
18  var $_oDb;
19  var $_oConfig;
20  var $_aForm;
22 
23  /*
24  * Constructor.
25  */
26  function __construct(&$oDb, &$oConfig)
27  {
28  $this->_oDb = &$oDb;
29  $this->_oConfig = &$oConfig;
30 
31  $this->_aForm = array(
32  'form_attrs' => array(
33  'id' => 'pmt_details',
34  'name' => 'pmt_details',
35  'action' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'details/',
36  'method' => 'post',
37  'enctype' => 'multipart/form-data'
38  ),
39  'params' => array(
40  'db' => array(
41  'table' => '',
42  'key' => 'id',
43  'uri' => '',
44  'uri_title' => '',
45  'submit_name' => 'submit'
46  ),
47  'checker_helper' => 'ChPmtDetailsFormCheckerHelper'
48  ),
49  'inputs' => array (
50  )
51  );
52 
53  $this->_bCollapseFirst = true;
54  }
55 
56  function getForm($iUserId)
57  {
58  $aInputs = $this->_oDb->getForm();
59  if(empty($aInputs))
60  return '';
61 
62  $sLangsPrefix = $this->_oConfig->getLangsPrefix();
63 
64  if($iUserId == CH_PMT_ADMINISTRATOR_ID)
65  $this->_aForm['form_attrs']['action'] = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'admin/';
66 
67  $bCollapsed = $this->_bCollapseFirst;
68  $iProviderId = 0;
69  $sProviderName = "";
70  $aUserValues = $this->_oDb->getFormData($iUserId);
71  foreach($aInputs as $aInput) {
72  $sReturnDataUrl = $this->_oConfig->getDataReturnUrl() . $sProviderName . '/' . $iUserId;
73 
74  if($iProviderId != $aInput['provider_id']) {
75  if(!empty($iProviderId))
76  $this->_aForm['inputs']['provider_' . $iProviderId . '_end'] = array(
77  'type' => 'block_end'
78  );
79 
80  $this->_aForm['inputs']['provider_' . $aInput['provider_id'] . '_begin'] = array(
81  'type' => 'block_header',
82  'caption' => _t($aInput['provider_caption']),
83  'collapsable' => true,
84  'collapsed' => $bCollapsed
85  );
86 
87  $iProviderId = $aInput['provider_id'];
88  $sProviderName = $aInput['provider_name'];
89  $bCollapsed = true;
90  }
91 
92  $this->_aForm['inputs'][$aInput['name']] = array(
93  'type' => $aInput['type'],
94  'name' => $aInput['name'],
95  'caption' => _t($aInput['caption']),
96  'value' => $aUserValues[$aInput['id']]['value'],
97  'info' => _t($aInput['description']),
98  'attrs' => array(
99  'ch-data-provider' => $iProviderId
100  ),
101  'checker' => array (
102  'func' => $aInput['check_type'],
103  'params' => $aInput['check_params'],
104  'error' => _t($aInput['check_error']),
105  )
106  );
107 
108  //--- Make some field dependent actions ---//
109  switch($aInput['type']) {
110  case 'select':
111  if(empty($aInput['extra']))
112  break;
113 
114  $aAddon = array('values' => array());
115 
116  $aPairs = explode(',', $aInput['extra']);
117  foreach($aPairs as $sPair) {
118  $aPair = explode('|', $sPair);
119  $aAddon['values'][] = array('key' => $aPair[0], 'value' => _t($aPair[1]));
120  }
121  break;
122 
123  case 'checkbox':
124  $this->_aForm['inputs'][$aInput['name']]['value'] = 'on';
125  $aAddon = array('checked' => $aUserValues[$aInput['id']]['value'] == 'on' ? true : false);
126  break;
127 
128  case 'value':
129  if(str_replace($aInput['provider_option_prefix'], '', $aInput['name']) == 'return_url')
130  $this->_aForm['inputs'][$aInput['name']]['value'] = $sReturnDataUrl;
131  break;
132  }
133 
134  if(!empty($aAddon) && is_array($aAddon))
135  $this->_aForm['inputs'][$aInput['name']] = array_merge($this->_aForm['inputs'][$aInput['name']], $aAddon);
136  }
137 
138  $this->_aForm['inputs']['provider_' . $iProviderId . '_end'] = array(
139  'type' => 'block_end'
140  );
141  $this->_aForm['inputs']['submit'] = array(
142  'type' => 'submit',
143  'name' => 'submit',
144  'value' => _t($sLangsPrefix . 'details_submit'),
145  );
146 
147  ch_import('ChTemplFormView');
148  $oForm = new ChTemplFormView($this->_aForm);
149  $oForm->initChecker();
150 
151  if($oForm->isSubmittedAndValid()) {
152  $aOptions = $this->_oDb->getOptions();
153  foreach($aOptions as $aOption)
154  $this->_oDb->updateOption($iUserId, $aOption['id'], process_db_input(isset($_POST[$aOption['name']]) ? $_POST[$aOption['name']] : "", CH_TAGS_STRIP));
155 
156  header('Location: ' . $oForm->aFormAttrs['action']);
157  }
158  else {
159  foreach($oForm->aInputs as $aInput)
160  if(!empty($aInput['error'])) {
161  $iProviderId = (int)$aInput['attrs']['ch-data-provider'];
162  $oForm->aInputs['provider_' . $iProviderId . '_begin']['collapsed'] = false;
163  }
164 
165  return $oForm->getCode();
166  }
167  }
168 
169  function getFormBlock($iUserId = -1)
170  {
171  $sLangsPrefix = $this->_oConfig->getLangsPrefix();
172  $sBaseUrl = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri();
173 
174  if(!isLogged())
175  return MsgBox(_t($sLangsPrefix . 'err_required_login'));
176 
177  $aTopMenu = array(
178  'pmt-orders-processed-lnk' => array('href' => $sBaseUrl . 'orders/processed/', 'title' => _t($sLangsPrefix . 'btn_orders_processed')),
179  'pmt-orders-pending-lnk' => array('href' => $sBaseUrl . 'orders/pending/', 'title' => _t($sLangsPrefix . 'btn_orders_pending')),
180  'pmt-payment-settings-lnk' => array('href' => $sBaseUrl . 'details/', 'title' => _t($sLangsPrefix . 'btn_settings'), 'active' => 1)
181  );
182 
183  $sResult = $this->getForm(is_numeric($iUserId) && $iUserId != -1 ? $iUserId : getLoggedId());
184  return array((!empty($sResult) ? $sResult : MsgBox(_t($sLangsPrefix . 'msg_no_results'))), $aTopMenu, array(), false, 'getBlockCaptionMenu');
185  }
186 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
CH_PMT_ADMINISTRATOR_ID
const CH_PMT_ADMINISTRATOR_ID
Definition: ChPmtModule.php:17
ChTemplFormView
Definition: ChTemplFormView.php:11
ChPmtDetails\$_aForm
$_aForm
Definition: ChPmtDetails.php:20
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$sResult
$sResult
Definition: advanced_settings.php:26
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChPmtDetails\$_oConfig
$_oConfig
Definition: ChPmtDetails.php:19
php
isLogged
isLogged()
Definition: profiles.inc.php:24
$oForm
$oForm
Definition: host_tools.php:42
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$oDb
global $oDb
Definition: db.inc.php:39
ChPmtDetails\__construct
__construct(&$oDb, &$oConfig)
Definition: ChPmtDetails.php:26
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChPmtDetails\getForm
getForm($iUserId)
Definition: ChPmtDetails.php:56
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
$s
$s
Definition: embed.php:13
ChPmtDetails
Definition: ChPmtDetails.php:17
ChPmtDetailsFormCheckerHelper
Definition: ChPmtDetails.php:9
ChPmtDetails\$_bCollapseFirst
$_bCollapseFirst
Definition: ChPmtDetails.php:21
ChWsbFormCheckerHelper
Definition: ChWsbForm.php:461
ChPmtDetailsFormCheckerHelper\checkHttps
checkHttps($s)
Definition: ChPmtDetails.php:10
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChPmtDetails\getFormBlock
getFormBlock($iUserId=-1)
Definition: ChPmtDetails.php:169
ChPmtDetails\$_oDb
$_oDb
Definition: ChPmtDetails.php:18