require_once("dumper.php"); function OrderColumsAdmins($name) { global $module,$SORTLIST_IN_TABLEDEFFIELD; $S = '
'; $S .= ''; if (($_SESSION['sort'] == 'desc') and (($_SESSION['sortby'] == $name) or (empty($_SESSION['sortby']) and $name == $SORTLIST_IN_TABLEDEFFIELD))) $S .= ''; else $S .= ''; $S .= '
'; $S .= ''; if (($_SESSION['sort'] == 'asc') and (($_SESSION['sortby'] == $name) or (empty($_SESSION['sortby']) and $name == $SORTLIST_IN_TABLEDEFFIELD))) $S .= ''; else $S .= ''; $S .= '

'; return $S; } function openpage($link) { $fd = @fopen($link, "r"); $text=""; if (!$fd) return -1; else { while (!feof ($fd)) { $text .= fgets($fd, 4096); } } fclose ($fd); return $text; } function getInfoByName($module,$name) { list($type,$table,$ntable,$nntable) = explode('_',$name); $Arr = array(); $Arr['table'] = $table; switch($type) { case 'mselect': include('include/parts/'.$module.'.php'); $Arr['doptable'] = $names[$ntable]; break; } return $Arr; } function ImgView($img,$default) { if (file_exists($img)) echo(''); else echo($default); } include_once('usersfunctions.php'); include_once('ctrlsfunctions.php'); include_once('adminfunctions.php'); include_once('formfunctions.php'); function FastQuery($name,$id,$field = 'id') { global $sql; $pr = GetPrefix($name); $qry = 'select * from '.$pr.'_'.$name.' where '.$field.'="'.$id.'"'; $row = $sql->fetch_one($qry); return $row; } function FastQueryArray($name,$id,$field = 'id',$doptable='') { global $sql; $pr = GetPrefix($name); $qry = 'select * from '.$pr.'_'.$name.$doptable.' where '.$field.'="'.$id.'"'; $row = $sql->fetch_array($qry); return $row; } function AddHistory($idt,$table,$user,$userid,$chA='1',$lang) { return; global $sql,$prefix; $query = "create table if not exists ".$prefix."_history( id int(11) unsigned NOT NULL auto_increment, idt int(11) not null, lang varchar(3) not null default 'ru', module varchar(20) not null, userid int(11) not null, user varchar(50) not null, isadmin int(1), changedatetime datetime, PRIMARY KEY (id), UNIQUE KEY id (id), KEY `view` (`module`,`idt`,`lang`), KEY `date` (`changedatetime`) ) DEFAULT CHARSET=utf8"; $sql->query($query); if (!empty($idt) and !empty($table) and !empty($user) and !empty($userid) and !empty($lang)) { $qry = 'select id from '.$prefix.'_history where idt="'.StringToSave($idt).'" and lang="'.StringToSave($lang).'" and module="'.StringToSave($table).'" and user="'.StringToSave($user).'" and userid="'.StringToSave($userid).'" and isadmin="'.StringToSave($chA).'" order by changedatetime desc limit 2'; $row = $sql->fetch_array($qry); if (count($row) > 1) { $query = "update ".$prefix."_history set changedatetime='".date("Y-m-d H:i:s")."' where id='".$row[0]['id']."'"; $sql->query($query); $res = $row[0]['id']; } else { $query = "insert into ".$prefix."_history (idt,lang,module,user,userid,isadmin,changedatetime) values( '".StringToSave($idt)."', '".StringToSave($lang)."', '".StringToSave($table)."', '".StringToSave($user)."', '".StringToSave($userid)."', '".StringToSave($chA)."', '".date("Y-m-d H:i:s")."' )"; $sql->query($query); $res = $sql->insert_id(); } } return $res; } function DelHistory($module,$idt,$lang) { return; global $sql,$prefix; if (!empty($idt) and !empty($module)) { $qry = 'delete from '.$prefix.'_history where lang="'.$lang.'" and idt="'.$idt.'" and module="'.$module.'"'; $sql->query($qry); } } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function url_exists($url) { $handle = @fopen($url, "r"); if ($handle === false) return false; fclose($handle); return true; } function str_replace_first($str) { if (strpos("?",$str) == 0) $str = preg_replace("/&/", "?", $str,1); return $str; } function fDeleteMoreSpaces($str) { $outS = ''; $flag = true; for($i=0;$i $valuelang) { $qry = 'delete from '.$prefix.'_'.$keylang.'_chvalue where select_tovar='.$_POST['idtovar']; $sql->query($qry); } else { $qry = 'delete from '.$prefix2.'_chvalue where select_tovar='.$_POST['idtovar']; $sql->query($qry); } foreach($_POST as $key => $value) { list($attr,$type,$idchr) = explode("_",$key); if($attr == 'tosave') { $maxid = GetMaxID(); if ($multilang) { foreach($langs as $keylang => $valuelang) { $qry = 'insert into '.$prefix.'_'.$keylang.'_chvalue (id,select_tovar,num_id,num_idparent,enum_characteristic,text_name,textarea_name) values("'.$maxid.'","'.$idtovar.'","'.$idchr.'","'.$idparent.'","'.$type.'"'; switch($type) { case "string": $qry .= ',"'.StringToSave($value).'",""'; break; case "checkbox": $qry .= ',"'.StringToSave($value).'",""'; break; case "textarea": $qry .= ',"","'.addslashes($value).'"'; break; case "select": $qry .= ',"'.StringToSave($value).'",""'; break; case "radio": $qry .= ',"'.StringToSave($value).'",""'; break; default: $qry .= ',"",""'; } $qry .= ')'; $sql->query($qry); } } else { $qry = 'insert into '.$prefix2.'_chvalue (id,select_tovar,num_id,num_idparent,enum_characteristic,text_name,textarea_name) values("'.$maxid.'","'.$idtovar.'","'.$idchr.'","'.$idparent.'","'.$type.'"'; switch($type) { case "string": $qry .= ',"'.StringToSave($value).'",""'; break; case "checkbox": $qry .= ',"'.StringToSave($value).'",""'; break; case "textarea": $qry .= ',"","'.addslashes($value).'"'; break; case "select": $qry .= ',"'.StringToSave($value).'",""'; break; case "radio": $qry .= ',"'.StringToSave($value).'",""'; break; default: $qry .= ',"",""'; } $qry .= ')'; $sql->query($qry); } } } } function viewchar($id,$module) { global $sql,$prefix,$prefix2,$gl_url; $qry = 'select * from '.$prefix2.'_'.$module.' where id='.$id; $row = $sql->fetch_one($qry); $parentid = $row['select_characteristic']; if(!empty($row)) { echo '

'.$row['text_name'].'

'; $qryp = 'select * from '.$prefix2.'_characteristic where id='.$row['select_characteristic']; $rowp = $sql->fetch_one($qryp); $parentname = $rowp['text_name']; $qryp = 'select * from '.$prefix2.'_chvalue where select_tovar="'.$id.'"'; $rowp = $sql->fetch_array($qryp); $cur_value = array(); foreach($rowp as $key => $value) { if ($value['enum_characteristic'] == 'textarea') $cur_value[$value['num_id']] = stripslashes($value['textarea_name']); else $cur_value[$value['num_id']] = StringToScreen($value['text_name']); } $rowp = null; $qry = 'select * from '.$prefix2.'_characteristic where parent="'.$row['select_characteristic'].'" order by ord'; $row = $sql->fetch_array($qry); if(sizeof($row)>0) { echo '
'; echo ''.$parentname.''; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; foreach($row as $key => $value) { if ($value['enum_characteristic'] == 'radio') { echo '

'; echo ''.$value['text_name'].': '; } else echo '

'.$value['text_name'].':
'; switch($value['enum_characteristic']) { case "string" : echo ''; break; case "checkbox" : echo ''; break; case "radio" : $qry = 'select * from '.$prefix2.'_characteristic where parent="'.$value['id'].'"'; $rowradio = $sql->fetch_array($qry); $i = -1; foreach($rowradio as $keyradio => $valueradio) { $i++; if ($i<>0) echo '

'; echo $valueradio['text_name'].': '; echo ''; } break; case "textarea" : echo ''; break; case "select" : echo ''; break; } if ($value['enum_characteristic'] == 'radio') echo '

'; } echo '

'; echo '

'; echo '
'; } } } function GetStructFromXML($path) { $xml = GetXML($path); $ArrStruct = array(); //echo $path.'
';print_r($xml);
	$i = -1;
	if(sizeof($xml)>1)
	{
		foreach($xml as $value)
		{
			if(($value['tag']=='COUNTPAGES')&&($value['level']==2)&&(($value['type'] == 'open') or ($value['type'] == 'complete')))
			{
				$ArrStruct['COUNTPAGES'] = $value['value'];
			}
			if(($value['tag']=='TIME')&&($value['level']==2)&&(($value['type'] == 'open') or ($value['type'] == 'complete')))
			{
				$ArrStruct['TIME'] = $value['value'];
			}
			if(($value['tag']=='ERRSQL')&&($value['level']==2)&&(($value['type'] == 'open') or ($value['type'] == 'complete')))
			{
				$ArrStruct['ERRSQL'] = $value['value'];
			}
			if(($value['tag']=='RECORD')&&($value['level']==2)&&(($value['type'] == 'open') or ($value['type'] == 'complete')))
			{
					$i++;
					$tmpArr = array();
					//$tmpArr['text'] = $value['value'];
					$tmpArr['id'] = $value['attributes']['ID'];
					$ArrStruct['RECORD'][$i] = $tmpArr;
			}
			if(($value['tag']=='DOP')&&($value['level']==3))
			{
				$ArrStruct['RECORD'][$i][$value['attributes']['NAME']] = $value['value'];
			}
		}
	}
	
	//echo '
';print_r($ArrStruct);
	return $ArrStruct;
}

 function GetXML($url)
 {		
	$file=$url;
	$vals = '';
	$page = @file_get_contents($file);
	if (!($page === false))
	{
		$xml_parser = xml_parser_create();
		$index = null;
		xml_parse_into_struct($xml_parser, $page, $vals, $index);
		xml_parser_free($xml_parser);		
	}
	return $vals;	
}

// get shablon
function GetShablon($name)
{
	global $sql,$prefix2;
	$query = 'select fck_body from '.$prefix2.'_shablon where text_value="'.$name.'"';
	$row = $sql->fetch_one($query);
	return $row['fck_body'];
}
// $p  - shablon 

//  Create way of movement
function SetPath($title,$addpath)
{	
	$arr = $tmpPath = array();
	$Cnt = isset($_SESSION['PATH']) && is_array($_SESSION['PATH']) ? count($_SESSION['PATH']) : 0;
	if (@is_array($_SESSION['PATH']))
		foreach($_SESSION['PATH'] as $value)
		{
			$Arrurl = parse_url($value['path']);
			$tmpPath[$value['i']] = $Arrurl['path']; 
		
		}		
	$Arrurl = parse_url($addpath);		
	$url = $Arrurl['path'];
	if (!@in_array($url,$tmpPath))
	{
		$arr['title'] = $title; 
		$arr['path'] = $addpath;
		$arr['i'] = $Cnt;	
		$_SESSION['PATH'][$Cnt] = $arr;
	}	
	else
	{
		// in array and all next records must delete
		$ind = array_search($url,$tmpPath);
		if ($ind <> $Cnt)
		{
			$i = $Cnt-1;
			
			while($i > ($ind-1))
			{
				unset($_SESSION['PATH'][$i]);
				$i--;
			}	
			$Cnt = isset($_SESSION['PATH']) && is_array($_SESSION['PATH']) ? count($_SESSION['PATH']) : 0;
			$arr['title'] = $title; 
			$arr['path'] = $addpath;
			$arr['i'] = $Cnt;	
			$_SESSION['PATH'][$Cnt] = $arr;
			
		}		
	}
	//echo '
';print_r($_SESSION['PATH']);
	return $_SESSION['PATH'];
}

function GetConstantsByModule($mod)
{
	global $prefix,$sql;
	$query = 'select id,text_name from '.$prefix.'_'.$_SESSION['site']['mainlang'].'_defines where check_end=0 and text_name="'.$mod.'"';
	$m_parent = $sql->fetch_one($query);
	if (!empty($m_parent['id']))
	{
		$query = 'select text_name,textarea_value, check2_fck, fck_body from '.$prefix.'_'.$_SESSION['site']['mainlang'].'_defines where check_end=1 and parent='.$m_parent['id'];
		$result = $sql->fetch_array($query);	
		$def = array();
		if (sizeof($result) > 0)
			foreach($result as $key => $value)
			{
				if ($_GET['viewConst'] == 1)
					$def[$value['text_name']] = ''.stripcslashes($m_parent['text_name'].':'.$value['text_name']).'';
				else 
				{
					if ($value['check2_fck'] == 1)
						$def[$value['text_name']] = $value['fck_body'];
					else $def[$value['text_name']] = StringToScreen($value['textarea_value']);
				}
			}
	}
	else
		$def = array();
	return $def;
}

function GetDefineByNamePHP($name)
{
	global $prefix,$sql;
	$query = 'select textarea_value from '.$prefix.'_'.$_SESSION['site']['mainlang'].'_defines where text_name="'.$name.'"';
	$result = $sql->fetch_one($query);	
	if (empty($result))
		return '!*'.$name.'*!';
	else
		return $result['areatext_value'];
	
}

function GetConstants()
{
	global $module,$prefix,$sql;
	$defines = array();
	$query = 'select text_name,textarea_value from '.$prefix.'_'.$_SESSION['site']['mainlang'].'_defines';
	$result = $sql->fetch_array($query);	
	if (sizeof($result) > 0)
		foreach($result as $key => $value)
			$defines[$value['text_name']] = $value['textarea_value'];

	return $defines;
}

function setParentConstant($ParentName)
{
	global $prefix2,$prefix,$sql,$langs;
	$maxid = 0;
	$flag = true;
	if (!empty($ParentName)) // if empty parent
	{
		if (sizeof($langs) > 0)
		{
			foreach($langs as $key =>$value)
			{
				// if exists constant
				$queryC = 'select id,text_name,textarea_value from '.$prefix.'_'.$key.'_defines where text_name="'.trim($ParentName).'" limit 1';
				$resultC = $sql->fetch_one($queryC);	
				if (empty($resultC))
				{
					if ($flag)
					{
						$maxid = GetMaxID('','');	
						$flag = false;
					}
					$query = 'insert into '.$prefix.'_'.$key.'_defines set id='.$maxid.', text_name="'.trim($ParentName).'", textarea_value="'.trim($ParentName).'"';
					$sql->query($query);
				}
				else
				{
					if ($flag)
					{
						$maxid = $resultC['id'];
						$flag = false;
					}
					else
					{
						if ($maxid <> $resultC['id'])
						{
							$query = 'update '.$prefix.'_'.$key.'_defines set id='.$maxid.' where id='.$resultC['id'];
							$sql->query($query);										
						}	
					}	
				}	
			}		
			
		}
	}
	return $maxid;
}

function setConstant($ParentName,$NameConst,$arrDefines)
{
	global $prefix2,$prefix,$sql,$langs;
	$flag = true;
	if (!empty($NameConst) and  is_array($arrDefines))
	{
		if (sizeof($langs) > 0)
		{
			$parent = 0;
			if (!empty($ParentName))
			{
				$parent = setParentConstant($ParentName);
			}
			foreach($langs as $key =>$value)
			{
				$queryC = 'select id,text_name,textarea_value from '.$prefix.'_'.$key.'_defines where text_name="'.trim($NameConst).'" and parent="'.$parent.'" limit 1';
				$resultC = $sql->fetch_one($queryC);	
				if (empty($resultC))
				{
					if ($flag)
					{
						$maxid = GetMaxID('','');	
						$flag = false;
					}
					$query = 'insert into '.$prefix.'_'.$key.'_defines set id='.$maxid.',parent='.$parent.', text_name="'.trim($NameConst).'", check_end=1,textarea_value="'.trim($NameConst).'"';
					$sql->query($query);
					if(@in_array($key,array_keys($arrDefines)))
					{
						$query = 'update '.$prefix.'_'.$key.'_defines set textarea_value="'.addslashes($arrDefines[$key]).'" where id='.$maxid;
						$sql->query($query);					
					}
				}
				else
				{
					if ($flag)
					{
						$maxid = $resultC['id'];
						$flag = false;
					}
					else
					{
						if ($maxid <> $resultC['id'])
						{
							$query = 'update '.$prefix.'_'.$key.'_defines set id='.$maxid.',parent='.$parent.' where id='.$resultC['id'];
							$sql->query($query);										
						}	
					}	
				}
			}		
		}
	}
}

function getConstantByName($name)
{
	if (defined($name))
		return constant($name);
	else
		return '*'.$name.'*';	
}

function GetMaxID()
{
	global $sql,$prefix;
	$query = "create table if not exists 
	".$prefix."_maxid (
	id int(11) unsigned NOT NULL auto_increment,
	GUID varchar(255) default NULL,
	PRIMARY KEY  (id),
	UNIQUE KEY id (id)
	) DEFAULT CHARSET=utf8"; 
	$sql->query($query);	
	
	
	$query = "insert into ".$prefix."_maxid set GUID='".uniqid(rand(), true)."'";
	$sql->query($query);	
	$res = $sql->insert_id(); 
	return $res;
} 

function GetPrefix($mod,$anotherlang = '')
{
	global $prefix,$c_parts;
	if (empty($mod))
		return $prefix.'_'.(empty($anotherlang) ? $_SESSION['site']['mainlang']:$anotherlang);
		
	
	if (!$c_parts->getPrefix($mod) and $c_parts->getSynhro($mod) == 0)
		$pr = $prefix;
	else	
		$pr = $prefix.'_'.(empty($anotherlang) ? $_SESSION['site']['mainlang'] :$anotherlang);
			
	return $pr;
	
}


function getlevelLIST($myparent,$level) 
{
	global $prefix, $sql, $module, $prefix2;
	$level++;	
	if (empty($myparent) or ($myparent ==0))
		return $level;
	$query = 'select id, parent from '.$prefix2.'_'.$module.' where id='.$myparent;
	$row = $sql->fetch_one($query);
	
	if ($level >= 10)
		return $level;
		
	if (!empty($row)) 
		$level = getlevelLIST($row['parent'],$level);
		
	return $level;	
}


function CREATEPAGEFORLIST()
{
	$PAGE = '';
	if (isset($_GET['idtable']))
		if (!empty($_GET['idtable']) or $_GET['idtable'] == 0)
			$PAGE .= '&idtable='.$_GET['idtable'];
	if (!empty($_GET['page']))
		$PAGE .= '&page='.$_GET['page'];
	if (!empty($_GET['folder']))
		$PAGE .= '&folder='.$_GET['folder'];
	return $PAGE;	
}

function delfile($id, $name)
{
	global $module, $prefix2, $lang, $HTTP_REFERER, $sql;

	$dir = "upload/".$module."/".$_SESSION['lang'];

	$query = "select ".$name." from ".$prefix2."_".$module." where id='$id'";
	$row = $sql->fetch_one($query);
	if (!empty($row[$name]))
	{
		@unlink($dir."/".$row[$name]);
		list($type) = explode("_", $name);
		if ($type == "img")
		{
			@unlink($dir."/tn_".$row[$name]);
			for ($i=1; $i<=10; $i++)		
				@unlink($dir."/tn".$i."_".$row[$name]);		
		}
		$query = "update ".$prefix2."_".$module." set ".$name."='' where id='$id'";
		$sql->query($query);
	}

	header("Location: ".$_SERVER['HTTP_REFERER']);
}

function delchildpage($id)
{
	global $prefix2, $langs, $prefix, $module, $c_parts, $lang, $sql;
	global $tables, $names, $photonum;

	$sql->query("delete from ".$prefix."_urls where parent='".$id."' and module='".$module."'");	
	$cols = array('id' => $id);
	sql_delete($module, $cols);
	
	if ($c_parts->getSynhro($module))
	{
		foreach($langs as $key => $value)
		{
			$query = "show tables like '".$prefix."_".$key."_".$module."_photos'";
			$row = $sql->fetch_one($query);
			if (count($row))
			{
				$query = "select id, img from ".$prefix."_".$key."_".$module."_photos where parent='$id'";
				$row = $sql->fetch_array($query);
				foreach ($row as $value)
				{
					deleteindex($prefix."_".$key, $id, $value['id']);
					$dir = "upload/".$module."/".$key;
					@unlink($dir."/".$value['img']);
					@unlink($dir."/tn_".$value['img']);		
					for ($i=1; $i<=10; $i++)		
						@unlink($dir."/tn".$i."_".$value['img']);						
				}

				$query = "delete from ".$prefix."_".$key."_".$names[$photonum]." where parent='$id'";
				$sql->query($query);
				DelHistory($names[$photonum],$id,$key);
			}
		}
	}
	else
	{
		$query = "show tables like '".$prefix2."_".$module."_photos'";		
		$row = $sql->fetch_one($query);
		if (count($row))
		{
			$query = "select id, img from ".$prefix2."_".$module."_photos where parent='$id'";			
			$row = $sql->fetch_array($query);
			foreach ($row as $value)
			{			
				deleteindex($prefix2, $id, $value['id']);
				$dir = "upload/".$module."/".$_SESSION['lang'];
				@unlink($dir."/".$value['img']);
				@unlink($dir."/tn_".$value['img']);		
				for ($i=1; $i<=10; $i++)		
					@unlink($dir."/tn".$i."_".$value['img']);	
			}
			for($i=1; $iquery($query);
				DelHistory($names[$photonum],$id,$_SESSION['lang']);
			}
		}
	}
	$query="select id from ".$prefix2."_".$module." where parent='$id'";
	$row = $sql->fetch_array($query);
	foreach($row as $value)
		delchildpage($value['id']);
}

function delpage($id)
{
	global $prefix2, $langs, $prefix, $module, $c_parts, $lang, $sql;
	global $tables, $names,$id_site,$url,$baseurl, $photonum;

	$sql->query("delete from ".$prefix."_urls where parent='".$id."' and module='".$module."'");
	$cols = array('id' => $id);	
	sql_delete($module, $cols);
	
	if ($c_parts->getSynhro($module))
	{
		foreach($langs as $key => $value)
		{
			$query = "show tables like '".$prefix."_".$key."_".$module."_photos'";			
			$row = $sql->fetch_one($query);
			if (count($row))
			{				
				$query = "select id, img from ".$prefix."_".$key."_".$module."_photos where parent='$id'";
				$row = $sql->fetch_array($query);
				foreach ($row as $value)
				{
					deleteindex($prefix."_".$key, $id, $value['id']);
					$dir = "upload/".$module."/".$key;
					@unlink($dir."/".$value['img']);
					@unlink($dir."/tn_".$value['img']);		
					for ($i=1; $i<=10; $i++)		
						@unlink($dir."/tn".$i."_".$value['img']);	
				}
				for($i=1; $iquery($query);
					DelHistory($names[$photonum],$id,$key);
				}
			}
		}
	}
	else
	{
		$query = "show tables like '".$prefix2."_".$module."_photos'";
		$row = $sql->fetch_one($query);		
		if (count($row))
		{			
			$query = "select id, img from ".$prefix2."_".$module."_photos where parent='$id'";
			$row = $sql->fetch_array($query);
			foreach ($row as $value)
			{
				deleteindex($prefix2, $id, $value['id']);
				$dir = "upload/".$module."/".$_SESSION['lang'];
				@unlink($dir."/".$value['img']);
				@unlink($dir."/tn_".$value['img']);						
				for ($i=1; $i<=10; $i++)		
					@unlink($dir."/tn".$i."_".$value['img']);					
			}
			for($i=1; $iquery($query);
				DelHistory($names[$photonum],$id,$_SESSION['lang']);
			}
		}
	}
	$query="select id from ".$prefix2."_".$module." where parent='$id'";
	$row = $sql->fetch_array($query);
	foreach($row as $value)
	{
		delchildpage($value['id']);
	}	
	if (sizeof($c_parts->GetRef($module)>0) and is_array($c_parts->GetRef($module)))
	{
		foreach($c_parts->GetRef($module) as $key => $value)
		{
			if($value)
			{
				$query = "delete from ".$prefix2."_".$value[0]." where ".$value[1]."=\"".$id."\" ";
			}	
			else	
				$query = "update ".$prefix2."_".$value[0]." set ".$value[1]."=0";
			$sql->query($query);
		}
	}

	if (($url == 'insession') and (!empty($_SESSION['currentUrl'])))
		header('Location: '.$_SESSION['currentUrl']);
	else
		header("Location: admin.php?module=".$module.CREATEPAGEFORLIST());
	
}

define("GIS_GIF", 1);
define("GIS_JPG", 2);
define("GIS_PNG", 3);

function resize_image($src_file, $dest_file, $new_size, $thumb_use="wd")
{
    global $CONFIG, $ERROR;
    global $lang_errors;

    $imginfo = getimagesize($src_file);
    if ($imginfo == null)
        return false;
    // GD can only handle JPG & PNG images
    if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_GIF && $imginfo[2] != GIS_PNG && ($method == 'gd1' || $method == 'gd2')) {
        $ERROR = $lang_errors['gd_file_type_err'];
        return false;
    }
    // height/width
    $srcWidth = $imginfo[0];
    $srcHeight = $imginfo[1];
    if ($thumb_use == 'ht') {
        $ratio = $srcHeight / 130;
    } elseif ($thumb_use == 'wd') {
        $ratio = $srcWidth / $new_size;
    } else {
        $ratio = max($srcWidth, $srcHeight) / $new_size;
    }
    $ratio = max($srcWidth, $srcHeight) / $new_size;
    $ratio = max($ratio, 1.0);
	if ($new_size < $ratio)
	{
		$destWidth = (int)($srcWidth / $ratio);
		$destHeight = (int)($srcHeight / $ratio);
		ini_set("memory_limit", "32M");
		$CONFIG['jpeg_qual'] = intval(100);
		$CONFIG['gif_qual'] = intval(100);

		if (!function_exists('imagecreatefromjpeg')) 
			cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
        if (!function_exists('imagecreatefromgif')) 
			cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
		if (!function_exists('imagecreatetruecolor'))
			cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page', __FILE__, __LINE__);
		if ($imginfo[2] == GIS_JPG)
			$src_img = imagecreatefromjpeg($src_file);
		elseif ($imginfo[2] == GIS_PNG) 
		 $src_img = imagecreatefrompng($src_file);
		else
		 $src_img = imagecreatefromgif($src_file);

		if (!$src_img)
		{
	                $ERROR = $lang_errors['invalid_image'];
        	        return false;
		}

		$dst_img = imagecreatetruecolor($destWidth, $destHeight);
		imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, (int)$destWidth, (int)$destHeight, $srcWidth, $srcHeight);
		
		if($imginfo[2] == GIS_JPG||$imginfo[2] == GIS_PNG)
		 imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
		else
		 imagegif($dst_img, $dest_file, $CONFIG['gif_qual']);

		imagedestroy($src_img);
		imagedestroy($dst_img);

		chmod($dest_file, 0644);

		$imginfo = getimagesize($dest_file);
		if ($imginfo == null)
		{
			$ERROR = $lang_errors['resize_failed'];
			@unlink($dest_file);
			return false;
		} else return true;
	}
}

function error($errstr)
{
	echo('
'.$errstr.'
'); } function message($message) { echo('
'.$message.'
'); } //Save From Input To Database function StringToSave($string) { $string = trim($string); $string=str_replace("&", "&", $string); $string=str_replace("\\\"", """, $string); $string=str_replace("<", "<", $string); $string=str_replace(">", ">", $string); return $string; } //Echo TEXTAREA from Database To Screen function StringToScreen($string) { $string = str_replace('"', """, $string); $string = str_replace('\'', "'", $string); $string = str_replace('<', "<", $string); $string = str_replace('>', ">", $string); return $string; // return htmlspecialchars($string); } function checkAccess($module,$type) { global $prefix2, $sql; if ((!$_SESSION['isSA']) and ($module<>'main')) { $query = 'select rights.* from '.GetPrefix('users').'_users as users left join '.GetPrefix('rights').'_rights as prights on prights.id=users.selectlevel_rights_base_1 left join '.GetPrefix('rights').'_rights as rights on rights.parent=prights.id where users.id="'.$_SESSION['adminid'].'" and rights.check_active=1 and prights.check_active=1 and users.check_active=1'; $row = $sql->fetch_array($query); foreach($row as $key => $value) { if (($module == $value['enum_modules']) && $value[$type]) return 1; } return 0; } else return 1; } function checkadmin($login, $module) { global $prefix,$prefix2,$sql; if ($_SESSION['isSA']) { $query = "select id, access from ".$prefix."_admins where login='".$_SESSION['login']."'"; $row = $sql->fetch_one($query); $bufarr = explode("#", $row['access']); if (in_array($module, $bufarr)) return 1; else return 0; } else { $query = 'select rights.* from '.GetPrefix('users').'_users as users left join '.GetPrefix('rights').'_rights as prights on prights.id=users.selectlevel_rights_base_1 left join '.GetPrefix('rights').'_rights as rights on rights.parent=prights.id where users.id="'.$_SESSION['adminid'].'" and rights.check_active=1 and prights.check_active=1 and users.check_active=1'; $row = $sql->fetch_array($query); foreach($row as $key => $value) { if (($module == $value['enum_modules']) && $value['check2_view']) return 1; } return 0; } } function FormatDate($data) { list($year, $month, $day) = explode("-", $data); return $month.".".$day.".".$year; } function DefineJFCK($id, $wsize, $hsize, $types, $fields, $button = 0) { global $module, $sql; echo(''); if (!$button) echo(''); else echo('Edit '); } function DateFormat($data) { if (($data != "") && ($data != "0000-00-00")) { list($year, $month, $day) = explode("-", $data); return $day."/".$month."/".$year; } else return ""; } function MailVal($Addr, $Level, $Timeout = 15000) { // Valid Top-Level Domains $gTLDs = "com:net:org:edu:gov:mil:int:arpa:aero:biz:coop:info:int:museum:name:pro:"; $CCs = "ad:ae:af:ag:ai:al:am:an:ao:aq:ar:as:at:au:aw:az:ba:bb:bd:be:bf:". "bg:bh:bi:bj:bm:bn:bo:br:bs:bt:bv:bw:by:bz:ca:cc:cf:cd:cg:ch:ci:". "ck:cl:cm:cn:co:cr:cs:cu:cv:cx:cy:cz:de:dj:dk:dm:do:dz:ec:ee:eg:". "eh:er:es:et:fi:fj:fk:fm:fo:fr:fx:ga:gb:gd:ge:gf:gh:gi:gl:gm:gn:". "gp:gq:gr:gs:gt:gu:gw:gy:hk:hm:hn:hr:ht:hu:id:ie:il:in:io:iq:ir:". "is:it:jm:jo:jp:ke:kg:kh:ki:km:kn:kp:kr:kw:ky:kz:la:lb:lc:li:lk:". "lr:ls:lt:lu:lv:ly:ma:mc:md:mg:mh:mk:ml:mm:mn:mo:mp:mq:mr:ms:mt:". "mu:mv:mw:mx:my:mz:na:nc:ne:nf:ng:ni:nl:no:np:nr:nt:nu:nz:om:pa:". "pe:pf:pg:ph:pk:pl:pm:pn:pr:pt:pw:py:qa:re:ro:ru:rw:sa:sb:sc:sd:". "se:sg:sh:si:sj:sk:sl:sm:sn:so:sr:st:su:sv:sy:sz:tc:td:tf:tg:th:". "tj:tk:tm:tn:to:tp:tr:tt:tv:tw:tz:ua:ug:uk:um:us:uy:uz:va:vc:ve:". "vg:vi:vn:vu:wf:ws:ye:yt:yu:za:zm:zr:zw:"; // The countries can have their own 'TLDs', e.g. mydomain.com.au $cTLDs = "com:net:org:edu:gov:mil:co:ne:or:ed:go:mi:"; $fail = 0; $sh = false; $mxhosts = array(); $weight = array(); // Shift the address to lowercase to simplify checking $Addr = strtolower($Addr); // Check 99.99% of addresses //$expr="^[\w\-]+(?:\.[\w\-]+)*@(?:[\w\-]+\.)+[a-zA-Z]{2,7}$"; //$expr = "^[a-z0-9\-]+(?:_\.[a-z0-9\-]+)*@(?:[a-z0-9\-]+\.)+[a-z]{2,7}$"; //$expr="^([\w\._\-]+)@(([\w\-]+\.)+)([a-z]{2,7})$"; //if(!ereg("$expr", $Addr)) $fail=1; // Split the Address into user and domain parts $UD = explode("@", $Addr); if (sizeof($UD) != 2 || !$UD[0]) { $fail = 1; // print "point 1"; } //$expr="^([\w|\.|_|\-|\!]+)$"; //$expr = "^([\w\-]+([_|\.|\!]*[\w\-]+)*)$"; //$expr = "^[A-Za-z0-9\-\_\.\!]*$"; $expr="^[_a-z0-9-]+(\.[_a-z0-9-]+)*$"; if (!preg_match("~".$expr."~i", $UD[0])) { $fail = 1; // print "point 2"; } // Split the domain part into its Levels $Levels = explode(".", $UD[1]); $sLevels = sizeof($Levels); if ($sLevels < 2) { $fail = 1; // print "point 3"; } // Get the TLD, strip off trailing ] } ) > and check the length $tld = $Levels[$sLevels-1]; $tld = preg_replace("~[>)}]$|]$~", "", $tld); if (strlen($tld) < 2 || strlen($tld) > 4 && $tld != "museum") { $fail = 1; // print "point 4:" . $tld; } $Level--; // If the string after the last dot isn't in the generic TLDs or country codes, it's invalid. if ($Level && !$fail) { $Level--; if (strpos($gTLDs, $tld.":") === false && strpos($CCs, $tld.":") === false) { $fail = 2; //print "point 5"; } } // If it's a country code, check for a country TLD; add on the domain name. if ($Level && !$fail) { $cd = $sLevels - 2; $domain = $Levels[$cd].".".$tld; if (strpos($cTLDs, $Levels[$cd].":") !== false) { $cd--; $domain = $Levels[$cd].".".$domain; } } // See if there's an MX record for the domain if ($Level && !$fail) { $Level--; if (!getmxrr($domain, $mxhosts, $weight)) $fail = 3; } // Attempt to connect to port 25 on an MX host if ($Level && !$fail) { $Level--; foreach ($mxhosts as $mxhost) { if ($sh) break; $sh = @fsockopen($mxhost, 25); } if (!$sh) $fail = 4; } // See if anyone answers if ($Level && !$fail) { $Level--; set_socket_blocking($sh, false); $out = ""; $t = 0; while ($t++ < $Timeout && !$out) $out = fgets($sh, 256); if (!preg_match("~^220~", (string)$out)) $fail = 5; } if ($sh) fclose($sh); return $fail; } //MailVal function createTables($module,$tables,$names,$values,$prefix2,$bkey) { global $lang,$prefix,$sql,$c_parts; if (sizeof($tables)>0) foreach($tables as $tablekey => $table) { $count = sizeof($table); if ($module == "admins") $tablename = $prefix."_".$module; elseif (!empty($names[$tablekey])) $tablename = $prefix2."_".$names[$tablekey]; else $tablename = $prefix2."_".$module; if (!empty($names[$tablekey]) or ($module == "admins")) $query = "create table if not exists ".$tablename." (id int(11) unsigned not null primary key auto_increment, parent int(11) unsigned not null default 0, ord int(11) unsigned not null default 0, check_active tinyint(1) unsigned not null default 1, check_end tinyint(1) unsigned not null default 0, "; elseif ($c_parts->getSynhro($module) == 1) $query = "create table if not exists ".$tablename." (id int(11) unsigned not null primary key, parent int(11) unsigned not null default 0, ord int(11) unsigned not null default 0, check_active tinyint(1) unsigned not null default 1, check_end tinyint(1) unsigned not null default 0, "; else $query = "create table if not exists ".$tablename." (id int(11) unsigned not null primary key auto_increment, parent int(11) unsigned not null default 0, ord int(11) unsigned not null default 0, check_active tinyint(1) unsigned not null default 1, check_end tinyint(1) unsigned not null default 0, "; foreach($table as $key => $value) $query .= $key." ".$value.", "; $query .= "INDEX parent (parent)) DEFAULT CHARSET=utf8"; $sql->query($query); $query = "describe ".$tablename.""; $fields = array(); $row = $sql->fetch_array($query); foreach($row as $value) $fields[] = $value['Field']; foreach($table as $key => $value) { foreach($fields as $key2 => $value2) if ($key == $value2) continue 2; $query = "alter table ".$tablename." add (".$key." ".$value.")"; $sql->query($query); } } if (!file_exists("upload/".$module)) { mkdir("upload/".$module); chmod("upload/".$module, 0777); } if (empty($bkey)) $bkey = $lang; if (!file_exists("upload/".$module."/".$bkey)) { mkdir("upload/".$module."/".$bkey); chmod("upload/".$module."/".$bkey, 0777); } } function createData($tables,$values,$module,$names,$langs) { global $prefix,$prefix2,$sql,$c_parts; //echo '
'; print_r($module);
	if (sizeof($tables)>0)
		foreach($tables as $tablekey => $table)
		{
			$count = sizeof($table);
			

			if ($module == "admins")
			{
				$tablename = $prefix."_".$module;
			}	
			elseif (!empty($names[$tablekey]))
			{
				if ($c_parts->getSynhro($module) == 1)
				{
					$tablename = $prefix."_".$_SESSION['lang']."_".$names[$tablekey];
				}	
				else	
				{
					$tablename = $prefix."_".$names[$tablekey];
				}	
			}		
			else
			{
				if ($c_parts->getPrefix($module))
				{
					$tablename = $prefix."_".$_SESSION['lang']."_".$module;
				}	
				else	
				{
					$tablename = $prefix."_".$module;
				}	
			}
			$query = "select count(*) as count from ".$tablename."";
			$row = $sql->fetch_one($query, 1);
			$bcount = $row['count'];
			if ((!$bcount) && (!empty($values[$tablekey])))
			{
				$sql->query("START TRANSACTION");		
				if ($c_parts->getPrefix($module))
				{
					foreach($values[$tablekey] as $valuekey => $valuevalue)
					{
						$maxid = GetMaxID();	
						foreach($langs as $key => $value)
						{
							$tablename = $prefix."_".$key."_".$module;
							$query = "insert into ".$tablename." (id,";
							$j=0;
							foreach($table as $key => $value)
							{
								$j++;
								if ($count == $j)
								{
									$query .= $key.") values(".$maxid.",";
								}	
								else $query .= $key.", ";
							}
							foreach($valuevalue as $k => $val)
							{			
								if (!is_array($val))
								{
									$query .= "\"".$val."\", ";
								}
							}
							$query = substr($query,0,-2).')';
							
							$sql->query($query);					
								if (!empty($valuevalue['__parent']['parent']))
								{
									$queryS = 'select * from '.$tablename.' where textarea_value="'.$valuevalue['__parent']['parent'].'"';
									$rowS = $sql->fetch_one($queryS);
									if (!empty($rowS['id']))
									{
										if (!empty($maxid))
										{
											$query = 'update '.$tablename.' set parent ='.$rowS['id'].' where id='.$maxid;
											$sql->query($query);					
										}	
									}
								}	
								if (!empty($valuevalue['__checkend']['checkend']))
								{
									if (!empty($maxid))
									{
										$query = 'update '.$tablename.' set check_end ='.$valuevalue['__checkend']['checkend'].' where id='.$maxid;
										$sql->query($query);					
									}	
								}	
							
						}
					
					}
				}
				else
				{
					$tablename = $prefix."_".$module;
						
					foreach($values[$tablekey] as $valuekey => $valuevalue)
					{
						$query = "insert into ".$tablename." (";
						$j=0;
						foreach($table as $key => $value)
						{
							$j++;
							if ($count == $j)
							{
								$query .= $key.") values(";
							}	
							else $query .= $key.", ";
						}
						$j=0;
						foreach($valuevalue as $k => $val)
						{
							$j++;
							if ($count == $j)
								$query .= "\"".$val."\")";
							else $query .= "\"".$val."\", ";
						}
						$sql->query($query);					
					}
				}
				$sql->query("COMMIT");
			}
		}
}  
  
function CheckFirst($module, $prefix2='', $bkey="")
{        
	global $langs,$prefix,$c_parts, $sql;
	
	$query = "create table if not exists ".$prefix."_urls (id int(11) unsigned not null primary key auto_increment, parent int, url varchar(255), module varchar(255)) DEFAULT CHARSET=utf8";
	$sql->query($query);
	if (file_exists('include/parts/'.$module.'.php'))
	{
		include('include/parts/'.$module.'.php');
		$sql->query("delete from ".$prefix."_urls where url='".$module."'");
		$sql->query("insert into ".$prefix."_urls (parent, url) values(0, '".$module."')");
		if ($c_parts->getPrefix($module))
		{	
			foreach($langs as $key => $value)
				createTables($module,$tables,$names,$values,$prefix.'_'.$key,$bkey);			
		}		
		else
			createTables($module,$tables,$names,$values,$prefix,$bkey);
		//if (($module == 'admins') or ($module == 'config') or ($module == 'razdel'))
		{
			createData($tables,$values,$module,$names,$langs);
		}		
	}
}

function sql_insert($table, $cols)
{
	global $module, $langs, $prefix2, $prefix, $sql,$lang,$c_parts;

	if (file_exists('include/parts/'.$module.'.php'))
		include('include/parts/'.$module.'.php');

	/* id */ 	
	if ($c_parts->getSynhro($module) == 1)
	{
		$maxid = GetMaxID();	
		$cols['id'] = $maxid;
	}
	/* */
	
	$j=0;
	$vals = "";
	$bufquery = "(";
	foreach($cols as $key => $value)
	{
		$j++;
		if ($j == count($cols))
		{
			$bufquery .= $key.") values(";
			$vals .= "'$value')";
		}
		else
		{
			$bufquery .= $key.", ";
			$vals .= "'$value', ";
		}
	}
	$bufquery .= $vals;

	if ($c_parts->getSynhro($module) == 1)
	{
		foreach($langs as $key => $value)
			CheckFirst($module, $prefix."_".$key);
		
		$sql->query("START TRANSACTION");
		foreach($langs as $key => $value)
		{
		
			$query = "insert into ".$prefix."_".$key."_".$table." ".$bufquery;
			$res = mysql_query($query);
			if ($res === FALSE)
				{
					echo("Error SQL: ");
					echo('');
					echo $query;
					echo('');
					$sql->query("ROLLBACK");
					exit;
				}	
			if ($key == $lang)
			{
				$idm = $sql->insert_id();
			}	
			$idm = $maxid;
			AddHistory($idm,$table,$_SESSION['login'],$_SESSION['adminid'],$_SESSION['isSA'],$key);		
			if (($key <> $_SESSION['lang']) and ($idm <> 0) and ($module != "defines"))
			{
				$query = "update ".$prefix."_".$key."_".$table." set check_active = 0 where id = ".$idm;
				$sql->query($query);
			}
			//indexing($prefix."_".$key, $cols, $idm);
		}
		$sql->query("COMMIT");
	}
	else
	{
		$query = "insert into ".$prefix2."_".$table." ".$bufquery;
		$sql->query($query);
		$idm=$sql->insert_id();
		AddHistory($idm,$table,$_SESSION['login'],$_SESSION['adminid'],$_SESSION['isSA'],$_SESSION['lang']);		
		//indexing($prefix2, $cols, $idm);
	}
	return $idm;
}


function sql_delete($table, $cols)
{
	global $module, $langs, $prefix2, $prefix, $langs, $lang, $c_parts, $indexing, $sql;

	if (file_exists('include/parts/'.$module.'.php'))
		include('include/parts/'.$module.'.php');

	$j=0;
	$where = "(";
	foreach($cols as $key => $value)
	{
		$j++;
		if ($j == count($cols))
			$where.= $key."='$value')";
		else $where.= $key."='$value' and ";
		if ($key == "id")
			$delid = $value;
	}

	$query = "describe ".$prefix2."_".$table;
	$row = $sql->fetch_array($query);
	foreach ($row as $value)
	{
		list($type, $name) = explode("_", $value['Field']);
		$def = "_".$row['Field'];
		if (($type == "img") || ($type == "file"))
		{
			if ($c_parts->getSynhro($module))
			{
				foreach($langs as $key => $var)
				{
					$dir = "upload/".$module."/".$key;

					$query = "select id, ".$value['Field']." from ".$prefix."_".$key."_".$table." where ".$where;
					$row = $sql->fetch_one($query);

					if (!empty($row[$value['Field']]) && file_exists($dir."/".$row[$value['Field']]))
					{
						@unlink($dir."/".$row[$value['Field']]);
						if ($type == "img")
						{
							@unlink($dir."/tn_".$row[$value['Field']]);
							for ($i=1; $i<=10; $i++)		
								@unlink($dir."/tn".$i."_".$row[$value['Field']]);		
						}
					}
				}
			}
			else
			{
				$dir = "upload/".$module."/".$_SESSION['lang'];

				$query = "select id, ".$value['Field']." from ".$prefix2."_".$table." where ".$where;
				$row = $sql->fetch_one($query);

				if (!empty($row[$value['Field']]) && file_exists($dir."/".$row[$value['Field']]))
				{
					@unlink($dir."/".$row[$value['Field']]);
					if ($type == "img")
					{
						@unlink($dir."/tn_".$row[$value['Field']]);
						for ($i=1; $i<=10; $i++)		
							@unlink($dir."/tn".$i."_".$row[$value['Field']]);		
					}
				}
			}
		}
	}
	if ($c_parts->getSynhro($module) == 1)
	{
		foreach($langs as $key => $value)
		{
			if (!empty($delid))
			{
				$query = "select id, parent, ord from ".$prefix."_".$key."_".$table." where id='$delid'";			
				$row = $sql->fetch_one($query);
			}			
			if (!empty($delid))
			{
				if (!empty($row['ord']) and ($row['id'] != 0))
				{
					$query = "update ".$prefix."_".$key."_".$table." set ord=ord-1 where ord>".$row['ord']." and parent=".$row['parent']."";
					$sql->query($query);
				}
			}
			$query = "delete from ".$prefix."_".$key."_".$table." where ".$where;
			$sql->query($query);
			DelHistory($table,$delid,$key);			

			if ($indexing && !empty($delid))
				deleteindex($prefix."_".$key, $delid, $photopage);
		}
	}
	else
	{
		if (!empty($delid))
		{
			$query = "select id, parent, ord from ".$prefix2."_".$table." where id='$delid'";
			$row = $sql->fetch_one($query);
		}
		if (!empty($delid))
		{
			if (!empty($row['ord']) and ($row['id'] != 0))
			{
				$query = "update ".$prefix2."_".$table." set ord=ord-1 where ord>".$row['ord']." and parent=".$row['parent']."";
				$sql->query($query);				
			}	
		}
		$query = "delete from ".$prefix2."_".$table." where ".$where;
		$sql->query($query);
		DelHistory($table,$delid,$_SESSION['lang']);			

		if ($indexing && !empty($delid))
				deleteindex($prefix2, $delid, $photopage);
	}
}

function sql_select($cols, $where=null, $order=null, $limit=null, $check_active=1)
{
	global $prefix2, $module, $sql;

	$query = "select ";
	if (!empty($cols))
	{
		foreach($cols as $value)
			$query .= $value.", ";
		$query = substr($query, 0, strlen($query)-2);
	}
	else $query .="* ";
	$query .= " from ".GetPrefix($module)."_".$module;
	if ($check_active == 0)
		$query .= " where (check_active=1 or check_active=0) and ";
	else $query .= " where check_active=1 and ";
	if (!empty($where))
	{
		foreach($where as $key => $value)
			$query .= $key."='".$value."' and ";
	}
	$query = substr($query, 0, strlen($query)-4);
	if (!empty($order))
	{
		$query .= " order by ";
		foreach($order as $key => $value)
			$query .= $key." ".$value.", ";
		$query = substr($query, 0, strlen($query)-2);
	}
	else $query .= " order by ord asc";
	if (!empty($limit))
		$query .= " limit ".$limit;
	$row = $sql->fetch_array($query);
	$i = -1;
	foreach ($row as $value)
	{
		$i++;
		$res[$i] = $value;
		foreach($res[$i] as $key => $var)
		{
			if ($key == "text_value")
			{
				if ($res[$i][$key] != "")
					$res[$i]['url'] = $res[$i][$key];
				else $res[$i]['url'] = $module."/".$res[$i]['id'];
			}
			else
			{
				list($type, $name) = explode("_", $key);
				if ($type == "date")
					$res[$i][$key] = DateFormat($res[$i][$key]);
				if (($type == "text") || ($type == "textarea") || ($type == "email"))
				{
					if (($key == "text_name") && ($module == "topmenu"))
						;
					else $res[$i][$key] = StringToScreen($res[$i][$key]);
					$res[$i][$key] = str_replace("\n", "
", $res[$i][$key]); } } } } return $res; } function tagdeleteindex($prefix,$id,$photopage=0) { global $module,$sql,$tags_indexing; if ($tags_indexing && moduleindex($module)) { $query = "SELECT word FROM ".$prefix."_tagindex_links WHERE parent='$id' ANd module='$module' AND photopage='$photopage'"; $row = $sql->fetch_array($query); foreach ($row as $value) { $query = "SELECt count(*) AS count FROM ".$prefix."_tagindex_links WHERE word=".$value['word']." AND (parent!='$id' || photopage!='$photopage')"; $row = $sql->fetch_one($query); $count = $row['count']; if ($count == 0) { $query = "DELETE FROM ".$prefix."_tagindex_words WHERE id=".$value['word']; $sql->query($query); } } $query = "DELETE FROM ".$prefix."_tagindex_links WHERE parent='$id' AND photopage='$photopage'"; $sql->query($query); } } function tagindexing($prefix, $cols, $id, $photopage=0) { global $module,$sql,$tags_indexing; if ($tags_indexing && moduleindex($module)) { $query = 'CREATE TABLE IF NOT EXISTS '.$prefix.'_tagindex_words (id int unsigned auto_increment primary key, word varchar(255) not null default "")'; $sql->query($query); $query = 'CREATE TABLE IF NOT EXISTS '.$prefix.'_tagindex_links (word int unsigned not null default 0, parent int unsigned not null default 0, module varchar(255) not null default "", photopage int unsigned not null default 0, active tinyint(1) not null default 1, INDEX word_parnt (word, parent))'; $sql->query($query); $body = ""; foreach($cols as $key => $value) { if ($key != "textarea_tags") continue; list($type, $name) = explode("_", $key); if (($type == "bfck") || ($type == "fck") || ($type == "text") || ($type == "textarea")) { $value = str_replace("\n"," ", $value); $value = str_replace("\r","", $value); $value = str_replace('&', ' ', $value); $value = str_replace(' ', ' ', $value); $value = str_replace('"', ' ', $value); $value = str_replace('<', ' ', $value); $value = str_replace('>', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('

', ' ', $value); $value = strip_tags($value); $value = str_replace(' -', ' ', $value); $value = str_replace('.', ' ', $value); $value = str_replace('!', ' ', $value); $value = str_replace('?', ' ', $value); $value = str_replace(':', ' ', $value); $value = str_replace(';', ' ', $value); $value = str_replace(')', ' ', $value); $value = str_replace('(', ' ', $value); $value = str_replace('"', ' ', $value); $value = str_replace('\'', ' ', $value); $value = str_replace('\\', ' ', $value); $value = mb_strtolower($value, 'UTF-8'); $body .= $value." "; } } $body = explode(",", $body); array_walk($body, 'sw'); $body = array_unique($body); $body = implode(",", $body); while(stristr($body, " ")) $body=str_replace(" ", " ", $body); deleteindex($prefix, $id, $photopage); $record = $id; $body = explode(",", $body); foreach($body as $value) { if ($value) { if ($module == "article") { $query = "SELECT check_active FROM ".$prefix."_".$module." WHERE id='$record'"; $row = $sql->fetch_one($query); $active = $row['check_active']; } else { $active = 1; } $query = "SELECT id FROM ".$prefix."_tagindex_words WHERE word='$value'"; $row = $sql->fetch_one($query); if ($row) { $query = "INSERT INTO ".$prefix."_tagindex_links(word,parent,module,photopage,active) values('{$row['id']}','$record','$module','$photopage','$active')"; $sql->query($query); } else { $query = "INSERT INTO ".$prefix."_tagindex_words(word) VALUES('$value')"; $sql->query($query); $word = $sql->insert_id(); $query = "INSERT INTO ".$prefix."_tagindex_links (word,parent,module,photopage,active) VALUES('$word','$record','$module','$photopage','$active')"; $sql->query($query); } } } } } function indexing($prefix, $cols, $id, $photopage=0) { global $module,$sql,$indexing,$tags_indexing; if ($tags_indexing) tagindexing($prefix, $cols, $id, $photopage); if ($indexing) { $query = 'create table if not exists '.$prefix.'_index_words (id int unsigned auto_increment primary key, word varchar(255) not null default "") DEFAULT CHARSET=utf8'; $sql->query($query); $query = 'create table if not exists '.$prefix.'_index_links (word int unsigned not null default 0, parent int unsigned not null default 0, module varchar(255) not null default "", photopage int unsigned not null default 0, active tinyint(1) not null default 1, INDEX word_parnt (word, parent)) DEFAULT CHARSET=utf8'; $sql->query($query); $body = ""; foreach($cols as $key => $value) { list($type, $name) = explode("_", $key); if (($type == "bfck") || ($type == "fck") || ($type == "text") || ($type == "textarea")) { $value = str_replace("\n"," ", $value); $value = str_replace("\r","", $value); $value = str_replace('&', ' ', $value); $value = str_replace('&mdash', ' ', $value); $value = str_replace(' ', ' ', $value); $value = str_replace('"', ' ', $value); $value = str_replace('<', ' ', $value); $value = str_replace('>', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('
', ' ', $value); $value = str_replace('

', ' ', $value); $value = strip_tags($value); $value = str_replace(' -', ' ', $value); $value = str_replace('.', ' ', $value); $value = str_replace(',', ' ', $value); $value = str_replace('!', ' ', $value); $value = str_replace('?', ' ', $value); $value = str_replace(':', ' ', $value); $value = str_replace(';', ' ', $value); $value = str_replace(')', ' ', $value); $value = str_replace('(', ' ', $value); $value = str_replace('"', ' ', $value); $value = str_replace('\'', ' ', $value); $value = str_replace('\\', ' ', $value); $value = mb_strtolower($value, "UTF-8"); $body .= $value." "; } } $body= explode(" ", $body); array_walk($body, 'sw'); $body = array_unique($body); $body = implode(" ", $body); while(stristr($body, " ")) $body=str_replace(" ", " ", $body); if (empty($photopage)) $photopage=0; deleteindex($prefix, $id, $photopage); $record = $id; $body= explode(" ", $body); foreach($body as $value) { if (!empty($value) && (mb_strlen($value)>4)) { if (($module == "news") || ($module == "pages") || ($module == "spec") || ($module == "foryou") || ($module == "links") || ($module == "addlink") || ($module == "gallery")) { if ($module == "addlink") $bmodule = "links"; else $bmodule = $module; $query = "select check_active from ".$prefix."_".$bmodule." where id='$record'"; $row = $sql->fetch_one($query); $active = $row['check_active']; } else { $active = 1; $bmodule = $module; } $query = "select id from ".$prefix."_index_words where word='$value'"; $row = $sql->fetch_one($query); if (!empty($row)) { $query = "insert into ".$prefix."_index_links (word, parent, module, photopage, active) values('{$row['id']}', '$record', '$bmodule', '$photopage', '$active')"; $sql->query($query); } else { $query = "insert into ".$prefix."_index_words (word) values('$value')"; $sql->query($query); $word = $sql->insert_id(); $query = "insert into ".$prefix."_index_links (word, parent, module, photopage, active) values('$word', '$record', '$bmodule', '$photopage', '$active')"; $sql->query($query); } } } } } function deleteindex($prefix, $id, $photopage=0) { global $module,$sql,$tags_indexing; if ($tags_indexing) tagdeleteindex($prefix, $id, $photopage); $query = "SELECt word FROM ".$prefix."_index_links where parent='$id' and module='$module' and photopage='$photopage'"; $row = $sql->fetch_array($query); foreach ($row as $value) { $query = "select count(*) as count from ".$prefix."_index_links where word=".$value['word']." and (parent!='$id' || photopage!='$photopage')"; $row = $sql->fetch_one($query); $count = $row['count']; if ($count == 0) { $query = "delete from ".$prefix."_index_words where id=".$value['word']; $sql->query($query); } } $query = "delete from ".$prefix."_index_links where parent='$id' and photopage='$photopage'"; $sql->query($query); } function sw(&$item1, $key) { if (strlen($item1)<3) $item1=""; } function active($id, $active) { global $prefix,$prefix2, $module, $expand, $indexing, $sql,$langs,$c_parts; if (isset($_SESSION['parentmodule'])) $pmodule = $_SESSION['parentmodule']['child']; else $pmodule = $module; if (sizeof($c_parts->getSynhroElements($pmodule)>0) and is_array($c_parts->getSynhroElements($pmodule))) { if(in_array('check_active',$c_parts->getSynhroElements($pmodule))) { foreach($langs as $key => $value) { $query="update ".$prefix."_".$key."_".$pmodule." set check_active='$active' where id='$id'"; $sql->query($query); } } else { $query="update ".$prefix2."_".$pmodule." set check_active='$active' where id='$id'"; $sql->query($query); } } else { $query="update ".$prefix2."_".$pmodule." set check_active='$active' where id='$id'"; $sql->query($query); } // if ($indexing) // { // $query="update ".$prefix2."_index_links set active='$active' where parent='$id' and module='$module'"; // $sql->query($query); // } if (!empty($_SESSION['s_http_prev'])) { $i = strpos($_SESSION['s_http_prev'], "active"); if ($i === FALSE) header("Location: ".$_SESSION['s_http_prev']); else header("Location: admin.php?module=".$module); } else header("Location: admin.php?module=".$module); } function addslashes_inArray($arr) { foreach($arr as $key => $value) if (is_array($value)) $arr[$key] = addslashes_inArray($value); else $arr[$key] = addslashes((string)$value); return $arr; } function formatPrice($price) { $prcm=array(); $i=-1; if(strlen($price)>3) { $price1=$price; while(strlen($price1)>3) { $prc1=substr($price1, strlen($price1)-3, 3); $prc2=substr($price1, 0, strlen($price1)-3); $i++; $prcm[$i]=$prc1; $price1=$prc2; } $i++; $prcm[$i]=$price1; $prcret=''; for($i=0; $ifetch_one($query); return $row['maxord']+1; } function GetValueID() { global $prefix2,$module,$id,$sql; $table = $prefix2.'_'.$module; if ($id) { $query = "SELECT id FROM $table WHERE text_value='$id'"; $row = $sql->fetch_one($query); if ($row['id']) $id = $row['id']; } else { $query = "SELECT id FROM $table WHERE check_active=1 AND parent=0 ORDER BY ord LIMIT 1"; $row = $sql->fetch_one($query); $id = $row['id']; } } function GetAllValue($custom=false) { global $module; if ($custom) $module = $custom; $cols = array('*'); $where = array('parent' => '0'); return sql_select($cols, $where); } function FillMeta($page) { global $data; if ($page['text_title']) $data['title'] = $page['text_title']; else $data['title'] = $page['text_name']; if ($page['textarea_keywords']) $data['keywords'] = $page['textarea_keywords']; if ($page['textarea_description']) $data['description'] = $page['textarea_description']; } function FillMetaID($id) { global $prefix2,$sql,$data; $query = "SELECT * FROM ".$prefix2."_meta WHERE id='$id'"; $page = $sql->fetch_one($query); if ($page['text_title']) $data['title'] = $page['text_title']; else $data['title'] = $page['text_name']; if ($page['textarea_keywords']) $data['keywords'] = $page['textarea_keywords']; if ($page['textarea_description']) $data['description'] = $page['textarea_description']; } function SendAdminMail($message,$subject,$from=false) { global $defGeneral; $mail_adm = $defGeneral['admin_mail']; if (!$from) $from = $mail_adm; $headers = "Content-type: text/plain; charset=windows-1251\r\nFrom: ".$from; mail($mailadm,mb_convert_encoding($subject,"WINDOWS-1251","UTF-8"),mb_convert_encoding($message,"WINDOWS-1251","UTF-8"),$headers); } function add($mess) { global $errmess; $errmess .= $mess."
\n"; } function saveWatermark($img,$path="") { include_once 'include/watermark.php'; $img_watermark = 'images/water.gif'; if (empty($path)) $path = 'upload/objects/tmp/'; $watermark = new watermark(); $watermarkinfo = getimagesize($img_watermark); if ($watermarkinfo['mime'] == 'image/jpeg') $watermark_img_obj = imagecreatefromjpeg($img_watermark); elseif($watermarkinfo['mime'] == 'image/gif') $watermark_img_obj = imagecreatefromgif($img_watermark); elseif($watermarkinfo['mime'] == 'image/png') $watermark_img_obj = imagecreatefrompng($img_watermark); $imginfo = getimagesize($path.$img); if ($imginfo['mime'] == 'image/jpeg') { $main_img_obj = imagecreatefromjpeg($path.$img); $return_img_obj = $watermark->create_watermark($main_img_obj,$watermark_img_obj,50); imagejpeg($return_img_obj,$path.$img,100); } elseif($imginfo['mime'] == 'image/gif') { $main_img_obj = imagecreatefromgif($path.$img); $return_img_obj = $watermark->create_watermark($main_img_obj,$watermark_img_obj,50); imagegif($return_img_obj,$path.$img); } elseif($imginfo['mime'] == 'image/png') { $main_img_obj = imagecreatefrompng($path.$img); $return_img_obj = $watermark->create_watermark($main_img_obj,$watermark_img_obj,50); imagepng($return_img_obj,$path.$img,50); } } ?>