Location: PHPKode > projects > Knowledge Box > knowledgebox/external/index.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/>.
   */


  // knowledge box
  require_once ('require/knowledgebox.php');

  // base
  $base = new KBModuleBase ();
  $base->load (KBEV_BASE);

  // get resources
  $bases = KBModuleBase::getBases ();
  $groups = KBModuleGroup::getVisibleGroupsByBase (KBEV_BASE);
  $elements = KBModuleElement::getElementsByBase (KBEV_BASE);

  // get config
  $configResultsPerPage = KBModuleConfig::getConfig (KBEV_BASE, KB_CONFIG_PROPERTY_RESULTS);
  $configLastEntries = KBModuleConfig::getConfig (KBEV_BASE, KB_CONFIG_PROPERTY_LASTENTRIES);
  $configDateFormat = KBModuleConfig::getConfig (KBEV_BASE, KB_CONFIG_PROPERTY_DATEFORMAT);
  $configDateSeparator = KBModuleConfig::getConfig (KBEV_BASE, KB_CONFIG_PROPERTY_DATESEPARATOR);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title><?= $translation ['titleKnowledgeBox'] ?> - <?= $base->getName () ?></title>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <link rel="stylesheet" href="css/knowledgebox.css" type="text/css" />

  <script type="text/javascript">
    function batchKeywords (id, value)
    {
      var opt = document.searchForm ["keywords_" + id + "[]"].options;
      for (var i = 0; i < opt.length; i++)
        opt [i].selected = value;
    }
  </script>
</head>

<body>

<table border="0" width="100%">
<tr>
  <td valign="bottom"><h1 style="padding-left:10px;"><?= $base->getName () ?></h1></td>
  <td align="right"><img src="img/knowledgebox.png" alt="Knowledge Box" style="padding-right:20px;" border="0" /></td>
</tr>
</table>

<div style="background-color:#FFFFFF;padding-left:2px;">

<br />
<fieldset style="border:solid 1px #AAAAAA;margin-left:10px;margin-right:10px;background-color:#F6F6F6;">
<legend style="color:#666666; font-weight:bold; font-size:13px;background-color:#FFFFFF;border:solid 1px #AAAAAA;padding:2px;"><?= $translation ['titleSearch'] ?></legend>

<form name="searchForm" action="search.php" method="post">

<br />
<table cellpadding="0" cellspacing="0" border="0" style="padding-left:10px;">
<tr>
<?
  // iterate groups
  foreach ($groups as $group)
  {
    // only filled groups
    if (!KBModuleKeyword::hasKeywordsInGroup ($group->getId ()))
      continue;

    // get labels
    $labels = KBModuleLabel::getLabelsByGroup ($group->getId ());
?>
  <td>
    <div style="padding-bottom:5px;font-weight:bold;">
      <?= $group->getName () ?>
    </div>
    <select name="keywords_<?= $group->getId () ?>[]" multiple="multiple" style="<? if (!$group->isAutomaticWidth ()) print ('width:' . $group->getWidth ().'px;');?>height:160px;">
    <?
      // iterate labels
      foreach ($labels as $label)
      {
        // only filled labels
        if (!KBModuleKeyword::hasKeywordsInLabel ($label->getId ()))
          continue;

        // get keywords
        $keywords = KBModuleKeyword::getKeywordsByLabel ($label->getId ());
    ?>
      <? if ($label->isVisible ()) { ?>
        <optgroup label="<?= $label->getName () ?>&nbsp;&nbsp;">
      <? } ?>
      <?
        // iterate keywords
        foreach ($keywords as $keyword)
        {
          $sel = false;

          // check selected
          if (KBEV_EXECUTE_SEARCH) {
            $keys = $_SESSION [KBEV_SEARCH_KEYWORDS];

            // investigate
            foreach ($keys as $keywordId) {
              if ($keyword->getId () == $keywordId) {
                $sel = true;
                continue;
              }
            }
          }
      ?>
        <option value="<?= $keyword->getId () ?>"<? if ($sel) print (' selected="selected"'); ?>><?= $keyword->getName () ?>&nbsp;&nbsp;</option>
      <?
        } // end iterate keywords
      ?>
      <? if ($label->isVisible ()) { ?>
        </optgroup>
      <? } ?>
    <?
      } // end iterate labels
    ?>
    </select>
    <div style="color:#666666;width:100%;text-align:right;">
    <? if (false) { ?>
      <a href="javascript:batchKeywords(<?= $group->getId () ?>,true);"><?= $translation ['batchSelectAll'] ?></a>
      |
    <? } ?>
      <a href="javascript:batchKeywords(<?= $group->getId () ?>,false);">Unselect</a>
    </div>
  </td>
  <td width="10">&nbsp;</td>
<?
  } // end iterate groups
?>
</tr>
</table>

<br /><br />

<table cellpadding="0" cellspacing="0" border="0">
<tr>
  <td>

<fieldset style="border:solid 1px #AAAAAA;margin-left:10px;margin-right:10px;">
<legend style="color:#666666; font-size:11px; font-weight:bold;background-color:#FFFFFF;border:solid 1px #AAAAAA;padding:2px;"><?= $translation ['labelSearchByContent'] ?></legend>

<br />
<?= $translation ['labelSearchByText'] ?>
<input type="text" value="<?= str_replace ('"', '&quot;', $_SESSION [KBEV_SEARCH_TEXT]); ?>" name="query" maxlength="128" size="32" />

&nbsp;&nbsp;

<?= $translation ['labelSearchByField'] ?>
<select name="field">
  <option value="-1"<? if ((int) $_SESSION [KBEV_SEARCH_FIELD] == -1) print (' selected="selected"'); ?>><?= $translation ['labelSearchByFieldAll'] ?></option>
  <option value="0"<? if ((int) $_SESSION [KBEV_SEARCH_FIELD] == 0) print (' selected="selected"'); ?>><?= $translation ['fieldTypeName'] ?></option>
  <?
    // fields
    $fields = KBModuleField::getFieldsByBase (KBEV_BASE);

    // iterate
    foreach ($fields as $field)
    {
      if ($field->isType (KB_FIELD_IMAGE) || $field->isType (KB_FIELD_PASSWORD) || $field->isType (KB_FIELD_LABEL))
        continue;
  ?>
  <option value="<?= $field->getId () ?>"<? if ($field->getId () == (int) $_SESSION [KBEV_SEARCH_FIELD]) print (' selected="selected"'); ?>><?= $field->getName () ?></option>
  <?
    }
  ?>
</select>

<br />&nbsp;
</fieldset>

  </td>
  <td align="center">

<fieldset style="border:solid 1px #AAAAAA;margin-left:10px;margin-right:10px;">
<legend style="color:#666666; font-size:11px; font-weight:bold;background-color:#FFFFFF;border:solid 1px #AAAAAA;padding:2px;"><?= $translation ['labelSearchSubmit'] ?></legend>

    <br />
    <input type="submit" value="<?= $translation ['actionSearchButton'] ?>" name="btnFuseAction" />
    <br />&nbsp;

</fieldset>

  </td>
</tr>
</table>

</form>
</fieldset>
<br />&nbsp;

<?

// results wanted?
// two cases: a search is made or display last entries if it matches config
if ((!KBEV_EXECUTE_SEARCH && $configLastEntries->getIntValue () != 0) || KBEV_EXECUTE_SEARCH)
{

  // entries
  if (KBEV_EXECUTE_SEARCH)
    $entries = KBModuleSearch::getResults (KBEV_BASE, $_SESSION [KBEV_SEARCH_KEYWORDS], $_SESSION [KBEV_SEARCH_TEXT], $_SESSION [KBEV_SEARCH_FIELD]);
  else
    $entries = KBModuleSearch::getLastEntries (KBEV_BASE, $configLastEntries->getIntValue ());

  // sort entries
  if (strlen ($_SESSION [KB_SEARCH_SORT_FIELD]) > 0)
    usort ($entries, 'sortEntries');

  // paginate
  if (KBEV_EXECUTE_SEARCH) {
    $pages = KBModuleSearch::getTotalPages ($entries, $configResultsPerPage->getIntValue ());
    $entries = KBModuleSearch::getPaginatedResults ($entries, $_SESSION [KBEV_SEARCH_INDEX], $configResultsPerPage->getIntValue ());
  }

  // output
  $elements = KBModuleSearch::getElements (KBEV_BASE);
?>

<? if (empty ($entries)) { ?>

  <fieldset style="border:solid 1px #AAAAAA;margin-left:10px;margin-right:10px;background-color:#F6F6F6;">
  <legend style="color:#666666; font-weight:bold; font-size:13px;background-color:#FFFFFF;border:solid 1px #AAAAAA;padding:2px;"><?= $translation ['subTitleNoResults'] ?></legend>

  <p style="padding-left:10px;padding-bottom:40px;">
    <?= $translation ['noResultsFoundExplanation'] ?>
  </p>

<? } else { ?>

  <fieldset style="border:solid 1px #AAAAAA;margin-left:10px;margin-right:10px;background-color:#F6F6F6;">
  <legend style="color:#666666; font-weight:bold; font-size:13px;background-color:#FFFFFF;border:solid 1px #AAAAAA;padding:2px;">
    <?
      if (KBEV_EXECUTE_SEARCH)
        print ($translation ['subTitleSearchResults']);

      else
      {
        if ($configLastEntries->getIntValue () == -1)
          print ($translation ['subTitleEntries']);
        else
          print ($translation ['subTitleLastEntries']);
      }
    ?>
  </legend>

<? if (KBEV_EXECUTE_SEARCH && $pages > 1) { ?>

  <div style="text-align:center;">
    <?= $translation ['pagingSearchResults'] ?>&nbsp;&nbsp;
    <? for ($i = 0; $i < $pages; $i++) { ?>
      <a href="index.php?m=knowledgebox&inx=<?= $i ?>"<? if ($i == $_SESSION [KBEV_SEARCH_INDEX]) print (' style="font-weight:bold;text-decoration:underline;"');?>><?= ($i + 1) ?></a>
    <? } ?>
  </div>

<? } ?>

<br />
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
  <th width="35" style="font-size:12px;font-weight:bold;border:solid 1px #AAAAAA;"><?= $translation ['columnView'] ?></th>
  <?
    // elements
    foreach ($elements as $element)
    {
      $sortable = true;

      if ($element->isType (KB_ELEMENT_FIELD))
      {
        $field = new KBModuleField ();
        $field->load ($element->getResourceId ());

        $sortable = $field->isSortable ();
      }
  ?>
    <th style="border:solid 1px #AAAAAA;border-left:0px;<? if (!$element->isAutomaticWidth ()) { ?>width:<?= $element->getWidth () ?>px;<? } ?>" align="center">
      <table cellpadding="0" cellspacing="0" border="0" align="center" style="height:25px;">
      <tr>
        <td>
          <? if ($sortable) { ?>
          <a href="<?= str_replace ('&', '&amp;', KBModuleSearch::makeSortUrl ($element->getId (), 'asc')); ?>"><?= str_replace ('>', ' />', str_replace ('align=\'center\'', 'alt=""', dPshowImage ('./../../../images/arrow-up.gif', '11', '11'))) ?></a>
          <? } ?>
        </td>
        <td style="font-weight:bold;font-size:12px;" nowrap="nowrap">
          &nbsp;
          <? if ($element->getName () == '#fieldTypeName#') { ?>
            <?= $translation ['fieldTypeName'] ?>
          <? } elseif ($element->getName () == '#elementTypeKeywords#') { ?>
            <?= $translation ['elementTypeKeywords'] ?>
          <? } elseif ($element->getName () == '#elementTypeRelations#') { ?>
            <?= $translation ['elementTypeRelations'] ?>
          <? } else { ?>
            <?= $element->getName () ?>
          <? } ?>
          &nbsp;
        </td>
        <td>
          <? if ($sortable) { ?>
          <a href="<?= str_replace ('&', '&amp;', KBModuleSearch::makeSortUrl ($element->getId (), 'desc')); ?>"><?= str_replace ('>', ' />', str_replace ('align=\'center\'', 'alt=""', dPshowImage ('./../../../images/arrow-down.gif', '11', '11'))) ?></a>
          <? } ?>
        </td>
      </tr>
      </table>
    </th>
  <?
    } // end elements
  ?>
</tr>
<tr>
  <? for ($i = 0; $i <= count ($elements); $i++) { ?>
    <td style="<? if ($i == 0) { ?>border-left:solid 1px #AAAAAA;<? } ?>border-right:solid 1px #AAAAAA;font-size:2px;height:2px;background-color:#FFFFFF;">&nbsp;</td>
  <? } ?>
</tr>
<?

  $odd = 1;

  // entries
  foreach ($entries as $entry)
  {
    $odd = 1 - $odd;
?>
  <tr>
    <? for ($i = 0; $i <= count ($elements); $i++) { ?>
      <td style="<? if ($i == 0) { ?>border-left:solid 1px #AAAAAA;<? } ?>border-right:solid 1px #AAAAAA;font-size:2px;height:2px;<? if ((boolean) $odd) { ?>background-color:#FFFFFF;<? } ?>">&nbsp;</td>
    <? } ?>
  </tr>
  <tr style="<? if ((boolean) $odd) { ?>background-color:#FFFFFF;<? } ?>">
    <td align="center" valign="top" style="border-left:solid 1px #AAAAAA;border-right:solid 1px #AAAAAA;">
      <a href="view.php?id=<?= $entry->getId () ?>">
      <?= str_replace ('>', ' />', str_replace ('align=\'center\'', 'alt=""', dPshowImage ('./../../../images/obj/folder-shared.gif', '16', '16'))) ?></a>
    </td>
    <?
      // elements
      foreach ($elements as $element)
      {
        // kind of entry name
        if ($element->isType (KB_ELEMENT_ENTRY)) {
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;"><?= $entry->getName () ?></td>
      <?
        // kind of field
        } else if ($element->isType (KB_ELEMENT_FIELD)) {

          // get field
          $field = new KBModuleField ();
          $field->load ($element->getResourceId ());

          // get substance
          $substance = KBModuleSubstance::getSubstance ($entry->getId (), $field->getId ());

          // field is a text or html
          if ($field->getType () == KB_FIELD_TEXT || $field->getType () == KB_FIELD_HTML) {
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;"><?= $substance->getTextValue () ?>&nbsp;</td>
      <?
          // field is an email
          } elseif ($field->getType () == KB_FIELD_EMAIL) {
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <a href="mailto:<?= $substance->getTextValue () ?>"><?= $substance->getTextValue () ?></a>
          <? } ?>
          &nbsp;
        </td>
      <?
          // field is a password
          } elseif ($field->getType () == KB_FIELD_PASSWORD) {
      ?>
        <td valign="top" align="center" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <?= $translation ['encryptedPassword'] ?>
          <? } else { ?>
            <?= $translation ['undefinedPassword'] ?>
          <? } ?>
          &nbsp;
        </td>
      <?
          // field is a link
          } elseif ($field->getType () == KB_FIELD_LINK) {
            $targetBlank = (int) $substance->getMimeType () == 1;
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <a href="<?= $substance->getTextValue () ?>"<? if ($targetBlank) { ?> target="_blank"<? } ?>><?= $substance->getInformation () ?></a>
          <? } ?>
          &nbsp;
        </td>
      <?
          // field is a file
          } elseif ($field->getType () == KB_FIELD_FILE) {
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <a href="../io/<?= KB_STREAM_FILE ?>.php?entry=<?= $entry->getId () ?>&amp;field=<?= $field->getId () ?>"><?= $substance->getInformation () ?></a>
          <? } ?>
          &nbsp;
        </td>
      <?
          // field is an image
          } elseif ($field->getType () == KB_FIELD_IMAGE) {
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <img src="../io/<?= KB_STREAM_IMAGE ?>.php?entry=<?= $entry->getId () ?>&amp;field=<?= $field->getId () ?>">
          <? } ?>
          &nbsp;
        </td>
      <?
          // field is a date
          } elseif ($field->getType () == KB_FIELD_DATE) {

            if (strlen ($substance->getTextValue ()) > 0) {
              $day = substr ($substance->getTextValue (), -2);
              $month = substr ($substance->getTextValue (), 4, 2);
              $year = substr ($substance->getTextValue (), 0, 4);
            }
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <? if (strlen ($substance->getTextValue ()) > 0) { ?>
            <?= formatDateAsInConfig ($day, $month, $year, $configDateFormat, $configDateSeparator); ?>
          <? } ?>
          &nbsp;
        </td>
      <?
          } // end field

        // kind of keywords
        } else if ($element->isType (KB_ELEMENT_KEYWORDS)) {

          // get relations
          $relations = KBModuleRelation::getRelationsByEntry ($entry->getId ());

          // get group
          $group = new KBModuleGroup ();
          $group->load ($element->getResourceId ());

          // get keywords
          $displayedKeywords = 0;
          $keywords = KBModuleKeyword::getKeywordsByGroup ($group->getId ());
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <?
            // keywords. ordered!.
            foreach ($keywords as $keyword)
            {
              // relations
              foreach ($relations as $relation)
              {
                if ($keyword->getId () == $relation->getKeywordId ())
                {
                  if ($displayedKeywords > 0)
                    print ('; ');

                  print ('<a href="relation.php?keyword=' . $keyword->getId () . '">' . $keyword->getName () . '</a>');

                  $displayedKeywords++;
                  continue;
                }
              }
            }
          ?>
          &nbsp;
        </td>
      <?
        // kind of keywords aggregation
        } else if ($element->isType (KB_ELEMENT_AGGREGATION)) {

          // get relations
          $relations = KBModuleRelation::getRelationsByEntry ($entry->getId ());

      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
        <?
          $displayedKeywords = 0;

          // iterate groups
          foreach ($groups as $group)
          {
            // get keywords
            $keywords = KBModuleKeyword::getKeywordsByGroup ($group->getId ());

            // keywords. ordered!.
            foreach ($keywords as $keyword)
            {
              // relations
              foreach ($relations as $relation)
              {
                if ($keyword->getId () == $relation->getKeywordId ())
                {
                  if ($displayedKeywords > 0)
                    print ('; ');

                  print ('<a href="relation.php?keyword=' . $keyword->getId () . '">' . $keyword->getName () . '</a>');

                  $displayedKeywords++;
                  continue;
                }
              }
            }
          }
          ?>
          &nbsp;
        </td>
      <?
        // kind of relations
        } else if ($element->isType (KB_ELEMENT_RELATIONS)) {

          // get relations
          $relatives = KBModuleRelative::getRelativesByEntry ($entry->getId ());

          // get base
          $base = new KBModuleBase ();
          $base->load ($element->getResourceId ());

          // get entries
          $displayedEntries = 0;
          $dEntries = KBModuleEntry::getEntriesByBase ($base->getId ());
      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
          <?
            // entries. ordered!.
            foreach ($dEntries as $dEntry)
            {
              // relations
              foreach ($relatives as $relative)
              {
                if ($dEntry->getId () == $relative->getRelativeId ())
                {
                  if ($displayedEntries > 0)
                    print ('; ');

                  print ('<a href="view.php?id=' . $dEntry->getId () . '&kbid=' . $dEntry->getBaseId () . '">' . $dEntry->getName () . '</a>');

                  $displayedEntries++;
                  continue;
                }
              }
            }
          ?>
          &nbsp;
        </td>
      <?
        // kind of relations aggregation
        } else if ($element->isType (KB_ELEMENT_COLLECTION)) {

          // get relations
          $relatives = KBModuleRelative::getRelativesByEntry ($entry->getId ());

      ?>
        <td valign="top" style="border-right:solid 1px #AAAAAA;">
        <?
          $displayedEntries = 0;

          // iterate bases
          foreach ($bases as $base)
          {
            // get entries
            $dEntries = KBModuleEntry::getEntriesByBase ($base->getId ());

            // entries. ordered!.
            foreach ($dEntries as $dEntry)
            {
              // relations
              foreach ($relatives as $relative)
              {
                if ($dEntry->getId () == $relative->getRelativeId ())
                {
                  if ($displayedEntries > 0)
                    print ('; ');

                  print ('<a href="view.php?id=' . $dEntry->getId () . '&kbid=' . $dEntry->getBaseId () . '">' . $dEntry->getName () . '</a>');

                  $displayedEntries++;
                  continue;
                }
              }
            }
          }
          ?>
          &nbsp;
        </td>
      <?
        } // end relations aggregation

      } // end elements
    ?>
  </tr>
  <tr>
    <? for ($i = 0; $i <= count ($elements); $i++) { ?>
      <td style="<? if ($i == 0) { ?>border-left:solid 1px #AAAAAA;<? } ?>border-right:solid 1px #AAAAAA;font-size:2px;height:2px;<? if ((boolean) $odd) { ?>background-color:#FFFFFF;<? } ?>">&nbsp;</td>
    <? } ?>
  </tr>
<?
  } // end entries
?>
<tr>
  <? for ($i = 0; $i <= count ($elements); $i++) { ?>
    <td style="border-bottom:solid 1px #AAAAAA;<? if ($i == 0) { ?>border-left:solid 1px #AAAAAA;<? } ?>border-right:solid 1px #AAAAAA;font-size:2px;height:2px;<? if (!(boolean) $odd) { ?>background-color:#FFFFFF;<? } ?>">&nbsp;</td>
  <? } ?>
</tr>
</table>

<? if (KBEV_EXECUTE_SEARCH && $pages > 1) { ?>

  <br />
  <div style="text-align:center;">
    <?= $translation ['pagingSearchResults'] ?>&nbsp;&nbsp;
    <? for ($i = 0; $i < $pages; $i++) { ?>
      <a href="index.php?m=knowledgebox&inx=<?= $i ?>"<? if ($i == $_SESSION [KBEV_SEARCH_INDEX]) print (' style="font-weight:bold;text-decoration:underline;"');?>><?= ($i + 1) ?></a>
    <? } ?>

    <br />&nbsp;
  </div>

<? } ?>

<? } // end check empty results ?>

<?
  } // end wanted last results
?>

</fieldset>

</div>

</body>
</html>
Return current item: Knowledge Box