function searchMasses($args, $offset = 0, $limit = 20)
{
    $return = array('offset' => $offset, 'limit' => $limit);
    $where = array(" m.torles = '0000:00:00 00:00:00' ");
    //templomok
    if (isset($args['templom']) and is_numeric($args['templom'])) {
        $where[] = ' m.tid = ' . $args['templom'];
    } elseif ($args['varos'] != '' or $args['kulcsszo'] != '' or $args['egyhazmegye'] != '' or $args['gorog'] == 'gorog' or $args['hely'] != '' or $args['tnyelv'] != '0') {
        if ($args['varos'] == 'Budapest') {
            $args['varos'] = 'Budapest*';
        }
        $tmp = $args;
        if (isset($tmp['leptet'])) {
            unset($tmp['leptet']);
        }
        if (isset($tmp['min'])) {
            unset($tmp['min']);
        }
        $results = searchChurches($args, 0, 1000000);
        $tids[] = 0;
        if (isset($results['results'])) {
            foreach ($results['results'] as $r) {
                $tids[] = $r['id'];
            }
        }
        $where[] = " m.tid IN (" . implode(",", $tids) . ")";
    }
    if ($args['gorog'] == 'gorog') {
        $where[] = "egyhazmegye IN (17,18)";
    }
    //milyen nap
    if ($args['mikor'] == 'x') {
        $args['mikor'] = $args['mikordatum'];
    }
    $where[] = "m.nap IN ('" . date('N', strtotime($args['mikor'])) . "',0)";
    //milyen időszakban
    $day = date('m-d', strtotime($args['mikor']));
    $where[] = "( ( m.tmp_datumtol <= '" . $day . "' AND '" . $day . "' <= m.tmp_datumig AND m.tmp_relation = '<'  )\n    OR  ( ( m.tmp_datumig <= '" . $day . "' OR '" . $day . "' <= m.tmp_datumtol ) AND ( m.tmp_relation = '>' ) )  \n    OR ( m.tmp_datumig = '" . $day . "' AND m.tmp_datumig = '" . $day . "' AND  m.tmp_relation = '=' ) )";
    //milyen héten
    if (date('W', strtotime($args['mikor'])) & 1) {
        $parossag = 'pt';
    } else {
        $parossag = "ps";
    }
    $hanyadikP = getWeekInMonth($args['mikor']);
    $hanyadikM = getWeekInMonth($args['mikor'], '-');
    $where[] = "( m.nap2 IN ('','0','" . $hanyadikM . "','" . $hanyadikP . "','" . $parossag . "') OR m.nap2 IS NULL)";
    //milyen órákban
    if ($args['mikor2'] == 'de') {
        $where[] = " m.ido < '12:00:01' AND m.ido > '00:00:01' ";
    } elseif ($args['mikor2'] == 'du') {
        $where[] = " m.ido > '11:59:59'";
    } elseif ($args['mikor2'] == 'x') {
        $idok = explode('-', $args['mikorido']);
        $where[] = " m.ido >= '" . $idok[0] . ":00'";
        $where[] = " m.ido <= '" . $idok[1] . ":00'";
    }
    //LANGUAGES
    $languages = unserialize(LANGUAGES);
    foreach ($languages as $abbrev => $attribute) {
        if ($attribute['abbrev'] != 'h') {
            $nothu[] = $abbrev;
        }
    }
    if ($args['nyelv'] != '0' and $args['nyelv'] != '') {
        if ($args['nyelv'] == 'h') {
            $where[] = "( m.nyelv REGEXP '(^|,)(" . $args['nyelv'] . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' OR \n                templomok.orszag = 12 AND m.nyelv NOT REGEXP '(^|,)(" . implode("|", $nothu) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' )";
        } else {
            $where[] = "( m.nyelv REGEXP '(^|,)(" . $args['nyelv'] . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' )";
        }
    }
    //ATTRIBUTES
    $attributes = unserialize(ATTRIBUTES);
    //age group (checkbox)
    if (isset($args['kor'])) {
        foreach ($attributes as $abbrev => $attribute) {
            if ($attribute['group'] == 'age') {
                $ages[] = $abbrev;
            }
        }
        $wherekor = array();
        foreach ($args['kor'] as $kor) {
            if (in_array($kor, $ages)) {
                $wherekor[] = " m.milyen REGEXP '(^|,)(" . $kor . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
            } elseif ($kor == 'na') {
                $wherekor[] = " m.milyen NOT REGEXP '(^|,)(" . implode('|', $ages) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
            }
        }
        $where[] = " ( " . implode(' OR ', $wherekor) . ") ";
    }
    //music group (chekbox)
    if (isset($args['zene'])) {
        foreach ($attributes as $abbrev => $attribute) {
            if ($attribute['group'] == 'music') {
                $musics[] = $abbrev;
            }
        }
        $wherezene = array();
        foreach ($args['zene'] as $zene) {
            if (in_array($zene, $musics)) {
                $wherezene[] = " m.milyen REGEXP '(^|,)(" . $zene . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
            } elseif ($zene == 'na') {
                $wherezene[] = " m.milyen NOT REGEXP '(^|,)(" . implode("|", $musics) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
            }
        }
        $where[] = " ( " . implode(' OR ', $wherezene) . ") ";
    }
    //rite group (select)
    if ($args['ritus'] != '0') {
        if ($args['ritus'] == 'gor') {
            foreach ($attributes as $abbrev => $attribute) {
                if ($attribute['group'] == 'liturgy' and $attribute['isitmass'] == true and $attribute['abbrev'] != 'gor') {
                    $notgor[] = $abbrev;
                }
            }
            $where[] = "( m.milyen REGEXP '(^|,)(gor)([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' OR \n                        ( (egyhazmegye = 17 OR egyhazmegye = 18 ) AND m.milyen NOT REGEXP '(^|,)(" . implode("|", $notgor) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ) )";
        } elseif ($args['ritus'] == 'rom') {
            foreach ($attributes as $abbrev => $attribute) {
                if ($attribute['group'] == 'liturgy' and $attribute['isitmass'] == true and $attribute['abbrev'] != 'rom') {
                    $notrom[] = $abbrev;
                }
            }
            $where[] = "( (m.milyen NOT REGEXP '(^|,)(" . implode("|", $notrom) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' AND egyhazmegye NOT IN (17,18)) OR \n                        ( egyhazmegye IN (17,18) AND m.milyen REGEXP '(^|,)(rom)([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ) )";
        } else {
            $where[] = " m.milyen REGEXP '(^|,)(" . $args['ritus'] . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
        }
    }
    //liturgy (not mass) group (checkbox/radio)
    $not = $only = array();
    foreach ($attributes as $abbrev => $attribute) {
        if ($attribute['group'] == 'liturgy' and $attribute['isitmass'] == false) {
            $not[$abbrev] = $abbrev;
        }
    }
    if (isset($args['liturgy'])) {
        foreach ($args['liturgy'] as $liturgy) {
            if (isset($not[$liturgy])) {
                unset($not[$liturgy]);
            }
        }
    }
    if (count($not) > 0) {
        $where[] = " m.milyen NOT REGEXP '(^|,)(" . implode('|', $not) . ")([0]{0,1}|" . $hanyadikP . "|" . $hanyadikM . "|" . $parossag . ")(,|\$)' ";
    }
    $select = "SELECT m.*,templomok.nev,templomok.ismertnev,templomok.varos,templomok.letrehozta \nFROM misek m \n";
    $select .= " LEFT JOIN templomok ON m.tid = templomok.id \n";
    //Tudjuk meg, hogy hány templomban van megfelelő összesen
    $query = "SELECT count(*) as sum FROM ( \n";
    $query .= $select;
    if (count($where) > 0) {
        $query .= " WHERE " . implode("\n AND ", $where);
    }
    $query .= "\n GROUP BY tid \n";
    $query .= ") groups ;";
    if (!($lekerdez = mysql_query($query))) {
        echo "HIBA a templom keresőben!<br>{$query}<br>" . mysql_error();
    }
    $row = mysql_fetch_row($lekerdez, MYSQL_ASSOC);
    $return['sum'] = $row['sum'];
    //Akkor jöhet a limitált csoportos lekérdezés, mert az jó
    $query = $select;
    $query .= " JOIN ( ";
    $query .= $select;
    if (count($where) > 0) {
        $query .= " WHERE " . implode(' AND ', $where);
    }
    $query .= " GROUP BY tid \n";
    $query .= " ORDER BY ido, templomok.varos, templomok.nev ";
    $query .= " LIMIT " . $offset . "," . $limit;
    $query .= ") groups ON groups.tid = m.tid ";
    if (count($where) > 0) {
        $query .= " WHERE " . implode(' AND ', $where);
    }
    $query .= " ORDER BY ido, templomok.varos, templomok.nev ";
    if (!($lekerdez = mysql_query($query))) {
        echo "HIBA a templom keresőben!<br>{$query}<br>" . mysql_error();
    }
    $masses = array();
    //echo $query;
    while ($row = mysql_fetch_row($lekerdez, MYSQL_ASSOC)) {
        if ($row['tmp_datumtol'] == $row['tmp_datumig']) {
            $type = 'particulars';
        } else {
            $type = 'periods';
        }
        $masses[$row['tid']][$type][$row['idoszamitas']][] = $row;
    }
    //use particulars only, if we can
    foreach ($masses as $tid => $church) {
        if (array_key_exists("particulars", $church)) {
            $masses[$tid] = $church['particulars'];
        } elseif (array_key_exists("periods", $church)) {
            $masses[$tid] = $church['periods'];
        }
    }
    // weight
    foreach ($masses as $tid => $periods) {
        $weight = 0;
        $tmp = array();
        foreach ($periods as $period) {
            $m = array_shift(array_values($period));
            $w = $m['weight'];
            if ($w == '') {
                $w = 0;
            }
            if ($w >= $weight) {
                $tmp = $period;
                $weight = $w;
            }
        }
        $return['churches'][$tid] = array_shift(array_values($tmp));
        //ezt szebben is lehetne
        $return['churches'][$tid]['masses'] = $tmp;
    }
    /* */
    //echo "<pre>".print_r($return,1); exit;
    return $return;
}
 public function __construct()
 {
     global $user, $config;
     $query = "select id,nev from egyhazmegye where ok='i' order by sorrend";
     $lekerdez = mysql_query($query);
     while (list($id, $nev) = mysql_fetch_row($lekerdez)) {
         $ehmT[$id] = $nev;
     }
     $query = "select id,ehm,nev from espereskerulet";
     $lekerdez = mysql_query($query);
     while (list($id, $ehm, $nev) = mysql_fetch_row($lekerdez)) {
         $espkerT[$ehm][$id] = $nev;
     }
     $varos = $_POST['varos'];
     $kulcsszo = $_POST['kulcsszo'];
     $ehm = $_POST['ehm'];
     //	$megye=$_POST['megye'];
     if (empty($_POST['espker'])) {
         $espkerpT = $_POST['espkerT'];
         $espker = $espkerpT[$ehm];
     } else {
         $espker = $_POST['espker'];
     }
     //Templom űrlap
     $templomurlap = "\n<div style='display: none'><form method=post><input type=hidden name=m_id value=26><input type=hidden name=m_op value=keres></div>";
     $templomurlap .= "<input type=hidden id=keresestipus name=keresestipus value=0>";
     //$templomurlap .= "<input type=hidden name=tavolsag id=tavolsag size=20 class=keresourlap value='".$_REQUEST['tavolsag']."'>";
     //$templomurlap .= "<input type=hidden name=hely id=tavolsag size=20 class=keresourlap value='".$_REQUEST['hely']."'>";
     $templomurlap .= "\n<img src=img/space.gif width=5 height=10><br><span class=kiscim>Település: </span><input type=text name=varos id=varos size=20 class=keresourlap value='{$varos}'><br><img src=img/space.gif width=5 height=8>";
     $templomurlap .= "<br><span class=kiscim>Kulcsszó: </span><input type=text name=kulcsszo size=20 class=keresourlap value='{$kulcsszo}'><br><img src=img/space.gif width=5 height=8>";
     //Egyházmegye
     $templomurlap .= "<br><span class=kiscim>Egyházmegye: </span><br><img src=img/space.gif width=5 height=5><br><img src=img/space.gif width=10 height=5><select name=ehm class=keresourlap onChange=\"if(this.value!=0) {";
     foreach ($ehmT as $id => $nev) {
         $templomurlap .= "document.getElementById({$id}).style.display='none'; ";
     }
     $templomurlap .= "document.getElementById(this.value).style.display='inline'; document.getElementById('valassz').style.display='none'; } else {";
     foreach ($ehmT as $id => $nev) {
         $templomurlap .= "document.getElementById({$id}).style.display='none'; ";
     }
     $templomurlap .= "document.getElementById('valassz').style.display='inline';}\"><option value=0>mindegy</option>";
     foreach ($ehmT as $id => $nev) {
         $templomurlap .= "<option value={$id}";
         if ($id == $ehm) {
             $templomurlap .= ' selected';
         }
         $templomurlap .= ">{$nev}</option>";
         if ($id == $ehm) {
             $espkerurlap .= "<select id={$id} name=espkerT[{$id}] class=keresourlap style='display: inline'><option value=0>mindegy</option>";
         } else {
             $espkerurlap .= "<select id={$id} name=espkerT[{$id}] class=keresourlap style='display: none'><option value=0>mindegy</option>";
         }
         if (is_array($espkerT[$id])) {
             foreach ($espkerT[$id] as $espid => $espnev) {
                 $espkerurlap .= "<option value={$espid}";
                 if ($espker == $espid) {
                     $espkerurlap .= ' selected';
                 }
                 $espkerurlap .= ">{$espnev}</option>";
             }
         }
         $espkerurlap .= "</select>";
     }
     $templomurlap .= "</select><br><img src=img/space.gif width=5 height=8>";
     //Espereskerület
     $templomurlap .= "<br><span class=kiscim>Espereskerület: </span><br><img src=img/space.gif width=5 height=5><br><img src=img/space.gif width=10 height=5>";
     if (empty($ehm)) {
         $templomurlap .= "<div id='valassz' style='display: inline' class=keresourlap>Először válassz egyházmegyét.</div>";
     }
     $templomurlap .= $espkerurlap;
     $templomurlap .= "<br><img src=img/space.gif width=5 height=8>";
     $templomurlap .= "\n<br><img src=img/space.gif width=5 height=10><div align=right><input type=submit value=keresés class=keresourlap><br><img src=img/space.gif width=5 height=10></div><div style='display: none'></form></div>";
     $postdata .= "<input type=hidden name=varos value='{$varos}'>";
     $postdata .= "<input type=hidden name=tavolsag value='" . $_REQUEST['tavolsag'] . "'>";
     $postdata .= "<input type=hidden name=hely value='" . $_REQUEST['hely'] . "'>";
     $postdata .= "<input type=hidden name=kulcsszo value='{$kulcsszo}'>";
     $postdata .= "<input type=hidden name=gorog value='" . $_REQUEST['gorog'] . "'>";
     $postdata .= "<input type=hidden name=tnyelv value='" . $_REQUEST['tnyelv'] . "'>";
     $postdata .= "<input type=hidden name=espker value='{$espker}'>";
     $postdata .= "<input type=hidden name=ehm value='{$ehm}'>";
     $min = $_POST['min'];
     $leptet = $_POST['leptet'];
     if ($min < 0 or empty($min)) {
         $min = 0;
     }
     if (empty($leptet)) {
         $leptet = 20;
     }
     $results = searchChurches($_POST, $min, $leptet);
     $mennyi = $results['sum'];
     if ($mennyi == 1) {
         //ga('send','event','Outgoing Links','click','".$pleb_url."');
         //header ("Location: ?templom=".$talalat['id']);
         echo "\n        <script type='text/javascript'>\n            (function(i,s,o,g,r,a,m){i[\"GoogleAnalyticsObject\"]=r;i[r]=i[r]||function(){\n\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n  })(window,document,\"script\",\"//www.google-analytics.com/analytics.js\",\"ga\");\n\n    ga(\"create\", \"UA-3987621-4\", \"miserend.hu\");\n    ga('send','event','Search','fast','" . $varos . $kulcsszo . $ehm . "');\n    \n    window.location = '?templom=" . $results['results'][0]['id'] . "';\n           \n         </script>";
         die;
     }
     $kezd = $min + 1;
     $veg = $mennyi;
     if ($min > 0) {
         $leptetprev .= "\n<form method=post><input type=hidden name=m_id value=26><input type=hidden name=m_op value=keres>";
         $leptetprev .= $postdata;
         $leptetprev .= "<input type=hidden name=min value={$prev}>";
         $leptetprev .= "\n<input type=submit value=Előző class=urlap><input type=text size=2 value={$leptet} name=leptet class=urlap></form>";
     }
     if ($mennyi > $leptet) {
         $veg = $min + $leptet;
         $prev = $min - $leptet;
         if ($prev < 0) {
             $prev = 0;
         }
         $next = $min + $leptet;
         if ($mennyi > $min + $leptet) {
             $leptetnext .= "\n<form method=post><input type=hidden name=m_id value=26><input type=hidden name=m_op value=keres><input type=hidden name=min value={$next}>";
             $leptetnext .= $postdata;
             $leptetnext .= "\n<input type=submit value=Következő class=urlap><input type=text size=2 value={$leptet} name=leptet class=urlap></form>";
         }
     }
     $tartalom .= "<span class=alap>Összesen: {$mennyi} találat<br>Listázás: {$kezd} - {$veg}</span><br><br>";
     if ($mennyi > 0) {
         foreach ($results['results'] as $templom) {
             $tid = $templom['id'];
             $tnev = $templom['nev'];
             $tismertnev = $templom['ismertnev'];
             $tvaros = $templom['varos'];
             $letrehozta = $templom['letrehozta'];
             $tartalom .= "<a href=?templom={$tid} class=felsomenulink title='{$tismertnev}'><b>{$tnev}</b> <font color=#8D317C>({$tvaros})</font></a>";
             if ($user->checkRole('miserend') or $letrehozta == $user->login) {
                 $tartalom .= " <a href=?m_id=27&m_op=addtemplom&tid={$tid}><img src=img/edit.gif title='szerkesztés' align=absmiddle border=0></a> <a href=?m_id=27&m_op=addmise&tid={$tid}><img src=img/mise_edit.gif align=absmiddle border=0 title='mise módosítása'></a>";
             }
             if ($tismertnev != '') {
                 $tartalom .= "<br/><span class=\"alap\" style=\"margin-left: 20px; font-style: italic;\">" . $tismertnev . "</span>";
             }
             $tartalom .= "<br><img src=img/space.gif width=4 height=5><br>";
         }
         $tartalom .= '<br>' . $leptetprev . $leptetnext;
     } else {
         $tartalom .= '<span class=alap>A keresés nem hozott eredményt</span>';
     }
     $focim = "Keresés a templomok között";
     $variables = array('focim' => $focim, 'content' => $tartalom, 'templomurlap' => $templomurlap, 'design_url' => $config['path']['domain']);
     $variables['template'] = 'search/resultsChurches.twig';
     foreach ($variables as $key => $var) {
         $this->{$key} = $var;
     }
 }
Exemple #3
0
<?php

if (isset($_REQUEST['update'])) {
    updateOverpass();
    exit;
}
$vars['title'] = 'JOSM összeköttetés';
$vars['template'] = 'layout_simpliest';
if (isset($_REQUEST['nosuccess'])) {
    $nosuccess = "&nosuccess";
}
$churches = searchChurches(array());
if (isset($_REQUEST['page']) and is_numeric($_REQUEST['page'])) {
    $offset = $_REQUEST['page'];
} else {
    $offset = 0;
}
if (isset($_REQUEST['limit']) and is_numeric($_REQUEST['limit'])) {
    $limit = $_REQUEST['limit'];
} else {
    $limit = 30;
}
$query1 = "SELECT t.id FROM templomok t \n\t            LEFT JOIN osm ON osm.tid = t.id \n\t            WHERE osm.type IS NULL and ok = 'i' \n\t\t\t\tORDER BY t.id LIMIT " . $limit . " OFFSET " . $limit * $offset . " ;";
$query = "SELECT t.id FROM templomok t \n\t            WHERE  ok = 'i' \n\t\t\t\tORDER BY t.id  ASC LIMIT " . $limit . " OFFSET " . $limit * $offset . " ;";
if ($nosuccess) {
    $query = $query1;
}
$result = mysql_query($query);
$tmp = array();
while ($row = mysql_fetch_assoc($result)) {
    $tmp[] = $row['id'];