wikiplugin_shopperinfo.php 3.19 KB
Newer Older
1
<?php
2

3
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
rjsmelo's avatar
rjsmelo committed
4
//
5
6
7
// 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$
8

9
10
function wikiplugin_shopperinfo_info()
{
11
12
13
14
15
16
17
18
19
20
21
22
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
    return [
        'name' => tra('Collect Anonymous Shopper Info'),
        'documentation' => tra('PluginShopperinfo'),
        'description' => tra('Collect shopper information for the shopping cart'),
        'prefs' => ['wikiplugin_shopperinfo', 'payment_feature'],
        'iconname' => 'cart',
        'introduced' => 7,
        'filter' => 'wikicontent',
        'format' => 'html',
        'tags' => [ 'experimental' ],
        'params' => [
            'values' => [
                'required' => true,
                'name' => tra('Values to be collected'),
                'description' => tra('Names of values to be collected separated by : as defined in shopper profile'),
                'since' => '7.0',
                'filter' => 'text',
                'separator' => ':'
            ],
            'labels' => [
                'required' => true,
                'name' => tra('Labels for the values to be collected'),
                'description' => tra('Labels of the values to be collected separated by a colon'),
                'since' => '7.0',
                'filter' => 'text',
                'separator' => ':'
            ],
            'showifloggedin' => [
                'required' => false,
                'name' => tra('Show even if logged in'),
                'description' => tra('Normally this is used for anonymous users but sometimes may be used when logged in also'),
                'since' => '7.0',
                'filter' => 'alpha',
                'default' => 'n',
                'options' => [
                    ['text' => '', 'value' => ''],
                    ['text' => tra('Yes'), 'value' => 'y'],
                    ['text' => tra('No'), 'value' => 'n']
                ]
            ],
        ],
    ];
53
54
}

rjsmelo's avatar
rjsmelo committed
55
function wikiplugin_shopperinfo($data, $params)
56
{
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    global $user;
    $smarty = TikiLib::lib('smarty');
    if ($user && $params['showifloggedin'] != 'y' || empty($params['values'])) {
        return '';
    }
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['shopperinfo'])) {
        foreach ($params['values'] as $v) {
            // Check all filled in
            if (empty($_POST[$v])) {
                $access = TikiLib::lib('access');
                $access->redirect($_SERVER['REQUEST_URI'], tr('Please fill in all fields'));
                die;
            }
        }
        foreach ($params['values'] as $v) {
            $_SESSION['shopperinfo'][$v] = $_POST[$v];
        }
    }
    $values = [];
    foreach ($params['values'] as $k => $v) {
        $t['name'] = $v;
        if (! empty($_SESSION['shopperinfo'][$v])) {
            $t['current'] = $_SESSION['shopperinfo'][$v];
        }
        if (! empty($params['labels'][$k])) {
            $t['label'] = $params['labels'][$k];
        }
        $values[] = $t;
    }
    $smarty->assign('values', $values);
    $form = $smarty->fetch('wiki-plugins/wikiplugin_shopperinfo.tpl');
    return $form;
rjsmelo's avatar
rjsmelo committed
89
}