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 8/** 9 * Handler class for IP selector: 10 * 11 * Letter key ~I~ 12 */ 13class Tracker_Field_Ip extends Tracker_Field_Abstract implements Tracker_Field_Synchronizable 14{ 15 public static function getTypes() 16 { 17 return [ 18 'I' => [ 19 'name' => tr('IP Selector'), 20 'description' => tr('IP address input field'), 21 'help' => 'IP selector', 22 'prefs' => ['trackerfield_ipaddress'], 23 'tags' => ['basic'], 24 'default' => 'n', 25 'params' => [ 26 'autoassign' => [ 27 'name' => tr('Auto-assign'), 28 'description' => tr('Automatically assign the value on creation or edit.'), 29 'filter' => 'int', 30 'default' => 1, 31 'options' => [ 32 0 => tr('None'), 33 1 => tr('Creator'), 34 2 => tr('Modifier'), 35 ], 36 'legacy_index' => 0, 37 ], 38 ], 39 ], 40 ]; 41 } 42 43 function getFieldData(array $requestData = []) 44 { 45 global $tiki_p_admin_trackers; 46 47 $ins_id = $this->getInsertId(); 48 $data = $this->getItemData(); 49 $autoAssign = $this->getOption('autoassign'); 50 51 if (empty($data) && $tiki_p_admin_trackers == 'n' && $autoAssign == '1') { 52 // if it is a new tracker item, ip auto assign is enabled and user doesn't 53 // have $tiki_p_admin_trackers there is no information about the ip address 54 // in the form so we have to get it from TikiLib::get_ip_address() 55 $value = TikiLib::lib('tiki')->get_ip_address(); 56 } elseif (isset($requestData[$ins_id])) { 57 $value = $requestData[$ins_id]; 58 } else { 59 $value = $this->getValue(); 60 } 61 62 return [ 63 'value' => $value, 64 ]; 65 } 66 67 function renderInput($context = []) 68 { 69 return $this->renderTemplate("trackerinput/ip.tpl", $context); 70 } 71 72 function importRemote($value) 73 { 74 return $value; 75 } 76 77 function exportRemote($value) 78 { 79 return $value; 80 } 81 82 function importRemoteField(array $info, array $syncInfo) 83 { 84 return $info; 85 } 86} 87