<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of general
 *
 * @author Carolina
 */
class general {

    //put your code here

    public function __construct() {
        
    }

    function getDocNextCode($type_doc) {
        $sql = "select if(((max(substr( documents.id,4,7)) + 1) > 0),concat(upper('$type_doc'),lpad((max(substr( documents.id,4,7)) + 1),7,_utf8'0')),concat(upper('$type_doc'),lpad((count(substr( documents.id,4,7)) + 1),7,_utf8'0'))) AS new_req_code from documents where documents.doc_id = '$type_doc'";
        return $sql;
    }

    static function format_numbers($number, $decimal) {
        return number_format($number, $decimal, ',', '.');
    }

    function display_msg($type, $text) {
        switch ($type) {
            case "warning":
                $class = "ui-state-highlight";
                $title = "Advertencia";
                $icon = "ui-icon-info";
                break;
            case "error":
                $class = "ui-state-error";
                $title = "Error";
                $icon = "ui-icon-alert";
                break;

            default:
                break;
        }
        $html = '<div class="ui-widget"><div style="margin-top: 20px; padding: 0 .7em;" class="' . $class . ' ui-corner-all">
				<p><span style="float: left; margin-right: .3em;" class="ui-icon ' . $icon . '"></span>
				<strong>' . $title . '!</strong> ' . $text . '</p>
			</div></div>';
        echo $html;
    }

    function display_msg_menu() {
        $class = "ui-state-highlight";
        $title = "Info";
        $icon = "ui-icon-info";
        $text = "Para más opciones presione el boton secundario del raton sobre los items";
        $html = '<div class="ui-widget"><div style="margin-top: 20px; padding: 0 .7em;" class="' . $class . ' ui-corner-all">
				<p><span style="float: left; margin-right: .3em;" class="ui-icon ' . $icon . '"></span>
				<strong>' . $title . '!</strong> ' . $text . '</p>
			</div></div>';
        echo $html;
    }

    function display_msg_reqlogin() {
        $class = "ui-state-highlight";
        $title = "Info";
        $icon = "ui-icon-info";
        $text = "Debe Loguearse para acceder a esta información";
        $html = '<div class="ui-widget"><div style="margin-top: 20px; padding: 0 .7em;" class="' . $class . ' ui-corner-all">
				<p><span style="float: left; margin-right: .3em;" class="ui-icon ' . $icon . '"></span>
				<strong>' . $title . '!</strong> ' . $text . '</p>
			</div></div>';
        echo $html;
    }

    function include_jquery_validator() {
        echo "<script type=\"text/javascript\" src=\"" . DOMAIN_ROOT . "js/jquery.validate.js\"></script>";
    }

    static function ShowDate($date) {
        return date("d/m/Y", strtotime($date));
    }
    static function ShowFullDate($date) {
        return date("d/m/Y H:i:s", strtotime($date));
    }

    static function MysqlDayName($n) {
        switch ($n) {
            case 1:
                echo 'Domingo';
                break;
            case 2:
                echo 'Lunes';
                break;
            case 3:
                echo 'Martes';
                break;
            case 4:
                echo 'Miercoles';
                break;
            case 5:
                echo 'Jueves';
                break;
            case 6:
                echo 'Viernes';
                break;
            case 7:
                echo 'Sabado';
                break;

            default:
                echo 'No Definido';
                break;
        }
    }

    static function setJson($model) {
        $result = array();
        foreach ($model as $p):
            array_push($result, $p->to_json());
        endforeach;
//        $result = "[" . implode(",", $result) . "]";
//        $result = str_replace('":', '":"', $result);
//        $result = str_replace(',"', '","', $result);
//        $result = str_replace('""', '"', $result);
        return json_encode($result);
    }
    
    static function countPed($sectors){
        $peds = 0;
        foreach ($sectors as $sector => $ped):
        $peds += count($ped);    
        endforeach;
        return $peds;
    }
    
    static function countArt($arts){
        $peds = 0;
       foreach ($arts as $art):
        $peds += $art->total_art;    
        endforeach;
        return $peds;
    }

}

?>
