<?php
/*
+-----------------------------------------------------------------------------+
| $Id: channel.php 2010-05-24 12:37:44Z Bleakwind $
| Channel list handle
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

if ($sys->get['ope'] == "process") {
    // update_click
    function channel_process()
    {
        global $LANGUAGE,$LANGLIST,$SETTING,$CONFIGURE,$MEMBER,$ADMIN,$db,$sys,$c,$ac;
        $ajax_response = new xajaxResponse();
        if( preg_match("/^[1-9][0-9]{0,10}$/",$sys->get['channel_id']) ){
            $channel_info = func::db_select(DB_TABLE_CHANNEL, "if_turn,if_turn_url", "id=".$sys->get['channel_id']);
            $channel_info = $channel_info[0];
            if ($channel_info['if_turn'] == "1" && !empty($channel_info['if_turn_url'])){
                $ajax_response->redirect($channel_info['if_turn_url']);
            }
        }
        return $ajax_response;
    }
    $bwajax->register(XAJAX_FUNCTION, "channel_process");

    $new_template = "page_blank.htm";

} else {

    $bwajax->configure('requestURI', $CONFIGURE['common']['control_index']."?act=channel&ope=process&channel_id=".$sys->get['channel_id']);
    $bwajax->register(XAJAX_FUNCTION, "channel_process");

    if( !preg_match("/^[1-9][0-9]{0,10}$/",$sys->get['channel_id']) ){
        $sys->prompt("failed",$LANGUAGE['s']['channel']['channel_id_error']."<!-- channel_id_error -->");
    } else {

        $sys->return_channel_info($sys->get['channel_id']);
        $sys->return_setmodel_info($sys->channel_info['setmodel_id']);

        if( !preg_match("/^[1-9][0-9]{0,10}$/",$sys->channel_info['id']) ){
            $sys->prompt("failed",$LANGUAGE['s']['channel']['channel_id_not_exist']."<!-- channel_id_not_exist -->");
        } elseif ($sys->channel_info['if_enable'] != "1") {
            $sys->prompt("failed",$LANGUAGE['s']['channel']['channel_not_enable']."<!-- channel_not_enable -->");
        } else { 

            if ($sys->channel_info['if_turn'] == "1") {
                $new_template = "page_redirect.htm";
            } else {

                $channel_sub = $sys->return_channel_list($sys->get['channel_id']);

                // Template for setmodel
                if (!empty($sys->setmodel_info['template_channel']) && file_exists($t->template_dir.$sys->setmodel_info['template_channel'])) {
                    $new_template = $sys->setmodel_info['template_channel'];
                    if (substr($new_template, -4, 4) == ".htm") {
                        $dir_css_new    = substr($new_template, 0, -4)."/css/css.css";
                        $dir_js_new     = substr($new_template, 0, -4)."/js/js.js";
                    } elseif (substr($new_template, -5, 5) == ".html") {
                        $dir_css_new    = substr($new_template, 0, -5)."/css/css.css";
                        $dir_js_new     = substr($new_template, 0, -5)."/js/js.js";
                    }
                }

                // Template for setmodel
                if (!empty($sys->channel_info['template_channel']) && file_exists($t->template_dir.$sys->channel_info['template_channel'])) {
                    $new_template = $sys->channel_info['template_channel'];
                    if (substr($new_template, -4, 4) == ".htm") {
                        $dir_css_new    = substr($new_template, 0, -4)."/css/css.css";
                        $dir_js_new     = substr($new_template, 0, -4)."/js/js.js";
                    } elseif (substr($new_template, -5, 5) == ".html") {
                        $dir_css_new    = substr($new_template, 0, -5)."/css/css.css";
                        $dir_js_new     = substr($new_template, 0, -5)."/js/js.js";
                    }
                }

                if (preg_match("/^[1-9][0-9]{0,10}$/i", $sys->channel_info['id'])) {
                    $sys->return_channel_path($sys->channel_info['id']);
                }

                $t->assign(array(
                    "channel_info"      => $sys->channel_info,
                    "channel_path"      => $sys->channel_path,
                    "channel_sub"       => $channel_sub,
                ));
            }
        }
    }
}
if (!empty($sys->channel_path)) { 
    foreach($sys->channel_path as $v){ 
        $public_var['page_place'][] = $v['name']; 
        $public_var['page_keyword'] = array_merge((array)$public_var['page_keyword'], array_filter(preg_split("/[\s,]+/", $v['keyword'])));
    }
}
?>
