<?php
/**
 * pragmaMx - Web Content Management System
 * Pinwand Module
 * Copyright by pragmaMx Developer Team - http://www.pragmamx.org
 *
 * pragmaMx 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.
 *
 * $Revision: 1.6 $
 * $Author: tora60 $
 * $Date: 2009/12/19 07:56:33 $
 *
 * this file based on: Pinwand Modul V.2.0
 * by H. Grunert (http://www.marx-city.de)
 * which based on Pinwand 1.0 by ~ http://www.designer-ag.com
 * Copyright (c) 2004 by ~ designer-ag.com
 */

defined('mxMainFileLoaded') or die('access denied');

$module_name = basename(dirname(__FILE__));
mxGetLangfile($module_name);
include(dirname(__FILE__) . DS . 'includes' . DS . 'settings.php');
include_once(dirname(__FILE__) . DS . 'includes' . DS . 'functions.php');

$index = $showrblocks;

$action = (empty($_REQUEST['action'])) ? '' : $_REQUEST['action'];

switch ($action) {
    case 'add' :
    case 'addsave' :
    case 'edit' :
    case 'editsave' :
    case 'del' :
        include_once(dirname(__FILE__) . DS . 'includes' . DS . 'input.php');
        break;
    default :
        if (MX_IS_USER) {
            $userdata = mxGetUserData();
            $uid = $userdata['uid'];
        } else {
            $uid = 0;
        }

        if (method_exists('pmxHeader', 'add_jquery')) {
            pmxHeader::add_jquery('ui.core.js', 'ui.draggable.js');
        } else {
            pmxHeader::add_script(PMX_JAVASCRIPT_PATH . 'jquery/jquery.js');
            pmxHeader::add_script(PMX_JAVASCRIPT_PATH . 'jquery/ui.core.js');
            pmxHeader::add_script(PMX_JAVASCRIPT_PATH . 'jquery/ui.draggable.js');
        }
        pmxHeader::add_style("modules/$module_name/style/style.css");
        pmxHeader::add_style("modules/$module_name/style/style_ie.css" , '', 'IE');
        $img_edit = mxCreateImage('modules/' . $module_name . '/images/edit.gif', _EDIT, 0, 'align="right"');
        $img_dele = mxCreateImage('modules/' . $module_name . '/images/delete.gif', _DELETE, 0, 'align="right"');

        include("header.php");
        opentable();
        echo "<div id=\"pwmain\" style=\"width: " . $maxbreite . "px; height: " . ($maxhoehe + 250) . "px;\">";
        echo "<div id=\"caption\" style=\"color:#" . $titelfarbe . ";\">" . $titeltext . "</div>";
        echo "<div id=\"layer1\" class=\"area3\">\n";
        echo "<a href=\"http://www.pragmamx.org\" target=\"_blank\">mx-Pinwand 3.0</a>";
        echo "<img src=\"modules/" . $module_name . "/images/pin0.gif\" class=\"pin1\" alt=\"\" />\n";
        echo "<img src=\"modules/" . $module_name . "/images/pin0.gif\" class=\"pin2\" alt=\"\" />\n";
        echo "</div>\n";
        switch (true) {
            case $werdarfposten == 'alle':
            case MX_IS_USER && $werdarfposten == 'user':
            case MX_IS_ADMIN:
                echo "<div id=\"layer2\" class=\"area3\">"
                 . "<a href=\"modules.php?name=" . $module_name . "&amp;action=add\">" . _PW_WRITENOTE . "</a>\n"
                 . "<img src=\"modules/" . $module_name . "/images/pin8.gif\" class=\"pin1\" alt=\"\" />\n"
                 . "<img src=\"modules/" . $module_name . "/images/pin9.gif\" class=\"pin2\" alt=\"\" />\n"
                 . "</div>";
        }
        echo "<div style=\"position: relative;\">\n";

        $i = 0;

        $result = sql_query("SELECT p.*, u.uid as user_id, u.uname as user_name FROM ${prefix}_pinwand AS p LEFT JOIN {$user_prefix}_users AS u ON p.uid = u.uid ORDER BY p.datum");
        while ($row = sql_fetch_assoc($result)) {
            $i++;
            $x = mt_rand(0, $maxbreite - 200);
            $y = mt_rand(30, $maxhoehe);

            if ($checktime && $row['vorlauf'] && $row['vorlauf'] < time()) {
                sql_query("DELETE FROM ${prefix}_pinwand WHERE `id` = " . intval($row['id']));
                continue;
            }

            $lefttime = '';
            if ($checktime && $showremtime) {
                if (time() > $row['vorlauf']) {
                    $lefttime = _PWTIMELEFT . ': ' . _PWNOTDEFINED;
                } else {
                    $pwdays = floor(($row['vorlauf'] - time()) / (60 * 60 * 24));
                    $pwhours = floor((($row['vorlauf'] - time()) / (60 * 60)) % 24);
                    $lefttime = _PWTIMELEFT . ': ' . $pwdays . ' ' . _PMDAYS . ', ' . $pwhours . ' ' . _PMHOURS;
                }
            }

            $username = '';
            if ($showlinktoaccount && $row['user_name']) {
                $username = mxCreateUserprofileLink($row['user_name'], $row['user_name'], _PWPROFILE);
            }
            if (!$username && $row['email']) {
                $username = '<a href="mailto:' . mxPrepareToDisplay($row['email']) . '">' . $row['name'] . '</a>';
            }
            if (!$username) {
                $username = $row['name'];
            }

            $buttons = '';
            if (($uid == $row['user_id'] && $postercandelete) || MX_IS_ADMIN) {
                $buttons .= '<a href="modules.php?name=' . $module_name . '&amp;action=del&amp;id=' . $row['id'] . '" class="xdelet">  ' . $img_dele . '  </a>';
            }
            if (($uid == $row['user_id'] && $darfpostereditieren) || MX_IS_ADMIN) {
                $buttons .= '<a href="modules.php?name=' . $module_name . '&amp;action=edit&amp;id=' . $row['id'] . '">  ' . $img_edit . '  </a>';
            }

            $datum = mx_strftime(_XDATESTRING, $row['datum']);
            $text = nl2br(pinwand_desmile(mxPrepareToDisplay(wordwrap2($row['text'], 24, ' ', true))));
            if (MX_IS_ADMIN) {
                $ip = ($row['ipnumber']);
            }

            echo '<div class="drag" style="left:' . $x . 'px;top:' . $y . 'px;z-index:' . $i . ';" id="pw' . $row['id'] . '">'
             . '<img src="modules/' . $module_name . '/images/pin' . $row['pin'] . '.gif" alt="pin' . $i . '" title="' . _PWPIN_TITLE_AUS . '" class="pin" id="p' . $i . '">'
             . '<div class="zettel area' . $row['col'] . '" id="zp' . $i . '">'
             . '<b>' . $username . '</b>, <span class="nowrap">' . $datum . '</span>'
             . '<div class="entry">' . $text . '</div>'
             . '<div class="pinfo">' . $buttons . $lefttime .'</div>'
             . '<div class="pinfo">'. $ip .'</div>'
             . '</div>'
             . '</div>' . "\n";
        }
        echo "</div></div>";

        closetable();

        $getid = (empty($_GET['id'])) ? 0 : intval($_GET['id']);

        ?>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
  var z = <?php echo ($i + 10) ?>;

  $('#pw' + <?php echo $getid ?>).css("z-index", z++);

  $('a.xdelet').show();
  $('a.xdelet').click(function() {
    return confirm('<?php echo html_entity_decode(_PWSUREDELETE) ?>');
  });

  $('.drag').draggable({ opacity: 0.55 });
  $('.drag').mouseover(function() {
    this.style.zIndex = z++;
  });
  $('.drag .pin').click(function() {
    $('.drag #z' + this.id + '.zettel').toggle();

    if ($('.drag #z' + this.id + '.zettel').is(':visible')) {
        $('.drag #' + this.id).attr('title', '<?php echo _PWPIN_TITLE_AUS ?>');
    } else {
        $('.drag #' + this.id).attr('title', '<?php echo _PWPIN_TITLE_EIN ?>');
    }
  });

});

//]]>
</script>
<?php include("footer.php");
        return;
}

?>