Ejemplo n.º 1
0
    $columns['ticket_product'] = array('title' => 'Product', 'callback' => function ($ticket) {
        if ($ticket['faq_product_id']) {
            $faq_product = module_faq::get_faq_product($ticket['faq_product_id']);
            echo $faq_product && isset($faq_product['name']) ? htmlspecialchars($faq_product['name']) : '';
        }
    });
}
if (class_exists('module_envato', false)) {
    $columns['ticket_envato'] = array('title' => _l('Envato%s', module_config::c('envato_show_ticket_earning', 0) ? ' (' . dollar($envato_count * 0.7) . ')' : ''), 'callback' => function ($ticket) {
        $items = module_envato::get_items_by_ticket($ticket['ticket_id']);
        foreach ($items as $item) {
            echo '<a href="' . $item['url'] . '">' . htmlspecialchars($item['name']) . '</a> ';
        }
    });
}
if (class_exists('module_group', false) && module_config::c('ticket_enable_groups', 1) && module_group::groups_enabled()) {
    $columns['ticket_group'] = array('title' => 'Group', 'callback' => function ($ticket) {
        // find the groups for this customer.
        $groups = module_group::get_groups_search(array('owner_table' => 'ticket', 'owner_id' => $ticket['ticket_id']));
        $g = array();
        foreach ($groups as $group) {
            $g[] = $group['name'];
        }
        echo implode(', ', $g);
    });
}
if (module_config::c('ticket_allow_priority', 0) && module_config::c('ticket_show_priority', 1)) {
    $columns['ticket_priority'] = array('title' => 'Priority', 'callback' => function ($ticket) use($priorities) {
        echo $priorities[$ticket['priority']];
    });
}
Ejemplo n.º 2
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;
}