ClaveAudio_Web/_incl/code.php
2011-05-06 11:33:27 +00:00

217 lines
5.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
function in_istr ($hay, $needle) {
return strpos( strtolower($hay), strtolower($needle) );
}
function Proper($string) {
$words = split(" ", $string);
$newwords = array();
foreach ($words as $word) {
$word = ucfirst($word);
array_push($newwords, $word);
}
return join(" ", $newwords);
}
function saveFile($filepath, $content) {
$out = fopen($filepath, "w");
fwrite($out, $content);
fclose($out);
}
function numArray2Select($etiquetas, $valor, $cardinalidad = 1){
$select = '';
$i = $cardinalidad;
foreach($etiquetas as $item){
$select .= '<option value="' . $i . '"';
if($i == $valor) {
$select .= ' selected';
}
$select .= '>' . $item . '</option>' . "\r";
$i ++;
}
return $select;
}
function array2Select($etiquetas, $valor=''){
$select = '';
foreach($etiquetas as $item){
$select .= '<option value="' . $item . '"';
if($item == $valor) {
$select .= ' selected';
}
$select .= '>' . ucwords($item) . '</option>' . "\r";
}
return $select;
}
function array2Control($etiquetas, $nombre, $clase, $tipo, $valores=''){
$i = 0;
if($tipo == 'checkbox' && strlen($valores)) {
// paso la cadena de valores a una matriz
$checkArray = explode(', ', $valores);
}
// esto est‡ mal: estoy mezclando el c—digo con el interfaz...
$select = '<table border="0" cellpadding="1" cellspacing="1"><tr valign="top">';
foreach($etiquetas as $item){
if($i >= 5){
$select .= '</tr><tr>';
$i = 0;
}
// aqu comparo el valor correspondiente a esta etiqueta
$checked = '';
if(strlen($valores)){
switch($tipo){
case 'radio':
if($item == $valores) {
$checked .= ' checked';
}
break;
case 'checkbox':
if(in_array($item, $checkArray)) {
$checked = ' checked';
}
break;
}
}
// y aqu "dibujo" el objeto, con etiqueta y valor si lo hubiera.
$select .= '<td valign="top"><label class="' . $clase . '"><input type="' . $tipo . '" name="' . $nombre . ($tipo=='checkbox' ? '[]' : '') . '" id="' . $nombre . ($tipo=='checkbox' ? '[]' : '') . '" value="' . $item .'"' . $checked . '>' . $item . '</label></td>';
$i ++;
}
$select .= '</tr></table>';
return $select;
}
function miNumberFormat($cantidad) {
$resultado = number_format($cantidad, 2, ',', '.');
if(substr($resultado, strlen($resultado) - 2, 2) == '00') {
$resultado = substr($resultado, 0, strlen($resultado) - 3);
}
return($resultado);
}
function componProducto($string, $seccion){
$palabras = explode(" ", $string);
$output = '';
foreach($palabras as $palabra) {
$final = substr($palabra, strlen($palabra) - 2, 2);
if($final == 'as' || $final == 'os' &&
// OJO: EXCEPCIONES
$palabra != 'giradiscos' &&
$palabra != 'conos') {
$palabra = substr($palabra, 0, strlen($palabra) - 1);
}
if($final == 'es') {
$consonante = substr($palabra, strlen($palabra) - 3, 1);
$vocal = substr($palabra, strlen($palabra) - 4, 1);
if(($consonante == 'l' && $vocal != 'a') || $consonante == 's' || $consonante == 't') {
$palabra = substr($palabra, 0, strlen($palabra) - 1);
} else {
$palabra = substr($palabra, 0, strlen($palabra) - 2);
}
}
// OJO: EXCEPCIONES
if($palabra == 'Subwoofers'){
$palabra = 'Subwoofer';
}
$output .= $palabra . " ";
}
// OJO: EXCEPCIONES
if($seccion == 'AL') {
$cadena = substr($output, 0, 3);
switch($cadena){
case 'Pac':
case 'Sub':
break;
case 'Cen':
$output = 'Altavoz ' . $output;
break;
default:
$output = 'Altavoz de ' . $output;
break;
}
}
return ($output);
}
function resume($string, $length = 50, $ellipsis = "...")
{
$paragraph = explode(" ", $string);
if($length < count($paragraph))
{
for($i = 0; $i < $length; $i++)
{
if($i < $length - 1)
$output .= $paragraph[$i] . " ";
else
$output .= $paragraph[$i] . $ellipsis;
}
return $output;
}
return $string;
}
// a pretty pretty generic function para to draw un paginator
//
// params: $numRecords = el total de numHits de una busqueda
// $start = el primero registro que muestro (0 o multiplo de $limit)
// $limit = numero de registros por pagino
// $estilo = el estilo que se aplica a una pagina activa
//
//
function drawPaginator($numRecords, $start, $limit, $estilo) {
$paginator = '';
$numPages = round($numRecords / $limit) + ($numRecords % $limit ? 1 : 0);
$curPage = ($start == 0 ? 1 : round($start / $limit) + 1);
if($curPage > 5 && $numPages > 10) {
$firstPage = $curPage - 5;
if($firstPage > $numPages - 10) {
$firstPage = $numPages - 10;
}
} else {
$firstPage = 0;
}
if($start) {
$paginator .= '<a href="' . $_SERVER['PHP_SELF'] . '?start=' . ($start - $limit) . '" class="'. $estilo . '">';
$paginator .= '<';
$paginator .= '</a>';
}
$paginator .= '&nbsp;';
for($i = 1; $i <= min(10, $numPages); $i++){
$drawPage = $firstPage + $i;
if($curPage != $drawPage) {
$paginator .= '<a href="' . $_SERVER['PHP_SELF'] . '?start=' . ($drawPage - 1) * $limit . '" class="'. $estilo . '">';
} else {
$paginator .= '<b>';
}
$paginator .= $drawPage;
if($curPage != $drawPage) {
$paginator .= '</a>';
} else {
$paginator .= '</b>';
}
$paginator .= '&nbsp;';
}
if($start + $limit < $numRecords){
$paginator .= '<a href="' . $_SERVER['PHP_SELF'] . '?start=' . ($start + $limit) . '" class="'. $estilo . '">';
$paginator .= '>';
$paginator .= '</a>';
}
return $paginator;
}
?>