Location: PHPKode > projects > Knowledge Box > knowledgebox/wizard/keyword.php
<?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
  $keyword_id = (int) dPgetParam ($_GET, 'id');

  // instanciate
  $keyword = new KBModuleKeyword ();

  // load record
  if ($keyword_id > 0 && !$keyword->load ($keyword_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);
  
  // label
  $label = new KBModuleLabel ();
  $label->load (KB_LABEL);

  // title block
  $titleBlock = new CTitleBlock (utf8_encode (html_entity_decode ($AppUI->_($keyword_id > 0 ? 'titleEditKeyword' : 'titleNewKeyword'))), 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, html_entity_decode ($label->getName ()));
  $titleBlock->addCrumb ('?m=' . KB_MODULE . '&pane=' . KB_PANE_KEYWORDS, utf8_encode (html_entity_decode ($AppUI->_('crumbKeywords'))));

  // delete link
  if ($keyword_id > 0)
    $titleBlock->addCrumbDelete (utf8_encode (html_entity_decode ($AppUI->_('actionDeleteKeyword'))));

  // show the title block
  $titleBlock->show ();

  // get keywords
  $keywords = KBModuleKeyword::getKeywordsByLabel (KB_LABEL);

?>

<script type="text/javascript">

  function submitIt ()
  {
    var f = document.keywordForm;

    if (f.name.value.length == 0) {
      alert ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertEmptyKeywordName'))); ?>");
      f.name.focus ();
      return false;
    }

    return true;
  }
  
  function delIt ()
  {
    if (confirm ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertDeleteKeyword'))); ?>"))
    {
      var f = document.keywordForm;
      f.del.value = "1";
      f.submit ();
    }
  }
  
  function cancelIt ()
  {
    location.href = "index.php?m=<?= KB_MODULE ?>&pane=<?= KB_PANE_KEYWORDS ?>";
  }
  
</script>

<form name="keywordForm" action="index.php?m=<?= KB_MODULE ?>" method="post" onSubmit="return submitIt();">

<input type="hidden" name="dosql" value="keyword" />
<input type="hidden" name="del" value="0" />
<input type="hidden" name="id" value="<?= $keyword_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->_('inputKeywordName') ?></td>
      <td width="20">&nbsp;</td>
      <td width="100%">
        <input type="text" size="32" name="name" value="<?= str_replace ('&amp;', '&', dPformSafe ($keyword->getName ())) ?>" maxlength="128" />
      </td>
    </tr>
    <tr>
      <td align="right" nowrap="nowrap"><?= $AppUI->_('inputRanking') ?></td>
      <td>&nbsp;</td>
      <td>
        <select name="rank">
        <?
          // insert
          if ($keyword_id == 0)
          {
        ?>
          <option value="0"><?= $AppUI->_('inputRankingFirst') ?></option>
          <?
            $i = 0;
            $t = count ($keywords);

            // iterate over keywords
            foreach ($keywords as $key)
            {
              $i++;
          ?>
            <option value="<?= ((int) $key->getRank () + 1) ?>"<? if ($i == $t) print (' selected="selected"'); ?>><?= $AppUI->_('inputRankingAfter') ?> <?= $key->getName () ?></option>
          <?
            }
          
          // update
          } else {
          
            if ($keyword->getRank () > 0) {
          ?>
            <option value="0"><?= $AppUI->_('inputRankingFirst') ?></option>
          <?
            }

            // iterate over keywords
            foreach ($keywords as $key)
            {
              if ($key->getId () == $keyword_id) {
            ?>
              <option value="-1" selected="selected"><?= $AppUI->_('inputRankingSame') ?></option>
            <?
              } elseif (((int) $key->getRank () + 1) != $keyword->getRank ()) {
            ?>
              <option value="<?= $key->getRank () > $keyword->getRank () ? $key->getRank () : ((int) $key->getRank () + 1) ?>"><?= $AppUI->_('inputRankingAfter') ?> <?= $key->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>
Return current item: Knowledge Box