Cheetah
All Classes Namespaces Files Functions Variables Pages
memb_levels.php
Go to the documentation of this file.
1 <?php
2 
8 require_once('../inc/header.inc.php');
9 require_once(CH_DIRECTORY_PATH_INC . 'profiles.inc.php');
10 require_once(CH_DIRECTORY_PATH_INC . 'design.inc.php');
11 require_once(CH_DIRECTORY_PATH_INC . 'admin_design.inc.php');
12 require_once(CH_DIRECTORY_PATH_INC . 'utils.inc.php');
13 ch_import('ChWsbAdminSettings');
14 ch_import('ChTemplSearchResult');
15 
16 $logged['admin'] = member_auth(1, true, true);
17 
18 $oSettings = new ChWsbAdminSettings(5, CH_WSB_URL_ADMIN . 'memb_levels.php?tab=settings');
19 
20 //--- Process submit ---//]
21 $aResults = array();
25 if (isset($_POST['save']) && isset($_POST['cat'])) {
26  $aResults['settings'] = $oSettings->saveChanges($_POST);
27 } elseif ((isset($_POST['adm-mlevels-enable']) || isset($_POST['adm-mlevels-disable'])) && !empty($_POST['levels'])) {
28  if (isset($_POST['adm-mlevels-enable'])) {
29  $sValue = 'yes';
30  } elseif (isset($_POST['adm-mlevels-disable'])) {
31  $sValue = 'no';
32  }
33 
34  $GLOBALS['MySQL']->query("UPDATE `sys_acl_levels` SET `Active`='" . $sValue . "' WHERE `ID` IN ('" . implode("','", $_POST['levels']) . "')");
35 } elseif (isset($_POST['adm-mlevels-delete']) && !empty($_POST['levels'])) {
36  foreach ($_POST['levels'] as $iId) {
37  if (($aResults['levels'] = deleteMembership($iId)) !== true) {
38  break;
39  }
40  }
41 } elseif (isset($_POST['adm-mlevels-actions-enable']) || isset($_POST['adm-mlevels-actions-disable'])) {
42  $iLevelId = (int)$_POST['level'];
43 
44  foreach ($_POST['actions'] as $iId) {
45  if (isset($_POST['adm-mlevels-actions-enable'])) {
46  $sQuery = "REPLACE INTO `sys_acl_matrix` SET `IDLevel`='" . $iLevelId . "', `IDAction`='" . $iId . "'";
47  } else {
48  $sQuery = "DELETE FROM `sys_acl_matrix` WHERE `IDLevel`='" . $iLevelId . "' AND `IDAction`='" . $iId . "'";
49  }
50 
51  $GLOBALS['MySQL']->query($sQuery);
52  }
53 } elseif (isset($_POST['adm-mlevels-prices-add'])) {
54  $iLevelId = (int)$_POST['level'];
55  $iDays = (int)$_POST['days'];
56  $iPrice = (float)trim($_POST['price'], " $");
57 
58  $iLevelIdDb = (int)$GLOBALS['MySQL']->getOne("SELECT `id` FROM `sys_acl_level_prices` WHERE `IDLevel`='" . $iLevelId . "' AND `Days`='" . $iDays . "' LIMIT 1");
59  if ($iLevelIdDb == 0) {
60  $GLOBALS['MySQL']->query("INSERT INTO `sys_acl_level_prices`(`IDLevel`, `Days`, `Price`) VALUES('" . $iLevelId . "', '" . $iDays . "', '" . $iPrice . "')");
61  } else {
62  $mixedResultPrices = _t('_adm_txt_mlevels_price_exists');
63  }
64 } elseif (isset($_POST['adm-mlevels-prices-delete'])) {
65  $GLOBALS['MySQL']->query("DELETE FROM `sys_acl_level_prices` WHERE `id` IN ('" . implode("','", $_POST['prices']) . "')");
66 } elseif (isset($_POST['adm-mlevels-action-save'])) {
67  $sQuery = "REPLACE INTO `sys_acl_matrix` SET `IDLevel`='" . (int)$_POST['levelId'] . "', `IDAction`='" . (int)$_POST['actionId'] . "'";
68  $sQuery .= !empty($_POST['allowedCnt']) ? ", `AllowedCount`='" . (int)$_POST['allowedCnt'] . "'" : "";
69  $sQuery .= !empty($_POST['period']) ? ", `AllowedPeriodLen`='" . (int)$_POST['period'] . "'" : "";
70  $sQuery .= !empty($_POST['dateStart']) && strtotime($_POST['dateStart']) > 0 ? ", `AllowedPeriodStart`=FROM_UNIXTIME(" . strtotime($_POST['dateStart']) . ")" : "";
71  $sQuery .= !empty($_POST['dateEnd']) && strtotime($_POST['dateEnd']) > 0 ? ", `AllowedPeriodEnd`=FROM_UNIXTIME(" . strtotime($_POST['dateEnd']) . ")" : "";
72  $aResult = $GLOBALS['MySQL']->query($sQuery) > 0 ? array('code' => 0, 'message' => MsgBox(_t('_adm_txt_mlevels_action_saved'))) : array('code' => 1, 'message' => MsgBox(_t('_adm_txt_mlevels_action_cannot_save')));
73 
74  echo "<script>parent.onResult(" . json_encode($aResult) . ");</script>";
75  exit;
76 } elseif (isset($_POST['action']) && $_POST['action'] == 'get_edit_form_action') {
77  echo json_encode(array('code' => PageCodeAction((int)$_POST['level_id'], (int)$_POST['action_id'], $mixedResultAction)));
78  exit;
79 }
80 
81 $iLevelId = ch_get('level') !== false ? (int)ch_get('level') : 0;
82 
84 $_page = array(
85  'name_index' => $iNameIndex,
86  'css_name' => array('settings.css', 'memb_levels.css'),
87  'js_name' => array('memb_levels.js'),
88  'header' => _t('_adm_page_cpt_memb_levels'),
89 );
91  'page_code_main' => PageCodeMain($aResults, $iLevelId),
92  'page_code_actions' => ch_get('action') !== false && ch_get('action') == 'actions' && $iLevelId > 0 ? PageCodeActions($iLevelId, $mixedResultActions) : "",
93  'page_code_prices' => ch_get('action') !== false && ch_get('action') == 'prices' && $iLevelId > 0 ? PageCodePrices($iLevelId, $mixedResultPrices) : "",
94 );
95 
96 // add necessary js and css files
97 ch_import('ChTemplFormView');
98 $oForm = new ChTemplFormView(array());
99 $oForm->addCssJs(true, true);
100 
101 PageCodeAdmin();
102 
104 {
105  $sTab = ch_get('tab') !== false ? process_db_input(ch_get('tab')) : 'levels';
106 
107  $bEdit = ch_get('action') !== false && ch_get('action') == 'edit';
108  if ($bEdit) {
109  $sTab = 'levels_add';
110  }
111 
112  $aTopItems = array(
113  'adm-mlevels-btn-levels' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_mlevels_levels'), 'active' => $sTab == 'levels' ? 1 : 0),
114  'adm-mlevels-btn-levels-add' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_mlevels_levels_add'), 'active' => $sTab == 'levels_add' ? 1 : 0),
115  'adm-mlevels-btn-settings' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_mlevels_settings'), 'active' => $sTab == 'settings' ? 1 : 0)
116  );
117 
118  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels.html', array(
119  'content_levels' => _getLevelsList(isset($aResults['levels']) ? $aResults['levels'] : true, $sTab == 'levels'),
120  'content_create' => _getLevelsCreateForm($bEdit ? $iLevelId : 0, $sTab == 'levels_add'),
121  'content_settings' => _getLevelsSettingsForm(isset($aResults['settings']) ? $aResults['settings'] : true, $sTab == 'settings'),
122  ));
123 
124  return DesignBoxAdmin(_t('_adm_box_cpt_mlevel_memberships'), $sResult, $aTopItems);
125 }
126 
127 function _getLevelsList($mixedResult, $bActive = false)
128 {
129  $sSubmitUrl = CH_WSB_URL_ADMIN . 'memb_levels.php?tab=levels';
130 
131  $sResult = '';
132  if ($mixedResult !== true && !empty($mixedResult)) {
133  $bActive = true;
134  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
135  }
136 
137  //--- Get Items ---//
138  $aItemsSystem = $aItemsCustom = array();
139 
140  $aLevels = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `title`, `Active` AS `active`, `Purchasable` AS `purchasable`, `Removable` AS `removable` FROM `sys_acl_levels` WHERE `Removable`='no' ORDER BY `ID` ASC");
141  foreach ($aLevels as $aLevel) {
142  $aItemsSystem[] = array(
143  'id' => $aLevel['id'],
144  'title' => $aLevel['title'],
145  'actions_link' => $GLOBALS['site']['url_admin'] . 'memb_levels.php?action=actions&level=' . $aLevel['id'] . '#actions' . $aLevel['id'],
146  );
147  }
148 
149  $oModuleDb = new ChWsbModuleDb();
150  $bPayment = $oModuleDb->isModule('payment');
151 
152  $aLevels = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `title`, `Active` AS `active`, `Purchasable` AS `purchasable`, `Removable` AS `removable` FROM `sys_acl_levels` WHERE `Removable`='yes' ORDER BY `Order` ASC");
153  foreach ($aLevels as $aLevel) {
154  $aItemsCustom[] = array(
155  'id' => $aLevel['id'],
156  'title' => $aLevel['title'],
157  'class' => $aLevel['active'] == 'yes' ? 'adm-mlevels-enabled' : 'adm-mlevels-disabled',
158  'actions_link' => $GLOBALS['site']['url_admin'] . 'memb_levels.php?action=actions&level=' . $aLevel['id'] . '#actions' . $aLevel['id'],
159  'ch_if:editable' => array(
160  'condition' => $aLevel['removable'] == 'yes',
161  'content' => array(
162  'edit_link' => $GLOBALS['site']['url_admin'] . 'memb_levels.php?action=edit&level=' . $aLevel['id'],
163  )
164  ),
165  'ch_if:purchasable' => array(
166  'condition' => $bPayment && $aLevel['purchasable'] == 'yes',
167  'content' => array(
168  'price_link' => $GLOBALS['site']['url_admin'] . 'memb_levels.php?action=prices&level=' . $aLevel['id'] . '#prices' . $aLevel['id'],
169  )
170  )
171  );
172  }
173 
174  //--- Get Controls ---//
175  $aButtons = array(
176  'adm-mlevels-enable' => _t('_adm_btn_mlevels_enable'),
177  'adm-mlevels-disable' => _t('_adm_btn_mlevels_disable'),
178  'adm-mlevels-delete' => _t('_adm_btn_mlevels_delete')
179  );
180  $sControls = ChTemplSearchResult::showAdminActionsPanel('adm-mlevels-list-form', $aButtons, 'levels');
181 
182  return $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_list.html', array(
183  'display' => $bActive ? 'block' : 'none',
184  'action' => $sSubmitUrl,
185  'result' => $sResult,
186  'ch_repeat:items_system' => $aItemsSystem,
187  'ch_repeat:items_custom' => $aItemsCustom,
188  'controls' => $sControls
189  ));
190 }
191 
192 function _getLevelsCreateForm($iLevelId, $bActive = false)
193 {
194  $sSubmitUrl = CH_WSB_URL_ADMIN . 'memb_levels.php';
195 
196  $aLevel = array();
197  if (($bEdit = $iLevelId != 0) === true) {
198  $aLevel = $GLOBALS['MySQL']->getRow("SELECT `Name` AS `Name`, `Description` AS `Description`, `Order` AS `Order` FROM `sys_acl_levels` WHERE `ID`= ? LIMIT 1", [$iLevelId]);
199  }
200 
201  if (!$bEdit) {
202  $aLevels = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `title`, `Active` AS `active`, `Purchasable` AS `purchasable`, `Removable` AS `removable` FROM `sys_acl_levels` WHERE `Removable`='no' ORDER BY `ID` ASC");
203  foreach ($aLevels as $aLevel2) {
204  $aItemsSystem[$aLevel2['id']] = $aLevel2['title'];
205  }
206  $sCopyFromCaption = _t('_adm_txt_mlevels_copy');
207  } else {
208  $aItemsSystem = array();
209  $sCopyFromCaption = '';
210  }
211 
212  $aForm = array(
213  'form_attrs' => array(
214  'id' => 'adm-mlevels-create',
215  'action' => $sSubmitUrl . '?tab=levels_add',
216  'method' => 'post',
217  'enctype' => 'multipart/form-data',
218  ),
219  'params' => array(
220  'db' => array(
221  'table' => 'sys_acl_levels',
222  'key' => 'ID',
223  'uri' => '',
224  'uri_title' => '',
225  'submit_name' => 'Submit'
226  ),
227  ),
228  'inputs' => array(
229  'Active' => array(
230  'type' => 'hidden',
231  'name' => 'Active',
232  'value' => 'no',
233  'db' => array(
234  'pass' => 'Xss',
235  ),
236  ),
237  'Purchasable' => array(
238  'type' => 'hidden',
239  'name' => 'Purchasable',
240  'value' => 'yes',
241  'db' => array(
242  'pass' => 'Xss',
243  ),
244  ),
245  'Removable' => array(
246  'type' => 'hidden',
247  'name' => 'Removable',
248  'value' => 'yes',
249  'db' => array(
250  'pass' => 'Xss',
251  ),
252  ),
253  'Name' => array(
254  'type' => 'text',
255  'name' => 'Name',
256  'caption' => _t('_adm_txt_mlevels_name'),
257  'value' => isset($aLevel['Name']) ? $aLevel['Name'] : '',
258  'required' => true,
259  'db' => array(
260  'pass' => 'Xss',
261  ),
262  'checker' => array(
263  'func' => 'length',
264  'params' => array(3,100),
265  'error' => _t('_adm_txt_mlevels_name_err'),
266  ),
267  ),
268  'Icon' => array(
269  'type' => 'file',
270  'name' => 'Icon',
271  'caption' => _t('_adm_txt_mlevels_icon'),
272  'required' => true,
273  'checker' => array(
274  'func' => '',
275  'params' => '',
276  'error' => _t('_adm_txt_mlevels_icon_err'),
277  ),
278  ),
279  'Description' => array(
280  'type' => 'textarea',
281  'name' => 'Description',
282  'caption' => _t('_adm_txt_mlevels_description'),
283  'value' => isset($aLevel['Description']) ? $aLevel['Description'] : '',
284  'db' => array(
285  'pass' => 'XssHtml',
286  ),
287  ),
288  'Order' => array(
289  'type' => 'text',
290  'name' => 'Order',
291  'caption' => _t('_adm_txt_mlevels_order'),
292  'value' => isset($aLevel['Order']) ? $aLevel['Order'] : $GLOBALS['MySQL']->getOne("SELECT MAX(`Order`)+1 FROM `sys_acl_levels`"),
293  'required' => true,
294  'db' => array(
295  'pass' => 'Int',
296  ),
297  'checker' => array(
298  'func' => 'preg',
299  'params' => array('/^[1-9][0-9]*$/'),
300  'error' => _t('_adm_txt_mlevels_order_err'),
301  ),
302  ),
303  'CopyFrom' => array(
304  'type' => 'radio_set',
305  'name' => 'CopyFrom',
306  'caption' => $sCopyFromCaption,
307  'value' => $aItem['Target'] == '_blank' ? '_blank' : '_self',
308  'values' => $aItemsSystem,
309  'attrs' => array()
310  ),
311  'Submit' => array(
312  'type' => 'submit',
313  'name' => 'Submit',
314  'value' => _t('_adm_btn_mlevels_add'),
315  ),
316  )
317  );
318 
319  //--- Convert Add to Edit
320  if ($bEdit) {
321  unset($aForm['inputs']['Active']);
322  unset($aForm['inputs']['Purchasable']);
323  unset($aForm['inputs']['Removable']);
324 
325  $aForm['form_attrs']['action'] = $sSubmitUrl . '?action=edit&level=' . $iLevelId;
326  $aForm['inputs']['Icon']['info'] = _t('_adm_txt_mlevels_icon_info_edit');
327  $aForm['inputs']['Icon']['required'] = false;
328  $aForm['inputs']['Icon']['checker'] = array();
329  $aForm['inputs']['Submit']['value'] = _t('_adm_btn_mlevels_save');
330  $aForm['inputs']['ID'] = array(
331  'type' => 'hidden',
332  'name' => 'ID',
333  'value' => $iLevelId,
334  'db' => array(
335  'pass' => 'Int',
336  )
337  );
338  }
340  $oForm->initChecker();
341 
342  if ($oForm->isSubmittedAndValid()) {
343  $sFilePath = CH_DIRECTORY_PATH_ROOT . 'media/images/membership/';
344  $sFileName = time();
345  $sFileExt = '';
346 
347  //--- Add new level
348  if (!$bEdit) {
349  if ($GLOBALS['MySQL']->getOne("SELECT `Name` FROM `sys_acl_levels` WHERE `Name`='" . $oForm->getCleanValue('Name') . "' LIMIT 1")) {
350  $oForm->aInputs['Name']['error'] = _t('_adm_txt_mlevels_name_err_non_uniq');
351  } elseif (isImage($_FILES['Icon']['type'], $sFileExt) && !empty($_FILES['Icon']['tmp_name']) && move_uploaded_file($_FILES['Icon']['tmp_name'], $sFilePath . $sFileName . '.' . $sFileExt)) {
352  $sPath = $sFilePath . $sFileName . '.' . $sFileExt;
353  imageResize($sPath, $sPath, 110, 110);
354 
355  $iId = (int)$oForm->insert(array('Icon' => $sFileName . '.' . $sFileExt));
356  if ($iId != 0) {
357  $sName = $oForm->getCleanValue('Name');
358  addStringToLanguage('_adm_txt_mp_' . strtolower($sName), $sName);
359 
360  $iCopyFrom = (int)$oForm->getCleanValue('CopyFrom');
361  // If $sCopyFrom is set, then copy the actions from the level in $sCopyFrom to the new level.
362  if ($iCopyFrom > 0) {
363  _copyMatrix($iCopyFrom, $iId);
364  }
365  }
366 
367  header('Location: ' . $sSubmitUrl);
368  exit;
369  } else {
370  $oForm->aInputs['Icon']['error'] = $oForm->aInputs['Icon']['checker']['error'];
371  }
372  }
373  //--- Edit existing level
374  else {
375  $aValsToAdd = array();
376  if (isImage($_FILES['Icon']['type'], $sFileExt) && !empty($_FILES['Icon']['tmp_name']) && move_uploaded_file($_FILES['Icon']['tmp_name'], $sFilePath . $sFileName . '.' . $sFileExt)) {
377  $aValsToAdd['Icon'] = $sFileName . '.' . $sFileExt;
378 
379  $sPath = $sFilePath . $sFileName . '.' . $sFileExt;
380  imageResize($sPath, $sPath, 110, 110);
381 
382  $sIconOld = $GLOBALS['MySQL']->getOne("SELECT `Icon` FROM `sys_acl_levels` WHERE `ID`='" . $iLevelId . "' LIMIT 1");
383  if (!empty($sIconOld)) {
384  @unlink($sFilePath . $sIconOld);
385  }
386  }
387 
388  $bResult = $oForm->update($iLevelId, $aValsToAdd);
389  if ($bResult !== false) {
390  deleteStringFromLanguage('_adm_txt_mp_' . strtolower($aLevel['Name']));
391 
392  $sName = $oForm->getCleanValue('Name');
393  addStringToLanguage('_adm_txt_mp_' . strtolower($sName), $sName);
394  }
395 
396  header('Location: ' . $sSubmitUrl);
397  exit;
398  }
399  }
400 
401  return $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_create.html', array(
402  'display' => $bActive ? 'block' : 'none',
403  'form' => $oForm->getCode()
404  ));
405 }
406 
407 function _copyMatrix($iFromId, $iToId)
408 {
409  // Copies the membership actions martix from the From ID to the To ID
410  $aMatrix = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_acl_matrix` WHERE `IDLevel` = '$iFromId'");
411  //echo $iFromId . '<br>';
412  //echo $iToId . '<br>';
413  //echo '<pre>' . print_r($aMatrix, true) . '</pre>';
414  //exit;
415  foreach ($aMatrix as $id => $value) {
416  $sSet = "`IDLevel` = '$iToId', ";
417  $sSet .= "`IDAction` = '" . $value['IDAction'] . "', ";
418  $sSet .= "`AllowedCount` = '" . $value['AllowedCount'] . "', ";
419  $sSet .= "`AllowedPeriodLen` = '" . $value['AllowedPeriodLen'] . "', ";
420  $sSet .= "`AllowedPeriodStart` = '" . $value['AllowedPeriodStart'] . "', ";
421  $sSet .= "`AllowedPeriodEnd` = '" . $value['AllowedPeriodEnd'] . "', ";
422  $sSet .= "`AdditionalParamValue` = '" . $value['AdditionalParamValue'] . "';";
423  $GLOBALS['MySQL']->query("INSERT INTO `sys_acl_matrix` SET " . $sSet);
424  }
425 }
426 
427 
428 function _getLevelsSettingsForm($mixedResult, $bActive = false)
429 {
430  $sResult = $GLOBALS['oSettings']->getForm();
431  if ($mixedResult !== true && !empty($mixedResult)) {
432  $bActive = true;
433  $sResult = $mixedResult . $sResult;
434  }
435 
436  return $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_settings.html', array(
437  'display' => $bActive ? 'block' : 'none',
438  'form' => $sResult
439  ));
440 }
441 
442 function PageCodeActions($iId, $mixedResult)
443 {
444  $sTitle = $GLOBALS['MySQL']->getOne("SELECT `Name` FROM `sys_acl_levels` WHERE `ID`='" . $iId . "' LIMIT 1");
445 
446  //--- Get Items ---//
447  $aItems = array();
448 
449  $aActions = $GLOBALS['MySQL']->getAll("SELECT `ta`.`ID` AS `id`, `ta`.`Name` AS `title` FROM `sys_acl_actions` AS `ta` ORDER BY `ta`.`Name`");
450  $aActionsActive = $GLOBALS['MySQL']->getAllWithKey("SELECT `ta`.`ID` AS `id`, `ta`.`Name` AS `title` FROM `sys_acl_actions` AS `ta`
451  LEFT JOIN `sys_acl_matrix` AS `tm` ON `ta`.`ID`=`tm`.`IDAction` LEFT JOIN `sys_acl_levels` AS `tl` ON `tm`.`IDLevel`=`tl`.`ID` WHERE `tl`.`ID`= ?", "id", [$iId]);
452 
453  translateMembershipActions($aActions);
454 
455  foreach ($aActions as $aAction) {
456  $bEnabled = array_key_exists($aAction['id'], $aActionsActive);
457  $aItems[] = array(
458  'action_id' => $aAction['id'],
459  'title' => $aAction['title'],
460  'class' => $bEnabled ? 'adm-mlevels-enabled' : 'adm-mlevels-disabled',
461  'ch_if:enabled' => array(
462  'condition' => $bEnabled,
463  'content' => array(
464  'level_id' => $iId,
465  'action_id' => $aAction['id'],
466  'title' => $aAction['title']
467  )
468  ),
469  'ch_if:disabled' => array(
470  'condition' => !$bEnabled,
471  'content' => array(
472  'action_id' => $aAction['id'],
473  'title' => $aAction['title']
474  )
475  ),
476  );
477  }
478 
479  //--- Get Controls ---//
480  $aButtons = array(
481  'adm-mlevels-actions-enable' => _t('_adm_btn_mlevels_enable'),
482  'adm-mlevels-actions-disable' => _t('_adm_btn_mlevels_disable')
483  );
484  $sControls = ChTemplSearchResult::showAdminActionsPanel('adm-mlevels-actions-form', $aButtons, 'actions');
485 
486  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_actions.html', array(
487  'id' => $iId,
488  'ch_repeat:items' => $aItems,
489  'controls' => $sControls,
490  'url_admin' => $GLOBALS['site']['url_admin']
491  ));
492 
493  if ($mixedResult !== true && !empty($mixedResult)) {
494  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
495  }
496 
497  return DesignBoxAdmin(_t('_adm_box_cpt_mlevel_actions', $sTitle), $sResult);
498 }
499 function PageCodeAction($iLevelId, $iActionId, $mixedResult)
500 {
501  $aAction = $GLOBALS['MySQL']->getRow("SELECT * FROM `sys_acl_matrix` WHERE `IDLevel`='" . $iLevelId . "' AND `IDAction`= ?", [$iActionId]);
502 
503  $aForm = array(
504  'form_attrs' => array(
505  'id' => 'adm-mlevels-action-form',
506  'target' => 'adm-mlevels-action-iframe',
507  'action' => $GLOBALS['site']['url_admin'] . 'memb_levels.php',
508  'method' => 'post',
509  'enctype' => 'multipart/form-data'
510  ),
511  'params' => array(),
512  'inputs' => array(
513  'levelId' => array(
514  'type' => 'hidden',
515  'name' => 'levelId',
516  'value' => $iLevelId
517  ),
518  'actionId' => array(
519  'type' => 'hidden',
520  'name' => 'actionId',
521  'value' => $iActionId
522  ),
523  'allowedCnt' => array(
524  'type' => 'text',
525  'name' => 'allowedCnt',
526  'caption' => _t('_adm_txt_mlevels_actions_number'),
527  'info' => _t('_adm_txt_mlevels_actions_number_desc'),
528  'value' => isset($aAction['AllowedCount']) ? (int)$aAction['AllowedCount'] : ""
529  ),
530  'period' => array(
531  'type' => 'text',
532  'name' => 'period',
533  'caption' => _t('_adm_txt_mlevels_actions_reset'),
534  'info' => _t('_adm_txt_mlevels_actions_reset_desc'),
535  'value' => isset($aAction['AllowedPeriodLen']) ? (int)$aAction['AllowedPeriodLen'] : ""
536  ),
537  'dateStart' => array(
538  'type' => 'datetime',
539  'name' => 'dateStart',
540  'caption' => _t('_adm_txt_mlevels_actions_avail_start'),
541  'info' => _t('_adm_txt_mlevels_actions_avail_desc'),
542  'value' => isset($aAction['AllowedPeriodStart']) ? preg_replace('/(\d+):(\d+):(\d+)/', '$1:$2', $aAction['AllowedPeriodStart']) : "",
543  'attrs' => array(
544  'allow_input' => 'true',
545  ),
546  'db' => array(
547  'pass' => 'DateTime',
548  ),
549  ),
550  'dateEnd' => array(
551  'type' => 'datetime',
552  'name' => 'dateEnd',
553  'caption' => _t('_adm_txt_mlevels_actions_avail_end'),
554  'info' => _t('_adm_txt_mlevels_actions_avail_desc'),
555  'value' => isset($aAction['AllowedPeriodEnd']) ? preg_replace('/(\d+):(\d+):(\d+)/', '$1:$2', $aAction['AllowedPeriodEnd']) : "",
556  'attrs' => array(
557  'allow_input' => 'true',
558  ),
559  'db' => array(
560  'pass' => 'DateTime',
561  ),
562  ),
563  'adm-mlevels-action-save' => array(
564  'type' => 'submit',
565  'name' => 'adm-mlevels-action-save',
566  'value' => _t('_adm_btn_mlevels_save'),
567  ),
568  )
569  );
571 
572  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_action.html', array(
573  'content' => $oForm->getCode()
574  ));
575 
576  if ($mixedResult !== true && !empty($mixedResult)) {
577  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
578  }
579 
580  return $GLOBALS['oFunctions']->popupBox('adm-mlevels-action', _t('_adm_box_cpt_mlevel_action'), $sResult);
581 }
582 function PageCodePrices($iId, $mixedResult)
583 {
584  //--- Get Items ---//
585  $oModuleDb = new ChWsbModuleDb();
586  if (!$oModuleDb->isModule('payment')) {
587  return '';
588  }
589 
590  $aInfo = ChWsbService::call('payment', 'get_currency_info');
591  $sCurrencySign = $aInfo['sign'];
592 
593  $aItems = array();
594  $aPrices = $GLOBALS['MySQL']->getAll("SELECT `id` AS `id`, `Days` AS `days`, `Price` AS `price` FROM `sys_acl_level_prices` WHERE `IDLevel`= ? ORDER BY `id`", [$iId]);
595  foreach ($aPrices as $aPrice) {
596  $aItems[] = array(
597  'id' => $aPrice['id'],
598  'title' => (int)$aPrice['days'] == 0 ? _t('_adm_txt_mlevels_price_info_lifetime', $sCurrencySign, $aPrice['price']) : _t('_adm_txt_mlevels_price_info', $aPrice['days'], $sCurrencySign, $aPrice['price']),
599  );
600  }
601 
602  //--- Get Controls ---//
603  $sTopControls = $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_prices_top_controls.html', array());
604 
605  $aButtons = array(
606  'adm-mlevels-prices-delete' => _t('_adm_btn_mlevels_delete')
607  );
608  $sControls = ChTemplSearchResult::showAdminActionsPanel('adm-mlevels-prices-form', $aButtons, 'prices');
609 
610  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('mlevels_prices.html', array(
611  'id' => $iId,
612  'top_controls' => $sTopControls,
613  'ch_repeat:items' => $aItems,
614  'controls' => $sControls
615  ));
616 
617  if ($mixedResult !== true && !empty($mixedResult)) {
618  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
619  }
620 
621  $sTitle = $GLOBALS['MySQL']->getOne("SELECT `Name` FROM `sys_acl_levels` WHERE `ID`='" . $iId . "' LIMIT 1");
622  return DesignBoxAdmin(_t('_adm_box_cpt_mlevel_prices', $sTitle), $sResult);
623 }
624 function isImage($sMimeType, &$sFileExtension)
625 {
626  $bResult = true;
627  switch ($sMimeType) {
628  case 'image/jpeg':
629  case 'image/pjpeg':
630  $sFileExtension = 'jpg';
631  break;
632  case 'image/png':
633  case 'image/x-png':
634  $sFileExtension = 'png';
635  break;
636  case 'image/gif':
637  $sFileExtension = 'gif';
638  break;
639  default:
640  $bResult = false;
641  }
642  return $bResult;
643 }
645 {
646  $iId = (int)$iId;
647 
648  $aLevel = $GLOBALS['MySQL']->getRow("SELECT `Icon` AS `icon`, `Removable` AS `removable`, `Name` AS `name` FROM `sys_acl_levels` WHERE `ID`= ?", [$iId]);
649  if (empty($aLevel)) {
650  return "_adm_txt_mlevels_not_found";
651  }
652 
653  //Check if membership can be removed
654  if ($aLevel['removable'] != 'yes') {
655  return '_adm_txt_mlevels_cannot_remove';
656  }
657 
658  //Check if there are still members using this ANNUAL membership
659  $iDateExpires = $GLOBALS['MySQL']->getOne("SELECT UNIX_TIMESTAMP(MAX(`DateExpires`)) as `MaxDateExpires` FROM `sys_acl_levels_members` WHERE `IDLevel`='" . $iId . "'");
660  if ($iDateExpires > time()) {
661  return "_adm_txt_mlevels_is_used";
662  }
663 
664  //Check if there are members using this LIFETIME membership
665  $iLifetime = (int)$GLOBALS['MySQL']->getOne("SELECT COUNT(`IDMember`) FROM `sys_acl_levels_members` WHERE `DateStarts`<=NOW() AND ISNULL(`DateExpires`) AND `IDLevel`='" . $iId . "'");
666  if ($iLifetime > 0) {
667  return "_adm_txt_mlevels_is_used";
668  }
669 
670  @unlink(CH_DIRECTORY_PATH_ROOT . 'media/images/membership/' . $aLevel['icon']);
671  db_res("DELETE FROM `sys_acl_level_prices` WHERE `IDLevel`='" . $iId . "'");
672  db_res("DELETE FROM `sys_acl_matrix` WHERE `IDLevel`='" . $iId . "'");
673  db_res("DELETE FROM `sys_acl_levels` WHERE `ID`='" . $iId . "'");
674  deleteStringFromLanguage('_adm_txt_mp_' . strtolower($aLevel['name']));
675 
676  return true;
677 }
_getLevelsCreateForm
_getLevelsCreateForm($iLevelId, $bActive=false)
Definition: memb_levels.php:192
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
$iLevelId
if(isset($_POST['save']) &&isset($_POST['cat'])) elseif((isset($_POST['adm-mlevels-enable'])||isset($_POST['adm-mlevels-disable'])) &&!empty($_POST['levels'])) elseif(isset($_POST['adm-mlevels-delete']) &&!empty($_POST['levels'])) elseif(isset($_POST['adm-mlevels-actions-enable'])||isset($_POST['adm-mlevels-actions-disable'])) elseif(isset($_POST['adm-mlevels-prices-add'])) elseif(isset($_POST['adm-mlevels-prices-delete'])) elseif(isset($_POST['adm-mlevels-action-save'])) elseif(isset($_POST['action']) && $_POST['action']=='get_edit_form_action') $iLevelId
Definition: memb_levels.php:81
deleteStringFromLanguage
deleteStringFromLanguage($langKey, $langID=-1)
Definition: languages.inc.php:446
ChTemplFormView
Definition: ChTemplFormView.php:11
$_page_cont
$_page_cont[$iNameIndex]
Definition: memb_levels.php:90
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
translateMembershipActions
translateMembershipActions(&$aActions)
Definition: membership_levels.inc.php:766
$sResult
$sResult
Definition: advanced_settings.php:26
$mixedResultActions
$mixedResultActions
Definition: memb_levels.php:22
$aResults
$aResults
Definition: memb_levels.php:21
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
PageCodeMain
PageCodeMain($aResults, $iLevelId)
Definition: memb_levels.php:103
php
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
$iId
$iId
Definition: license.php:15
$_page
$_page
Definition: memb_levels.php:84
isImage
isImage($sMimeType, &$sFileExtension)
Definition: memb_levels.php:624
_getLevelsSettingsForm
_getLevelsSettingsForm($mixedResult, $bActive=false)
Definition: memb_levels.php:428
$aInfo
$aInfo
Definition: constants.inc.php:21
$oSettings
$oSettings
Definition: memb_levels.php:18
$mixedResultAction
$mixedResultAction
Definition: memb_levels.php:23
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
$logged
$logged['admin']
Definition: memb_levels.php:16
exit
exit
Definition: cart.php:21
$aTopItems
$aTopItems
Definition: antispam.php:366
$oModuleDb
$oModuleDb
Definition: classifieds.php:20
$sTitle
$sTitle
Definition: actions.inc.php:13
PageCodeAction
PageCodeAction($iLevelId, $iActionId, $mixedResult)
Definition: memb_levels.php:499
addStringToLanguage
addStringToLanguage($langKey, $langString, $langID=-1, $categoryID=CH_WSB_LANGUAGE_CATEGORY_SYSTEM)
Definition: languages.inc.php:364
$oForm
$oForm
Definition: memb_levels.php:98
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
$bResult
$bResult
Definition: get_file.php:11
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
$sFileExtension
$sFileExtension
Definition: header.inc.php:9
_copyMatrix
_copyMatrix($iFromId, $iToId)
Definition: memb_levels.php:407
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
_getLevelsList
_getLevelsList($mixedResult, $bActive=false)
Definition: memb_levels.php:127
$iNameIndex
$iNameIndex
Definition: memb_levels.php:83
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
PageCodeActions
PageCodeActions($iId, $mixedResult)
Definition: memb_levels.php:442
$aForm
$aForm
Definition: forgot.php:43
ChBaseSearchResult\showAdminActionsPanel
static showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName='entry', $bSelectAll=true, $bSelectAllChecked=false, $sCustomHtml='')
Definition: ChBaseSearchResult.php:81
deleteMembership
deleteMembership($iId)
Definition: memb_levels.php:644
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
imageResize
imageResize( $srcFilename, $dstFilename, $sizeX, $sizeY, $forceJPGOutput=false, $isSquare=false)
Definition: images.inc.php:29
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
$mixedResultPrices
$mixedResultPrices
Definition: memb_levels.php:24
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
PageCodePrices
PageCodePrices($iId, $mixedResult)
Definition: memb_levels.php:582
$sName
$sName
Definition: ChWsbAdminTools.php:853
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10