<?php

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

function getBrowserLanguage() {
    $res = "fr";
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    switch ($lang) {
        case "fr": $res = "0";
            break;
        case "en": $res = "1";
            break;
        default: $res = "0";
    }
    
    return strtolower($res);
}


function populateLanguageFile($lang){
    $filename = "lang/lang_$lang".".xml"; 
    $xml = simplexml_load_file($filename);
    
   // print_r($xml);
    
    $nodes =  count($xml->WebElement);
   // echo $nodes;
    for($i=0 ; $i < $nodes ; $i++ ){
        
      $data =   (string)$xml->WebElement[$i]['id'];
     // print_r((string)$data);
        
       // echo $xml->WebElement[$i]['id'].":".$xml->WebElement[$i]."";
      // $id = $xml->WebElement[$i]['id'];
       
       //print_r($id[0]);
       $cfgWebUI[$data] = (string)$xml->WebElement[$i] ;
        
        //echo $xml->WebElement[$i]['id'];
        
    }
    
   return $cfgWebUI;  
    
}

function topMenuJsonData($data){
    
    $json = "{ \'menuId\' : ".$data." }";
    
    return  $json;
    
}




function getTotalPage($total, $maxElement){
    $totalPage = 1;
    
        if($total <=$maxElement) {
            
            $totalPage = 1;
            
            return $totalPage;
        }
        
        
        $work = ceil($total/$maxElement);
        
        
    return $work;
    
}



function getCurrentPage($startLimit, $maxElement , $total){
  /*  
     if($total <=$maxElement) {
            
            $totalPage = 1;
            
            return $totalPage;
        }
        
    if($startLimit ==0){
        
        
        return 1;
    }
   * 
   * 
   */
    
     if($startLimit ==0){
        
        
        return 1;
    }
    
    $temp = ceil(($total - $startLimit)/$maxElement) - 1;
    $work = ceil($total/$maxElement);
    
    $page = $work-$temp;
    
    return $page;
    
}

function enablePreviousPageLink($currentPage){
    
    if($currentPage> 1) return true; else return false;
    
    
    
}


function enableNextPageLink($currentPage, $totalPage){
   
    $work = $totalPage - $currentPage;
    
    if($work>0) return true;  else return false;
    
    
    
}


function extractParathensisData($data){
    $extracted = null;
    $separator = array("(",")");
    $data = str_replace($separator, ";", $data);
    
    $extracted = explode(";", $data);
    
    
    return $extracted[1];
    
}


?>
