Cheetah
membership_levels.inc.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( 'header.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC . 'db.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC . 'languages.inc.php' );
11 require_once( CH_DIRECTORY_PATH_INC . 'profiles.inc.php' );
12 
13 //MESSAGE CONSTANTS PASSED TO _t_ext() FUNCTION BY checkAction()
14 //NOTE: checkAction() RETURNS LANGUAGE DEPENDANT MESSAGES
15 
16 define('CHECK_ACTION_MESSAGE_NOT_ALLOWED', "_ACTION_NOT_ALLOWED");
17 define('CHECK_ACTION_MESSAGE_NOT_ACTIVE', "_ACTION_NOT_ACTIVE");
18 define('CHECK_ACTION_MESSAGE_LIMIT_REACHED', "_ACTION_LIMIT_REACHED");
19 define('CHECK_ACTION_MESSAGE_MESSAGE_EVERY_PERIOD', "_ACTION_EVERY_PERIOD");
20 define('CHECK_ACTION_MESSAGE_NOT_ALLOWED_BEFORE', "_ACTION_NOT_ALLOWED_BEFORE");
21 define('CHECK_ACTION_MESSAGE_NOT_ALLOWED_AFTER', "_ACTION_NOT_ALLOWED_AFTER");
22 
23 //NODES OF THE $args ARRAY THAT IS PASSED TO THE _t_ext() FUNCTION BY checkAction()
24 
25 define('CHECK_ACTION_LANG_FILE_ACTION', 1);
26 define('CHECK_ACTION_LANG_FILE_MEMBERSHIP', 2);
27 define('CHECK_ACTION_LANG_FILE_LIMIT', 3);
28 define('CHECK_ACTION_LANG_FILE_PERIOD', 4);
29 define('CHECK_ACTION_LANG_FILE_AFTER', 5);
30 define('CHECK_ACTION_LANG_FILE_BEFORE', 6);
31 define('CHECK_ACTION_LANG_FILE_SITE_EMAIL', 7);
32 
33 //ACTION ID's
34 
35 define('ACTION_ID_SEND_VKISS', 1);
36 define('ACTION_ID_VIEW_PROFILES', 2);
37 define('ACTION_ID_VOTE', 3);
38 define('ACTION_ID_SEND_MESSAGE', 4);
39 define('ACTION_ID_GET_EMAIL', 5);
40 define('ACTION_ID_COMMENTS_POST', 6);
41 define('ACTION_ID_COMMENTS_VOTE', 7);
42 define('ACTION_ID_COMMENTS_EDIT_OWN', 8);
43 define('ACTION_ID_COMMENTS_REMOVE_OWN', 9);
44 define('ACTION_ID_SEND_FRIEND_REQUEST', 10);
45 
46 //PREDEFINED MEMBERSHIP ID's
47 
48 define('MEMBERSHIP_ID_NON_MEMBER', 1);
49 define('MEMBERSHIP_ID_STANDARD', 2);
50 define('MEMBERSHIP_ID_PROMOTION', 3);
51 
52 //INDICES FOR checkAction() RESULT ARRAY
53 
54 define('CHECK_ACTION_RESULT', 0);
55 define('CHECK_ACTION_MESSAGE', 1);
56 define('CHECK_ACTION_PARAMETER', 3);
57 
58 //CHECK_ACTION_RESULT NODE VALUES
59 
60 define('CHECK_ACTION_RESULT_ALLOWED', 0);
61 define('CHECK_ACTION_RESULT_NOT_ALLOWED', 1);
62 define('CHECK_ACTION_RESULT_NOT_ACTIVE', 2);
63 define('CHECK_ACTION_RESULT_LIMIT_REACHED', 3);
64 define('CHECK_ACTION_RESULT_NOT_ALLOWED_BEFORE', 4);
65 define('CHECK_ACTION_RESULT_NOT_ALLOWED_AFTER', 5);
66 
80 /*function getMembersCount($iMembershipId = 0, $time = '', $except = false) //'A' just old unused function
81 {
82  $iMembershipId = (int)$iMembershipId;
83  $time = ($time == '') ? time() : (int)$time;
84  $except = $except ? true : false;
85 
86  if($iMembershipId == MEMBERSHIP_ID_NON_MEMBER || $iMembershipId < 0) return -1;
87 
88  $resProfiles = db_res("SELECT COUNT(*) FROM Profiles");
89 
90  $totalProfiles = mysql_fetch_row($resProfiles);
91  $totalProfiles = (int)$totalProfiles[0];
92 
93  if($iMembershipId == 0) return $totalProfiles;
94 
95  $queryWhereMembership = '';
96 
97  if($iMembershipId != MEMBERSHIP_ID_STANDARD) $queryWhereMembership = "IDLevel = $iMembershipId AND";
98 
99  $query = "
100  SELECT COUNT(DISTINCT IDMember)
101  FROM `sys_acl_levels_members`
102  WHERE $queryWhereMembership
103  (DateExpires IS NULL OR UNIX_TIMESTAMP(DateExpires) > $time) AND
104  (DateStarts IS NULL OR UNIX_TIMESTAMP(DateStarts) <= $time)";
105 
106  $resProfileMemLevels = db_res($query);
107 
108  $membershipProfiles = mysql_fetch_row($resProfileMemLevels);
109  $membershipProfiles = (int)$membershipProfiles[0];
110 
111  if($iMembershipId == MEMBERSHIP_ID_STANDARD) $membershipProfiles = $totalProfiles - $membershipProfiles;
112 
113  if($except) $membershipProfiles = $totalProfiles - $membershipProfiles;
114 
115  return $membershipProfiles;
116 }*/
117 
122 {
123  $iMemberId = (int)$iMemberId;
124  $time = ($time == '') ? time() : (int)$time;
125 
131  $aMemLevel = $GLOBALS['MySQL']->getRow("
132  SELECT `sys_acl_levels_members`.IDLevel as ID,
133  `sys_acl_levels`.Name as Name,
134  UNIX_TIMESTAMP(`sys_acl_levels_members`.DateStarts) as DateStarts,
135  UNIX_TIMESTAMP(`sys_acl_levels_members`.DateExpires) as DateExpires,
136  `sys_acl_levels_members`.`TransactionID` AS `TransactionID`
137  FROM `sys_acl_levels_members`
138  RIGHT JOIN Profiles
139  ON `sys_acl_levels_members`.IDMember = Profiles.ID
140  AND (`sys_acl_levels_members`.DateStarts IS NULL
141  OR `sys_acl_levels_members`.DateStarts <= FROM_UNIXTIME(?))
142  AND (`sys_acl_levels_members`.DateExpires IS NULL
143  OR `sys_acl_levels_members`.DateExpires > FROM_UNIXTIME(?))
144  LEFT JOIN `sys_acl_levels`
145  ON `sys_acl_levels_members`.IDLevel = `sys_acl_levels`.ID
146 
147  WHERE Profiles.ID = ?
148 
149  ORDER BY `sys_acl_levels_members`.DateStarts DESC
150 
151  LIMIT 0, 1", [$time, $time, $iMemberId]);
152 
156  if (!$aMemLevel || !count($aMemLevel)) {
157  //fetch info about Non-member membership
158  $aMemLevel = $GLOBALS['MySQL']->fromCache('sys_acl_levels' . MEMBERSHIP_ID_NON_MEMBER, 'getRow', "SELECT ID, Name FROM `sys_acl_levels` WHERE ID = ?", [MEMBERSHIP_ID_NON_MEMBER]);
159  if(!$aMemLevel || !count($aMemLevel)) {
160  //this should never happen, but just in case
161  echo "<br /><b>getMemberMembershipInfo()</b> fatal error: <b>Non-Member</b> membership not found.";
162  exit();
163  }
164  return $aMemLevel;
165  }
166 
170  if(is_null($aMemLevel['ID'])) {
171  $aMemLevel = $GLOBALS['MySQL']->fromCache('sys_acl_levels' . MEMBERSHIP_ID_STANDARD, 'getRow', "SELECT ID, Name FROM `sys_acl_levels` WHERE ID = ?", [MEMBERSHIP_ID_STANDARD]);
172  if (!$aMemLevel || !count($aMemLevel)) {
173  //again, this should never happen, but just in case
174  echo "<br /><b>getMemberMembershipInfo()</b> fatal error: <b>Standard</b> membership not found.";
175  exit();
176  }
177  }
178 
179  return $aMemLevel;
180 }
181 
186 {
187  $iTime = $iTime == '' ? time() : (int)$iTime;
188 
189  $aMembershipCurrent = getMemberMembershipInfo_current($iMemberId, $iTime);
190  if(in_array($aMembershipCurrent['ID'], array(MEMBERSHIP_ID_STANDARD, MEMBERSHIP_ID_NON_MEMBER)))
191  return $aMembershipCurrent;
192 
193  $aMembership = $aMembershipCurrent;
194  while($aMembership['ID'] != MEMBERSHIP_ID_STANDARD) {
195  $aMembershipLast = $aMembership;
196  if((int)$aMembership['DateExpires'] == 0)
197  break;
198 
199  $aMembership = getMemberMembershipInfo_current($iMemberId, $aMembership['DateExpires']);
200  }
201 
202  return $aMembershipLast;
203 }
204 
205 
234 function getMemberMembershipInfo($iMemberId, $iTime = '', $bCheckUserStatus = false)
235 {
236  $iTime = ($iTime == '') ? time() : (int)$iTime;
237 
238  if ($bCheckUserStatus && ($aProfile = getProfileInfo($iMemberId)) && $aProfile['Status'] != 'Active')
239  $aMembershipCurrent =& $GLOBALS['MySQL']->fromCache('sys_acl_levels' . MEMBERSHIP_ID_NON_MEMBER, 'getRow', "SELECT ID, Name FROM `sys_acl_levels` WHERE ID = ".MEMBERSHIP_ID_NON_MEMBER);
240  else
241  $aMembershipCurrent = getMemberMembershipInfo_current($iMemberId, $iTime);
242 
243  if(in_array($aMembershipCurrent['ID'], array(MEMBERSHIP_ID_STANDARD, MEMBERSHIP_ID_NON_MEMBER)))
244  return $aMembershipCurrent;
245 
246  $aMembership = $aMembershipCurrent;
247  do {
248  $iDateStarts = $aMembership['DateStarts'];
249  $aMembership = getMemberMembershipInfo_current($iMemberId, ((int)$iDateStarts < 1 ? 0 : $iDateStarts - 1));
250  } while($aMembership['ID'] == $aMembershipCurrent['ID'] && (int)$aMembership['DateStarts']);
251 
252  $aMembership = $aMembershipCurrent;
253  do {
254  $iDateExpires = $aMembership['DateExpires'];
255  $aMembership = getMemberMembershipInfo_current($iMemberId, $iDateExpires);
256  } while($aMembership['ID'] == $aMembershipCurrent['ID'] && (int)$aMembership['DateExpires']);
257 
258  $aMembershipCurrent['DateStarts'] = $iDateStarts;
259  $aMembershipCurrent['DateExpires'] = $iDateExpires;
260 
261  return $aMembershipCurrent;
262 }
263 
313 function checkAction($iMemberId, $actionID, $performAction = false, $iForcedProfID = 0, $isCheckMemberStatus = true)
314 {
315  global $logged;
316  global $site;
317 
318  //output array initialization
319 
320  $result = array();
321  $arrLangFileParams = array();
322 
323  $dateFormat = "F j, Y, g:i a"; //used when displaying error messages
324 
325  //input validation
326 
327  $iMemberId = (int)$iMemberId;
328  $actionID = (int)$actionID;
329  $performAction = $performAction ? true : false;
330 
331  //get current member's membership information
332 
333  $arrMembership = getMemberMembershipInfo($iMemberId, '', $isCheckMemberStatus);
334 
335  $arrLangFileParams[CHECK_ACTION_LANG_FILE_MEMBERSHIP] = $arrMembership['Name'];
336  $arrLangFileParams[CHECK_ACTION_LANG_FILE_SITE_EMAIL] = $site['email'];
337 
338  //profile active check
339 
340  if($arrMembership['ID'] != MEMBERSHIP_ID_NON_MEMBER || $logged['admin'] || $logged['moderator']) {
341  $iDestID = $iMemberId;
342  if ( (isAdmin() || isModerator()) && $iForcedProfID>0) {
343  $iDestID = $iForcedProfID;
344  $performAction = false;
345  }
346  }
347 
348  //get permissions for the current action
349 
350  $resMembershipAction = db_res("
351  SELECT Name,
352  IDAction,
353  AllowedCount,
354  AllowedPeriodLen,
355  UNIX_TIMESTAMP(AllowedPeriodStart) as AllowedPeriodStart,
356  UNIX_TIMESTAMP(AllowedPeriodEnd) as AllowedPeriodEnd,
357  AdditionalParamValue
358  FROM `sys_acl_actions`
359  LEFT JOIN `sys_acl_matrix`
360  ON `sys_acl_matrix`.IDAction = `sys_acl_actions`.ID
361  AND `sys_acl_matrix`.IDLevel = {$arrMembership['ID']}
362  WHERE `sys_acl_actions`.ID = $actionID");
363 
364  //no such action
365 
366  if($resMembershipAction->rowCount() < 1) {
367  echo "<br /><b>checkAction()</b> fatal error. Unknown action ID: $actionID<br />";
368  exit();
369  }
370 
371  $arrAction = $resMembershipAction->fetch();
372 
373  $result[CHECK_ACTION_PARAMETER] = $arrAction['AdditionalParamValue'];
374  $arrLangFileParams[CHECK_ACTION_LANG_FILE_ACTION] = _t('_mma_' . str_replace(' ', '_', $arrAction['Name']));
375 
376  //action is not allowed for the current membership
377 
378  if(is_null($arrAction['IDAction'])) {
380  $result[CHECK_ACTION_MESSAGE] = _t_ext(CHECK_ACTION_MESSAGE_NOT_ALLOWED, $arrLangFileParams);
381  return $result;
382  }
383 
384  //Check fixed period limitations if present (also for non-members)
385 
386  if($arrAction['AllowedPeriodStart'] && time() < $arrAction['AllowedPeriodStart']) {
387 
388  $arrLangFileParams[CHECK_ACTION_LANG_FILE_BEFORE] = date($dateFormat, $arrAction['AllowedPeriodStart']);
389 
392 
393  return $result;
394  }
395 
396  if($arrAction['AllowedPeriodEnd'] && time() > $arrAction['AllowedPeriodEnd']) {
397 
398  $arrLangFileParams[CHECK_ACTION_LANG_FILE_AFTER] = date($dateFormat, $arrAction['AllowedPeriodEnd']);
399 
402 
403  return $result;
404  }
405 
406  //if non-member, allow action without performing further checks
407 
408  if ($arrMembership['ID'] == MEMBERSHIP_ID_NON_MEMBER) {
410  return $result;
411  }
412 
413  //check other limitations (for members only)
414 
415  $allowedCnt = (int)$arrAction['AllowedCount']; //number of allowed actions
416  //if not specified or 0, number of
417  //actions is unlimited
418 
419  $periodLen = (int)$arrAction['AllowedPeriodLen']; //period for AllowedCount in hours
420  //if not specified, AllowedCount is
421  //treated as total number of actions
422  //permitted
423 
424  //number of actions is limited
425 
426  if($allowedCnt > 0) {
427  //get current action info for the member
428 
429  $actionTrack = db_res("SELECT ActionsLeft,
430  UNIX_TIMESTAMP(ValidSince) as ValidSince
431  FROM `sys_acl_actions_track`
432  WHERE IDAction = $actionID AND IDMember = $iMemberId");
433 
434  $actionsLeft = $performAction ? $allowedCnt - 1 : $allowedCnt;
435  $validSince = time();
436  $actionTrack = $actionTrack->fetch();
437 
438  //member is requesting/performing this action for the first time,
439  //and there is no corresponding record in sys_acl_actions_track table
440 
441  if (!$actionTrack) {
442  //add action to sys_acl_actions_track table
443  db_res("
444  INSERT INTO `sys_acl_actions_track` (IDAction, IDMember, ActionsLeft, ValidSince)
445  VALUES ($actionID, $iMemberId, $actionsLeft, FROM_UNIXTIME($validSince))");
446 
448  return $result;
449  }
450 
451  //action record in sys_acl_actions_track table is out of date
452 
453  $periodEnd = (int)$actionTrack['ValidSince'] + $periodLen * 3600; //ValidSince is in seconds, PeriodLen is in hours
454 
455  if($periodLen > 0 && $periodEnd < time()) {
456  db_res("
457  UPDATE `sys_acl_actions_track`
458  SET ActionsLeft = $actionsLeft, ValidSince = FROM_UNIXTIME($validSince)
459  WHERE IDAction = $actionID AND IDMember = $iMemberId");
460 
462  return $result;
463  }
464 
465  //action record is up to date
466 
467  $actionsLeft = (int)$actionTrack['ActionsLeft'];
468 
469  //action limit reached for now
470 
471  if($actionsLeft <= 0 ) {
472  $arrLangFileParams[CHECK_ACTION_LANG_FILE_LIMIT] = $allowedCnt;
473  $arrLangFileParams[CHECK_ACTION_LANG_FILE_PERIOD] = $periodLen;
474 
476  $result[CHECK_ACTION_MESSAGE] = '<div style="width: 80%">' .
477  _t_ext(CHECK_ACTION_MESSAGE_LIMIT_REACHED, $arrLangFileParams) .
478  ($periodLen > 0 ? _t_ext(CHECK_ACTION_MESSAGE_MESSAGE_EVERY_PERIOD, $arrLangFileParams) : '') .
479  '.</div>';
480 
481  return $result;
482  }
483 
484  if($performAction) {
485  $actionsLeft--;
486 
487  db_res("
488  UPDATE `sys_acl_actions_track`
489  SET ActionsLeft = $actionsLeft
490  WHERE IDAction = $actionID AND IDMember = $iMemberId");
491  }
492  }
493 
495  return $result;
496 }
497 
511 function buyMembership($iMemberId, $iMembershipId, $sTransactionId, $bStartsNow = false)
512 {
513  $iMemberId = (int)$iMemberId;
514  $iMembershipId = (int)$iMembershipId;
515 
516  $aMembership = db_arr("SELECT
517  `tl`.`ID` AS `ID`,
518  `tlp`.`Days` AS `Days`,
519  `tl`.`Active` AS `Active`,
520  `tl`.`Purchasable` AS `Purchasable`
521  FROM `sys_acl_levels` AS `tl`
522  LEFT JOIN `sys_acl_level_prices` AS `tlp` ON `tl`.`ID`=`tlp`.`IDLevel`
523  WHERE `tlp`.`id`='" . $iMembershipId . "'"
524  );
525  if(!is_array($aMembership) || empty($aMembership))
526  return false;
527 
528  $iMembershipId = (int)$aMembership['ID'];
529 
530  //check for predefined non-purchasable memberships
531  if(in_array($iMembershipId, array(MEMBERSHIP_ID_NON_MEMBER, MEMBERSHIP_ID_STANDARD, MEMBERSHIP_ID_PROMOTION)))
532  return false;
533 
534  //check if membership is active and purchasable
535  if($aMembership['Active'] != 'yes' || $aMembership['Purchasable'] != 'yes')
536  return false;
537 
538  return setMembership($iMemberId, $iMembershipId, $aMembership['Days'], $bStartsNow, $sTransactionId);
539 }
540 
561 function setMembership($iMemberId, $iMembershipId, $iDays = 0, $bStartsNow = false, $sTransactionId = '', $isSendMail = true)
562 {
563  $iMemberId = (int)$iMemberId;
564  $iMembershipId = (int)$iMembershipId;
565  $iDays = (int)$iDays;
566  $bStartsNow = $bStartsNow ? true : false;
567 
568  $SECONDS_IN_DAY = 86400;
569 
570  if(!$iMemberId)
571  $iMemberId = -1;
572 
573  if(empty($sTransactionId))
574  $sTransactionId = 'NULL';
575 
576  //check if member exists
578  if(!$aProfileInfo)
579  return false;
580 
581  //check if membership exists
582  $iRes = (int)db_value("SELECT COUNT(`ID`) FROM `sys_acl_levels` WHERE `ID`='" . $iMembershipId . "' LIMIT 1");
583  if($iRes != 1)
584  return false;
585 
586  if($iMembershipId == MEMBERSHIP_ID_NON_MEMBER)
587  return false;
588 
589  $aMembershipCurrent = getMemberMembershipInfo($iMemberId);
590  $aMembershipLatest = getMemberMembershipInfo_latest($iMemberId);
591 
595  if($iMembershipId == MEMBERSHIP_ID_STANDARD) {
596  if($aMembershipCurrent['ID'] == MEMBERSHIP_ID_STANDARD)
597  return true;
598 
599  //delete any present and future memberships
600  $res = db_res("DELETE FROM `sys_acl_levels_members` WHERE `IDMember`='" . $iMemberId . "' AND (`DateExpires` IS NULL OR `DateExpires`>NOW())");
601  if(db_affected_rows($res) <= 0)
602  return false;
603  }
604 
605  if($iDays < 0)
606  return false;
607 
608  $iDateStarts = time();
609  if(!$bStartsNow) {
614  if(!is_null($aMembershipLatest['DateExpires']))
615  $iDateStarts = $aMembershipLatest['DateExpires'];
616  else if(is_null($aMembershipLatest['DateExpires']) && $aMembershipLatest['ID'] != MEMBERSHIP_ID_STANDARD)
617  return false;
618  } else {
619  // delete previous profile's membership level and actions traces
620  db_res("DELETE FROM `sys_acl_levels_members` WHERE `IDMember`='" . $iMemberId . "'");
622  }
623 
627  $iDateExpires = $iDays != 0 ? (int)$iDateStarts + $iDays * $SECONDS_IN_DAY : 'NULL';
628  $res = db_res("INSERT `sys_acl_levels_members` (`IDMember`, `IDLevel`, `DateStarts`, `DateExpires`, `TransactionID`) VALUES ('" . $iMemberId . "', '" . $iMembershipId . "', FROM_UNIXTIME(" . $iDateStarts . "), FROM_UNIXTIME(" . $iDateExpires . "), '" . $sTransactionId . "')");
629  if(db_affected_rows($res) <= 0)
630  return false;
631 
632  //Set Membership Alert
633  ch_import('ChWsbAlerts');
634  $oZ = new ChWsbAlerts('profile', 'set_membership', '', $iMemberId, array('mlevel'=> $iMembershipId, 'days' => $iDays, 'starts_now' => $bStartsNow, 'txn_id' => $sTransactionId));
635  $oZ->alert();
636 
637  //Notify user about changed membership level
638  ch_import('ChWsbEmailTemplates');
639  $oEmailTemplate = new ChWsbEmailTemplates();
640  $aTemplate = $oEmailTemplate->getTemplate('t_MemChanged', $iMemberId);
641 
642  $aMembershipInfo = getMembershipInfo($iMembershipId);
643  $aTemplateVars = array(
644  'MembershipLevel' => $aMembershipInfo['Name']
645  );
646 
647  if ($isSendMail)
648  sendMail( $aProfileInfo['Email'], $aTemplate['Subject'], $aTemplate['Body'], $iMemberId, $aTemplateVars);
649 
650  //Notify admin about changed user's membership level
651  $aTemplate = $oEmailTemplate->parseTemplate('t_UserMemChanged', $aTemplateVars, $iMemberId);
652  sendMail($GLOBALS['site']['email'], $aTemplate['Subject'], $aTemplate['Body']);
653 
654  return true;
655 }
656 
670 function getMemberships($purchasableOnly = false)
671 {
672  $result = array();
673 
674  $queryPurchasable = '';
675 
676  if($purchasableOnly) {
677  $queryPurchasable = "INNER JOIN `sys_acl_level_prices` ON `sys_acl_level_prices`.IDLevel = `sys_acl_levels`.ID WHERE Purchasable = 'yes' AND Active = 'yes'";
678  }
679 
680  $resMemLevels = db_res("SELECT DISTINCT `sys_acl_levels`.ID, `sys_acl_levels`.Name FROM `sys_acl_levels` $queryPurchasable");
681 
682  while($r = $resMemLevels->fetch()) {
683  $result[(int)$r['ID']] = $r['Name'];
684  }
685 
686  return $result;
687 }
688 
698 function getMembershipPrices($iMembershipId)
699 {
700  $iMembershipId = (int)$iMembershipId;
701  $result = array();
702 
703  $resMemLevelPrices = db_res("SELECT Days, Price FROM `sys_acl_level_prices` WHERE IDLevel = $iMembershipId ORDER BY Days ASC");
704 
705  while(list($days, $price) = $resMemLevelPrices->fetch()) {
706  $result[(int)$days] = (float)$price;
707  }
708 
709  return $result;
710 }
711 
724 function getMembershipInfo($iMembershipId)
725 {
726  $iMembershipId = (int)$iMembershipId;
727  $result = array();
728 
729  $resMemLevels = db_res("SELECT Name, Active, Purchasable, Removable FROM `sys_acl_levels` WHERE ID = ?", [$iMembershipId]);
730 
731  if($resMemLevels->rowCount() > 0) {
732  $result = $resMemLevels->fetch();
733  }
734 
735  return $result;
736 }
737 
744 function defineMembershipActions ($aActionsAll, $sPrefix = 'CH_')
745 {
746  $aActions = array ();
747  foreach ($aActionsAll as $sName)
748  if (!defined($sPrefix . strtoupper(str_replace(' ', '_', $sName))))
749  $aActions[] = $sName;
750  if (!$aActions)
751  return;
752 
753  $sPlaceholders = implode(',', array_fill(0, count($aActions), '?'));
754  $res = db_res("SELECT `ID`, `Name` FROM `sys_acl_actions` WHERE `Name` IN({$sPlaceholders})", $aActions);
755  while ($r = $res->fetch()) {
756  define ($sPrefix . strtoupper(str_replace(' ', '_', $r['Name'])), $r['ID']);
757  }
758 }
759 
760 function membershipActionsCmp($a, $b)
761 {
762  $sNameField = isset($a['Name']) ? 'Name' : 'title';
763  return strcmp($a[$sNameField], $b[$sNameField]);
764 }
765 
766 function translateMembershipActions (&$aActions)
767 {
768  reset($aActions);
769  $a = current ($aActions);
770  $sNameField = isset($a['Name']) ? 'Name' : 'title';
771 
772  foreach ($aActions as $i => $a)
773  $aActions[$i][$sNameField] = _t('_mma_' . str_replace(' ', '_', $a[$sNameField]));
774 
775  usort ($aActions, 'membershipActionsCmp');
776 }
777 
778 function markMembershipAsExpiring($iMemberId, $iLevelId, $sTransactionId)
779 {
780  $res = db_res("UPDATE `sys_acl_levels_members` SET `Expiring`='1' WHERE `IDMember`= ? AND `IDLevel`= ? AND `TransactionID`= ? LIMIT 1", [
781  $iMemberId,
782  $iLevelId,
783  $sTransactionId
784  ]);
785  return db_affected_rows($res) > 0;
786 }
787 
789 {
790  $res = db_res("UPDATE `sys_acl_levels_members` SET `Expiring`='0' WHERE `IDMember`= ? AND `IDLevel`= ? AND `TransactionID`= ? LIMIT 1", [
791  $iMemberId,
792  $iLevelId,
793  $sTransactionId
794  ]);
795  return db_affected_rows($res) > 0;
796 }
797 
799 {
800  $res = db_res("UPDATE `sys_acl_levels_members` SET `Expiring`='0' WHERE 1");
801  return db_affected_rows($res) > 0;
802 }
803 
805 {
806  return db_res("DELETE FROM `sys_acl_actions_track` WHERE `IDMember` = ?", [$iMemberId]);
807 }
CHECK_ACTION_RESULT_NOT_ALLOWED_BEFORE
const CHECK_ACTION_RESULT_NOT_ALLOWED_BEFORE
Definition: membership_levels.inc.php:64
$iMemberId
$iMemberId
Definition: profile.php:91
$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
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
CHECK_ACTION_RESULT_LIMIT_REACHED
const CHECK_ACTION_RESULT_LIMIT_REACHED
Definition: membership_levels.inc.php:63
translateMembershipActions
translateMembershipActions(&$aActions)
Definition: membership_levels.inc.php:766
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
membershipActionsCmp
membershipActionsCmp($a, $b)
Definition: membership_levels.inc.php:760
ChWsbEmailTemplates
Definition: ChWsbEmailTemplates.php:11
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
unmarkMembershipAsExpiring
unmarkMembershipAsExpiring($iMemberId, $iLevelId, $sTransactionId)
Definition: membership_levels.inc.php:788
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
sendMail
sendMail( $sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID=0, $aPlus=array(), $sEmailFlag='html', $isDisableAlert=false, $bForceSend=false)
Definition: utils.inc.php:461
CHECK_ACTION_MESSAGE
const CHECK_ACTION_MESSAGE
Definition: membership_levels.inc.php:55
setMembership
setMembership($iMemberId, $iMembershipId, $iDays=0, $bStartsNow=false, $sTransactionId='', $isSendMail=true)
Definition: membership_levels.inc.php:561
CHECK_ACTION_MESSAGE_NOT_ALLOWED
const CHECK_ACTION_MESSAGE_NOT_ALLOWED
Definition: membership_levels.inc.php:16
buyMembership
buyMembership($iMemberId, $iMembershipId, $sTransactionId, $bStartsNow=false)
Definition: membership_levels.inc.php:511
php
$oZ
$oZ
Definition: db.php:20
unmarkMembershipAsExpiringAll
unmarkMembershipAsExpiringAll()
Definition: membership_levels.inc.php:798
MEMBERSHIP_ID_STANDARD
const MEMBERSHIP_ID_STANDARD
Definition: membership_levels.inc.php:49
getMemberMembershipInfo_current
getMemberMembershipInfo_current($iMemberId, $time='')
Definition: membership_levels.inc.php:121
getMemberMembershipInfo_latest
getMemberMembershipInfo_latest($iMemberId, $iTime='')
Definition: membership_levels.inc.php:185
CHECK_ACTION_PARAMETER
const CHECK_ACTION_PARAMETER
Definition: membership_levels.inc.php:56
CHECK_ACTION_LANG_FILE_MEMBERSHIP
const CHECK_ACTION_LANG_FILE_MEMBERSHIP
Definition: membership_levels.inc.php:26
CHECK_ACTION_MESSAGE_LIMIT_REACHED
const CHECK_ACTION_MESSAGE_LIMIT_REACHED
Definition: membership_levels.inc.php:18
getMemberships
getMemberships($purchasableOnly=false)
Definition: membership_levels.inc.php:670
getMembershipInfo
getMembershipInfo($iMembershipId)
Definition: membership_levels.inc.php:724
isAdmin
isAdmin()
Definition: index.php:649
isModerator
isModerator($iId=0)
Definition: profiles.inc.php:58
clearActionsTracksForMember
clearActionsTracksForMember($iMemberId)
Definition: membership_levels.inc.php:804
ChWsbAlerts
Definition: ChWsbAlerts.php:39
db_arr
db_arr($query, $bindings=[])
Definition: db.inc.php:76
exit
exit
Definition: cart.php:21
$aProfile
$aProfile
Definition: flash.php:14
_t_ext
_t_ext($key, $args)
Definition: languages.inc.php:524
$site
$site['ver']
Definition: version.inc.php:8
CHECK_ACTION_LANG_FILE_ACTION
const CHECK_ACTION_LANG_FILE_ACTION
Definition: membership_levels.inc.php:25
CHECK_ACTION_LANG_FILE_BEFORE
const CHECK_ACTION_LANG_FILE_BEFORE
Definition: membership_levels.inc.php:30
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
CHECK_ACTION_RESULT_NOT_ALLOWED
const CHECK_ACTION_RESULT_NOT_ALLOWED
Definition: membership_levels.inc.php:61
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
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
CHECK_ACTION_LANG_FILE_LIMIT
const CHECK_ACTION_LANG_FILE_LIMIT
Definition: membership_levels.inc.php:27
db_affected_rows
db_affected_rows($oStmt=null)
Definition: db.inc.php:56
CHECK_ACTION_LANG_FILE_AFTER
const CHECK_ACTION_LANG_FILE_AFTER
Definition: membership_levels.inc.php:29
MEMBERSHIP_ID_NON_MEMBER
const MEMBERSHIP_ID_NON_MEMBER
Definition: membership_levels.inc.php:48
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
defineMembershipActions
defineMembershipActions($aActionsAll, $sPrefix='CH_')
Definition: membership_levels.inc.php:744
$aProfileInfo
$aProfileInfo
Definition: short_profile_info.php:23
CHECK_ACTION_MESSAGE_NOT_ALLOWED_BEFORE
const CHECK_ACTION_MESSAGE_NOT_ALLOWED_BEFORE
Definition: membership_levels.inc.php:20
getMemberMembershipInfo
getMemberMembershipInfo($iMemberId, $iTime='', $bCheckUserStatus=false)
Definition: membership_levels.inc.php:234
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
CHECK_ACTION_LANG_FILE_PERIOD
const CHECK_ACTION_LANG_FILE_PERIOD
Definition: membership_levels.inc.php:28
CHECK_ACTION_MESSAGE_NOT_ALLOWED_AFTER
const CHECK_ACTION_MESSAGE_NOT_ALLOWED_AFTER
Definition: membership_levels.inc.php:21
getMembershipPrices
getMembershipPrices($iMembershipId)
Definition: membership_levels.inc.php:698
$logged
$logged['member']
Definition: activation_email.php:16
CHECK_ACTION_RESULT_NOT_ALLOWED_AFTER
const CHECK_ACTION_RESULT_NOT_ALLOWED_AFTER
Definition: membership_levels.inc.php:65
CHECK_ACTION_MESSAGE_MESSAGE_EVERY_PERIOD
const CHECK_ACTION_MESSAGE_MESSAGE_EVERY_PERIOD
Definition: membership_levels.inc.php:19
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
markMembershipAsExpiring
markMembershipAsExpiring($iMemberId, $iLevelId, $sTransactionId)
Definition: membership_levels.inc.php:778
MEMBERSHIP_ID_PROMOTION
const MEMBERSHIP_ID_PROMOTION
Definition: membership_levels.inc.php:50
CHECK_ACTION_LANG_FILE_SITE_EMAIL
const CHECK_ACTION_LANG_FILE_SITE_EMAIL
Definition: membership_levels.inc.php:31
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10