<commit_before><?php
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// 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$
if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) != FALSE) {
	header('location: index.php');
	exit;
}
global $user;
if (empty($user)) {
	return;
}
$tracker_id = $prefs['tracker_force_tracker_id'];
$tracker_definition = Tracker_Definition::get($tracker_id);
//user field info
$user_field_id = $tracker_definition->getUserField();
$user_field = $tracker_definition->getField($user_field_id);
$user_field_permname = $user_field['permName'];
//mandatory field info
$mandatory_field_permname = $prefs['tracker_force_mandatory_field'];
$mandatory_field_info = $tracker_definition->getFieldFromPermName($mandatory_field_permname);
$mandatory_field_id = $mandatory_field_info['fieldId'];

$fields = array_map('trim', explode(',', $prefs['tracker_force_tracker_fields']));
$trackerlib = TikiLib::lib('trk');
$item = $trackerlib->get_item($tracker_id,$user_field_id,$user);

if ($item) {
	//if the mandatory field is empty or if it's a checkbox and is set to 'n', force tracker input
	if (empty($item[$mandatory_field_id]) || ($mandatory_field_info['type'] =='c' && $item[$mandatory_field_id] == "n")) {
		$action = "update";
	} else {
		return; //do nothing
	}
} else {
	$action = "new";
}

$smarty->assign_by_ref("force_fill_action",$action);
$smarty->assign("force_fill_tracker",$tracker_id);
$smarty->assign("force_fill_user_field",$user_field_id);
$smarty->assign("force_fill_user_field_permname",$user_field_permname);
$smarty->assign("force_fill_mandatory_field",$mandatory_field_id);
$smarty->assign("force_fill_item",$item);
$smarty->assign("force_fill_fields",json_encode($fields, JSON_FORCE_OBJECT));
<commit_msg>[FIX] Added a pref check to tracker_force_fill prefs to ensure that dependent prefs are filled out as well (crashes if dependent prefs are empty)<commit_after><?php
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// 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$
if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) != FALSE) {
	header('location: index.php');
	exit;
}
global $user;
if (empty($user) || empty($prefs['tracker_force_tracker_id']) || $prefs['tracker_force_mandatory_field'] || $prefs['tracker_force_tracker_fields']) {
	return;
}
$tracker_id = $prefs['tracker_force_tracker_id'];
$tracker_definition = Tracker_Definition::get($tracker_id);
//user field info
$user_field_id = $tracker_definition->getUserField();
$user_field = $tracker_definition->getField($user_field_id);
$user_field_permname = $user_field['permName'];
//mandatory field info
$mandatory_field_permname = $prefs['tracker_force_mandatory_field'];
$mandatory_field_info = $tracker_definition->getFieldFromPermName($mandatory_field_permname);
$mandatory_field_id = $mandatory_field_info['fieldId'];

$fields = array_map('trim', explode(',', $prefs['tracker_force_tracker_fields']));
$trackerlib = TikiLib::lib('trk');
$item = $trackerlib->get_item($tracker_id,$user_field_id,$user);

if ($item) {
	//if the mandatory field is empty or if it's a checkbox and is set to 'n', force tracker input
	if (empty($item[$mandatory_field_id]) || ($mandatory_field_info['type'] =='c' && $item[$mandatory_field_id] == "n")) {
		$action = "update";
	} else {
		return; //do nothing
	}
} else {
	$action = "new";
}

$smarty->assign_by_ref("force_fill_action",$action);
$smarty->assign("force_fill_tracker",$tracker_id);
$smarty->assign("force_fill_user_field",$user_field_id);
$smarty->assign("force_fill_user_field_permname",$user_field_permname);
$smarty->assign("force_fill_mandatory_field",$mandatory_field_id);
$smarty->assign("force_fill_item",$item);
$smarty->assign("force_fill_fields",json_encode($fields, JSON_FORCE_OBJECT));

{'fraction_non_alphanumeric': 0.15666502705361535, 'fraction_numerical': 0.003935071323167732, 'mean_word_length': 7.997787610619469, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4100846', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1395, 'n_words': 276}