1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_hasbought_info() 9{ 10 return [ 11 'name' => tra('Has Bought'), 12 'description' => tra('Check whether a user has bought an item or added it to the shopping cart'), 13 'documentation' => tra('PluginHasBought'), 14 'prefs' => ['wikiplugin_hasbought', 'payment_feature'], 15 'filter' => 'wikicontent', 16 'iconname' => 'cart', 17 'tags' => [ 'experimental' ], 18 'introduced' => 7, 19 'params' => [ 20 'key' => [ 21 'required' => true, 22 'name' => tra('Key Name'), 23 'description' => tra('Key name of passcode to be checked'), 24 'since' => '7.0', 25 'filter' => 'text', 26 'default' => '', 27 ], 28 'label' => [ 29 'required' => true, 30 'name' => tra('Key Labels'), 31 'description' => tra('Label of the key name of passcode to be checked'), 32 'since' => '7.0', 33 'filter' => 'text', 34 'default' => '', 35 ], 36 'trackerId' => [ 37 'required' => true, 38 'name' => tra('Tracker ID'), 39 'description' => tra('Tracker from which to get passcode to check against'), 40 'since' => '7.0', 41 'filter' => 'text', 42 'default' => '', 43 'profile_reference' => 'tracker', 44 ], 45 'fieldId' => [ 46 'required' => true, 47 'name' => tra('Field ID'), 48 'description' => tra('Field ID from which to get passcode to check against'), 49 'since' => '7.0', 50 'filter' => 'text', 51 'default' => '', 52 'profile_reference' => 'tracker_field', 53 ], 54 'itemId' => [ 55 'required' => true, 56 'name' => tra('Item ID'), 57 'description' => tra('Item ID from which to get passcode to check against'), 58 'since' => '7.0', 59 'filter' => 'text', 60 'default' => '', 61 'profile_reference' => 'tracker_item', 62 ], 63 ], 64 ]; 65} 66 67function wikiplugin_hasticket($data, $params) 68{ 69 global $user; 70 $smarty = TikiLib::lib('smarty'); 71 if (empty($params['key']) || empty($params['trackerId']) || empty($params['itemId']) || empty($params['fieldId'])) { 72 return ''; 73 } 74 $key = $params['key']; 75 if ($_SERVER['REQUEST_METHOD'] == 'POST' && ! empty($_POST['trackerpasscode'])) { 76 // Check all filled in 77 if (empty($_POST['trackerpasscode'])) { 78 $access = TikiLib::lib('access'); 79 $access->redirect($_SERVER['REQUEST_URI'], tr('Please fill in all fields')); 80 die; 81 } 82 $_SESSION['wikiplugin_trackerpasscode'][$key] = $_POST['trackerpasscode']; 83 } 84 $dataelse = ''; 85 if (strpos($data, '{ELSE}')) { 86 $dataelse = substr($data, strpos($data, '{ELSE}') + 6); 87 $data = substr($data, 0, strpos($data, '{ELSE}')); 88 } 89 // check code 90 $trklib = TikiLib::lib('trk'); 91 $correctcode = $trklib->get_item_value($params['trackerId'], $params['itemId'], $params['fieldId']); 92 if ($_SESSION['wikiplugin_trackerpasscode'][$key] == $correctcode) { 93 return $data; 94 } else { 95 $smarty->assign('label', $params['label']); 96 $form = $smarty->fetch('wiki-plugins/wikiplugin_trackerpasscode.tpl'); 97 if (! empty($dataelse)) { 98 return $dataelse . $form; 99 } else { 100 return $form; 101 } 102 } 103} 104