<?php
/*
=====================
Модуль скачан с сайта:
Понедельников НЕТ! - Сайт альтернативной поддержки Slaed CMS! (http://www.ponedelnikov.net)
=====================
SHAKA1, 2009
e-mail: seregam007@mail.ru
=====================
*/
if (!defined('MODULE_FILE')) {Header("Location: ../../index.php");exit;}

$module_name = basename(dirname(__FILE__));
get_lang($module_name);
require_once("config/config_ideas.php");
require_once("ideas/functions.php");

function idea_comments($iid, $close=1, $reason='', $stop='', $descript='', $addname='', $addmail='', $whoclose='') {
global $db, $prefix, $user, $idea, $module_name, $admin, $admin_file;
list($count) = $db->sql_fetchrow($db->sql_query("SELECT Count(id) FROM ".$prefix."_icomments WHERE iid='$iid'"));
$content ='<div class="blue_block"><div class="blue_lt"><div class="blue_rt"><div class="blue_lb"><div class="blue_rb"><div class="blue_block_status">';
if ($count>0) {
$total_pages = ceil($count / $idea['com_page']);
if ($idea['com_nap']==2) $pagenum = (isset($_GET['pagenum'])) ? intval($_GET['pagenum']) : $total_pages;
else $pagenum = (isset($_GET['pagenum'])) ? intval($_GET['pagenum']) : 1;
if ($idea['com_nap']==2) $min = $idea['com_page'] * ($total_pages - $pagenum);
else $min = $idea['com_page'] * ($pagenum - 1);
$content .='<h2 class="comments">'._COM_IDEA.'</h2>';
$result = $db->sql_query("SELECT id, uid, author, cdate, text, ip, email FROM ".$prefix."_icomments WHERE iid='$iid' ORDER BY cdate ".$idea['sort_comm']." LIMIT $min, ".$idea['com_page']."");
while(list($id, $uid, $author, $cdate, $text, $ip, $email) = $db->sql_fetchrow($result)) {
$content .='<div class="line_com"></div><div class="comment_block"><div class="user_ansver">';
if ($uid!=0) $content .='<a href="index.php?name=Account&amp;op=info&amp;uname='.$author.'">'.$author.'</a>';
else $content .='<span class="iguest_ansver">'.$author.'</span>';
if ($idea['bb_decode']==1 || $idea['bb_comm']==1) $text=bb_decode($text);
$text=nl2br($text);
$content .=', '.ideadate($cdate, 1).'</div><div class="commnent_text">'.$text.'</div>';
$content .='</div>';
if (is_admin($admin)) $content .= '<div style="margin-top:30px;background: #FFFFCC;border: 1px solid green;"><div style="margin:5px;">['._IP_IADM.' <a href="http://www.dnsstuff.com/tools/whois.ch?ip='.$ip.'">'.$ip.'</a> - <a href="/'.$admin_file.'.php?op=SecurityBlocker&amp;new_ip='.$ip.'">'._BLOCK_IADM.'</a> | '._MAIL_IADM.' <a href="mailto:'.$email.'">'.$email.'</a>]<br />[<a href="'.$admin_file.'.php?op=aidea_comedit&amp;id='.$id.'">'._EDT_IADM.'</a> | <a href="'.$admin_file.'.php?op=aidea_comdel&amp;id='.$id.'">'._DEL_IADM.'</a>]</div></div>';
}
if ($count>$idea['com_page']) $content .='<div class="line_com"></div>';
$content .=ideas_page($module_name, $count, $total_pages, $idea['com_page'], "op=full_idea&amp;id=$iid&amp;", $idea['com_nap']);
} else $content .='<h2 class="r_title no_bg pl0">'._NOT_COM.'</h2>';
$content .='</div></div></div></div></div></div>';
if ($idea['add_comm']==3) $content .=idea_comform(0, ""._DEF_IER1."", "", "", $iid);
elseif ($idea['add_comm']==2 && $close==3) $content .=idea_comform(0, ""._DEF_IER2."$whoclose"._DEF_IER21."", $reason, "", $iid);
elseif ($idea['add_comm']==2 && !is_user($user)) $content .=idea_comform(0, ""._DEF_IER3."", "", "", $iid);
elseif ($idea['add_comm']!=4 && $close==3) $content .=idea_comform(0, ""._DEF_IER4."", $reason, "", $iid);
elseif ($idea['add_comm']!=4 && $close==2 && !is_user($user)) $content .=idea_comform(0, ""._DEF_IER5."", $reason, "", $iid);
elseif ($stop!='') $content .=idea_comform(1, "", "", $stop, $iid, $descript, $addname, $addmail);
else $content .=idea_comform(1, "", "", "", $iid);
return $content;
}

function idea_comform($status=0, $msg='', $reason='', $stop='', $iid=0, $descript='', $addname='', $addmail='') {
global $user, $idea, $module_name;
$valid='';
if ($reason!='') $msg=$reason;
if ($status==0 || $iid==0) return $text='<h2 class="r_title no_bg pl0">'.$msg.'</h2>';
else {
$text ='<form action="index.php?name='.$module_name.'&amp;op=icom_save" name="post" id="idea_create" method="post"><div class="gr_block_lt"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content">'.$stop.'<div class="input_comment">'._COM_TEXT.'</div>';
if($idea['bb_comm']==1) $text .='<textarea id="ifull" name="descript" cols="65" rows="5" style="width:400px" onkeypress="TransliteFeld(this, event)" onselect="FieldName(this, this.name)" onclick="FieldName(this, this.name)" onkeyup="FieldName(this, this.name)">'.$descript.'</textarea>'.get_code("ifull").'';
else $text .='<textarea name="descript" id="ifull" cols="15" rows="15" style="width:500px;">'.$descript.'</textarea>';
$valid .='<script type="text/javascript">var ifull = new LiveValidation(\'ifull\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true, onValid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}, onInvalid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}}); ifull.add(Validate.Length, {minimum: 10, tooShortMessage: "'._COM_VALID3.'"});</script>';
$text .='<br /><br /></div></div></div></div></div>';
if (($idea['code_comm']==1 && !is_user($user)) || $idea['code_comm']==2) {
$code ='<tr><td class="lbl"><span id="slaed-capcha"><img src="/kcaptcha/index.php?rnd='.time().'" class="lblimg" style="cursor:pointer;" onclick="this.a;if (!this.a)this.a=this.src; this.src=this.a+\'&amp;new=\'+Math.random();" title="'._IDEA_CLICK.'" alt="'._IDEA_CODE.'" /></span></td><td><input type="hidden" name="opi" value="ds" /><input type="text" id="icode" name="keystring" class="inp" maxlength="6" /><br /><small class="requer">'._IDEA_CODE.'</small></td>';
$valid .='<script type="text/javascript">var icode = new LiveValidation(\'icode\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true }); icode.add(Validate.Length, { is: 6 , wrongLengthMessage: "'._IDEA_VALID4.'"});</script>';
$code .='</tr>';
} else $code='';
if (is_user($user) && $idea['code_comm']==2) $text .='<div class="gr_block_lt" id="verify_logged_cont"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content"><div id="verify_logged">'._IDEA_HELLO.'<a href="/index.php?name=Account&amp;op=info&amp;uname='.text_filter($user[1]).'" class="idea_author_name">'.text_filter($user[1]).'</a>'._IDEA_HELLO2.' <table class="form1">'.$code.'</table></div></div></div></div></div></div>';
elseif (is_user($user)) $text .='<div class="gr_block_lt" id="verify_logged_cont"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content"><div id="verify_logged">'._COM_HELLO.'<a href="/index.php?name=Account&amp;op=info&amp;uname='.text_filter($user[1]).'" class="idea_author_name">'.text_filter($user[1]).'</a>'._COM_HELLO2.'</div></div></div></div></div></div>';
elseif (!is_user($user)) {
$text .='<div class="gr_block_lt_normal" id="inline_auth_block"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="r_block_content with_tab_menu"><div id="no_registration"><table class="form1"><tr><td class="lbl">'._IDEA_NAME.'<br /><small class="requer">'._IDEA_REC.'</small></td><td><input type="text" id="iname" name="addname" value="'.$addname.'" class="inp" /></td></tr>';
$valid .='<script type="text/javascript">var iname = new LiveValidation(\'iname\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true}); iname.add(Validate.Length, {minimum: 3, tooShortMessage: "'._IDEA_VALID5.'"});</script>';
$text .='<tr><td class="lbl">'._IDEA_EMAIL.'<br /><small class="requer">'._IDEA_REC.'</small></td><td><input type="text" id="imail" name="addmail" value="'.$addmail.'" class="inp" /></td>';
$valid .='<script type="text/javascript">var imail = new LiveValidation(\'imail\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true }); imail.add(Validate.Email, {failureMessage: "'._IDEA_VALID6.'"});</script>';
$text .='</tr>'.$code .'</table>'.$valid .'</div><div class="cl"></div></div></div></div></div></div>';
}
$text .='<div class="gr_block_lt"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content">'._COM_QUOTE.'<div class="add_idea"><input type="hidden" name="iid" value="'.$iid.'"  /><a href="javascript: _v(\'idea_create\').submit();" class="add_idea_link">'._COM_INPUT.'</a></div><div class="cl"></div></div></div></div></div></div></form>';
}
return $text;
}

function icom_save() {
global $prefix, $db, $user, $defis, $idea, $module_name;
$stop='';
$iid = (isset($_POST['iid'])) ? intval($_POST['iid']) : 0;
if ($idea['add_comm']==3) $stop=""._DEF_IER1."";
elseif ($idea['add_comm']==2 && $close==3) $stop=""._DEF_IER6."";
elseif ($idea['add_comm']==2 && !is_user($user)) $stop=""._DEF_IER3."";
elseif ($idea['add_comm']!=4 && $close==3) $stop=""._DEF_IER4."";
elseif ($idea['add_comm']!=4 && $close==2 && !is_user($user)) $stop=""._DEF_IER5."";
if ($stop!='') {full_idea($iid, $stop);exit;}
else {
$ip = text_filter(getenv("REMOTE_ADDR"));
if (isset($_POST['descript']) && strlen(trim($_POST['descript']))>=10) $descript=text_filter($_POST['descript']);
else {$stop .='<div class="LV_invalid">'._COM_ERROR2.'</div>';$descript=text_filter($_POST['descript']);}
if(!is_user($user)) {
if (isset($_POST['addname']) && strlen(trim($_POST['addname']))>=3) $addname=text_filter($_POST['addname']);
else {$stop .='<div class="LV_invalid">'._IDEA_ERROR3.'</div>';$addname=text_filter($_POST['addname']);}
if (isset($_POST['addmail']) && trim($_POST['addmail'])!='' && validmail(text_filter($_POST['addmail']))==1) $addmail=text_filter($_POST['addmail']);
else {$stop .='<div class="LV_invalid">'._IDEA_ERROR4.'</div>';$addmail=text_filter($_POST['addmail']);}
$ins="NULL, '$iid', '0', '$addname', '".time()."', '$descript', '$ip', '$addmail'";
} elseif (is_user($user)) {
$userinfo=getusrinfo($user);
$addname=$userinfo['user_name'];
$addmail=$userinfo['user_email'];
$uid=$userinfo['user_id'];
$ins="NULL, '$iid', '$uid', '$addname', '".time()."', '$descript', '$ip', '$addmail'";
}
if (captcha_check_captcha(1) && ($idea['code_comm']==2 || ($idea['code_comm']==1 && !is_user($user)))) $stop .='<div class="LV_invalid">'._IDEA_ECAPCHA.'</div>';
elseif (captcha_check_captcha(0) && $stop=='') {
$db->sql_query("INSERT INTO ".$prefix."_icomments VALUES ($ins)");
$db->sql_query("UPDATE ".$prefix."_ideas SET comments=comments+1 WHERE id='$iid'");
Header("Location: index.php?name=$module_name&op=full_idea&id=$iid");
}
if ($stop!='') {full_idea($iid, "<br /><h3>"._IDEA_ERROR5."</h3>$stop<br />", $descript, $addname, $addmail);exit;}
}
}

function ai_rating($id='', $totalvotes='', $votes='', $num='') {
global $db, $prefix, $user, $idea, $module_name;
ajax_cache();
$urlplus='#';
$urlminus='#';
$idea['rating2']=$idea['rating']*3600;
$java = (isset($_GET['java'])) ? intval($_GET['java']) : 1;
$id = (isset($_GET['id'])) ? intval($_GET['id']) : $id;
$rating = (isset($_GET['rating'])) ? intval($_GET['rating']) : 0;
if ($idea['javavoit']=='1') {$urlplus='index.php?name='.$module_name.'&amp;op=ai_rating&amp;id='.$id.'&amp;rating=1&amp;java=0';$urlminus='index.php?name='.$module_name.'&amp;op=ai_rating&amp;id='.$id.'&amp;rating=2&amp;java=0';
} elseif ($idea['javavoit']=='0' && $java=='0') {Header("Location: index.php?name=$module_name"); return false;}
if ($id) {
$query = "totalvote, karma FROM ".$prefix."_ideas WHERE id='$id'";
$ip = getip_idea();
$cookies = (intval($_COOKIE['Ideas-'.$id.''])) ? $_COOKIE['Ideas-'.$id.''] : "";
$postname = (is_user($user)) ? text_filter(substr($user[1], 0, 25)) : "";
   if (($idea['whovote']=='1' && !is_user($user)) || $idea['whovote']=='3') {
 if (isset($_GET['java'])) Header("Location: index.php?name=$module_name");
 else return "".vote_graphic_ajax($votes, $totalvotes, '0')."";
   } elseif ($cookies == $id || $num > 0) {
return "".vote_graphic_ajax($votes, $totalvotes, '1')."";
   } elseif (!$cookies && !$num && !$rating) {
$votes = (intval($votes)) ? $votes : 1;
if ($idea['rating_minus']==1) return '<div id="rate'.$id.'"><a href="'.$urlplus.'" class="vote_plus" onclick="return ajax(\'index.php?name='.$module_name.'&op=ai_rating&id='.$id.'&rating=1\', \'rate'.$id.'\');" title="'._GOOD_IDEA.'">'._PLUS_IDEA.'</a><span>'.$totalvotes.'</span> '.plur_lng(abs($totalvotes), ''._COUNT_VOTE.'').'<a href="'.$urlminus.'" onclick="return ajax(\'index.php?name='.$module_name.'&op=ai_rating&id='.$id.'&rating=2\', \'rate'.$id.'\');" class="vote_minus" title="'._BAD_IDEA.'">'._MINUS_IDEA.'</a></div>';
else return '<div id="rate'.$id.'"><span>'.$totalvotes.'</span> '.plur_lng(abs($totalvotes), ''._COUNT_VOTE.'').'<a href="'.$urlplus.'" class="vote_idea" onclick="return ajax(\'index.php?name='.$module_name.'&op=ai_rating&id='.$id.'&rating=1\', \'rate'.$id.'\');" title="'._GOOD_IDEA.'">'._VOTE_BUTTON.'</a></div>';
   } elseif (!$cookies && !$num && $rating) {
   $new = time();
if ($idea['rating_minus']==1 || ($idea['rating_minus']==0 && $rating==1)) {setcookie("Ideas-".$id."", $id, time() + intval($idea['rating2']));$db->sql_query("INSERT INTO ".$prefix."_irating VALUES (NULL, '$id', '$new', '$postname', '$ip')");}
 if ($rating==1) $db->sql_query("UPDATE ".$prefix."_ideas SET totalvote=totalvote+1, karma=karma+1 WHERE id='$id'");
 elseif ($rating==2 && $idea['rating_minus']==1) $db->sql_query("UPDATE ".$prefix."_ideas SET totalvote=totalvote+1, karma=karma-1 WHERE id='$id'");
list($votes, $totalvotes) = $db->sql_fetchrow($db->sql_query("SELECT ".$query.""));
 if ($java==0) Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
 else print "".vote_graphic_ajax($votes, $totalvotes, '1')."";
}
} else Header("Location: index.php?name=$module_name");
}

function vote_graphic_ajax($votes, $total, $youvote='0') {
ajax_cache();
$votes = intval($votes)>0 ? $votes : 1;
$stle='cnt';
if ($total<'0') $stle='red';
if ($youvote=='1') $content ='<div id="vote_'.$stle.'"><span>'.$total.'</span> '.plur_lng(abs($total), ''._COUNT_VOTE.'').'<div class="you_vote_foot"><span>'._VOTE_IDEA.'</span></div></div>';
else $content ='<div id="vote_'.$stle.'"><span>'.$total.'</span> '.plur_lng(abs($total), ''._COUNT_VOTE.'').'</div>';
return $content;
}

function add_form($all=0) {
global $module_name, $user, $idea;
if ($idea['addidea']==2 || ($idea['addidea']==1 && is_user($user)) || $all==1) {
$text ='<div class="left_part"><div id="search_block">
<form action="index.php?name='.$module_name.'&amp;op=add_idea" method="post">
<fieldset><div class="i_prop">'._I_WANT.'</div>
<input name="title" id="search_input" type="text" value="" maxlength="50" />
<input type="submit" value="" class="search_go" onmouseover="this.className=\'search_goover\';" onmouseout="this.className=\'search_go\';" />
<input type="button" value="" id="search_reset" onclick="_v(\'search_input\').value=\'\';" />
</fieldset>
</form>
</div></div>';
} else $text='';
return $text;
}

function popup_idea() {
global $prefix, $db, $module_name, $idea;
$count=0;
list($count) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_ideas"));
$text ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>'._I_WANT.'</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /><link rel="stylesheet" href="ideas/css-idea.css" type="text/css" /></head><body style="background:#EFEFEF">';
if ($count>0) {
if ($idea['popconst']!='') $where='WHERE id IN ('.$idea['popconst'].')';
elseif ($idea['moder']==1) $where='WHERE status!=5'; else $where='';
if($idea['popconst']!='') $result = $db->sql_query("SELECT id, title, karma, status FROM ".$prefix."_ideas $where ORDER BY ".$idea['poporder']." ".$idea['popsort']."");
else $result = $db->sql_query("SELECT id, title, karma, status FROM ".$prefix."_ideas $where ORDER BY ".$idea['poporder']." ".$idea['popsort']." LIMIT 0, ".$idea['poplimit']."");
$text .='<div class="gray_block"><div class="saersh_info">'.plur_lng($count, ''._COUNT_SAY.'').' '.$count.' '.plur_lng($count, ''._COUNT_IDEA.'').'...</div><div class="white_block"><div class="white_block_top">';
while(list($id, $title, $karma, $status) = $db->sql_fetchrow($result)) {
if (strlen(strip_tags($title))>$idea['cut']) $title="".cut($title,$idea['cut'],$idea['cut'])."...";
if ($status=='1') $statuscl='<div class="status status1_s status_right"><a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" target="_blank">'._DISMISS_IDEA.'</a></div></div>';
elseif ($status=='2') $statuscl='<div class="status status2_s status_right"><a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" target="_blank">'._DOING_IDEA.'</a></div></div>';
elseif ($status=='3') $statuscl='<div class="status status3_s status_right"><a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" target="_blank">'._PLAN_IDEA.'</a></div></div>';
elseif ($status=='4') $statuscl='<div class="status status4_s status_right"><a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" target="_blank">'._EXECUTE_IDEA.'</a></div></div>';
else $statuscl='</div>';
$stle='green';
if ($karma<0) $stle='red';
$text .= '<div class="idea_green_block"><div class="idea_green_bottom"><div class="idea_green_top">
<div class="idea_'.$stle.'_left"><div class="vote_count"><b>'.$karma.'</b> '.plur_lng(abs($karma), ''._COUNT_VOTE.'').'</div>
'.$statuscl.'
<div class="idea_title">
<a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" class="drop_right" target="_blank"></a>
<a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" target="_blank"><b>'.$title.'</b></a>
</div>
<div class="cl"></div></div></div></div>';
	}
	$text .= '</div></div>';
} else $text .= '<div class="gray_block"><div class="saersh_info">'._NO_IDEA.'</div></div>';
$text .='</body></html>';
print $text;
}

function add_idea($title='', $descript='', $addname='', $addmail='', $stop='') {
global $prefix, $db, $user, $module_name, $pagetitle, $defis, $idea;
$valid='';
$pagetitle = "$defis "._ADD_IDEA."";
if (isset($_POST['title']) && $_POST['title']!='') $title=text_filter($_POST['title']);
head();
OpenTable();
if ($idea['naviform']!=0) print imenu(0);
if ($idea['addidea']=='0') $text=warning(""._IDEA_ACT0."", "", "", 1);
elseif ($idea['addidea']=='1' && !is_user($user)) $text=warning(""._IDEA_ACT1."", "", "", 1);
else {
$text ='<form action="index.php?name='.$module_name.'&amp;op=save_idea" id="idea_create" name="post" method="post"><div class="gr_block_lt"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content">'.$stop.'<h3>'._I_WANT.'</h3><input type="text" name="title" id="ititle" value="'.$title.'" class="proj_input" />';
$valid .='<script type="text/javascript">var ititle = new LiveValidation(\'ititle\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true, onValid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}, onInvalid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}}); ititle.add(Validate.Length, {minimum: 10, tooShortMessage: "'._IDEA_VALID2.'"});</script>';
$text .='<br /><br /><div class="input_comment">'._IDEA_MORE.'</div>'.get_code("ifull").'<textarea id="ifull" name="descript" cols="65" rows="5" style="width:400px" onkeypress="TransliteFeld(this, event)" onselect="FieldName(this, this.name)" onclick="FieldName(this, this.name)" onkeyup="FieldName(this, this.name)">'.$descript.'</textarea>';
$valid .='<script type="text/javascript">var ifull = new LiveValidation(\'ifull\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true, onValid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}, onInvalid: function(){this.insertMessage(this.createMessageDiv()); this.addFieldClass();}}); ifull.add(Validate.Length, {minimum: 20, tooShortMessage: "'._IDEA_VALID3.'"});</script>';
$text .='<br /><br /></div></div></div></div></div>';
if (($idea['seccode']==1 && !is_user($user)) || $idea['seccode']==2) {
$code ='<tr><td class="lbl"><span id="slaed-capcha"><img src="/kcaptcha/index.php?rnd='.time().'" class="lblimg" style="cursor:pointer;" onclick="this.a;if (!this.a)this.a=this.src; this.src=this.a+\'&amp;new=\'+Math.random();" title="'._IDEA_CLICK.'" alt="'._IDEA_CODE.'" /></span></td><td><input type="hidden" name="opi" value="ds" /><input type="text" id="icode" name="keystring" class="inp" maxlength="6" /><br /><small class="requer">'._IDEA_CODE.'</small></td></tr>';
$valid .='<script type="text/javascript">var icode = new LiveValidation(\'icode\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true }); icode.add(Validate.Length, { is: 6 , wrongLengthMessage: "'._IDEA_VALID4.'"});</script>';
} else $code='';
if (is_user($user) && $idea['seccode']==2) $text .='<div class="gr_block_lt" id="verify_logged_cont"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content"><div id="verify_logged">'._IDEA_HELLO.'<a href="/index.php?name=Account&amp;op=info&amp;uname='.text_filter($user[1]).'" class="idea_author_name">'.text_filter($user[1]).'</a>'._IDEA_HELLO2.' <table class="form1">'.$code.'</table></div></div></div></div></div></div>';
elseif (is_user($user)) $text .='<div class="gr_block_lt" id="verify_logged_cont"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content"><div id="verify_logged">'._IDEA_HELLO.'<a href="/index.php?name=Account&amp;op=info&amp;uname='.text_filter($user[1]).'" class="idea_author_name">'.text_filter($user[1]).'</a>'._IDEA_HELLO2.'</div></div></div></div></div></div>';
elseif (!is_user($user)) {
$text .='<div class="gr_block_lt_normal" id="inline_auth_block"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="r_block_content with_tab_menu"><div id="no_registration"><table class="form1"><tr><td class="lbl">'._IDEA_NAME.'<br /><small class="requer">'._IDEA_REC.'</small></td><td><input type="text" id="iname" name="addname" value="'.$addname.'" class="inp" /></td></tr>';
$valid .='<script type="text/javascript">var iname = new LiveValidation(\'iname\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true}); iname.add(Validate.Length, {minimum: 3, tooShortMessage: "'._IDEA_VALID5.'"});</script>';
$text .='<tr><td class="lbl">'._IDEA_EMAIL.'<br /><small class="requer">'._IDEA_REC.'</small></td><td><input type="text" id="imail" name="addmail" value="'.$addmail.'" class="inp" /></td></tr>';
$valid .='<script type="text/javascript">var imail = new LiveValidation(\'imail\', { validMessage: "'._IDEA_VALID1.'", onlyOnBlur: true }); imail.add(Validate.Email, {failureMessage: "'._IDEA_VALID6.'"});</script>';
$text .=''.$code .'</table>'.$valid.'</div><div class="cl"></div></div></div></div></div></div>';
}
$text .='<div class="gr_block_lt"><div class="gr_block_rt"><div class="gr_block_lb"><div class="gr_block_rb"><div class="gr_block_content">'._FRASE_IDEA.'<div class="add_idea"><a href="javascript: _v(\'idea_create\').submit();" class="add_idea_link">'._ADD_IDEA.'</a></div><div class="cl"></div></div></div></div></div></div></form>';
}
print $text;
CloseTable();
foot();
}

function save_idea() {
global $prefix, $db, $user, $defis, $idea, $module_name;
$stop='';
$uid=0;
$ins='';
$ip = text_filter(getenv("REMOTE_ADDR"));
if (isset($_POST['title']) && strlen(trim($_POST['title']))>=10) $title=text_filter($_POST['title']);
else $stop .='<div class="LV_invalid">'._IDEA_ERROR1.'</div>';
if (isset($_POST['descript']) && strlen(trim($_POST['descript']))>=20) $descript=text_filter($_POST['descript']);
else $stop .='<div class="LV_invalid">'._IDEA_ERROR2.'</div>';
if(!is_user($user) && $idea['addidea']==2) {
if (isset($_POST['addname']) && strlen(trim($_POST['addname']))>=3) $addname=text_filter($_POST['addname']);
else $stop .='<div class="LV_invalid">'._IDEA_ERROR3.'</div>';
if (isset($_POST['addmail']) && trim($_POST['addmail'])!='' && validmail(text_filter($_POST['addmail']))==1) $addmail=text_filter($_POST['addmail']);
else $stop .='<div class="LV_invalid">'._IDEA_ERROR4.'</div>';
$ins="NULL, '$title', '$descript', '$addname', '$addmail', '$ip', 0, '".time()."', 0, 0, 5, 1, '', 0, '', '', 0, ''";
} elseif (is_user($user) && $idea['addidea']!=0) {
$userinfo=getusrinfo($user);
$addname=$userinfo['user_name'];
$addmail=$userinfo['user_email'];
$uid=$userinfo['user_id'];
$ins="NULL, '$title', '$descript', '$addname', '$addmail', '$ip', '$uid', '".time()."', 0, 0, 5, 1, '', 0, '', '', 0, ''";
}
if (captcha_check_captcha(1) && ($idea['seccode']==2 || ($idea['seccode']==1 && !is_user($user)))) $stop .='<div class="LV_invalid">'._IDEA_ECAPCHA.'</div>';
elseif ($ins!='' && $stop=='' && ($idea['addidea']==2 || ($idea['addidea']==1 && is_user($user)))) {
$db->sql_query("INSERT INTO ".$prefix."_ideas VALUES ($ins)");
head();
OpenTable();
if ($idea['naviform']!=0) print imenu();
if ($idea['addform']!=0) print add_form();
warning(''._IDEA_THX.'');
CloseTable();
foot();
}
if ($stop!='') add_idea($title, $descript, $addname, $addmail, "<br /><h3>"._IDEA_ERROR5."</h3>$stop<br />");
else Header("Location: index.php?name=$module_name");
}

function imenu ($message=1) {
global $module_name, $idea;
$sort = (isset($_GET['sort'])) ? intval($_GET['sort']) : 0;
$text ='<div id="ideamenuhead"><div class="ideadleft"><div class="ideadright">';
$text .='<a href="index.php?name='.$module_name.'" title="'._IMENU_1.'">'._IMENU_1.'</a>';
$text .='<a href="index.php?name='.$module_name.'&amp;sort=1" title="'._IMENU_2.'">'._IMENU_2.'</a>';
$text .='<a href="index.php?name='.$module_name.'&amp;sort=2" title="'._IMENU_3T.'">'._IMENU_3.'</a>';
if ($idea['moder']==2) $text .='<a href="index.php?name='.$module_name.'&amp;sort=3" title="'._IMENU_4T.'">'._IMENU_4.'</a>';
$text .='<a href="index.php?name='.$module_name.'&amp;sort=4" title="'._IMENU_5T.'">'._IMENU_5.'</a>';
if ($idea['addidea']==2 || ($idea['addidea']==1 && is_user($user))) $text .='<a href="index.php?name='.$module_name.'&amp;op=add_idea" title="'._IMENU_6T.'">'._IMENU_6.'</a>';
$text .='</div></div></div>';

if ($sort==1 || $sort==11 || $sort==12 || $sort==13) $pretitle='<h2>'._SHOW_IMR.'</h2><p><a href="index.php?name='.$module_name.'&amp;sort=11">&raquo; '._AIMENU_11.'</a>'._IMENU_11.'</p><p><a href="index.php?name='.$module_name.'&amp;sort=12">&raquo; '._AIMENU_12.'</a>'._IMENU_12.'</p><p><a href="index.php?name='.$module_name.'&amp;sort=13">&raquo; '._AIMENU_13.'</a>'._IMENU_13.'</p>';
elseif ($sort==2 || $sort==21 || $sort==22 || $sort==23 || $sort==24) $pretitle='<h2>'._SHOW_IST.'</h2><p><a href="index.php?name='.$module_name.'&amp;sort=21">&raquo; '._EXECUTE_IDEA.'</a>'._IMENU_21.'</p><p><a href="index.php?name='.$module_name.'&amp;sort=22">&raquo; '._DOING_IDEA.'</a>'._IMENU_22.'</p><p><a href="index.php?name='.$module_name.'&amp;sort=23">&raquo; '._PLAN_IDEA.'</a>'._IMENU_23.'</p><p><a href="index.php?name='.$module_name.'&amp;sort=24">&raquo; '._DISMISS_IDEA.'</a>'._IMENU_24.'</p>';
else $pretitle=''._MAIN_IMENU.'';

if ($message!=0 && $sort!=3 && $sort!=4 && !isset($_GET['op'])) {
$text .='<div id="imenu_middle"><div id="imenu_container"><div id="imenu_content"><div class="imenu_post"><div class="imenu_pt"><div class="imenu_pb">
<div class="imenu_entry">'.$pretitle.'</div>
</div></div></div></div></div></div>';
}
return $text;
}

function main_idea() {
global $prefix, $db, $module_name, $pagetitle, $defis, $idea, $admin, $user, $admin_file;
$pagetitle = "$defis "._IDEATITLE."";
$where='';
$by=$idea['mainby'];
$dsas=$idea['dsas'];
head();
OpenTable();
$sort = (isset($_GET['sort'])) ? intval($_GET['sort']) : 0;
if ($sort==4) $where="WHERE answer!=''";
elseif ($sort==3 && $idea['moder']==2) $where="WHERE status=5";
elseif ($sort==21) $where="WHERE status=4";
elseif ($sort==22) $where="WHERE status=2";
elseif ($sort==23) $where="WHERE status=3";
elseif ($sort==24) $where="WHERE status=1";
elseif ($sort==11) {$by='karma';$dsas='DESC';}
elseif ($sort==12) {$by='totalvote';$dsas='DESC';}
elseif ($sort==13) {$by='comments';$dsas='DESC';}
$text ='';
$text .="<div style=\"width:560px;position:relative;left:50%;margin-left:-280px;\">";
if ($idea['naviform']!=0) $text .=imenu();
if ($idea['addform']!=0) $text .=add_form();
$count=0;
if ($idea['moder']==1 && $where!='') $where .=' AND status!=5';
elseif ($idea['moder']==1 && $where=='') $where ='WHERE status!=5';
list($count) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_ideas $where"));
if ($count>0) {
$total_pages = ceil($count / $idea['ionpage']);
if ($idea['num_page']==2) $pagenum = (isset($_GET['pagenum'])) ? intval($_GET['pagenum']) : $total_pages;
else $pagenum = (isset($_GET['pagenum'])) ? intval($_GET['pagenum']) : 1;
if ($idea['num_page']==2) $min = $idea['ionpage'] * ($total_pages - $pagenum);
else $min = $idea['ionpage'] * ($pagenum - 1);
$past = time() - intval($idea['rating']*3600);
$db->sql_query("DELETE FROM ".$prefix."_irating WHERE time<'$past'");
$ip = getip_idea();
$postname = (is_user($user)) ? text_filter(substr($user[1], 0, 25)) : "";
$sqlr = $db->sql_query("SELECT Count(id), iid FROM ".$prefix."_irating WHERE (host='$ip') OR (name='$postname' AND name!='') GROUP BY iid");
while (list($cid, $iid) = $db->sql_fetchrow($sqlr)) $massiv[$iid] = array($cid);
$result = $db->sql_query("SELECT id, title, `desc`, author, mail, ip, uid, `date`, karma, comments, status, close, answer, responder, timeanswer, totalvote FROM ".$prefix."_ideas $where ORDER BY $by $dsas LIMIT $min, ".$idea['ionpage']."");
while(list($id, $title, $desc, $author, $mail, $ip, $uid, $date, $karma, $comments, $status, $close, $answer, $responder, $timeanswer, $totalvote) = $db->sql_fetchrow($result)) {
$desc=nl2br(bb_decode($desc));
$answer=nl2br(bb_decode($answer));
if (strlen(strip_tags($title))>$idea['cut']) $title="".cut($title,$idea['cut'],$idea['cut'])."...";
$text .='<div class="post"><div class="post_top"><div class="vote">';
if ($status=='1') $statuscl='<div class="status status1"><a href="#idea_'.$id.'" id="idea_'.$id.'">'._DISMISS_IDEA.'</a></div>';
elseif ($status=='2') $statuscl='<div class="status status2"><a href="#idea_'.$id.'" id="idea_'.$id.'">'._DOING_IDEA.'</a></div>';
elseif ($status=='3') $statuscl='<div class="status status3"><a href="#idea_'.$id.'" id="idea_'.$id.'">'._PLAN_IDEA.'</a></div>';
elseif ($status=='4') $statuscl='<div class="status status4"><a href="#idea_'.$id.'" id="idea_'.$id.'">'._EXECUTE_IDEA.'</a></div>';
else $statuscl='';
if ($answer!='' && (is_admin($admin) || ($idea['delotvet']=='2' && is_user($user) && chk_imoder($idea['official'])==1) || ($idea['delotvet']=='1' && is_user($user) && chk_imoder($idea['official'])==1 && $responder!='' && $responder==htmlspecialchars(substr($user[1], 0, 25))))) $otdel='<div style="float:right;font-weight: bold;padding:5px;"><a href="index.php?name='.$module_name.'&amp;op=otvet_idel&amp;id='.$id.'">'._IOTVET_DEL.'</a></div>';
else $otdel='';
if ($answer!='') $otvet='<div class="answer"><div class="answer_top"><div class="user_ansver"><div class="answer_type">'._OTVET_IDEA.'</div><span class="off_otvet">'.$responder.', '.ideadate($timeanswer ,1).'</span></div>'.$answer.''.$otdel.'</div></div>';
else $otvet='';
$text .=''.$statuscl.''.ai_rating($id, $karma, $totalvote, $massiv[$id][0]).'</div>';
$text .='<div class="post_content"><div class="post_icon"></div>';
$text .='<h2><a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'">'.$title.'</a></h2><div class="post_text">'.$desc.'</div>'.$otvet.'<div class="post_panel">';
if ($uid!=0) $text .='<div class="user_comment"><a href="index.php?name=Account&amp;op=info&amp;uname='.$author.'">'.$author.'</a>, '.ideadate($date ,1).'</div>';
else $text .='<div class="guest_comment">'.$author.', '.ideadate($date ,1).'</div>';
if ($idea['add_comm']==3 || ($idea['add_comm']==2 && $close==3) || ($idea['add_comm']==1 && $close==3)) $class_com="comments_close";
elseif ($idea['add_comm']==2 && !is_user($user) || ($idea['add_comm']==1 && ($close==2 && !is_user($user)))) $class_com="comments_guest";
else $class_com="comments";
$text .='<a href="index.php?name='.$module_name.'&amp;op=full_idea&amp;id='.$id.'" class="'.$class_com.'">'.$comments.' '.plur_lng($comments, ''._COUNT_COMMENT.'').'</a>';
if (is_admin($admin)) $text .= '<div style="margin-top:30px;background: #FFFFCC;border: 1px solid green;"><div style="margin:5px;">['._IP_IADM.' <a href="http://www.dnsstuff.com/tools/whois.ch?ip='.$ip.'">'.$ip.'</a> - <a href="/'.$admin_file.'.php?op=SecurityBlocker&amp;new_ip='.$ip.'">'._BLOCK_IADM.'</a> | '._MAIL_IADM.' <a href="mailto:'.$mail.'">'.$mail.'</a>]<br />[<a href="'.$admin_file.'.php?op=aidea_edit&amp;id='.$id.'">'._EDT_IADM.'</a> | <a href="'.$admin_file.'.php?op=aidea_delete&amp;id='.$id.'">'._DEL_IADM.'</a>]</div></div>';
$text .= '</div></div><div class="cl"></div></div></div>';
		}
		if ($sort!=0) $sort="sort=$sort&amp;";
		else $sort='';
$text .=ideas_page($module_name, $count, $total_pages, $idea['ionpage'], "$sort", $idea['num_page']);

} elseif ($sort!=0) {
  $text .= warning(''._NO_IFOUND.'');
} else $text .= '<div class="gray_block"><div class="saersh_info">'._NO_IDEA.'</div></div>';
$text .="</div>";
print $text;
CloseTable();
foot();
}

function full_idea($id='', $stop='', $descript='', $addname='', $addmail='') {
global $prefix, $db, $module_name, $pagetitle, $defis, $idea, $admin, $user, $admin_file;
$pagetitle = "$defis "._IDEATITLE."";
if (isset($_GET['id']) && $_GET['id']!='') $id=intval($_GET['id']);
$count=0;
if ($idea['moder']==1) $where='AND status!=5'; else $where='';
list($count) = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_ideas WHERE id='$id' $where"));
if ($count>0) {
$past = time() - intval($idea['rating']*3600);
$db->sql_query("DELETE FROM ".$prefix."_irating WHERE time<'$past'");
$ip = getip_idea();
$postname = (is_user($user)) ? text_filter(substr($user[1], 0, 25)) : "";
$sqlr = $db->sql_query("SELECT Count(id), iid FROM ".$prefix."_irating WHERE (host='$ip') OR (name='$postname' AND name!='') GROUP BY iid");
while (list($cid, $iid) = $db->sql_fetchrow($sqlr)) $massiv[$iid] = array($cid);
$result = $db->sql_query("SELECT id, title, `desc`, author, mail, ip, uid, `date`, karma, comments, status, close, reason, answer, responder, timeanswer, totalvote, whoclose FROM ".$prefix."_ideas WHERE id='$id'");
list($id, $title, $desc, $author, $mail, $ip, $uid, $date, $karma, $comments, $status, $close, $reason, $answer, $responder, $timeanswer, $totalvote, $whoclose) = $db->sql_fetchrow($result);
$desc=nl2br(bb_decode($desc));
$answer=nl2br(bb_decode($answer));
if ($status=='1') $statuscl=''._IDF_STS.'  <span style="font-weight: bold; color: #F06060;">'._DISMISS_IDEA.'</span>';
elseif ($status=='2') $statuscl=''._IDF_STS.'  <span style="font-weight: bold; color: orange;">'._DOING_IDEA.'</span>';
elseif ($status=='3') $statuscl=''._IDF_STS.'  <span style="font-weight: bold; color: #1595E6;">'._PLAN_IDEA.'</span>';
elseif ($status=='4') $statuscl=''._IDF_STS.'  <span style="font-weight: bold; color: green;">'._EXECUTE_IDEA.'</span>';
else $statuscl=''._IDF_STS.'  <span style="font-weight: bold; color: grey;">'._NOTSEE_IDEA.'</span>';
if ($answer!='' && (is_admin($admin) || ($idea['delotvet']=='2' && is_user($user) && chk_imoder($idea['official'])==1) || ($idea['delotvet']=='1' && is_user($user) && chk_imoder($idea['official'])==1 && $responder!='' && $responder==htmlspecialchars(substr($user[1], 0, 25))))) $otdel='<div style="float:right;font-weight: bold;padding:5px;"><a href="index.php?name='.$module_name.'&amp;op=otvet_idel&amp;id='.$id.'">'._IOTVET_DEL.'</a></div>';
else $otdel='';
if ($answer!='') $otvet='<div id="idea_respond"><div class="answer2"><div class="answer_top2"><div class="user_ansver2"><div class="answer_type2">'._OTVET_IDEA.'</div><span class="off_otvet">'.$responder.', '.ideadate($timeanswer ,1).'</span></div>'.$answer.''.$otdel.'</div></div></div>';
else $otvet='';
if ($uid!=0) $author='<a href="index.php?name=Account&amp;op=info&amp;uname='.$author.'">'.$author.'</a>';
$text .= '<div class="content_cont"><div class="big_idea_block bib2"><div class="blue_block"><div class="blue_lt"><div class="blue_rt"><div class="blue_lb"><div class="blue_rb"><div class="blue_block_status">';
$text .='<h1>'.$title.'</h1>';
$text .='<div class="big_idea_text"><div class="big_idea_left"><div class="vote" id="vote_full">'.ai_rating($id, $karma, $totalvote, $massiv[$id][0]).'</div></div>';
$text .='<p>'.$desc.'</p>'.$otvet.'';
$text .='</div><div class="cl"></div><div class="post_panel"><div>'._SAY_IDEA.': ';
$text .=''.$author.', '.ideadate($date ,1).'</div><div>'.$statuscl.'</div>';
if (is_admin($admin)) $text .= '<div style="margin-top:30px;background: #FFFFCC;border: 1px solid green;"><div style="margin:5px;">['._IP_IADM.' <a href="http://www.dnsstuff.com/tools/whois.ch?ip='.$ip.'">'.$ip.'</a> - <a href="/'.$admin_file.'.php?op=SecurityBlocker&amp;new_ip='.$ip.'">'._BLOCK_IADM.'</a> | '._MAIL_IADM.' <a href="mailto:'.$mail.'">'.$mail.'</a>]<br />[<a href="'.$admin_file.'.php?op=aidea_edit&amp;id='.$id.'">'._EDT_IADM.'</a> | <a href="'.$admin_file.'.php?op=aidea_delete&amp;id='.$id.'">'._DEL_IADM.'</a>]</div></div>';
$text .='</div></div></div></div></div></div></div><div class="cl"></div></div>';
		}
if ($answer=='' && (is_admin($admin) || (is_user($user) && chk_imoder($idea['official'])==1))) $text .=idea_otvet($id);
if (is_admin($admin) || (is_user($user) && chk_imoder($idea['moders'])==1)) $text .= close_iform($id, $close, $reason, $whoclose);
$text .= idea_comments($id, $close, $reason, $stop, $descript, $addname, $addmail, $whoclose);
$text .='</div><div class="cl"></div>';
head();
OpenTable();
if ($idea['naviform']!=0) print imenu();
if ($idea['addform']!=0) print add_form();
if ($count>0) print $text;
else print warning(''._NOT_IDEA.'');
CloseTable();
foot();
}

function close_iform($id, $close, $reason, $whoclose) {
global $module_name, $admin, $user;
if (is_admin($admin)) $moder=$admin['1'];
elseif (is_user($user)) $moder=htmlspecialchars(substr($user[1], 0, 25));
if ($close==1) {$status=''._MOD_IER1.'';$option ="<option value=\"2\">"._VAR_CL1."</option><option value=\"3\" selected>"._VAR_CL2."</option>";}
elseif ($close==2) {$status=''._MOD_IER2.' ('.$whoclose.')';$option ="<option value=\"3\">"._VAR_CL2."</option><option value=\"1\" selected>"._VAR_CL3."</option>";}
elseif ($close==3) {$status=''._MOD_IER3.' ('.$whoclose.')';$option ="<option value=\"1\">"._VAR_CL3."</option><option value=\"2\" selected>"._VAR_CL4."</option>";}
$text = '<div class="big_idea_block bib2"><div class="blue_block"><div class="blue_lt"><div class="blue_rt"><div class="blue_lb"><div class="blue_rb"><div class="blue_block_status">';
$text .="<h2 class='r_title no_bg pl0'>"._IOP_CL." $id</h2><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\" width=\"100%\"><form name=\"post\" action=\"index.php?name=$module_name\" method=\"post\">";
$text .="<tr><td><b>"._ITEK_STS."</b></td><td><font class=\"option\">$status</font></td></tr>";
if ($reason!='') $text .="<tr><td><b>"._ITEK_RSN."</b></td><td><font class=\"option\">$reason</font></td></tr>";
$text .="<tr><td><b>"._IMOD_NICK."</b></td><td>".$moder."</td></tr>";
$text .="<tr><td><b>"._IMOD_ACT."</b></td><td><select name=\"close\" style=\"width:400px\">$option</select></td></tr>";
$text .="<tr><td><b>"._IWHY_CLS."</b></td><td><textarea name=\"reason\" cols=\"65\" rows=\"2\" style=\"width:400px\"></textarea></td></tr>";
$text .="<tr><td colspan=\"2\" align=\"center\"><br /><input type=\"hidden\" name=\"iid\" value=\"$id\" /><input type=\"hidden\" name=\"op\" value=\"close_isave\" /><input type=\"submit\" value=\""._IMOD_OK."\" /></td></tr></form></table>";
$text .='</div></div></div></div></div></div></div><div class="cl"></div>';
return $text;
}

function idea_otvet($id) {
global $module_name, $admin, $user;
if (is_admin($admin)) $moder=$admin['1'];
elseif (is_user($user)) $moder=htmlspecialchars(substr($user[1], 0, 25));
$text = '<div class="big_idea_block bib2"><div class="blue_block"><div class="blue_lt"><div class="blue_rt"><div class="blue_lb"><div class="blue_rb"><div class="blue_block_status">';
$text .="<h2 class='r_title no_bg pl0'>"._IOTVET_HL." $id</h2><table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\" width=\"100%\"><form name=\"post\" action=\"index.php?name=$module_name\" method=\"post\">";
$text .="<tr><td><b>"._IMOD_NICK."</b></td><td>".$moder."</td></tr>";
$text .='<tr><td><b>'._IOTVET_AN.'</b></td><td><textarea id="iotvet" name="otvet" cols="65" rows="5" style="width:400px" onkeypress="TransliteFeld(this, event)" onselect="FieldName(this, this.name)" onclick="FieldName(this, this.name)" onkeyup="FieldName(this, this.name)"></textarea>'.get_code("iotvet").'</td></tr>';
$text .="<tr><td colspan=\"2\" align=\"center\"><br /><input type=\"hidden\" name=\"iid\" value=\"$id\" /><input type=\"hidden\" name=\"op\" value=\"otvet_isave\" /><input type=\"submit\" value=\""._IOTVET_AD."\" /></td></tr></form></table>";
$text .='</div></div></div></div></div></div></div><div class="cl"></div>';
return $text;
}

function otvet_isave() {
global $prefix, $db, $module_name, $idea, $admin, $user;
$otvet = (isset($_POST['otvet'])) ? text_filter($_POST['otvet']) : '';
$id = (isset($_POST['iid'])) ? intval($_POST['iid']) : 0;
if ($id!=0 && $otvet!='' && (is_admin($admin) || (is_user($user) && chk_imoder($idea['official'])==1))) {
if (is_admin($admin)) $moder=$admin['1'];
elseif (is_user($user)) $moder=htmlspecialchars(substr($user[1], 0, 25));
$db->sql_query("UPDATE ".$prefix."_ideas SET answer='$otvet', responder='$moder', timeanswer='".time()."' WHERE id='$id'");
Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
} elseif ($id!=0) Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
  else Header("Location: index.php?name=$module_name");
}

function otvet_idel() {
global $prefix, $db, $module_name, $idea, $admin, $user;
$responder='';
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
if ($id!=0 && is_user($user)) {$result = $db->sql_query("SELECT responder FROM ".$prefix."_ideas WHERE id='$id'");list($responder) = $db->sql_fetchrow($result);}

if ($id!=0 && (is_admin($admin) || ($idea['delotvet']=='2' && is_user($user) && chk_imoder($idea['official'])==1) || ($idea['delotvet']=='1' && is_user($user) && chk_imoder($idea['official'])==1 && $responder!='' && $responder==htmlspecialchars(substr($user[1], 0, 25))))) {
$db->sql_query("UPDATE ".$prefix."_ideas SET answer='', responder='', timeanswer='' WHERE id='$id'");
Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
} elseif ($id!=0) Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
  else Header("Location: index.php?name=$module_name");
}

function close_isave() {
global $prefix, $db, $module_name, $idea, $admin, $user;
$close = (isset($_POST['close'])) ? intval($_POST['close']) : 0;
$reason = (isset($_POST['reason'])) ? text_filter($_POST['reason']) : '';
$id = (isset($_POST['iid'])) ? intval($_POST['iid']) : 0;
if ($id!=0 && $close!=0 && (is_admin($admin) || (is_user($user) && chk_imoder($idea['moders'])==1))) {
if (is_admin($admin)) $moder=$admin['1'];
elseif (is_user($user)) $moder=htmlspecialchars(substr($user[1], 0, 25));
$db->sql_query("UPDATE ".$prefix."_ideas SET reason='$reason', whoclose='$moder', close='$close' WHERE id='$id'");
Header("Location: index.php?name=$module_name&op=full_idea&id=$id");
} else Header("Location: index.php?name=$module_name");
}

switch($op) {
	default:
	main_idea();
	break;

	case "save_idea":
	save_idea();
	break;

	case "full_idea":
	full_idea();
	break;

	case "popup_idea":
	popup_idea();
	break;

	case "icom_save":
	icom_save();
	break;

	case "add_idea":
	add_idea();
	break;

	case "ai_rating":
	ai_rating();
	break;
	
	case "idea_comments":
	idea_comments();
	break;

	case "close_isave":
	close_isave();
	break;
	
	case "otvet_isave":
	otvet_isave();
	break;
	
	case "otvet_idel":
	otvet_idel();
	break;
}