<?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
$field_id = (int) dPgetParam ($_GET, 'id');
// instanciate
$field = new KBModuleField ();
// load record
if ($field_id > 0 && !$field->load ($field_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->_($field_id > 0 ? 'titleEditField' : 'titleNewField'))), KB_MODULE_ICON);
// breadcrumbs
$titleBlock->addCrumb ('?m=' . KB_MODULE, html_entity_decode ($base->getName ()));
$titleBlock->addCrumb ('?m=' . KB_MODULE . '&e=fields', utf8_encode (html_entity_decode ($AppUI->_('crumbFields'))));
// delete link
if ($field_id > 0)
$titleBlock->addCrumbDelete (utf8_encode (html_entity_decode ($AppUI->_('actionDeleteField'))));
// show the title block
$titleBlock->show ();
// get fields
$fields = KBModuleField::getFieldsByBase (KB_BASE);
?>
<script type="text/javascript">
function chooseFieldType (sel)
{
document.getElementById ('element_helper').style.display = "block";
document.getElementById ('element_mandatory').style.display = "block";
document.getElementById ('element_visible').style.display = "block";
document.getElementById ('element_helper_na').style.display = "none";
document.getElementById ('element_mandatory_na').style.display = "none";
document.getElementById ('element_visible_na').style.display = "none";
if (sel.value == <?= KB_FIELD_LABEL ?>) {
document.getElementById ('element_helper').style.display = "none";
document.getElementById ('element_mandatory').style.display = "none";
document.getElementById ('element_visible').style.display = "none";
document.getElementById ('element_helper_na').style.display = "block";
document.getElementById ('element_mandatory_na').style.display = "block";
document.getElementById ('element_visible_na').style.display = "block";
}
}
function submitIt ()
{
var f = document.fieldForm;
if (f.name.value.length == 0) {
alert ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertEmptyFieldName'))); ?>");
f.name.focus ();
return false;
}
return true;
}
function delIt ()
{
if (confirm ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertDeleteField'))); ?>"))
{
var f = document.fieldForm;
f.del.value = "1";
f.submit ();
}
}
function cancelIt ()
{
location.href = "index.php?m=<?= KB_MODULE ?>";
}
</script>
<form name="fieldForm" action="index.php?m=<?= KB_MODULE ?>" method="post" onSubmit="return submitIt();">
<input type="hidden" name="dosql" value="field" />
<input type="hidden" name="del" value="0" />
<input type="hidden" name="id" value="<?= $field_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->_('inputFieldName') ?></td>
<td width="20"> </td>
<td width="100%">
<input type="text" size="32" name="name" value="<?= str_replace ('&', '&', dPformSafe ($field->getName ())) ?>" maxlength="128" />
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputFieldHelper') ?></td>
<td> </td>
<td>
<div id="element_helper" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>none<? } else { ?>block<? } ?>;">
<input type="text" size="32" name="helper" value="<?= str_replace ('&', '&', dPformSafe ($field->getHelper ())) ?>" maxlength="128" />
</div>
<div id="element_helper_na" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>block<? } else { ?>none<? } ?>;padding-top:3px;padding-bottom:3px;color:#666666;">
<?= $AppUI->_('inputElementSelectorNA') ?>
</div>
</td>
</tr>
<? if ($field_id == 0) { ?>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputFieldType') ?></td>
<td> </td>
<td>
<select name="type" onChange="chooseFieldType(this);">
<option value="<?= KB_FIELD_TEXT ?>"><?= $AppUI->_('fieldTypeText') ?></option>
<option value="<?= KB_FIELD_HTML ?>"><?= $AppUI->_('fieldTypeHTML') ?></option>
<option value="<?= KB_FIELD_FILE ?>"><?= $AppUI->_('fieldTypeFile') ?></option>
<option value="<?= KB_FIELD_IMAGE ?>"><?= $AppUI->_('fieldTypeImage') ?></option>
<option value="<?= KB_FIELD_DATE ?>"><?= $AppUI->_('fieldTypeDate') ?></option>
<option value="<?= KB_FIELD_LINK ?>"><?= $AppUI->_('fieldTypeLink') ?></option>
<option value="<?= KB_FIELD_EMAIL ?>"><?= $AppUI->_('fieldTypeEmail') ?></option>
<option value="<?= KB_FIELD_PASSWORD ?>"><?= $AppUI->_('fieldTypePassword') ?></option>
<option value="<?= KB_FIELD_LABEL ?>"><?= $AppUI->_('fieldTypeLabel') ?></option>
</select>
</td>
</tr>
<? } ?>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputFieldMandatory') ?></td>
<td> </td>
<td>
<div id="element_mandatory" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>none<? } else { ?>block<? } ?>;">
<input type="checkbox" name="mandatory" value="1" style="margin-left:0px;"<? if ($field_id > 0 && $field->isMandatory ()) print (' checked="checked"'); ?> />
</div>
<div id="element_mandatory_na" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>block<? } else { ?>none<? } ?>;padding-top:3px;padding-bottom:3px;color:#666666;">
<?= $AppUI->_('inputElementSelectorNA') ?>
</div>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputFieldDisplayed') ?></td>
<td> </td>
<td>
<div id="element_visible" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>none<? } else { ?>block<? } ?>;">
<input type="checkbox" name="visible" value="1" style="margin-left:0px;"<? if ($field_id == 0 || $field->isVisible ()) print (' checked="checked"'); ?> />
</div>
<div id="element_visible_na" style="display:<? if ($field_id > 0 && $field->getType () == KB_FIELD_LABEL) { ?>block<? } else { ?>none<? } ?>;padding-top:3px;padding-bottom:3px;color:#666666;">
<?= $AppUI->_('inputElementSelectorNA') ?>
</div>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputRanking') ?></td>
<td> </td>
<td>
<select name="rank">
<?
// insert
if ($field_id == 0)
{
?>
<option value="0"><?= $AppUI->_('inputRankingAfter'); ?> <?= $AppUI->_('fieldTypeName') ?></option>
<?
$i = 0;
$t = count ($fields);
// iterate over fields
foreach ($fields as $fld)
{
$i++;
?>
<option value="<?= ((int) $fld->getRank () + 1) ?>"<? if ($i == $t) print (' selected="selected"'); ?>><?= $AppUI->_('inputRankingAfter'); ?> <?= $fld->getName () ?></option>
<?
}
// update
} else {
if ($field->getRank () > 0) {
?>
<option value="0"><?= $AppUI->_('inputRankingAfter'); ?> <?= $AppUI->_('fieldTypeName') ?></option>
<?
}
// iterate over fields
foreach ($fields as $fld)
{
if ($fld->getId () == $field_id) {
?>
<option value="-1" selected="selected"><?= $AppUI->_('inputRankingSame'); ?></option>
<?
} elseif (((int) $fld->getRank () + 1) != $field->getRank ()) {
?>
<option value="<?= $fld->getRank () > $field->getRank () ? $fld->getRank () : ((int) $fld->getRank () + 1) ?>"><?= $AppUI->_('inputRankingAfter'); ?> <?= $fld->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>