tiki-user_mailin.php 3.67 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 9 10 11 12 13

$section = 'mytiki';
require_once ('tiki-setup.php');

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

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

// Validate current user's permissions
$access->check_permission(array('tiki_p_send_mailin'));

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

22
$tikifeedback = array();
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

if ($prefs['feature_wiki_structure'] === 'y') {
	$structlib = TikiLib::lib('struct');
	
	// Add a new route
	if (!empty($_REQUEST['mailinSubjPattNew']) || !empty($_REQUEST['mailinBodyPattNew'])) {
		$mailinSubjPattNew = $_REQUEST['mailinSubjPattNew'];
		$mailinBodyPattNew = $_REQUEST['mailinBodyPattNew'];
		$mailinNewStruct = $_REQUEST['mailinNewStruct'];
		$mailinParNew = $_REQUEST['mailinParNew'];
		$mailinActNew = $_REQUEST['mailinActNew'];
		
		$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';
			}
			
53
			// Add new structure route
54
			$usermailinlib->add_user_mailin_struct($user, $subj_pattern, $body_pattern, $structure_id, $page_id, $is_active);
55 56 57 58
			$tikifeedback[] = array(
				'num' => 1,
				'mes' => tra('Mail-in added new structure route')
			);
59 60 61 62 63 64 65
		}
	}
	
	// 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']);
66 67 68 69
			$tikifeedback[] = array(
				'num' => 1,
				'mes' => tra('Deleted structure route')
			);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
		}
	}
	
	// Update changed routes
	for ($i = 1; ; $i++) {
		if (!isset($_REQUEST['changed_'.$i])) {
			break;
		}
		if ($_REQUEST['changed_'.$i] !== 'y') {
			continue;
		}
		
		// Route updated
		$mailin_struct_id = $_REQUEST['mailin_struct_id_'.$i];
		if (empty($mailin_struct_id)) {
			continue;
		}
		$mailin_struct_id = (int)$mailin_struct_id;
		$username = $user;
		$subj_pattern = $_REQUEST['mailinSubjPatt'.$i];
		$body_pattern = $_REQUEST['mailinBodyPatt'.$i];
		$structure_id = (int) $_REQUEST['mailinStruct'.$i];

		$retrieve_data = false;
		$info = $tikilib->get_page_info($_REQUEST['mailinPar'.$i], $retrieve_data);
		if ($info === false) {
			$page_id = null;
		} else {
			$page_id = (int)$info['page_id'];
		}

		$is_active = ($_REQUEST['mailinAct'.$i] == "on") ? 'y' : 'n';
		
		$usermailinlib->update_user_mailin_struct($mailin_struct_id, $username, $subj_pattern, $body_pattern, $structure_id, $page_id, $is_active);
104 105 106 107
		$tikifeedback[] = array(
			'num' => 1,
			'mes' => tra('Updated structure route')
		);
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	}
	
	// Prepare route display
	$userStructs = $usermailinlib->list_user_mailin_struct($user);
	
	$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');
} 

123
$smarty->assign_by_ref('tikifeedback', $tikifeedback);
124 125 126 127
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
$smarty->assign('mid', 'tiki-user_mailin.tpl');
$smarty->display("tiki.tpl");