<?PHP
if( ! defined( 'DATALIFEENGINE' )) {die( "Hacking attempt!" );}
@include_once ( SYSTEM_DIR . '/data/tableconfig.php' );
if( ! $user_group[$member_id['user_group']]['allow_admin']  ) {msg( "error", $lang['index_denied'], $lang['index_denied'] );}
if( $action == "" ) {header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] . "?mod=table&action=list");}

include_once ROOT_DIR . '/language/' . $config['langs'] . '/table.lng';

function showStatus( $statusId ) {
	global $lang_table;
	$statusId = intval( $statusId );
	switch ( $statusId ) {
		case "0":
			$status = "<font color=\"#FF8000\">" . $lang_table['edit_status_0'] . "</font>";
		break;

		case "1":
            $status = "<font color=\"#0000FF\">" . $lang_table['edit_status_1'] . "</font>";
		break;

		case "2":
			$status = "<font color=\"#FF0000\">" . $lang_table['edit_status_2'] . "</font>";
		break;

		case "3":
			$status = "<font color=\"#008000\">" . $lang_table['edit_status_3'] . "</font>";
		break;
	}
	return $status;
}

function menu() {
	global $lang_table;
    echo <<< HTML
<table width="100%">
<tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr>
<tr>
<td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
<tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['main_menu']}</div></td>
</tr>
</table>
<div class="unterline"></div>
<table width="100%">
<tr>
<td width="55%">
<div class="quick"><a href="{$PHP_SELF}?mod=table&amp;action=list"><img src="system/skins/images/table/other.png" align="left" border="0">
<h3>{$lang_table['main_control']}</h3>
{$lang_table['main_control_descr']}</a></div></td>
<td width="50%">
<div class="quick"><a href="{$PHP_SELF}?mod=table&amp;action=options"><img src="system/skins/images/table/options.png" align="left" border="0">
<h3>{$lang_table['main_options']}</h3>
{$lang_table['main_options_descr']}</a></div></td></tr>
</table>
</td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr>
<tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr>
</table>
HTML;
}

if( isset( $_REQUEST['author'] ) ) $author = $db->safesql( trim( htmlspecialchars( $_REQUEST['author'] ) ) ); else $author = "";
if( isset( $_REQUEST['ifdelete'] ) ) $ifdelete = $_REQUEST['ifdelete']; else $ifdelete = "";
if( isset( $_REQUEST['search_cat'] ) ) $search_cat = $db->safesql( trim( htmlspecialchars( $_REQUEST['search_cat'] ) ) ); else $search_cat = "";

if( $action == "list" ) {

	$_SESSION['admin_referrer'] = $_SERVER['REQUEST_URI'];

	echoheader( "table", $lang_table['edit_head'] );

	$search_field = $db->safesql( trim( htmlspecialchars( stripslashes( urldecode( $_REQUEST['search_field'] ) ), ENT_QUOTES ) ) );
	$search_author = $db->safesql( trim( htmlspecialchars( stripslashes( urldecode( $_REQUEST['search_author'] ) ), ENT_QUOTES ) ) );
	$fromordersdate = $db->safesql( trim( htmlspecialchars( stripslashes( $_REQUEST['fromordersdate'] ), ENT_QUOTES ) ) );
	$toordersdate = $db->safesql( trim( htmlspecialchars( stripslashes( $_REQUEST['toordersdate'] ), ENT_QUOTES ) ) );

	$start_from = intval( $_REQUEST['start_from'] );
	$news_per_page = intval( $_REQUEST['news_per_page'] );
	$gopage = intval( $_REQUEST['gopage'] );

	$_REQUEST['orders_status'] = intval ($_REQUEST['orders_status']);
	$orders_status_sel = array ('1'=>'','2'=>'','3'=>'','4'=>'','5'=>'');
	$orders_status_sel[$_REQUEST['orders_status']] = 'selected="selected"';

	if( ! $news_per_page or $news_per_page < 1 ) {
		$news_per_page = 50;
	}
	if( $gopage ) $start_from = ($gopage - 1) * $news_per_page;
	
	if( $start_from < 0 ) $start_from = 0;

	$where = array ();

	if( $search_field != "" ) {
		$where[] = "(runame like '%$search_field%' OR enname like '%$search_field%' OR link like '%$search_field%')";
	}

	if( $search_author != "" ) {
		$where[] = "autor like '$search_author%'";
	}

	if( $search_cat != "" ) {
		$where[] = "category regexp '[[:<:]]($search_cat)[[:>:]]'";
	}

	if( $fromordersdate != "" ) {
		$fromdate = strtotime( $fromordersdate );
		$where[] = "date >= '$fromdate'";
	}

	if( $toordersdate != "" ) {
		$todate = strtotime( $toordersdate );
		$where[] = "date <= '$todate'";
	}

	if ($_REQUEST['orders_status'] == 1) $where[] = "status NOT IN (5)";
	elseif ($_REQUEST['orders_status'] == 2) $where[] = "status = '0'";
	elseif ($_REQUEST['orders_status'] == 3) $where[] = "status = '1'";
	elseif ($_REQUEST['orders_status'] == 4) $where[] = "status = '2'";
	elseif ($_REQUEST['orders_status'] == 5) $where[] = "status = '3'";

	if( count( $where ) ) {
		
		$where = implode( " AND ", $where );
		$where = " WHERE " . $where;
	
	} else {
		$where = "";
	}

	$order_by = array ();

	if( $_REQUEST['search_order_m'] == "asc" or $_REQUEST['search_order_m'] == "desc" ) $search_order_m = $_REQUEST['search_order_m'];
	else $search_order_m = "";
	if( $_REQUEST['search_order_d'] == "asc" or $_REQUEST['search_order_d'] == "desc" ) $search_order_d = $_REQUEST['search_order_d'];
	else $search_order_d = "";
	if( $_REQUEST['search_order_t'] == "asc" or $_REQUEST['search_order_t'] == "desc" ) $search_order_t = $_REQUEST['search_order_t'];
	else $search_order_t = "";

	if( ! empty( $search_order_m ) ) {
		$order_by[] = "status $search_order_m";
	}
	if( ! empty( $search_order_d ) ) {
		$order_by[] = "date $search_order_d";
	}
	if( ! empty( $search_order_t ) ) {
		$order_by[] = "runame $search_order_t";
	}

	$order_by = implode( ", ", $order_by );
	if( ! $order_by ) $order_by = "date desc";

	$search_order_mod = array ('----' => '', 'asc' => '', 'desc' => '' );
	if( isset( $_REQUEST['search_order_m'] ) ) {
		$search_order_mod[$search_order_m] = 'selected';
	} else {
		$search_order_mod['----'] = 'selected';
	}
	$search_order_date = array ('----' => '', 'asc' => '', 'desc' => '' );
	if( isset( $_REQUEST['search_order_d'] ) ) {
		$search_order_date[$search_order_d] = 'selected';
	} else {
		$search_order_date['desc'] = 'selected';
	}
	$search_order_title = array ('----' => '', 'asc' => '', 'desc' => '' );
	if( ! empty( $search_order_t ) ) {
		$search_order_title[$search_order_t] = 'selected';
	} else {
		$search_order_title['----'] = 'selected';
	}

	$db->query( "SELECT * FROM " . PREFIX . "_table" . $where . " ORDER BY " . $order_by . " LIMIT $start_from,$news_per_page" );

	// Prelist Entries
	if( $start_from == "0" ) {
		$start_from = "";
	}
	$i = $start_from;
	$entries_showed = 0;
	
	$entries = "";
	
	while ( $row = $db->get_array() ) {
		
		$i ++;
		
		$itemdate = date( "d.m.Y G:i", $row['date'] );
		if(strlen($row['runame']) > 65) $runame = substr($row['runame'],0,65)." ..."; else $runame = $row['runame'];
		if(strlen($row['enname']) > 65) $enname = substr($row['enname'],0,65)." ..."; else $enname = $row['enname'];

		$runame = htmlspecialchars( stripslashes( $runame ), ENT_QUOTES );
		$enname = htmlspecialchars( stripslashes( $enname ), ENT_QUOTES );

		$runame = str_replace("&amp;","&", $runame );
		$enname = str_replace("&amp;","&", $enname );

		$name = htmlspecialchars( stripslashes( $row['name'] ), ENT_QUOTES );
		$fileyear = stripslashes( $row['fileyear'] );

		$statusd = showStatus( $row['status'] );

		$entries .= "<tr><td class=\"list\" style=\"padding:4px;\">$itemdate - ";

		$entries .= "<a title='$lang_table[edit_act]' class=\"list\" href=\"$PHP_SELF?mod=table&action=edit&id=$row[0]\">$runame / $enname ( $fileyear )</a>
		<td align=center></td><td align=center>";

		$entries .= "</td><td style=\"text-align: center\">";
		
		$entries .= "$statusd<td align=\"center\">";
		
		if (!$row['category']) $my_cat = "---"; else {
			$my_cat = htmlspecialchars( stripslashes($row['category']));
		}

		$entries .= "$my_cat<td class=\"list\"><a class=list href=\"?mod=editusers&action=list&search=yes&search_name=" . $row['autor'] . "\">" . $row['autor'] . "</a>
<td align=center><input name=\"selected_orders[]\" value=\"{$row['id']}\" type='checkbox'></tr><tr><td background=\"system/skins/images/mline.gif\" height=1 colspan=7></td></tr>";
		$entries_showed ++;

		if( $i >= $news_per_page + $start_from ) {
			break;
		}
	}

	// End prelisting
	$result_count = $db->super_query( "SELECT COUNT(*) as count FROM " . PREFIX . "_table" . $where );

	$all_count_news = $result_count['count'];

	if( $member_id['user_group'] == 1  ) { //DLE >= 7.5
		menu();
}
	///////////////////////////////////////////
	// Options Bar
	$category_s = explode(",", stripslashes($table_config['category']));
	//$category_list = "<select size=1 name=\"category\">\r\n";
		foreach ( $category_s as $value => $description ) {
			$category_list .= "<option value=\"$description\"";
				if( $selected == $description ) {
					$category_list .= " selected ";
				}
		$category_list .= ">$description</option>\n";
		}
	//$category_list .= "</select>";

echo <<<HTML
<!-- calendar stylesheet -->
<link rel="stylesheet" type="text/css" media="all" href="system/skins/calendar-blue.css" title="win2k-cold-1" />
<script type="text/javascript" src="system/skins/calendar.js"></script>
<script type="text/javascript" src="system/skins/calendar-en.js"></script>
<script type="text/javascript" src="system/skins/calendar-setup.js"></script>
<script language="javascript">
    function search_submit(prm){
      document.optionsbar.start_from.value=prm;
      document.optionsbar.submit();
      return false;
    }
    function gopage_submit(prm){
      document.optionsbar.start_from.value= (prm - 1) * {$news_per_page};
      document.optionsbar.submit();
      return false;
    }
    </script>
<form action="?mod=table&amp;action=list" method="GET" name="optionsbar" id="optionsbar">
<input type="hidden" name="mod" value="table">
<input type="hidden" name="action" value="list">
<div style="padding-top:5px;padding-bottom:2px;display:none" name="advancedsearch" id="advancedsearch">
<table width="100%">
    <tr>
        <td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['edit_stat']} <b>{$entries_showed}</b> {$lang_table['edit_stat_1']} <b>{$all_count_news}</b></div></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
     <tr>
		<td style="padding:5px;">{$lang_table['edit_search_orderss']}</td>
		<td style="padding-left:5px;"><input class="edit" name="search_field" value="{$search_field}" type="text" size="35"></td>
		<td style="padding-left:5px;">{$lang['search_by_author']}</td>
		<td style="padding-left:22px;"><input class="edit" name="search_author" value="{$search_author}" type="text" size="36"></td>
    </tr>
     <tr>
		<td style="padding:5px;">{$lang['edit_cat']}</td>
		<td style="padding-left:5px;"><select name="search_cat" ><option selected value="">$lang[edit_all]</option>{$category_list}</select></td>
		<td style="padding-left:5px;">{$lang_table['search_by_date']}</td>
		<td style="padding-left:5px;">{$lang['edit_fdate']} <input type="text" name="fromordersdate" id="fromordersdate" size="11" maxlength="16" class="edit" value="{$fromordersdate}">
<img src="system/skins/images/img.gif"  align="absmiddle" id="f_trigger_dnews" style="cursor: pointer; border: 0" title="{$lang['edit_ecal']}"/>
<script type="text/javascript">
    Calendar.setup({
      inputField     :    "fromordersdate",     // id of the input field
      ifFormat       :    "%Y-%m-%d",      // format of the input field
      button         :    "f_trigger_dnews",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    false,
      singleClick    :    true
    });
</script> {$lang['edit_tdate']} <input type="text" name="toordersdate" id="toordersdate" size="11" maxlength="16" class="edit" value="{$toordersdate}">
<img src="system/skins/images/img.gif"  align="absmiddle" id="f_trigger_tnews" style="cursor: pointer; border: 0" title="{$lang['edit_ecal']}"/>
<script type="text/javascript">
    Calendar.setup({
      inputField     :    "toordersdate",     // id of the input field
      ifFormat       :    "%Y-%m-%d",      // format of the input field
      button         :    "f_trigger_tnews",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    false,
      singleClick    :    true
    });
</script></td>

    </tr>
     <tr>
		<td style="padding:5px;">{$lang_table['search_by_status']}</td>
		<td style="padding-left:5px;"><select name="orders_status" id="orders_status">
								<option {$orders_status_sel['1']} value="1">{$lang_table['orders_status_all']}</option>
								<option {$orders_status_sel['2']} value="2">{$lang_table['edit_status_0']}</option>
                                <option {$orders_status_sel['3']} value="3">{$lang_table['edit_status_1']}</option>
								<option {$orders_status_sel['4']} value="4">{$lang_table['edit_status_2']}</option>
								<option {$orders_status_sel['5']} value="5">{$lang_table['edit_status_3']}</option>
							</select></td>
		<td style="padding-left:5px;">{$lang_table['edit_page']}</td>
		<td style="padding-left:22px;"><input class="edit" style="text-align: center" name="news_per_page" value="{$news_per_page}" type="text" size="36"></td>
    </tr>
    <tr>
        <td colspan="4"><div class="hr_line"></div></td>
    </tr>
    <tr>
        <td colspan="4">{$lang_table['orders_order']}</td>
    </tr>
    <tr>
        <td style="padding:5px;"></td>
        <td style="padding:5px;">{$lang_table['edit_status1']}</td>
        <td style="padding:5px;">{$lang_table['search_by_date']}</td>
        <td style="padding:5px;">{$lang['edit_et']}</td>
    </tr>
    <tr>
        <td style="padding-left:2px;"></td>
        <td style="padding-left:2px;"><select name="search_order_m" id="search_order_m">
           <option {$search_order_mod['----']} value="">{$lang['user_order_no']}</option>
           <option {$search_order_mod['asc']} value="asc">{$lang['user_order_plus']}</option>
           <option {$search_order_mod['desc']} value="desc">{$lang['user_order_minus']}</option>
            </select>
        </td>
        <td style="padding-left:2px;"><select name="search_order_d" id="search_order_d">
           <option {$search_order_date['----']} value="">{$lang['user_order_no']}</option>
           <option {$search_order_date['asc']} value="asc">{$lang['user_order_plus']}</option>
           <option {$search_order_date['desc']} value="desc">{$lang['user_order_minus']}</option>
            </select>
        </td>
        <td style="padding-left:2px;" colspan="2"><select name="search_order_t" id="search_order_t">
           <option {$search_order_title['----']} value="">{$lang['user_order_no']}</option>
           <option {$search_order_title['asc']} value="asc">{$lang['user_order_plus']}</option>
           <option {$search_order_title['desc']} value="desc">{$lang['user_order_minus']}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="4"><div class="hr_line"></div></td>
    </tr>
    <tr>
		<td style="padding:5px;">&nbsp;</td>
		<td colspan="3">
<input type="hidden" name="start_from" id="start_from" value="{$start_from}">
<input onClick="javascript:search_submit(0); return(false);" class="edit" type="submit" value="{$lang['edit_act_1']}"></td>

    </tr>
</table>
</td>
        <td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div>
</form>
HTML;
	// End Options Bar

	echo <<<JSCRIPT
<script language='JavaScript' type="text/javascript">
<!--
function ckeck_uncheck_all() {
    var frm = document.table;
    for (var i=0;i<frm.elements.length;i++) {
        var elmnt = frm.elements[i];
        if (elmnt.type=='checkbox') {
            if(frm.master_box.checked == true){ elmnt.checked=false; }
            else{ elmnt.checked=true; }
        }
    }
    if(frm.master_box.checked == true){ frm.master_box.checked = false; }
    else{ frm.master_box.checked = true; }
}
-->
</script>
JSCRIPT;
	
	if( $entries_showed == 0 ) {
		
		echo <<<HTML
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
    <tr>
        <td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['orders_list']}</div></td>
        <td bgcolor="#EFEFEF" height="29" style="padding:5px;" align="right"><a href="javascript:ShowOrHide('advancedsearch');">{$lang_table['orders_advanced_search']}</a></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td align="center" style="height:50px;">{$lang_table['edit_noorders']}</td>
    </tr>
</table>
</td>
        <td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div>
HTML;
	
	} else {
		
		echo <<<HTML
<script type="text/javascript" src="system/ajax/menu.js"></script>
<form action="" method="post" name="table">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
    <tr>
        <td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['orders_list']}</div></td>
        <td bgcolor="#EFEFEF" height="29" style="padding:5px;" align="right"><a href="javascript:ShowOrHide('advancedsearch');">{$lang_table['orders_advanced_search']}</a></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td>
	<table width=100%>
	<tr>
    <td>&nbsp;&nbsp;{$lang_table['edit_date']}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$lang_table['edit_title']}
	<td width=10>&nbsp;&nbsp;
	<td width=80>&nbsp;&nbsp;
    <td width=80 align="center">{$lang_table['edit_status']}
    <td width=120 align="center">{$lang_table['edit_cat']}
    <td width=70 >{$lang_table['edit_author']}
    <td width=10 align="center"><input type="checkbox" name="master_box" title="{$lang['edit_selall']}" onclick="javascript:ckeck_uncheck_all()">
	</tr>
	<tr><td colspan="7"><div class="hr_line"></div></td></tr>
	{$entries}
	<tr><td colspan="7"><div class="hr_line"></div></td></tr>
HTML;
		
		// pagination

		$npp_nav = "<div class=\"news_navigation\" style=\"margin-bottom:5px; margin-top:5px;\">";
		
		if( $start_from > 0 ) {
			$previous = $start_from - $news_per_page;
			$npp_nav .= "<a onClick=\"javascript:search_submit($previous); return(false);\" href=\"#\" title=\"{$lang['edit_prev']}\">&lt;&lt;</a> ";
		}
		
		if( $all_count_news > $news_per_page ) {
			
			$enpages_count = @ceil( $all_count_news / $news_per_page );
			$enpages_start_from = 0;
			$enpages = "";
			
			if( $enpages_count <= 10 ) {
				
				for($j = 1; $j <= $enpages_count; $j ++) {
					
					if( $enpages_start_from != $start_from ) {
						
						$enpages .= "<a onClick=\"javascript:search_submit($enpages_start_from); return(false);\" href=\"#\">$j</a> ";
					
					} else {
						
						$enpages .= "<span>$j</span> ";
					}
					
					$enpages_start_from += $news_per_page;
				}
				
				$npp_nav .= $enpages;
			
			} else {
				
				$start = 1;
				$end = 10;
				
				if( $start_from > 0 ) {
					
					if( ($start_from / $news_per_page) > 4 ) {
						
						$start = @ceil( $start_from / $news_per_page ) - 3;
						$end = $start + 9;
						
						if( $end > $enpages_count ) {
							$start = $enpages_count - 10;
							$end = $enpages_count - 1;
						}
						
						$enpages_start_from = ($start - 1) * $news_per_page;
					
					}
				
				}
				
				if( $start > 2 ) {
					
					$enpages .= "<a onClick=\"javascript:search_submit(0); return(false);\" href=\"#\">1</a> ... ";
				
				}
				
				for($j = $start; $j <= $end; $j ++) {
					
					if( $enpages_start_from != $start_from ) {
						
						$enpages .= "<a onClick=\"javascript:search_submit($enpages_start_from); return(false);\" href=\"#\">$j</a> ";
					
					} else {
						
						$enpages .= "<span>$j</span> ";
					}
					
					$enpages_start_from += $news_per_page;
				}
				
				$enpages_start_from = ($enpages_count - 1) * $news_per_page;
				$enpages .= "... <a onClick=\"javascript:search_submit($enpages_start_from); return(false);\" href=\"#\">$enpages_count</a> ";
				
				$npp_nav .= $enpages;
			
			}
		
		}

		if( $all_count_news > $i ) {
			$how_next = $all_count_news - $i;
			if( $how_next > $news_per_page ) {
				$how_next = $news_per_page;
			}
			$npp_nav .= "<a onClick=\"javascript:search_submit($i); return(false);\" href=\"#\" title=\"{$lang['edit_next']}\">&gt;&gt;</a>";
		}

		$npp_nav .= "</div>";

		// pagination
		if( $entries_showed != 0 ) {
			echo <<<HTML
<tr><td>{$npp_nav}</td>
<td colspan=5 align="right" valign="top"><div style="margin-bottom:5px; margin-top:5px;">
<select name=s_action>
<option value="">{$lang['edit_selact']}</option>
<option value="mass_delete">{$lang['edit_seldel']}</option>
</select>
<input type=hidden name=mod value="table">
<input type=hidden name=action value="massactions">
<input type="hidden" name="user_hash" value="$dle_login_hash" />
<input class="edit" type="submit" value="{$lang['b_start']}">
</div></form><td></tr>
HTML;

			if( $all_count_news > $news_per_page ) {
				
				echo <<<HTML
<tr><td colspan="6">
{$lang['edit_go_page']} <input class="edit" style="text-align: center" name="gopage" id="gopage" value="" type="text" size="3"> <input onClick="javascript:gopage_submit(document.getElementById('gopage').value); return(false);" class="edit" type="button" value=" ok ">
</td></tr>
HTML;
			}
		
		}

		echo <<<HTML
	</table>
</td>
    </tr>
</table>
</td>
        <td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div>
HTML;
	}

	echofooter();
} 

// ********************************************************************************
// Показ заказа и редактирование
// ********************************************************************************
elseif( $action == "edit" ) {

	$id = intval( $_GET['id'] );
	$row = $db->super_query( "SELECT * FROM " . PREFIX . "_table where id = '$id'" );
	$found = FALSE;

	if( ! empty($id) AND $id == $row['id'] ) $found = TRUE;
	if( ! $found ) {
		msg( "error", $lang['cat_error'], $lang_table['edit_noorders'], "javascript:history.go(-1)" );
	}
	
	$cat_list = explode( ',', $row['category'] );
    
    $type_list = explode( ',', $row['type'] );

	$row['date'] = date("d-m-Y G:i", $row['date']);
    $row['runame'] = htmlspecialchars(stripslashes($row['runame']));
    $row['enname'] = htmlspecialchars(stripslashes($row['enname']));
    $row['category'] = htmlspecialchars(stripslashes($row['category']));
    $row['fileyear'] = htmlspecialchars(stripslashes($row['fileyear']));
    $row['answer'] = htmlspecialchars(stripslashes($row['answer']));
	$row['status'] = intval($row['status']);

    $doaction = "doedit";

	echoheader( "table", $lang_table['edit_head'] );

echo "<script type=\"text/javascript\">
    function confirmDelete(url){
    var agree=confirm(\"$lang_table[edit_cdel]\");
    if (agree)
    document.location=url;
    }

    function CheckStatus(Form){
		if(Form.allow_date.checked) {
		Form.allow_now.disabled = true;
		Form.allow_now.checked = false;
		} else {
		Form.allow_now.disabled = false;
		}
    }
</script>";

echo "<form method=post name=\"editorders\" id=\"editorders\" action=\"\">";

	$category_s = explode(",", stripslashes($table_config['category']));
	//$categories_list = "<select size=1 name=\"category\">\r\n";
		foreach ( $category_s as $value => $description ) {
			$categories_list .= "<option value=\"$description\"";
				if( $row['category'] == $description ) {
					$categories_list .= " selected ";
				}
		$categories_list .= ">$description</option>\n";
		}
	//$categories_list .= "</select>";
    
	$author_info = "<b>{$row['autor']}</b>";
	$author_info .= "&nbsp;<a onclick=\"javascript:window.open('?mod=editusers&action=edituser&user=".urlencode($row['autor'])."','User','toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=540,height=500'); return(false)\" href=\"#\"><img src=\"system/skins/images/user_edit.png\" style=\"vertical-align: middle;border: none;\" /></a>";
	
	echo <<<HTML
<script type="text/javascript">
	function tableorders(){
		document.location="$config[http_home_url]/index.php?do=table";
	}
</script>
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
    <tr>
        <td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['etitle']}</div></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td width="140" style="padding-left:5px;">{$lang['edit_info']}</td>
        <td>ID=<b>{$row['id']}</b>, {$lang['edit_eau']} {$author_info}</td>
    </tr>
    <tr>
        <td width="140" height="29" style="padding-left:5px;">{$lang_table['edit_runame']}</td>
        <td><input class="edit" type="text" size="55" name="runame" id="runame" value="{$row['runame']}"></td>
    </tr>
	<tr>
		<td width="140" height="29" style="padding-left:5px;">{$lang_table['edit_enname']}</td>
        <td><input class="edit" type="text" size="55" name="enname" id="enname" value="{$row['enname']}"></td>
    </tr>
    <tr>
        <td height="29" style="padding-left:5px;">{$lang['edit_edate']}</td>
        <td><input type="text" name="newdate" id="f_date_c" size="20"  class=edit value="{$row['date']}" DISABLED></td>
    </tr>
    <tr>
        <td height="29" style="padding-left:5px;">{$lang_table['edit_category']}</td>
        <td><select name="category" id="category">
		{$categories_list}
		</select>
		</td>
    </tr>
	<tr>
		<td width="140" height="29" style="padding-left:5px;">{$lang_table['edit_fileyear']}</td>
        <td><input class="edit" type="text" size="55" name="fileyear" id="fileyear" value="{$row['fileyear']}" maxlength="4"></td>
    </tr>
	<tr>
		<td width="200" style="padding:4px;">{$lang_table['edit_answer']}</td>
		<td><textarea style="font-family:verdana; font-size:11px; border:1px solid #E0E0E0" name="answer" rows="12" cols="130">{$row['answer']}</textarea></td>
	</tr>
	<tr>
		<td width="200" style="padding:4px;">{$lang_table['edit_status']}</td>
		<td>
HTML;

echo makeDropDown(array("0" => $lang_table['edit_status_0'], "1" => $lang_table['edit_status_1'], "2" => $lang_table['edit_status_2'], "3" => $lang_table['edit_status_3']), "status", $row['status']);

echo <<<HTML
</td></tr></table>
<div class="hr_line"></div>
<div style="padding-left:150px;padding-top:5px;padding-bottom:5px;">
<input type="submit" class="buttons" value="{$lang_table['btn_save']}" style="width:100px;">&nbsp;
<input onClick="confirmDelete('$PHP_SELF?mod=table&action=doedit&ifdelete=yes&id=$id&user_hash=$dle_login_hash')" type="button" class="buttons" value="{$lang['edit_dnews']}" style="width:100px;">
<input onClick="javascript:back()"; return(false)" href="#" type="button" class="buttons" value="{$lang[db_prev]}" style="width:120px;">
<input onClick="javascript:tableorders()"; return(false)" href="#" type="button" class="buttons" value="{$lang_table['go_page_orders']}" style="width:130px;">
<input type="hidden" name="id" value="$id" />
<input type="hidden" name="user_hash" value="$dle_login_hash" />
<input type="hidden" name="action" value="doedit" />
<input type="hidden" name="mod" value="table" />
</div>
HTML;

echo <<<HTML
</td>
        <td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div></form>
HTML;

	echofooter();
} 
// ********************************************************************************
// Сохранение или удаление
// ********************************************************************************
elseif( $action == "doedit" ) {
	if( $_REQUEST['user_hash'] == "" or $_REQUEST['user_hash'] != $dle_login_hash ) {
		die( "Hacking attempt! User not found" );
	}
	$id = intval( $_GET['id'] );
	$okdeleted = FALSE;

	if( $ifdelete != "yes" ) {
		$okchanges = TRUE;

		$runame = $db->safesql( trim( htmlspecialchars( $_POST['runame'] ) ) ) ;
		$enname = $db->safesql( trim( htmlspecialchars( $_POST['enname'] ) ) ) ;
		$fileyear = $db->safesql( trim( htmlspecialchars( $_POST['fileyear'] ) ) ) ;
		$category = $db->safesql( trim( htmlspecialchars( $_POST['category'] ) ) ) ;

        if ( trim( $runame ) != "" or $runame ){ $name = $runame; }
        if ( trim( $enname ) != "" or $enname ){ $name = $enname; }
        if( !$name ){msg( "error", $lang['cat_error'], $lang_table['orders_err_name'], "javascript:history.go(-1)" );}

		if( strlen( $fileyear ) > 4 ) {
			msg( "error", $lang['cat_error'], $lang_table['orders_err_year'], "javascript:history.go(-1)" );
		}
		if( strlen( $category ) > 20 ) {
			msg( "error", $lang['cat_error'], $lang_table['addorders_err_category'], "javascript:history.go(-1)" );
		}
		if (!is_numeric($fileyear)) {
			msg( "error", $lang['cat_error'], $lang_table['orders_err_year_type'], "javascript:history.go(-1)" );
		}

		$answer = $db->safesql(strip_tags(trim($_POST['answer'])));
		$editor = $db->safesql( trim( htmlspecialchars( $member_id['name'] ) ) ) ; //DLE > 7.5
        $status = intval($_POST['status']);
		$StatusSend = showStatus(intval($_POST['status']));

		if ( $table_config['msgs_usr'] == "yes" ) {
			$result = $db->super_query("SELECT " . USERPREFIX . "_users.name, " . USERPREFIX . "_users.email, " . PREFIX . "_table.autor, " . USERPREFIX . "_users.user_id FROM " . USERPREFIX . "_users INNER JOIN " . PREFIX . "_table ON (" . USERPREFIX . "_users.name = " . PREFIX . "_table.autor) WHERE id='$id'");
			$path = $config['http_home_url'];
			$subject = $lang_table['msgs_subject_usr'];
			$user_from = $lang_table['msg_user_from'];
			$time_send = time()+($config['date_adjust']*60);

				$editors =  "<a href=\"{$path}user/" . urlencode($editor) . "/\"><strong>" . $editor . "</strong></a>";

			$table_config['msgs_type1'] = stripslashes( html_entity_decode( $table_config['msgs_type1'] ) );
            $table_config['msgs_type1'] = str_replace( "{%id%}", $id, $table_config['msgs_type1'] );
			$table_config['msgs_type1'] = str_replace( "{%username%}", $result['name'], $table_config['msgs_type1'] );
			$table_config['msgs_type1'] = str_replace( "{%username_editor%}", $editors, $table_config['msgs_type1'] );
			$table_config['msgs_type1'] = str_replace( "{%date%}", date("d.m.Y H:i:s", $time_send), $table_config['msgs_type1'] );
			$table_config['msgs_type1'] = str_replace( "{%status%}", $StatusSend, $table_config['msgs_type1'] );

		if ( $table_config['msgs_type'] == "0" ) {
		
			if( ! $result['user_id'] ) { 
				msg( "error", $lang['cat_error'], $lang_table['not_user_id'], "javascript:history.go(-1)" );
				exit();
			}
			
			$db->query("INSERT INTO " . USERPREFIX . "_pm (subj, text, user, user_from, date, pm_read, folder) values ('$subject', '$table_config[msgs_type1]', '$result[user_id]', '$user_from', '$time_send', 'no', 'inbox')");
			$db->query("UPDATE " . USERPREFIX . "_users set pm_all=pm_all+1, pm_unread=pm_unread+1  WHERE user_id='$result[user_id]'");
	
		} else {
			include_once SYSTEM_DIR . '/classes/mail.class.php';
			$mail = new dle_mail( $config, true );
			$mail->from = $config['admin_mail'];
			$mail->send( $result['email'], $subject, $table_config['msgs_type1'] );

			if( $mail->send_error ) msg( "info", $lang['all_info'], $mail->smtp_msg );
		}
			$db->free($result);
		}

		$db->query("UPDATE " . PREFIX . "_table SET runame = '$runame', enname = '$enname', fileyear='$fileyear', category = '$category', answer='$answer', status='$status', editor='$editor' WHERE id='$id'");
		header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] . "?mod=table");
	} else
    {
		$db->query( "DELETE FROM " . PREFIX . "_table WHERE id='$id'" );
		$okdeleted = TRUE;
	}

	if( ! $_SESSION['admin_referrer'] ) {
		$_SESSION['admin_referrer'] = "?mod=table&amp;action=list";
	}

	if( $okdeleted ) {
		msg( "info", $lang_table['edit_delok'], $lang_table['edit_delok_1'], $_SESSION['admin_referrer'] );
	} elseif( $okchanges ) {
		msg( "info", $lang['edit_alleok'], $lang['edit_alleok_1'], $_SESSION['admin_referrer'] );
	} else {
		msg( "error", $lang['word_error'], $lang_table['edit_allerr'], $_SESSION['admin_referrer'] );
	}
    $cache->clear();
}

// ********************************************************************************
// Options
// ********************************************************************************
elseif ($_REQUEST['action'] == 'options') {
		if( $member_id['user_group'] != 1 ){ msg( "error", $lang['opt_denied'], $lang['opt_denied'] ); } //DLE >= 7.5
	include_once SYSTEM_DIR . '/classes/parse.class.php';
	$parse = new ParseFilter( Array (), Array (), 1, 1 );
	
	//$table_config['msgs_type0'] = str_replace( '&quot;', '"', $table_config['msgs_type0'] );
	//$table_config['msgs_type0'] = $parse->decodeBBCodes( $table_config['msgs_type0'], false );

	//$table_config['msgs_type1'] = str_replace( '&quot;', '"', $table_config['msgs_type1'] );
	//$table_config['msgs_type1'] = $parse->decodeBBCodes( $table_config['msgs_type1'], false );

echoheader( "options", $lang['opt_all'] );

	if( $member_id['user_group'] == 1  ) { //DLE >= 7.5
		menu();
	}

echo <<< HTML
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
<tr>
<td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr>
<tr>
<td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
<tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['opt_list']}</div></td>
</tr>
</table><div class="unterline"></div>
HTML;
/* Nullеd by DоtNеt */
    echo '<table width="100%"><form method="post">';

	showRow( $lang_table['opt_tab_offline'], $lang_table['opt_tab_offlined'], makeDropDown(array("no" => $lang['opt_sys_no'], "yes" => $lang['opt_sys_yes']), "save_con[table_offline]", "{$table_config['table_offline']}"));
	showRow( $lang_table['opt_tab_category'], $lang_table['opt_tab_categoryd'], "<input class=edit type=text style=\"text-align: center;\" name=\"save_con[category]\" value=\"{$table_config['category']}\" size=50>");

	showRow( $lang_table['opt_tab_an'], "<a onClick=\"javascript:Help('date')\" class=main href=\"#\">$lang[opt_sys_and]</a>", "<input class=edit type=text style=\"text-align: center;\"  name=\"save_con[timestamp_active]\" value=\"{$table_config['timestamp_active']}\" size=40>" );
	showRow( $lang_table['opt_tab_msort'], $lang_table['opt_tab_msortd'], makeDropDown( array ("DESC" => $lang['opt_sys_mminus'], "ASC" => $lang['opt_sys_mplus'] ), "save_con[orders_msort]", "{$table_config['orders_msort']}" ) );
	showRow( $lang_table['opt_tab_orders_number'], $lang_table['opt_tab_orders_numberd'], "<input class=edit type=text style=\"text-align: center;\" name=\"save_con[orders_number]\" value=\"{$table_config['orders_number']}\" size=30>");

	showRow( $lang_table['opt_tab_timeweek'], $lang_table['opt_tab_timeweekd'], "<input class=edit type=text style=\"text-align: center;\" name=\"save_con[timeweek]\" value=\"{$table_config['timeweek']}\" size=30>");
	showRow( $lang_table['opt_tab_auto_wrap'], $lang_table['opt_tab_auto_wrapd'], "<input class=edit type=text style=\"text-align: center;\" name=\"save_con[auto_wrap]\" value=\"{$table_config['auto_wrap']}\" size=30>");

	showRow( $lang_table['opt_tab_msgs'], $lang_table['opt_tab_msgsd'], makeDropDown(array("yes" => $lang['opt_sys_yes'], "no" => $lang['opt_sys_no']), "save_con[msgs_adm]", "{$table_config['msgs_adm']}"));
	showRow( $lang_table['opt_tab_msgs1'], $lang_table['opt_tab_msgsd1'], makeDropDown(array("yes" => $lang['opt_sys_yes'], "no" => $lang['opt_sys_no']), "save_con[msgs_usr]", "{$table_config['msgs_usr']}"));
	showRow( $lang_table['opt_tab_msgs_type'], $lang_table['opt_tab_msgs_typed'], makeDropDown(array("0" => $lang_table['opt_tab_msgs_type1'], "1" => $lang_table['opt_tab_msgs_type2']), "save_con[msgs_type]", "{$table_config['msgs_type']}"));

	$tr_hidden = " style='display:none'";

echo <<<HTML
<script language='JavaScript' type="text/javascript">
    function ShowOrHide(d1, d2) {
      if (d1 != '') DoDiv(d1);
      if (d2 != '') DoDiv(d2);
    }
    function DoDiv(id) {
      var item = null;
      if (document.getElementById) {
        item = document.getElementById(id);
      } else if (document.all){
        item = document.all[id];
      } else if (document.layers){
        item = document.layers[id];
      }
      if (!item) {
      }
      else if (item.style) {
        if (item.style.display == "none"){ item.style.display = ""; }
        else {item.style.display = "none"; }
      }else{ item.visibility = "show"; }
     }
</script>
HTML;

echo '<tr> <!- start main -->
    <td style="padding:4px" class="option">
    <b><a class="main" href="javascript:ShowOrHide(\'msgs-send1\',\'msgs-send2\')">' . $lang_table['opt_tab_mail_info1'] . '</a></b>
	<br />' . $lang_table['opt_tab_mail_info2'] .'</tr>
    <tr id=\'msgs-send1\' ' . $tr_hidden . '>
    <td valign="top" style="padding: 5px"  colspan="2">' . $lang_table['mail_pm_info1'] . '</td>
    </tr>
    <tr id=\'msgs-send2\' ' . $tr_hidden . '>
    <td colspan="2">
    <textarea rows="15" style="width:98%;" name="save_con[msgs_type0]">' . $table_config['msgs_type0'] . '</textarea>
	</tr>
    <tr><td background="system/skins/images/mline.gif" height=1 colspan=2></td></tr>
	<!-- End main -->';

echo '<tr> <!- start main -->
    <td style="padding:4px" class="option">
    <b><a class="main" href="javascript:ShowOrHide(\'msgs-send3\',\'msgs-send4\')">' . $lang_table['opt_tab_mail_info1'] . '</a></b>
	<br />' . $lang_table['opt_tab_mail_info3'] .'</tr>
    <tr id=\'msgs-send3\' ' . $tr_hidden . '>
    <td valign="top" style="padding: 5px"  colspan="2">' . $lang_table['mail_pm_info2'] . '</td>
    </tr>
    <tr id=\'msgs-send4\' ' . $tr_hidden . '>
    <td colspan="2">
    <textarea rows="15" style="width:98%;" name="save_con[msgs_type1]">' . $table_config['msgs_type1'] . '</textarea>
	</tr>
    <tr><td background="system/skins/images/mline.gif" height=1 colspan=2></td></tr>
	<!-- End main -->';
	
	$groups = get_groups();
	$groups = get_groups(explode(',', $table_config['grouplevel']));
	
	echo <<<HTML
	<tr><td style="padding:4px" class="option">
<b>{$lang_table['opt_tab_grouplevel']}</b><br /><span class=small>{$lang_table['opt_tab_groupleveld']}</span>
<td width=394 align=middle >
<select name="save_con[grouplevel]">{$groups}</select>
</tr><tr><td background="system/skins/images/mline.gif" height=1 colspan=2></td></tr>
HTML;
	
	echo <<< HTML
<td><div class="navigation">
<input type="hidden" name="action" value="save">
<input type="hidden" name="user_hash" value="$dle_login_hash" />
<input type="submit" class=bbcodes value=" {$lang_table['opt_btn_save']} ">
</div></td>
</form></table>
</td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr>
<tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr>
</table>
HTML;

echofooter();
	echo <<< HTML
</td>
<td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr>
<tr>
<td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr>
</table></div>
HTML;
}

elseif( $action == "massactions" ) {

if( ! $_SESSION['admin_referrer'] ) {
	$_SESSION['admin_referrer'] = "?mod=table&amp;action=list";
}

	if( $member_id['user_group'] !=1  ) { //DLE >= 7.5
		msg( "error", $lang['mass_error'], $lang['mass_ddenied'], $_SESSION['admin_referrer'] );
	}

$selected_orders = $_REQUEST['selected_orders'];

if( ! $selected_orders ) {
	msg( "error", $lang['mass_error'], $lang_table['mass_denied'], $_SESSION['admin_referrer'] );
}

if( $_REQUEST['user_hash'] == "" or $_REQUEST['user_hash'] != $dle_login_hash ) {
	die( "Hacking attempt! User not found" );
}

$s_action = htmlspecialchars( strip_tags( stripslashes( $_POST['s_action'] ) ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Подтвреждение удаления
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
if( $s_action == "mass_delete" ) {
	echoheader( "options", $lang_table['mass_head'] );
	echo <<<HTML
<form action="{$PHP_SELF}" method="post">
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
    <tr>
        <td width="4"><img src="system/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
        <td background="system/skins/images/tl_oo.gif"><img src="system/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
        <td width="6"><img src="system/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
    </tr>
    <tr>
        <td background="system/skins/images/tl_lb.gif"><img src="system/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
        <td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
    <tr>
        <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">{$lang_table['mass_head']}</div></td>
    </tr>
</table>
<div class="unterline"></div>
<table width="100%">
    <tr>
        <td style="padding:2px;" height="100" align="center">{$lang_table['mass_confirm']}
HTML;
	/* Nulled by N2C-TEAM(DotNet) */
	echo "(<b>" . count( $selected_orders ) . "</b>) $lang_table[mass_confirm_1]<br><br>
<input class=bbcodes type=submit value=\"   $lang[mass_yes]   \"> &nbsp; <input type=button class=bbcodes value=\"  $lang[mass_no]  \" onclick=\"javascript:document.location='$PHP_SELF?mod=table&action=list'\">
<input type=hidden name=s_action value=\"do_mass_delete\">
<input type=hidden name=user_hash value=\"{$dle_login_hash}\">
<input type=hidden name=mod value=\"table\">
<input type=hidden name=action value=\"massactions\">";
	foreach ( $selected_orders as $ordersid ) {
		$ordersid = intval($ordersid);
		echo "<input type=hidden name=selected_orders[] value=\"$ordersid\">\n";
	}

	echo <<<HTML
    </tr>
</table>
</td>
        <td background="system/skins/images/tl_rb.gif"><img src="system/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
    </tr>
    <tr>
        <td><img src="system/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
        <td background="system/skins/images/tl_ub.gif"><img src="system/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
        <td><img src="system/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
    </tr>
</table>
</div></form>
HTML;
	
	echofooter();
	exit();
} 
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Удаление новостей
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif( $s_action == "do_mass_delete" ) {
	$deleted_articles = 0;
	
	foreach ( $selected_orders as $id ) {
		$id = intval( $id );
		$deleted_articles ++;
		$db->query( "DELETE FROM " . PREFIX . "_table WHERE id='$id'" );
	}

	if( count( $selected_orders ) == $deleted_articles ) {
		msg( "info", $lang_table['mass_head'], $lang_table['mass_delok'], $_SESSION['admin_referrer'] );
	} else {
		msg( "error", $lang['mass_notok'], "$deleted_articles $lang[mass_i] " . count( $selected_orders ) . " $lang[mass_notok_1]", $_SESSION['admin_referrer'] );
	}
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Ничего не выбрано
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
else {
	msg( "info", $lang['mass_noact'], $lang['mass_noact_1'], $_SESSION['admin_referrer'] );
}
}

// ********************************************************************************
// Write options
// ********************************************************************************
if( $action == "save" ) {
	if( $_REQUEST['user_hash'] == "" or $_REQUEST['user_hash'] != $dle_login_hash ) {
		die( "Hacking attempt! User not found" );
	}

	$save_con = $_POST['save_con'];

	include_once SYSTEM_DIR . '/classes/parse.class.php';
	$parse = new ParseFilter( Array (), Array (), 1, 1 );

	$save_con['msgs_type0'] = $parse->process( stripslashes( trim( $save_con['msgs_type0'] ) ) );
	$save_con['msgs_type0'] = str_replace( '"', '&quot;', $parse->BB_Parse( $save_con['msgs_type0'], false ) );

	$save_con['msgs_type1'] = $parse->process( stripslashes( trim( $save_con['msgs_type1'] ) ) );
	$save_con['msgs_type1'] = str_replace( '"', '&quot;', $parse->BB_Parse( $save_con['msgs_type1'], false ) );

	$find[] = "'\r'";
	$replace[] = "";
	$find[] = "'\n'";
	$replace[] = "";

	$save_con['version_id'] = "2.5";
	$save_con = $save_con + $table_config;

		if( $member_id['user_group'] != 1 ){ msg( "error", $lang['opt_denied'], $lang['opt_denied'] ); } //DLE >= 7.5

	$handler = fopen( SYSTEM_DIR . '/data/tableconfig.php', "w" );

	fwrite( $handler, "<?PHP \n\n//Tables Configurations\n\n\$table_config = array (\n\n" );
	foreach ( $save_con as $name => $value ) {

	if( $name != "msgs_type0" OR $name != "msgs_type1") {
		$value = trim( stripslashes( $value ) );
		$value = htmlspecialchars( $value, ENT_QUOTES);
		$value = preg_replace( $find, $replace, $value );

		$name = trim( stripslashes( $name ) );
		$name = htmlspecialchars( $name, ENT_QUOTES );
		$name = preg_replace( $find, $replace, $name );
	}
		
		$value = str_replace( "$", "&#036;", $value );
		$value = str_replace( "{", "&#123;", $value );
		$value = str_replace( "}", "&#125;", $value );
		
		$name = str_replace( "$", "&#036;", $name );
		$name = str_replace( "{", "&#123;", $name );
		$name = str_replace( "}", "&#125;", $name );
		
		fwrite( $handler, "'{$name}' => \"{$value}\",\n\n" );
	
	}
	fwrite( $handler, ");\n\n?>" );
	fclose( $handler );

    $cache->clear();
	msg( "info", $lang['opt_sysok'], "$lang[opt_sysok_1]<br /><br /><a href=$PHP_SELF?mod=table&action=options>$lang[db_prev]</a>" );
}

?>