PHP ceil Examples

PHP ceil - 30 examples found. These are the top rated real world PHP examples of ceil extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
2
/**
 * utf8::str_pad
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = utf8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = utf8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
Example #2
1
function getLocation($str)
{
    $array_size = intval(substr($str, 0, 1));
    // 拆成的行数
    $code = substr($str, 1);
    // 加密后的串
    $len = strlen($code);
    $subline_size = $len % $array_size;
    // 满字符的行数
    $result = array();
    $deurl = "";
    for ($i = 0; $i < $array_size; $i += 1) {
        if ($i < $subline_size) {
            array_push($result, substr($code, 0, ceil($len / $array_size)));
            $code = substr($code, ceil($len / $array_size));
        } else {
            array_push($result, substr($code, 0, ceil($len / $array_size) - 1));
            $code = substr($code, ceil($len / $array_size) - 1);
        }
    }
    for ($i = 0; $i < ceil($len / $array_size); $i += 1) {
        for ($j = 0; $j < count($result); $j += 1) {
            $deurl = $deurl . "" . substr($result[$j], $i, 1);
        }
    }
    return str_replace("^", "0", urldecode($deurl));
}
Example #3
1
function page_navi($before = '', $after = '')
{
    global $wpdb, $wp_query;
    $request = $wp_query->request;
    $posts_per_page = intval(get_query_var('posts_per_page'));
    $paged = intval(get_query_var('paged'));
    $numposts = $wp_query->found_posts;
    $max_page = $wp_query->max_num_pages;
    if ($numposts <= $posts_per_page) {
        return;
    }
    if (empty($paged) || $paged == 0) {
        $paged = 1;
    }
    $pages_to_show = 3;
    $pages_to_show_minus_1 = $pages_to_show - 1;
    $half_page_start = floor($pages_to_show_minus_1 / 2);
    $half_page_end = ceil($pages_to_show_minus_1 / 2);
    $start_page = $paged - $half_page_start;
    if ($start_page <= 0) {
        $start_page = 1;
    }
    $end_page = $paged + $half_page_end;
    if ($end_page - $start_page != $pages_to_show_minus_1) {
        $end_page = $start_page + $pages_to_show_minus_1;
    }
    if ($end_page > $max_page) {
        $start_page = $max_page - $pages_to_show_minus_1;
        $end_page = $max_page;
    }
    if ($start_page <= 0) {
        $start_page = 1;
    }
    echo $before . '<div class="pagination_wrapper"><ul class="pagination">' . "";
    if ($paged > 1) {
        $first_page_text = "First";
        echo '<li class="prev"><a href="' . get_pagenum_link() . '" title="First">' . $first_page_text . '</a></li>';
    }
    $prevposts = get_previous_posts_link('Prev');
    if ($prevposts) {
        echo '<li>' . $prevposts . '</li>';
    } else {
        echo '<li class="disabled"><a href="#">Prev</a></li>';
    }
    for ($i = $start_page; $i <= $end_page; $i++) {
        if ($i == $paged) {
            echo '<li class="active"><a href="#">' . $i . '</a></li>';
        } else {
            echo '<li><a href="' . get_pagenum_link($i) . '">' . $i . '</a></li>';
        }
    }
    if ($end_page < $max_page) {
        $last_page_text = $max_page;
        echo '<li class="next"><a href="' . get_pagenum_link($max_page) . '" title="Last">' . $last_page_text . '</a></li>';
    }
    echo '<li class="">';
    next_posts_link('Next');
    echo '</li>';
    echo '</ul></div>' . $after . "";
}
Example #4
1
 public function mostrarPost($page = 1)
 {
     // traemos la cantidad de registros para el paginador
     $registros = DB::table('post')->join('temas', 'post_tema', '=', 'temas.tema_id')->where('post_tipo', 'ENTRADA')->orderBy('post_fec', 'desc')->get();
     $totalRegistros = count($registros);
     //die("totalRegistros ".$totalRegistros); //16
     $paginador = 15;
     // Parametrizarlo desde DB
     $cantPagina = $totalRegistros / $paginador;
     //die("cantPagina ".$cantPagina); //1.066
     $cantPagina = ceil($cantPagina);
     //die("cantidad de paginas ".$cantPagina); //2
     if ($page != 1) {
         $comienzo = $page * $paginador - $paginador + 1;
         // ((2*15)-15+1);
         // (30)-14
         // comenzara en la 16, pagina 2 y asi sucesivamente..
     } else {
         $comienzo = 1;
     }
     $final = $page * $paginador;
     $post = DB::table('post')->join('temas', 'post_tema', '=', 'temas.tema_id')->where('post_tipo', 'ENTRADA')->orderBy('post_fec', 'desc')->skip($comienzo - 1)->take($final)->get();
     //
     if (count($post) < 1) {
         $error = "No hay más resultados para mostrar.";
     } else {
         $error = "";
     }
     $tema = DB::table('post as p')->select('tm.tema_txt', 'tm.tema_img')->distinct()->join('usuarios as u', 'p.post_usu', '=', 'u.usuarios_id')->join('temas as tm', 'p.post_tema', '=', 'tm.tema_id')->orderBy('tm.tema_txt', 'asc')->get();
     // Retornamos todos los datos
     $entradas = DB::table('post as p')->select('p.*', 'u.usuarios_name', 'tm.tema_txt')->join('usuarios as u', 'p.post_usu', '=', 'u.usuarios_id')->join('temas as tm', 'p.post_tema', '=', 'tm.tema_id')->orderBy('p.post_fec', 'desc')->get();
     return View::make('index', array('post' => $post, 'temas' => $tema, 'cantidadPag' => $cantPagina, 'errores' => $error, 'entradas' => $entradas));
 }
Example #5
1
 public function lists($productId)
 {
     if (IS_AJAX) {
         $page_size = 10;
         $page = I('page', 1, 'intval');
         $start = ($page - 1) * $page_size;
         $map = array('product_id' => $productId, 'status' => 1);
         $ProductBid = M('ProductBid');
         $total_count = $ProductBid->where($map)->count();
         if ($total_count) {
             $total_page = ceil($total_count / $page_size);
             $bid_list = $ProductBid->where($map)->order('bid_id desc')->limit($start . ',' . $page_size)->select();
             $User = M('User');
             foreach ($bid_list as $key => $value) {
                 $bid_list[$key]['user_info'] = $User->find($value['user_id']);
             }
             $this->assign('bid_list', $bid_list);
             $product_info = M('Product')->where($map)->find();
             $this->assign('product_info', $product_info);
             $range_price = $product_info['range_price'];
             $content = $this->fetch('ajaxLists');
             if ($product_info['product_type'] == 3) {
                 $value = array('info' => array('currentPrice' => $product_info['range_price'], 'bidPrice' => $product_info['range_price'], 'lastId' => 1), 'htmlString' => $content, 'isNextPage' => $total_page == 1 || $total_page == $page ? false : true, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => $total_page);
             } else {
                 $max_bid_price = $ProductBid->where($map)->max('bid_price');
                 $value = array('info' => array('currentPrice' => $max_bid_price, 'bidPrice' => $max_bid_price + $range_price, 'lastId' => 1), 'htmlString' => $content, 'isNextPage' => $total_page == 1 || $total_page == $page ? false : true, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => $total_page);
             }
         } else {
             $value = array('htmlString' => '', 'isNextPage' => false, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => 1);
         }
         $this->resultSuccess('加载中...', $value);
     } else {
         //$this->display();
     }
 }
 private function LoadEquipsAndExtraInfo($locale)
 {
     $db = ConnectCharacterDatabase($locale);
     $equipslot = 14;
     $nameslot = 21;
     if ($this->petslot == 2) {
         $equipslot = 30;
         $nameslot = 31;
     } elseif ($this->petslot == 3) {
         $equipslot = 38;
         $nameslot = 39;
     }
     $this->equip = -1;
     $this->nametag = -1;
     $q = $db->query("\r\nSELECT\r\n\tslot, itemid, expires\r\nFROM\r\n\titems\r\nWHERE\r\n\tcharacter_id = " . $this->character_id . "\r\n\tAND\r\n\t(\r\n\t\tslot = " . $equipslot . "\r\n\t\tOR\r\n\t\tslot = " . $nameslot . "\r\n\t\tOR\r\n\t\tcashid = " . $this->cashid . "\r\n\t)");
     while ($row = $q->fetch_row()) {
         if ($row[0] == $equipslot) {
             $this->equip = $row[1];
         } elseif ($row[0] == $nameslot) {
             $this->nametag = $row[1];
         } else {
             $this->expires = ceil($row[2] / 10000000 - 11644473600);
             $this->itemid = $row[1];
         }
     }
 }
Example #7
1
/**
 *  2Moons
 *  Copyright (C) 2012 Jan Kröpke
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package 2Moons
 * @author Jan Kröpke <info@2moons.cc>
 * @copyright 2012 Jan Kröpke <info@2moons.cc>
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
 * @version 1.7.3 (2013-05-19)
 * @info $Id: CreateOnePlanetRecord.php 2640 2013-03-23 19:23:26Z slaver7 $
 * @link http://2moons.cc/
 */
function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName, $HomeWorld = false, $AuthLevel = 0, $Iron, $Gold, $Crystal, $Elyrium, $iPlanetCount)
{
    global $LNG;
    $CONF = Config::getAll(NULL, $Universe);
    if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (Config::get('max_system') < $System || 1 > $System) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (Config::get('max_planets') < $Position || 1 > $Position) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (CheckPlanetIfExist($Galaxy, $System, $Position, $Universe)) {
        return false;
    }
    $tp = 0;
    if ($iPlanetCount >= 3) {
        $tp = 1;
    }
    $FieldFactor = Config::get('planet_factor');
    require 'includes/PlanetData.php';
    $Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData)));
    $TMax = $PlanetData[$Pos]['temp'];
    $TMin = $TMax - 40;
    $Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor');
    $Types = $PlanetData[$Pos]['image'];
    $Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1];
    $GLOBALS['DATABASE']->query("INSERT INTO " . PLANETS . " SET\n\t\t\t\tname = '" . $Name . "',\n\t\t\t\tuniverse = " . $Universe . ",\n\t\t\t\tid_owner = " . $PlanetOwnerID . ",\n\t\t\t\tgalaxy = " . $Galaxy . ",\n\t\t\t\tsystem = " . $System . ",\n\t\t\t\tplanet = " . $Position . ",\n\t\t\t\tlast_update = " . TIMESTAMP . ",\n\t\t\t\tplanet_type = '1',\n\t\t\t\tcolo_metal = " . $Iron . ",\n\t\t\t\tcolo_crystal = " . $Gold . ",\n\t\t\t\tcolo_deut = " . $Crystal . ",\n\t\t\t\tcolo_elyrium = " . $Elyrium . ",\n\t\t\t\tteleport_portal = " . $tp . ",\n\t\t\t\timage = '" . $Types . "',\n\t\t\t\tdiameter = " . floor(1000 * sqrt($Fields)) . ",\n\t\t\t\tfield_max = " . ($HomeWorld ? Config::get('initial_fields') : floor($Fields)) . ",\n\t\t\t\ttemp_min = " . $TMin . ",\n\t\t\t\ttemp_max = " . $TMax . ",\n\t\t\t\tmetal = " . Config::get('metal_start') . ",\n\t\t\t\tmetal_perhour = " . Config::get('metal_basic_income') . ",\n\t\t\t\tcrystal = " . Config::get('crystal_start') . ",\n\t\t\t\tcrystal_perhour = " . Config::get('crystal_basic_income') . ",\n\t\t\t\tdeuterium = " . Config::get('deuterium_start') . ",\n\t\t\t\tdeuterium_perhour = " . Config::get('deuterium_basic_income') . ",\n\t\t\t\telyrium = " . Config::get('deuterium_start') . ",\n\t\t\t\telyrium_perhour = " . Config::get('deuterium_basic_income') . ";");
    return $GLOBALS['DATABASE']->GetInsertID();
}
Example #8
0
 public function run($group_id = false)
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $grid = $this->loadDataGrid('users');
     $users_model = cmsCore::getModel('users');
     $users_model->setPerPage(admin::perpage);
     $filter = array();
     $filter_str = $this->request->get('filter');
     $filter_str = cmsUser::getUPSActual('admin.grid_filter.users', $filter_str);
     if ($filter_str) {
         $content_model = cmsCore::getModel('content')->setTablePrefix('');
         parse_str($filter_str, $filter);
         $users_model->applyGridFilter($grid, $filter);
         if (!empty($filter['advanced_filter'])) {
             parse_str($filter['advanced_filter'], $dataset_filters);
             $users_model->applyDatasetFilters($dataset_filters);
         }
     }
     if ($group_id) {
         $users_model->filterGroup($group_id);
     }
     $total = $users_model->getUsersCount();
     $perpage = isset($filter['perpage']) ? $filter['perpage'] : admin::perpage;
     $pages = ceil($total / $perpage);
     $users = $users_model->getUsers();
     cmsTemplate::getInstance()->renderGridRowsJSON($grid, $users, $total, $pages);
     $this->halt();
 }
Example #9
0
 public function run()
 {
     $page = $this->getInput('page');
     $count = $this->_getPwAnnounceDs()->countAnnounce();
     if (0 < $count) {
         $totalPage = ceil($count / $this->pageNumber);
         $page > $totalPage && ($page = $totalPage);
         list($start, $limit) = Pw::page2limit($page, $this->pageNumber);
         if ($page <= 0) {
             $page = 1;
         }
     }
     $announceInfo = array();
     $announceInfos = $this->_getPwAnnounceDs()->getAnnounceOrderByVieworder($schoolid = '', $limit, $start);
     $announceInfos = $this->_getPwAnnounceService()->formatAnnouncesUsername($announceInfos);
     $openSchools = $this->_getSchoolDS()->getOpenedSchools();
     $this->setOutput($openSchools, 'openSchools');
     foreach ($announceInfos as $akey => &$eachInfo) {
         $found = false;
         foreach ($openSchools as $key => $eachSchool) {
             if ($eachInfo['schoolid'] == $eachSchool['schoolid']) {
                 $eachInfo['schoolName'] = $eachSchool['name'];
                 $found = true;
                 break;
             }
         }
         if ($found == false) {
             $eachInfo['schoolName'] = "所有学校";
         }
     }
     $this->setOutput($announceInfos, 'announceInfos');
     $this->setOutput($count, 'count');
     $this->setOutput($page, 'page');
     $this->setOutput($this->pageNumber, 'perPage');
 }
Example #10
0
 function set($entries, $page, $limit)
 {
     self::$entries = $entries;
     self::$limit = $limit;
     self::$pages = $entries > 0 ? ceil($entries / $limit) : 0;
     self::$page = self::sanitize($page, self::$pages);
 }
Example #11
0
 /**
  * @param $file_name
  * @return array
  * @throws ApplicationException
  */
 public static function generate($file_name)
 {
     set_time_limit(0);
     $temp_file = TempFileProvider::generate("peaks", ".raw");
     $command = sprintf("%s -v quiet -i %s -ac 1 -f u8 -ar 11025 -acodec pcm_u8 %s", self::$ffmpeg_cmd, escapeshellarg($file_name), escapeshellarg($temp_file));
     shell_exec($command);
     if (!file_exists($temp_file)) {
         throw new ApplicationException("Waveform could not be generated!");
     }
     $chunk_size = ceil(filesize($temp_file) / self::PEAKS_RESOLUTION);
     $peaks = withOpenedFile($temp_file, "r", function ($fh) use(&$chunk_size) {
         while ($data = fread($fh, $chunk_size)) {
             $peak = 0;
             $array = str_split($data);
             foreach ($array as $item) {
                 $code = ord($item);
                 if ($code > $peak) {
                     $peak = $code;
                 }
                 if ($code == 255) {
                     break;
                 }
             }
             (yield $peak - 127);
         }
     });
     TempFileProvider::delete($temp_file);
     return $peaks;
 }
 public function execute()
 {
     $this->forceSystemAuthentication();
     myDbHelper::$use_alternative_con = null;
     $partnerId = $this->getRequestParameter("partnerId", null);
     $uiConfId = $this->getRequestParameter("uiConfId", null);
     $page = $this->getRequestParameter("page", 1);
     if ($partnerId !== null && $partnerId !== "") {
         $pageSize = 50;
         $c = new Criteria();
         $c->add(widgetPeer::PARTNER_ID, $partnerId);
         if ($uiConfId) {
             $c->add(widgetPeer::UI_CONF_ID, $uiConfId);
         }
         $c->addDescendingOrderByColumn(widgetPeer::CREATED_AT);
         $total = widgetPeer::doCount($c);
         $lastPage = ceil($total / $pageSize);
         $c->setOffset(($page - 1) * $pageSize);
         $c->setLimit($pageSize);
         $widgets = widgetPeer::doSelect($c);
     } else {
         $total = 0;
         $lastPage = 0;
         $widgets = array();
     }
     $this->uiConfId = $uiConfId;
     $this->page = $page;
     $this->lastPage = $lastPage;
     $this->widgets = $widgets;
     $this->partner = PartnerPeer::retrieveByPK($partnerId);
     $this->partnerId = $partnerId;
 }
Example #13
0
 function pagination($messageParPage, $table, $sscategorie)
 {
     /*
     paginatio_array 0->Nbre d'enregistrements
     paginatio_array 1->Nbre de pages
     paginatio_array 2->Pages actuelle
     paginatio_array 3->Première entrée
     */
     $sscategorie = Utils::anti_injection($sscategorie);
     $pagination_array = array();
     $sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . $table . " WHERE sscat_radio=" . $sscategorie;
     $getTotal = Db::query($sqlQuery);
     $donnees_total = Db::fetch_assoc($getTotal);
     $pagination_array[0] = $donnees_total['total'];
     $pagination_array[1] = ceil($pagination_array[0] / $messageParPage);
     if (isset($_GET['page'])) {
         $pagination_array[2] = intval($_GET['page']);
         if ($pagination_array[2] > $pagination_array[1] && $pagination_array[1] > 0) {
             $pagination_array[2] = $pagination_array[1];
         }
     } else {
         $pagination_array[2] = 1;
     }
     $pagination_array[3] = ($pagination_array[2] - 1) * $messageParPage;
     return $pagination_array;
 }
Example #14
0
function getPagerInfo()
{
    global $mysqli, $table, $page, $limit, $sidx, $sord, $total_pages, $count, $start, $scol, $stext, $columnid, $compcode, $user;
    if (!$sidx) {
        $sidx = $columnid;
    }
    if (isset($_GET['Stext']) && $_GET['Scol'] == 'itemcode') {
        $sql = "SELECT COUNT(*) AS count FROM {$table} \n\t\t\t\tWHERE compcode='{$compcode}' AND \n\t\t\t\t{$_GET['Scol']} LIKE '{$_GET['Stext']}%'";
    } else {
        if (isset($scol) && $stext != '') {
            $sql = "SELECT COUNT(*) AS count FROM {$table} \n\t\t\t\tWHERE compcode='{$compcode}' AND {$_GET['Scol']} \n\t\t\t\tLIKE '%{$_GET['Stext']}%'";
        } else {
            $sql = "SELECT COUNT(*) AS count FROM {$table} WHERE compcode='{$compcode}'";
        }
    }
    $result = $mysqli->query($sql);
    $row = $result->fetch_assoc();
    $count = $row['count'];
    if ($count > 0) {
        $total_pages = ceil($count / $limit);
    } else {
        $total_pages = 0;
    }
    if ($page > $total_pages && $count > 0) {
        $page = $total_pages;
    }
    $start = $limit * $page - $limit;
}
Example #15
0
 /**
  * @Request({"filter": "array", "page":"int"})
  * @Response("extension://page/views/admin/pages/index.razr")
  */
 public function indexAction($filter = null, $page = 0)
 {
     if ($filter) {
         $this['session']->set('page.filter', $filter);
     } else {
         $filter = $this['session']->get('page.filter', []);
     }
     $query = $this->pages->query();
     if (isset($filter['status']) && is_numeric($filter['status'])) {
         $query->where(['status' => intval($filter['status'])]);
     }
     if (isset($filter['search']) && strlen($filter['search'])) {
         $query->where(function ($query) use($filter) {
             $query->orWhere('title LIKE :search', ['search' => "%{$filter['search']}%"]);
         });
     }
     $limit = self::PAGES_PER_PAGE;
     $count = $query->count();
     $total = ceil($count / $limit);
     $page = max(0, min($total - 1, $page));
     $query->offset($page * $limit)->limit($limit)->orderBy('title');
     if ($this['request']->isXmlHttpRequest()) {
         return $this['response']->json(['table' => $this['view']->render('extension://page/views/admin/pages/table.razr', ['count' => $count, 'pages' => $query->get(), 'roles' => $this->roles->findAll()]), 'total' => $total]);
     }
     return ['head.title' => __('Pages'), 'pages' => $query->get(), 'statuses' => Page::getStatuses(), 'filter' => $filter, 'total' => $total, 'count' => $count];
 }
Example #16
0
 /**
  * Список пользователей
  */
 public function index()
 {
     $list = Request::input('list', 'all');
     $login = Request::input('login');
     if (Request::isMethod('post')) {
         $users = User::all(array('select' => 'login', 'order' => 'point DESC, login ASC'));
         foreach ($users as $key => $val) {
             if (strtolower($login) == strtolower($val->login)) {
                 $position = $key + 1;
             }
         }
         if (isset($position)) {
             $page = ceil($position / Setting::get('users_per_page'));
             App::setFlash('success', 'Позиция в рейтинге: ' . $position);
             App::redirect("/users?page={$page}&login={$login}");
         } else {
             App::setFlash('danger', 'Пользователь с данным логином не найден!');
         }
     }
     $count['users'] = $total = User::count();
     $count['admins'] = User::count(['conditions' => ['level in (?)', ['moder', 'admin']]]);
     $condition = [];
     if ($list == 'admins') {
         $total = $count['admins'];
         $condition = ['level IN(?)', ['moder', 'admin']];
     }
     $page = App::paginate(Setting::get('users_per_page'), $total);
     $users = User::all(array('conditions' => $condition, 'offset' => $page['offset'], 'limit' => $page['limit'], 'order' => 'point DESC, login ASC'));
     App::view('users.index', compact('users', 'page', 'count', 'list', 'login'));
 }
Example #17
0
function Zend_Locale_Math_Sub($op1, $op2, $op3 = null)
{
    if (empty($op1)) {
        $op1 = 0;
    }
    $result = $op1 - $op2;
    if ((string) ($result + $op2) != (string) $op1) {
        /**
         * @see Zend_Locale_Math_Exception
         */
        require_once 'Zend/Locale/Math/Exception.php';
        throw new Zend_Locale_Math_Exception("subtraction overflow: {$op1} - {$op2} != {$result}", $op1, $op2, $result);
    }
    if ($op3 != 0) {
        $result = round($result, $op3);
    } else {
        if ($result > 0) {
            $result = floor($result);
        } else {
            $result = ceil($result);
        }
    }
    if ($op3 > 0) {
        if ((string) $result == "0") {
            $result = "0.";
        }
        if (strlen($result) < $op3 + 2) {
            $result = str_pad($result, $op3 + 2, "0", STR_PAD_RIGHT);
        }
    }
    return $result;
}
 function Page($length, $num)
 {
     $this->pageSize = $length;
     //$this->totalPage=$num;
     $page = $_GET['page'];
     if (empty($page) || $page < 1) {
         $page = 1;
     }
     $this->pageNum = ceil($num / $this->pageSize);
     if ($page > $this->pageNum) {
         $page = $this->pageNum;
     }
     $this->curPage = $page;
     if ($this->curPage == 1) {
         $this->lastPage = 1;
     } else {
         $this->lastPage = $this->curPage - 1;
     }
     if ($this->curPage == $this->pageNum) {
         $this->nextPage = $this->pageNum;
     } else {
         $this->nextPage = $this->curPage + 1;
     }
     // echo $this->pageNum;
 }
 public function getPages($count)
 {
     if ($count == 0) {
         return 1;
     }
     return ceil($count / $this->getLimit());
 }
Example #20
0
 public function index()
 {
     $sort = $this->input->get_post('sort', true);
     $desc = $this->input->get_post('desc', true);
     $zd = $this->input->get_post('zd', true);
     $yid = intval($this->input->get_post('yid'));
     $tid = intval($this->input->get_post('tid'));
     $key = $this->input->get_post('key', true);
     $page = intval($this->input->get('page'));
     if ($page == 0) {
         $page = 1;
     }
     $data['page'] = $page;
     $data['sort'] = $sort;
     $data['zd'] = $zd;
     $data['yid'] = $yid;
     $data['key'] = $key;
     $data['tid'] = $tid;
     if (empty($sort)) {
         $sort = "addtime";
     }
     $sql_string = "SELECT id,name,pic,hits,tid,yid,singerid,addtime FROM " . CS_SqlPrefix . "dance_topic where 1=1";
     if ($yid == 1) {
         $sql_string .= " and yid=0";
     }
     if ($yid == 2) {
         $sql_string .= " and yid=1";
     }
     if (!empty($key)) {
         if ($zd == 'user') {
             $uid = getzd('user', 'id', $key, 'name');
             $sql_string .= " and uid='" . intval($uid) . "'";
         } elseif ($zd == 'singer') {
             $singerid = getzd('singer', 'id', $key, 'name');
             $sql_string .= " and singerid='" . intval($singerid) . "'";
         } else {
             $sql_string .= " and " . $zd . " like '%" . $key . "%'";
         }
     }
     if ($tid > 0) {
         $sql_string .= " and tid=" . ($tid - 1) . "";
     }
     $sql_string .= " order by " . $sort . " desc";
     $query = $this->db->query($sql_string);
     $total = $query->num_rows();
     $base_url = site_url('dance/admin/topic') . "?yid=" . $yid . "&key=" . $key . "&sort=" . $sort . "&tid=" . $tid;
     $per_page = 15;
     $totalPages = ceil($total / $per_page);
     // 总页数
     $data['nums'] = $total;
     if ($total < $per_page) {
         $per_page = $total;
     }
     $sql_string .= ' limit ' . $per_page * ($page - 1) . ',' . $per_page;
     $query = $this->db->query($sql_string);
     $data['topic'] = $query->result();
     $data['pages'] = get_admin_page($base_url, $totalPages, $page, 10);
     //获取分页类
     $this->load->view('topic.html', $data);
 }
 /**
  * opening of the session - mandatory arguments won't be needed
  *
  * @param string $savePath
  * @param string $sessionName
  * @return bool
  */
 public function open($savePath, $sessionName)
 {
     if (!isset($this->_lifeTime)) {
         $this->_lifeTime = intval(ini_get("session.gc_maxlifetime"));
     }
     if (!isset($this->_refreshTime)) {
         $this->_refreshTime = ceil($this->_lifeTime / 3);
     }
     $this->_initSessionData = null;
     $this->_memcache = new Memcache();
     if (Kwf_Config::getValue('aws.simpleCacheCluster')) {
         $servers = Kwf_Util_Aws_ElastiCache_CacheClusterEndpoints::getCached(Kwf_Config::getValue('aws.simpleCacheCluster'));
     } else {
         if (Kwf_Cache_Simple::$memcacheHost) {
             $servers = array(array('host' => Kwf_Cache_Simple::$memcacheHost, 'port' => Kwf_Cache_Simple::$memcachePort));
         } else {
             throw new Kwf_Exception("no memcache configured");
         }
     }
     foreach ($servers as $s) {
         if (version_compare(phpversion('memcache'), '2.1.0') == -1 || phpversion('memcache') == '2.2.4') {
             // < 2.1.0
             $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
         } else {
             if (version_compare(phpversion('memcache'), '3.0.0') == -1) {
                 // < 3.0.0
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1, true, null, 10000);
             } else {
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
             }
         }
     }
     return true;
 }
Example #22
0
 function JieqiPage($total, $onepage, $page = 1, $num = 10, $pagevar = 'page', $pageajax = 0)
 {
     $this->total =& $total;
     $this->onepage =& $onepage;
     $this->total_page = @ceil($total / $onepage);
     if (defined('JIEQI_MAX_PAGES') && JIEQI_MAX_PAGES > 0 && $this->total_page > JIEQI_MAX_PAGES) {
         $this->total_page = intval(JIEQI_MAX_PAGES);
     }
     if ($this->total_page <= 1) {
         $this->total_page = 1;
     }
     $this->page =& $page;
     $this->num =& $num;
     $this->pagevar = $pagevar;
     if (substr($pagevar, 0, 1) == '.') {
         $this->usefake = 1;
     } else {
         $this->usefake = 0;
     }
     if ($pageajax > 0 || defined('JIEQI_AJAX_PAGE') && JIEQI_AJAX_PAGE > 0) {
         $this->useajax = 1;
     } else {
         $this->useajax = 0;
     }
     $this->linkhead = jieqi_addurlvars(array($this->pagevar => ''), true, false);
 }
Example #23
0
 /**
  * get the number of offsets needed to build a complete pager
  * @return int
  */
 function get_offset_count()
 {
     if (!$this->offsetCount) {
         $this->offsetCount = ceil($this->get_total_item_count() / $this->step);
     }
     return $this->offsetCount;
 }
Example #24
0
 public function index()
 {
     $view = new Admin_View("admin.html");
     $view->page_title = t("Users and groups");
     $view->page_type = "collection";
     $view->page_subtype = "admin_users";
     $view->content = new View("admin_users.html");
     // @todo: add this as a config option
     $page_size = module::get_var("user", "page_size", 10);
     $page = Input::instance()->get("page", "1");
     $builder = db::build();
     $user_count = $builder->from("users")->count_records();
     // Pagination info
     $view->page = $page;
     $view->page_size = $page_size;
     $view->children_count = $user_count;
     $view->max_pages = ceil($view->children_count / $view->page_size);
     $view->content->pager = new Pagination();
     $view->content->pager->initialize(array("query_string" => "page", "total_items" => $user_count, "items_per_page" => $page_size, "style" => "classic"));
     // Make sure that the page references a valid offset
     if ($page < 1) {
         url::redirect(url::merge(array("page" => 1)));
     } else {
         if ($page > $view->content->pager->total_pages) {
             url::redirect(url::merge(array("page" => $view->content->pager->total_pages)));
         }
     }
     // Join our users against the items table so that we can get a count of their items
     // in the same query.
     $view->content->users = ORM::factory("user")->order_by("users.name", "ASC")->find_all($page_size, $view->content->pager->sql_offset);
     $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all();
     print $view;
 }
Example #25
0
function MG_selectUsers($page)
{
    global $glversion, $_CONF, $_MG_CONF, $_TABLES, $_USER, $LANG_MG00, $LANG_MG01;
    $retval = '';
    $T = new Template($_MG_CONF['template_path']);
    $T->set_file('admin', 'createmembers.thtml');
    $T->set_var(array('site_admin_url' => $_CONF['site_admin_url'], 'site_url' => $_CONF['site_url'], 'xhtml' => XHTML));
    $T->set_block('admin', 'UserRow', 'uRow');
    $start = $page * 50;
    $end = 50;
    $sql = "SELECT COUNT(gl.uid) AS count " . "FROM {$_TABLES['users']} AS gl " . "LEFT JOIN {$_TABLES['mg_userprefs']} AS mg ON gl.uid=mg.uid " . "WHERE gl.status = 3 AND gl.uid > 2 AND (mg.member_gallery IS NULL OR mg.member_gallery < 1)";
    $result = DB_query($sql);
    list($total_records) = DB_fetchArray($result);
    $sql = "SELECT gl.uid, gl.status, gl.username, gl.fullname, mg.member_gallery " . "FROM {$_TABLES['users']} AS gl " . "LEFT JOIN {$_TABLES['mg_userprefs']} AS mg ON gl.uid=mg.uid " . "WHERE gl.status = 3 AND gl.uid > 2 AND (mg.member_gallery IS NULL OR mg.member_gallery < 1) " . "ORDER BY gl.username ASC LIMIT {$start},{$end}";
    $result = DB_query($sql);
    while ($row = DB_fetchArray($result)) {
        if ($glversion[1] < 4) {
            $row['status'] = 3;
        }
        $uid = $row['uid'];
        $remote = SEC_inGroup("Remote Users", $uid) ? '(r)' : '';
        $username = $row['username'];
        $member_gallery = $row['member_gallery'];
        $T->set_var(array('uid' => $uid, 'username' => $username . ' ' . $remote . ' - ' . $row['fullname'], 'select' => '<input type="checkbox" name="user[]" value="' . $uid . '"' . XHTML . '>'));
        $T->parse('uRow', 'UserRow', true);
    }
    $T->set_var(array('lang_userid' => $LANG_MG01['userid'], 'lang_username' => $LANG_MG01['username'], 'lang_select' => $LANG_MG01['select'], 'lang_checkall' => $LANG_MG01['check_all'], 'lang_uncheckall' => $LANG_MG01['uncheck_all'], 'lang_save' => $LANG_MG01['save'], 'lang_cancel' => $LANG_MG01['cancel'], 'lang_reset' => $LANG_MG01['reset'], 's_form_action' => $_MG_CONF['admin_url'] . 'createmembers.php', 'pagenav' => COM_printPageNavigation($_MG_CONF['admin_url'] . 'createmembers.php', $page + 1, ceil($total_records / 50))));
    $retval .= $T->finish($T->parse('output', 'admin'));
    return $retval;
}
Example #26
0
 public function sysmsg($re = false)
 {
     $map['uid'] = $this->uid;
     //分页处理
     import("ORG.Util.Page");
     $count = M('inner_msg')->where($map)->count('id');
     $p = new Page($count, 15);
     $page = $p->show();
     $Lsql = "{$p->firstRow},{$p->listRows}";
     //分页处理
     $list = M('inner_msg')->where($map)->order('id DESC')->limit($Lsql)->select();
     $read = M("inner_msg")->where("uid={$this->uid} AND status=1")->count('id');
     $this->assign("list", $list);
     $this->assign("pagebar", $page);
     $this->assign("read", $read);
     $this->assign("unread", $count - $read);
     $this->assign("count", $count);
     if (true === $re) {
         $dpage = array();
         $dpage['numpage'] = $count ? ceil($count / 15) : 1;
         $dpage['curpage'] = (int) $_GET['p'] ? (int) $_GET['p'] : 1;
         $this->assign("dpage", $dpage);
         return $list;
     }
     $data['html'] = $this->fetch();
     exit(json_encode($data));
 }
 /**
  * Set up the columns, dataset, paginator
  * @return void
  */
 public function prepare_items()
 {
     // Set up columns
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Perform bulk actions
     $this->do_bulk_action();
     $data = $this->_get_profiles();
     // Sort data
     $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name';
     $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'asc';
     $data = $this->_sort($data, $orderby, $order);
     // 20 items per page
     $per_page = 20;
     // Get page number
     $current_page = $this->get_pagenum();
     // Get total items
     $total_items = count($data);
     // Carve out only the visible dataset
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $data;
     // Set up the paginator
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
 function do_paging()
 {
     if ($this->total_users_for_query > $this->users_per_page) {
         // have to page the results
         $this->paging_text = paginate_links(array('total' => ceil($this->total_users_for_query / $this->users_per_page), 'current' => $this->page, 'prev_text' => '&laquo; Previous Page', 'next_text' => 'Next Page &raquo;', 'base' => 'users.php?%_%', 'format' => 'userspage=%#%', 'add_args' => array('usersearch' => urlencode($this->search_term))));
     }
 }
 public function getPosition($from = 1, $count = 1)
 {
     $console = Console::getInstance();
     $console->operationStart('Collecting search results');
     $this->pageNumber = ceil($from / $this->positionsPerPage);
     if ($count < 1 || $count > 10) {
         $console->operationEnd();
         $console - error('Count must be in 1-10. ' . $count . ' is setted');
         return false;
     }
     $sites = array();
     $position = 1;
     do {
         $console->operationStep();
         $pageResults = $this->getPageResults();
         foreach ($pageResults as $pr) {
             $sitesCount = count($sites);
             $domain = ($domain = String::rebuildUrl($pr->url, false, false, true, false)) ? $domain : $pr->url;
             if (IgnoreList::isInList($domain) || $sitesCount && $sites[$sitesCount - 1]->domain == $domain) {
                 continue;
             }
             $site = new Site();
             $site->name = strip_tags($pr->title);
             $site->position = $position++;
             $site->link = $pr->url;
             $site->domain = $domain;
             $sites[] = $site;
         }
         $this->pageNumber++;
     } while ($sitesCount < $count);
     //$this->pageNumber++ * $this->positionsPerPage < $count // old
     $console->operationEnd();
     return array_slice($sites, 0, $count);
 }
Example #30
0
 function do_main()
 {
     $notifications = (array) KTNotification::getList(array("user_id = ?", $this->oUser->getId()));
     $num_notifications = count($notifications);
     $PAGE_SIZE = 5;
     $page = (int) KTUtil::arrayGet($_REQUEST, 'page', 0);
     $page_count = ceil($num_notifications / $PAGE_SIZE);
     if ($page >= $page_count) {
         $page = $page_count - 1;
     }
     if ($page < 0) {
         $page = 0;
     }
     // slice the notification array.
     $notifications = array_slice($notifications, $page * $PAGE_SIZE, $PAGE_SIZE);
     // prepare the batch html.  easier to do this here than in the template.
     $batch = array();
     for ($i = 0; $i < $page_count; $i++) {
         if ($i == $page) {
             $batch[] = sprintf("<strong>%d</strong>", $i + 1);
         } else {
             $batch[] = sprintf('<a href="%s">%d</a>', KTUtil::addQueryStringSelf($this->meldPersistQuery(array("page" => $i), "main", true)), $i + 1);
         }
     }
     $batch_html = implode(' &middot; ', $batch);
     $count_string = sprintf(_kt("Showing Notifications %d - %d of %d"), $page * $PAGE_SIZE + 1, min(($page + 1) * $PAGE_SIZE, $num_notifications), $num_notifications);
     $this->oPage->setTitle(_kt("Items that require your attention"));
     $oTemplate =& $this->oValidator->validateTemplate("ktcore/misc/notification_overflow");
     $oTemplate->setData(array('count_string' => $count_string, 'batch_html' => $batch_html, 'notifications' => $notifications));
     return $oTemplate->render();
 }