示例#1
0
function process_pagination($rows, $per_page = 20, $page_number = 0, $table_id = 'table')
{
    $data = array();
    $data['rows'] = array();
    $data['links'] = '';
    if ($per_page !== false && $per_page <= 0) {
        $per_page = 20;
    }
    hook_handle_callback('pagination_hook_init');
    if (isset($GLOBALS['pagination_group_hack'])) {
        module_group::run_pagination_hook($rows);
    }
    if (isset($GLOBALS['pagination_import_export_hack'])) {
        module_import_export::run_pagination_hook($rows);
    }
    if (class_exists('module_table_sort', false)) {
        module_table_sort::run_pagination_hook($rows, $per_page);
    }
    $db_resource = false;
    if (is_resource($rows)) {
        // have the db handle for the sql query
        $db_resource = $rows;
        unset($rows);
        $total = mysql_num_rows($db_resource);
    } else {
        if (is_array($rows)) {
            // we have the rows in an array.
            $total = count($rows);
        } else {
            print_header_message();
            echo 'Pagination failed. Please try going to Settings > Update and click the Manual Update button. If that does not fix this error please report this bug.';
            exit;
        }
    }
    // pagination hooks
    ob_start();
    if ($total > 0) {
        // group hack addition
        hook_handle_callback('pagination_hook_display');
        if (isset($GLOBALS['pagination_group_hack']) && module_group::groups_enabled()) {
            module_group::display_pagination_hook();
        }
        if (get_display_mode() != 'mobile') {
            // export hack addition
            if (isset($GLOBALS['pagination_import_export_hack'])) {
                module_import_export::display_pagination_hook();
            }
            if (class_exists('module_table_sort', false)) {
                module_table_sort::display_pagination_hook($per_page);
            }
        }
    }
    $pagination_hooks = ob_get_clean();
    // default summary/links content
    ob_start();
    echo '<div class="pagination_summary"><p>';
    if ($total > 0) {
        _e('Showing records %s to %s of %s', $page_number * $per_page + 1, $total, $total);
        echo $pagination_hooks;
    } else {
        _e('No results found');
    }
    echo '</p></div>';
    $data['summary'] = ob_get_clean();
    ob_start();
    echo '<div class="pagination_links">';
    //echo "\n<p>";
    echo _l('Page %s of %s', 1, 1);
    //echo '</p>';
    echo '</div>';
    $data['links'] = ob_get_clean();
    $data['page_numbers'] = 1;
    if ($per_page === false || $total <= $per_page) {
        if ($db_resource) {
            $rows = array();
            //if($per_page !== false && $total<=$per_page){
            // pull out all records.
            while ($row = mysql_fetch_assoc($db_resource)) {
                $rows[] = $row;
            }
            if (mysql_num_rows($db_resource) > 0) {
                mysql_data_seek($db_resource, 0);
            }
            //}
        }
        $data['rows'] = $rows;
    } else {
        if (isset($_REQUEST['pg' . $table_id])) {
            $page_number = $_REQUEST['pg' . $table_id];
        }
        if ($table_id && $table_id != 'table' && $total > $per_page) {
            // we remember the last page number we were on.
            if (!isset($_SESSION['_table_page_num'])) {
                $_SESSION['_table_page_num'] = array();
            }
            if (!isset($_SESSION['_table_page_num'][$table_id])) {
                $_SESSION['_table_page_num'][$table_id] = array('total_count' => 0, 'page_number' => 0);
            }
            $_SESSION['_table_page_num'][$table_id]['total_count'] = $total;
            if (isset($_REQUEST['pg' . $table_id])) {
                $page_number = $_REQUEST['pg' . $table_id];
            } else {
                if ($_SESSION['_table_page_num'][$table_id]['total_count'] == $total) {
                    $page_number = $_SESSION['_table_page_num'][$table_id]['page_number'];
                }
            }
            $_SESSION['_table_page_num'][$table_id]['page_number'] = $page_number;
            //echo $table_id.' '.$total . ' '.$per_page.' '.$page_number; print_r($_SESSION['_table_page_num']);
        }
        $page_number = min(ceil($total / $per_page) - 1, $page_number);
        // slice up the result into the number of rows requested.
        if ($db_resource) {
            // do the the mysql way:
            mysql_data_seek($db_resource, $page_number * $per_page);
            $x = 0;
            while ($x < $per_page) {
                $row_data = mysql_fetch_assoc($db_resource);
                if ($row_data) {
                    $data['rows'][] = $row_data;
                }
                $x++;
            }
            unset($row_data);
        } else {
            // the old array way.
            $data['rows'] = array_slice($rows, $page_number * $per_page, $per_page);
        }
        $data['summary'] = '';
        $data['links'] = '';
        $request_uri = preg_replace('/[&?]pg' . preg_quote($table_id) . '=\\d+/', '', $_SERVER['REQUEST_URI']);
        $request_uri .= preg_match('/\\?/', $request_uri) ? '&' : '?';
        $request_uri = htmlspecialchars($request_uri);
        if (count($data['rows'])) {
            $page_count = ceil($total / $per_page);
            // group into ranges with cute little .... around the numbers if there's too many.
            $rangestart = max(0, $page_number - 5);
            $rangeend = min($page_count - 1, $page_number + 5);
            ob_start();
            echo '<div class="pagination_summary">';
            echo '<p>';
            _e('Showing records %s to %s of %s', $page_number * $per_page + 1, $page_number * $per_page + count($data['rows']), $total);
            //echo 'Showing records ' . (($page_number*$per_page)+1) . ' to ' . (($page_number*$per_page)+count($data['rows'])) .' of ' . $total . '</p>';
            echo $pagination_hooks;
            echo '</p>';
            echo '</div>';
            $data['summary'] = ob_get_clean();
            ob_start();
            echo '<div class="pagination_links">';
            //echo "\n<p>";
            echo '<span>';
            if ($page_number > 0) {
                ?>
			    <a href="<?php 
                echo $request_uri;
                ?>
pg<?php 
                echo $table_id;
                ?>
=<?php 
                echo $page_number - 1;
                ?>
#t_<?php 
                echo $table_id;
                ?>
" rel="<?php 
                echo $page_number - 1;
                ?>
"><?php 
                _e('&laquo; Prev');
                ?>
</a> |
			<?php 
            } else {
                ?>
			    <?php 
                _e('&laquo; Prev');
                ?>
 |
			<?php 
            }
            echo '</span>';
            if ($rangestart > 0) {
                ?>
 <span><a href="<?php 
                echo $request_uri;
                ?>
pg<?php 
                echo $table_id;
                ?>
=0#t_<?php 
                echo $table_id;
                ?>
" rel="0" class="">1</a></span> <?php 
                if ($rangestart > 1) {
                    echo ' ... ';
                }
            }
            for ($x = $rangestart; $x <= $rangeend; $x++) {
                if ($x == $page_number) {
                    ?>
					<span><a href="<?php 
                    echo $request_uri;
                    ?>
pg<?php 
                    echo $table_id;
                    ?>
=<?php 
                    echo $x;
                    ?>
#t_<?php 
                    echo $table_id;
                    ?>
" rel="<?php 
                    echo $x;
                    ?>
" class="current"><?php 
                    echo $x + 1;
                    ?>
</a></span>
					<?php 
                } else {
                    ?>
					<span><a href="<?php 
                    echo $request_uri;
                    ?>
pg<?php 
                    echo $table_id;
                    ?>
=<?php 
                    echo $x;
                    ?>
#t_<?php 
                    echo $table_id;
                    ?>
" rel="<?php 
                    echo $x;
                    ?>
" class=""><?php 
                    echo $x + 1;
                    ?>
</a></span>
					<?php 
                }
            }
            if ($rangeend < $page_count - 1) {
                if ($rangeend < $page_count - 2) {
                    echo ' ... ';
                }
                ?>
 <span><a href="<?php 
                echo $request_uri;
                ?>
pg<?php 
                echo $table_id;
                ?>
=<?php 
                echo $page_count - 1;
                ?>
#t_<?php 
                echo $table_id;
                ?>
" rel="<?php 
                echo $page_count - 1;
                ?>
" class=""><?php 
                echo $page_count;
                ?>
</a></span> <?php 
            }
            if ($page_number < $page_count - 1) {
                ?>
			    | <span><a href="<?php 
                echo $request_uri;
                ?>
pg<?php 
                echo $table_id;
                ?>
=<?php 
                echo $page_number + 1;
                ?>
#t_<?php 
                echo $table_id;
                ?>
" rel="<?php 
                echo $page_number + 1;
                ?>
"><?php 
                _e('Next &raquo;');
                ?>
</a></span>
			<?php 
            } else {
                ?>
			    | <span><?php 
                _e('Next &raquo;');
                ?>
</span>
			<?php 
            }
            //echo '</p>';
            echo '</div>';
            ?>
			<script type="text/javascript">
				$(function(){
					$('.pagination_links a').each(function(){
						// make the links post the search bar on pagination.
						$(this).click(function(){
							// see if there's a search bar to post.
							var search_form = false;
							search_form = $('.search_form')[0];
							$('.search_bar').each(function(){
								var form = $(this).parents('form');
								if(typeof form != 'undefined'){
									search_form = form;
								}
							});
							if(typeof search_form == 'object'){
								$(search_form).append('<input type="hidden" name="pg<?php 
            echo $table_id;
            ?>
" value="'+$(this).attr('rel')+'">');
								search_form = search_form[0];
								if(typeof search_form.submit == 'function'){
									search_form.submit();
								}else{
									$('[name=submit]',search_form).click();
								}
								return false;
							}
						});
					});
				});
			</script>
			<?php 
            $data['links'] = ob_get_clean();
            $data['page_numbers'] = $page_count;
        }
    }
    return $data;
}
示例#2
0
if ($job_id > 0 && $job['job_id'] == $job_id) {
    $module->page_title = _l('Job: %s', $job['name']);
} else {
    $module->page_title = _l('Job: %s', _l('New'));
}
// check permissions.
if (class_exists('module_security', false)) {
    module_security::sanatise_data('job', $job);
}
$job_tasks = module_job::get_tasks($job_id);
if (class_exists('module_import_export', false)) {
    if (module_job::can_i('view', 'Export Job Tasks')) {
        module_import_export::enable_pagination_hook(array('name' => 'Job Tasks Export', 'fields' => array('Job Name' => 'job_name', 'Task ID' => 'task_id', 'Order' => 'task_order', 'Short Description' => 'description', 'Long Description' => 'long_description', 'Hours' => 'hours', 'Hours Completed' => 'completed', 'Amount' => 'amount', 'Billable' => 'billable', 'Fully Completed' => 'fully_completed', 'Date Due' => 'date_due', 'Invoice #' => 'invoice_number', 'Staff Member' => 'user_name', 'Approval Required' => 'approval_required')));
        if (isset($_REQUEST['import_export_go']) && $_REQUEST['import_export_go'] == 'yes') {
            // do the task export.
            module_import_export::run_pagination_hook($job_tasks);
        }
    }
    if (module_job::can_i('view', 'Import Job Tasks')) {
        $import_tasks_link = module_import_export::import_link(array('callback' => 'module_job::handle_import_tasks', 'name' => 'Job Tasks', 'job_id' => $job_id, 'return_url' => $_SERVER['REQUEST_URI'], 'fields' => array('Task ID' => array('task_id', false, 'The existing system ID for this task. Will overwrite existing task ID. Leave blank to create new task.'), 'Order' => array('task_order', false, 'The numerical order the tasks will appear in.'), 'Short Description' => array('description', true), 'Long Description' => 'long_description', 'Hours' => 'hours', 'Hours Completed' => 'completed', 'Amount' => 'amount', 'Billable' => array('billable', false, '1 for billable, 0 for non-billable'), 'Fully Completed' => array('fully_completed', false, '1 for fully completed, 0 for not completed'), 'Date Due' => array('date_due', false, 'When this task is due for completion'), 'Staff Member' => array('user_name', false, 'One of: ' . implode(', ', $staff_member_rel)), 'Approval Required' => array('approval_required', false, '1 if the administrator needs to approve this task, 0 if it does not require approval'))));
    }
}
?>


<script type="text/javascript">

    $(function(){
        if(typeof ucm.job != 'undefined'){
            ucm.job.ajax_task_url = '<?php 
echo module_job::link_ajax_task($job_id, false);
示例#3
0
if ($quote_id > 0 && $quote['quote_id'] == $quote_id) {
    $module->page_title = _l('Quote: %s', $quote['name']);
} else {
    $module->page_title = _l('Quote: %s', _l('New'));
}
// check permissions.
if (class_exists('module_security', false)) {
    module_security::sanatise_data('quote', $quote);
}
$quote_tasks = module_quote::get_quote_items($quote_id, $quote);
if (class_exists('module_import_export', false)) {
    if (module_quote::can_i('view', 'Export Quote Tasks')) {
        module_import_export::enable_pagination_hook(array('name' => 'Quote Tasks Export', 'fields' => array('Quote Name' => 'quote_name', 'Task ID' => 'quote_task_id', 'Order' => 'task_order', 'Short Description' => 'description', 'Long Description' => 'long_description', 'Hours' => 'hours', 'Amount' => 'amount', 'Billable' => 'billable', 'Staff Member' => 'user_name')));
        if (isset($_REQUEST['import_export_go']) && $_REQUEST['import_export_go'] == 'yes') {
            // do the task export.
            module_import_export::run_pagination_hook($quote_tasks);
        }
    }
    if (module_quote::can_i('view', 'Import Quote Tasks')) {
        $import_tasks_link = module_import_export::import_link(array('callback' => 'module_quote::handle_import_tasks', 'name' => 'Quote Tasks', 'quote_id' => $quote_id, 'return_url' => $_SERVER['REQUEST_URI'], 'fields' => array('Task ID' => array('quote_task_id', false, 'The existing system ID for this task. Will overwrite existing task ID. Leave blank to create new task.'), 'Order' => array('task_order', false, 'The numerical order the tasks will appear in.'), 'Short Description' => array('description', true), 'Long Description' => 'long_description', 'Hours' => 'hours', 'Hours Completed' => 'completed', 'Amount' => 'amount', 'Billable' => array('billable', false, '1 for billable, 0 for non-billable'), 'Staff Member' => array('user_name', false, 'One of: ' . implode(', ', $staff_member_rel)))));
    }
}
?>


<script type="text/javascript">

    $(function(){
        if(typeof ucm.quote != 'undefined'){
            ucm.quote.ajax_task_url = '<?php 
echo module_quote::link_ajax_task($quote_id, false);