protected function CreatePageNavigator() { $result = new CompositePageNavigator($this); $partitionNavigator = new PageNavigator('pnav', $this, $this->dataset); $partitionNavigator->SetRowsPerPage(20); $result->AddPageNavigator($partitionNavigator); return $result; }
protected function CreatePageNavigator() { $result = new CompositePageNavigator($this); $partitionNavigator = new CustomPageNavigator('partition', $this, $this->dataset, $this->RenderText('Department'), $result); $partitionNavigator->OnGetPartitionCondition->AddListener('partition' . '_GetPartitionConditionHandler', $this); $partitionNavigator->OnGetPartitions->AddListener('partition' . '_GetPartitionsHandler', $this); $partitionNavigator->SetAllowViewAllRecords(true); $partitionNavigator->SetNavigationStyle(NS_LIST); $result->AddPageNavigator($partitionNavigator); $partitionNavigator = new PageNavigator('pnav', $this, $this->dataset); $partitionNavigator->SetRowsPerPage(20); $result->AddPageNavigator($partitionNavigator); return $result; }
/** * HTML Grid */ public function grid($per_page, $action, $ex_params = NULL, $where = NULL, $table_attributes = ' class="table_list"') { $this->per_page = $per_page; if (!empty($where)) { $this->where = $where; } if ($this->offset > 0) { $this->recordoffset = $this->offset * $per_page; } $text = ' <table ' . $table_attributes . '> <tr> '; if ($this->edit && $this->delete) { $text .= ' <th style="width:80px;"> </th>'; } elseif ($this->edit || $this->delete) { $text .= ' <th style="width:25px;"> </th>'; } foreach ($this->column_names as $name => $field) { $text .= ' <th>' . $name . ' <a href="?order_by=' . $field . '&order=' . $this->get_vars[$field]['order'] . '&offset=' . $this->offset . '&action=' . $action . $ex_params . '"><img src="' . $this->get_vars[$field]['img'] . '" alt="-Order-" border="none"></a></th>'; } $text .= ' </tr>'; $sql = $this->make_sql(); /*if( !empty($this->base_sql) ){ $sql = $this->base_sql." ".(!empty($this->where) ? " WHERE ".$this->where : '' )." ORDER BY ".$this->order_by." ".$this->order." LIMIT ".$this->recordoffset.", ".$per_page."; "; } else { $sql = "SELECT * FROM ".$this->table." ".(!empty($this->where) ? " WHERE ".$this->where : '' )." ORDER BY ".$this->order_by." ".$this->order." LIMIT ".$this->recordoffset.", ".$per_page."; "; }*/ //echo '<pre>'.$sql.'</pre>'; //get recordset $rs = $this->sql_con->createResultSet($sql, $this->db); // returns mysql_fetch_array foreach ($rs as $row) { $text .= ' <tr>'; if ($this->edit || $this->delete) { $text .= '<td>'; if ($this->edit) { //|| ($edit_person && $user->person_id() == $row['person_id']) ){ $text .= '<a href="?action=' . $action . '&command=3&' . $this->pri . '=' . $row[$this->pri] . '&order_by=' . $this->order_by . '&order=' . $this->order . $ex_params . '" title="Edit record"><img src="' . ADMIN_IMAGES_DIR . 'edit.png" alt="Edit" border="0"></a> '; } if ($this->edit && $this->delete) { $text .= ' | '; } if ($this->delete) { $text .= '<a href="?action=' . $action . '&command=4&' . $this->pri . '=' . $row[$this->pri] . '&order_by=' . $this->order_by . '&order=' . $this->order . $ex_params . '" title="Delete record"><img src="' . ADMIN_IMAGES_DIR . 'delete.png" alt="Delete Record" border="0"></a> '; } $text .= '</td>'; } foreach ($this->column_names as $name => $field) { if ($field == 'email') { $text .= ' <td><a href="mailto:' . $row['email'] . '">' . $row['email'] . '</a></td>'; } elseif (!empty($this->column_filters[$field])) { // set filters switch ($this->column_filters[$field]['filter']) { case 'array': $tmp = ''; if (isset($this->column_filters[$field]['array'][$row[$field]])) { $tmp = $this->column_filters[$field]['array'][$row[$field]]; } $text .= ' <td>' . $tmp . '</td>'; break; case 'custom': $replace = array(); foreach ($this->column_filters[$field]['replace'] as $r) { $replace[] = $row[$r]; } $empty = false; if (isset($this->column_filters[$field]['empty_row'])) { foreach ($this->column_filters[$field]['empty_row'] as $k => $v) { //echo ' K: '.$k.' => '.$v.' CID: '.$row[$k]; if ($row[$k] == $v) { $empty = true; } } } if ($empty) { $text .= ' <td></td>'; } else { $text .= ' <td>' . str_replace($this->column_filters[$field]['search'], $replace, $this->column_filters[$field]['str']) . '</td>'; } break; case 'date': $text .= ' <td>' . date($this->column_filters[$field]['format'], strtotime($row[$field])) . '</td>'; break; case 'money': $text .= ' <td>$' . number_format($row[$field], 2) . '</td>'; break; } } else { $text .= ' <td>' . (isset($row[$field]) ? $row[$field] : '') . '</td>'; } } $text .= ' </tr>'; } $text .= ' </table> '; $pagename = ''; //basename($_SERVER['PHP_SELF']); //find total number of records $totalrecords = $rs->getUnlimitedNumberRows(); $numpages = ceil($totalrecords / $per_page); //create category parameter $otherparameter = "&action=" . $action . '&perpage=' . $per_page . '&order_by=' . $this->order_by . '&order=' . $this->order . $ex_params; //create if needed if ($numpages > 1) { //create navigator $nav = new PageNavigator($pagename, $totalrecords, $per_page, $this->recordoffset, 10, $otherparameter); $text .= $nav->getNavigator(); } return $text; }
} .nav a.prev:hover, .nav a.next:hover{ color: #9cc; } h2{ margin-top: 2em; } </style> </head> <body> <h2>基本</h2> <?php require_once 'pagenavigator.php'; $nav1 = new PageNavigator(); $nav2 = new PageNavigator(array('linkHelper' => 'list.html?page={{page}}&from={{current}}&max={{max}}', 'prevText' => '←', 'nextText' => '→', 'moreText' => '……', 'size' => 9)); $nav3 = new PageNavigator(array('numberHelper' => '<button href="{{link}}" class="item number" data-page="{{page}}">{{page}}</button>', 'currentHelper' => '<button class="item number current" data-page="{{page}}" disabled="disabled">{{page}}</button>')); ?> <div class="nav"><?php echo $nav1->create(1, 5); ?> </div> <div class="nav"><?php echo $nav1->create(2, 5); ?> </div> <div class="nav"><?php echo $nav1->create(5, 5); ?> </div> <div class="nav"><?php echo $nav1->create(1, 6);
function presentacion_noticias() { ?> <div class="grid_12" id="Principal"> <?php define("PERPAGE", 10); define("OFFSET", "offset"); //get query string $offset = @$_GET[OFFSET]; //check variable if (!isset($offset)) { $recordoffset = 0; } else { //calc record offset $recordoffset = $offset * PERPAGE; } $q = "SELECT * FROM Noticias order by Fecha LiMIT {$recordoffset}, " . PERPAGE; $c = "SELECT * FROM Noticias order by Fecha"; $r = mysql_query($q); if (mysql_num_rows($r) > 0) { //table is non-empty while ($row = mysql_fetch_assoc($r)) { $net_vote = $row['votos']; //this is the net result of voting up and voting down ?> <div id="noticia_individual"> <a href="inicio.php"><img src="grayarrow.gif" alt="" ></a> <a id="titulo" href="<?php echo $row['link_noticia']; ?> "> <?php echo $row['titulo']; ?> </a><br> <a id="url" href="<?php echo $row['link_noticia']; ?> " >(<?php echo $row['link_noticia']; ?> )</a> <div id="resto_noticia"> <p id="fecha">Enviado el: <?php $fecha = date('d/m/Y', strtotime($row['Fecha'])); echo $fecha; ?> </p> <p id="descripcion"> <?php echo $row['descripcion']; ?> </p> <br> </div><br> <div id="footer_noticia"> <p class="votos"> <?php echo $row['votos']; ?> Puntos |</p> <p class="votos">Categoria: <?php echo $row['categoria']; ?> |</p> <p class="votos"><a id="comentario" href="http://localhost/TestSitioWeb/Comentarios_noticia.php?id_not=<?php echo $row['id_noticia']; ?> " >Ver Comentarios </a></p> </div> <br> </div> <br> <hr /> <?php } } $pagename = basename($_SERVER['PHP_SELF']); //find total number of records $prueba = mysql_query($c); $totalrecords = mysql_num_rows($prueba); $numpages = ceil($totalrecords / PERPAGE); //create category parameter //create if needed if ($numpages > 1) { //create navigator $nav = new PageNavigator($pagename, $totalrecords, PERPAGE, $recordoffset); echo $nav->getNavigator(); } ?> </div> <?php }
function presentacion_noticias($consulta) { ?> <div class="grid_8" id="Principal"> <?php define("PERPAGE", 10); define("OFFSET", "offset"); //get query string $offset = @$_GET[OFFSET]; //check variable if (!isset($offset)) { $recordoffset = 0; } else { //calc record offset $recordoffset = $offset * PERPAGE; } $q = $consulta . " LiMIT {$recordoffset}, " . PERPAGE; $c = "SELECT * FROM Noticias"; $r = mysql_query($q); if (mysql_num_rows($r) > 0) { //table is non-empty while ($row = mysql_fetch_assoc($r)) { $net_vote = $row['votos']; //this is the net result of voting up and voting down ?> <div id="noticia_individual"> <!-- <a href="index.php"><img src="grayarrow.gif" alt="" ></a> Asi funciona --> <?php if (substr($row['link_noticia'], -3) == "jpg" || substr($row['link_noticia'], -3) == "gif") { ?> <div id="imagen"> <img id="imagen_noticia" src="<?php echo $row['link_noticia']; ?> " alt="" > </div> <div id="div_titulo_imagen"> <a id="titulo" href="<?php echo $row['link_noticia']; ?> "> <?php echo $row['titulo']; ?> </a><br> </div> <div id="div_link_imagen"> <a id="url" href="<?php echo $row['link_noticia']; ?> " >(<?php echo $row['link_noticia']; ?> )</a> </div> <?php } else { ?> <div id="div_titulo"> <a id="titulo" href="<?php echo $row['link_noticia']; ?> "> <?php echo $row['titulo']; ?> </a><br> </div> <div id="div_link"> <a id="url" href="<?php echo $row['link_noticia']; ?> " >(<?php echo $row['link_noticia']; ?> )</a> </div> <?php } ?> <div id="resto_noticia"> <p id="fecha">Enviado hace <?php $fecha = strtotime($row['Fecha']); echo tiempo_transcurrido($fecha) . " por "; ?> <a href="" ><?php echo $row['id_usuario']; ?> </a> </p> <!-- <div id="imagen_categoria"><img src="<?php echo 'imagenesCategorias/' . $row['imagen_categoria']; ?> " id="imagen_noticia" alt="" ></div> <p id="descripcion"> <?php echo $row['descripcion']; ?> </p> --> <br> </div> <div id="footer_noticia"> <!-- <p class="votos"> <?php echo $row['votos']; ?> Puntos |</p> --> <p class="votos">Categoria: <?php echo $row['categoria']; ?> |</p> <p class="votos"><a id="comentario" href="Comentarios_noticia.php?id_not=<?php echo $row['id_noticia']; ?> " >Comentarios | </a></p> <p class='votes_count' id='votes_count<?php echo $row['id_noticia']; ?> '><?php echo $row['votos'] . " votos | "; ?> </p> <?php if (isset($_SESSION['valid_user'])) { $consulta_votos = "Select 1 from voto where id_noticia =" . $row['id_noticia'] . " and usuario ='" . $_SESSION['valid_user'] . "'"; $f = mysql_query($consulta_votos); if (mysql_num_rows($f) == 0) { ?> <div> <span class='vote_buttons' id='vote_buttons<?php echo $row['id_noticia']; ?> '> <a href='javascript:;' class='vote_up' id='<?php echo $row['id_noticia']; ?> '>me gusta</a> </span> <span class='vote_buttons' id='vote_buttons<?php echo $row['id_noticia']; ?> '> <a href='javascript:;' class='vote_down' id='<?php echo $row['id_noticia']; ?> '>no me gusta</a> </span> </div> <?php } } ?> </div> <div class="clear"></div> </div> <br> <hr /> <?php } } $pagename = basename($_SERVER['PHP_SELF']); //find total number of records $prueba = mysql_query($c); $totalrecords = mysql_num_rows($prueba); $numpages = ceil($totalrecords / PERPAGE); //create category parameter //create if needed if ($numpages > 1) { //create navigator $nav = new PageNavigator($pagename, $totalrecords, PERPAGE, $recordoffset); echo $nav->getNavigator(); } ?> </div> </div> <?php }
public function index() { /*////////////////////////////////////////////////////////////////////////// // Aquire Search Results (read local XML file). */ if (isset($_POST['searchtext'])) { $srchtext = filter_var($_POST['searchtext'], FILTER_SANITIZE_STRING); } elseif (isset($_GET['q'])) { $srchtext = urldecode($_GET['q']); } else { $srchtext = ''; } $result_xml = __SITE_PATH . "/sample_search_result.xml"; if (file_exists($result_xml)) { $xml = simplexml_load_file($result_xml); } else { exit('Failed to load ' . $result_xml); } /*////////////////////////////////////////////////////////////////////////// // Format Search Results (based on sample image). */ $results = array(); foreach ($xml->SearchResult as $result) { $url = (string) $result->Url; $rank1m = (int) $result->Rank1M; $retail = (string) $result->Retailness == 'true' ? 'Yes' : 'No'; $adult = ucfirst((string) $result->Adult); $category = (string) $result->Category; $category == '-' ? $category = 'Unspecified' : $category; $category = str_replace(' ', ': ', $category); $category = str_replace('-', ' > ', $category); $category = str_replace('_', ' ', $category); $domain = substr($url, 0, strpos($url, '.')); //parse for domain(no extensions) $results[] = array('url' => $url, 'rank1m' => $rank1m, 'retail' => $retail, 'adult' => $adult, 'domain' => $domain, 'category' => $category); } /*////////////////////////////////////////////////////////////////////////// // Sort Search Results */ /* Default sort by Rank1M. */ $results = $this->orderBy($results, 'rank1m'); /* Check for Url match and move to top of displayed result. */ $srchtext_arr = explode(" ", $srchtext); $key = null; $dontmatch = array('Yes', 'No'); foreach ($srchtext_arr as $text) { if ($text && !in_array($text, $dontmatch)) { //exclude empty string && $dontmatch /* also check for domain w/o extensions */ if (!is_int($key) && is_int(strpos($text, '.'))) { $key = $this->recursiveArraySearch($results, substr($text, 0, strpos($text, '.'))); } else { $key = $this->recursiveArraySearch($results, $text); } if (is_int($key)) { //move to 1st position $value = $results[$key]; unset($results[$key]); $tail = array_splice($results, 0); array_push($results, $value); $results = array_merge($results, $tail); $key = null; } } } /*////////////////////////////////////////////////////////////////////////// // Create PageNavigotor */ /* $this->registry->action is 2nd URL parameter and will default to 'index if not specified.*/ //$offset = $this->registry->action == 'index' ? 0 : $this->registry->action; $offset = isset($_GET['p']) ? (int) $_GET['p'] : 0; $pagename = __SITE_ROOT . 'results'; $totaloffset = $offset * PERPAGE; $totalcount = 10; // As provided by Alexa $numpages = ceil($totalcount / PERPAGE); $maxpagesshown = PAGELINKS; $params = 'q=' . urlencode($srchtext); $pagenav = ''; if ($numpages > 1) { $nav = new PageNavigator($pagename, $totalcount, PERPAGE, $totaloffset, $maxpagesshown, $params); $pagenav = $nav->getNavigator(); } else { $pagenav = 'Page 1 of 1'; } /*////////////////////////////////////////////////////////////////////////// // Presentation Logic. */ /*** Alias view templates. */ $views = $this->registry->template; /* debug */ $views->srchtext_arr = $srchtext_arr; //debug $views->srchtext = $srchtext; //debug $views->offset = $offset; //debug $views->msg = $this->registry->controller . ':' . $this->registry->action; //debug $views->key = $key; //debug $views->results = array_slice($results, PERPAGE * $offset, PERPAGE); $views->pagenav = $pagenav; $views->layout = 'basic'; $views->pgtitle = 'Alexa Code Sample'; $views->withresults = $this->registry->controller == 'results'; $views->show('home'); }