tiki-user_mailin.php 3.46 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
3 4 5 6
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
7 8

$section = 'mytiki';
rjsmelo's avatar
rjsmelo committed
9
require_once('tiki-setup.php');
10 11 12 13

// Validate that the mail-in feature is activated
$access->check_feature('feature_mailin');

14 15 16 17
// Validate current user
$access->check_user($user);

// Validate current user's permissions
rjsmelo's avatar
rjsmelo committed
18
$access->check_permission(['tiki_p_send_mailin']);
19

20
$usermailinlib = TikiLib::lib('usermailin');
21 22 23

if ($prefs['feature_wiki_structure'] === 'y') {
	$structlib = TikiLib::lib('struct');
rjsmelo's avatar
rjsmelo committed
24

25
	// Add a new route
rjsmelo's avatar
rjsmelo committed
26
	if (! empty($_REQUEST['mailinSubjPattNew']) || ! empty($_REQUEST['mailinBodyPattNew'])) {
27 28 29 30 31
		$mailinSubjPattNew = $_REQUEST['mailinSubjPattNew'];
		$mailinBodyPattNew = $_REQUEST['mailinBodyPattNew'];
		$mailinNewStruct = $_REQUEST['mailinNewStruct'];
		$mailinParNew = $_REQUEST['mailinParNew'];
		$mailinActNew = $_REQUEST['mailinActNew'];
rjsmelo's avatar
rjsmelo committed
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
		$subj_pattern = $mailinSubjPattNew;
		$body_pattern = $mailinBodyPattNew;
		$structure_id = (int)$mailinNewStruct;

		if ($structure_id > 0) {
			$retrieve_data = false;
			$info = $tikilib->get_page_info($mailinParNew, $retrieve_data);
			if ($info == false) {
				$page_id = null;
			} else {
				$page_id = $info['page_id'];
			}
			if ($mailinActNew == "on") {
				$is_active = 'y';
			} else {
				$is_active = 'n';
			}
rjsmelo's avatar
rjsmelo committed
50

51
			// Add new structure route
52
			$usermailinlib->add_user_mailin_struct($user, $subj_pattern, $body_pattern, $structure_id, $page_id, $is_active);
53
			Feedback::success(tr('Added new structure route'));
54 55
		}
	}
rjsmelo's avatar
rjsmelo committed
56

57 58 59 60
	// Delete a route
	if (isset($_REQUEST['delete']) && $_REQUEST['delete'] == 'y') {
		if (isset($_REQUEST['mailin_struct_id']) && (int)$_REQUEST['mailin_struct_id'] > 0) {
			$usermailinlib->delete_user_mailin_struct((int)$_REQUEST['mailin_struct_id']);
61
			Feedback::success(tr('Deleted structure route'));
62 63
		}
	}
rjsmelo's avatar
rjsmelo committed
64

65
	// Update changed routes
rjsmelo's avatar
rjsmelo committed
66 67
	for ($i = 1;; $i++) {
		if (! isset($_REQUEST['changed_' . $i])) {
68 69
			break;
		}
rjsmelo's avatar
rjsmelo committed
70
		if ($_REQUEST['changed_' . $i] !== 'y') {
71 72
			continue;
		}
rjsmelo's avatar
rjsmelo committed
73

74
		// Route updated
rjsmelo's avatar
rjsmelo committed
75
		$mailin_struct_id = $_REQUEST['mailin_struct_id_' . $i];
76 77 78 79 80
		if (empty($mailin_struct_id)) {
			continue;
		}
		$mailin_struct_id = (int)$mailin_struct_id;
		$username = $user;
rjsmelo's avatar
rjsmelo committed
81 82 83
		$subj_pattern = $_REQUEST['mailinSubjPatt' . $i];
		$body_pattern = $_REQUEST['mailinBodyPatt' . $i];
		$structure_id = (int) $_REQUEST['mailinStruct' . $i];
84 85

		$retrieve_data = false;
rjsmelo's avatar
rjsmelo committed
86
		$info = $tikilib->get_page_info($_REQUEST['mailinPar' . $i], $retrieve_data);
87 88 89 90 91 92
		if ($info === false) {
			$page_id = null;
		} else {
			$page_id = (int)$info['page_id'];
		}

rjsmelo's avatar
rjsmelo committed
93 94
		$is_active = ($_REQUEST['mailinAct' . $i] == "on") ? 'y' : 'n';

95
		$usermailinlib->update_user_mailin_struct($mailin_struct_id, $username, $subj_pattern, $body_pattern, $structure_id, $page_id, $is_active);
96
		Feedback::success(tra('Updated structure route'));
97
	}
rjsmelo's avatar
rjsmelo committed
98

99 100
	// Prepare route display
	$userStructs = $usermailinlib->list_user_mailin_struct($user);
rjsmelo's avatar
rjsmelo committed
101

102 103 104 105 106 107 108 109
	$offset = 0;
	$maxRecords = -1;
	$sort_mode = 'pageName_asc';
	$structs = $structlib->list_structures($offset, $maxRecords, $sort_mode);

	$smarty->assign('structs', $structs['data']);
	$smarty->assign('userStructs', $userStructs['data']);
	$smarty->assign('addNewRoute', 'y');
rjsmelo's avatar
rjsmelo committed
110
}
111 112 113 114 115

// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
$smarty->assign('mid', 'tiki-user_mailin.tpl');
$smarty->display("tiki.tpl");