Ejemplo n.º 1
0
<?
/**
 *
 * @author Magnus Rosenbaum <*****@*****.**>
 * @package Basisentscheid
 */


require "inc/common_http.php";

$ngroup = Ngroup::get();

if ($action) {
	Login::access_action("member");
	action_required_parameters('area');
	$area = new Area($_POST['area']);
	if (!$area->id) {
		warning("The requested area does not exist!");
		redirect();
	}
	switch ($action) {
	case "subscribe":
		$area->activate_participation();
		redirect();
		break;
	case "unsubscribe":
		$area->deactivate_participation();
		redirect();
		break;
	}
	warning(_("Unknown action"));
Ejemplo n.º 2
0
"><label for="name"><?php 
echo _("Name or location of the ballot");
?>
</label><span class="input"><input type="text" name="name" id="name" value="<?php 
echo h($ballot->name);
?>
"></span></div>
<div class="input <?php 
echo stripes();
?>
"><label for="ngroup"><?php 
echo _("Group of location");
?>
</label><span class="input">
<?
input_select("ngroup", Ngroup::options($period->ngroup()->parent), $ballot->ngroup, 'id="ngroup"');
?>
</span></div>
<div class="input <?php 
echo stripes();
?>
"><label for="opening_hour"><?php 
echo _("Opening hours");
?>
</label><span class="input">
<select name="opening_hour" id="opening_hour">
<?
if ($ballot->opening) {
	list($hour, $minute, $second) = explode(":", $ballot->opening);
} else {
	$hour = 0;
Ejemplo n.º 3
0
?>" class="sub<?
if ($filter=="admitted") { ?> active<? }
?>"><?=_("admitted")?> (<?=$counts['admitted']?>)</a>
	</div>
	<div class="mid">
		<a href="<?=URI::build($params + ['filter'=>"debate"])?>" title="<?
printf(ngettext("%d issue in debate phase", "%d issues in debate phase", $counts['debate']), $counts['debate']);
?>"<?
if ($filter=="debate") { ?> class="active"<? }
?>><?=_("Debate")?> (<?=$counts['debate']?>)</a>
	</div>
	<div class="mid">
		<a href="<?=URI::build($params + ['filter'=>"voting"])?>" title="<?
printf(_("%d issues in voting, %d in voting preparation and %d in counting phase"), $counts['voting'], $counts['preparation'], $counts['counting']);
$nyvic = $ngroup->not_yet_voted_issues_count();
if ($nyvic) { ?> &mdash; <?=Ngroup::not_yet_voted($nyvic); }
?>"<?
if ($filter=="voting") { ?> class="active"<? }
?>><?=_("Voting")?> (<?=($counts['voting']+$counts['preparation']+$counts['counting']);
if ($nyvic) { ?>, <? printf(_("not voted on %d"), $nyvic); }
?>)</a>
	</div>
</div>
<div class="top">
	<div class="mid_dummy">
		<a href="<?=URI::build($params + ['filter'=>"closed"])?>" title="<?
printf(_("%d issues are finished, %d issues are cancelled"), $counts['finished'], $counts['cancelled']);
?>" class="top<?
if ($filter=="closed") { ?> active<? }
?>"><?=_("closed")?> (<?=($counts['finished']+$counts['cancelled'])?>)</a>
	</div>
Ejemplo n.º 4
0
	/**
	 * display Ngroup drop down menu
	 */
	public static function display_switch() {
?>
					<form method="GET" action="<?
		switch (BN) {
			// jump to proposals list if the same page doesn't show the equivalent content in other groups
		case "proposal.php":
		case "proposal_edit.php":
		case "draft.php":
		case "vote.php":
		case "vote_result.php":
			echo "proposals.php";
			$hidden = false;
			break;
		default:
			echo BN;
			// pages with list and edit mode and content depending on the group
		case "periods.php":
		case "admin_areas.php":
			$hidden = array(
				'ngroup' => null, // remove ngroup, because the new ngroup comes from the drop down menu
				'id'     => null  // remove id to go back from edit to list mode
			);
		}
		?>">
						<select name="ngroup" onchange="this.form.submit()" tabindex="2">
<?
		if (Login::$member) {
			$sql = "SELECT ngroup.*, member FROM ngroup
			LEFT JOIN member_ngroup ON member_ngroup.ngroup = ngroup.id AND member_ngroup.member = ".intval(Login::$member->id);
		} else {
			$sql = "SELECT * FROM ngroup";
		}
		$sql .= " ORDER BY name";
		$result = DB::query($sql);
		$ngroups = array();
		while ( $ngroup = DB::fetch_object($result, "Ngroup") ) {
			$ngroups[] = $ngroup;
		}
		$ngroups = Ngroup::parent_sort_active($ngroups);
		// own ngroups
		if (Login::$member) {
?>
							<optgroup label="<?php 
echo _("own groups");
?>
">
<?
			foreach ($ngroups as $ngroup) {
				if (!$ngroup->member) continue;
				// save groups list of the logged in member
				Login::$ngroups[] = $ngroup->id;
				// use the first ngroup as default
				if ($_SESSION['ngroup']==0) $_SESSION['ngroup'] = $ngroup->id;
?>
								<option value="<?php 
echo $ngroup->id;
?>
"<?
				if ($ngroup->id==$_SESSION['ngroup']) { ?> selected class="selected"<? }
				?>>&#9670; <?php 
echo $ngroup->name;
?>
</option>
<?
			}
?>
							</optgroup>
<?
		}
		// other ngroups
?>
							<optgroup label="<?php 
echo Login::$member ? _("other groups") : _("groups");
?>
">
<?
		foreach ($ngroups as $ngroup) {
			// save list of active groups
			Ngroup::$active_ngroups[] = $ngroup->id;
			if (Login::$member and $ngroup->member) continue;
			// use the first ngroup as default
			if ($_SESSION['ngroup']==0) $_SESSION['ngroup'] = $ngroup->id;
?>
								<option value="<?php 
echo $ngroup->id;
?>
"<?
			if ($ngroup->id==$_SESSION['ngroup']) { ?> selected class="selected"<? }
			?>>&#9671; <?php 
echo $ngroup->name;
?>
</option>
<?
		}
?>
							</optgroup>
						</select>
<?
		// add the hidden fields after the drop down menu to have ngroup always in the first place of the GET parameters
		if ($hidden) URI::hidden($hidden);
?>
					</form>
<?
	}
Ejemplo n.º 5
0
<?
/**
 *
 * @author Magnus Rosenbaum <*****@*****.**>
 * @package Basisentscheid
 */


require "inc/common_http.php";

Login::access("admin");

Ngroup::get();

$d = new DbTableAdmin("Area");
$d->columns = array(
	array("id", _("No."), "right", "", false),
	array("name", _("Name"), 'size'=>30, 'required'=>true),
	array("participants", _("Participants"), "center", "", false)
);
$d->enable_filter = false;

$d->global_where = array('ngroup' => $_SESSION['ngroup']);

$d->reference_check = array("SELECT id FROM issue WHERE area=%d");

$d->msg_add_record              = _("New area");
$d->msg_edit_record             = _("Edit area %id%");
$d->msg_record_saved            = _("The new area %id% has been saved.");
$d->msg_really_delete           = _("Do you really want to delete the area %id%?");
$d->msg_record_deleted          = _("The area %id% has been deleted.");
Ejemplo n.º 6
0
	/**
	 * assign all remaining members to their nearest ballots
	 */
	public function assign_members_to_ballots() {

		// get all approved ballots
		$sql_ballot = "SELECT * FROM ballot WHERE period=".intval($this->id)." AND approved=TRUE";
		$result_ballot = DB::query($sql_ballot);
		$ballots = array();
		while ( $ballot = DB::fetch_object($result_ballot, "Ballot") ) {
			$ballots[] = $ballot;
		}

		// If no ballots were approved at all, ballot voting just can not take place.
		if (!$ballots) return;

		// get all ngroups within the ngroup of the period
		$result = DB::query("SELECT * FROM ngroup");
		$ngroups = array();
		while ( $ngroup = DB::fetch_object($result, "Ngroup") ) $ngroups[$ngroup->id] = $ngroup;
		$period_ngroups = Ngroup::parent_sort($ngroups, $ngroups[$this->ngroup]->parent);

		// get all members, who are in the current period not assigned to a ballot yet
		$sql = "SELECT member.* FROM member
			JOIN member_ngroup ON member_ngroup.member = member.id AND member_ngroup.ngroup = ".intval($this->ngroup)."
			LEFT JOIN offlinevoter ON member.id = offlinevoter.member AND offlinevoter.period = ".intval($this->id)."
			WHERE offlinevoter.member IS NULL";
		$result = DB::query($sql);
		while ( $member = DB::fetch_object($result, "Member") ) {

			// get lowest member ngroup (within the ngroup of the period)
			$lowest_member_ngroup = $member->lowest_ngroup($period_ngroups);
			if (!$lowest_member_ngroup) {
				trigger_error("No lowest member ngroup found", E_USER_NOTICE);
				$best_ballots = $ballots;
			} else {

				// rate ballots by distance between member and ballot
				foreach ( $ballots as $ballot ) {

					$ballot_ngroup = $period_ngroups[$ballot->ngroup];
					$ballot->score = 0; // if no matching is found at all

					// climb up from the lowest ngroup of the member until the top
					$reference_member_ngroup = $lowest_member_ngroup;
					do {
						if ( self::ngroup_is_equal_or_child($ballot_ngroup, $reference_member_ngroup, $period_ngroups) ) {
							// Score depends on how far the member has to climb up, but not on how deep the ballot is from there.
							$ballot->score = $reference_member_ngroup->depth;
							break;
						}
					} while (
						$reference_member_ngroup->parent and
						$reference_member_ngroup = $period_ngroups[$reference_member_ngroup->parent] // step up to parent of member ngroup
					);

				}

				// pick ballots with highest score
				$highest_score = 0;
				$best_ballots = array();
				foreach ( $ballots as $ballot ) {
					if ($ballot->score == $highest_score) {
						$best_ballots[] = $ballot;
					} elseif ($ballot->score > $highest_score) {
						$best_ballots = array($ballot);
						$highest_score = $ballot->score;
					}
				}

			}

			// assign member to random of the best ballots
			/** @noinspection PhpUndefinedMethodInspection */
			$best_ballots[rand(0, count($best_ballots)-1)]->assign_member($member);

		}

		$this->update_voters_cache();

	}
Ejemplo n.º 7
0
/**
 * create group and areas
 *
 * @param string  $name
 * @param object  $parent (optional)
 * @return array
 */
function create_ngroup($name, Ngroup $parent=null) {

	$ngroup = new Ngroup;
	$ngroup->id = DB::fetchfield("SELECT max(id) FROM ngroup") + 1;
	$ngroup->name = $name;
	if ($parent) $ngroup->parent = $parent->id;
	$ngroup->active = true;
	$ngroup->minimum_population = 200;
	$ngroup->minimum_quorum_votingmode = 10;
	$ngroup->create(['id', 'name', 'parent', 'active', 'minimum_population', 'minimum_quorum_votingmode']);

	$area = new Area;
	$area->ngroup = $ngroup->id;
	$area->name = "Politik";
	$area->create();
	$area2 = new Area;
	$area2->ngroup = $ngroup->id;
	$area2->name = "Innerparteiliches";
	$area2->create();

	return [$ngroup, $area];
}
Ejemplo n.º 8
0
const DOCROOT = "";

require "inc/config.php";
require "inc/errors.php";
require "inc/common.php";
require "inc/functions.php";
require "inc/functions_http.php";

// buffer output until it either gets displayed on this page or gets written to the session at a redirect
ob_start();

require "inc/locale.php";

Login::init(); // start session

Ngroup::init(); // get current Ngroup

// all actions use this global variable
if (isset($_POST['action'])) $action = $_POST['action']; else $action = null;

// detect CSRF attacks
// To make this work the 'action' parameter should be used on every POST form.
if ($action) {
	if (empty($_POST['csrf'])) {
		error("CSRF token missing in POST request!");
	}
	if ($_POST['csrf'] != $_SESSION['csrf']) {
		error("CSRF token does not match!");
	}
}
Ejemplo n.º 9
0
		<td class="proposals"><a href="proposals.php?ngroup=<?php 
echo $ngroup->id;
?>
"><?php 
echo _("Proposals");
?>
 (<?php 
echo $ngroup->proposals_count();
?>
)</a><?
		if ( $own and Login::$member->eligible and Login::$member->verified and $nyvic = $ngroup->not_yet_voted_issues_count() ) {
			?> <a href="proposals.php?ngroup=<?php 
echo $ngroup->id;
?>
&filter=voting"><?php 
echo Ngroup::not_yet_voted($nyvic);
?>
</a><?
		}
		?></td>
		<td><a href="periods.php?ngroup=<?php 
echo $ngroup->id;
?>
"><?php 
echo _("Periods");
?>
 (<?php 
echo $ngroup->periods_count();
?>
)</a></td>
		<td><a href="areas.php?ngroup=<?php 
Ejemplo n.º 10
0
	for ( $index = 3; $index < count($data); $index++ ) {
		$name = trim($data[$index]);
		if (!$name) continue; // skip empty group names
		if (!isset($ngroup_map[$name])) {
			// get matching group
			$result = DB::query("SELECT * FROM ngroup WHERE name ILIKE ".DB::esc($name));
			if ( $ngroup = DB::fetch_object($result, "Ngroup") ) {
				if ( DB::num_rows($result) > 1 ) {
					echo "WARNING: More than one matching groups for '$name' were found!\n";
				}
				if ($ngroup->parent != $parent) {
					echo "WARNING: The parent of group '$name' is '$ngroup->parent' in the database, but '$parent' in line $line!\n";
				}
			} else {
				// create group that does not yet exist
				$ngroup = new Ngroup;
				$ngroup->name   = $name;
				$ngroup->parent = $parent;
				$ngroup->create(['name', 'parent']);
				echo "Created group '$name'\n";
			}
			$ngroup_map[$name] = $ngroup->id;
		}
		$ngroups[] = $ngroup_map[$name];
		$parent    = $ngroup_map[$name];
	}

	$sql = "SELECT * FROM member WHERE invite=".DB::esc($invite);
	DB::transaction_start();
	$result = DB::query($sql);
	if ( $member = DB::fetch_object($result, "Member") ) {
Ejemplo n.º 11
0
/**
 * head part of the page and not yet displayed output
 *
 * @param string  $title
 * @param boolean $help  (optional) display a help block next to <h1>
 */
function html_head($title, $help=false) {

	$output = ob_get_clean();

	// we use HTML 5
?>
<!DOCTYPE html>
<html lang="<?=LANG?>">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title><?=h(TITLE." - ".$title)?></title>
	<link rel="stylesheet" media="all" href="css/style.css?<?=version()?>">
<?
	if (Login::$admin) {
?>
	<link rel="stylesheet" media="all" href="css/admin.css?<?=version()?>">
<?
	}
	// generated by http://realfavicongenerator.net/
	// If the installation is in a subfolder, all these icons and favicon.ico have to be either copied to the webroot or deleted from this html head.
?>
	<link rel="apple-touch-icon" sizes="57x57"   href="/apple-touch-icon-57x57.png">
	<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
	<link rel="apple-touch-icon" sizes="72x72"   href="/apple-touch-icon-72x72.png">
	<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
	<link rel="apple-touch-icon" sizes="60x60"   href="/apple-touch-icon-60x60.png">
	<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
	<link rel="apple-touch-icon" sizes="76x76"   href="/apple-touch-icon-76x76.png">
	<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
	<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
	<link rel="icon" type="image/png" href="/favicon-192x192.png" sizes="192x192">
	<link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160">
	<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
	<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
	<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
	<meta name="msapplication-TileColor" content="#603cba">
	<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<?
	// end of favicons
?>
	<!--[if lt IE 9]>
	<script src="js/html5shiv-printshiv.js"></script>
	<![endif]-->
</head>
<body>

<?
	if (DEBUG) {
?>
<!--
<?=strtr( print_r(
				array(
					'BN'          => BN,
					'REQUEST_URI' => $_SERVER['REQUEST_URI'],
					'GET'         => $_GET,
					'POST'        => $_POST,
					'SESSION'     => $_SESSION
				),
				true ), array("<!--"=>"<!-", "-->"=>"->") );
		unset($_SESSION['redirects']);
?>
-->
<?
	}
?>

<header>
	<a href="index.php" id="logo" tabindex="-1"><img src="img/logo.png" width="58" height="50" alt=""></a>
	<div id="header">
		<div id="user">
			<? html_user(); ?>
		</div>
		<nav>
			<ul>
				<li><a href="index.php" id="home" tabindex="1">Basisentscheid</a></li>
				<li>
<?
	Ngroup::display_switch();
?>
				</li>
<?
	navlink('proposals.php', _("Proposals"), true);
	navlink('periods.php', _("Periods"), true);
	if (Login::$admin) {
		navlink('admin_areas.php', _("Areas"), true);
	} else {
		navlink('areas.php', _("Areas"), true);
	}
?>
			</ul>
			<ul class="manual">
<?
	navlink('manual.php', _("Manual"));
?>
			</ul>
<?
	if (Login::$admin) {
?>
			<ul class="admin">
<?
		navlink('admin_members.php', _("Members"));
		navlink('admins.php', _("Admins"));
		navlink('admin_ngroups.php', _("Groups"));
?>
			</ul>
<?
	}
?>
		</nav>
		<div class="rclear"></div>
	</div>
</header>

<h1><?=$title?></h1>
<?
	if ($help) help("", true);
?>
<div class="clearfix"></div>
<?

	// show MOTD once for each session and always on the home page
	if (
		defined("MOTD") and
		// display it always on the home page
		(empty($_SESSION['motd_seen']) or BN=="index.php") and
		// never display it on these pages
		BN != "register.php" and
		BN != "reset_password.php" and
		BN != "request_password_reset.php" and
		BN != "confirm_mail.php"
	) {
?>
<section class="motd"><?=MOTD?></section>
<?
		$_SESSION['motd_seen'] = true;
	}

	// not yet displayed output from previous page with redirect
	if (isset($_SESSION['output'])) {
		if ($_SESSION['output']) {
?>
<section class="messages"><?=$_SESSION['output']?></section>
<div class="clearfix"></div>
<?
		}
		unset($_SESSION['output']);
	}

	session_write_close(); // release session lock

	// output from before the html head
	if ($output) {
?>
<section class="messages"><?=$output?></section>
<div class="clearfix"></div>
<?
	}

	$GLOBALS['html_head_issued'] = true;
}