So here's the situation: I have two Tiki-Wiki trackers: One called Orders and the other called Customers. When a new item is added to the Orders tracker, one of the fields required is the customer, selected from the Customer tracker. Occasionally we have delinquent customers and need to "blacklist" them, preventing new order items being created for this customer. What is the best way to accomplish this?
I figured the best way to do this it to build a custom validator, as seen here: https://doc.tiki.org/Tracker+Field+Validation. I would then have a new field in the customers tracker that would indicate if they are on the blacklist. The validator would look up the customer and if they are blacklisted, disallow entering a new order.
My (poor) attempt at this is below:
<?php
function validator_Blacklist($input, $parameter = '', $message = '')
{
$trklib = TikiLib::lib('trk');
//parse_str($parameter, $arr);
//$info = $trklib->get_tracker_field($arr['fieldId']);
$bl = $trklib->get_item(4,204,$input);
if($bl>=1)
return tra("Customer is blacklisted.");
return true;
}
?>
Okay, so I did manage to solve this using a validator:
There was also an issue where my field type (Item Link) was passing undefined $input. Some digging showed that validatorslib.php wasn't handling Item Link as a drop-down type (the letter key for Item Link being 'r'):
I changed the first line to:
Everything seems to be working now (and I don't think I broke any other functionality in the process.) I will probably make this more robust when I have time (take the tracker and fields as parameters, etc.).