Exemplo n.º 1
0
 private function get_where_clauses($live_only)
 {
     $where_clauses = array();
     if ($live_only) {
         array_push($where_clauses, array("leaflet.live", "=", 1));
     }
     $this->election_id = get_election_id($this->election_id);
     array_push($where_clauses, array("leaflet_election.election_id", "=", $this->election_id));
     //required
     array_push($where_clauses, array("leaflet_image.sequence", "=", 1));
     //optional
     if (isset($this->publisher_party_id) && $this->publisher_party_id != '' && $this->publisher_party_id != 0) {
         array_push($where_clauses, array("publisher_party_id", "=", $this->publisher_party_id));
     }
     if (isset($this->party_attack_id) && $this->party_attack_id != '' && $this->party_attack_id != 0) {
         array_push($where_clauses, array("leaflet_party_attack.party_id", "=", $this->party_attack_id));
     }
     if (isset($this->category_id) && $this->category_id != '' && $this->category_id != 0) {
         array_push($where_clauses, array("leaflet_category.category_id", "=", $this->category_id));
     }
     if (isset($this->constituency_id) && $this->constituency_id != '' && $this->constituency_id != 0) {
         array_push($where_clauses, array("leaflet_constituency.constituency_id", "=", $this->constituency_id));
     }
     if (isset($this->tag) && $this->tag != '') {
         array_push($where_clauses, array("tag.tag", "=", $this->tag));
     }
     return $where_clauses;
 }
 public static function example_postcode()
 {
     $election_id = get_election_id($election_id);
     $search = factory::create('search');
     $result = $search->search("australian_postcode", array(array('election_id', '=', $election_id)), null, null, null, 1);
     return $result[0]->postcode;
 }
Exemplo n.º 3
0
 function bind()
 {
     $this->page_title = "Election leaflets by category";
     $search = factory::create('search');
     $election_id = get_election_id();
     // Get categories
     $categories = $search->search_cached("category", array(array("category_election.election_id", "=", $election_id)), 'AND', array(array("category_election", "inner")), array(array('name', "ASC")));
     $this->assign("categories", $categories);
 }
Exemplo n.º 4
0
 function bind()
 {
     $this->page_title = "Election leaflets by party";
     $search = factory::create('search');
     //get top parties
     $election_id = get_election_id();
     $parties = $search->search_cached("party", array(array("party_election.election_id", "=", $election_id)), "AND", array(array("party_election", "inner")), array(array("name", "ASC")));
     $this->assign("parties", $parties);
 }
Exemplo n.º 5
0
 public function get_weighted_tags($limit = 100, $election_id = null)
 {
     $election_id = get_election_id($election_id);
     $sql = "SELECT tag.tag, tag.tag_id, COUNT(leaflet_tag.leaflet_id) AS count FROM tag ";
     $sql .= "INNER JOIN leaflet_tag ON tag.tag_id = leaflet_tag.tag_id ";
     $sql .= "INNER JOIN leaflet ON leaflet_tag.leaflet_id=leaflet.leaflet_id ";
     $sql .= "INNER JOIN leaflet_election ON leaflet.leaflet_id=leaflet_election.leaflet_id ";
     $sql .= "WHERE leaflet.live=1 AND leaflet_election.election_id={$election_id} ";
     $sql .= "GROUP BY tag.tag, tag.tag_id ORDER BY COUNT(leaflet_tag.leaflet_id) DESC LIMIT " . $limit;
     return $this->execute($sql);
 }
Exemplo n.º 6
0
 public function count_live($cache = true, $election_id = null)
 {
     $election_id = get_election_id($election_id);
     $return = array();
     $sql = "SELECT COUNT(leaflet.leaflet_id) AS count FROM leaflet JOIN leaflet_election ON leaflet.leaflet_id = leaflet_election.leaflet_id WHERE leaflet.live = 1 AND leaflet_election.election_id = {$election_id}";
     if ($cache) {
         $return = $this->execute_cached($sql);
     } else {
         $return = $this->execute($sql);
     }
     return $return[0]->count;
 }
Exemplo n.º 7
0
 public function get_category_count($date_since, $limit = 10, $cache = true, $election_id = null)
 {
     $election_id = get_election_id($election_id);
     $return = array();
     $category = factory::create('category');
     $sql = "SELECT COUNT(leaflet_category.leaflet_category_id) as count, category.name, category.category_id FROM category ";
     $sql .= "INNER JOIN leaflet_category ON category.category_id = leaflet_category.category_id ";
     $sql .= "INNER JOIN leaflet ON leaflet_category.leaflet_id = leaflet.leaflet_id ";
     $sql .= "INNER JOIN leaflet_election ON leaflet_election.leaflet_id = leaflet.leaflet_id ";
     $sql .= "WHERE date_delivered > '{$date_since}' AND leaflet.live=1 AND leaflet_election.election_id = {$election_id} ";
     $sql .= "GROUP BY category.name, category.category_id ORDER BY COUNT(leaflet_category.leaflet_category_id) DESC LIMIT " . $limit;
     if ($cache) {
         $return = $category->execute_cached($sql);
     } else {
         $return = $category->execute($sql);
     }
     return $return;
 }
Exemplo n.º 8
0
 public static function get_constituency_count($date_since, $limit = 10, $cache = true, $election_id = null)
 {
     $election_id = get_election_id($election_id);
     $return = array();
     $constituency = factory::create('constituency');
     $sql = "SELECT COUNT(leaflet_constituency.leaflet_constituency_id) AS count, constituency.name, constituency.url_id, constituency.constituency_id FROM constituency ";
     $sql .= "INNER JOIN leaflet_constituency ON constituency.constituency_id = leaflet_constituency.constituency_id ";
     $sql .= "INNER JOIN leaflet ON leaflet_constituency.leaflet_id = leaflet.leaflet_id ";
     $sql .= "INNER JOIN leaflet_election ON leaflet_election.leaflet_id = leaflet.leaflet_id ";
     $sql .= "WHERE date_delivered > '{$date_since}' AND leaflet.live=1 AND leaflet_election.election_id = {$election_id} ";
     $sql .= "GROUP By constituency.name, constituency.constituency_id ";
     $sql .= "ORDER BY count(leaflet_constituency.leaflet_constituency_id) desc limit " . $limit;
     if ($cache) {
         $return = $constituency->execute_cached($sql);
     } else {
         $return = $constituency->execute($sql);
     }
     return $return;
 }
Exemplo n.º 9
0
 function bind()
 {
     if ($this->constituencies) {
         $s = "";
         foreach ($this->constituencies as $c) {
             $s = $s . '<li><a href="' . $c->url_id . '">' . $c->name . '</a></li>';
         }
         $this->add_warning("There are several electorates within postcode " . $this->postcode . ". Choose from one of the following: <ul>" . $s . "</ul>");
     } else {
         if ($this->has_search) {
             $this->add_warning("sorry, we couldn't find a constituency for you");
         }
     }
     $search = factory::create('search');
     $election_id = get_election_id();
     $constituencies = $search->search_cached("constituency", array(array("constituency_election.election_id", "=", $election_id)), "AND", array(array("constituency_election", "inner")), array(array("name", "ASC")));
     $this->assign("constituencies", $constituencies);
     # Set example postcode for display on the page
     $australian_postcode = factory::create("australian_postcode");
     $this->assign("example_postcode", $australian_postcode->example_postcode());
 }
Exemplo n.º 10
0
 public function display_template()
 {
     $this->smarty->assign("site_name", SITE_NAME);
     $this->smarty->assign("site_tag_line", SITE_TAG_LINE);
     if (defined('BANNER')) {
         $this->smarty->assign("banner", BANNER);
     }
     $this->smarty->assign("root_dir", ROOT_DIR);
     $this->smarty->assign("www_server", WWW_SERVER);
     $this->smarty->assign("domain", DOMAIN);
     $this->smarty->assign("area_names", AREA_NAMES);
     $this->smarty->assign("leaflets_email", LEAFLETS_EMAIL);
     $this->smarty->assign("secure_server", SECURE_SERVER);
     $this->smarty->assign("form_action", htmlspecialchars($_SERVER['PHP_SELF']) . '?' . $_SERVER["QUERY_STRING"]);
     $this->smarty->assign("onloadscript", $this->onloadscript);
     if (sizeof($this->warn_controls) == 0) {
         $this->smarty->assign("set_focus_control", $this->set_focus_control);
     } else {
         $this->smarty->assign("set_focus_control", $this->warn_controls[0]);
     }
     $this->smarty->assign("elections", $this->get_elections());
     $this->smarty->assign("warnings", $this->warnings);
     $this->smarty->assign("messages", $this->messages);
     $this->smarty->assign("data", $this->data);
     $this->smarty->assign("show_warnings", sizeof($this->warnings) > 0);
     $this->smarty->assign("show_messages", sizeof($this->messages) > 0);
     $this->smarty->assign("warn_controls", $this->warn_controls);
     $this->smarty->assign("page_title", htmlspecialchars($this->page_title));
     $this->smarty->assign("menu_item", $this->menu_item);
     $this->smarty->assign("tracker_location", $this->tracker_location);
     $this->smarty->assign("show_tracker", $this->show_tracker);
     $this->smarty->assign("viewstate", $this->serialize_viewstate());
     $this->smarty->assign("rss_link", $this->rss_link);
     $this->smarty->assign("current_url", $this->get_url());
     $this->smarty->assign("current_page", htmlspecialchars($_SERVER['PHP_SELF']));
     $this->smarty->assign("has_map", $this->has_map);
     $this->smarty->assign("has_upload", $this->has_upload);
     $this->smarty->assign("google_maps_key", GOOGLE_MAPS_KEY);
     $this->smarty->assign("map_provider", MAP_PROVIDER);
     $this->smarty->assign("google_analytics_tracker", GOOGLE_ANALYTICS_TRACKER);
     // Get the name of the current election, probably a more
     // efficient way to do this somehow
     $search = factory::create("search");
     $result = $search->search("election", array(array("election_id", "=", get_election_id())));
     $this->smarty->assign("current_election", $result[0]->name);
     foreach ($this->warn_controls as $warn_control) {
         $this->assign('warn_' . $warn_control, true);
     }
     //register the image url function
     $this->smarty->register_function('image_url', 'get_image_url');
     $this->smarty->display($this->smarty_template);
 }
Exemplo n.º 11
0
 private function get_vars()
 {
     $election_id = get_election_id();
     //page count
     $page = get_http_var("page");
     if (isset($page) && is_numeric($page) && $page > 0) {
         $page = floor($page);
     } else {
         $page = 1;
     }
     $this->leaflet_search->start = (floor($page) - 1) * PAGE_ITEMS_COUNT;
     //search term
     $search_term = get_http_var("q");
     if (isset($search_term) && $search_term != '') {
         $this->search_term = trim($search_term);
     }
     $publisher_party_url_id = get_http_var("p");
     if (isset($publisher_party_url_id) && $publisher_party_url_id != '') {
         $search = factory::create('search');
         $results = $search->search_cached('party', array(array('url_id', '=', $publisher_party_url_id)));
         if (count($results) != 1) {
             throw_404();
         }
         $this->leaflet_search->publisher_party_id = $results[0]->party_id;
     }
     $category_id = get_http_var("c");
     if (isset($category_id) && $category_id != '') {
         $this->leaflet_search->category_id = trim($category_id);
     }
     $tag = get_http_var("t");
     if (isset($tag) && $tag != '') {
         $this->leaflet_search->tag = trim($tag);
     }
     $party_attack_id = get_http_var("a");
     if (isset($party_attack_id) && $party_attack_id != '') {
         $this->leaflet_search->party_attack_id = trim($party_attack_id);
     }
     $constituency_url_id = trim(get_http_var("n"));
     if (isset($constituency_url_id) && $constituency_url_id != '') {
         $search = factory::create('search');
         $results = $search->search_cached('constituency', array(array("url_id", "=", $constituency_url_id), array("constituency_election.election_id", "=", $election_id)), "AND", array(array("constituency_election", "inner")));
         if (count($results) != 1) {
             throw_404();
         }
         $this->leaflet_search->constituency_id = $results[0]->constituency_id;
     }
     $is_rss = get_http_var("rss");
     if (isset($is_rss) && $is_rss != '') {
         $this->is_rss = true;
     }
     // If RSS, get a different number of items
     if ($this->is_rss) {
         $this->leaflet_search->number = RSS_ITEMS_COUNT;
     } else {
         $this->leaflet_search->number = PAGE_ITEMS_COUNT;
     }
 }
Exemplo n.º 12
0
 public function get_party_count($date_since, $limit = 10, $cache = true)
 {
     $election_id = get_election_id($election_id);
     $return = array();
     $party = factory::create('party');
     $sql = "SELECT party.name, party.party_id, party.url_id, party.colour, COUNT(leaflet.leaflet_id) as count FROM leaflet ";
     $sql .= "INNER JOIN party on leaflet.publisher_party_id = party.party_id ";
     $sql .= "INNER JOIN leaflet_election ON leaflet.leaflet_id = leaflet_election.leaflet_id ";
     $sql .= "WHERE date_uploaded > '{$date_since}' AND leaflet.live=1 AND leaflet_election.election_id = {$election_id} ";
     $sql .= "GROUP BY party.name, party.party_id, party.colour ";
     $sql .= "ORDER BY COUNT(leaflet.leaflet_id) DESC LIMIT " . $limit;
     if ($cache) {
         $return = $party->execute_cached($sql);
     } else {
         $return = $party->execute($sql);
     }
     return $return;
 }
Exemplo n.º 13
0
 function validate()
 {
     $this->election_id = get_election_id();
     if (!isset($this->data['txtTitle']) || $this->data['txtTitle'] == '') {
         $this->add_warning('Please add a title for this leaflet');
         $this->add_warn_control('txtTitle');
     }
     if (!isset($this->data['ddlPartyBy']) || $this->data['ddlPartyBy'] == '') {
         $this->add_warning('Please specify the party responsible for this leaflet');
         $this->add_warn_control('ddlPartyBy');
     }
     if (!isset($this->data['txtName']) || $this->data['txtName'] == '') {
         $this->add_warning('Please add your name');
         $this->add_warn_control('txtName');
     }
     if (!isset($this->data['txtEmail']) || $this->data['txtEmail'] == '' || !valid_email($this->data['txtEmail'])) {
         $this->add_warning('Please add a valid email address');
         $this->add_warn_control('txtEmail');
     }
     //TODO: handle non-UK postcodes
     if (!isset($this->data['txtPostcode']) || $this->data['txtPostcode'] == '') {
         $this->add_warning('Please add a post code for this leaflet');
         $this->add_warn_control('txtPostcode');
     } else {
         if (!is_postcode($this->data['txtPostcode'])) {
             $this->add_warning('Please enter a valid postcode');
             $this->add_warn_control('txtPostcode');
         } else {
             $geocoder = factory::create('geocoder');
             $postcode = trim($this->data['txtPostcode']);
             $success = $geocoder->set_from_postcode($postcode, COUNTRY_CODE_TLD);
             if (!$success) {
                 $this->add_warning('Sorry, we couldn\'t locate that postcode');
                 $this->add_warn_control('txtPostcode');
             } else {
                 $this->lng = $geocoder->lng;
                 $this->lat = $geocoder->lat;
             }
             if (strlen(trim($this->data['ddlConstituencyHint'])) > 0) {
                 $this->data['ddlConstituency'] = $this->data['ddlConstituencyHint'];
             }
             //Convert postcode to electorate
             $australian_postcode = factory::create('australian_postcode');
             $names = $australian_postcode->lookup_constituency_names($postcode);
             if (isset($this->data['ddlConstituency'])) {
                 if (in_array($this->data['ddlConstituency'], $names)) {
                     $name = $this->data['ddlConstituency'];
                 } else {
                     $this->add_warning("The postcode and electorate don't match up. Are you sure you got them both correct?");
                     $this->add_warn_control('txtPostcode');
                     $this->add_warn_control('ddlConstituency');
                 }
             } else {
                 if (count($names) == 0) {
                     $this->add_warning("The postcode is in not in a valid electorate.");
                     $this->add_warn_control('ddlConstituency');
                 } else {
                     if (count($names) == 1) {
                         $name = $names[0];
                     } else {
                         $this->add_warning("The postcode is in more than one electorate. Please an electorate below.");
                         $this->add_warn_control('ddlConstituency');
                     }
                 }
             }
             if ($name) {
                 $search = factory::create('search');
                 $result = $search->search("constituency", array(array("name", "=", $name), array("constituency_election.election_id", "=", $this->election_id = get_election_id())), "AND", array(array("constituency_election", "inner")));
                 if (count($result) == 1) {
                     $this->constituency_id = $result[0]->constituency_id;
                 }
             }
         }
     }
     return count($this->warnings) == 0;
 }