예제 #1
0
function list_blocks()
{
    global $query4redirect, $block_arr, $xoopsGTicket;
    // cachetime options
    $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH);
    // displaying TH
    smartsection_collapsableBar('blockstable', 'blocksicon', _AM_SSECTION_BLOCKS, _AM_SSECTION_BLOCKSTXT);
    echo "\n\t<form action='admin.php' name='blockadmin' method='post'>\n\t\t<table width='100%' class='outer' cellpadding='4' cellspacing='1'>\n\t\t<tr valign='middle'>\n\t\t\t<th>" . _AM_TITLE . "</th>\n\t\t\t<th align='center' nowrap='nowrap'>" . _AM_SIDE . "</th>\n\t\t\t<th align='center'>" . _AM_WEIGHT . "</th>\n\t\t\t<th align='center'>" . _AM_VISIBLEIN . "</th>\n\t\t\t<th align='center'>" . _AM_BCACHETIME . "</th>\n\t\t\t<th align='center'>" . _AM_ACTION . "</th>\n\t\t</tr>\n";
    // blocks displaying loop
    $class = 'even';
    $block_configs = get_block_configs();
    foreach (array_keys($block_arr) as $i) {
        $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = "";
        $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = "#FFFFFF";
        $weight = $block_arr[$i]->getVar("weight");
        $title = $block_arr[$i]->getVar("title");
        $name = $block_arr[$i]->getVar("name");
        $bcachetime = $block_arr[$i]->getVar("bcachetime");
        $bid = $block_arr[$i]->getVar("bid");
        // visible and side
        if ($block_arr[$i]->getVar("visible") != 1) {
            $sseln = " checked='checked'";
            $scoln = "#FF0000";
        } else {
            switch ($block_arr[$i]->getVar("side")) {
                default:
                case XOOPS_SIDEBLOCK_LEFT:
                    $ssel0 = " checked='checked'";
                    $scol0 = "#00FF00";
                    break;
                case XOOPS_SIDEBLOCK_RIGHT:
                    $ssel1 = " checked='checked'";
                    $scol1 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_LEFT:
                    $ssel2 = " checked='checked'";
                    $scol2 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_RIGHT:
                    $ssel4 = " checked='checked'";
                    $scol4 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_CENTER:
                    $ssel3 = " checked='checked'";
                    $scol3 = "#00FF00";
                    break;
            }
        }
        // bcachetime
        $cachetime_options = '';
        foreach ($cachetimes as $cachetime => $cachetime_name) {
            if ($bcachetime == $cachetime) {
                $cachetime_options .= "<option value='{$cachetime}' selected='selected'>{$cachetime_name}</option>\n";
            } else {
                $cachetime_options .= "<option value='{$cachetime}'>{$cachetime_name}</option>\n";
            }
        }
        // target modules
        $db =& Database::getInstance();
        $result = $db->query("SELECT module_id FROM " . $db->prefix('block_module_link') . " WHERE block_id='{$bid}'");
        $selected_mids = array();
        while (list($selected_mid) = $db->fetchRow($result)) {
            $selected_mids[] = intval($selected_mid);
        }
        $module_handler =& xoops_gethandler('module');
        $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
        $criteria->add(new Criteria('isactive', 1));
        $module_list =& $module_handler->getList($criteria);
        $module_list[-1] = _AM_TOPPAGE;
        $module_list[0] = _AM_ALLPAGES;
        ksort($module_list);
        $module_options = '';
        foreach ($module_list as $mid => $mname) {
            if (in_array($mid, $selected_mids)) {
                $module_options .= "<option value='{$mid}' selected='selected'>{$mname}</option>\n";
            } else {
                $module_options .= "<option value='{$mid}'>{$mname}</option>\n";
            }
        }
        // delete link if it is cloned block
        if ($block_arr[$i]->getVar("block_type") == 'D' || $block_arr[$i]->getVar("block_type") == 'C') {
            $delete_link = "<br /><a href='admin.php?fct=blocksadmin&amp;op=delete&amp;bid={$bid}'>" . _DELETE . "</a>";
        } else {
            $delete_link = '';
        }
        // clone link if it is marked as cloneable block
        // $modversion['blocks'][n]['can_clone']
        if ($block_arr[$i]->getVar("block_type") == 'D' || $block_arr[$i]->getVar("block_type") == 'C') {
            $can_clone = true;
        } else {
            $can_clone = false;
            foreach ($block_configs as $bconf) {
                if ($block_arr[$i]->getVar("show_func") == $bconf['show_func'] && $block_arr[$i]->getVar("func_file") == $bconf['file'] && (empty($bconf['template']) || $block_arr[$i]->getVar("template") == $bconf['template'])) {
                    if (!empty($bconf['can_clone'])) {
                        $can_clone = true;
                    }
                }
            }
        }
        if ($can_clone) {
            $clone_link = "<br /><a href='admin.php?fct=blocksadmin&amp;op=clone&amp;bid={$bid}'>" . _CLONE . "</a>";
        } else {
            $clone_link = '';
        }
        // displaying part
        echo "\n\t\t<tr valign='middle'>\n\t\t\t<td class='{$class}'>\n\t\t\t\t{$name}\n\t\t\t\t<br />\n\t\t\t\t<input type='text' name='title[{$bid}]' value='{$title}' size='20' />\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center' nowrap='nowrap' width='125px'>\n\t\t\t\t<div style='float:left;background-color:{$scol0};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='" . XOOPS_SIDEBLOCK_LEFT . "' style='background-color:{$scol0};' {$ssel0} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>-</div>\n\t\t\t\t<div style='float:left;background-color:{$scol2};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='" . XOOPS_CENTERBLOCK_LEFT . "' style='background-color:{$scol2};' {$ssel2} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;background-color:{$scol3};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='" . XOOPS_CENTERBLOCK_CENTER . "' style='background-color:{$scol3};' {$ssel3} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;background-color:{$scol4};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='" . XOOPS_CENTERBLOCK_RIGHT . "' style='background-color:{$scol4};' {$ssel4} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>-</div>\n\t\t\t\t<div style='float:left;background-color:{$scol1};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='" . XOOPS_SIDEBLOCK_RIGHT . "' style='background-color:{$scol1};' {$ssel1} />\n\t\t\t\t</div>\n\t\t\t\t<br />\n\t\t\t\t<br />\n\t\t\t\t<div style='float:left;width:40px;'>&nbsp;</div>\n\t\t\t\t<div style='float:left;background-color:{$scoln};'>\n\t\t\t\t\t<input type='radio' name='side[{$bid}]' value='-1' style='background-color:{$scoln};' {$sseln} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>" . _NONE . "</div>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<input type='text' name=weight[{$bid}] value='{$weight}' size='3' maxlength='5' style='text-align:right;' />\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<select name='bmodule[{$bid}][]' size='5' multiple='multiple'>\n\t\t\t\t\t{$module_options}\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<select name='bcachetime[{$bid}]' size='1'>\n\t\t\t\t\t{$cachetime_options}\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid={$bid}'>" . _EDIT . "</a>{$delete_link}{$clone_link}\n\t\t\t\t<input type='hidden' name='bid[{$bid}]' value='{$bid}' />\n\t\t\t</td>\n\t\t</tr>\n";
        $class = $class == 'even' ? 'odd' : 'even';
    }
    echo "\n\t\t<tr>\n\t\t\t<td class='foot' align='center' colspan='6'>\n\t\t\t\t<input type='hidden' name='query4redirect' value='{$query4redirect}' />\n\t\t\t\t<input type='hidden' name='fct' value='blocksadmin' />\n\t\t\t\t<input type='hidden' name='op' value='order' />\n\t\t\t\t" . $xoopsGTicket->getTicketHtml(__LINE__, 1800, 'myblocksadmin') . "\n\t\t\t\t<input type='submit' name='submit' value='" . _SUBMIT . "' />\n\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t</form>\n";
    smartsection_close_collapsable('blockstable', 'blocksicon');
}
function list_blockinstances()
{
    global $query4redirect, $block_arr, $xoopsGTicket;
    $myts =& MyTextSanitizer::getInstance();
    // cachetime options
    $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH);
    // displaying TH
    echo "\n\t<form action='admin.php' name='blockadmin' method='post'>\n\t\t<table width='95%' class='outer' cellpadding='4' cellspacing='1'>\n\t\t<tr valign='middle'>\n\t\t\t<th>" . _AM_TITLE . "</th>\n\t\t\t<th align='center' nowrap='nowrap'>" . _AM_SIDE . "</th>\n\t\t\t<th align='center'>" . _AM_WEIGHT . "</th>\n\t\t\t<th align='center'>" . _AM_VISIBLEIN . "</th>\n\t\t\t<th align='center'>" . _AM_BCACHETIME . "</th>\n\t\t\t<th align='right'>" . _AM_ACTION . "</th>\n\t\t</tr>\n";
    // get block instances
    $crit = new Criteria("bid", "(" . implode(",", array_keys($block_arr)) . ")", "IN");
    $criteria = new CriteriaCompo($crit);
    $criteria->setSort('visible DESC, side ASC, weight');
    $instance_handler =& xoops_gethandler('blockinstance');
    $instances =& $instance_handler->getObjects($criteria, true, true);
    //Get modules and pages for visible in
    $module_list[_AM_SYSTEMLEVEL]["0-2"] = _AM_ADMINBLOCK;
    $module_list[_AM_SYSTEMLEVEL]["0-1"] = _AM_TOPPAGE;
    $module_list[_AM_SYSTEMLEVEL]["0-0"] = _AM_ALLPAGES;
    $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
    $criteria->add(new Criteria('isactive', 1));
    $module_handler =& xoops_gethandler('module');
    $module_main =& $module_handler->getObjects($criteria, true, true);
    if (count($module_main) > 0) {
        foreach (array_keys($module_main) as $mid) {
            $module_list[$module_main[$mid]->getVar('name')][$mid . "-0"] = _AM_ALLMODULEPAGES;
            $pages = $module_main[$mid]->getInfo("pages");
            if ($pages == false) {
                $pages = $module_main[$mid]->getInfo("sub");
            }
            if (is_array($pages) && $pages != array()) {
                foreach ($pages as $id => $pageinfo) {
                    $module_list[$module_main[$mid]->getVar('name')][$mid . "-" . $id] = $pageinfo['name'];
                }
            }
        }
    }
    // blocks displaying loop
    $class = 'even';
    $block_configs = get_block_configs();
    foreach (array_keys($instances) as $i) {
        $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = "";
        $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = "#FFFFFF";
        $weight = $instances[$i]->getVar("weight");
        $title = $instances[$i]->getVar("title");
        $bcachetime = $instances[$i]->getVar("bcachetime");
        $bid = $instances[$i]->getVar("bid");
        $name = $myts->makeTboxData4Edit($block_arr[$bid]['name']);
        $visiblein = $instances[$i]->getVisibleIn();
        // visible and side
        if ($instances[$i]->getVar("visible") != 1) {
            $sseln = " checked='checked'";
            $scoln = "#FF0000";
        } else {
            switch ($instances[$i]->getVar("side")) {
                default:
                case XOOPS_SIDEBLOCK_LEFT:
                    $ssel0 = " checked='checked'";
                    $scol0 = "#00FF00";
                    break;
                case XOOPS_SIDEBLOCK_RIGHT:
                    $ssel1 = " checked='checked'";
                    $scol1 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_LEFT:
                    $ssel2 = " checked='checked'";
                    $scol2 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_RIGHT:
                    $ssel4 = " checked='checked'";
                    $scol4 = "#00FF00";
                    break;
                case XOOPS_CENTERBLOCK_CENTER:
                    $ssel3 = " checked='checked'";
                    $scol3 = "#00FF00";
                    break;
            }
        }
        // bcachetime
        $cachetime_options = '';
        foreach ($cachetimes as $cachetime => $cachetime_name) {
            if ($bcachetime == $cachetime) {
                $cachetime_options .= "<option value='{$cachetime}' selected='selected'>{$cachetime_name}</option>\n";
            } else {
                $cachetime_options .= "<option value='{$cachetime}'>{$cachetime_name}</option>\n";
            }
        }
        $module_options = '';
        foreach ($module_list as $mname => $module) {
            $module_options .= "<optgroup label='{$mname}'>\n";
            foreach ($module as $mkey => $mval) {
                if (in_array($mkey, $visiblein)) {
                    $module_options .= "<option value='{$mkey}' selected='selected'>{$mval}</option>\n";
                } else {
                    $module_options .= "<option label='{$mval}' value='{$mkey}'>{$mval}</option>\n";
                }
            }
            $module_options .= "</optgroup>\n";
        }
        // delete link if it is cloned block
        $delete_link = "<br /><a href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;id={$i}&amp;selmod={$mid}'>" . _DELETE . "</a>";
        // displaying part
        echo "\n\t\t<tr valign='middle'>\n\t\t\t<td class='{$class}'>\n\t\t\t\t{$name}\n\t\t\t\t<br />\n\t\t\t\t<input type='text' name='title[{$i}]' value='{$title}' size='20' />\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center' nowrap='nowrap' width='125px'>\n\t\t\t\t<div style='float:left;background-color:{$scol0};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='" . XOOPS_SIDEBLOCK_LEFT . "' style='background-color:{$scol0};' {$ssel0} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>-</div>\n\t\t\t\t<div style='float:left;background-color:{$scol2};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='" . XOOPS_CENTERBLOCK_LEFT . "' style='background-color:{$scol2};' {$ssel2} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;background-color:{$scol3};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='" . XOOPS_CENTERBLOCK_CENTER . "' style='background-color:{$scol3};' {$ssel3} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;background-color:{$scol4};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='" . XOOPS_CENTERBLOCK_RIGHT . "' style='background-color:{$scol4};' {$ssel4} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>-</div>\n\t\t\t\t<div style='float:left;background-color:{$scol1};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='" . XOOPS_SIDEBLOCK_RIGHT . "' style='background-color:{$scol1};' {$ssel1} />\n\t\t\t\t</div>\n\t\t\t\t<br />\n\t\t\t\t<br />\n\t\t\t\t<div style='float:left;width:40px;'>&nbsp;</div>\n\t\t\t\t<div style='float:left;background-color:{$scoln};'>\n\t\t\t\t\t<input type='radio' name='side[{$i}]' value='-1' style='background-color:{$scoln};' {$sseln} />\n\t\t\t\t</div>\n\t\t\t\t<div style='float:left;'>" . _NONE . "</div>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<input type='text' name=weight[{$i}] value='{$weight}' size='3' maxlength='5' style='text-align:right;' />\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<select name='bmodule[{$i}][]' size='5' multiple='multiple'>\n\t\t\t\t\t{$module_options}\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<select name='bcachetime[{$i}]' size='1'>\n\t\t\t\t\t{$cachetime_options}\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='right'>\n\t\t\t\t<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&amp;op=edit&amp;id={$i}'>" . _EDIT . "</a>{$delete_link}\n\t\t\t\t<input type='hidden' name='id[{$i}]' value='{$i}' />\n\t\t\t</td>\n\t\t</tr>\n";
        $class = $class == 'even' ? 'odd' : 'even';
    }
    // list block classes for add (not instances)
    foreach ($block_arr as $bid => $block) {
        $description4show = '';
        foreach ($block_configs as $bconf) {
            if ($block['show_func'] == $bconf['show_func'] && $block['func_file'] == $bconf['file'] && (empty($bconf['template']) || $block['template'] == $bconf['template'])) {
                if (!empty($bconf['description'])) {
                    $description4show = $myts->makeTboxData4Show($bconf['description']);
                }
            }
        }
        echo "\n\t\t<tr>\n\t\t\t<td class='{$class}' align='left'>\n\t\t\t\t" . $myts->makeTboxData4Edit($block['name']) . "\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='left' colspan='4'>\n\t\t\t\t{$description4show}\n\t\t\t</td>\n\t\t\t<td class='{$class}' align='center'>\n\t\t\t\t<input type='submit' name='addblock[{$bid}]' value='" . _ADD . "' />\n\t\t\t</td>\n\t\t</tr>\n\t\t\n";
        $class = $class == 'even' ? 'odd' : 'even';
    }
    echo "\n\t\t<tr>\n\t\t\t<td class='foot' align='center' colspan='6'>\n\t\t\t\t<input type='hidden' name='query4redirect' value='{$query4redirect}' />\n\t\t\t\t<input type='hidden' name='fct' value='blocksadmin' />\n\t\t\t\t<input type='hidden' name='op' value='order2' />\n\t\t\t\t" . $xoopsGTicket->getTicketHtml(__LINE__, 1800, 'myblocksadmin') . "\n\t\t\t\t<input type='submit' name='submit' value='" . _SUBMIT . "' />\n\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t</form>\n";
}