[Mapbender-commits] r3649 - in branches/print_dev/http: extensions
img img/button_digitize javascripts php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Mar 9 05:08:08 EDT 2009
Author: mschulz
Date: 2009-03-09 05:08:08 -0400 (Mon, 09 Mar 2009)
New Revision: 3649
Added:
branches/print_dev/http/extensions/DifferenceEngine.php
branches/print_dev/http/img/asc.gif
branches/print_dev/http/img/bg.gif
branches/print_dev/http/img/button_digitize/punchPolygon_off.png
branches/print_dev/http/img/button_digitize/punchPolygon_on.png
branches/print_dev/http/img/button_digitize/punchPolygon_over.png
branches/print_dev/http/img/desc.gif
branches/print_dev/http/img/digitize.png
branches/print_dev/http/img/map.png
branches/print_dev/http/javascripts/mod_tooltip.php
branches/print_dev/http/javascripts/wfsFilter.js
branches/print_dev/http/php/mod_category_filteredGUI.php
branches/print_dev/http/php/mod_createCategory.php
Log:
merged from trunk
Added: branches/print_dev/http/extensions/DifferenceEngine.php
===================================================================
--- branches/print_dev/http/extensions/DifferenceEngine.php (rev 0)
+++ branches/print_dev/http/extensions/DifferenceEngine.php 2009-03-09 09:08:08 UTC (rev 3649)
@@ -0,0 +1,1062 @@
+<?php
+/**
+ * A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
+ *
+ * Additions by Axel Boldt for MediaWiki
+ *
+ * @copyright (C) 2000, 2001 Geoffrey T. Dairiki <dairiki at dairiki.org>
+ * @license You may copy this code freely under the conditions of the GPL.
+ */
+define('USE_ASSERTS', function_exists('assert'));
+
+class _DiffOp {
+ var $type;
+ var $orig;
+ var $closing;
+
+ function reverse() {
+ trigger_error("pure virtual", E_USER_ERROR);
+ }
+
+ function norig() {
+ return $this->orig ? sizeof($this->orig) : 0;
+ }
+
+ function nclosing() {
+ return $this->closing ? sizeof($this->closing) : 0;
+ }
+}
+
+class _DiffOp_Copy extends _DiffOp {
+ var $type = 'copy';
+
+ function _DiffOp_Copy ($orig, $closing = false) {
+ if (!is_array($closing))
+ $closing = $orig;
+ $this->orig = $orig;
+ $this->closing = $closing;
+ }
+
+ function reverse() {
+ return new _DiffOp_Copy($this->closing, $this->orig);
+ }
+}
+
+class _DiffOp_Delete extends _DiffOp {
+ var $type = 'delete';
+
+ function _DiffOp_Delete ($lines) {
+ $this->orig = $lines;
+ $this->closing = false;
+ }
+
+ function reverse() {
+ return new _DiffOp_Add($this->orig);
+ }
+}
+
+class _DiffOp_Add extends _DiffOp {
+ var $type = 'add';
+
+ function _DiffOp_Add ($lines) {
+ $this->closing = $lines;
+ $this->orig = false;
+ }
+
+ function reverse() {
+ return new _DiffOp_Delete($this->closing);
+ }
+}
+
+class _DiffOp_Change extends _DiffOp {
+ var $type = 'change';
+
+ function _DiffOp_Change ($orig, $closing) {
+ $this->orig = $orig;
+ $this->closing = $closing;
+ }
+
+ function reverse() {
+ return new _DiffOp_Change($this->closing, $this->orig);
+ }
+}
+
+
+/**
+ * Class used internally by Diff to actually compute the diffs.
+ *
+ * The algorithm used here is mostly lifted from the perl module
+ * Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
+ * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
+ *
+ * More ideas are taken from:
+ * http://www.ics.uci.edu/~eppstein/161/960229.html
+ *
+ * Some ideas are (and a bit of code) are from from analyze.c, from GNU
+ * diffutils-2.7, which can be found at:
+ * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
+ *
+ * closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
+ * are my own.
+ *
+ * @author Geoffrey T. Dairiki
+ * @access private
+ */
+class _DiffEngine
+{
+ function diff ($from_lines, $to_lines) {
+ $n_from = sizeof($from_lines);
+ $n_to = sizeof($to_lines);
+
+ $this->xchanged = $this->ychanged = array();
+ $this->xv = $this->yv = array();
+ $this->xind = $this->yind = array();
+ unset($this->seq);
+ unset($this->in_seq);
+ unset($this->lcs);
+
+ // Skip leading common lines.
+ for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
+ if ($from_lines[$skip] != $to_lines[$skip])
+ break;
+ $this->xchanged[$skip] = $this->ychanged[$skip] = false;
+ }
+ // Skip trailing common lines.
+ $xi = $n_from; $yi = $n_to;
+ for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
+ if ($from_lines[$xi] != $to_lines[$yi])
+ break;
+ $this->xchanged[$xi] = $this->ychanged[$yi] = false;
+ }
+
+ // Ignore lines which do not exist in both files.
+ for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
+ $xhash[$from_lines[$xi]] = 1;
+ for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
+ $line = $to_lines[$yi];
+ if ( ($this->ychanged[$yi] = empty($xhash[$line])) )
+ continue;
+ $yhash[$line] = 1;
+ $this->yv[] = $line;
+ $this->yind[] = $yi;
+ }
+ for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
+ $line = $from_lines[$xi];
+ if ( ($this->xchanged[$xi] = empty($yhash[$line])) )
+ continue;
+ $this->xv[] = $line;
+ $this->xind[] = $xi;
+ }
+
+ // Find the LCS.
+ $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv));
+
+ // Merge edits when possible
+ $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
+ $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
+
+ // Compute the edit operations.
+ $edits = array();
+ $xi = $yi = 0;
+ while ($xi < $n_from || $yi < $n_to) {
+ USE_ASSERTS && assert($yi < $n_to || $this->xchanged[$xi]);
+ USE_ASSERTS && assert($xi < $n_from || $this->ychanged[$yi]);
+
+ // Skip matching "snake".
+ $copy = array();
+ while ( $xi < $n_from && $yi < $n_to
+ && !$this->xchanged[$xi] && !$this->ychanged[$yi]) {
+ $copy[] = $from_lines[$xi++];
+ ++$yi;
+ }
+ if ($copy)
+ $edits[] = new _DiffOp_Copy($copy);
+
+ // Find deletes & adds.
+ $delete = array();
+ while ($xi < $n_from && $this->xchanged[$xi])
+ $delete[] = $from_lines[$xi++];
+
+ $add = array();
+ while ($yi < $n_to && $this->ychanged[$yi])
+ $add[] = $to_lines[$yi++];
+
+ if ($delete && $add)
+ $edits[] = new _DiffOp_Change($delete, $add);
+ elseif ($delete)
+ $edits[] = new _DiffOp_Delete($delete);
+ elseif ($add)
+ $edits[] = new _DiffOp_Add($add);
+ }
+ return $edits;
+ }
+
+
+ /**
+ * Divide the Largest Common Subsequence (LCS) of the sequences
+ * [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
+ * sized segments.
+ *
+ * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an
+ * array of NCHUNKS+1 (X, Y) indexes giving the diving points between
+ * sub sequences. The first sub-sequence is contained in [X0, X1),
+ * [Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on. Note
+ * that (X0, Y0) == (XOFF, YOFF) and
+ * (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
+ *
+ * This function assumes that the first lines of the specified portions
+ * of the two files do not match, and likewise that the last lines do not
+ * match. The caller must trim matching lines from the beginning and end
+ * of the portions it is going to specify.
+ */
+ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) {
+ $flip = false;
+
+ if ($xlim - $xoff > $ylim - $yoff) {
+ // Things seems faster (I'm not sure I understand why)
+ // when the shortest sequence in X.
+ $flip = true;
+ list ($xoff, $xlim, $yoff, $ylim)
+ = array( $yoff, $ylim, $xoff, $xlim);
+ }
+
+ if ($flip)
+ for ($i = $ylim - 1; $i >= $yoff; $i--)
+ $ymatches[$this->xv[$i]][] = $i;
+ else
+ for ($i = $ylim - 1; $i >= $yoff; $i--)
+ $ymatches[$this->yv[$i]][] = $i;
+
+ $this->lcs = 0;
+ $this->seq[0]= $yoff - 1;
+ $this->in_seq = array();
+ $ymids[0] = array();
+
+ $numer = $xlim - $xoff + $nchunks - 1;
+ $x = $xoff;
+ for ($chunk = 0; $chunk < $nchunks; $chunk++) {
+ if ($chunk > 0)
+ for ($i = 0; $i <= $this->lcs; $i++)
+ $ymids[$i][$chunk-1] = $this->seq[$i];
+
+ $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks);
+ for ( ; $x < $x1; $x++) {
+ $line = $flip ? $this->yv[$x] : $this->xv[$x];
+ if (empty($ymatches[$line]))
+ continue;
+ $matches = $ymatches[$line];
+ reset($matches);
+ while (list ($junk, $y) = each($matches))
+ if (empty($this->in_seq[$y])) {
+ $k = $this->_lcs_pos($y);
+ USE_ASSERTS && assert($k > 0);
+ $ymids[$k] = $ymids[$k-1];
+ break;
+ }
+ while (list ($junk, $y) = each($matches)) {
+ if ($y > $this->seq[$k-1]) {
+ USE_ASSERTS && assert($y < $this->seq[$k]);
+ // Optimization: this is a common case:
+ // next match is just replacing previous match.
+ $this->in_seq[$this->seq[$k]] = false;
+ $this->seq[$k] = $y;
+ $this->in_seq[$y] = 1;
+ }
+ else if (empty($this->in_seq[$y])) {
+ $k = $this->_lcs_pos($y);
+ USE_ASSERTS && assert($k > 0);
+ $ymids[$k] = $ymids[$k-1];
+ }
+ }
+ }
+ }
+
+ $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
+ $ymid = $ymids[$this->lcs];
+ for ($n = 0; $n < $nchunks - 1; $n++) {
+ $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
+ $y1 = $ymid[$n] + 1;
+ $seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
+ }
+ $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
+
+ return array($this->lcs, $seps);
+ }
+
+ function _lcs_pos ($ypos) {
+ $end = $this->lcs;
+ if ($end == 0 || $ypos > $this->seq[$end]) {
+ $this->seq[++$this->lcs] = $ypos;
+ $this->in_seq[$ypos] = 1;
+ return $this->lcs;
+ }
+
+ $beg = 1;
+ while ($beg < $end) {
+ $mid = (int)(($beg + $end) / 2);
+ if ( $ypos > $this->seq[$mid] )
+ $beg = $mid + 1;
+ else
+ $end = $mid;
+ }
+
+ USE_ASSERTS && assert($ypos != $this->seq[$end]);
+
+ $this->in_seq[$this->seq[$end]] = false;
+ $this->seq[$end] = $ypos;
+ $this->in_seq[$ypos] = 1;
+ return $end;
+ }
+
+ /**
+ * Find LCS of two sequences.
+ *
+ * The results are recorded in the vectors $this->{x,y}changed[], by
+ * storing a 1 in the element for each line that is an insertion
+ * or deletion (ie. is not in the LCS).
+ *
+ * The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
+ *
+ * Note that XLIM, YLIM are exclusive bounds.
+ * All line numbers are origin-0 and discarded lines are not counted.
+ */
+ function _compareseq ($xoff, $xlim, $yoff, $ylim) {
+ // Slide down the bottom initial diagonal.
+ while ($xoff < $xlim && $yoff < $ylim
+ && $this->xv[$xoff] == $this->yv[$yoff]) {
+ ++$xoff;
+ ++$yoff;
+ }
+
+ // Slide up the top initial diagonal.
+ while ($xlim > $xoff && $ylim > $yoff
+ && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
+ --$xlim;
+ --$ylim;
+ }
+
+ if ($xoff == $xlim || $yoff == $ylim)
+ $lcs = 0;
+ else {
+ // This is ad hoc but seems to work well.
+ //$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
+ //$nchunks = max(2,min(8,(int)$nchunks));
+ $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1;
+ list ($lcs, $seps)
+ = $this->_diag($xoff,$xlim,$yoff, $ylim,$nchunks);
+ }
+
+ if ($lcs == 0) {
+ // X and Y sequences have no common subsequence:
+ // mark all changed.
+ while ($yoff < $ylim)
+ $this->ychanged[$this->yind[$yoff++]] = 1;
+ while ($xoff < $xlim)
+ $this->xchanged[$this->xind[$xoff++]] = 1;
+ }
+ else {
+ // Use the partitions to split this problem into subproblems.
+ reset($seps);
+ $pt1 = $seps[0];
+ while ($pt2 = next($seps)) {
+ $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
+ $pt1 = $pt2;
+ }
+ }
+ }
+
+ /**
+ * Adjust inserts/deletes of identical lines to join changes
+ * as much as possible.
+ *
+ * We do something when a run of changed lines include a
+ * line at one end and has an excluded, identical line at the other.
+ * We are free to choose which identical line is included.
+ * `compareseq' usually chooses the one at the beginning,
+ * but usually it is cleaner to consider the following identical line
+ * to be the "change".
+ *
+ * This is extracted verbatim from analyze.c (GNU diffutils-2.7).
+ */
+ function _shift_boundaries ($lines, &$changed, $other_changed) {
+ $i = 0;
+ $j = 0;
+
+ USE_ASSERTS && assert('sizeof($lines) == sizeof($changed)');
+ $len = sizeof($lines);
+ $other_len = sizeof($other_changed);
+
+ while (1) {
+ /*
+ * Scan forwards to find beginning of another run of changes.
+ * Also keep track of the corresponding point in the other file.
+ *
+ * Throughout this code, $i and $j are adjusted together so that
+ * the first $i elements of $changed and the first $j elements
+ * of $other_changed both contain the same number of zeros
+ * (unchanged lines).
+ * Furthermore, $j is always kept so that $j == $other_len or
+ * $other_changed[$j] == false.
+ */
+ while ($j < $other_len && $other_changed[$j])
+ $j++;
+
+ while ($i < $len && ! $changed[$i]) {
+ USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
+ $i++; $j++;
+ while ($j < $other_len && $other_changed[$j])
+ $j++;
+ }
+
+ if ($i == $len)
+ break;
+
+ $start = $i;
+
+ // Find the end of this run of changes.
+ while (++$i < $len && $changed[$i])
+ continue;
+
+ do {
+ /*
+ * Record the length of this run of changes, so that
+ * we can later determine whether the run has grown.
+ */
+ $runlength = $i - $start;
+
+ /*
+ * Move the changed region back, so long as the
+ * previous unchanged line matches the last changed one.
+ * This merges with previous changed regions.
+ */
+ while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) {
+ $changed[--$start] = 1;
+ $changed[--$i] = false;
+ while ($start > 0 && $changed[$start - 1])
+ $start--;
+ USE_ASSERTS && assert('$j > 0');
+ while ($other_changed[--$j])
+ continue;
+ USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
+ }
+
+ /*
+ * Set CORRESPONDING to the end of the changed run, at the last
+ * point where it corresponds to a changed run in the other file.
+ * CORRESPONDING == LEN means no such point has been found.
+ */
+ $corresponding = $j < $other_len ? $i : $len;
+
+ /*
+ * Move the changed region forward, so long as the
+ * first changed line matches the following unchanged one.
+ * This merges with following changed regions.
+ * Do this second, so that if there are no merges,
+ * the changed region is moved forward as far as possible.
+ */
+ while ($i < $len && $lines[$start] == $lines[$i]) {
+ $changed[$start++] = false;
+ $changed[$i++] = 1;
+ while ($i < $len && $changed[$i])
+ $i++;
+
+ USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
+ $j++;
+ if ($j < $other_len && $other_changed[$j]) {
+ $corresponding = $i;
+ while ($j < $other_len && $other_changed[$j])
+ $j++;
+ }
+ }
+ } while ($runlength != $i - $start);
+
+ /*
+ * If possible, move the fully-merged run of changes
+ * back to a corresponding run in the other file.
+ */
+ while ($corresponding < $i) {
+ $changed[--$start] = 1;
+ $changed[--$i] = 0;
+ USE_ASSERTS && assert('$j > 0');
+ while ($other_changed[--$j])
+ continue;
+ USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
+ }
+ }
+ }
+}
+
+/**
+ * Class representing a 'diff' between two sequences of strings.
+ */
+class Diff
+{
+ var $edits;
+
+ /**
+ * Constructor.
+ * Computes diff between sequences of strings.
+ *
+ * @param $from_lines array An array of strings.
+ * (Typically these are lines from a file.)
+ * @param $to_lines array An array of strings.
+ */
+ function Diff($from_lines, $to_lines) {
+ $eng = new _DiffEngine;
+ $this->edits = $eng->diff($from_lines, $to_lines);
+ //$this->_check($from_lines, $to_lines);
+ }
+
+ /**
+ * Compute reversed Diff.
+ *
+ * SYNOPSIS:
+ *
+ * $diff = new Diff($lines1, $lines2);
+ * $rev = $diff->reverse();
+ * @return object A Diff object representing the inverse of the
+ * original diff.
+ */
+ function reverse () {
+ $rev = $this;
+ $rev->edits = array();
+ foreach ($this->edits as $edit) {
+ $rev->edits[] = $edit->reverse();
+ }
+ return $rev;
+ }
+
+ /**
+ * Check for empty diff.
+ *
+ * @return bool True iff two sequences were identical.
+ */
+ function isEmpty () {
+ foreach ($this->edits as $edit) {
+ if ($edit->type != 'copy')
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Compute the length of the Longest Common Subsequence (LCS).
+ *
+ * This is mostly for diagnostic purposed.
+ *
+ * @return int The length of the LCS.
+ */
+ function lcs () {
+ $lcs = 0;
+ foreach ($this->edits as $edit) {
+ if ($edit->type == 'copy')
+ $lcs += sizeof($edit->orig);
+ }
+ return $lcs;
+ }
+
+ /**
+ * Get the original set of lines.
+ *
+ * This reconstructs the $from_lines parameter passed to the
+ * constructor.
+ *
+ * @return array The original sequence of strings.
+ */
+ function orig() {
+ $lines = array();
+
+ foreach ($this->edits as $edit) {
+ if ($edit->orig)
+ array_splice($lines, sizeof($lines), 0, $edit->orig);
+ }
+ return $lines;
+ }
+
+ /**
+ * Get the closing set of lines.
+ *
+ * This reconstructs the $to_lines parameter passed to the
+ * constructor.
+ *
+ * @return array The sequence of strings.
+ */
+ function closing() {
+ $lines = array();
+
+ foreach ($this->edits as $edit) {
+ if ($edit->closing)
+ array_splice($lines, sizeof($lines), 0, $edit->closing);
+ }
+ return $lines;
+ }
+
+ /**
+ * Check a Diff for validity.
+ *
+ * This is here only for debugging purposes.
+ */
+ function _check ($from_lines, $to_lines) {
+ if (serialize($from_lines) != serialize($this->orig()))
+ trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
+ if (serialize($to_lines) != serialize($this->closing()))
+ trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
+
+ $rev = $this->reverse();
+ if (serialize($to_lines) != serialize($rev->orig()))
+ trigger_error("Reversed original doesn't match", E_USER_ERROR);
+ if (serialize($from_lines) != serialize($rev->closing()))
+ trigger_error("Reversed closing doesn't match", E_USER_ERROR);
+
+
+ $prevtype = 'none';
+ foreach ($this->edits as $edit) {
+ if ( $prevtype == $edit->type )
+ trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
+ $prevtype = $edit->type;
+ }
+
+ $lcs = $this->lcs();
+ trigger_error("Diff okay: LCS = $lcs", E_USER_NOTICE);
+ }
+}
+
+/**
+ * FIXME: bad name.
+ */
+class MappedDiff
+extends Diff
+{
+ /**
+ * Constructor.
+ *
+ * Computes diff between sequences of strings.
+ *
+ * This can be used to compute things like
+ * case-insensitve diffs, or diffs which ignore
+ * changes in white-space.
+ *
+ * @param $from_lines array An array of strings.
+ * (Typically these are lines from a file.)
+ *
+ * @param $to_lines array An array of strings.
+ *
+ * @param $mapped_from_lines array This array should
+ * have the same size number of elements as $from_lines.
+ * The elements in $mapped_from_lines and
+ * $mapped_to_lines are what is actually compared
+ * when computing the diff.
+ *
+ * @param $mapped_to_lines array This array should
+ * have the same number of elements as $to_lines.
+ */
+ function MappedDiff($from_lines, $to_lines,
+ $mapped_from_lines, $mapped_to_lines) {
+
+ assert(sizeof($from_lines) == sizeof($mapped_from_lines));
+ assert(sizeof($to_lines) == sizeof($mapped_to_lines));
+
+ $this->Diff($mapped_from_lines, $mapped_to_lines);
+
+ $xi = $yi = 0;
+ for ($i = 0; $i < sizeof($this->edits); $i++) {
+ $orig = &$this->edits[$i]->orig;
+ if (is_array($orig)) {
+ $orig = array_slice($from_lines, $xi, sizeof($orig));
+ $xi += sizeof($orig);
+ }
+
+ $closing = &$this->edits[$i]->closing;
+ if (is_array($closing)) {
+ $closing = array_slice($to_lines, $yi, sizeof($closing));
+ $yi += sizeof($closing);
+ }
+ }
+ }
+}
+
+/**
+ * A class to format Diffs
+ *
+ * This class formats the diff in classic diff format.
+ * It is intended that this class be customized via inheritance,
+ * to obtain fancier outputs.
+ */
+class DiffFormatter
+{
+ /**
+ * Number of leading context "lines" to preserve.
+ *
+ * This should be left at zero for this class, but subclasses
+ * may want to set this to other values.
+ */
+ var $leading_context_lines = 0;
+
+ /**
+ * Number of trailing context "lines" to preserve.
+ *
+ * This should be left at zero for this class, but subclasses
+ * may want to set this to other values.
+ */
+ var $trailing_context_lines = 0;
+
+ /**
+ * Format a diff.
+ *
+ * @param $diff object A Diff object.
+ * @return string The formatted output.
+ */
+ function format($diff) {
+
+ $xi = $yi = 1;
+ $block = false;
+ $context = array();
+
+ $nlead = $this->leading_context_lines;
+ $ntrail = $this->trailing_context_lines;
+
+ $this->_start_diff();
+
+ foreach ($diff->edits as $edit) {
+ if ($edit->type == 'copy') {
+ if (is_array($block)) {
+ if (sizeof($edit->orig) <= $nlead + $ntrail) {
+ $block[] = $edit;
+ }
+ else{
+ if ($ntrail) {
+ $context = array_slice($edit->orig, 0, $ntrail);
+ $block[] = new _DiffOp_Copy($context);
+ }
+ $this->_block($x0, $ntrail + $xi - $x0,
+ $y0, $ntrail + $yi - $y0,
+ $block);
+ $block = false;
+ }
+ }
+ $context = $edit->orig;
+ }
+ else {
+ if (! is_array($block)) {
+ $context = array_slice($context, sizeof($context) - $nlead);
+ $x0 = $xi - sizeof($context);
+ $y0 = $yi - sizeof($context);
+ $block = array();
+ if ($context)
+ $block[] = new _DiffOp_Copy($context);
+ }
+ $block[] = $edit;
+ }
+
+ if ($edit->orig)
+ $xi += sizeof($edit->orig);
+ if ($edit->closing)
+ $yi += sizeof($edit->closing);
+ }
+
+ if (is_array($block))
+ $this->_block($x0, $xi - $x0,
+ $y0, $yi - $y0,
+ $block);
+
+ return $this->_end_diff();
+ }
+
+ function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) {
+ $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen));
+ foreach ($edits as $edit) {
+ if ($edit->type == 'copy')
+ $this->_context($edit->orig);
+ elseif ($edit->type == 'add')
+ $this->_added($edit->closing);
+ elseif ($edit->type == 'delete')
+ $this->_deleted($edit->orig);
+ elseif ($edit->type == 'change')
+ $this->_changed($edit->orig, $edit->closing);
+ else
+ trigger_error("Unknown edit type", E_USER_ERROR);
+ }
+ $this->_end_block();
+ }
+
+ function _start_diff() {
+ ob_start();
+ }
+
+ function _end_diff() {
+ $val = ob_get_contents();
+ ob_end_clean();
+ return $val;
+ }
+
+ function _block_header($xbeg, $xlen, $ybeg, $ylen) {
+ if ($xlen > 1)
+ $xbeg .= "," . ($xbeg + $xlen - 1);
+ if ($ylen > 1)
+ $ybeg .= "," . ($ybeg + $ylen - 1);
+
+ return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
+ }
+
+ function _start_block($header) {
+ echo $header;
+ }
+
+ function _end_block() {
+ }
+
+ function _lines($lines, $prefix = ' ') {
+ foreach ($lines as $line)
+ echo "$prefix $line\n";
+ }
+
+ function _context($lines) {
+ $this->_lines($lines);
+ }
+
+ function _added($lines) {
+ $this->_lines($lines, ">");
+ }
+ function _deleted($lines) {
+ $this->_lines($lines, "<");
+ }
+
+ function _changed($orig, $closing) {
+ $this->_deleted($orig);
+ echo "---\n";
+ $this->_added($closing);
+ }
+}
+
+
+/**
+ * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
+ *
+ */
+
+define('NBSP', "\xC2\xA0"); // utf-8 non-breaking space.
+
+class _HWLDF_WordAccumulator {
+ function _HWLDF_WordAccumulator () {
+ $this->_lines = array();
+ $this->_line = '';
+ $this->_group = '';
+ $this->_tag = '';
+ }
+
+ function _flushGroup ($new_tag) {
+ if ($this->_group !== '') {
+ if ($this->_tag == 'mark')
+ $this->_line .= '<strong>'.$this->_group.'</strong>';
+ else
+ $this->_line .= $this->_group;
+ }
+ $this->_group = '';
+ $this->_tag = $new_tag;
+ }
+
+ function _flushLine ($new_tag) {
+ $this->_flushGroup($new_tag);
+ if ($this->_line != '')
+ $this->_lines[] = $this->_line;
+ $this->_line = '';
+ }
+
+ function addWords ($words, $tag = '') {
+ if ($tag != $this->_tag)
+ $this->_flushGroup($tag);
+
+ foreach ($words as $word) {
+ // new-line should only come as first char of word.
+ if ($word == '')
+ continue;
+ if ($word[0] == "\n") {
+ $this->_group .= NBSP;
+ $this->_flushLine($tag);
+ $word = substr($word, 1);
+ }
+ assert(!strstr($word, "\n"));
+ $this->_group .= $word;
+ }
+ }
+
+ function getLines() {
+ $this->_flushLine('~done');
+ return $this->_lines;
+ }
+}
+
+class WordLevelDiff extends MappedDiff
+{
+ function WordLevelDiff ($orig_lines, $closing_lines) {
+ list ($orig_words, $orig_stripped) = $this->_split($orig_lines);
+ list ($closing_words, $closing_stripped) = $this->_split($closing_lines);
+
+
+ $this->MappedDiff($orig_words, $closing_words,
+ $orig_stripped, $closing_stripped);
+ }
+
+ function _split($lines) {
+ // FIXME: fix POSIX char class.
+# if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
+ if (!preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
+ implode("\n", $lines),
+ $m)) {
+ return array(array(''), array(''));
+ }
+ return array($m[0], $m[1]);
+ }
+
+ function orig () {
+ $orig = new _HWLDF_WordAccumulator;
+
+ foreach ($this->edits as $edit) {
+ if ($edit->type == 'copy')
+ $orig->addWords($edit->orig);
+ elseif ($edit->orig)
+ $orig->addWords($edit->orig, 'mark');
+ }
+ return $orig->getLines();
+ }
+
+ function closing () {
+ $closing = new _HWLDF_WordAccumulator;
+
+ foreach ($this->edits as $edit) {
+ if ($edit->type == 'copy')
+ $closing->addWords($edit->closing);
+ elseif ($edit->closing)
+ $closing->addWords($edit->closing, 'mark');
+ }
+ return $closing->getLines();
+ }
+}
+
+/**
+ * "Unified" diff formatter.
+ *
+ * This class formats the diff in classic "unified diff" format.
+ */
+class UnifiedDiffFormatter extends DiffFormatter
+{
+ function UnifiedDiffFormatter($context_lines = 4) {
+ $this->leading_context_lines = $context_lines;
+ $this->trailing_context_lines = $context_lines;
+ }
+
+ function _block_header($xbeg, $xlen, $ybeg, $ylen) {
+ if ($xlen != 1)
+ $xbeg .= "," . $xlen;
+ if ($ylen != 1)
+ $ybeg .= "," . $ylen;
+ return "@@ -$xbeg +$ybeg @@\n";
+ }
+
+ function _added($lines) {
+ $this->_lines($lines, "+");
+ }
+ function _deleted($lines) {
+ $this->_lines($lines, "-");
+ }
+ function _changed($orig, $final) {
+ $this->_deleted($orig);
+ $this->_added($final);
+ }
+}
+
+/**
+ * Wikipedia Table style diff formatter.
+ *
+ */
+class TableDiffFormatter extends DiffFormatter
+{
+ function TableDiffFormatter() {
+ $this->leading_context_lines = 2;
+ $this->trailing_context_lines = 2;
+ }
+
+ function _pre($text){
+ $text = htmlspecialchars($text);
+ $text = str_replace(' ',' ',$text);
+ return $text;
+ }
+
+ function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
+ global $lang;
+ $l1 = $lang['line'].' '.$xbeg;
+ $l2 = $lang['line'].' '.$ybeg;
+ $r = '<tr><td class="diff-blockheader" colspan="2">'.$l1.":</td>\n" .
+ '<td class="diff-blockheader" colspan="2">'.$l2.":</td></tr>\n";
+ return $r;
+ }
+
+ function _start_block( $header ) {
+ print( $header );
+ }
+
+ function _end_block() {
+ }
+
+ function _lines( $lines, $prefix=' ', $color="white" ) {
+ }
+
+ function addedLine( $line ) {
+ $line = str_replace(' ',' ',$line);
+ return '<td>+</td><td class="diff-addedline">' .
+ $line.'</td>';
+ }
+
+ function deletedLine( $line ) {
+ $line = str_replace(' ',' ',$line);
+ return '<td>-</td><td class="diff-deletedline">' .
+ $line.'</td>';
+ }
+
+ function emptyLine() {
+ //$line = str_replace(' ',' ',$line);
+ return '<td colspan="2"> </td>';
+ }
+
+ function contextLine( $line ) {
+ $line = str_replace(' ',' ',$line);
+ return '<td> </td><td class="diff-context">'.$line.'</td>';
+ }
+
+ function _added($lines) {
+ foreach ($lines as $line) {
+ print( '<tr>' . $this->emptyLine() .
+ $this->addedLine( $line ) . "</tr>\n" );
+ }
+ }
+
+ function _deleted($lines) {
+ foreach ($lines as $line) {
+ print( '<tr>' . $this->deletedLine( $line ) .
+ $this->emptyLine() . "</tr>\n" );
+ }
+ }
+
+ function _context( $lines ) {
+ foreach ($lines as $line) {
+ print( '<tr>' . $this->contextLine( $line ) .
+ $this->contextLine( $line ) . "</tr>\n" );
+ }
+ }
+
+ function _changed( $orig, $closing ) {
+ $diff = new WordLevelDiff( $orig, $closing );
+ $del = $diff->orig();
+ $add = $diff->closing();
+
+ while ( $line = array_shift( $del ) ) {
+ $aline = array_shift( $add );
+ print( '<tr>' . $this->deletedLine( $line ) .
+ $this->addedLine( $aline ) . "</tr>\n" );
+ }
+ $this->_added( $add ); # If any leftovers
+ }
+}
+
+
+//Setup VIM: ex: et ts=2 enc=utf-8 :
Added: branches/print_dev/http/img/asc.gif
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/asc.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/bg.gif
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/bg.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/button_digitize/punchPolygon_off.png
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/button_digitize/punchPolygon_off.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/button_digitize/punchPolygon_on.png
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/button_digitize/punchPolygon_on.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/button_digitize/punchPolygon_over.png
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/button_digitize/punchPolygon_over.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/desc.gif
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/desc.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/digitize.png
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/digitize.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/img/map.png
===================================================================
(Binary files differ)
Property changes on: branches/print_dev/http/img/map.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/print_dev/http/javascripts/mod_tooltip.php
===================================================================
--- branches/print_dev/http/javascripts/mod_tooltip.php (rev 0)
+++ branches/print_dev/http/javascripts/mod_tooltip.php 2009-03-09 09:08:08 UTC (rev 3649)
@@ -0,0 +1,367 @@
+<?php
+# $Id: mod_toggleModule.php 2238 2008-03-13 14:24:56Z christoph $
+# http://www.mapbender.org/index.php/mod_toggleModule.php
+# Copyright (C) 2002 CCGIS
+#
+# This program 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 2, or (at your option)
+# any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+
+$wfs_conf_filename = "wfs_default.conf";
+include '../include/dyn_php.php';
+$fname = dirname(__FILE__) . "/../../conf/" . $wfs_conf_filename;
+if (file_exists($fname)) {
+ include($fname);
+}
+else {
+ $e = new mb_exception("tooltip.php: Configuration file " . $wfs_conf_filename . " not found.");
+}
+
+echo "var tooltipTarget ='".$e_target[0]."';";
+
+include '../include/dyn_js.php';
+?>
+//tolerance when we ask wfs
+var mb_wfs_tolerance = 8;
+
+//initialize Element Vars
+
+//destination frame for the request (creates Popup if empty)
+if(typeof(tooltip_destinationFrame)==='undefined')
+ var tooltip_destinationFrame = "";
+if(typeof(tooltip_timeDelay)==='undefined')
+ var tooltip_timeDelay = 1000;
+if(typeof(tooltip_styles)==='undefined')
+ var tooltip_styles = "";
+if(typeof(tooltip_width)==='undefined')
+ var tooltip_width = 270;
+if(typeof(tooltip_height)==='undefined')
+ var tooltip_height = 200;
+if(typeof(tooltip_styles_detail)==='undefined')
+ var tooltip_styles_detail = "";
+try{
+ var no_result_text = eval(tooltip_noResultArray);
+}catch(e){
+ var no_result_text = ["Kein Ergebnis.",'<body onLoad="javascript:window.close()">'];
+}
+var mouseMoves=0;
+var tooltipWin=null;
+var point;
+var tooltipWfsRequestCount = 0;
+var tooltipWmsRequestCount = 0;
+var numberOfFinishedWfsRequests = 0;
+var numberOfFinishedWmsRequests = 0;
+var visibleRequest = 0;
+var TooltipMsg = {'title':"<?php echo _mb("Information");?>"};
+
+//buttonWfs_toDigitize_on ="0";
+
+function mod_tooltipInit(){
+var tooltip_map = getMapObjByName(tooltipTarget);
+var ind = getMapObjIndexByName(tooltipTarget);
+var myMapObj = mb_mapObj[ind];
+
+var map_el = myMapObj.getDomElement();
+
+ $(map_el.ownerDocument).mousemove(function(event){
+ var point = tooltip_map.getMousePos(event);
+ //mb_getMousePos(event,myMapObj.getMousePosition(event));
+ mod_tooltip_run();
+ }).mouseout(function(){mouseMoves=0;});
+}
+
+eventInit.register(mod_tooltipInit);
+
+function mod_tooltip_run(){
+ mouseMoves++;
+ setTimeout("if(mouseMoves=="+mouseMoves+"&&clickX=="+clickX+"&&clickY=="+clickY+")fireRequests();",tooltip_timeDelay);
+}
+
+function fireRequests(){
+ var ind = getMapObjIndexByName(tooltipTarget);
+ point = new Point(clickX,clickY);
+ var point_geom = new Geometry(geomType.point);
+ point_geom.addPoint(mapToReal(tooltipTarget,point));
+ visibleRequest = 0;
+
+ //FeatureInfo requests
+ urls = mb_mapObj[ind].getFeatureInfoRequests(point);
+ tooltipWmsRequestCount = urls.length;
+ numberOfFinishedWmsRequests = 0;
+ for(var j=0;j < urls.length;j++){
+ mb_ajax_post("../extensions/ext_featureInfoTunnel.php", {url:urls[j]},
+ checkFeatureInfoResults);
+ }
+
+ //WFS requests
+ requests = getWfsRequests(tooltipTarget, point_geom, true);
+ tooltipWfsRequestCount = requests.length;
+ numberOfFinishedWfsRequests = 0;
+ resultGeomArray = new GeometryArray();
+ for(var j=0;j< requests.length;j++){
+ mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,requests[j],function(js_code,status){
+ if (js_code) {
+ eval(js_code);
+ }
+ if (typeof(geom) == "undefined") {
+ var geom = new GeometryArray();
+ }
+ checkWfsResultsFinished(geom);
+ });
+ }
+}
+
+function checkFeatureInfoResults(js_code,status){
+ numberOfFinishedWmsRequests++;
+
+ //check if there are results
+ if(js_code == ""){
+ if(!isFirstResult())
+ displayResultDoc("");
+ return;
+ }
+
+ for(var k=0;k < no_result_text.length;k++){
+ if(js_code.indexOf(no_result_text[k])!==-1){
+ if(!isFirstResult())
+ displayResultDoc("");
+ return;
+ }
+ }
+
+ //output code
+ displayResultDoc(js_code);
+}
+
+function checkWfsResultsFinished(g){
+ //check if all wfs requests arrived
+ numberOfFinishedWfsRequests++;
+ if (typeof(g) == 'object'){
+ resultGeomArray.union(g);
+ }
+ if (numberOfFinishedWfsRequests == tooltipWfsRequestCount) {
+ if(resultGeomArray.count()>0){
+ //generate and output result
+ if(resultGeomArray.count()>1)
+ var html = createSimpleWfsResultHtml(resultGeomArray);
+ else
+ var html = createDetailedWfsResultHtml(resultGeomArray);
+ displayResultDoc(html);
+ }
+ else if(!isFirstResult())
+ displayResultDoc("");
+ }
+}
+
+function isFirstResult(){
+ return visibleRequest == 0;
+}
+
+function isLastResult(){
+ return (numberOfFinishedWfsRequests == tooltipWfsRequestCount && numberOfFinishedWmsRequests == tooltipWmsRequestCount);
+}
+
+function displayResultDoc(html){
+ //test if we have a fixed destination and create popup otherwise
+ if(tooltip_destinationFrame=="")
+ return showBalloonFrame(html);
+
+ //put the frame there
+ $("#"+tooltip_destinationFrame).each(function(){
+ var oDoc = this.contentWindow || this.contentDocument;
+ if (oDoc.document) {
+ oDoc = oDoc.document;
+ }
+ if(isFirstResult())
+ oDoc.open();
+ oDoc.write(html);
+ if(isLastResult())
+ oDoc.close();
+ });
+ visibleRequest++;
+}
+
+function showBalloonFrame(html){
+ if(isFirstResult()){
+ //claculate Position
+ x=point.x+parseInt(document.getElementById(tooltipTarget).style.left);
+ y=point.y+parseInt(document.getElementById(tooltipTarget).style.top);
+
+ //hide old Popup
+ if(tooltipWin&&tooltipWin.isVisible())
+ tooltipWin.destroy();
+
+ //create Popup and append document
+ tooltipWin = new mb_popup({html:'<iframe id="tooltipWin" name="tooltipWin" src="about:blank"/>',title:TooltipMsg.title,width:tooltip_width,height:tooltip_height,balloon:true,left:x,top:y});
+ //open document
+ tooltipWin.open();
+ }
+ tooltipWin.write(html);
+
+ if(isLastResult()){
+ tooltipWin.close();
+ }
+
+ //finally display popup
+ tooltipWin.show();
+}
+
+function getWfsRequests(target, geom, checkscale, filteroption){
+ //get all configurations
+ wfs_config = get_complete_wfs_conf();
+ var ind = getMapObjIndexByName(target);
+ var db_wfs_conf_id = [];
+ var js_wfs_conf_id = [];
+
+ //search configurations that are selected (and in scale)
+ for (var i=0; i < mb_mapObj[ind].wms.length; i++){
+ for(var ii=0; ii < mb_mapObj[ind].wms[i].objLayer.length; ii++){
+ var o = mb_mapObj[ind].wms[i].objLayer[ii];
+ if(o.gui_layer_wfs_featuretype != '' && o.gui_layer_querylayer == '1'){
+ if(!checkscale || o.checkScale(mb_mapObj[ind]))
+ db_wfs_conf_id[db_wfs_conf_id.length] = o.gui_layer_wfs_featuretype;
+ }
+ }
+ }
+ for(var i=0; i < db_wfs_conf_id.length; i++){
+ for(var ii=0; ii < wfs_config.length; ii++){
+ if(wfs_config[ii]['wfs_conf_id'] == db_wfs_conf_id[i]){
+ js_wfs_conf_id[js_wfs_conf_id.length] = ii;
+ break;
+ }
+ }
+ }
+
+ //build requests
+ var requests = [];
+
+ for(var i=0;i < js_wfs_conf_id.length; i++){
+ //build url
+ var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
+ url += mb_getConjunctionCharacter(wfs_config[js_wfs_conf_id[i]]['wfs_getfeature']);
+ url += "service=wfs&request=getFeature&version=1.0.0";
+ url += "&typename="+ wfs_config[js_wfs_conf_id[i]]['featuretype_name'];
+ url += "&filter=";
+
+ //search for geometry column
+ var geometryCol;
+ for(var j=0; j < wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+ if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+ geometryCol = wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
+ }
+ }
+
+ //get filter
+ var filter = new WfsFilter();
+ filter.addSpatial(geom, geometryCol, filteroption, wfs_config[js_wfs_conf_id[i]]['featuretype_srs'], target);
+
+ requests.push({'url':url,'filter':filter.toString(), 'typename':wfs_config[js_wfs_conf_id[i]]['featuretype_name'],'js_wfs_conf_id':js_wfs_conf_id[i], 'db_wfs_conf_id':db_wfs_conf_id[i]});
+ }
+
+ return requests;
+}
+
+function createSimpleWfsResultHtml(_geomArray){
+ var geometryIndex = 0;
+ wfsConf = get_complete_wfs_conf();
+ var html = '<html><head><style type="text/css">';
+ html += tooltip_styles;
+ html += "</style></head><body><table>\n";
+
+ for (var i = 0 ; i < _geomArray.count(); i ++) {
+ if (_geomArray.get(i).get(-1).isComplete()) {
+ html += "\t<tr class='list_"+(i%2?"uneven":"even")+"'>\n\t\t<td \n";
+// html += "\t\t\t onmouseover='mb_wfs_perform(\"over\",_geomArray.get("+i+"));' ";
+// html += " onmouseout='mb_wfs_perform(\"out\",_geomArray.get("+i+"))' ";
+// html += " onclick='mb_wfs_perform(\"click\",_geomArray.get("+i+"));' ";
+ var geomName = getWfsListEntry(_geomArray.get(i));
+ html += ">" + geomName +"</td>";
+ html += "\t\t</tr>\n";
+ }
+ }
+
+ html += "</table></body>\n";
+ return html;
+}
+
+function createDetailedWfsResultHtml(_geomArray){
+ var geometryIndex = 0;
+ var cnt = 0;
+ wfsConf = get_complete_wfs_conf();
+ var html = '<html><head><style type="text/css">';
+ html += tooltip_styles_detail;
+ html += "</style></head><body><table>\n";
+
+ var wfsConfIndex = _geomArray.get(geometryIndex).wfs_conf;
+ var currentWfsConf = wfsConf[wfsConfIndex];
+ for (var i = 0 ; i <currentWfsConf.element.length; i ++) {
+ if(currentWfsConf.element[i].f_show_detail==1){
+ if( _geomArray.get(geometryIndex).e.getElementValueByName(currentWfsConf.element[i].element_name)!=false){
+ html +="<tr class='list_"+(cnt%2?"uneven":"even")+"'><td>\n";
+ html += currentWfsConf.element[i].f_label;
+ html +="</td>\n";
+ html += "<td>\n";
+ var elementVal = _geomArray.get(geometryIndex).e.getElementValueByName(currentWfsConf.element[i].element_name);
+ if(currentWfsConf.element[i].f_form_element_html.indexOf("href")!=-1){
+ var setUrl = currentWfsConf.element[i].f_form_element_html.replace(/href\s*=\s*['|"]\s*['|"]/, "href='"+elementVal+"' target='_blank'");
+ if(setUrl.match(/><\/a>/)){
+ var newLink = setUrl.replace(/><\/a>/, ">"+elementVal+"</a>");
+ }
+ else{
+ var newLink = setUrl;
+ }
+ html += newLink;
+ }
+ else{
+ html += elementVal;
+ }
+ html += "</td></tr>\n";
+ cnt++;
+ }
+ }
+ }
+
+ html += "</table></body>\n";
+ return html;
+}
+
+
+function getWfsListEntry (geom) {
+ wfsConfId = geom.wfs_conf;
+ wfsConf = window.frames["wfs_conf"].get_wfs_conf();
+ if (typeof(wfsConfId) == "number" && wfsConfId >=0 && wfsConfId < wfsConf.length) {
+ var resultArray = [];
+ for (var i = 0 ; i < wfsConf[wfsConfId]['element'].length ; i++) {
+ if (wfsConf[wfsConfId]['element'][i]['f_show'] == 1 && geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']) !=false) {
+ var pos = wfsConf[wfsConfId]['element'][i]['f_respos'];
+ if (typeof(resultArray[pos]) != "undefined") {
+ resultArray[pos] += " " + geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']);
+ }
+ else {
+ resultArray[pos] = geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']);
+ }
+ }
+ }
+ var resultName = resultArray.join(" ");
+ if (resultName == "") {
+ resultName = wfsConf[wfsConfId]['g_label'];
+ }
+ return resultName;
+ }
+ else {
+ return false;
+ }
+}
+
Added: branches/print_dev/http/javascripts/wfsFilter.js
===================================================================
--- branches/print_dev/http/javascripts/wfsFilter.js (rev 0)
+++ branches/print_dev/http/javascripts/wfsFilter.js 2009-03-09 09:08:08 UTC (rev 3649)
@@ -0,0 +1,236 @@
+function WfsFilter () {
+
+ this.operators = [
+ {
+ "operator":"==",
+ "wfsOpenTag":"PropertyIsEqualTo",
+ "wfsCloseTag":"PropertyIsEqualTo"
+ },
+ {
+ "operator":">=",
+ "wfsOpenTag":"PropertyIsGreaterThanOrEqualTo",
+ "wfsCloseTag":"PropertyIsGreaterThanOrEqualTo"
+ },
+ {
+ "operator":"<=",
+ "wfsOpenTag":"PropertyIsLessThanOrEqualTo",
+ "wfsCloseTag":"PropertyIsLessThanOrEqualTo"
+ },
+ {
+ "operator":">>",
+ "wfsOpenTag":"PropertyIsGreaterThan",
+ "wfsCloseTag":"PropertyIsGreaterThan"
+ },
+ {
+ "operator":"<<",
+ "wfsOpenTag":"PropertyIsLessThan",
+ "wfsCloseTag":"PropertyIsLessThan"
+ },
+ {
+ "operator":"<>",
+ "wfsOpenTag":"PropertyIsNotEqualTo",
+ "wfsCloseTag":"PropertyIsNotEqualTo"
+ },
+ {
+ "operator":"LIKE",
+ "wfsOpenTag":"PropertyIsLike wildCard='*' singleChar='.' escape='!'",
+ "wfsCloseTag":"PropertyIsLike"
+ }
+ ];
+
+ var conditionToString = function (condition, operator){
+ var splitParam = condition.split(operator);
+ var columnName = trim(splitParam[0]);
+ var columnValue = trim(splitParam[1]);
+
+/*
+ if (operator == 'LIKE') {
+ columnValue = "*"+ columnValue +"*";
+ }
+*/
+ for (var i = 0 ; i < that.operators.length ; i++) {
+ if (that.operators[i].operator == operator){
+
+ // add condition: Property
+ var condString = '<'+that.operators[i].wfsOpenTag+'>' +
+ '<PropertyName>'+columnName+'</PropertyName>' +
+ '<Literal>'+columnValue+'</Literal>' +
+ '</'+that.operators[i].wfsCloseTag+'>';
+
+/*
+ // add condition: Property is not null
+ '<ogc:Not><ogc:PropertyIsNull>' +
+ '<ogc:PropertyName>'+columnName+'</ogc:PropertyName>' +
+ '</ogc:PropertyIsNull></ogc:Not>';
+*/
+ return condString;
+ }
+ }
+ return "";
+ };
+
+ var getOperatorFromCondition = function (aCondition) {
+ for (var j = 0; j < that.operators.length; j++) {
+ if (aCondition.match(that.operators[j].operator)) {
+ return that.operators[j].operator;
+ }
+ }
+ return false;
+ };
+
+ /**
+ * parse the filter from the HTML form,
+ *
+ * @param {String} filter like "[usertype]<>3 AND [firstname]==Emil"
+ */
+ this.parse = function (filter) {
+ if (filter !== '') {
+
+ filter = filter.replace(/\[/g,"");
+ filter = filter.replace(/\]/g,"");
+ var condArray = filter.split(' AND ');
+ var wfsCond = [];
+ for (var i = 0 ; i < condArray.length ; i++) {
+ var currentOperator = getOperatorFromCondition(condArray[i]);
+ if (!currentOperator) {
+ return false;
+ }
+ wfsCond.push(conditionToString(condArray[i], currentOperator));
+ }
+ conditionArray = conditionArray.concat(wfsCond);
+ }
+ return true;
+ };
+
+ this.addSpatial = function (spatialRequestGeom, geometryColumn, filteroption, srs, target) {
+ if(typeof(spatialRequestGeom) != "undefined"){
+ var spatialRequestFilter = "";
+ if(spatialRequestGeom.geomType == geomType.polygon){
+ spatialRequestFilter += "<" + filteroption + "><ogc:PropertyName>" +
+ geometryColumn + "</ogc:PropertyName><gml:Polygon srsName=\""+srs+"\">" +
+ "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+ for(var k=0; k<spatialRequestGeom.count(); k++){
+ if (k > 0) {
+ spatialRequestFilter += " ";
+ }
+ spatialRequestFilter += spatialRequestGeom.get(k).x+","+spatialRequestGeom.get(k).y;
+ }
+ spatialRequestFilter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>";
+ spatialRequestFilter += "</gml:Polygon></" + filteroption + ">";
+ }
+ else if(spatialRequestGeom.geomType == geomType.line){
+ var rectangle = [];
+ rectangle = spatialRequestGeom.getBBox();
+
+ spatialRequestFilter += "<" + filteroption + "><ogc:PropertyName>" +
+ geometryColumn + "</ogc:PropertyName><gml:Polygon srsName=\""+srs+"\">" +
+ "<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>" +
+ rectangle[0].x+","+rectangle[0].y + " " +
+ rectangle[0].x+","+rectangle[1].y + " " +
+ rectangle[1].x+","+rectangle[1].y + " " +
+ rectangle[1].x+","+rectangle[0].y + " " +
+ rectangle[0].x+","+rectangle[0].y +
+ "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>" +
+ "</gml:Polygon></" + filteroption + ">";
+ }
+ else if(spatialRequestGeom.geomType == geomType.point){
+ var tmp = spatialRequestGeom.get(0);
+ var mapPos = makeRealWorld2mapPos(target,tmp.x, tmp.y);
+ var buffer = mb_wfs_tolerance/2;
+ var realWorld1 = makeClickPos2RealWorldPos(target,mapPos[0]-buffer,mapPos[1]-buffer);
+ var realWorld2 = makeClickPos2RealWorldPos(target,mapPos[0]+buffer,mapPos[1]-buffer);
+ var realWorld3 = makeClickPos2RealWorldPos(target,mapPos[0]+buffer,mapPos[1]+buffer);
+ var realWorld4 = makeClickPos2RealWorldPos(target,mapPos[0]-buffer,mapPos[1]+buffer);
+ spatialRequestFilter += "<Intersects><ogc:PropertyName>";
+ spatialRequestFilter += geometryColumn;
+ spatialRequestFilter += "</ogc:PropertyName><gml:Polygon srsName=\""+srs+"\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";
+ spatialRequestFilter += realWorld1[0] + "," + realWorld1[1] + " " + realWorld2[0] + "," + realWorld2[1] + " ";
+ spatialRequestFilter += realWorld3[0] + "," + realWorld3[1] + " " + realWorld4[0] + "," + realWorld4[1] + " " + realWorld1[0] + "," + realWorld1[1];
+ spatialRequestFilter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></Intersects>";
+ }
+/*
+ spatialRequestFilter += "<ogc:Not><ogc:PropertyIsNull>";
+ spatialRequestFilter += "<ogc:PropertyName>" + geometryColumn + "</ogc:PropertyName>";
+ spatialRequestFilter += "</ogc:PropertyIsNull></ogc:Not>";
+*/
+ conditionArray.push(spatialRequestFilter);
+ }
+ };
+
+ this.addPreConfigured = function (propName, propValueArray, toUpper, operator) {
+ var orConditions = "";
+ for (var j=0; j < propValueArray.length; j++) {
+ if (operator == 'greater_than' || operator == 'less_than' || operator == 'equal') {
+ if(propValueArray[j]!=''){
+ var tag;
+ if (operator == 'greater_than') {
+ tag = "PropertyIsGreaterThan";
+ }
+ else if (operator == 'less_than') {
+ tag = "PropertyIsLessThan";
+ }
+ else if (operator == 'equal') {
+ tag = "PropertyIsEqualTo";
+ }
+
+ orConditions += "<ogc:" + tag + ">";
+ orConditions += "<ogc:PropertyName>" + propName + "</ogc:PropertyName>";
+ orConditions += "<ogc:Literal>";
+
+ if (toUpper == 1) {
+ propValueArray[j] = propValueArray[j].toUpperCase();
+ }
+
+ orConditions += propValueArray[j] + "</ogc:Literal></ogc:" + tag + ">";
+ }
+ }
+ else {
+ var leftSide = "";
+ var rightSide = "*";
+
+ if (operator != 'rightside') {
+ leftSide = "*";
+ }
+ orConditions += "<ogc:PropertyIsLike wildCard='*' singleChar='.' escape='!'>";
+ orConditions += "<ogc:PropertyName>" + propName + "</ogc:PropertyName>";
+ orConditions += "<ogc:Literal>" + leftSide;
+ if (toUpper == 1){
+ propValueArray[j] = propValueArray[j].toUpperCase();
+ }
+ orConditions += propValueArray[j] + rightSide;
+ orConditions += "</ogc:Literal></ogc:PropertyIsLike>";
+ }
+/*
+ orConditions += "<ogc:Not><ogc:PropertyIsNull>";
+ orConditions += "<ogc:PropertyName>" + propName + "</ogc:PropertyName>";
+ orConditions += "</ogc:PropertyIsNull></ogc:Not>";
+*/
+ }
+ if(propValueArray.length > 1){
+ orConditions = "<Or>" + orConditions + "</Or>";
+ }
+ this.add(orConditions);
+ };
+
+ this.add = function (aFilterString) {
+ conditionArray.push(aFilterString);
+ };
+
+ this.toString = function () {
+ var str = "";
+ str += "<ogc:Filter xmlns:ogc='http://www.opengis.net/ogc' ";
+ str += "xmlns:gml='http://www.opengis.net/gml'>";
+ if (conditionArray.length > 1) {
+ str += "<And>" + conditionArray.join("") + "</And>";
+ }
+ else {
+ str += conditionArray.join("");
+ }
+ str += "</ogc:Filter>";
+ return str;
+ };
+
+ var conditionArray = [];
+ var that = this;
+}
+
Added: branches/print_dev/http/php/mod_category_filteredGUI.php
===================================================================
--- branches/print_dev/http/php/mod_category_filteredGUI.php (rev 0)
+++ branches/print_dev/http/php/mod_category_filteredGUI.php 2009-03-09 09:08:08 UTC (rev 3649)
@@ -0,0 +1,250 @@
+<?php
+# $Id:$
+# http://www.mapbender.org/index.php/Administration
+# Copyright (C) 2002 CCGIS
+#
+# This program 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 2, or (at your option)
+# any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import_request_variables("PG");
+require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';
+?>
+<title>Administration</title>
+<?php
+include '../include/dyn_css.php';
+
+?>
+<script language="JavaScript">
+function validate(wert){
+ if(document.forms[0]["selected_category"].selectedIndex == -1){
+ document.getElementsByName("selected_category")[0].style.backgroundColor = '#ff0000';
+ return;
+ }else{
+ if(wert == "remove"){
+ if(document.forms[0]["remove_gui[]"].selectedIndex == -1){
+ document.getElementsByName("remove_gui[]")[0].style.backgroundColor = '#ff0000';
+ return;
+ }
+ document.form1.remove.value = 'true';
+ document.form1.submit();
+ }
+ if(wert == "insert"){
+ if(document.forms[0]["selected_gui[]"].selectedIndex == -1){
+ document.getElementsByName("selected_gui[]")[0].style.backgroundColor = '#ff0000';
+ return;
+ }
+ document.form1.insert.value = 'true';
+ document.form1.submit();
+ }
+ }
+}
+/**
+ * filter the category list
+ */
+function filtercategory(list, all, str){
+ str=str.toLowerCase();
+ var selection=[];
+ var i,j,selected;
+ for(i=0;i<list.options.length;i++){
+ if(list.options[i].selected)
+ selection[selection.length]=list.options[i].value;
+ }
+
+ list.options.length = 0;
+ for(i=0; i<all.length; i++){
+ if(all[i]['name'].toLowerCase().indexOf(str)==-1)
+ continue;
+ selected=false;
+ for(j=0;j<selection.length;j++){
+ if(selection[j]==all[i]['id']){
+ selected=true;
+ break;
+ }
+ }
+ var newOption = new Option(selected?all[i]['name']:all[i]['name'],all[i]['id'],false,selected);
+ newOption.setAttribute("title", all[i]['description']);
+ list.options[list.options.length] = newOption;
+ }
+}
+</script>
+
+</head>
+<body>
+<?php
+
+$fieldHeight = 20;
+
+$cnt_gui = 0;
+$cnt_category = 0;
+$cnt_gui = 0;
+$cnt_gui_category = 0;
+$cnt_gui_gui = 0;
+$exists = false;
+$logged_user_name=$_SESSION["mb_user_name"];
+$logged_user_id=$_SESSION["mb_user_id"];
+
+$admin = new administration();
+
+
+/*handle remove, update and insert*****************************************************************/
+if($insert){
+ if(count($selected_gui)>0){
+ for($i=0; $i<count($selected_gui); $i++){
+ $exists = false;
+ $sql_insert = "SELECT * from gui_gui_category where fkey_gui_category_id = $1 and fkey_gui_id = $2";
+ $v = array($selected_category,$selected_gui[$i]);
+ $t = array('i','s');
+ $res_insert = db_prep_query($sql_insert,$v,$t);
+ while(db_fetch_row($res_insert)){$exists = true;}
+ if($exists == false){
+ $sql_insert = "INSERT INTO gui_gui_category(fkey_gui_category_id, fkey_gui_id) VALUES($1, $2)";
+ $v = array($selected_category,$selected_gui[$i]);
+ $t = array('i','s');
+ $res_insert = db_prep_query($sql_insert,$v,$t);
+ }
+ }
+ }
+}
+if($remove){
+ if(count($remove_gui)>0){
+ for($i=0; $i<count($remove_gui); $i++){
+ $sql_remove = "DELETE FROM gui_gui_category WHERE fkey_gui_id = $1 and fkey_gui_category_id = $2";
+ $v = array($remove_gui[$i],$selected_category);
+ $t = array('s','i');
+ db_prep_query($sql_remove,$v,$t);
+ }
+ }
+}
+
+/*get owner guis *******************************************************************************/
+$guisByOwner = $admin->getGuisByOwner($logged_user_id,false);
+for ($i = 0; $i < count($guisByOwner); $i++) {
+ $gui_id[$cnt_gui] = $guisByOwner[$i];
+ $gui_name[$cnt_gui] = $guisByOwner[$i];
+ $cnt_gui++;
+}
+
+/*get categories **********************************************************************************/
+$sql_category = "SELECT * FROM gui_category order by category_id;";
+$res_category = db_query($sql_category);
+while($row = db_fetch_array($res_category)){
+ $category_id[$cnt_category] = $row["category_id"];
+ $category_name[$cnt_category] = $row["category_name"];
+ $category_description[$cnt_category] = $row["category_description"];
+ $cnt_category++;
+}
+# has to be solved by a function
+$guiCategories = $admin->getGuiCategories();
+echo "<br>getGuiCategories - mehrere Spalten";
+echo "Noch einbauen getGuiCategories".count($guiCategories);
+
+
+/*
+*
+* get owner gui for selected category
+*
+*/
+if (count($category_id) == 0 AND count($gui_id) == 0){ die("There is no gui or category available for this user");}
+
+#$sql_category_gui = "SELECT gui.gui_id, gui.gui_name, gui_gui_category.fkey_gui_category_id FROM gui_gui_category ";
+#$sql_category_gui .= "INNER JOIN gui ON gui_gui_category.fkey_gui_id = gui.gui_id ";
+#$sql_category_gui .= "WHERE gui_gui_category.fkey_gui_category_id = $1 ";
+#echo $sql_category_gui;egories);
+
+#if(!$selected_category){$v = array($category_id[0]);}
+#if($selected_category){$v = array($selected_category);}
+#$t = array('i');
+#$sql_category_gui .= " ORDER BY gui.gui_name";
+
+if(!$selected_category){$selectedCategory = $category_id[0];}
+if($selected_category){$selectedCategory = $selected_category;}
+$getGuisByOwnerBySelectedGuiCategory = $admin->getGuisByOwnerByGuiCategory($logged_user_id,$selectedCategory);
+
+$cnt_gui_category = count($getGuisByOwnerBySelectedGuiCategory);
+$gui_category_id = $getGuisByOwnerBySelectedGuiCategory;
+
+#$res_category_gui = db_prep_query($sql_category_gui,$v,$t);
+#while($row = db_fetch_array($res_category_gui)){
+#$gui_category_id[$cnt_gui_category] = $row["gui_id"];
+#$gui_category_name[$cnt_gui_category] = $row["gui_name"];
+#$cnt_gui_category++;
+#}
+
+/*INSERT HTML*/
+echo "<form name='form1' action='" . $self ."' method='post'>";
+/*filterbox****************************************************************************************/
+echo "<input type='text' value='' class='filter1' id='filter1' name='filter1' onkeyup='filtercategory(document.getElementById(\"selectedcategory\"),category,this.value);'/>";
+
+/*insert all category in selectbox*****************************************************************/
+echo "<div class='text1'>Category: </div>";
+echo "<select style='background:#ffffff' onchange='submit();' class='select1' id='selectedcategory' name='selected_category' size='10'>";
+for($i=0; $i<$cnt_category; $i++){
+ echo "<option value='" . $category_id[$i] . "' ";
+ if($selected_category && $selected_category == $category_id[$i]){
+ echo "selected>".$category_name[$i];
+ }
+ else
+ echo ">" . $category_name[$i];
+ echo "</option>";
+}
+echo "</select>";
+
+/*insert all guis in selectbox********************************************************************/
+echo "<div class='text2'>GUI:</div>";
+echo "<select style='background:#ffffff' class='select2' multiple='multiple' name='selected_gui[]' size='$fieldHeight' >";
+for($i=0; $i<$cnt_gui; $i++){
+ echo "<option value='" . $gui_name[$i] . "'>" . $gui_name[$i] . "</option>";
+}
+echo "</select>";
+
+/*Button******************************************************************************************/
+
+echo "<div class='button1'><input type='button' value='==>' onClick='validate(\"insert\")'></div>";
+echo "<input type='hidden' name='insert'>";
+
+echo "<div class='button2'><input type='button' value='<==' onClick='validate(\"remove\")'></div>";
+echo "<input type='hidden' name='remove'>";
+
+/*insert category_gui_dependence in selectbox**************************************************/
+echo "<div class='text3'>SELECTED GUI:</div>";
+echo "<select style='background:#ffffff' class='select3' multiple='multiple' name='remove_gui[]' size='$fieldHeight' >";
+for($i=0; $i<$cnt_gui_category; $i++){
+ echo "<option value='" . $gui_category_id[$i] . "'>" .$gui_category_id[$i]. "</option>";
+}
+echo "</select>";
+echo "</form>";
+
+?>
+<script type="text/javascript">
+<!--
+document.forms[0].selected_category.focus();
+var category=[];
+<?php
+for($i=0; $i<$cnt_category; $i++){
+ echo "category[".$i."]=[];\n";
+ echo "category[".$i."]['id']='" . $category_id[$i] . "';\n";
+ echo "category[".$i."]['name']='" . $category_name[$i] . "';\n";
+ echo "category[".$i."]['description']='" . $category_description[$i] . "';\n";
+}
+?>
+// -->
+</script>
+</body>
+</html>
\ No newline at end of file
Added: branches/print_dev/http/php/mod_createCategory.php
===================================================================
--- branches/print_dev/http/php/mod_createCategory.php (rev 0)
+++ branches/print_dev/http/php/mod_createCategory.php 2009-03-09 09:08:08 UTC (rev 3649)
@@ -0,0 +1,127 @@
+<?php
+# $Id:$
+# http://www.mapbender.org/index.php/Administration
+# Copyright (C) 2002 CCGIS
+#
+# This program 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 2, or (at your option)
+# any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import_request_variables("PG");
+require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+<head>
+<meta http-equiv="cache-control" content="no-cache">
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="expires" content="0">
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';
+?>
+<title>New Category</title>
+<?php include '../include/dyn_css.php'; ?>
+<?php
+if(isset($newCategory) && $newCategory != ""){
+ $sql = "SELECT category_name FROM gui_category WHERE category_name = $1";
+ $v = array($newCategory);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ if(db_fetch_row($res)){
+ echo "<script type='text/javascript'>";
+ echo "alert('Error: Category already exists!');";
+ echo "</script>";
+ }
+ else{
+ $sql = "INSERT INTO gui_category (category_name,category_description) ";
+ $sql .= "VALUES($1, $2)";
+ $v = array($newCategory,$newDesc);
+ $t = array('s','s');
+
+ $res = db_prep_query($sql,$v,$t);
+ $categoryCreated=true;
+ }
+}
+?>
+<script type="text/javascript">
+<!--
+function setFocus(){
+ document.form1.newCategory.focus();
+}
+function validate(){
+ if(document.form1.newCategory.value == ""){
+ alert("<?php echo _mb("Please enter a category name!")?>");
+ document.form1.newCategory.focus();
+ return;
+ }
+ else if(document.form1.newDesc.value == ""){
+ alert("<?php echo _mb("Please enter a category description!")?>");
+ document.form1.newDesc.focus();
+ return;
+ }
+ else{
+ document.form1.submit();
+ }
+}
+// -->
+</script>
+</head>
+<body onload='setFocus()'>
+<form name='form1' action="<?php echo $self; ?>" method="POST">
+
+<?php
+ $v = array();
+ $t = array();
+ $c = 1;
+ $sql = "SELECT * from gui_category";
+ $sql .= " order by lower(category_name);";
+ $res = db_prep_query($sql,$v,$t);
+ $count=0;
+ while($row = db_fetch_array($res)){
+ $category_name[$count]= $row["category_name"];
+ $category_description[$count]=$row["category_description"];
+ $count++;
+ }
+ echo "<p\n";
+ echo "<div class= 'guiList1_text'>"._mb("existing Categories").":</div>\n";
+#echo "<select class='categoryList' size='14' name='categoryList' onchange='setCategory(this.value)'>\n";
+ echo "<select class='categoryList' size='14' name='categoryList' onchange=''>\n";
+ for ($i=0; $i<count($category_name);$i++){
+ echo "<option value='".$category_name[$i]."' ";
+ echo ">".$category_name[$i]. " - ".$category_description[$i]."</option>\n";
+ }
+ echo "</select>\n";
+ echo "</p\n";
+?>
+
+<table>
+<tr><td><?php echo _mb("Category Name"); ?>: </td><td><input type='text' name='newCategory'></td></tr>
+<tr><td><?php echo _mb("Description"); ?>: </td><td><input type='text' name='newDesc'></td></tr>
+<tr><td></td><td><input type='button' onclick='validate()' value="<?php echo _mb("new"); ?>"></td></tr>
+</table>
+
+<?php
+if(isset($newCategory) && $newCategory != ""){
+ if ($categoryCreated==true){
+ echo "<p class = 'categroyList'>";
+ echo "<b>".$newCategory."</b> - "._mb("The Category has been created successfully.");
+ echo "<p>";
+ }else{
+ echo"error";
+ }
+}
+?>
+</form>
+</body>
+</html>
\ No newline at end of file
More information about the Mapbender_commits
mailing list