// Ìîäóëü, ñîäåðæàùèé "îáùåóïîòðåáèòåëüíûå" ôóíêöèè:
header("Content-Type: text/html; charset=utf-8");
require_once "include/sql.php";
require_once "include/interfaces.php";
function DogBlock ($id, $addinfo = FALSE) {
$outtext .= "
";
}
function Page_AuthForm($userid = FALSE) {
GLOBAL $if;
if($userid) {
$outtext .= "{$if['mess_user_authorized']} ".ShowNames($userid,'users').".";
}
else {
$outtext .= " ";
}
return $outtext;
}
function Page_Title($userid = FALSE) {
GLOBAL $if;
$outtext = "";
GLOBAL $if;
$outtext .= "
";
$outtext .= "";
$outtext .= "  | ";
$outtext .= " {$if['title_header']} | ";
$outtext .= " ";
$outtext .= " ";
$outtext .= Page_AuthForm($userid);
$outtext .= " ";
$outtext .= " ";
$outtext .= " | ";
$outtext .= "
";
$outtext .= "
";
$outtext .= "
";
return $outtext;
}
function LangUrl($urlstr, $langid = 1) {
$islang = strpos($urlstr, 'userif');
$isq = strpos($urlstr, '?');
if($islang !== FALSE)
$urlstr[$islang+7] = $langid;
elseif($isq)
$urlstr = $urlstr ."&userif=$langid";
else
$urlstr = $urlstr ."?userif=$langid";
return $urlstr;
}
function Page_Menu($userid = FALSE) {
GLOBAL $if;
$ustr = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$outtext .= "";
return $outtext;
}
function Page_Alphabet() {
$outtext .= "";
return $outtext;
}
function Page_Operations($id = FALSE, $userid = FALSE, $div = TRUE) {
GLOBAL $if;
if($div)
$outtext .= "";
if($userid) {
if($id) {
$tmp = data_select(
array('sex' => 0, 'fatherid' => 0, 'motherid' => 0, 'breeder' => 0, 'kennelid' => 0, 'datebirth' => 0),
array('id' => (int)$id),
'dogs');
if($tmp['sex'] == 2)
$male = TRUE;
else
$male=FALSE;
$lmstr = ($tmp['fatherid']?"fatherid={$tmp['fatherid']}":"");
$lmstr = ($lmstr?"&":"").($tmp['motherid']?"motherid={$tmp['motherid']}":"");
}
if(is_admin($userid))
$rc = data_select(array('COUNT(id)' => 'cnt'), array('active' => 0), 'dogs');
$outtext .= "
";
$outtext .= "";
$outtext .= " | "; // добавление �обак
$outtext .= " ";
$outtext .= " | ";
$outtext .= " "; // вы�тавки
$outtext .= " ";
$outtext .= " | ";
$outtext .= " "; // �правочники
$outtext .= " ";
$outtext .= " | ";
if(is_admin($userid)) {
$outtext .= " "; // �и�темные �правочники
$outtext .= " ";
$outtext .= " | ";
}
$outtext .= " "; // �лужебные
$outtext .= " ";
$outtext .= " | ";
$outtext .= "
";
$outtext .= "
";
}
else
$outtext .= "";
if($div)
$outtext .= "
";
return $outtext;
}
function Page_Search () {
GLOBAL $if;
$outtext .= "";
$outtext .= Page_BaseSearch();
$outtext .= Page_AdvSearch();
$outtext .= "
";
return $outtext;
}
function Page_BaseSearch() {
GLOBAL $if;
$outtext .= "";
return $outtext;
}
function Page_AdvSearch () {
GLOBAL $if;
$outtext .= "";
return $outtext;
}
function FormHeader($id = FALSE, $userid = FALSE, $jq = FALSE) {
GLOBAL $if;
LiteHeader($id, $jq);
echo Page_Menu($userid);
echo Page_Title($userid);
echo Page_Operations($id, $userid);
echo Page_Alphabet();
echo Page_Search();
echo "";
};
function FormEnding($userid = FALSE) {
GLOBAL $if;
echo "
";
/*
echo "";
*/
echo "";
echo "
";
echo "";
echo "";
echo <<
EOT;
echo " | ";
echo "";
echo "Web scripts ''Virtual breed database 2.0'' - Copyright ©, 2004-".date(Y)." Y.Semenov - All rights reserved. // Site opens 14, august 2018";
echo " | ";
echo "
";
echo "
";
echo "
";
LiteEnding();
}
function LiteEnding() {
echo "";
echo "";
}
function FormFeedback() {
GLOBAL $if;
$outtext .= "";
return $outtext;
}
function Title($title, $context) {
$retstr .= "";
$retstr .= "
$title";
if($context <> "") {
$retstr .= "
";
$retstr .= " ";
$retstr .= " $context";
$retstr .= " ";
$retstr .= "
";
}
$retstr .= "
";
return $retstr;
}
function TitleBlock($title, $links, $text = FALSE, $pre_lenght = 86, $cssid = FALSE) {
if(is_array($links))
foreach($links as $name => $url)
$context .= ($context?" / ":""). "$name";
else
$context = $links;
$retstr .= title($title, $context);
$retstr .= "$text
";
return $retstr;
};
function InfoBlock($title, $links, $text = FALSE, $pre_lenght = FALSE, $cssid = FALSE) {
$retstr .= "";
$retstr .= "
$title";
$retstr .= ($links?"
$links
":"");
$retstr .= "";
$retstr .= $text;
$retstr .= "
";
return $retstr;
};
function DictBlock($title, $text = FALSE, $cssid = FALSE) {
$retstr .= "\n";
$retstr .= "
$title
\n";
$retstr .= $text;
$retstr .= "\n";
return $retstr;
};
function TwoColumns($c1, $c2) {
echo "";
echo "";
echo " | $c1 | ";
echo " $c2 | ";
echo "
";
echo "
";
};
?>
// Ìîäóëü, ñîäåðæàùèé ôóíêöèè äëÿ ðàáîòû ñ Ðîäîñëîâíûìè è èõ ïîñòðîåíèÿ
require_once "include/common.php";
require_once "include/interfaces.php";
require_once "include/sql.php";
function PdCount($id,$level,$carr, $base=FALSE) {
SQLConn();
$qstr = "SELECT d.fatherid, d.motherid FROM dogs as d WHERE d.id=$id";
$dta=mysql_query($qstr);
if(!$row) {
if(!$dta) $row=array('fatherid'=>'','motherid'=>'');
else $row=mysql_fetch_array($dta);
};
if(!IsActive($row['fatherid'])) $row['fatherid']="" ;
if(!IsActive($row['motherid'])) $row['motherid']="" ;
if($id && $base != $carr[$id]['base']) { $carr[$id]['count']++; $carr[$id]['base'] = $base; }
if($level) {
$carr = PdCount($row['fatherid'],$level-1,$carr,$id);
$carr = PdCount($row['motherid'],$level-1,$carr,$id);
};
return $carr;
};
function PdColors($carr) {
$clarr = array (
1 => '#FFC9C9',
2 => '#FFF4C9',
3 => '#F4FF7C',
4 => '#D3FFB3',
5 => '#B3FFF9',
6 => '#B3D1FF',
7 => '#D3BBFF',
8 => '#B3FFD3',
9 => '#FFBBF1',
10 => '#DEF8B1');
if(is_array($carr))
foreach($carr as $cid => $cc) {
if($cc['count'] < 2) unset($carr[$cid]); }
$i = 1;
if(is_array($carr))
foreach($carr as $cid => $cc) {
$carr[$cid] = $clarr[$i];
$i++;
};
return $carr;
}
function Pedigree($id, $level=3, $params = FALSE, $carr = FALSE) {
// ïðîâåðêà ìàññèâ ïàðàìåòðîâ îôîðìëåíèÿ
if(!$params) $params = array();
if(!$params['size']) $params['size'] = '8.0pt';
if(!$params['font']) $params['font'] = 'Tahoma';
if(!isset($params['dataset'])) {
$ds['rkf'] = FALSE;
$ds['hd'] = TRUE;
$ds['titles'] = TRUE;
$ds['study'] = TRUE;
$ds['owner'] = FALSE;
$ds['height'] = FALSE;
$ds['country'] = TRUE;
$ds['year'] = FALSE;
$ds['col'] = TRUE;
}
else
$ds = $params['dataset'];
GLOBAL $if;
GLOBAL $userid;
SQLConn();
if(is_admin($userid))
$qstr = "SELECT d.cid, d.sex, d.fatherid, d.motherid, d.datebirth, d.rkf, ".(($if['id'] == 1)?"countries.name":"countries.little")." as cname, d.owner, ".(($if['id']==1)?"d.name AS dogname":"d.engname AS dogname").", dg.gene_k FROM dogs as d LEFT JOIN countries ON d.countryid=countries.id LEFT JOIN dogs_gene AS dg ON d.id=dg.dogid WHERE d.id=$id";
else
$qstr = "SELECT d.cid, d.sex, d.fatherid, d.motherid, d.datebirth, d.rkf, countries.little, d.owner, ".(($if['id']==1)?"d.name AS dogname":"d.engname AS dogname")." FROM dogs as d LEFT JOIN countries ON d.countryid=countries.id WHERE d.id=$id";
$dta=mysql_query($qstr);
if(!$row) {
if(!$dta) $row=array('fatherid'=>'','motherid'=>'');
else $row=mysql_fetch_array($dta);
};
if(!IsActive($row['fatherid'])) $row['fatherid']="" ;
if(!IsActive($row['motherid'])) $row['motherid']="" ;
if($carr[$id]) $bgcol = $carr[$id]; else $bgcol = "#ffffff";
if($params['ph'] && file_exists("ph/$id-0.jpg"))
$p_link = "
";
if($ds['rkf']) $rkfstr = ShowRKF($id);
// if($ds['hd']) $hdstr = ShowHealth($id);
if($hdstr) $hdstr = "$hdstr";
if($ds['titles']) $titstr = ShowTitles($id,", ",5);
if($ds['study']) $titstr .= ($titstr?"
":"").ShowStudy($id, ', ');
if($ds['height']) {
$dm = data_select('tall', array('dogid' => $id), 'dogsize');
$sizestr = $dm['tall'];
}
if($ds['country'] && $row['cname']) $countrystr = $row['cname'];
if($row['datebirth']) $year = substr($row['datebirth'],0,4);
if($year == "0000" || !$ds['year']) $year = FALSE;
if($ds['col'] && $row['cid']) $colstr = "
".ShowNames($row['col'], 'colors', ($if['id']==1)?FALSE:TRUE);
if(is_admin($userid) && $row['gene_k'] > 0)
$genestr = "".ShowNames($row['gene_k'], 'gen_k')."
";
$retstr .= "".
$p_link.
($titstr?"$titstr ":"").
"".
DogFullName($id,TRUE,$addinfo, array('color' => '#0000ff')).
"".
" ".
"".
($rkfstr?"$rkfstr":"").
($hdstr?", $hdstr":"").
(($row['owner'] && $ds['owner'])?" ".str_replace("&", "&", $row['owner'])."":"").
($sizestr?"$sizestr cm ":"").
($countrystr?"$countrystr ":"").
($year?"$year ":"").
$colstr.
"$genestr";
$retstr .= " | \n";
if($level)
$retstr = $retstr.Pedigree($row['fatherid'],$level-1,$params,$carr).Pedigree($row['motherid'],$level-1,$params,$carr);
else
$retstr = $retstr . "\n";
return $retstr;
};
function InbreedSort($carr) {
if(is_array($carr) && count($carr) > 0) {
foreach($carr AS $k => $v)
$ord[$k] = $v['level'];
asort($ord);
foreach($ord AS $k => $v)
$ord[$k] = $carr[$k];
}
else
$ord = $carr;
return $ord;
}
function InbreedStr($carr, $ceil = "; ") {
if(is_array($carr))
foreach($carr AS $id => $ci)
if($ci['count']>1) $retstr .= DogFullName($id, TRUE, FALSE, array('upper' => TRUE))." - ".$ci['str'].$ceil;
return $retstr;
}
function Inbreed($id, $level=5, $carr, $base=FALSE, $step = 0) {
SQLConn();
$qstr = "SELECT d.fatherid, d.motherid FROM dogs as d WHERE d.id=$id";
$dta=mysql_query($qstr);
if(!$row) {
if(!$dta) $row=array('fatherid'=>'','motherid'=>'');
else $row=mysql_fetch_array($dta);
};
if(!IsActive($row['fatherid'])) $row['fatherid'] = "" ;
if(!IsActive($row['motherid'])) $row['motherid'] = "" ;
if($id && ($base != $carr[$id]['base'] || !$base)) {
$carr[$id]['count']++;
$carr[$id]['str'] .= ($carr[$id]['str']?" , ":"").$step;
$carr[$id]['base'] = $base;
// äîáàâèì õðàíåíèå ìèíèìàëüíîãî óðîâíÿ âõîæäåíèÿ èíáðèäèíãà - ÷òîáû ïîòîì ñîðòèðîâàòü
if(!$carr[$id]['level'] || ($carr[$id]['level'] > $step)) $carr[$id]['level'] = $step;
}
if($level) {
$carr = Inbreed($row['fatherid'], $level-1, $carr, $id, $step + 1);
$carr = Inbreed($row['motherid'], $level-1, $carr, $id, $step + 1);
};
return $carr;
};
function InbreedArray($da, $level = 4, $base = 1) {
$fib_array = Inbreed($da['fatherid'],$level,FALSE,FALSE,$base);
$mib_array = Inbreed($da['motherid'],$level,FALSE,FALSE,$base);
if(is_array($fib_array))
foreach($fib_array as $fid => $fi) {
if(!$mib_array[$fid] || $mib_array[$fid]['base'] == $fi['base'])
unset($fib_array[$fid]);
else {
$fib_array[$fid]['str'] .= " : ".$mib_array[$fid]['str'];
$fib_array[$fid]['count'] += $mib_array[$fid]['count'];
$fib_array[$fid]['level'] = min($fib_array[$fid]['level'],$mib_array[$fid]['level']);
}
}
return $fib_array;
}
function PedigreeArray($id, $level, $ar) {
$n = count($ar) + 1;
$ar[$n]['pid'] = $id;
$ar[$n]['level'] = $level;
if($level<4) {
$r = data_select(array('fatherid' => 0, 'motherid' => 0), array('id' => $id), 'dogs');
if($r['fatherid'])
$ar = PedigreeArray($r['fatherid'], $level + 1, $ar);
if($r['motherid'])
$ar = PedigreeArray($r['motherid'], $level + 1, $ar);
}
return $ar;
}
function PedigreeDBupdate($id, $ar) {
$id = (int)$id;
mysql_query("DELETE FROM pd WHERE id = $id");
foreach($ar as $n => $el)
mysql_query("INSERT INTO pd VALUES($id, $n, {$el['level']}, {$el['pid']})");
}
function PedigreesAll() {
$dtd = mysql_query("SELECT id, fatherid, motherid FROM dogs ORDER BY id LIMIT 12000, 2000");
while($r = mysql_fetch_array($dtd)) {
$ar = array();
$ar = PedigreeArray($r['fatherid'], 1, $ar);
$ar = PedigreeArray($r['motherid'], 1, $ar);
PedigreeDBupdate($r['id'], $ar);
}
}
function PedigreeUpdateOffsprings($id) {
$id = (int)$id;
$dtd = mysql_query("SELECT d.id, d.fatherid, d.motherid FROM dogs AS d, pd AS p WHERE d.id=p.id AND p.pid=$id AND p.level<=3");
while($r = mysql_fetch_array($dtd)) {
$ar = array();
$ar = PedigreeArray($r['fatherid'], 1, $ar);
$ar = PedigreeArray($r['motherid'], 1, $ar);
PedigreeDBupdate($r['id'], $ar);
}
}
?>