Commit 8c09e531 authored by Vitaly Lipatov's avatar Vitaly Lipatov

do support for projects with subdirs

parent 283eed00
<?php
function get_site_id($DBH, $url) {
//error_log("\nurl: $url\n");
$mas_url = parse_url($url);
if (!isset($mas_url['host']))
return 0;
$host = $mas_url['host'];
$query_sites = "SELECT sites.id AS id, sites.site AS url FROM sites
WHERE sites.site REGEXP ?";
$STH = $DBH->prepare($query_sites);
$STH->execute(array("^(https?://)*(www.)*" . $host . "/?"));
if ($STH->rowCount() == 0) {
error_log("no host $host");
return 0;
}
$max_id = 0;
$max_len = 0;
while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
//echo $row['id'] . " " . $row['url'] . " in " . $url . "\n";
//preg_match('/(foo)(bar)(baz)/', $row['url'] , $matches
// TODO: сравнивать строки, начиная с ://
$pos = strpos ($url, $row['url']);
$len = strlen($row['url']);
//echo "pos = $pos, len = $len\n";
if ($pos !== false && $max_len < $len) {
$max_id = $row['id'];
$max_len = $len;
}
}
//echo "Result: $max_id, $max_len\n";
return $max_id;
}
/*
// Uncomment for test
require __DIR__ . "/vendor/autoload.php";
require_once('configuration.php');
$DBH = new PDO(DB_DRIVER . ":host=" . DB_HOSTNAME . ";dbname=" . DB_DATABASE, DB_USERNAME, DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
get_site_id($DBH, "https://bogaiskov.ru");
get_site_id($DBH, "https://bogaiskov.ru/test/t1/page.php");
get_site_id($DBH, "https://bogaiskov.ru/dum");
*/
......@@ -12,6 +12,7 @@ header('Access-Control-Allow-Origin: *');
require_once('configuration.php');
require_once('functions.php');
require_once('dbfunctions.php');
require_once('language.php');
require_once('constants.php');
......@@ -70,7 +71,6 @@ $userdata['url'] = getFormatingUrl(rawurldecode(getRequest('url', '')));
$userdata['text'] = htmlspecialchars(rawurldecode(getRequest('text', '')));
$userdata['context'] = htmlspecialchars(rawurldecode(getRequest('context', '')));
/* Парсим сайт для получения коренного сайта */
$mas_url = parse_url($userdata['url']);
if (!isset($mas_url['host'])) {
echoJsonData(array('success' => 'false', 'message' => $_language[$code_language]["error_valid_url"]));
......@@ -87,6 +87,7 @@ if (!isset($mas_url['host'])) {
/* Достаем номер сайта и email-ы пользователей */
try {
/*
$query_emails = "SELECT r.id_site AS id_site,
u.email AS email
FROM users AS u, responsible AS r
......@@ -104,7 +105,19 @@ try {
// 08.06.17: supports every protocol
// ^(https?://)*(www.)*etersoft.com/?$
$STH->execute(array("^(https?://)*(www.)*" . $mas_url["host"] . "/?$"));
*/
$id_site = get_site_id($DBH, $userdata['url']);
$query_emails = "SELECT r.id_site AS id_site,
u.email AS email
FROM users AS u
INNER JOIN responsible AS r ON r.id_user = u.id
WHERE r.id_site = $id_site
AND r.status = '1'";
//error_log($query_emails);
$STH = $DBH->prepare($query_emails);
$STH->execute(array($id_site));
if ($STH->rowCount() > 0) {
$email_users = array();
while ($row = $STH->fetch(PDO::FETCH_ASSOC)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment