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' );
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");
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);
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);
48 define(
'MEMBERSHIP_ID_NON_MEMBER', 1);
49 define(
'MEMBERSHIP_ID_STANDARD', 2);
50 define(
'MEMBERSHIP_ID_PROMOTION', 3);
54 define(
'CHECK_ACTION_RESULT', 0);
55 define(
'CHECK_ACTION_MESSAGE', 1);
56 define(
'CHECK_ACTION_PARAMETER', 3);
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);
124 $time = ($time ==
'') ?
time() : (int)$time;
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`
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
147 WHERE Profiles.ID = ?
149 ORDER BY `sys_acl_levels_members`.DateStarts DESC
156 if (!$aMemLevel || !count($aMemLevel)) {
159 if(!$aMemLevel || !count($aMemLevel)) {
161 echo
"<br /><b>getMemberMembershipInfo()</b> fatal error: <b>Non-Member</b> membership not found.";
170 if(is_null($aMemLevel[
'ID'])) {
172 if (!$aMemLevel || !count($aMemLevel)) {
174 echo
"<br /><b>getMemberMembershipInfo()</b> fatal error: <b>Standard</b> membership not found.";
187 $iTime = $iTime ==
'' ?
time() : (int)$iTime;
191 return $aMembershipCurrent;
193 $aMembership = $aMembershipCurrent;
195 $aMembershipLast = $aMembership;
196 if((
int)$aMembership[
'DateExpires'] == 0)
202 return $aMembershipLast;
236 $iTime = ($iTime ==
'') ?
time() : (int)$iTime;
244 return $aMembershipCurrent;
246 $aMembership = $aMembershipCurrent;
248 $iDateStarts = $aMembership[
'DateStarts'];
250 }
while($aMembership[
'ID'] == $aMembershipCurrent[
'ID'] && (
int)$aMembership[
'DateStarts']);
252 $aMembership = $aMembershipCurrent;
254 $iDateExpires = $aMembership[
'DateExpires'];
256 }
while($aMembership[
'ID'] == $aMembershipCurrent[
'ID'] && (
int)$aMembership[
'DateExpires']);
258 $aMembershipCurrent[
'DateStarts'] = $iDateStarts;
259 $aMembershipCurrent[
'DateExpires'] = $iDateExpires;
261 return $aMembershipCurrent;
313 function checkAction(
$iMemberId, $actionID, $performAction =
false, $iForcedProfID = 0, $isCheckMemberStatus =
true)
321 $arrLangFileParams = array();
323 $dateFormat =
"F j, Y, g:i a";
328 $actionID = (int)$actionID;
329 $performAction = $performAction ?
true :
false;
343 $iDestID = $iForcedProfID;
344 $performAction =
false;
350 $resMembershipAction =
db_res(
"
355 UNIX_TIMESTAMP(AllowedPeriodStart) as AllowedPeriodStart,
356 UNIX_TIMESTAMP(AllowedPeriodEnd) as AllowedPeriodEnd,
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");
366 if($resMembershipAction->rowCount() < 1) {
367 echo
"<br /><b>checkAction()</b> fatal error. Unknown action ID: $actionID<br />";
371 $arrAction = $resMembershipAction->fetch();
378 if(is_null($arrAction[
'IDAction'])) {
386 if($arrAction[
'AllowedPeriodStart'] &&
time() < $arrAction[
'AllowedPeriodStart']) {
396 if($arrAction[
'AllowedPeriodEnd'] &&
time() > $arrAction[
'AllowedPeriodEnd']) {
415 $allowedCnt = (int)$arrAction[
'AllowedCount'];
419 $periodLen = (int)$arrAction[
'AllowedPeriodLen'];
426 if($allowedCnt > 0) {
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");
434 $actionsLeft = $performAction ? $allowedCnt - 1 : $allowedCnt;
435 $validSince =
time();
436 $actionTrack = $actionTrack->fetch();
444 INSERT INTO `sys_acl_actions_track` (IDAction, IDMember, ActionsLeft, ValidSince)
445 VALUES ($actionID, $iMemberId, $actionsLeft, FROM_UNIXTIME($validSince))");
453 $periodEnd = (int)$actionTrack[
'ValidSince'] + $periodLen * 3600;
455 if($periodLen > 0 && $periodEnd <
time()) {
457 UPDATE `sys_acl_actions_track`
458 SET ActionsLeft = $actionsLeft, ValidSince = FROM_UNIXTIME($validSince)
459 WHERE IDAction = $actionID AND IDMember = $iMemberId");
467 $actionsLeft = (int)$actionTrack[
'ActionsLeft'];
471 if($actionsLeft <= 0 ) {
488 UPDATE `sys_acl_actions_track`
489 SET ActionsLeft = $actionsLeft
490 WHERE IDAction = $actionID AND IDMember = $iMemberId");
514 $iMembershipId = (int)$iMembershipId;
516 $aMembership =
db_arr(
"SELECT
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 .
"'"
525 if(!is_array($aMembership) ||
empty($aMembership))
528 $iMembershipId = (int)$aMembership[
'ID'];
535 if($aMembership[
'Active'] !=
'yes' || $aMembership[
'Purchasable'] !=
'yes')
564 $iMembershipId = (int)$iMembershipId;
565 $iDays = (int)$iDays;
566 $bStartsNow = $bStartsNow ?
true :
false;
568 $SECONDS_IN_DAY = 86400;
573 if(
empty($sTransactionId))
574 $sTransactionId =
'NULL';
582 $iRes = (int)
db_value(
"SELECT COUNT(`ID`) FROM `sys_acl_levels` WHERE `ID`='" . $iMembershipId .
"' LIMIT 1");
600 $res =
db_res(
"DELETE FROM `sys_acl_levels_members` WHERE `IDMember`='" .
$iMemberId .
"' AND (`DateExpires` IS NULL OR `DateExpires`>NOW())");
608 $iDateStarts =
time();
614 if(!is_null($aMembershipLatest[
'DateExpires']))
615 $iDateStarts = $aMembershipLatest[
'DateExpires'];
620 db_res(
"DELETE FROM `sys_acl_levels_members` WHERE `IDMember`='" .
$iMemberId .
"'");
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 .
"')");
634 $oZ =
new ChWsbAlerts(
'profile',
'set_membership',
'',
$iMemberId, array(
'mlevel'=> $iMembershipId,
'days' => $iDays,
'starts_now' => $bStartsNow,
'txn_id' => $sTransactionId));
640 $aTemplate = $oEmailTemplate->getTemplate(
't_MemChanged',
$iMemberId);
643 $aTemplateVars = array(
644 'MembershipLevel' => $aMembershipInfo[
'Name']
651 $aTemplate = $oEmailTemplate->parseTemplate(
't_UserMemChanged', $aTemplateVars,
$iMemberId);
652 sendMail(
$GLOBALS[
'site'][
'email'], $aTemplate[
'Subject'], $aTemplate[
'Body']);
674 $queryPurchasable =
'';
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'";
680 $resMemLevels =
db_res(
"SELECT DISTINCT `sys_acl_levels`.ID, `sys_acl_levels`.Name FROM `sys_acl_levels` $queryPurchasable");
682 while($r = $resMemLevels->fetch()) {
683 $result[(int)$r[
'ID']] = $r[
'Name'];
700 $iMembershipId = (int)$iMembershipId;
703 $resMemLevelPrices =
db_res(
"SELECT Days, Price FROM `sys_acl_level_prices` WHERE IDLevel = $iMembershipId ORDER BY Days ASC");
705 while(list($days, $price) = $resMemLevelPrices->fetch()) {
706 $result[(int)$days] = (
float)$price;
726 $iMembershipId = (int)$iMembershipId;
729 $resMemLevels =
db_res(
"SELECT Name, Active, Purchasable, Removable FROM `sys_acl_levels` WHERE ID = ?", [$iMembershipId]);
731 if($resMemLevels->rowCount() > 0) {
732 $result = $resMemLevels->fetch();
746 $aActions = array ();
748 if (!defined($sPrefix . strtoupper(str_replace(
' ',
'_',
$sName))))
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']);
762 $sNameField = isset($a[
'Name']) ?
'Name' :
'title';
763 return strcmp($a[$sNameField], $b[$sNameField]);
769 $a = current ($aActions);
770 $sNameField = isset($a[
'Name']) ?
'Name' :
'title';
772 foreach ($aActions
as $i => $a)
773 $aActions[$i][$sNameField] =
_t(
'_mma_' . str_replace(
' ',
'_', $a[$sNameField]));
775 usort ($aActions,
'membershipActionsCmp');
780 $res =
db_res(
"UPDATE `sys_acl_levels_members` SET `Expiring`='1' WHERE `IDMember`= ? AND `IDLevel`= ? AND `TransactionID`= ? LIMIT 1", [
790 $res =
db_res(
"UPDATE `sys_acl_levels_members` SET `Expiring`='0' WHERE `IDMember`= ? AND `IDLevel`= ? AND `TransactionID`= ? LIMIT 1", [
800 $res =
db_res(
"UPDATE `sys_acl_levels_members` SET `Expiring`='0' WHERE 1");
806 return db_res(
"DELETE FROM `sys_acl_actions_track` WHERE `IDMember` = ?", [
$iMemberId]);