Example #1
0
/**
 * Display the manual pages results table
 *
 * @param array Params
 */
function items_manual_results_block($params = array())
{
    // Make sure we are not missing any param:
    $params = array_merge(array('results_param_prefix' => 'items_manual_'), $params);
    if (!is_logged_in()) {
        // Only logged in users can access to this function
        return;
    }
    global $current_User, $blog, $Blog, $admin_url, $Session;
    $result_fadeout = $Session->get('fadeout_array');
    $cat_ID = param('cat_ID', 'integer', 0);
    if (empty($Blog)) {
        // Init Blog
        $BlogCache =& get_BlogCache();
        $blog = get_param('blog');
        if (!empty($blog)) {
            // Get Blog by ID
            $Blog = $BlogCache->get_by_ID($blog, false);
        }
        if (empty($Blog) && !empty($cat_ID)) {
            // Get Blog from chapter ID
            $ChapterCache =& get_ChapterCache();
            if ($Chapter =& $ChapterCache->get_by_ID($cat_ID, false)) {
                $Blog = $Chapter->get_Blog();
                $blog = $Blog->ID;
            }
        }
    }
    if (empty($Blog) || $Blog->get('type') != 'manual') {
        // No Blog, Exit here
        return;
    }
    if (is_ajax_content()) {
        $order_action = param('order_action', 'string');
        if ($order_action == 'update') {
            // Update an order to new value
            $order_value = (int) param('order_value', 'string', 0);
            $order_data = param('order_data', 'string');
            $order_data = explode('-', $order_data);
            $order_obj_ID = (int) $order_data[2];
            if ($order_obj_ID > 0) {
                switch ($order_data[1]) {
                    case 'chapter':
                        // Update chapter order
                        $ChapterCache =& get_ChapterCache();
                        if ($updated_Chapter =& $ChapterCache->get_by_ID($order_obj_ID, false)) {
                            if ($current_User->check_perm('blog_cats', '', false, $updated_Chapter->blog_ID)) {
                                // Check permission to edit this Chapter
                                $updated_Chapter->set('order', $order_value);
                                $updated_Chapter->dbupdate();
                                $ChapterCache->clear();
                            }
                        }
                        break;
                    case 'item':
                        // Update item order
                        $ItemCache =& get_ItemCache();
                        if ($updated_Item =& $ItemCache->get_by_ID($order_obj_ID, false)) {
                            if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $updated_Item)) {
                                // Check permission to edit this Item
                                $updated_Item->set('order', $order_value);
                                $updated_Item->dbupdate();
                            }
                        }
                        break;
                }
            }
        }
    }
    load_class('_core/ui/_uiwidget.class.php', 'Table');
    $Table = new Table(NULL, $params['results_param_prefix']);
    $Table->title = T_('Manual Pages');
    // Redirect to manual pages after adding chapter
    $redirect_page = '&redirect_page=manual';
    $Table->global_icon(T_('Add new chapter...'), 'add', $admin_url . '?ctrl=chapters&action=new&blog=' . $blog . $redirect_page, ' ' . T_('Add top level chapter') . ' »', 3, 4);
    $Table->cols[] = array('th' => T_('Name'));
    $Table->cols[] = array('th' => T_('URL "slug"'));
    $Table->cols[] = array('th' => T_('Order'), 'th_class' => 'shrinkwrap');
    $Table->cols[] = array('th' => T_('Actions'));
    if (is_ajax_content()) {
        // init results param by template name
        if (!isset($params['skin_type']) || !isset($params['skin_name'])) {
            debug_die('Invalid ajax results request!');
        }
        $Table->init_params_by_skin($params['skin_type'], $params['skin_name']);
    }
    $Table->display_init(NULL, $result_fadeout);
    $Table->display_head();
    echo $Table->replace_vars($Table->params['content_start']);
    $Table->display_list_start();
    $Table->display_col_headers();
    $Table->display_body_start();
    manual_display_chapters();
    $Table->display_body_end();
    $Table->display_list_end();
    // Flush fadeout
    $Session->delete('fadeout_array');
    echo $Table->params['content_end'];
    if (!is_ajax_content()) {
        // Create this hidden div to get a function name for AJAX request
        echo '<div id="' . $params['results_param_prefix'] . 'ajax_callback" style="display:none">' . __FUNCTION__ . '</div>';
    }
}