Архив

Архив Март 2013
17 марта 2013 1 комментарий
echo 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],'?'));
Categories: PHP Tags:
15 марта 2013 Нет комментариев

No comment.. Все достаточно просто.

var time_from=new Date(order_from['y'],order_from['m']-1,order_from['d']);
var time_to=new Date(order_to['y'],order_to['m']-1,order_to['d']);
var order_days=Math.floor((time_to.getTime()-time_from.getTime())/(1000*60*60*24));

http://belonogov.blogspot.com/2009/01/blog-post_12.html

Categories: Javascript Tags:
14 марта 2013 1 комментарий
<script type="text/javascript">
	function SearchBlur(text,input) {
		$inp = document.getElementById(input);
		if ($inp.value!='') {
			return false;
		}
		else {
			$inp.value=text;
		}
	}
	function SearchFocus(text,input) {
		$inp = document.getElementById(input);
		if ($inp.value==text) {
			$inp.value='';
		}
		else {
			return false;
		}
	}
</script>
<?php
function show_form() {
?>
	<form action="" method="post">
		<table class="blitz_feedback" border="0" cellspacing="0">
			<tr>
				<td class="label"><label for="name">ФИО</label></td>
				<td><input id="name" name="name" size="40" type="text"/></td>
			</tr>
			<tr>
				<td class="label"><label for="tel">Телефон</label></td>
				<td><input id="tel" name="tel" size="40" type="text"/></td>
			</tr>
			<tr>
				<td class="label"><label for="email">Почта</label></td>
				<td><input id="email" name="email" size="40" type="text"/></td>
			</tr>
			<tr>
				<td colspan="2">
					<textarea id="mess" name="mess" cols="41" rows="7" onfocus="SearchFocus('Ваше сообщение..','mess');" onblur="SearchBlur('Ваше сообщение..','mess');">Ваше сообщение..</textarea>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="label" align="right"><input type="submit" value="Отправить" name="submit"/></td>
			</tr>
		</table>
	</form>
<?
}
function complete_mail() {
	$_POST['mess']=htmlspecialchars(trim($_POST['mess']));
	$_POST['name']=htmlspecialchars(trim($_POST['name']));
	$_POST['tel']=htmlspecialchars(trim($_POST['tel']));
	$_POST['email']=htmlspecialchars(trim($_POST['email']));
	if ((empty($_POST['name']))||(!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i",$_POST['email']))||(empty($_POST['mess']))||(empty($_POST['tel']))) {
		$errors=array();
		if (empty($_POST['name'])) {
			$errors[]=0;
		}
		if(!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i",$_POST['email'])) {
			$errors[]=1;
		}
		if(empty($_POST['mess'])) {
			$errors[]=2;
		}
		if(empty($_POST['tel'])) {
			$errors[]=3;
		}
		output_err($errors);
	}
	else {
		$oCore_QueryBuilder_Select = Core_QueryBuilder::select()
			->from('constants')
			->where('name','=','SUPERUSER_EMAIL');
		$aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
		$to=$aRows[0]['value'];
		$mess='Имя отправителя:'.$_POST['name'].'
Контактный телефон:'.$_POST['tel'].'
Контактный email:'.$_POST['email'].'
'.$_POST['mess'];
		$title=$_SERVER['HTTP_HOST']." | Обратная связь";
		$from=$_POST['email'];
		$headers="From: {$from}\r\n";
		$headers.= "MIME-Version: 1.0\r\n";
		$headers.="Content-type: text/plain; charset=utf-8\r\n";
		$headers.="Content-Transfer-Encoding: 8bit";
		mail($to,$title,$mess,$headers);
		echo 'Спасибо! Ваше письмо отправлено.';
	}
}
function output_err($errors) {
	$err[0]='ОШИБКА! Не введено имя.';
	$err[1]='ОШИБКА! Неверно введен e-mail.';
	$err[2]='ОШИБКА! Не введено сообщение.';
	$err[3]='ОШИБКА! Не введен телефон.';
	foreach ($errors as $error) {
		echo '<p class="mess_err">'.$err[$error].'</p>';
	}
	show_form();
}
if (isset($_POST['submit'])) {
	complete_mail();
}
else {
	show_form();
}
?>

Взято за основу: http://www.hostcms.ru/forums/17/981/

Categories: CMS Tags: ,
14 марта 2013 Нет комментариев

Для SELECT (в примере для получения всех активных товаров)

$oCore_QueryBuilder_Select = Core_QueryBuilder::select()
	->from('shop_items')
	->where('active', '=', 1);
$aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
foreach ($aRows as $row) {
	echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
}

Документация по QueryBuilder: http://www.hostcms.ru/documentation/guide/modules/core/querybuilder/

Categories: CMS Tags: ,
13 марта 2013 Нет комментариев

xls-шаблоны находятся в папке /hostcmsfiles/xsl/
Имена в формате id_шаблона.xsl

Categories: CMS Tags:
13 марта 2013 Нет комментариев

Ошибка при редактировании шаблонов: экранирование кавычек (портятся файлы template.htm и style.css). В следствии чего на сайте
Unexpected character in input: '\' (ASCII=92) state=1
Решается отключением 3 видов магических кавычек (не пробовал)

magic_quotes_gpc Off
magic_quotes_runtime Off
magic_quotes_sybase Off

Еще советуют в bootstrap.php вынести в начало файла:

set_magic_quotes_runtime(0);
ini_set('magic_quotes_gpc', 0);
ini_set('magic_quotes_sybase', 0);
ini_set('magic_quotes_runtime', 0);

но мне не помогло.

Categories: CMS Tags: ,
10 марта 2013 Нет комментариев

В примере нужно собрать массив sql-запросов из файла дампа sql.

<?php
function remove_comments(&$output) {
	$lines = explode("\n", $output);
	$output = "";
	$linecount = count($lines);
	$in_comment = false;
	for($i = 0; $i < $linecount; $i++) {
		if( preg_match("/^\/\*/", preg_quote($lines[$i])) ) {
			$in_comment = true;
		}
		if( !$in_comment ) {
			$output .= $lines[$i] . "\n";
		}
		if( preg_match("/\*\/$/", preg_quote($lines[$i])) ) {
			$in_comment = false;
		}
	}
	unset($lines);
	return $output;
}
function remove_remarks($sql) {
	$lines = explode("\n", $sql);
	$sql = "";
	$linecount = count($lines);
	$output = "";
	for ($i = 0; $i < $linecount; $i++) {
		if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0)) {
			if ($lines[$i][0] != "#") {
				$output .= $lines[$i] . "\n";
			}
			else {
				$output .= "\n";
			}
			$lines[$i] = "";
		}
	}
	return $output;
}
function split_sql_file($sql, $delimiter) {
	$tokens = explode($delimiter, $sql);
	$sql = "";
	$output = array();
	$matches = array();
	$token_count = count($tokens);
	for ($i = 0; $i < $token_count; $i++) {
		if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0))) {
			$total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
			$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
			$unescaped_quotes = $total_quotes - $escaped_quotes;
			if (($unescaped_quotes % 2) == 0) {
				$output[] = $tokens[$i];
				$tokens[$i] = "";
			}
			else {
				$temp = $tokens[$i] . $delimiter;
				$tokens[$i] = "";
				$complete_stmt = false;
				for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++) {
					$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
					$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
					$unescaped_quotes = $total_quotes - $escaped_quotes;
					if (($unescaped_quotes % 2) == 1) {
						$output[] = $temp . $tokens[$j];
						$tokens[$j] = "";
						$temp = "";
						$complete_stmt = true;
						$i = $j;
					}
					else {
						$temp .= $tokens[$j] . $delimiter;
						$tokens[$j] = "";
					}
				}
			}
		}
	}
	return $output;
}
?>

Использование, учитывая что $ungzdata — текст из файла sql-дампа.

$SQL=array();
$SQL=remove_comments($ungzdata);
$SQL=remove_remarks($SQL);
$SQL=split_sql_file($SQL,";");
Categories: MySQL, PHP Tags: ,