Esempio n. 1
0
define('P2_EDIT_CONF_USER_PASSWORD', 16);
define('P2_EDIT_CONF_FILE_ADMIN', 1024);
define('P2_EDIT_CONF_FILE_ADMIN_EX', 2048);
include P2_CONFIG_DIR . '/conf_user_def.inc.php';
//=====================================================================
// 前処理
//=====================================================================
// {{{ 保存ボタンが押されていたら、設定を保存
if (!empty($_POST['submit_save'])) {
    // 値の適正チェック、矯正
    // トリム
    $_POST['conf_edit'] = array_map('trim', $_POST['conf_edit']);
    // 選択肢にないもの → デフォルト矯正
    notSelToDef();
    // ルールを適用する
    applyRules();
    // ポストされた値 > 現在の値 > デフォルト値 の順で新しい設定を作成する
    $conf_save = array('.' => $_conf['p2version']);
    foreach ($conf_user_def as $k => $v) {
        if (array_key_exists($k, $_POST['conf_edit'])) {
            $conf_save[$k] = $_POST['conf_edit'][$k];
        } elseif (array_key_exists($k, $_conf)) {
            $conf_save[$k] = $_conf[$k];
        } else {
            $conf_save[$k] = $v;
        }
    }
    // シリアライズして保存
    FileCtl::make_datafile($_conf['conf_user_file']);
    if (FileCtl::file_write_contents($_conf['conf_user_file'], serialize($conf_save)) === false) {
        P2Util::pushInfoHtml('<p>×設定を更新保存できませんでした</p>');
 /**
  * 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');
     }
 }