/** * read record from database (again) * * @param integer $id (optional) only needed on new reads */ public function read($id=0) { if (!$id) $id = $this->id; $sql = "SELECT * FROM $this->table WHERE id=".intval($id); if ( ! $row = DB::fetchassoc($sql) ) return; foreach ( $row as $key => $value ) $this->$key = $value; foreach ( $this->boolean_fields as $key ) DB::to_bool($this->$key); // reset dependent attributes foreach ( $this->dependent_attributes as $attribute ) $this->$attribute = null; }
/** * get the current notification settings * * @return array */ public function notification_settings() { $notify = Notification::$default_settings; $sql = "SELECT * FROM notify WHERE member=".intval($this->id); $result = DB::query($sql); while ( $row = DB::fetch_assoc($result) ) { foreach (Notification::$default_settings['all'] as $type => $dummy) DB::to_bool($row[$type]); $notify[$row['interest']] = $row; } return $notify; }
/** * called by cli/cron.php */ function cron() { // If called by a regular cron job it's no problem to skip it sometimes. if (BN=="cron.php") { if (!cron_lock()) return; } else { while (!cron_lock()) { echo "Waiting for lock ...\n"; sleep(5); } } $sql_period = "SELECT *, debate <= now() AS debate_now, preparation <= now() AS preparation_now, voting <= now() AS voting_now, ballot_assignment <= now() AS ballot_assignment_now, ballot_preparation <= now() AS ballot_preparation_now, counting <= now() AS counting_now FROM period"; $result_period = DB::query($sql_period); while ( $period = DB::fetch_object($result_period, "Period") ) { /** @var Period $period */ DB::to_bool($period->debate_now); DB::to_bool($period->preparation_now); DB::to_bool($period->voting_now); DB::to_bool($period->ballot_assignment_now); DB::to_bool($period->ballot_preparation_now); DB::to_bool($period->counting_now); $issues_start_debate = array(); $issues_start_voting = array(); $issues_finished_voting = array(); // ballots switch ($period->state) { // ballot assignment case "ballot_application": if (!$period->ballot_assignment_now) break; $period->assign_members_to_ballots(); $sql_ballot = "SELECT * FROM ballot WHERE period=".intval($period->id); $result_ballot = DB::query($sql_ballot); while ( $ballot = DB::fetch_object($result_ballot, "Ballot") ) { // notification to the ballot agents whether the ballot was approved // TODO: more than one ballot agent $notification = new Notification("ballot_approved"); $notification->period = $period; $notification->ballot = $ballot; $sql = "SELECT member FROM offlinevoter WHERE ballot = ".intval($ballot->id)." AND agent = TRUE"; $recipients = DB::fetchfieldarray($sql); $notification->send($recipients); if (!$ballot->approved) continue; // notification to the members to which ballots they were assigned $notification = new Notification("ballot_assigned"); $notification->period = $period; $notification->ballot = $ballot; $sql = "SELECT member FROM offlinevoter WHERE ballot = ".intval($ballot->id); $recipients = DB::fetchfieldarray($sql); $notification->send($recipients); } $period->state = "ballot_assignment"; $period->update(["state"]); break; // ballot preparation case "ballot_assignment": if (!$period->ballot_preparation_now) break; // final upload of the complete postal and ballot voters if ( upload_voters($period, true) ) { $period->state = "ballot_preparation"; $period->update(["state"]); } // ballot_preparation is the final state. } // proposals and issues $sql_issue = "SELECT * FROM issue WHERE period=".intval($period->id)." AND state NOT IN ('finished', 'cancelled')"; $result_issue = DB::query($sql_issue); while ( $issue = DB::fetch_object($result_issue, "Issue") ) { /** @var Issue $issue */ switch ($issue->state) { // debate case "entry": if (!$period->debate_now) break; $all_proposals_revoked = true; $admitted_proposals = false; $not_admitted_proposals = false; foreach ( $issue->proposals() as $proposal ) { /** @var Proposal $proposal */ if ($proposal->state_cancelled()) continue; //if ( $proposal->check_proponents() ) { $all_proposals_revoked = false; if ($proposal->state=="admitted") $admitted_proposals = true; else $not_admitted_proposals = true; /*} else { // revoke proposals without proponents $proposal->state = "revoked"; $proposal->update(["state"]); }*/ } if ($all_proposals_revoked) { $issue->cancel(); break; } // None of the proposals are admitted yet. if (!$admitted_proposals) break; if ($not_admitted_proposals) { /* split issue $new_issue = new Issue; $new_issue->area = $issue->area; $new_issue->create(); foreach ( $issue->proposals() as $proposal ) { if ($proposal->state_cancelled()) continue; if ($proposal->state=="admitted") continue; $proposal->issue = $new_issue->id; $proposal->update(["issue"]); }*/ // cancel proposals foreach ( $issue->proposals() as $proposal ) { /** @var $proposal Proposal */ if ($proposal->state_cancelled()) continue; if ($proposal->state=="admitted") continue; $proposal->cancel("cancelled_debate"); } } $issue->state = "debate"; $issue->update(["state"], 'debate_started=now()'); $issues_start_debate[] = $issue; break; // preparation case "debate": if (!$period->preparation_now) break; // revoke proposals, which were scheduled for revokation revoke_before_preparation($issue); // don't proceed to preparation if all proposals were cancelled if ($issue->state == "cancelled") break; $issue->state = "preparation"; $issue->update(["state"], 'preparation_started=now()'); break; // voting case "preparation": if (!$period->voting_now) break; // collect issues for online voting start if ( !$issue->votingmode_offline() ) $issues_start_voting[] = $issue; // Issues which reached offline voting, stay in preparation state until an admin enters the voting result. break; // counting case "voting": if (!$period->counting_now) break; $issue->state = "counting"; $issue->update(["state"], 'counting_started=now()'); $issue->counting(); $issue->finish(); $issues_finished_voting[] = $issue; remove_inactive_participants($period->ngroup); break; // "finished" and "cancelled" are the final issue states. } } // debate start notifications if ($issues_start_debate) { $notification = new Notification("debate"); $notification->period = $period; $notification->issues = $issues_start_debate; $notification->send(); } // voting finished notifications if ($issues_finished_voting) { $notification = new Notification("finished"); $notification->period = $period; $notification->issues = $issues_finished_voting; $notification->send(); } // start voting and send individual notifications with tokens if ($issues_start_voting) $period->start_voting($issues_start_voting); } cron_unlock(); }
/** * make lists of supporters and proponents and find out if the logged in member is supporter or proponent * * @return array */ public function supporters() { $supporters = array(); // list of supporters as strings $proponents = array(); // list of proponents (also unconfirmed) as objects of class member $is_supporter = false; // if the logged in member is supporter $is_proponent = false; // if the logged in member is confirmed proponent $is_valid = false; // if the logged in member is valid supporter $sql = "SELECT member, anonymous, proponent, proponent_confirmed, ".$this->sql_supporter_valid()." AS valid FROM supporter WHERE proposal=".intval($this->id); $result = DB::query($sql); while ( $row = DB::fetch_assoc($result) ) { DB::to_bool($row['proponent_confirmed']); DB::to_bool($row['valid']); $expired = $row['valid'] ? "" : " expired"; $member = new Member($row['member']); if (Login::$member and $member->id==Login::$member->id) { if ($row['proponent_confirmed']) { $is_proponent = true; $is_supporter = true; $supporters[] = '<span class="self'.$expired.'">'.content2html($row['proponent']).' <i>('._("proponent").')</i></span>'; } elseif ($row['anonymous']===DB::value_true) { $is_supporter = "anonymous"; $supporters[] = '<span class="self'.$expired.'">'._("anonymous").'</span>'; } else { $is_supporter = true; $supporters[] = '<span class="self'.$expired.'">'.$member->link().'</span>'; } $is_valid = $row['valid']; } else { if ($row['proponent_confirmed']) { if ($row['valid']) $supporters[] = $row['proponent'].' <i>('._("proponent").')</i>'; else $supporters[] = '<span class="expired">'.content2html($row['proponent']).' <i>('._("proponent").')</i></span>'; } elseif ($row['anonymous']===DB::value_true) { if ($row['valid']) $supporters[] = _("anonymous"); else $supporters[] = '<span class="expired">'._("anonymous").'</span>'; } else { if ($row['valid']) $supporters[] = $member->link(); else $supporters[] = '<span class="expired">'.$member->link().'</span>'; } } if ($row['proponent']!==null) { $member->proponent_name = $row['proponent']; $member->proponent_confirmed = $row['proponent_confirmed']; $proponents[] = $member; } } return array($supporters, $proponents, $is_supporter, $is_proponent, $is_valid); }
/** * display a list of voting mode votes * * @param resource $result * @param string $token (optional) token of the logged in member for highlighting */ public static function display_votingmode_votes($result, $token="") { ?> <table class="votes"> <tr><th><?=_("Vote token")?></th><th><?=_("Voting time")?></th><th><?=_("Demands offline voting")?></th></tr> <? // votes $previous_token = null; while ( $row = DB::fetch_assoc($result) ) { DB::to_bool($row['demand']); ?> <tr class="<?=stripes(); // highlight votes of the logged in member if ($token == $row['token']) { ?> self<? } // strike through votes, which have been overridden by a later vote if ($row['token'] == $previous_token) { ?> overridden<? } else $previous_token = $row['token']; ?>"><td><?=$row['token']?></td><? ?><td class="tdc"><?=date(VOTETIME_FORMAT, strtotime($row['votetime']))?></td><? ?><td><? display_checked($row['demand']) ?></td><? ?></tr> <? } ?> </table> <? }
*/ require "inc/common_http.php"; Login::logout(); $invite = trim(@$_GET['invite']); if ($invite) { $sql = "SELECT *, now() > invite_expiry AS invite_expired FROM member WHERE invite=".DB::esc($invite)." AND activated IS NULL"; $result = DB::query($sql); $member = DB::fetch_object($result, "Member"); if ($member) { DB::to_bool($member->invite_expired); if ($member->invite_expired) { warning(sprintf(_("The code you've entered is expired! Please contact %s to get a new one!"), MAIL_SUPPORT), true); $member = false; } } else { warning(_("The code you've entered is invalid!")); } } else { $member = false; } if (!$member) { html_head(_("Registration"));
$period = new Period(@$_GET['period']); if (!$period->id) { error("The requested period does not exist!"); } $_SESSION['ngroup'] = $period->ngroup; if (!$period->ballot_voting) { warning("There is no ballot voting available in this period!"); redirect("periods.php?ngroup=".$_SESSION['ngroup']."&hl=".$period->id); } if (Login::$member) { $sql = "SELECT * FROM offlinevoter WHERE member=".intval(Login::$member->id)." AND period=".intval($period->id); if ( $row_voters = DB::fetchassoc($sql) ) { DB::to_bool($row_voters['agent']); } } if ($action) { switch ($action) { case "select": Login::access_action("entitled", $_SESSION['ngroup']); action_required_parameters('ballot'); $ballot = new Ballot($_POST['ballot']); if (!$ballot->id) { warning("The requested area does not exist!"); redirect(); } if ($period->state=="ballot_preparation") { warning(_("In ballot preparation phase it is not allowed anymore to select or change the ballot."));