/** * Edit or add a user subscription. * * - Accessed from ?action=admin;area=paidsubscribe;sa=modifyuser */ public function action_modifyuser() { global $context, $txt, $modSettings; require_once SUBSDIR . '/PaidSubscriptions.subs.php'; loadSubscriptions(); $context['log_id'] = isset($_REQUEST['lid']) ? (int) $_REQUEST['lid'] : 0; $context['sub_id'] = isset($_REQUEST['sid']) ? (int) $_REQUEST['sid'] : 0; $context['action_type'] = $context['log_id'] ? 'edit' : 'add'; // Setup the template. $context['sub_template'] = 'modify_user_subscription'; $context['page_title'] = $txt[$context['action_type'] . '_subscriber']; loadJavascriptFile('suggest.js', array('defer' => true)); // If we haven't been passed the subscription ID get it. if ($context['log_id'] && !$context['sub_id']) { $context['sub_id'] = validateSubscriptionID($context['log_id']); } if (!isset($context['subscriptions'][$context['sub_id']])) { fatal_lang_error('no_access', false); } $context['current_subscription'] = $context['subscriptions'][$context['sub_id']]; // Searching? if (isset($_POST['ssearch'])) { return $this->action_viewsub(); } elseif (isset($_REQUEST['save_sub'])) { checkSession(); // Work out the dates... $starttime = mktime($_POST['hour'], $_POST['minute'], 0, $_POST['month'], $_POST['day'], $_POST['year']); $endtime = mktime($_POST['hourend'], $_POST['minuteend'], 0, $_POST['monthend'], $_POST['dayend'], $_POST['yearend']); // Status. $status = $_POST['status']; // New one? if (empty($context['log_id'])) { // Find the user... require_once SUBSDIR . '/Members.subs.php'; $member = getMemberByName($_POST['name']); if (empty($member)) { fatal_lang_error('error_member_not_found'); } if (alreadySubscribed($context['sub_id'], $member['id_member'])) { fatal_lang_error('member_already_subscribed'); } // Actually put the subscription in place. if ($status == 1) { addSubscription($context['sub_id'], $member['id_member'], 0, $starttime, $endtime); } else { $details = array('id_subscribe' => $context['sub_id'], 'id_member' => $member['id_member'], 'id_group' => $member['id_group'], 'start_time' => $starttime, 'end_time' => $endtime, 'status' => $status); logSubscription($details); } } else { $subscription_status = getSubscriptionStatus($context['log_id']); // Pick the right permission stuff depending on what the status is changing from/to. if ($subscription_status['old_status'] == 1 && $status != 1) { removeSubscription($context['sub_id'], $subscription_status['id_member']); } elseif ($status == 1 && $subscription_status['old_status'] != 1) { addSubscription($context['sub_id'], $subscription_status['id_member'], 0, $starttime, $endtime); } else { $item = array('start_time' => $starttime, 'end_time' => $endtime, 'status' => $status, 'current_log_item' => $context['log_id']); updateSubscriptionItem($item); } } // Done - redirect... redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']); } elseif (isset($_REQUEST['delete']) || isset($_REQUEST['finished'])) { checkSession(); // Do the actual deletes! if (!empty($_REQUEST['delsub'])) { $toDelete = array(); foreach ($_REQUEST['delsub'] as $id => $dummy) { $toDelete[] = (int) $id; } $deletes = prepareDeleteSubscriptions($toDelete); foreach ($deletes as $id_subscribe => $id_member) { removeSubscription($id_subscribe, $id_member, isset($_REQUEST['delete'])); } } redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']); } // Default attributes. if ($context['action_type'] == 'add') { $context['sub'] = array('id' => 0, 'start' => array('year' => (int) strftime('%Y', time()), 'month' => (int) strftime('%m', time()), 'day' => (int) strftime('%d', time()), 'hour' => (int) strftime('%H', time()), 'min' => (int) strftime('%M', time()) < 10 ? '0' . (int) strftime('%M', time()) : (int) strftime('%M', time()), 'last_day' => 0), 'end' => array('year' => (int) strftime('%Y', time()), 'month' => (int) strftime('%m', time()), 'day' => (int) strftime('%d', time()), 'hour' => (int) strftime('%H', time()), 'min' => (int) strftime('%M', time()) < 10 ? '0' . (int) strftime('%M', time()) : (int) strftime('%M', time()), 'last_day' => 0), 'status' => 1); $context['sub']['start']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['start']['month'] == 12 ? 1 : $context['sub']['start']['month'] + 1, 0, $context['sub']['start']['month'] == 12 ? $context['sub']['start']['year'] + 1 : $context['sub']['start']['year'])); $context['sub']['end']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['end']['month'] == 12 ? 1 : $context['sub']['end']['month'] + 1, 0, $context['sub']['end']['month'] == 12 ? $context['sub']['end']['year'] + 1 : $context['sub']['end']['year'])); if (isset($_GET['uid'])) { require_once SUBSDIR . '/Members.subs.php'; // Get the latest activated member's display name. $result = getBasicMemberData((int) $_GET['uid']); $context['sub']['username'] = $result['real_name']; } else { $context['sub']['username'] = ''; } } else { $row = getPendingSubscriptions($context['log_id']); if (empty($row)) { fatal_lang_error('no_access', false); } // Any pending payments? $context['pending_payments'] = array(); if (!empty($row['pending_details'])) { $pending_details = @unserialize($row['pending_details']); foreach ($pending_details as $id => $pending) { // Only this type need be displayed. if ($pending[3] == 'payback') { // Work out what the options were. $costs = @unserialize($context['current_subscription']['real_cost']); if ($context['current_subscription']['real_length'] == 'F') { foreach ($costs as $duration => $cost) { if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) { $context['pending_payments'][$id] = array('desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration])); } } } elseif ($costs['fixed'] == $pending[1]) { $context['pending_payments'][$id] = array('desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed'])); } } } // Check if we are adding/removing any. if (isset($_GET['pending'])) { foreach ($pending_details as $id => $pending) { // Found the one to action? if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id])) { // Flexible? if (isset($_GET['accept'])) { addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0); } unset($pending_details[$id]); $new_details = serialize($pending_details); // Update the entry. updatePendingSubscription($context['log_id'], $new_details); // Reload redirectexit('action=admin;area=paidsubscribe;sa=modifyuser;lid=' . $context['log_id']); } } } } $context['sub_id'] = $row['id_subscribe']; $context['sub'] = array('id' => 0, 'start' => array('year' => (int) strftime('%Y', $row['start_time']), 'month' => (int) strftime('%m', $row['start_time']), 'day' => (int) strftime('%d', $row['start_time']), 'hour' => (int) strftime('%H', $row['start_time']), 'min' => (int) strftime('%M', $row['start_time']) < 10 ? '0' . (int) strftime('%M', $row['start_time']) : (int) strftime('%M', $row['start_time']), 'last_day' => 0), 'end' => array('year' => (int) strftime('%Y', $row['end_time']), 'month' => (int) strftime('%m', $row['end_time']), 'day' => (int) strftime('%d', $row['end_time']), 'hour' => (int) strftime('%H', $row['end_time']), 'min' => (int) strftime('%M', $row['end_time']) < 10 ? '0' . (int) strftime('%M', $row['end_time']) : (int) strftime('%M', $row['end_time']), 'last_day' => 0), 'status' => $row['status'], 'username' => $row['username']); $context['sub']['start']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['start']['month'] == 12 ? 1 : $context['sub']['start']['month'] + 1, 0, $context['sub']['start']['month'] == 12 ? $context['sub']['start']['year'] + 1 : $context['sub']['start']['year'])); $context['sub']['end']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['sub']['end']['month'] == 12 ? 1 : $context['sub']['end']['month'] + 1, 0, $context['sub']['end']['month'] == 12 ? $context['sub']['end']['year'] + 1 : $context['sub']['end']['year'])); } }
/** * List and allow adding/entering all man rules, such as * * What it does: * - If it itches, it will be scratched. * - Yes or No are perfectly acceptable answers to almost every question. * - Men see in only 16 colors, Peach, for example, is a fruit, not a color. * * @uses sub template rules */ public function action_manrules() { global $txt, $context, $user_info, $scripturl; require_once SUBSDIR . '/PersonalMessage.subs.php'; // The link tree - gotta have this :o $context['linktree'][] = array('url' => $scripturl . '?action=pm;sa=manrules', 'name' => $txt['pm_manage_rules']); $context['page_title'] = $txt['pm_manage_rules']; $context['sub_template'] = 'rules'; // Load them... load them!! loadRules(); // Likely to need all the groups! require_once SUBSDIR . '/Membergroups.subs.php'; $context['groups'] = accessibleGroups(); // Applying all rules? if (isset($_GET['apply'])) { checkSession('get'); applyRules(true); redirectexit('action=pm;sa=manrules'); } // Editing a specific rule? if (isset($_GET['add'])) { $context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0; $context['sub_template'] = 'add_rule'; // Any known rule $js_rules = ''; foreach ($context['known_rules'] as $rule) { $js_rules .= JavaScriptEscape($rule) . ': ' . JavaScriptEscape($txt['pm_rule_' . $rule]) . ','; } $js_rules = '{' . substr($js_rules, 0, -1) . '}'; // Any known label $js_labels = ''; foreach ($context['labels'] as $label) { if ($label['id'] != -1) { $js_labels .= JavaScriptEscape($label['id'] + 1) . ': ' . JavaScriptEscape($label['name']) . ','; } } $js_labels = '{' . substr($js_labels, 0, -1) . '}'; // And all of the groups as well $js_groups = ''; foreach ($context['groups'] as $id => $title) { $js_groups .= JavaScriptEscape($id) . ': ' . JavaScriptEscape($title) . ','; } $js_groups = '{' . substr($js_groups, 0, -1) . '}'; // Oh my, we have a lot of text strings for this addJavascriptVar(array('criteriaNum' => 0, 'actionNum' => 0, 'groups' => $js_groups, 'labels' => $js_labels, 'rules' => $js_rules, 'txt_pm_readable_and' => $txt['pm_readable_and'], 'txt_pm_readable_or' => $txt['pm_readable_or'], 'txt_pm_readable_member' => $txt['pm_readable_member'], 'txt_pm_readable_group' => $txt['pm_readable_group'], 'txt_pm_readable_subject ' => $txt['pm_readable_subject'], 'txt_pm_readable_body' => $txt['pm_readable_body'], 'txt_pm_readable_buddy' => $txt['pm_readable_buddy'], 'txt_pm_readable_label' => $txt['pm_readable_label'], 'txt_pm_readable_delete' => $txt['pm_readable_delete'], 'txt_pm_readable_start' => $txt['pm_readable_start'], 'txt_pm_readable_end' => $txt['pm_readable_end'], 'txt_pm_readable_then' => $txt['pm_readable_then'], 'txt_pm_rule_not_defined' => $txt['pm_rule_not_defined'], 'txt_pm_rule_criteria_pick' => $txt['pm_rule_criteria_pick'], 'txt_pm_rule_sel_group' => $txt['pm_rule_sel_group'], 'txt_pm_rule_sel_action' => $txt['pm_rule_sel_action'], 'txt_pm_rule_label' => $txt['pm_rule_label'], 'txt_pm_rule_delete' => $txt['pm_rule_delete'], 'txt_pm_rule_sel_label' => $txt['pm_rule_sel_label']), true); // Current rule information... if ($context['rid']) { $context['rule'] = $context['rules'][$context['rid']]; $members = array(); // Need to get member names! foreach ($context['rule']['criteria'] as $k => $criteria) { if ($criteria['t'] == 'mid' && !empty($criteria['v'])) { $members[(int) $criteria['v']] = $k; } } if (!empty($members)) { require_once SUBSDIR . '/Members.subs.php'; $result = getBasicMemberData(array_keys($members)); foreach ($result as $row) { $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; } } } else { $context['rule'] = array('id' => '', 'name' => '', 'criteria' => array(), 'actions' => array(), 'logic' => 'and'); } // Add a dummy criteria to allow expansion for none js users. $context['rule']['criteria'][] = array('t' => '', 'v' => ''); } elseif (isset($_GET['save'])) { checkSession('post'); $context['rid'] = isset($_GET['rid']) && isset($context['rules'][$_GET['rid']]) ? (int) $_GET['rid'] : 0; // Name is easy! $ruleName = Util::htmlspecialchars(trim($_POST['rule_name'])); if (empty($ruleName)) { fatal_lang_error('pm_rule_no_name', false); } // Sanity check... if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { fatal_lang_error('pm_rule_no_criteria', false); } // Let's do the criteria first - it's also hardest! $criteria = array(); foreach ($_POST['ruletype'] as $ind => $type) { // Check everything is here... if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { continue; } elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { continue; } // Members need to be found. if ($type == 'mid') { require_once SUBSDIR . '/Members.subs.php'; $name = trim($_POST['ruledef'][$ind]); $member = getMemberByName($name, true); if (empty($member)) { continue; } $criteria[] = array('t' => 'mid', 'v' => $member['id_member']); } elseif ($type == 'bud') { $criteria[] = array('t' => 'bud', 'v' => 1); } elseif ($type == 'gid') { $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); } elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { $criteria[] = array('t' => $type, 'v' => Util::htmlspecialchars(trim($_POST['ruledef'][$ind]))); } } // Also do the actions! $actions = array(); $doDelete = 0; $isOr = $_POST['rule_logic'] == 'or' ? 1 : 0; foreach ($_POST['acttype'] as $ind => $type) { // Picking a valid label? if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind] - 1]))) { continue; } // Record what we're doing. if ($type == 'del') { $doDelete = 1; } elseif ($type == 'lab') { $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind] - 1); } } if (empty($criteria) || empty($actions) && !$doDelete) { fatal_lang_error('pm_rule_no_criteria', false); } // What are we storing? $criteria = serialize($criteria); $actions = serialize($actions); // Create the rule? if (empty($context['rid'])) { addPMRule($user_info['id'], $ruleName, $criteria, $actions, $doDelete, $isOr); } else { updatePMRule($user_info['id'], $context['rid'], $ruleName, $criteria, $actions, $doDelete, $isOr); } redirectexit('action=pm;sa=manrules'); } elseif (isset($_POST['delselected']) && !empty($_POST['delrule'])) { checkSession('post'); $toDelete = array(); foreach ($_POST['delrule'] as $k => $v) { $toDelete[] = (int) $k; } if (!empty($toDelete)) { deletePMRules($user_info['id'], $toDelete); } redirectexit('action=pm;sa=manrules'); } }