require_once dirname(__FILE__) . '/../../../../core/include/init.inc';
require_once dirname(__FILE__) . '/../../../../core/lib/html_form/html_form.inc';
$assetid = array_get_index($_GET, 'assetid');
if (is_null($assetid)) {
    return FALSE;
}
assert_valid_assetid($assetid);
$asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
if (is_null($asset) || !$asset->writeAccess()) {
    exit;
}
$all = array_get_index($_REQUEST, 'all', FALSE);
require_once dirname(__FILE__) . '/../../../../core/include/backend_outputter.inc';
$o = new Backend_Outputter();
$o->openSection('Metadata Keyword Replacements');
$o->openField('', 'wide_col');
?>

		<p>The following keyword replacements may be used for metadata values. Note that the percentage signs (%) are required.</p>

		<?php 
$o->openSection('Asset Information');
$o->openField('', 'wide_col');
?>

			<table class="sq-backend-table compact">
			<tr><th style="width: 250px;">Keyword</th><th>Description</th></tr>
			<tr><td><strong>%asset_assetid%</strong></td><td>The ID of the asset</td></tr>
			<tr><td><strong>%asset_name%</strong></td><td>Full name of the asset</td></tr>
			<tr><td><strong>%asset_name_linked%</strong></td><td>Full name of the asset with hyperlink</td></tr>
			<tr><td><strong>%asset_short_name%</strong></td><td>Short name of the asset</td></tr>
				border:				1px solid #E0E0E0;
			}

			legend {
				color:				#2086EA;
			}
		</style>
	</head>

	<body>
	<?php 
    require_once dirname(__FILE__) . '/../../../../core/include/backend_outputter.inc';
    // $backend = new Backend();
    $o = new Backend_Outputter();
    $o->openSection('Keyword List for \'' . $asset->attr('name') . '\' (#' . $asset->id . ')');
    $o->openField('&nbsp;');
    $questions = $asset->getQuestions();
    $sections = $asset->getSections();
    ?>
				<p>These keywords are available for use in Complex Formatting for insertion into the 'Page Contents' bodycopy, if it is enabled. The <b>'Question Field'</b> keywords (%question_field_*%) are replaced with the appropriate input field for that question. The <b>'Section Title'</b> keywords (%section_title_*%) will be replaced with the name of the section.</p>

		<p>
		<fieldset>
			<legend><b>Unattached Questions</b></legend>
			<table border="0" width="100%">
				<?php 
    foreach ($questions as $q_id => $question) {
        $q_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($asset->id . ':q' . $q_id);
        $q_name = $q_asset->attr('name');
        ?>
							<tr><td valign="top" width="200"><b>%question_field_<?php 
$o = new Backend_Outputter();
$o->openSection(translate('Keyword List for Simple Edit Keywords'));
$type_list = array();
$asset_type_list = $GLOBALS['SQ_SYSTEM']->am->getAssetTypes();
foreach ($asset_type_list as $key => $value) {
    if ($value['instantiable'] == 1) {
        $type_list[] = $key;
    }
}
$asset_types = array();
foreach ($type_list as $asset_type) {
    $type_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($asset_type);
    $asset_types[$asset_type] = $type_info['name'];
}
asort($asset_types);
$o->openField('', 'wide_col');
echo '<p style="margin: 0;">' . translate('Select your asset type') . ': ';
if (isset($_REQUEST['asset_type'])) {
    combo_box('asset_type', $asset_types, FALSE, $_REQUEST['asset_type']);
} else {
    combo_box('asset_type', $asset_types);
}
echo '&nbsp;';
submit_button('limbo_keywords_submit', translate('Get Keywords'));
echo '</p>';
$o->closeField();
$o->closeSection();
if (isset($_REQUEST['asset_type'])) {
    $asset_type = preg_replace('/[^a-zA-Z0-9_]+/', '', $_REQUEST['asset_type']);
    $ei = new Asset_Edit_Interface($asset_type);
    $ei->getSimpleEditKeywords($asset_type, $o);
					addAll = document.getElementById('addAll');
					addAll.style.display = 'none';
			}
		}

		</script>
	</head>

	<body>
	<?php 
    require_once dirname(__FILE__) . '/../../include/backend_outputter.inc';
    $o = new Backend_Outputter();
    $o->addOnLoad('checkTagsLeft()');
    $o->openSection(sprintf(translate('Suggested tags for %s'), get_asset_tag_line($asset->id)));
    $o->openField('');
    ?>
				<p><?php 
    echo sprintf(translate('Suggested tags for %s'), get_asset_tag_line($asset->id));
    ?>
</p>
				<p><?php 
    echo translate('Click \'Add Tag\' to tag this asset with the term');
    ?>
</p>

		<p>
		<fieldset>
			<legend><b><?php 
    echo translate('Suggested Tags');
    ?>