<?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_CONTRIBUTOR)
$AppUI->redirect (KB_ACCESS_DENIED);
// retrieve id
$label_id = (int) dPgetParam ($_GET, 'id');
// instanciate
$label = new KBModuleLabel ();
// load record
if ($label_id > 0 && !$label->load ($label_id))
{
// failed
$AppUI->setMsg ('invalidID', UI_MSG_ERROR, true);
$AppUI->redirect ();
}
// base
$base = new KBModuleBase ();
$base->load (KB_BASE);
// group
$group = new KBModuleGroup ();
$group->load (KB_GROUP);
// title block
$titleBlock = new CTitleBlock (utf8_encode (html_entity_decode ($AppUI->_($label_id > 0 ? 'titleEditLabel' : 'titleNewLabel'))), KB_MODULE_ICON);
// breadcrumb
$titleBlock->addCrumb ('?m=' . KB_MODULE, html_entity_decode ($base->getName ()));
$titleBlock->addCrumb ('?m=' . KB_MODULE . '&e=groups', html_entity_decode ($group->getName ()));
$titleBlock->addCrumb ('?m=' . KB_MODULE . '&pane=' . KB_PANE_LABELS, utf8_encode (html_entity_decode ($AppUI->_('crumbLabels'))));
// delete link
if ($label_id > 0)
$titleBlock->addCrumbDelete (utf8_encode (html_entity_decode ($AppUI->_('actionDeleteLabel'))));
// show the title block
$titleBlock->show ();
// get labels
$labels = KBModuleLabel::getLabelsByGroup (KB_GROUP);
?>
<script type="text/javascript">
function submitIt ()
{
var f = document.labelForm;
if (f.name.value.length == 0) {
alert ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertEmptyLabelName'))); ?>");
f.name.focus ();
return false;
}
return true;
}
function delIt ()
{
if (confirm ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertDeleteLabel'))); ?>"))
{
var f = document.labelForm;
f.del.value = "1";
f.submit ();
}
}
function cancelIt ()
{
location.href = "index.php?m=<?= KB_MODULE ?>&pane=<?= KB_PANE_LABELS ?>";
}
</script>
<form name="labelForm" action="index.php?m=<?= KB_MODULE ?>" method="post" onSubmit="return submitIt();">
<input type="hidden" name="dosql" value="label" />
<input type="hidden" name="del" value="0" />
<input type="hidden" name="id" value="<?= $label_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->_('inputLabelName') ?></td>
<td width="20"> </td>
<td width="100%">
<input type="text" size="32" name="name" value="<?= str_replace ('&', '&', dPformSafe ($label->getName ())) ?>" maxlength="128" />
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputLabelDisplayed') ?></td>
<td> </td>
<td>
<input type="checkbox" name="visible" value="1" style="margin-left:0px;"<? if ($label_id == 0 || $label->isVisible ()) print (' checked="checked"'); ?> />
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap"><?= $AppUI->_('inputRanking') ?></td>
<td> </td>
<td>
<select name="rank">
<?
// insert
if ($label_id == 0)
{
?>
<option value="0"><?= $AppUI->_('inputRankingFirst') ?></option>
<?
$i = 0;
$t = count ($labels);
// iterate over labels
foreach ($labels as $lbl)
{
$i++;
?>
<option value="<?= ((int) $lbl->getRank () + 1) ?>"<? if ($i == $t) print (' selected="selected"'); ?>><?= $AppUI->_('inputRankingAfter') ?> <?= $lbl->getName () ?></option>
<?
}
// update
} else {
if ($label->getRank () > 0) {
?>
<option value="0"><?= $AppUI->_('inputRankingFirst') ?></option>
<?
}
// iterate over labels
foreach ($labels as $lbl)
{
if ($lbl->getId () == $label_id) {
?>
<option value="-1" selected="selected"><?= $AppUI->_('inputRankingSame') ?></option>
<?
} elseif (((int) $lbl->getRank () + 1) != $label->getRank ()) {
?>
<option value="<?= $lbl->getRank () > $label->getRank () ? $lbl->getRank () : ((int) $lbl->getRank () + 1) ?>"><?= $AppUI->_('inputRankingAfter') ?> <?= $lbl->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>