<commit_before><?php

# Copyright (c) 2010 - 2012  <NAME>
# Copyright (c) 2012 - 2016  MantisBT Team - <EMAIL>
# Licensed under the MIT license

form_security_validate("plugin_Snippets_list_action");

$global = gpc_get_bool("global", false);

if ($global) {
	access_ensure_global_level(plugin_config_get("edit_global_threshold"));
	$user_id = 0;
} else {
	access_ensure_global_level(plugin_config_get("edit_own_threshold"));
	$user_id = auth_get_current_user_id();
}

$action = gpc_get_string("action");

$snippet_list = gpc_get_int_array("snippet_list", array());

if (count($snippet_list) < 1) {
	form_security_purge("plugin_Snippets_list_action");
	print_header_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
}

$snippets = Snippet::load_by_id($snippet_list, $user_id);

function array_object_properties($arr, $prop) {
	$props = array();
	foreach($arr as $key => $obj) {
		$props[$key] = $obj->$prop;
	}
	return $props;
}

### DELETE
if ($action == "delete") {
	$snippet_names = array_object_properties(Snippet::clean($snippets), "name");
	helper_ensure_confirmed(plugin_lang_get("action_delete_confirm") . "<br/>" . implode(", ", $snippet_names), plugin_lang_get("action_delete"));
	Snippet::delete_by_id(array_keys($snippets), $user_id);

	form_security_purge("plugin_Snippets_list_action");
	print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));

### EDIT
} elseif ($action == "edit") {
	$snippets = Snippet::clean($snippets, "form");
	layout_page_header();
	layout_page_begin();
?>

<br/>
<div class="form-container">
<form action="<?php echo plugin_page("snippet_list_action") ?>" method="post">
<?php echo form_security_field("plugin_Snippets_list_action") ?>
<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
<input type="hidden" name="action" value="update"/>

<table>

<thead>
<tr>
<td class="form-title" colspan="3"><?php echo plugin_lang_get($global ? "edit_global_title" : "edit_title") ?></td>
</tr>
</thead>

<tbody>
<?php $first = true; foreach ($snippets as $snippet): ?>
<?php if (!$first): ?><tr class="spacer"><td></td></tr><?php endif ?>

<tr>
<td class="center" rowspan="2"><input type="checkbox" class="ace"name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/><span class="lbl"></span></td>
<td class="category"><?php echo plugin_lang_get("edit_name") ?></td>
<td><input name="name_<?php echo $snippet->id ?>" value="<?php echo $snippet->name ?>"/></td>
</tr>

<tr>
<td class="category"><?php echo plugin_lang_get("edit_value") ?></td>
<td class="snippetspatternhelp"><textarea name="value_<?php echo $snippet->id ?>" cols="80" rows="6"><?php echo $snippet->value ?></textarea></td>
</tr>

<?php $first = false; endforeach ?>
</tbody>

<tfoot>
<tr>
<td class="center"><input type="checkbox" class="ace"checked="checked"/><span class="lbl"></span></td>
<td class="center" colspan="2"><input type="submit" value="<?php echo plugin_lang_get("action_edit") ?>"/></td>
</tr>
</tfoot>

</table><commit_msg>Fix edit snippet UI and removed checkboxes<commit_after><?php

# Copyright (c) 2010 - 2012  <NAME>
# Copyright (c) 2012 - 2016  MantisBT Team - <EMAIL>
# Licensed under the MIT license

form_security_validate("plugin_Snippets_list_action");

$global = gpc_get_bool("global", false);

if ($global) {
	access_ensure_global_level(plugin_config_get("edit_global_threshold"));
	$user_id = 0;
} else {
	access_ensure_global_level(plugin_config_get("edit_own_threshold"));
	$user_id = auth_get_current_user_id();
}

$action = gpc_get_string("action");

$snippet_list = gpc_get_int_array("snippet_list", array());

if (count($snippet_list) < 1) {
	form_security_purge("plugin_Snippets_list_action");
	print_header_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));
}

$snippets = Snippet::load_by_id($snippet_list, $user_id);

function array_object_properties($arr, $prop) {
	$props = array();
	foreach($arr as $key => $obj) {
		$props[$key] = $obj->$prop;
	}
	return $props;
}

### DELETE
if ($action == "delete") {
	$snippet_names = array_object_properties(Snippet::clean($snippets), "name");
	helper_ensure_confirmed(plugin_lang_get("action_delete_confirm") . "<br/>" . implode(", ", $snippet_names), plugin_lang_get("action_delete"));
	Snippet::delete_by_id(array_keys($snippets), $user_id);

	form_security_purge("plugin_Snippets_list_action");
	print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global));

### EDIT
} elseif ($action == "edit") {
	$snippets = Snippet::clean($snippets, "form");
	layout_page_header();
	layout_page_begin();
?>

<br/>

<div id="snippet-div" class="form-container">
	<form action="<?php echo plugin_page( 'snippet_list_action' ) ?>" method="post">
		<?php echo form_security_field("plugin_Snippets_list_action") ?>
		<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
		<input type="hidden" name="action" value="update"/>

<div class="widget-box widget-color-blue2">
	<div class="widget-header widget-header-small">
		<h4 class="widget-title lighter">
			<i class="ace-icon fa fa-user"></i>
			<?php echo plugin_lang_get( $global ? 'edit_global_title' : 'edit_title' ) ?>
		</h4>
	</div>
	<div class="widget-body">
		<div class="widget-main no-padding">
			<div class="table-responsive">
				<table class="table table-bordered table-condensed table-striped">

		<fieldset>

<?php $first = true; foreach ($snippets as $snippet): ?>
<?php if (!$first): ?><tr class="spacer"><td></td></tr><?php endif ?>

<tr>
<td class="category"><?php echo plugin_lang_get("edit_name") ?></td>
<td><input name="name_<?php echo $snippet->id ?>" value="<?php echo $snippet->name ?>"/></td>
</tr>

<tr>
<td class="category"><?php echo plugin_lang_get("edit_value") ?></td>
<td class="snippetspatternhelp"><textarea name="value_<?php echo $snippet->id ?>" cols="80" rows="6"><?php echo $snippet->value ?></textarea></td>
</tr>

<?php $first = false; endforeach ?>

<tfoot>
<tr>
<td class="center" colspan="2"><input type="submit" value="<?php echo plugin_lang_get("action_edit") ?>"/></td>
</tr>
</tfoot>

	</fieldset>
</table>
{'fraction_non_alphanumeric': 0.20087406927808352, 'fraction_numerical': 0.007931369375202332, 'mean_word_length': 7.35, 'pattern_counts': {'":': 0, '<': 142, '<?xml version=': 0, '>': 153, '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': '3491017', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2201, 'n_words': 414}