ACC SHELL

Path : /srv/www/vhosts/profias/inc/
File Upload :
Current File : /srv/www/vhosts/profias/inc/fce.php

<?php
 /*************************************************************************
  *
  *  Skrtipt obsahujici funkce pouzite v jinych skriptech
  *
  ************************************************************************/

 
  

  /* fce, ktera vrati kod, pro strankovani
  /*
  /* parametry: $on_page - pocet zaznamu na stranku
                $count - celkovy pocet zaznamu
                $pages_count -  pocet stranek ve strankovadle
                $offset - offset zaznamu
                $page - jmeno stranky, ze ktere je strankovadlo volano
                $params - GET parametry
  */
  
  function pageLang($ID, $id_lang){
  $dtb = new Db();

  $pat = $dtb -> select(
    'spl.name, spl.path',
    'sys_pages as sp LEFT JOIN sys_pages_languages as spl on (spl.id_page = sp.id)',
    'spl.id_language = '.$id_lang.' AND sp.id = '.(int)$ID,
    '1'
  );
   
   return $pat["path"];
}
  
  function paging($on_page, $count, $pages_count, $offset, $page, $params, $rel_href='', $offset_str='offset')
  {
   if (FALSE==$count) return '';    
  
    $result='<div class="paging">';  
    
    $get_str=get_params2($params, array($offset_str)); 

    
    $pages=ceil($count/$on_page);
    $actual=floor($offset/$on_page);
    $start=$actual-floor($pages_count/2);
    
    
    if ($start<0)
    {
      $start=0;
    }
    
    
    $end=$start+$pages_count;
    if ($end>$pages)
    {
      $end=$pages;
      $start=$end-$pages_count;
    }

    if ($start<0)
    {
      $start=0;
    }
    
    if ($start>0)
    {
      $tmp_pos=$offset-$on_page*floor($pages_count);
      if ($tmp_pos<0)
      {
        $tmp_pos=0;
      }
      $result.='<a class="straight" href="'.$page.'?'.$offset_str.'='.$tmp_pos.$get_str.$rel_href.'"> &laquo; </a> ';
    }

    if ($actual>0)
    {
      $result.='<a class="straight" href="'.$page.'?'.$offset_str.'='.($offset-$on_page).$get_str.$rel_href.'"> &lsaquo; </a> ';
    }

    if ($start==$end-1)
    {
      return '';  
    }
    
    for ($i=$start; $i<$end; $i++)
    {
      if ($i==$actual)
      {
        $result.='<span class="red"> '.($i+1).'</span> ';
      }
      else
      {
        $result.='<a href="'.$page.'?'.$offset_str.'='.($i*$on_page).$get_str.$rel_href.'"> '.($i+1).'</a> ';
      }
    }
    
    if ($actual<$pages-1)
    {
      $result.='<a class="straight" href="'.$page.'?'.$offset_str.'='.($offset+$on_page).$get_str.$rel_href.'"> &rsaquo; </a> ';
    }
    
    if ($end<$pages)
    {
      $tmp_pos=$offset+$on_page*floor($pages_count);
      if ($tmp_pos>$count-$on_page)
      {
        $tmp_pos=$count-$on_page;
      }
      $result.='<a class="straight" href="'.$page.'?'.$offset_str.'='.$tmp_pos.$get_str.$rel_href.'"> &raquo; </a> ';
    }

    $result.='</div>';  
 
    return $result;
  
  }


  function query($sql)
  {
    $query=mysql_query($sql);

    if (TRUE==mysql_error())
    {
      die(mysql_error().'<br />'.nl2br($sql)); 
    }
    
    $result=array();
    
    while ($data=mysql_fetch_array($query))
    {
      $result[]=$data;
    }

    return $result;
  }





  function text_paging($text, $on_page, $offset, $page='', $params=array())
  {
   if (FALSE==$on_page) return '';     
  
    $result='<div class="text_paging">';  
    
    $get_str=get_params($params, array('toffset')); 

    
    $pages=ceil(strlen($text)/$on_page);
    $actual=floor($offset/$on_page);
    $start=$actual-floor($pages_count/2);
    
    
    if ($start<0)
    {
      $start=0;
    }
    
    
    $end=$start+$pages_count;
    if ($end>$pages)
    {
      $end=$pages;
      $start=$end-$pages_count;
    }

    if ($start<0)
    {
      $start=0;
    }
    
    if ($start>0)
    {
      $tmp_pos=$offset-$on_page*floor($pages_count);
      if ($tmp_pos<0)
      {
        $tmp_pos=0;
      }
      $result.='<a class="paging-text-right" href="'.$page.'?toffset='.$tmp_pos.$get_str.'"> &laquo; </a> ';
    }

    if ($actual>0)
    {
      $result.='<a class="paging-text-left" href="'.$page.'?toffset='.($offset-$on_page).$get_str.'"> &lsaquo; </a> ';
    }

    if ($start==$end-1)
    {
      return '';  
    }
    
    for ($i=$start; $i<$end; $i++)
    {
      if ($i==$actual)
      {
        $result.='<span class="red"> '.($i+1).'</span> ';
      }
      else
      {
        $result.='<a href="'.$page.'?offset='.($i*$on_page).$get_str.'"> '.($i+1).'</a> ';
      }
    }
    
    if ($actual<$pages-1)
    {
      $result.='<a class="paging-text-right" href="'.$page.'?offset='.($offset+$on_page).$get_str.'"> &rsaquo; </a> ';
    }
    
    if ($end<$pages)
    {
      $tmp_pos=$offset+$on_page*floor($pages_count);
      if ($tmp_pos>$count-$on_page)
      {
        $tmp_pos=$count-$on_page;
      }
      $result.='<a class="paging-text-left" href="'.$page.'?offset='.$tmp_pos.$get_str.'"> &raquo; </a> ';
    }

    $result.='</div>';  
 
    return $result;
  
  }


  // fce, ktera vezme parametry a vrati GET string
  
  function get_params($params, $trash=array())
  {
    $get_str=''; 
    $trash[]='page_name'; 
    $keys=array_keys($params);
    for ($i=0; $i<count($keys); $i++)
    {
      if (FALSE==in_array($keys[$i], $trash))
      {
        $get_str.='&amp;'.$keys[$i].'='.$params[$keys[$i]];
      } 
    }
    
    return $get_str;  
  }

  // fce, ktera vezme parametry a vrati GET string pocita i s poli
  function get_params2($params, $trash=array())
  {
    $get_str=''; 
    $trash[]='page_name'; 
    
    
    foreach($params AS $key => $value){
      if (FALSE==in_array($key, $trash)){
        if (is_array($params[$key])){
          foreach($params[$key]  as $k => $v){
            $get_str.='&amp;'.$key.'%5B%5D='.$v;
          }
        }else{
          $get_str.='&amp;'.$key.'='.$value;        
        }
      }
    }
    return $get_str;  
  }



  function get_params3($params, $trash=array())
  {
    $get_str=''; 
    $trash[]='page_name'; 
    $keys=array_keys($params);
    for ($i=0; $i<count($keys); $i++)
    {
      if (FALSE==in_array($keys[$i], $trash))
      {
        $get_str.='<input type="hidden" name="'.$keys[$i].'" value="'.$params[$keys[$i]].'" />
        ';
      } 
    }
    
    return $get_str;  
  }
  // prevede nazev na systemovy nazev (bez diakritiky, ridicich znaku a mezer + zkrati jej na 40 znaku)
  

  function forum_suffix($number)
  {
    if (
      (0==($number%10)) 
      ||
      ((10<$number) && (20>$number))
    )       
    {
      return 'vků';
    }
    else
    if (1==($number%10))
    {
      return 'vek';
    }       
    else
    if (5>($number%10))
    {
      return 'vky';
    }       
    else
      return 'vků';
  }






  // fce na kontrolu a preformatovani casu
  function checkTime($datetime)   
  {
    $tmp_date=explode(', ', $datetime);   
    $date=explode('. ', $tmp_date[0]);
    $time=explode(':', $tmp_date[1]);

    $daysinmonth=array(31,28,31,30,31,30,31,31,30,31,30,31);
    if ((($date[2]%4==0) && ($date[2]%100!=0)) || ($date[2]%400==0)) $daysinmonth[2]=29;
    
    if (
      ((int)$date[0]>0) && ((int)$date[0]<=(int)$daysinmonth[(int)$date[1]-1])
      &&
      ((int)$date[1]>0) && ((int)$date[1]<13)
      &&
      ((int)$date[2]>=1970) && ((int)$date[2]<=3000)
      &&
      ((int)$time[0]>=0) && ((int)$time[0]<24)
      &&
      ((int)$time[1]>=0) && ((int)$time[0]<60)
    )
    {
      return $datetime;   
    }
    else
    {
      return '';
    }

  }
  // konec fce


  // prevede nazev na systemovy nazev (bez diakritiky, ridicich znaku a mezer + zkrati jej na 40 znaku)
  
  function sys_name($string)
  {
    $origin=array('ě','š','č','ř','ž','ý','á','í','é','ů','ú','ó','ď','ň','ť','Ě','Š','Č','Ř','Ž','Ý','Á','Í','É','Ů','Ú','Ó','Ď','Ň','Ť', '&nbsp;', ',', ';', ':', '(', ')', '-', '?', '!');
    $new=array('e','s','c','r','z','y','a','i','e','u','u','o','d','n','t','E','S','C','R','Z','Y','A','I','E','U','U','O','D','N','T', '_', '', '', '', '', '', '', '', '');
    $spec_chars=array('\'','\\',',','@','#','$','%','^','&','*','()');    

    $string=str_replace($origin, $new, $string);
    $string=str_replace($spec_chars, '', $string);         
    
    if (count($string)>40)
    {
      $string=trim(substr($string.' ', 0, 40), 'a..z');
    }
    
    return str_replace(' ', '_', trim($string));   
    
  }

  function sys_name2($string)
  {
    $origin=array('ě','š','č','ř','ž','ý','á','í','é','ů','ú','ó','ď','ň','ť','Ě','Š','Č','Ř','Ž','Ý','Á','Í','É','Ů','Ú','Ó','Ď','Ň','Ť', '&nbsp;', ' ', '/');
    $new=array('e','s','c','r','z','y','a','i','e','u','u','o','d','n','t','E','S','C','R','Z','Y','A','I','E','U','U','O','D','N','T', '-', '-', '-');
    $spec_chars=array('\'','\\',',','@','#','$','%','^','&','*','()');    

    $string=str_replace($origin, $new, $string);
    $string=str_replace($spec_chars, '', $string);         
    
    return  trim(strtolower($string));   
    
  }


  function get_attr($array, $name, $attrs, $sep=array(), &$parity)
  {
    $result='';
    
    $separator='';
    $attr='';
    
    $class=array(
      true=>'dark',
      false=>'bright',
    );
    
    for ($i=0; $i<count($attrs); $i++)
    {
      if (TRUE==$array[$attrs[$i]])
      {
        $attr.=$sep[$i].$array[$attrs[$i]];
      }
    }

    for ($i=count($attrs); $i<count($sep); $i++)
    {
      if (TRUE==$attr)
      {
        $attr.=$sep[$i];
      }
    }
    
    $text=$attr;
    $text=ereg_replace("[^\ \n][a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $text);
    $text=ereg_replace("[a-zA-Z0-9_/-?&%\.]+@([-]*[.]?[a-zA-Z0-9_/-?&%\.])+\.[a-zA-Z0-9_/-?&%]+", "<a href=\"mailto:\\0\">\\0</a>", $text);
    $text=ereg_replace("(^| |\n)(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
    $text=nl2br($text);
    
    if (TRUE==$attr)   
    {
      if (TRUE==$name)
      {
        $name='<div><div class="label">'.$name.':</div>';
      }
      else
      {
        $name='<div><div class="label"><!-- --></div>';
      }
      
    
      $result.='<div class="attr '.$class[$parity].'">
        '.$name.'<div class="value">'.$text.'</div>&nbsp;
      </div>
      <div class="clear_both"><!-- --></div>
      </div>
      ';
      $parity=!$parity;
    }          

    
    return $result;
  }


  function seconds($value)
  {
    $result='';
    $tmp=explode(',', ereg_replace('^(.*)°(.*)\'(.*)$', '\\1,\\2,\\3', trim($value, '"')));
    
    
    $result=$tmp[2]+$tmp[1]*60+$tmp[0]*3600;
       
    return $result;
  }

function htmlentities_iso88592($string='') {
   $pl_iso = array('&ecirc;', '&oacute;', '&plusmn;', '&para;', '&sup3;', '&iquest;', '&frac14;', '&aelig;', '&ntilde;', '&Ecirc;', '&Oacute;', '&iexcl;', '&brvbar;', '&pound;', '&not;', '&macr;', '&AElig;', '&Ntilde;');   
   $entitles = get_html_translation_table(HTML_ENTITIES);
   $entitles = array_diff($entitles, $pl_iso);
   return strtr($string, $entitles);
}


// Funkce na prevod libovolneho ceskeho textu $str na kodovani $code
// (puvodni kodovani neni nutne znat)
function AutoCzech($str, $code)
{
	// Ceske znaky v ruznych kodovanich (ASCII, Win-1250, ISO 8859-2, UTF-8)
	$autocp['asc'] = array ('A','C','D','E','E','I','N','O','R','S','T','U','U','Y','Z',
	                        'a','c','d','e','e','i','n','o','r','s','t','u','u','y','z');
	$autocp['win'] = array ('Á','Č','Ď','É','Ě','Í','Ň','Ó','Ř','©','«','Ú','Ů','Ý','®',
	                        'á','č','ď','é','ě','í','ň','ó','ř','ą','»','ú','ů','ý','ľ');
	$autocp['iso'] = array ('Á','Č','Ď','É','Ě','Í','Ň','Ó','Ř','©','«','Ú','Ů','Ý','®',
	                        'á','č','ď','é','ě','í','ň','ó','ř','±','»','ú','ů','ý','µ');
	$autocp['utf'] = array("\xc3\x81", "\xc3\x88", "\xc3\x8f", "\xc3\x89", "\xc3\x83", "\xc3\x8d", "\xc3\x92", "\xc3\x93", "\xc3\x98", "\xc5\xa0", "\xc2\x8d", "\xc3\x9a", "\xc3\x99", "\xc3\x9d", "\xc5\xbd",
	                       "\xc3\xa1", "\xc3\xa8", "\xc3\xaf", "\xc3\xa9", "\xc3\xac", "\xc3\xad", "\xc3\xb2", "\xc3\xb3", "\xc3\xb8", "\xc5\xa1", "\xc2\x9d", "\xc3\xba", "\xc3\xb9", "\xc3\xbd", "\xc5\xbe");

	// Vsechny ceske znaky ktere je mozne prevadet
	$autocp['merge'] = array_merge ($autocp['utf'], $autocp['win'], $autocp['iso']);

	// Prevod do UTF nelze primo, takze AutoCzech na ISO a pak FromToCzech ISO->UTF.
	if ($code=='utf') {
		$str = AutoCzech($str, 'iso');
		return str_replace($autocp['iso'], $autocp['utf'], $str);
		}
	// ... do vseho osttaniho (ISO, WIN, ASC) muzeme prevezt primo
	else {
		$to = array_merge ($autocp[$code], $autocp[$code], $autocp[$code]);
		return str_replace($autocp['merge'], $to, $str);
	}
}

function GetMetaCharset ($code)
{
	$code = strtolower(substr($code, 0, 3));
	$charset['iso'] = 'iso-8859-2';
	$charset['win'] = 'windows-1250';
	$charset['utf'] = '????';
	$charset['asc'] = 'iso-8859-1';
	return $charset[$code];
}


function unhtmlentities ($string)
{
   $trans_tbl = get_html_translation_table (HTML_ENTITIES);
   $trans_tbl = array_flip ($trans_tbl);
   return strtr ($string, $trans_tbl);
}






  function repair_name($name)
  {
    $tmp=explode('-', $name);
    
    if (0<count($tmp))
    {
      $tmp=explode(' ', $tmp[0]);
    }
  
    $result='';
    
  
    for ($i=0; $i<count($tmp); $i++)
    {
      $result.=ucfirst(strtolower($tmp[$i])).' ';
    }
  
    
    if (TRUE==trim($result))
    {
      return trim($result);
    }
    else
    {
      return $name;
    }
  }

  function repair_name_lite($name)
  {
    $tmp=explode(' ', $name);
  
    $result='';
  
    for ($i=0; $i<count($tmp); $i++)
    {
      $result.=ucfirst(strtolower($tmp[$i])).' ';
    }
  
    if (TRUE==trim($result))
    {
      return trim($result);
    }
    else
    {
      return $name;
    }
  }



  function record_update($admin)
  {



    if ('object'==$admin->table)
    {
      $old_data=$GLOBALS['db']->select(
        '*
        ',
        '
          objects AS o
          LEFT JOIN objects_languages AS ol ON (o.id=ol.id_object)
          LEFT JOIN attribute_values AS av ON (o.id=av.id_object)
        ',
        'o.id='.(int)$admin->id
      );
      $new_data=$GLOBALS['db']->select(
        '*
        ',
        '
          tmp_objects AS o
          LEFT JOIN tmp_objects_languages AS ol ON (o.id=ol.id_object)
          LEFT JOIN tmp_attribute_values AS av ON (o.id=av.id_object)
        ',
        'o.id='.(int)$admin->id
      );
    }
    

    if ('action'==$admin->table)
    {
      $old_data=$GLOBALS['db']->select(
        '*
        ',
        '
          actions AS o
          LEFT JOIN actions_languages AS ol ON (o.id=ol.id_action)
        ',
        'o.id='.(int)$admin->id
      );
      $new_data=$GLOBALS['db']->select(
        '*
        ',
        '
          tmp_actions AS o
          LEFT JOIN tmp_actions_languages AS ol ON (o.id=ol.id_action)
        ',
        'o.id='.(int)$admin->id
      );

    }


    if ('programme'==$admin->table)
    {
      $old_data=$GLOBALS['db']->select(
        '*
        ',
        '
          programmes AS o
          LEFT JOIN programmes_languages AS ol ON (o.id=ol.id_programme)
        ',
        'o.id='.(int)$admin->id
      );
      $new_data=$GLOBALS['db']->select(
        '*
        ',
        '
          tmp_programmes AS o
          LEFT JOIN tmp_programmes_languages AS ol ON (o.id=ol.id_programme)
        ',
        'o.id='.(int)$admin->id
      );

    }



    if ('accomodation'==$admin->table)
    {
      $old_data=$GLOBALS['db']->select(
        '*
        ',
        '
          accomodations AS o
          LEFT JOIN accomodations_languages AS ol ON (o.id=ol.id_accomodation)
          LEFT JOIN accomodations_accomodation_attributes AS av ON (o.id=av.id_accomodation)
        ',
        'o.id='.(int)$admin->id
      );
      $new_data=$GLOBALS['db']->select(
        '*
        ',
        '
          tmp_accomodations AS o
          LEFT JOIN tmp_accomodations_languages AS ol ON (o.id=ol.id_accomodation)
          LEFT JOIN tmp_accomodations_accomodation_attributes AS av ON (o.id=av.id_accomodation)
        ',
        'o.id='.(int)$admin->id
      );
    }


    
    if ($new_data!=$old_data)
    {


      $GLOBALS['db']->queryN('DELETE FROM operations WHERE admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=1 AND id_operation_type=1');
      $tmp2=$GLOBALS['db']->select('*', 'operations', 'admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=3 AND id_operation_type=3', '1');
      $tmp=$GLOBALS['db']->select('*', 'operations', 'admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=1 AND id_operation_type=1', '1');

      if ( (0==count($tmp)) && (0==count($tmp2)) )
      {


      if ('4'==$GLOBALS['user']['rights'])
      {
        $state=1;
      }
      else
      {
        $state=2;
      }

        $row=array(
          'id_operation_type'=>1,
          'id_user'=>(int)$GLOBALS['user']['id'],
          'admin_table'=>addslashes($admin->table),
          'admin_id'=>(int)$admin->id,
          'state'=>(int)$state,
          'rank'=>5,
        );
      

        $GLOBALS['db']->insert('operations', $row);
        
      }
        
    }
  
      
  }



  function record_update_declined($admin)
  {

    $GLOBALS['db']->queryN('UPDATE operations SET status=1 WHERE admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=3 AND id_operation_type=2');
  }


  function record_insert($admin, $id)
  {
      
      if ('4'==$GLOBALS['user']['rights'])
      {
        $state=1;
      }
      else
      {
        $state=2;
      }
  

        $row=array(
          'id_operation_type'=>2,
          'id_user'=>(int)$GLOBALS['user']['id'],
          'admin_table'=>addslashes($admin->table),
          'admin_id'=>(int)$id,
          'state'=>(int)$state,
          'rank'=>10,
        );
      
        $GLOBALS['db']->insert('operations', $row);

        
        if ('object'==$admin->table)
        {
          // ulozi se prava uzivatele k pristupu k objektu
          $GLOBALS['db']->queryN('DELETE FROM objects_users WHERE id_object='.(int)$id.' AND id_user='.(int)$GLOBALS['user']['id']);
          $row=array(
            'id_object'=>(int)$id,
            'id_user'=>(int)$GLOBALS['user']['id'],
          );
          $GLOBALS['db']->insert('objects_users', $row);
        }
  }





  function document_upload($admin, $id)
  {
  
    
  
       $GLOBALS['db']->queryN('DELETE FROM operations WHERE admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=1 AND id_operation_type=3');
      $tmp=$GLOBALS['db']->select('*', 'operations', 'admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=3 AND (id_operation_type=3 OR id_operation_type=2)', '1');

      if (0==count($tmp))
      {


      if ('4'==$GLOBALS['user']['rights'])
      {
        $state=1;
      }
      else
      {
        $state=2;
      }

        $row=array(
          'id_operation_type'=>3,
          'id_user'=>(int)$GLOBALS['user']['id'],
          'admin_table'=>addslashes($admin->table),
          'admin_id'=>(int)$admin->id,
          'state'=>(int)$state,
          'rank'=>5,
        );
      

        $GLOBALS['db']->insert('operations', $row);
     }   
  
  }



  // zjisti zda PC HLASOVALO
  function hlasoval($id){
    if (isset($_COOKIE['ank_'.$id])){
      return true;
    }else return false;
  }	
  
    
  // fce na kotrolu promene
  function var_test(&$variable, $default, $pattern){
    if ((isSet($variable)) && (eregi($pattern, trim(StripSlashes($variable)))))
      return trim(StripSlashes($variable));
    else
      return $default;
  }
  
  // vypise text pokud je natavena promenna
  function show($at, $text){
    if ($at != false ){
      return $text;
    }else return;
  }
  
  
  function get_childs($category){
    $db = new Db();
    if ($category > 0){
      $ichild = array();
      $ichild [0] = $category;
  
      
      for ($i=0;$i<count($ichild);$i++){
        $tmp = $db->select(
          'ot.id',
          'object_types AS ot',
          'ot.id_parent = '.$ichild[$i]
        );
         
        for ($j=0;$j<count($tmp);$j++){
          $ichild[] = $tmp[$j]['id'];
        }
      }
    }
    return $ichild;
  } 
  
  
  function get_auto_increment($table){
  $tmp=$GLOBALS['db']->query('SHOW TABLE STATUS LIKE \''.addslashes($table).'\'');
  return $tmp[0]['Auto_increment'];
  } 


  // funkce, tera zkontroluje prava uzivatele a pripadne jej vyhosti na index.php
  function allow($rights_str){
    if (FALSE==in_array($GLOBALS['user']['rights'], explode(',', $rights_str)))
    {
      header('location: index.php');
      die();
    }
        return TRUE;
  }








  function get_map_coords($map_borders, $map_size, $gps)
  {
  

  $east=$map_borders['east'];
  $west=$map_borders['west'];
  $south=$map_borders['south'];
  $north=$map_borders['north'];
  
  $map_width=$map_size['x'];
  $map_height=$map_size['y'];

  $sn=seconds($north);
  $ss=seconds($south);

  $cx=(seconds($east)+seconds($west))/2;
  $cy=(seconds($north)+seconds($south))/2;

  $width=(seconds($east)-seconds($west));
  $height=($sn-$ss);


        
        $x=($map_width/2-($cx-seconds($gps['x']))/$width*$map_width);
        
        $x=round($x+($width/2-$x)*0.04);
        
        $y=($map_height/2+($cy-seconds($gps['y']))/$height*$map_height);

        $y=round($y+($height/2-$y)*0.04);
    
    return array('x'=>$x, 'y'=>$y);
  
}


function documents($table, $id, $preview=0, $where=' AND f.active=\'Y\'')
{


      $files=$GLOBALS['db']->select(
        'f.*',
        $table.'s_files AS of
         LEFT JOIN files AS f ON (of.id_file=f.id)
         ',
        'of.id_'.$table.'='.(int)$id.'
         AND f.id!='.(int)$preview.'
          '.$where.'
        '
      );

      $files_str=$img_str='';

      for ($i=0; $i<count($files); $i++)
      {
        if (TRUE==in_array($files[$i]['type'], $GLOBALS['image_types']))
        {
          $img_str.='
            <a class="'.$table.'-img" href="'.$GLOBALS['ftp']['http_root'].'/'.$table.''.$id.'/'.$files[$i]['path'].'" onclick="return !showImage(\''.$GLOBALS['ftp']['http_root'].'/'.$table.''.$id.'/'.$files[$i]['path'].'\');">
              <img src="'.$GLOBALS['ftp']['http_root'].'/'.$table.''.$id.'/thumb-s/'.$files[$i]['path'].'" alt="" />
            </a>
          ';
        }
        else
        {
         $files_str.='<img src="/images/ico/'.$GLOBALS['icons'][$files[$i]['type']].'" alt="" style="float: left; padding-right: 5px;" /><a target="_blank" class="'.$icons[$files[$i]['type']].'" href="'.$GLOBALS['ftp']['http_root'].''.$table.''.$id.'/'.$files[$i]['path'].'">'.$files[$i]['name'].'</a><br />';
        }  
      }

 
      
    if (TRUE==$files_str)  
    {
      $files_str='<p id="documents">
        <b>Soubory ke staľení:</b><br />
        '.$files_str.'
        </p>
      ';
    }


  return array('images'=>$img_str, 'files'=>$files_str);
} 


//      $GLOBALS['db']->queryN('UPDATE operations SET status=1 WHERE admin_table=\''.addslashes($admin->table).'\' AND admin_id='.(int)$admin->id.' AND status=3 AND id_operation_type=2');

  
function convert_html_sequences($str) {
    $r = $str;
    $r = str_replace("&nbsp;"," ", $r);
    $r = str_replace("&iexcl;","!", $r);
    $r = str_replace("&cent;","c", $r);
    $r = str_replace("&pound;","L", $r);
    $r = str_replace("&curren;","¤", $r);
    $r = str_replace("&yen;","Y", $r);
    $r = str_replace("&brvbar;","Š", $r);
    $r = str_replace("&sect;","§", $r);
    $r = str_replace("&uml;","¨", $r);
    $r = str_replace("&copy;","Ś", $r);
    $r = str_replace("&ordf;","a", $r);
    $r = str_replace("&laquo;","Ť", $r);
    $r = str_replace("&not;","Ž", $r);
    $r = str_replace("&shy;","­", $r);
    $r = str_replace("&reg;","Ź", $r);
    $r = str_replace("&macr;","—", $r);
    $r = str_replace("&deg;","°", $r);
    $r = str_replace("&plusmn;","‘", $r);
    $r = str_replace("&sup2;","2", $r);
    $r = str_replace("&sup3;","3", $r);
    $r = str_replace("&acute;","´", $r);
    $r = str_replace("&micro;","ś", $r);
    $r = str_replace("&para;","ť", $r);
    $r = str_replace("&middot;","ž", $r);
    $r = str_replace("&cedil;","¸", $r);
    $r = str_replace("&sup1;","1", $r);
    $r = str_replace("&ordm;","o", $r);
    $r = str_replace("&raquo;","ź", $r);
    $r = str_replace("&frac14;","1", $r);
    $r = str_replace("&frac12;","1", $r);
    $r = str_replace("&frac34;","3", $r);
    $r = str_replace("&iquest;","?", $r);
    $r = str_replace("&Agrave;","A", $r);
    $r = str_replace("&Aacute;","Á", $r);
    $r = str_replace("&Acirc;","Â", $r);
    $r = str_replace("&Atilde;","A", $r);
    $r = str_replace("&Auml;","Ä", $r);
    $r = str_replace("&Aring;","A", $r);
    $r = str_replace("&AElig;","A", $r);
    $r = str_replace("&Ccedil;","Ç", $r);
    $r = str_replace("&Egrave;","E", $r);
    $r = str_replace("&Eacute;","É", $r);
    $r = str_replace("&Ecirc;","E", $r);
    $r = str_replace("&Euml;","Ë", $r);
    $r = str_replace("&Igrave;","I", $r);
    $r = str_replace("&Iacute;","Í", $r);
    $r = str_replace("&Icirc;","Î", $r);
    $r = str_replace("&Iuml;","I", $r);
    $r = str_replace("&ETH;","?", $r);
    $r = str_replace("&Ntilde;","N", $r);
    $r = str_replace("&Ograve;","O", $r);
    $r = str_replace("&Oacute;","Ó", $r);
    $r = str_replace("&Ocirc;","Ô", $r);
    $r = str_replace("&Otilde;","O", $r);
    $r = str_replace("&Ouml;","Ö", $r);
    $r = str_replace("&times;","×", $r);
    $r = str_replace("&Oslash;","O", $r);
    $r = str_replace("&Ugrave;","U", $r);
    $r = str_replace("&Uacute;","Ú", $r);
    $r = str_replace("&Ucirc;","U", $r);
    $r = str_replace("&Uuml;","Ü", $r);
    $r = str_replace("&Yacute;","Ý", $r);
    $r = str_replace("&THORN;","?", $r);
    $r = str_replace("&szlig;","ß", $r);
    $r = str_replace("&agrave;","a", $r);
    $r = str_replace("&aacute;","á", $r);
    $r = str_replace("&acirc;","â", $r);
    $r = str_replace("&atilde;","a", $r);
    $r = str_replace("&auml;","ä", $r);
    $r = str_replace("&aring;","a", $r);
    $r = str_replace("&aelig;","a", $r);
    $r = str_replace("&ccedil;","ç", $r);
    $r = str_replace("&egrave;","e", $r);
    $r = str_replace("&eacute;","é", $r);
    $r = str_replace("&ecirc;","e", $r);
    $r = str_replace("&euml;","ë", $r);
    $r = str_replace("&igrave;","i", $r);
    $r = str_replace("&iacute;","í", $r);
    $r = str_replace("&icirc;","î", $r);
    $r = str_replace("&iuml;","i", $r);
    $r = str_replace("&eth;","?", $r);
    $r = str_replace("&ntilde;","n", $r);
    $r = str_replace("&ograve;","o", $r);
    $r = str_replace("&oacute;","ó", $r);
    $r = str_replace("&ocirc;","ô", $r);
    $r = str_replace("&otilde;","o", $r);
    $r = str_replace("&ouml;","ö", $r);
    $r = str_replace("&divide;","÷", $r);
    $r = str_replace("&oslash;","o", $r);
    $r = str_replace("&ugrave;","u", $r);
    $r = str_replace("&uacute;","ú", $r);
    $r = str_replace("&ucirc;","u", $r);
    $r = str_replace("&uuml;","ü", $r);
    $r = str_replace("&yacute;","ý", $r);
    $r = str_replace("&thorn;","?", $r);
    $r = str_replace("&yuml;","y", $r);
     $r = str_replace("&scaron;","ą", $r);
     $r = str_replace("&bdquo;","\"", $r);
     $r = str_replace("&ldquo;","\"", $r);
     $r = str_replace("&Scaron;","©", $r);
     $r = str_replace("&ndash;","-", $r);

    $r = str_replace("&rchar;","\r", $r);
    return $r;
}


  function logCheck()
  {
    global $admin;
    
    $result=true;    
  
    if (TRUE==isset($_COOKIE['brpasswd']))
    {
      if ($_COOKIE['brpasswd']!=md5($admin['passwd']))
      {
        $result=false;
      }
    }
    else
    {
      $result=false; 
    }
    
    return $result; 
  }


function XMLStrFormat($str){
    global $asc2uni;
    $str = str_replace("&", "&amp;", $str);
    $str = str_replace("<", "&lt;", $str); 
    $str = str_replace(">", "&gt;", $str); 
    $str = str_replace("'", "&apos;", $str);  
    $str = str_replace("\"", "&quot;", $str); 
    $str = str_replace("\r", "", $str);
    $astr = @strtr($str,$asc2uni);
    return $str;
}


  
?>

ACC SHELL 2018