<svg version="1.1" style="position: absolute; width: 680px; height: 232px;">
<desc></desc>
<g>
<g transform="translate(48,40)" visibility="visible">
<image x="0" y="0" width="19" height="19" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://content.ikon.mn/chart/3142/images/lens.png"></image>
<text y="0" fill="#000000" font-family="Verdana" font-size="11" opacity="1">
<tspan y="0" x="0" style="font-size: 13px;">Бүгдийг харах</tspan>
</text>
</g>
</g>
</svg>
Sunday, August 16, 2015
Monday, August 10, 2015
write comment by ajax post using codeigniter with recaptcha
PHP
public function write_comment($article_id) {
$this->xhr_protect();
$this->load->config('recaptcha');
$secret_key = $this->config->item('secret_key', 'recaptcha');
require_once (APPPATH . 'libraries/recaptcha/recaptchalib.php');
$cf = $this->input->post('recaptcha_challenge_field');
$rf = $this->input->post('recaptcha_response_field');
$title = $this->input->post('title');
$message = $this->input->post('message');
if (empty($title) || empty($message)) {
$this->error('Нэр эсвэл сэтгэгдэл хоосон байна!');
}
$resp = recaptcha_check_answer($secret_key
, $this->input->ip_address()
, $cf
, $rf);
if (!$resp->is_valid) {
$this->error("Шалгах хэсэг буруу байна! (reCAPTCHA said: " . $resp->error . ")");
}
$article = $this->article_model->get($article_id);
if (empty($article)) {
show_404();
} else {
$this->load->model('comment_model');
$comment = array();
$comment['title'] = html_escape($title);
$comment['message'] = html_escape($message);
$comment['approved'] = 1;
$comment['ipaddress'] = $this->input->ip_address();
$comment['createddate'] = utc_datetime();
$comment['id'] = $this->comment_model->save($comment);
$article_comment = array('article_id' => $article['id'], 'comment_id' => $comment['id']);
$this->article_comment_model->save($article_comment);
$comment['date'] = date_descr($comment['createddate']);
$this->success('Амжилттай!', array('data' => $comment));
}
}
JS
<script type="text/javascript">
function CreateCaptcha() {
Recaptcha.create('<?php echo $site_key; ?>', 'recaptcha', {theme: "red"});
}
$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js', CreateCaptcha);
$('.post-reply-entry button').click(function (event) {
event.preventDefault();
var arr = $('#write_comment').postItems();
var params = {};
for (var i = 0; i < arr.length; i++) {
params[arr[i].name] = arr[i].value;
}
$.ajax({
url: '<?php echo site_url('forum/write_comment/' . $article['id']); ?>',
type: 'post',
dataType: 'json',
data: params,
cache: false,
success: function (result) {
CreateCaptcha();
if (result.success) {
$('#write_comment').find('[name="message"]').val();
var comment = (result.data);
var s = '<div class="reply-post-one"><div class="reply-user"><span class="username">' + comment.title;
s += '</span><span class="date">' + comment.date + '</span></div><p>' + comment.message + '</p></div>';
$(s).prependTo($('#forum_comment_list'));
} else {
alert(result.message);
}
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
}
});
});
$('a[href="#write_comment"]').click(function (event) {
event.preventDefault();
$('.site-container').animate({
scrollTop: $($(this).attr('href')).offset().top - 100
}, 1000, 'swing');
return false;
});
</script>
public function write_comment($article_id) {
$this->xhr_protect();
$this->load->config('recaptcha');
$secret_key = $this->config->item('secret_key', 'recaptcha');
require_once (APPPATH . 'libraries/recaptcha/recaptchalib.php');
$cf = $this->input->post('recaptcha_challenge_field');
$rf = $this->input->post('recaptcha_response_field');
$title = $this->input->post('title');
$message = $this->input->post('message');
if (empty($title) || empty($message)) {
$this->error('Нэр эсвэл сэтгэгдэл хоосон байна!');
}
$resp = recaptcha_check_answer($secret_key
, $this->input->ip_address()
, $cf
, $rf);
if (!$resp->is_valid) {
$this->error("Шалгах хэсэг буруу байна! (reCAPTCHA said: " . $resp->error . ")");
}
$article = $this->article_model->get($article_id);
if (empty($article)) {
show_404();
} else {
$this->load->model('comment_model');
$comment = array();
$comment['title'] = html_escape($title);
$comment['message'] = html_escape($message);
$comment['approved'] = 1;
$comment['ipaddress'] = $this->input->ip_address();
$comment['createddate'] = utc_datetime();
$comment['id'] = $this->comment_model->save($comment);
$article_comment = array('article_id' => $article['id'], 'comment_id' => $comment['id']);
$this->article_comment_model->save($article_comment);
$comment['date'] = date_descr($comment['createddate']);
$this->success('Амжилттай!', array('data' => $comment));
}
}
JS
<script type="text/javascript">
function CreateCaptcha() {
Recaptcha.create('<?php echo $site_key; ?>', 'recaptcha', {theme: "red"});
}
$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js', CreateCaptcha);
$('.post-reply-entry button').click(function (event) {
event.preventDefault();
var arr = $('#write_comment').postItems();
var params = {};
for (var i = 0; i < arr.length; i++) {
params[arr[i].name] = arr[i].value;
}
$.ajax({
url: '<?php echo site_url('forum/write_comment/' . $article['id']); ?>',
type: 'post',
dataType: 'json',
data: params,
cache: false,
success: function (result) {
CreateCaptcha();
if (result.success) {
$('#write_comment').find('[name="message"]').val();
var comment = (result.data);
var s = '<div class="reply-post-one"><div class="reply-user"><span class="username">' + comment.title;
s += '</span><span class="date">' + comment.date + '</span></div><p>' + comment.message + '</p></div>';
$(s).prependTo($('#forum_comment_list'));
} else {
alert(result.message);
}
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
}
});
});
$('a[href="#write_comment"]').click(function (event) {
event.preventDefault();
$('.site-container').animate({
scrollTop: $($(this).attr('href')).offset().top - 100
}, 1000, 'swing');
return false;
});
</script>
year month day check using reg expression example
if (/^([0-9]|[12]\d|3[0-1])$/.test(30) === false) {
alert('Day is invalid or empty');
}
if (/^([0-9]|[4]\d|1[0-2])$/.test(4) === false) {
alert('Month is invalid or empty');
}
if (/^(19|20)\d{2}$/.test('1986') === false) {
alert('Year is invalid or empty');
}
alert('Day is invalid or empty');
}
if (/^([0-9]|[4]\d|1[0-2])$/.test(4) === false) {
alert('Month is invalid or empty');
}
if (/^(19|20)\d{2}$/.test('1986') === false) {
alert('Year is invalid or empty');
}
Wednesday, August 5, 2015
mssql 2012 feature is Sequence objects
create sequence MySeq as int
start with 1 -- Start with value 1
increment by 1-- Increment with value 1
minvalue 0 -- Minimum value to start is zero
maxvalue 100 -- Maximum it can go to 100
no cycle -- Do not go above 100
cache 50 -- Increment 50 values in memory rather than incrementing from IO
SELECT NEXT VALUE FOR dbo.MySeq AS seq_no;
SELECT current_value FROM sys.sequences WHERE name = 'MySeq';
start with 1 -- Start with value 1
increment by 1-- Increment with value 1
minvalue 0 -- Minimum value to start is zero
maxvalue 100 -- Maximum it can go to 100
no cycle -- Do not go above 100
cache 50 -- Increment 50 values in memory rather than incrementing from IO
SELECT NEXT VALUE FOR dbo.MySeq AS seq_no;
SELECT current_value FROM sys.sequences WHERE name = 'MySeq';
SQL SERVER – NULLIF() vs ISNULL()
SQL SERVER – NULLIF() vs ISNULL()
NULLIF() Returns a null value if the two specified expressions are equal. If the Two expressions are not equal then it will return the first expression's value. Whether the returned value is NULL or NOT NULL, NULLIF() will return the same data type as the first expression
Syntax : NULLIF(expression1,expression2)
Example 1 :
Select NULLIF(100,50*2) 'NULLIF Value'
OutPut :
Example 2 :
Select NULLIF(2*2,2*7) 'NULLIF Value'
OutPut :
Example 3 :
Select NULLIF(20-2,19) 'NULLIF Value'
OutPut :
ISNULL() Replaces the NULL value with the specified expression value.
Syntax : ISNULL(check expression,replacement value)
Example 1 :
Select ISNULL(null,12) 'ISNULL VALUE'
OutPut :
Example 2:
Select ISNULL(marks,0) 'Marks' from Student
OutPut :
pagenite by rownumber, different of subquery vs with clause in mssql
This is one way (SQL2000)
SELECT * FROM
(
SELECT TOP (@pageSize) * FROM
(
SELECT TOP (@pageNumber * @pageSize) *
FROM tableName
ORDER BY columnName ASC
) AS t1
ORDER BY columnName DESC
) AS t2
ORDER BY columnName ASC
and this is another way (SQL 2005)
;WITH results AS (
SELECT
rowNo = ROW_NUMBER() OVER( ORDER BY columnName ASC )
, *
FROM tableName
)
SELECT *
FROM results
WHERE rowNo between (@pageNumber-1)*@pageSize+1 and @pageNumber*@pageSize
and this is another way SQL2012
SELECT * FROM Table_1
ORDER BY id
OFFSET 1 ROWS FETCH NEXT 3 ROWS ONLY
example
SELECT * from (SELECT *, ROW_NUMBER() OVER(ORDER BY id asc) as rownum FROM [test].[dbo].[Table_1]
) as a
where a.rownum > 1 and a.rownum < 4
GO
with b as (
SELECT *, ROW_NUMBER() OVER(ORDER BY (select 1)) as rownum FROM [test].[dbo].[Table_1]
)
select top 10 * from b where b.rownum > 1
GO
Subscribe to:
Posts (Atom)