예제 #1
0
파일: PastUI.php 프로젝트: rjsmelo/tiki
 public function getContents()
 {
     if (FutureLink_PastUI::$pairs->length > 0) {
         $this->setEncoding(TikiFilter_PrepareInput::delimiter('_')->toString(FutureLink_PastUI::$pairs));
         return FutureLink_PastUI::$pairs;
     }
     return array();
 }
예제 #2
0
 public function getContents()
 {
     if (!empty(self::$contributions)) {
         $this->setEncoding(TikiFilter_PrepareInput::delimiter('_')->toString(self::$contributions));
         return self::$contributions;
     }
     return array();
 }
예제 #3
0
 public function getContents()
 {
     global $textlinkContribution;
     if (!empty($textlinkContribution)) {
         $this->setEncoding(TikiFilter_PrepareInput::delimiter('_')->flatten($textlinkContribution));
         return $textlinkContribution;
     }
     return array();
 }
예제 #4
0
				// that is OK (prevents munging of $_SERVER with ?_SERVER=rubbish etc.)
				unset($GLOBALS[$key]);
			}
		}
	}
}
$serverFilter = new DeclFilter;
if ( ( isset($prefs['tiki_allow_trust_input']) && $prefs['tiki_allow_trust_input'] ) !== 'y' || $tiki_p_trust_input != 'y') {
	$serverFilter->addStaticKeyFilters(array('QUERY_STRING' => 'xss', 'REQUEST_URI' => 'xss', 'PHP_SELF' => 'xss',));
}
$jitServer = new JitFilter($_SERVER);
$_SERVER = $serverFilter->filter($_SERVER);
// Rebuild request after gpc fix
// _REQUEST should only contain GET and POST in the app

$prepareInput = new TikiFilter_PrepareInput('~');
$_GET = $prepareInput->prepare($_GET);
$_POST = $prepareInput->prepare($_POST);

$_REQUEST = array_merge($_GET, $_POST);
// Preserve unfiltered values accessible through JIT filtering
$jitPost = new JitFilter($_POST);
$jitGet = new JitFilter($_GET);
$jitRequest = new JitFilter($_REQUEST);
$jitCookie = new JitFilter($_COOKIE);
$jitPost->setDefaultFilter('xss');
$jitGet->setDefaultFilter('xss');
$jitRequest->setDefaultFilter('xss');
$jitCookie->setDefaultFilter('xss');
// Apply configured filters to all other input
if (!isset($inputConfiguration)) $inputConfiguration = array();
예제 #5
0
function wikiplugin_convene($data, $params)
{
    global $tikilib, $headerlib, $page, $tiki_p_edit;
    static $conveneI = 0;
    ++$conveneI;
    $i = $conveneI;
    $params = array_merge(array("title" => "Convene", "calendarid" => "1", "minvotes" => "3", "dateformat" => "short"), $params);
    extract($params, EXTR_SKIP);
    $dataString = $data . '';
    $dataArray = array();
    $existingUsers = json_encode(TikiLib::lib("user")->get_users_names());
    //start flat static text to prepared array
    $lines = explode("\n", trim($data));
    sort($lines);
    foreach ($lines as $line) {
        $line = trim($line);
        if (!empty($line)) {
            $parts = explode(':', $line);
            $dataArray[trim($parts[0])] = trim($parts[1]);
        }
    }
    $data = TikiFilter_PrepareInput::delimiter('_')->prepare($dataArray);
    //end flat static text to prepared array
    //start get users from array
    $users = array();
    foreach (end($data['dates']) as $user => $vote) {
        $users[] = $user;
    }
    //end get users from array
    //start votes summed together
    $votes = array();
    foreach ($data['dates'] as $stamp => $date) {
        foreach ($date as $vote) {
            if (empty($votes[$stamp])) {
                $votes[$stamp] = 0;
            }
            $votes[$stamp] += (int) $vote;
        }
    }
    //end votes summed together
    //start find top vote stamp
    $topVoteStamp = 0;
    foreach ($votes as $stamp => $vote) {
        if (!isset($votes[$topVoteStamp]) || isset($votes[$topVoteStamp]) && $vote > $votes[$topVoteStamp]) {
            $topVoteStamp = $stamp;
        }
    }
    //end find top vote stamp
    //start reverse array for easy listing as table
    $rows = array();
    foreach ($data['dates'] as $stamp => $date) {
        foreach ($date as $user => $vote) {
            if (isset($rows[$user][$stamp])) {
                $rows[$user][$stamp] = array();
            }
            $rows[$user][$stamp] = $vote;
        }
    }
    //end reverse array for easy listing as table
    $result = "";
    //start date header
    $dateHeader = "";
    foreach ($votes as $stamp => $totals) {
        if (!empty($dateformat) && $dateformat == "long") {
            $dateHeader .= "<td class='conveneHeader'>" . $tikilib->get_long_datetime($stamp) . ($tiki_p_edit == 'y' ? " <button class='conveneDeleteDate{$i} icon ui-widget-header ui-corner-all' data-date='{$stamp}'><img src='img/icons/delete.png' class='icon' width='16' height='16' title='" . tr("Delete Date") . "'/></button>" : "") . "</td>";
        } else {
            $dateHeader .= "<td class='conveneHeader'>" . $tikilib->get_short_datetime($stamp) . ($tiki_p_edit == 'y' ? " <button class='conveneDeleteDate{$i} icon ui-widget-header ui-corner-all' data-date='{$stamp}'><img src='img/icons/delete.png' class='icon' width='16' height='16' title='" . tr("Delete Date") . "'/></button>" : "") . "</td>";
        }
    }
    $result .= "\n\t\t<tr class='conveneHeaderRow'>\n\t\t\t<td></td>\n\t\t\t{$dateHeader}\n\t\t</tr>";
    //end date header
    //start user list and votes
    $userList = "";
    foreach ($rows as $user => $row) {
        $userList .= "<tr class='conveneVotes conveneUserVotes{$i}'>";
        $userList .= "<td>" . ($tiki_p_edit == 'y' ? "<button class='conveneUpdateUser{$i} icon ui-widget-header ui-corner-all'><img src='img/icons/pencil.png' class='icon' width='16' height='16' title='" . tr("Edit User/Save changes") . "' /></button><button data-user='******' title='" . tr("Delete User") . "' class='conveneDeleteUser{$i} icon ui-widget-header ui-corner-all'><img src='img/icons/delete.png' class='icon' width='16' height='16' /></button> " : "") . $user . "</td>";
        foreach ($row as $stamp => $vote) {
            if ($vote == 1) {
                $class = "ui-state-default convene-ok";
                $text = "<img src='img/icons/tick.png' alt='" . tr('Ok') . "' class='vote icon' width='16' height='16' />";
            } elseif ($vote == -1) {
                $class = "ui-state-default convene-no";
                $text = "<img src='img/icons/cross.png' alt='" . tr('Not ok') . "' class='vote icon' width='16' height='16' />";
            } else {
                $class = "ui-state-default convene-unconfirmed";
                $text = "<img src='img/icons/grey_question.png' alt='" . tr('Unconfirmed') . "' class='vote icon' width='16' height='16' />";
            }
            $userList .= "<td class='{$class}'>" . $text . "<input type='hidden' name='dates_" . $stamp . "_" . $user . "' value='{$vote}' class='conveneUserVote{$i}' />" . "</td>";
        }
        $userList .= "</tr>";
    }
    $result .= $userList;
    //end user list and votes
    //start add new user and votes
    $result .= "<tr class='conveneFooterRow'>";
    $result .= "<td>" . ($tiki_p_edit == 'y' ? "<input class='conveneAddUser{$i}' value='" . tr("Add User") . "' /><input type='button' value='" . tr('Add User') . "' class='conveneAddUserButton{$i}' />" : "") . "</td>";
    //end add new user and votes
    //start last row with auto selected date(s)
    $lastRow = "";
    foreach ($votes as $stamp => $total) {
        $pic = "";
        if ($total == $votes[$topVoteStamp]) {
            $pic .= $tiki_p_edit != "y" ? "<img src='img/icons/tick.png' class='icon' width='16' height='16' title='" . tr("Selected Date") . "' />" : "";
            if ($tiki_p_edit == 'y' && $votes[$topVoteStamp] >= $minvotes) {
                $pic .= "<button class='icon ui-widget-header ui-corner-all' onclick='document.location = \$(this).find(\"a\").attr(\"href\"); return false;'><a href='tiki-calendar_edit_item.php?todate={$stamp}&calendarId={$calendarid}' title='" . tr("Add as Calendar Event") . "'><img src='img/icons/calendar_add.png' class='icon' width='16' height='16' /></a></button>";
            }
        }
        $lastRow .= "<td class='conveneFooter'>" . $total . "&nbsp;{$pic}</td>";
    }
    $result .= $lastRow;
    $result .= "<td style='width: 20px;'>" . ($tiki_p_edit == 'y' ? "<input type='button' class='conveneAddDate{$i}' value='" . tr('Add Date') . "'/>" : "") . "</td>";
    $result .= "</tr>";
    //end last row with auto selected date(s)
    $result = <<<FORM
\t\t\t<form id='pluginConvene{$i}'>
\t\t\t\t<table cellpadding="2" cellspacing="2" border="0" style="width: 100%;">{$result}</table>
\t\t\t</form>
FORM;
    $conveneData = json_encode(array("dates" => $data['dates'], "users" => $users, "votes" => $votes, "topVote" => $votes[$topVoteStamp], "rows" => $rows, "data" => $dataString));
    $n = '\\n';
    $regexN = '/[\\r\\n]+/g';
    $headerlib->add_jq_onready(<<<JQ

\t\tvar convene{$i} = \$.extend({
\t\t\tfromBlank: function(user, date) {
\t\t\t\tif (!user || !date) return;
\t\t\t\tthis.data = "dates_" + Date.parseUnix(date) + "_" + user;
\t\t\t\tthis.save();
\t\t\t},
\t\t\tupdateUsersVotes: function() {
\t\t\t\tvar data = [];
\t\t\t\t\$('.conveneUserVotes{$i}').each(function() {
\t\t\t\t\t\$('.conveneUserVote{$i}').each(function() {
\t\t\t\t\t\tdata.push(\$(this).attr('name') + ' : ' + \$(this).val());
\t\t\t\t\t});
\t\t\t\t});

\t\t\t\tthis.data = data.join('{$n}');

\t\t\t\tthis.save();
\t\t\t},
\t\t\taddUser: function(user) {
\t\t\t\tif (!user) return;

\t\t\t\tvar data = [];

\t\t\t\tfor(date in this.dates) {
\t\t\t\t\tdata.push("dates_" + date + "_" + user);
\t\t\t\t}

\t\t\t\tthis.data += '{$n}' + data.join('{$n}');

\t\t\t\tthis.save();
\t\t\t},
\t\t\tdeleteUser: function(user) {
\t\t\t\tif (!user) return;
\t\t\t\tvar data = '';

\t\t\t\tfor(date in this.dates) {
\t\t\t\t\tfor(i in this.users) {
\t\t\t\t\t\tif (this.users[i] != user) {
\t\t\t\t\t\t\tdata += 'dates_' + date + '_' + this.users[i] + ' : ' + this.dates[date][this.users[i]] + '{$n}';
\t\t\t\t\t\t}
\t\t\t\t\t}
\t\t\t\t}

\t\t\t\tthis.data = data;

\t\t\t\tthis.save(true);
\t\t\t},
\t\t\taddDate: function(date) {
\t\t\t\tif (!date) return;
\t\t\t\tdate = Date.parseUnix(date);
\t\t\t\tvar addedData = '';

\t\t\t\tfor(user in this.users) {
\t\t\t\t\taddedData += 'dates_' + date + '_' + this.users[user] + ' : 0{$n}';
\t\t\t\t}

\t\t\t\tthis.data = (this.data + '{$n}' + addedData).split({$regexN}).sort();

\t\t\t\t//remove empty lines
\t\t\t\tfor(line in this.data) {
\t\t\t\t\tif (!this.data[line]) this.data.splice(line, 1);
\t\t\t\t}

\t\t\t\tthis.data = this.data.join('{$n}');

\t\t\t\tthis.save();
\t\t\t},
\t\t\tdeleteDate: function(date) {
\t\t\t\tif (!date) return;
\t\t\t\tdate += '';
\t\t\t\tvar addedData = '';

\t\t\t\tfor(user in this.users) {
\t\t\t\t\taddedData += 'dates_' + date + '_' + this.users[user] + ' : 0{$n}';
\t\t\t\t}

\t\t\t\tvar lines = convene{$i}.data.split({$regexN});
\t\t\t\tvar newData = [];
\t\t\t\tfor(line in lines) {
\t\t\t\t\tif (!(lines[line] + '').match(date)) {
\t\t\t\t\t\t newData.push(lines[line]);
\t\t\t\t\t}
\t\t\t\t}

\t\t\t\tthis.data = newData.join('{$n}');
\t\t\t\tthis.save();
\t\t\t},
\t\t\tsave: function(reload) {
\t\t\t\t\$("#page-data").modal(tr("Loading..."));

\t\t\t\tvar needReload = reload != undefined;
\t\t\t\tvar params = {
\t\t\t\t\tpage: "{$page}",
\t\t\t\t\tcontent: \$.trim(this.data),
\t\t\t\t\tindex: {$i},
\t\t\t\t\ttype: "convene",
\t\t\t\t\tparams: {
\t\t\t\t\t\ttitle: "{$title}",
\t\t\t\t\t\tcalendarid: {$calendarid},
\t\t\t\t\t\tminvotes: {$minvotes}
\t\t\t\t\t}
\t\t\t\t};
\t\t\t\t\$.post("tiki-wikiplugin_edit.php", params, function() {
\t\t\t\t\t\$.get(\$.service("wiki", "get_page", {page: "{$page}"}), function (data) {
\t\t\t\t\t\tif (needReload) {
\t\t\t\t\t\t\thistory.go(0);
\t\t\t\t\t\t} else {
\t\t\t\t\t\t\tif (data) {
\t\t\t\t\t\t\t\tvar newForm = \$("#pluginConvene{$i}", data);
\t\t\t\t\t\t\t\t\$("#pluginConvene{$i}", "#page-data").replaceWith(newForm);
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\tinitConvene{$i}();
\t\t\t\t\t\t\t\$("#page-data").modal();
\t\t\t\t\t\t}
\t\t\t\t\t});

\t\t\t\t});
\t\t\t}
\t\t}, {$conveneData});


\t\t//handle a blank convene
\t\tif ("{$tiki_p_edit}" == 'y') {
\t\t\t\$('#conveneBlank{$i}').each(function() {
\t\t\t\tvar table = \$('<table>' +
\t\t\t\t\t'<tr>' +
\t\t\t\t\t\t'<td>' +
\t\t\t\t\t\t\t'User: <input type="text" style="width: 100px;" id="conveneNewUser{$i}" />' +
\t\t\t\t\t\t'</td>' +
\t\t\t\t\t\t'<td>' +
\t\t\t\t\t\t\t'Date/Time: <input style="width: 100px;" id="conveneNewDatetime{$i}" />' +
\t\t\t\t\t\t'</td>' +
\t\t\t\t\t\t'<td style="vertical-align: middle;">' +
\t\t\t\t\t\t\t'<input type="button" id="conveneNewUserAndDate{$i}" value="' + tr("Add User & Date") + '" />' +
\t\t\t\t\t\t'</td>' +
\t\t\t\t\t'</tr>' +
\t\t\t\t'</table>').appendTo(this);

\t\t\t\t\$('#conveneNewUser{$i}').autocomplete({
\t\t\t\t\tsource: {$existingUsers}
\t\t\t\t});

\t\t\t\t\$('#conveneNewDatetime{$i}').datetimepicker();

\t\t\t\t\$('#conveneNewUserAndDate{$i}').click(function() {
\t\t\t\t\tconvene{$i}.fromBlank(\$('#conveneNewUser{$i}').val(), \$('#conveneNewDatetime{$i}').val());
\t\t\t\t});
\t\t\t});
\t\t} else {
\t\t\t\$('#conveneBlank{$i}').each(function() {
\t\t\t\t\$('<div />').text(tr("Login to edit Convene")).appendTo(this);
\t\t\t});
\t\t}

\t\tvar initConvene{$i} = function () {
\t\t\t\$('.conveneAddDate{$i}').click(function() {
\t\t\t\tvar dialogOptions = {
\t\t\t\t\tmodal: true,
\t\t\t\t\ttitle: tr("Add Date"),
\t\t\t\t\tbuttons: {}
\t\t\t\t};

\t\t\t\tdialogOptions.buttons[tr("Add")] = function() {
\t\t\t\t\tconvene{$i}.addDate(o.find('input:first').val());
\t\t\t\t\to.dialog('close');
\t\t\t\t}

\t\t\t\tvar o = \$('<div><input type="text" style="width: 100%;" /></div>')
\t\t\t\t\t.dialog(dialogOptions);

\t\t\t\to.find('input:first')
\t\t\t\t\t.datetimepicker()
\t\t\t\t\t.focus();
\t\t\t\treturn false;
\t\t\t});

\t\t\t\$('.conveneDeleteDate{$i}')
\t\t\t\t.click(function() {
\t\t\t\t\tconvene{$i}.deleteDate(\$(this).data("date"));
\t\t\t\t\treturn false;
\t\t\t\t});

\t\t\t\$('.conveneDeleteUser{$i}')
\t\t\t\t.click(function() {
\t\t\t\t\tif (confirm(tr("Are you sure you want to remove this user's votes?") + "\\n" +
\t\t\t\t\t\t\ttr("There is no undo"))) {
\t\t\t\t\t\tconvene{$i}.deleteUser(\$(this).data("user"));
\t\t\t\t\t}
\t\t\t\t\treturn false;
\t\t\t\t});

\t\t\t\$('.conveneUpdateUser{$i}').toggle(function() {
\t\t\t\t\$('.conveneUpdateUser{$i}').not(this).hide();
\t\t\t\t\$('.conveneDeleteUser{$i}').hide();
\t\t\t\t\$('.conveneDeleteDate{$i}').hide();
\t\t\t\t\$('.conveneMain{$i}').hide();
\t\t\t\t\$(this).parent().parent()
\t\t\t\t\t.addClass('ui-state-highlight')
\t\t\t\t\t.find('td').not(':first')
\t\t\t\t\t.addClass('conveneTd{$i}')
\t\t\t\t\t.removeClass('ui-state-default')
\t\t\t\t\t.addClass('ui-state-highlight');

\t\t\t\t\$(this).find('img').attr('src', 'img/icons/accept.png');
\t\t\t\tvar parent = \$(this).parent().parent();
\t\t\t\tparent.find('.vote').hide();
\t\t\t\tparent.find('input').each(function() {
\t\t\t\t\t\$('<select>' +
\t\t\t\t\t\t'<option value="">' + tr('Unconfirmed') + '</option>' +
\t\t\t\t\t\t'<option value="-1">' + tr('Not ok') + '</option>' +
\t\t\t\t\t\t'<option value="1">' + tr('Ok') + '</option>' +
\t\t\t\t\t'</select>')
\t\t\t\t\t\t.val(\$(this).val())
\t\t\t\t\t\t.insertAfter(this)
\t\t\t\t\t\t.change(function() {
\t\t\t\t\t\t\tvar cl = '';

\t\t\t\t\t\t\tswitch(\$(this).val() * 1) {
\t\t\t\t\t\t\t\tcase 1:     cl = 'convene-ok';break;
\t\t\t\t\t\t\t\tcase -1:    cl = 'convene-no';break;
\t\t\t\t\t\t\t\tdefault:    cl = 'convene-unconfirmed';
\t\t\t\t\t\t\t}

\t\t\t\t\t\t\t\$(this)
\t\t\t\t\t\t\t\t.parent()
\t\t\t\t\t\t\t\t.removeClass('convene-no convene-ok convene-unconfirmed')
\t\t\t\t\t\t\t\t.addClass(cl);

\t\t\t\t\t\t\tconvene{$i}.updateUsers = true;
\t\t\t\t\t\t});
\t\t\t\t});
\t\t\t}, function () {
\t\t\t\t\$('.conveneUpdateUser{$i}').show();
\t\t\t\t\$('.conveneDeleteUser{$i}').show();
\t\t\t\t\$('.conveneDeleteDate{$i}').show();
\t\t\t\t\$(this).parent().parent()
\t\t\t\t\t.removeClass('ui-state-highlight')
\t\t\t\t\t.find('.conveneTd{$i}')
\t\t\t\t\t.removeClass('ui-state-highlight')
\t\t\t\t\t.addClass('ui-state-default');

\t\t\t\t\$('.conveneMain{$i}').show();
\t\t\t\t\$(this).find('img').attr('src', 'img/icons/pencil.png');
\t\t\t\tvar parent = \$(this).parent().parent();
\t\t\t\tparent.find('select').each(function(i) {
\t\t\t\t\tparent.find('input.conveneUserVote{$i}').eq(i).val( \$(this).val() );

\t\t\t\t\t\$(this).remove();
\t\t\t\t});

\t\t\t\tif (convene{$i}.updateUsers) {
\t\t\t\t\tconvene{$i}.updateUsersVotes();
\t\t\t\t}
\t\t\t});

\t\t\tvar addUsers{$i} = \$('.conveneAddUser{$i}')
\t\t\t\t.click(function() {
\t\t\t\t\tif (!\$(this).data('clicked')) {
\t\t\t\t\t\t\$(this)
\t\t\t\t\t\t\t.data('initval', \$(this).val())
\t\t\t\t\t\t\t.val('')
\t\t\t\t\t\t\t.data('clicked', true);
\t\t\t\t\t}
\t\t\t\t})
\t\t\t\t.blur(function() {
\t\t\t\t\tif (!\$(this).val()) {
\t\t\t\t\t\t\$(this)
\t\t\t\t\t\t\t.val(\$(this).data('initval'))
\t\t\t\t\t\t\t.data('clicked', '');

\t\t\t\t\t}
\t\t\t\t})
\t\t\t\t.keydown(function(e) {
\t\t\t\t\tvar user = \$(this).val();

\t\t\t\t\tif (e.which == 13) {//enter
\t\t\t\t\t\tconvene{$i}.addUser(user);
\t\t\t\t\t\treturn false;
\t\t\t\t\t}
\t\t\t\t});

//ensure autocomplete works, it may not be available in mobile mode
            if (addUsers{$i}.autocomplete) {
\t\t\t\taddUsers{$i}.autocomplete({
\t\t\t\t\tsource: {$existingUsers}
\t\t\t\t});
            }

            \$('.conveneAddUserButton{$i}').click(function() {
                convene{$i}.addUser(\$('.conveneAddUser{$i}').val());
            });

\t\t\t\$('#pluginConvene{$i} .icon').css('cursor', 'pointer');
\t\t};
\t\tinitConvene{$i}();
JQ
);
    if (empty($dataString)) {
        $result = "<div id='conveneBlank{$i}'></div>";
    }
    return <<<RETURN
~np~
\t<div class="ui-widget-content ui-corner-all">
\t\t<div class="ui-widget-header ui-corner-top">
\t\t\t<h5 style="margin: 5px;">{$title}</h5>
\t\t</div>
\t\t\t{$result}
\t</div>
~/np~
RETURN;
}
function wikiplugin_convene($data, $params)
{
	global $tikilib, $headerlib, $page, $tiki_p_edit;

	static $conveneI = 0;
	++$conveneI;
	$i = $conveneI;
	
		
	$params = array_merge(
					array(
						"title" => "Convene",
						"calendarid" => "1",
						"dateformat" => "short"
					), 
					$params
	);

	extract($params, EXTR_SKIP);

	$dataString = $data . '';
	$dataArray = array();
	
	$existingUsers = json_encode(TikiLib::lib("user")->get_users_names());
	
	//start flat static text to prepared array
	$lines = explode("\n", trim($data));
	sort($lines);
	foreach ($lines as $line) {
		$line = trim($line);

		if (!empty($line)) {
			$parts = explode(':', $line);
			$dataArray[trim($parts[0])] = trim($parts[1]);
		}
	}
	
	$data = TikiFilter_PrepareInput::delimiter('_')->prepare($dataArray);
	//end flat static text to prepared array
	
	//start get users from array
	$users = array();
	foreach (end($data['dates']) as $user => $vote) {
		$users[] = $user;
	}
	//end get users from array
	
	
	//start votes summed together
	$votes = array();
	foreach ($data['dates'] as $stamp => $date) {
		foreach ($date as $vote) {
			if (empty($votes[$stamp])) $votes[$stamp] = 0;
			$votes[$stamp] += $vote;
		}
	}
	//end votes summed together
	
	
	//start find top vote stamp
	$topVoteStamp = 0;
	foreach ($votes as $stamp => $vote) {
		if (
			!isset($votes[$topVoteStamp]) || (
				isset($votes[$topVoteStamp]) &&
				$vote > $votes[$topVoteStamp]
			)
		) {
			$topVoteStamp = $stamp;
		}
	}
	//end find top vote stamp
	
	
	//start reverse array for easy listing as table
	$rows = array();
	foreach ($data['dates'] as $stamp => $date) {
		foreach ($date as $user => $vote) {
			if (isset($rows[$user][$stamp])) $rows[$user][$stamp] = array();
			 
			$rows[$user][$stamp] = $vote;
		}
	}
	//end reverse array for easy listing as table
	
	$result = "";
	
	//start date header
	$dateHeader = "";
	foreach ($votes as $stamp => $totals) {
		if (!empty($dateformat) && $dateformat == "long") {
			$dateHeader .= "<td class='conveneHeader'>". $tikilib->get_long_datetime($stamp) .
				($tiki_p_edit == 'y' ? " <button class='conveneDeleteDate$i icon ui-widget-header ui-corner-all' data-date='$stamp'><img src='img/icons/delete.png' class='icon' width='16' height='16' title='" . tr("Delete Date") . "'/></button>" : "").
			"</td>";
		} else {
			$dateHeader .= "<td class='conveneHeader'>". $tikilib->get_short_datetime($stamp) .
				($tiki_p_edit == 'y' ? " <button class='conveneDeleteDate$i icon ui-widget-header ui-corner-all' data-date='$stamp'><img src='img/icons/delete.png' class='icon' width='16' height='16' title='" . tr("Delete Date") . "'/></button>" : "").
			"</td>";
		}
	}
	$result .= "
		<tr class='conveneHeaderRow'>
			<td></td>
			$dateHeader
		</tr>";
	//end date header
	
	
	//start user list and votes 
	$userList = "";
	foreach ($rows as $user => $row) {
		$userList .= "<tr class='conveneVotes conveneUserVotes$i'>";
		$userList .= "<td>". ($tiki_p_edit == 'y' ? "<button class='conveneUpdateUser$i icon ui-widget-header ui-corner-all'><img src='img/icons/pencil.png' class='icon' width='16' height='16' title='" . tr("Edit User/Save changes") . "' /></button><button data-user='******' title='" . tr("Delete User") . "' class='conveneDeleteUser$i icon ui-widget-header ui-corner-all'><img src='img/icons/delete.png' class='icon' width='16' height='16' /></button> " : "") . $user . "</td>";
		foreach ($row as $stamp => $vote) {
			if ($vote == 1) {
				$class = 	"ui-state-default convene-ok";
				$text = 	"<img src='img/icons/tick.png' alt='" . tr('Ok') . "' class='vote icon' width='16' height='16' />";
			} elseif ($vote == -1) {
				$class = 	"ui-state-default convene-no";
				$text = 	"<img src='img/icons/cross.png' alt='" . tr('Not ok') . "' class='vote icon' width='16' height='16' />";
			} else {
				$class = 	"ui-state-default convene-unconfirmed";
				$text = 	"<img src='img/icons/grey_question.png' alt='" . tr('Unconfirmed') . "' class='vote icon' width='16' height='16' />";
			}
			
			$userList .= "<td class='$class'>". $text
				."<input type='hidden' name='dates_" . $stamp . "_" . $user . "' value='$vote' class='conveneUserVote$i' />"
				."</td>";
		}
		$userList .= "</tr>";
	}
	$result .= $userList;
	//end user list and votes
	
	
	//start add new user and votes
	$result .= "<tr class='conveneFooterRow'>";


	$result .= "<td>".(
		$tiki_p_edit == 'y'
			?
				"<input class='conveneAddUser$i' value='" . tr("Add User") . "' /><input type='button' value='" . tr('Add User') . "' class='conveneAddUserButton$i' />"
			: ""
		).
	"</td>";
	//end add new user and votes
	
	
	//start last row with auto selected date(s)
	$lastRow = "";
	foreach ($votes as $stamp => $total) {
		$pic = "";
		if ($total == $votes[$topVoteStamp]) {
			$pic .= ($tiki_p_edit != "y" ? "<img src='img/icons/tick.png' class='icon' width='16' height='16' title='" . tr("Selected Date") . "' />" : "");
			if ($tiki_p_edit == 'y') {
				$pic .= "<button class='icon ui-widget-header ui-corner-all' onclick='document.location = $(this).find(\"a\").attr(\"href\"); return false;'><a href='tiki-calendar_edit_item.php?todate=$stamp&calendarId=$calendarid' title='" . tr("Add as Calendar Event") . "'><img src='img/icons/calendar_add.png' class='icon' width='16' height='16' /></a></button>";
			}
		}
		
		$lastRow .= "<td class='conveneFooter'>". $total ."&nbsp;$pic</td>";
	}
	$result .= $lastRow;

	$result .= "<td style='width: 20px;'>" . (
		$tiki_p_edit == 'y'
			?
				"<input type='button' class='conveneAddDate$i' value='" . tr('Add Date') . "'/>"
			: ""
	)."</td>";

	$result .= "</tr>";
	//end last row with auto selected date(s)
	
	
	$result = <<<FORM
			<form id='pluginConvene$i'>
				<table cellpadding="2" cellspacing="2" border="0" style="width: 100%;">$result</table>
			</form>
FORM;
	
	$conveneData = json_encode(
					array(
						"dates" => $data['dates'],
						"users" => $users,
						"votes" => $votes,
						"topVote" => $votes[$topVoteStamp],
						"rows" =>	$rows,
						"data" => $dataString,
					)
	);

	$n = '\n';
	$regexN = '/[\r\n]+/g';
	
	$headerlib->add_jsfile("lib/jquery/jquery-ui-timepicker-addon.js");
	$headerlib->add_jq_onready(
<<<JQ
		
		var convene$i = $.extend({
			fromBlank: function(user, date) {
				if (!user || !date) return;
				this.data = "dates_" + Date.parseUnix(date) + "_" + user;
				this.save();
			},
			updateUsersVotes: function() {
				var data = [];
				$('.conveneUserVotes$i').each(function() {
					$('.conveneUserVote$i').each(function() {
						data.push($(this).attr('name') + ' : ' + $(this).val());
					});
				});
				
				this.data = data.join('$n');
				
				this.save();
			},
			addUser: function(user) {
				if (!user) return;
				
				var data = [];
				
				for(date in this.dates) {
					data.push("dates_" + date + "_" + user);
				}
				
				this.data += '$n' + data.join('$n');
				
				this.save();
			},
			deleteUser: function(user) {
				if (!user) return;
				var data = '';
				
				for(date in this.dates) {
					for(i in this.users) {
						if (this.users[i] != user) {
							data += 'dates_' + date + '_' + this.users[i] + ' : ' + this.dates[date][this.users[i]] + '$n';
						}
					}
				}
				
				this.data = data;
				
				this.save();
			},
			addDate: function(date) {
				if (!date) return;
				date = Date.parseUnix(date);
				var addedData = '';
				
				for(user in this.users) {
					addedData += 'dates_' + date + '_' + this.users[user] + ' : 0$n';
				}
				
				this.data = (this.data + '$n' + addedData).split($regexN).sort();
				
				//remove empty lines
				for(line in this.data) {
					if (!this.data[line]) this.data.splice(line, 1);
				}
				
				this.data = this.data.join('$n');
				
				this.save();
			},
			deleteDate: function(date) {
				if (!date) return;
				date += '';
				var addedData = '';
				
				for(user in this.users) {
					addedData += 'dates_' + date + '_' + this.users[user] + ' : 0$n';
				}

				var lines = convene$i.data.split($regexN);
				var newData = [];
				for(line in lines) {
					if (!(lines[line] + '').match(date)) {
						 newData.push(lines[line]);
					}
				}

				this.data = newData.join('$n');
				this.save();
			},
			save: function() {
				$.modal(tr("Loading..."));
				
				$('<form id="conveneSave$i" method="post" action="tiki-wikiplugin_edit.php">'+
					'<div>'+
						'<input type="hidden" name="page" value="$page"/>'+
						'<input type="hidden" name="content" value="' + $.trim(this.data) + '"/>'+
						'<input type="hidden" name="index" value="$i"/>'+
						'<input type="hidden" name="type" value="convene"/>'+
						'<input type="hidden" name="params[title]" value="$title"/>'+
					'</div>'+
				'</form>')
				.appendTo('body')
				.submit();
			}
		}, $conveneData);
		
		
		//handle a blank convene
		if ("$tiki_p_edit" == 'y') {
			$('#conveneBlank$i').each(function() {
				var table = $('<table>' +
					'<tr>' +
						'<td>' +
							'User: <input type="text" style="width: 100px;" id="conveneNewUser$i" />' +
						'</td>' +
						'<td>' +
							'Date/Time: <input style="width: 100px;" id="conveneNewDatetime$i" />' +
						'</td>' +
						'<td style="vertical-align: middle;">' +
							'<input type="button" id="conveneNewUserAndDate$i" value="' + tr("Add User & Date") + '" />' +
						'</td>' +
					'</tr>' +
				'</table>').appendTo(this);
				
				$('#conveneNewUser$i').autocomplete({
					source: $existingUsers
				});
				
				$('#conveneNewDatetime$i').datetimepicker();
				
				$('#conveneNewUserAndDate$i').click(function() {
					convene$i.fromBlank($('#conveneNewUser$i').val(), $('#conveneNewDatetime$i').val());
				});
			});
		} else {
			$('#conveneBlank$i').each(function() {
				$('<div />').text(tr("Login to edit Convene")).appendTo(this);
			});
		}
		
		$('.conveneAddDate$i').click(function() {
			var dialogOptions = {
				modal: true,
				title: tr("Add Date"),
				buttons: {}
			};
			
			dialogOptions.buttons[tr("Add")] = function() {
				convene$i.addDate(o.find('input:first').val());
				o.dialog('close');
			}
			
			var o = $('<div><input type="text" style="width: 100%;" /></div>')
				.dialog(dialogOptions);
			
			o.find('input:first')
				.datetimepicker()
				.focus();
			return false;
		});
		
		$('.conveneDeleteDate$i')
			.click(function() {
				convene$i.deleteDate($(this).data("date"));
				return false;
			});
		
		$('.conveneDeleteUser$i')
			.click(function() {
				convene$i.deleteUser($(this).data("user"));
				return false;
			});
		
		$('.conveneUpdateUser$i').toggle(function() {
			$('.conveneUpdateUser$i').not(this).hide();
			$('.conveneDeleteUser$i').hide();
			$('.conveneDeleteDate$i').hide();
			$('.conveneMain$i').hide();
			$(this).parent().parent()
				.addClass('ui-state-highlight')
				.find('td').not(':first')
				.addClass('conveneTd$i')
				.removeClass('ui-state-default')
				.addClass('ui-state-highlight');
			
			$(this).find('img').attr('src', 'img/icons/accept.png');
			var parent = $(this).parent().parent();
			parent.find('.vote').hide();
			parent.find('input').each(function() {
				$('<select>' +
					'<option value="">' + tr('Unconfirmed') + '</option>' +
				    '<option value="-1">' + tr('Not ok') + '</option>' +
				    '<option value="1">' + tr('Ok') + '</option>' +
				'</select>')
					.val($(this).val())
					.insertAfter(this)
					.change(function() {
						var cl = '';

						switch($(this).val() * 1) {
							case 1:     cl = 'convene-ok';break;
							case -1:    cl = 'convene-no';break;
							default:    cl = 'convene-unconfirmed';
						}

						$(this)
							.parent()
							.removeClass('convene-no convene-ok convene-unconfirmed')
							.addClass(cl);

						convene$i.updateUsers = true;
					});
			});
		}, function () {
			$('.conveneUpdateUser$i').show();
			$('.conveneDeleteUser$i').show();
			$('.conveneDeleteDate$i').show();
			$(this).parent().parent()
				.removeClass('ui-state-highlight')
				.find('.conveneTd$i')
				.removeClass('ui-state-highlight')
				.addClass('ui-state-default');
			
			$('.conveneMain$i').show();
			$(this).find('img').attr('src', 'img/icons/pencil.png');
			var parent = $(this).parent().parent();
			parent.find('select').each(function(i) {
				parent.find('input.conveneUserVote$i').eq(i).val( $(this).val() );

				$(this).remove();
			});
			
			if (convene$i.updateUsers) {
				convene$i.updateUsersVotes();
			}
		});
		
		$('.conveneAddUser$i')
			.click(function() {
				if (!$(this).data('clicked')) {
					$(this)
						.data('initval', $(this).val())
						.val('')
						.data('clicked', true);
				}
			})
			.blur(function() {
				if (!$(this).val()) {
					$(this)
						.val($(this).data('initval'))
						.data('clicked', '');

				}
			})
			.keydown(function(e) {
				var user = $(this).val();

				if (e.which == 13) {//enter
					convene$i.addUser(user);
					return false;
				}
			})
			.autocomplete({
				source: $existingUsers
			});

			$('.conveneAddUserButton$i').click(function() {
				convene$i.addUser($('.conveneAddUser$i').val());
			});
		
		$('#pluginConvene$i .icon').css('cursor', 'pointer');
JQ
);
	
	if (empty($dataString)) {
		$result = "<div id='conveneBlank$i'></div>";
	}
	
	return
<<<RETURN
~np~
	<div class="ui-widget-content ui-corner-all">
		<div class="ui-widget-header ui-corner-top">
			<h5 style="margin: 5px;">$title</h5>
		</div>
			$result
	</div>
~/np~
RETURN;
}
예제 #7
0
파일: Builder.php 프로젝트: linuxwhy/tiki-1
 function outputWikiData()
 {
     $result = "type : " . $this->type . "\n";
     foreach (TikiFilter_PrepareInput::delimiter('_')->flatten($this->values) as $key => $value) {
         if (!empty($value)) {
             $result .= $key . ' : ' . $value . "\n";
         }
     }
     return $result;
 }