<?php
/*
* Free IT Foundation
* Free Technology Serving Knowledge
* http://www.free-it-foundation.org
*
* This file is part of Knowledge Box.
*
* Knowledge Box is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knowledge Box is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Knowledge Box. If not, see <http://www.gnu.org/licenses/>.
*/
// restrict access
if (!KB_IS_ADMINISTRATOR)
$AppUI->redirect (KB_ACCESS_DENIED);
// retrieve id
$element_id = (int) dPgetParam ($_GET, 'id');
// instanciate
$element = new KBModuleElement ();
// load record
if ($element_id > 0 && !$element->load ($element_id))
{
// failed
$AppUI->setMsg ('invalidID', UI_MSG_ERROR, true);
$AppUI->redirect ();
}
// base
$base = new KBModuleBase ();
$base->load (KB_BASE);
// title block
$titleBlock = new CTitleBlock (utf8_encode (html_entity_decode ($AppUI->_($element_id > 0 ? 'titleEditElement' : 'titleNewElement'))), KB_MODULE_ICON);
// breadcrumbs
$titleBlock->addCrumb ('?m=' . KB_MODULE, html_entity_decode ($base->getName ()));
$titleBlock->addCrumb ('?m=' . KB_MODULE . '&e=elements', utf8_encode (html_entity_decode ($AppUI->_('crumbResultsOutput'))));
// delete link
if ($element_id > 0)
$titleBlock->addCrumbDelete (utf8_encode (html_entity_decode ($AppUI->_('actionDeleteElement'))));
// show the title block
$titleBlock->show ();
// get elements
$elements = KBModuleElement::getElementsByBase (KB_BASE);
// get resources
$bases = KBModuleBase::getBases ();
$fields = KBModuleField::getFieldsByBase (KB_BASE);
$groups = KBModuleGroup::getGroupsByBase (KB_BASE);
// fields without labels
$realFields = array ();
foreach ($fields as $field) {
if (!$field->isType (KB_FIELD_LABEL))
$realFields [] = $field;
}
?>
<script type="text/javascript">
function chooseElementType (sel)
{
document.getElementById ('select_undefined').style.display = "none";
document.getElementById ('select_field').style.display = "none";
document.getElementById ('select_group').style.display = "none";
document.getElementById ('select_entryname').style.display = "none";
document.getElementById ('select_aggregation').style.display = "none";
document.getElementById ('select_relations').style.display = "none";
document.getElementById ('select_collection').style.display = "none";
if (sel.value == <?= KB_ELEMENT_UNDEFINED ?>)
document.getElementById ('select_undefined').style.display = "block";
if (sel.value == <?= KB_ELEMENT_FIELD ?>)
document.getElementById ('select_field').style.display = "block";
else if (sel.value == <?= KB_ELEMENT_KEYWORDS ?>)
document.getElementById ('select_group').style.display = "block";
else if (sel.value == <?= KB_ELEMENT_ENTRY ?>)
document.getElementById ('select_entryname').style.display = "block";
else if (sel.value == <?= KB_ELEMENT_AGGREGATION ?>)
document.getElementById ('select_aggregation').style.display = "block";
else if (sel.value == <?= KB_ELEMENT_RELATIONS ?>)
document.getElementById ('select_relations').style.display = "block";
else if (sel.value == <?= KB_ELEMENT_COLLECTION ?>)
document.getElementById ('select_collection').style.display = "block";
}
function submitIt ()
{
var f = document.elementForm;
if (f.type.value == <?= KB_ELEMENT_UNDEFINED ?>) {
alert ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertUnselectedElementType'))); ?>");
f.type.focus ();
return false;
}
return true;
}
function delIt ()
{
if (confirm ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertDeleteElement'))); ?>"))
{
var f = document.elementForm;
f.del.value = "1";
f.submit ();
}
}
function cancelIt ()
{
location.href = "index.php?m=<?= KB_MODULE ?>";
}
</script>
<form name="elementForm" action="index.php?m=<?= KB_MODULE ?>" method="post" onSubmit="return submitIt();">
<input type="hidden" name="dosql" value="element" />
<input type="hidden" name="del" value="0" />
<input type="hidden" name="id" value="<?= $element_id ?>" />
<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
<tr>
<td width="50%" valign="top">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputElementType') ?></td>
<td width="20"> </td>
<td width="100%">
<select name="type" onChange="chooseElementType(this);">
<? if ($element_id == 0) { ?>
<option value="<?= KB_ELEMENT_UNDEFINED ?>"><?= $AppUI->_('inputElementTypeChoose') ?></option>
<? } ?>
<? if (count ($realFields) > 0) { ?>
<option value="<?= KB_ELEMENT_FIELD ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_FIELD) print (' selected="selected"'); ?>><?= $AppUI->_('elementTypeField') ?></option>
<? } ?>
<option value="<?= KB_ELEMENT_ENTRY ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_ENTRY) print (' selected="selected"'); ?>><?= $AppUI->_('fieldTypeName') ?></option>
<? if (count ($groups) > 0) { ?>
<option value="<?= KB_ELEMENT_KEYWORDS ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_KEYWORDS) print (' selected="selected"'); ?>><?= $AppUI->_('elementTypeKeywords') ?></option>
<? } ?>
<option value="<?= KB_ELEMENT_AGGREGATION ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_AGGREGATION) print (' selected="selected"'); ?>><?= $AppUI->_('elementTypeKeywordsAggregation') ?></option>
<option value="<?= KB_ELEMENT_RELATIONS ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_RELATIONS) print (' selected="selected"'); ?>><?= $AppUI->_('elementTypeRelations') ?></option>
<option value="<?= KB_ELEMENT_COLLECTION ?>"<? if ($element_id > 0 && $element->getType () == KB_ELEMENT_COLLECTION) print (' selected="selected"'); ?>><?= $AppUI->_('elementTypeRelationsAggregation') ?></option>
</select>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputElementSelector') ?></td>
<td> </td>
<td>
<div id="select_undefined" style="display:<? if ($element_id == 0) { ?>block<? } else { ?>none<? } ?>;padding-top:3px;padding-bottom:3px;color:#666666;">
<?= $AppUI->_('inputElementSelectorNA') ?>
</div>
<div id="select_field" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_FIELD) { ?>none<? } else { ?>block<? } ?>;">
<select name="resource_field">
<? foreach ($realFields as $field) { ?>
<option value="<?= $field->getId () ?>"<? if ($element_id > 0 && $element->getResourceId () == $field->getId ()) print (' selected="selected"') ?>><?= $field->getName () ?></option>
<? } ?>
</select>
</div>
<div id="select_group" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_KEYWORDS) { ?>none<? } else { ?>block<? } ?>;">
<select name="resource_group">
<? foreach ($groups as $group) { ?>
<option value="<?= $group->getId () ?>"<? if ($element_id > 0 && $element->getResourceId () == $group->getId ()) print (' selected="selected"') ?>><?= $group->getName () ?></option>
<? } ?>
</select>
</div>
<div id="select_entryname" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_ENTRY) { ?>none<? } else { ?>block<? } ?>;padding-top:3px;padding-bottom:3px;">
<?= $AppUI->_('fieldTypeName') ?> <?= $AppUI->_('inputElementEntryName') ?>
</div>
<div id="select_aggregation" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_AGGREGATION) { ?>none<? } else { ?>block<? } ?>;padding-top:3px;padding-bottom:3px;">
<?= $AppUI->_('inputElementKeywordsAggregation') ?>
</div>
<div id="select_relations" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_RELATIONS) { ?>none<? } else { ?>block<? } ?>;">
<select name="resource_relations">
<? foreach ($bases as $base) { ?>
<option value="<?= $base->getId () ?>"<? if ($element_id > 0 && $element->getResourceId () == $base->getId ()) print (' selected="selected"') ?>><?= $base->getName () ?></option>
<? } ?>
</select>
</div>
<div id="select_collection" style="display:<? if ($element_id == 0 || $element->getType () != KB_ELEMENT_COLLECTION) { ?>none<? } else { ?>block<? } ?>;padding-top:3px;padding-bottom:3px;">
<?= $AppUI->_('inputElementRelationsAggregation') ?>
</div>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputElementWidth') ?></td>
<td> </td>
<td>
<input type="text" size="5" name="width" value="<?= !$element->isAutomaticWidth () ? $element->getWidth () : 'auto' ?>" maxlength="4" />
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputRanking') ?></td>
<td> </td>
<td>
<select name="rank">
<?
// insert
if ($element_id == 0)
{
?>
<option value="0"><?= $AppUI->_('inputRankingFirst'); ?></option>
<?
$i = 0;
$t = count ($elements);
// iterate over elements
foreach ($elements as $el)
{
$i++;
?>
<option value="<?= ((int) $el->getRank () + 1) ?>"<? if ($i == $t) print (' selected="selected"'); ?>><?= $AppUI->_('inputRankingAfter'); ?>
<? if ($el->getName () == '#fieldTypeName#') { ?>
<?= $AppUI->_('fieldTypeName') ?>
<? } elseif ($el->getName () == '#elementTypeKeywords#') { ?>
<?= $AppUI->_('elementTypeKeywords') ?>
<? } elseif ($el->getName () == '#elementTypeRelations#') { ?>
<?= $AppUI->_('elementTypeRelations') ?>
<? } else { ?>
<?= $el->getName () ?>
<? } ?>
</option>
<?
}
// update
} else {
if ($element->getRank () > 0) {
?>
<option value="0"><?= $AppUI->_('inputRankingFirst'); ?></option>
<?
}
// iterate over elements
foreach ($elements as $el)
{
if ($el->getId () == $element_id) {
?>
<option value="-1" selected="selected"><?= $AppUI->_('inputRankingSame'); ?></option>
<?
} elseif (((int) $el->getRank () + 1) != $element->getRank ()) {
?>
<option value="<?= $el->getRank () > $element->getRank () ? $el->getRank () : ((int) $el->getRank () + 1) ?>"><?= $AppUI->_('inputRankingAfter'); ?>
<? if ($el->getName () == '#fieldTypeName#') { ?>
<?= $AppUI->_('fieldTypeName') ?>
<? } elseif ($el->getName () == '#elementTypeKeywords#') { ?>
<?= $AppUI->_('elementTypeKeywords') ?>
<? } elseif ($el->getName () == '#elementTypeRelations#') { ?>
<?= $AppUI->_('elementTypeRelations') ?>
<? } else { ?>
<?= $el->getName () ?>
<? } ?>
</option>
<?
}
}
}
?>
</select>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
<tr>
<td>
<input class="button" type="button" name="cancel" value="<?= $AppUI->_('actionCancel') ?>" onClick="cancelIt();" />
</td>
<td align="right">
<input class="button" type="submit" name="btnFuseAction" value="<?= $AppUI->_('actionSubmit') ?>"/>
</td>
</tr>
</table>
</form>