ACC SHELL

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

<?php

  class Admin
  {

    var 
      $action, // provadena akce (vetsinou posilana GETem nebo POSTem)
      $name, // nazev administrace (bude se zobrazovat jako nadpis)
      $type, // typ administrace
      $items, // pole polozek
      $table, // tabulka, ke ktere se administrace vztahuje (ktera se upravuje)
      $filesTable, // tabulka se 
      $data, //data z db
      $dataRow, // data o aktualni polozce
      $tmpDataRow, // date o aktualni polozce, cekajici na schvaleni
      $id, // id aktualniho zaznamu
      $ftp, // udaje pro pripojeni k FTP serveru
      $join, // tabulky, ktere se pripoji v selectu pro vypis dat
      $where, // podminka pro select dat
      $imageTypes, // typy obrazku
      $documents, // administrace bude s dokumenty (true/false)
      $actions,  // seznam akci
      $href, //urcuje, kam stranka po akci sroluje (#neco), uvadi se bez #
      $list, // tabulka pri vypisu polozek
      $template, // sablona pro formular
      $readOnly, // neni mozne nic editovat
      $order, // razeni
      $onPage, // pocet zaznamu na stranku pri vypisu
      $class, // trida formulare
      $groupby, // GROUP BY
      $offset, // offset pri strankovani
      $thumbDirectory,
      $templates, // sablony (pro detail, editaci a vkladani)
      $defaultLanguage, // jazyk primarne zvoleny pri vkladani
      $onLoad, // js fce pro body onload
      $listable, // je mone menit poradi polozek
      $filter, // seznam triditelnych polozek
      $sql,
      $colors, // barvy ve vypise
      $readOnlys, // seznam id jen pro cteni
      $log, /// logy
      $innerHTML // pridavny kod v adminu
      ; 
  
  
    
    // konstruktor
    // vytvoreni administrace
    function Admin($args=array())
    {
    
    // prevedeni promenne z pole $args na vlastnosti tridy Admin
      if (TRUE==$args['table'])
      {
        $this->table=$args['table'];
      }
      else
      {
        die('Error: no table selected');
      }
      
      // zjisti id aktualniho zaznamu
      if (TRUE==isset($_POST['id'.$this->table]))
      {
        $this->id=$_POST['id'.$this->table];
      }
      else if (TRUE==isset($_GET['id'.$this->table]))
      {
        $this->id=$_GET['id'.$this->table];
      }
      else
      {
        $this->id='';
      }
      
      // sablona pro formular
      if (TRUE==$args['template'])
      {
        $this->template=$args['template'];
      }
      else
      {
        $this->template='';
      }

      if (TRUE==isset($args['log']))
      {
        $this->log=$args['log'];
      }
      
      // seznam polozek vypisu
      if (TRUE==$args['list'])
      {
        $this->list=$args['list'];
      }
      else
      {
        die('Error: no list specified.');
      }

      // seznam polozek vypisu
      if (TRUE==$args['filter'])
      {
        $this->filter=$args['filter'];
      }
      else
      {
        $this->filter=array();
      }

      // pocet polozek vypisu na strance (default=20)
      if (TRUE==$args['on_page'])
      {
        $this->onPage=$args['on_page'];
      }
      else
      {
        $this->onPage=20;
      }

      // nazev administrace
      if (TRUE==$args['name'])
      {
        $this->name=$args['name'];
      }
      else
      {
        $this->name='&nbsp;';
      }

      // razeni vypisu
      if (TRUE==$args['order'])
      {
        $this->order=$args['order'];
      }
      else
      {
        $this->order=$this->table.'s.list';
      }

      // group
      if (TRUE==$args['groupby'])
      {
        $this->groupby=' GROUP BY '.$args['groupby'];
      }
      else
      {
        $this->groupby='';
      }

      // dokumenty
      if (''!==$args['documents'])
      {
        $this->documents=$args['documents'];
      }
      else
      {
        $this->documents=TRUE;
      }
      
      // dokumenty
      if (FALSE==$args['listable'])
      {
        $this->listable=$args['listable'];
      }
      else
      {
        $this->listable=TRUE;
      }

      if (TRUE==$args['href'])
      {
        $this->href=$args['href'].$this->table;
      }
      else
      {
        $this->href='here'.$this->table;
      }

      if (TRUE==$args['join'])
      {
        $this->join=' '.$args['join'];
      }
      else
      {
        $this->join='';
      }

      if (TRUE==$args['where'])
      {
        $this->where=' '.$args['where'];
      }
      else
      {
        $this->where='';
      }

      if (TRUE==$args['inner_html'])
      {
        $this->innerHTML=$args['inner_html'];
      }
      else
      {
        $this->innerHTML=array();
      }

      if (TRUE==$args['image_types'])
      {
        $this->imageTypes=$args['image_types'];
      }
      else
      {
        $this->imageTypes=array('image/jpeg', 'image/pjpeg', 'image/gif');
      }

      if (TRUE==$args['read_onlys'])
      {
        $this->readOnlys=$args['read_onlys'];
      }
      else
      {
        $this->readOnlys=array();
      }

      if (TRUE==$args['colors'])
      {
        $this->colors=$args['colors'];
      }
      else
      {
        $this->colors=array();
      }


      if (TRUE==$args['templates'])
      {
        $this->templates=$args['templates'];
      }
      else
      {
        $this->templates=array();
      }




      if (TRUE==$args['ftp'])
      {
        $this->ftp=$args['ftp'];
      }
      else
      {
        $this->ftp=array();
      }

      if (TRUE==$args['thumb_directory'])
      {
        $this->thumbDirectory=$args['thumb_directory'];
      }
      else
      {
        $this->thumbDirectory=$GLOBALS['thumb_directory'];
      }

      if (TRUE==$args['files_table'])
      {
        $this->filesTable=$args['files_table'];
      }
      else
      {
        $this->filesTable='files';
      }


      if (TRUE==$args['actions'])
      {
        if (FALSE==$args['actions']['add_file'])
        {
          $args['actions']['add_file']='Přidat dokument';
        }
        $this->actions=$args['actions'];
      }         
      else
      {
        $this->actions=array(
          'add'=>'přidat',
          'list'=>'seznam',
          'edit'=>'upravit',
          'edit_confirm'=>'uložit',
          'add_now'=>'přidat ',
          'after_add'=>'upravit',
          'delete'=>'smazat',
          'delete_confirm'=>'Ano, smazat',
          'add_file'=>'Přidat dokument',
        ); 
      }


      // zjisjit zda je postem poslana promenna action, pokud ano, zjistit ji, pokud ne, nastavit action na ''
      if (TRUE==isset($_POST['action'.$this->table]))
      {
        $this->action=$_POST['action'.$this->table];
      }
      else
      if (TRUE==isset($_GET['action'.$this->table]))
      {
        $this->action=$_GET['action'.$this->table];
      }
      else
      {
        $this->action=$this->actions['list'];
      }
  
      if (TRUE==$args['item_title'])
      {
        $this->itemTitle=$args['item_title'];
        $fields=array($args['item_title']);
      }
      else
      {
        $this->itemTitle=$this->table.'s.id';
        $fields=array($this->table.'s.id');
      }
    
      if (TRUE==$args['default_language'])
      {
        $this->defaultLanguage=$args['default_language'];
      }
      else
      {
        $this->defaultLanguage='';
      }

// konec: prevod argumentu z promenne args




      $sql['fields']=''.$this->table.'s.id';

      // nadpis polozky v seznamu 
      if (TRUE==$this->itemTitle)
      {
        $sql['fields'].=', '.$this->itemTitle.' AS item_title';
      } 
      else 
      {
        $sql['fields'].=', '.$this->table.'s.id AS item_title';
      }  
      
      

      $sql['from']=$this->table.'s';

      $sql['where']='1';   
      
      $froms=array();
      
      
      require_once('AdminItem.php');
      
    // vytvorit vsechny polozky administrace a sestavit SQL, pro nacteni dat z DB
      for ($i=0; $i<count($args['items']); $i++)
      {
        require_once($args['items'][$i]['type'].'.php');
        
        //print_r($args['items'][$i]);
        
        $this->items[$i]=new $args['items'][$i]['type']($args['items'][$i]);
        $this->items[$i]->formName.=$this->table;
        
        
        if ( ($this->actions['list']!=$this->action) && (($this->actions['detail']!=$this->action)) )
        {
          $tmp_select=$this->items[$i]->select($this);
        }
        else
        {
          $tmp_select=$this->items[$i]->getList($this);
        }

        if (TRUE==is_array($tmp_select))
        {
          if (TRUE==$tmp_select['fields'])
          {
            if (TRUE==isset($tmp_select['ftable']))
            {
              $field=$tmp_select['ftable'].'.'.$tmp_select['fields'];
            }
            else if (''==$tmp_select['table'])
            {
              $field=$tmp_select['fields'];
            }
            else if (TRUE==$tmp_select['table'])
            {
              $field=$tmp_select['table'].'.'.$tmp_select['fields'];
            }
            else
            {
              $field=$this->table.'s.'.$tmp_select['fields'];
            }  
            $sql['fields'].=', '.$field;
            $fields[]=$field;
          }

          if (FALSE==in_array($tmp_select['from'], $froms))
          {
            $sql['from'].=$tmp_select['from'];
            $froms[]=$tmp_select['from'];
          }
         // $sql['where'].=$tmp_select['where'];
        }
      }
      
     
      if (TRUE==$this->documents)
      {
         $sql['fields'].=', '.$this->table.'s.preview';
      }
      
      $sql['fields'].=', '.$this->table.'s.active';
      $sql['where'].=$tmp_select['where'].$this->where;
      $sql['from'].=$this->join;
      
      if (TRUE==isset($_GET['sort'.$this->table]))
      {
        $sql['order'].=$this->list['columns'][$_GET['sort'.$this->table]]['sort'].', '.$this->order;
      }
      else
      {
        $sql['order']=$this->order;
      }
      
      // strankovani 
      if (TRUE==$_GET['offset'.$this->table])
      {
        $this->offset=$_GET['offset'.$this->table];
      }
      else
      {
        $this->offset=0;
      }

      if (TRUE==$_GET['s'.$this->table])
      {
        $tmp=$separator='';
        for ($i=0; $i<count($fields); $i++)
        {
//          echo $fields[$i].' - '.
          $fields[$i]=preg_replace('/^(.*)\ AS\ .*$/', '\\1', $fields[$i]);
//          echo '*'.$fields[$i].'*<br />';
          if ('SUM('!=substr($fields[$i], 0, 4) && ('COUNT('!=substr($fields[$i], 0, 6)))
          {          
            $tmp.=$separator.$fields[$i].' LIKE \'%'.sys_name2($_GET['s'.$this->table]).'%\'';
            $separator=' OR ';
          }
        }
        $sql['where']='('.$sql['where'].') AND ('.$tmp.')';
      }
      


    // zjisteni poctu zaznamu
      $tmp=$GLOBALS['db']->select($this->table.'s.id', $sql['from'], $sql['where'].$this->groupby);
      $this->count=count($tmp);

    // nasteveni limitu      
      $start=$this->offset;
      
      if ($this->count<=$start)
      {
        $start=$this->count-1;
      }

      if (0>$start)
      {
        $start=0;
      }

      $this->offset=$start;
      

      $this->sql=$sql;      
      
      $sql['limit']=$start.', '.$this->onPage;
      
  
      $this->distinct=' DISTINCT ';
      
      $sql['fields'].=', '.$this->table.'s.list';
      
    // nacteni dat z DB
        $this->data=$GLOBALS['db']->select($this->distinct.$sql['fields'], $sql['from'], $sql['where'].$this->groupby, $sql['limit'], $sql['order']);


 
 
    // nacist informace o aktualni polozce   
      if (TRUE==$this->id)
      {
        $this->dataRow=$GLOBALS['db']->select($sql['fields'], $sql['from'], '('.$sql['where'].') AND '.$this->table.'s.id='.(int)$this->id.$this->groupby, '1');
        

      }   
      else
      {
        $this->dataRow=array();
      }
    
      $keys=@array_keys($this->dataRow);
      for ($i=0; $i<count($keys); $i++)
      {
        $this->dataRow[$keys[$i]]=stripslashes($this->dataRow[$keys[$i]]);
      }
    
//    print_r($this->dataRow);


    
      return TRUE;
  
    }
    
    // konec: konstruktor

// ****************************************************************************************************************************
// ****************************************************************************************************************************














// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                                S E Z N A M                                                     ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************

    // vrati seznam polozek
    function getList()
    {
    
      $result='';
      $table_data='';
      $parity=FALSE;




      //print_r($this->items);
      $filter_form=new Form();
      for ($i=0; $i<count($this->items); $i++)
      if (TRUE==$this->items[$i]->filter)      
      {
         $params=$this->items[$i]->getFormParams($this, $form);
         
          if (0<count($params))
          {
            for ($j=0; $j<count($params); $j++)
            {
              $filter_form->addInput($params[$j]['type'], $params[$j]['name'], $params[$j]['value'], $params[$j]['reg'], $params[$j]['css_id'], $params[$j]['css_class'], $params[$j]['spec'].' onchange="aa.submit();"', $params[$j]['label'].$help, $params[$j]['labell_id'], $params[$j]['label_class'], $params[$j]['options'], $params[$j]['inactive']);
            }
          }
      }
//      $result.=$filter_form->getHTML();

      
      $paging=paging($this->onPage, $this->count, 20, $this->offset, '', $_GET, '#list', 'offset'.$this->table);


      $search_form='
        <form action="?#'.$this->href.'" method="get" class="admin-search-form">
          <div>
            <input type="text" name="s'.$this->table.'" value="'.$_GET['s'.$this->table].'" />
            '.get_params3($_GET, array('s'.$this->table)).'
            <input type="submit" class="button" value="Vyhledat" />
          </div>
        </form>
      ';
      
      $result.=$search_form;

      // vytvoreni seznamu polozek (ve forme tabulky)    
      for ($i=0; $i<count($this->data); $i++)
      {

        if (FALSE==$parity)
        {
          $tr_class='bright';
        }
        else
        {
          $tr_class='dark';
        }
        $parity=!$parity;

       if ('N'==$this->data[$i]['active'])
       {
        $tr_class='inactive';
       }


        $table_data.=' <tr class="'.$tr_class.'">
        ';
      
      
      $style=$style_a='';
      
      if (0<count($this->colors))
      {
        for ($tmp=0; $tmp<count($this->colors); $tmp++)
        {
          if (TRUE==@in_array($this->data[$i]['id'], $this->colors[$tmp]['ids']))
          {
            $style=' style="background: #'.$this->colors[$tmp]['background'].'; color: #'.$this->colors[$tmp]['color'].'"';
            $style_a=' style="color: #'.$this->colors[$tmp]['color_a'].'"';
          }
        }
      }

      
        for ($j=0; $j<count($this->list['columns']); $j++)
        {
          // nasteveni odkazu
          if (TRUE==$this->list['columns'][$j]['href'])
          {
            if ('this'==$this->list['columns'][$j]['href'])
            {
              $href='?id'.$this->table.'='.$this->data[$i]['id'].get_params($_GET, array('id'.$this->table)).'#'.$this->href;
            }
            else
            {
              $href=$this->list['columns'][$j]['href'].$this->data[$i]['id'];
            }

          if (TRUE==$this->list['columns'][$j]['target'])
          {
            $target=' target="'.$this->list['columns'][$j]['target'].'"';
          }
          else
          {
            $target='';
          }
          
            $href_tag_start='<a'.$style_a.' href="'.$href.'"'.$target.'>';
            $href_tag_end='</a>';
          }
          else
          {
            $href_tag_start=$href_tag_end='';
          }




          // vytvoreni radku tabulky
          $table_data.='<td'.$style.'>
              '.$href_tag_start.'
                '.stripslashes($this->data[$i][sys_name($this->list['columns'][$j]['field']).$this->table].$this->list['columns'][$j]['alt_text']).'
              '.$href_tag_end.'
              &nbsp;
            </td>
          ';
        }

        // ikony operaci
        $icons='';
          
          
        if (TRUE==$this->defaultLanguage)
        {
          $tmp_lang=$this->table.'languages='.$this->defaultLanguage.'&amp;';
        }

          
        if (TRUE==$this->actions['edit'])
        {
          if (FALSE==isset($this->list['edit']))
          {
            $icons.='<a href="?action'.$this->table.'=edit&amp;'.$tmp_lang.'id'.$this->table.'='.$this->data[$i]['id'].get_params($_GET, array('action'.$this->table, 'id'.$this->table)).'" class="admin-icon-edit" title="'.$this->actions['edit'].'"><span class="no_css">'.$this->actions['edit'].'</span></a>';
           }
           else
           {
              $icons=$this->list['edit']($this->data[$i]['id']);
           }        
        }
        if (TRUE==$this->actions['delete'])
        {
          $icons.='<a href="?action'.$this->table.'=delete&amp;id'.$this->table.'='.$this->data[$i]['id'].get_params($_GET, array('action'.$this->table, 'id'.$this->table)).'" class="admin-icon-delete" title="'.$this->actions['delete'].'"><span class="no_css">'.$this->actions['delete'].'</span></a>';        
        }
        if (
          (TRUE==$this->actions['deactive'])
          &&
          ('Y'==$this->data[$i]['active'])
        )
        {
          $icons.='<a href="?action'.$this->table.'=deactive&amp;id'.$this->table.'='.$this->data[$i]['id'].get_params($_GET, array('action'.$this->table, 'id'.$this->table)).'" class="admin-icon-deactive" title="'.$this->actions['deactive'].'"><span class="no_css">'.$this->actions['deactive'].'</span></a>';        
        }
        if (
          (TRUE==$this->actions['active'])
          &&
          ('N'==$this->data[$i]['active'])
        )
        {
          $icons.='<a href="?action'.$this->table.'=active&amp;id'.$this->table.'='.$this->data[$i]['id'].get_params($_GET, array('action'.$this->table, 'id'.$this->table)).'" class="admin-icon-active" title="'.$this->actions['active'].'"><span class="no_css">'.$this->actions['deactive'].'</span></a>';        
        }
        
        if (FALSE==@in_array($this->data[$i]['id'], $this->readOnlys))
        {
        
        $table_data.='
          <td'.$style.' class="admin-icons">'.$icons.'</td>
        ';
        }
        else
        {
          $table_data.='
          <td'.$style.' class="admin-icons">&nbsp;</td>
        ';

        }

        if (TRUE==$this->listable)
        {  
          if (($i+1)<count($this->data))
          {
            $table_data.='
              <td><a href="?swap'.$this->table.'='.$this->data[$i]['list'].'-'.$this->data[$i+1]['list'].get_params($_GET, array('swap'.$this->table)).'">v</a></td>
            ';
          }
          else
          {
            $table_data.='
              <td>&nbsp;</td>
            ';
          }
        }          
          
        if (TRUE==$this->listable)
        {  
          if ($i>0)
          {
            $table_data.='
              <td><a href="?swap'.$this->table.'='.$this->data[$i]['list'].'-'.$this->data[$i-1]['list'].get_params($_GET, array('swap'.$this->table)).'">^</a></td>
            ';
          }
          else
          {
            $table_data.='
              <td>&nbsp;</td>
            ';
          }
        }


        $table_data.=" </tr>\n";

          if (TRUE==isset($this->list['inner']))
          {
            $table_data.='
              <tr>
                <td colspan="'.(count($this->list['columns'])+1).'">
                  '.$this->list['inner'][$this->data[$i]['id']].'
                </td>
              </tr>
            ';
          }

      }
      
      
      // vytvoreni hlavicky tabulky
      $table_header='';
      
      for ($i=0; $i<count($this->list['columns']); $i++)
      {
        if (FALSE==$this->list['columns'][$i]['sort'])
        {
          $table_header.='
            <th>'.$this->list['columns'][$i]['name'].'</th>
          ';
        }
        else
        {
          $table_header.='
            <th><a href="?sort'.$this->table.'='.$i.get_params($_GET, array('sort'.$this->table)).'">'.$this->list['columns'][$i]['name'].'</a></th>
          ';
        }
      }

      $table_header.='<th>&nbsp;</th>';

        if (TRUE==$this->listable)
        {  
          $table_header.='<th width="20">&nbsp;</th>';
          $table_header.='<th width="20">&nbsp;</th>';
        }
      



      
      if (TRUE==$table_data)
      {

      if (TRUE==$this->actions['add'])
      {
        if (TRUE==$this->defaultLanguage)
        {
          $tmp_lang='languages='.$this->defaultLanguage;
        }
      
        $result.='
          <div class="admin-icons">
            <a href="?action'.$this->table.'=add&amp;'.$this->table.$tmp_lang.get_params($_GET, array('id'.$this->table, 'action'.$this->table, $this->table.'languages')).'#'.$this->href.'" class="admin-icon-new" title="'.$this->actions['add'].'"><span class="no_css">'.$this->actions['add'].'</span></a>
            <div class="clear_both"><!-- --></div>
          </div>
        ';
      }

      
      
      

        $result.='
            '.$paging.'
            
            
          <table class="admin-list-table" cellpadding="0" cellspacing="0" border="0">
            <tr>
              '.$table_header.'
            </tr>
            '.$table_data.'
          </table>
            '.$paging.'

        ';
      }
      
      else
      {
        $result.='
          <p>Není k dispozici žádný záznam.</p>
        ';
      }
    
      if (TRUE==$this->actions['add'])
      {
        if (TRUE==$this->defaultLanguage)
        {
          $tmp_lang='languages='.$this->defaultLanguage;
        }
      
        $result.='
          <div class="admin-icons">
            <a href="?action'.$this->table.'=add&amp;'.$this->table.$tmp_lang.get_params($_GET, array('id'.$this->table, 'action'.$this->table, $this->table.'languages')).'#'.$this->href.'" class="admin-icon-new" title="'.$this->actions['add'].'#'.$this->href.'"><span class="no_css">'.$this->actions['add'].'</span></a>
            <div class="clear_both"><!-- --></div>
          </div>
        ';
      }
    
    
      return $result;
    
    }

// ****************************************************************************************************************************
// ****************************************************************************************************************************





// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                                E D I T A C E                                                   ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************

  function edit()
  {
  
        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
  
  
    $result='<h2>'.$this->dataRow['item_title'].'</h2>
    ';
    $result = '';
    // nacte se sablona editace (pokud existuje)
    if (TRUE==$this->templates['edit'])
    {
      ob_start();
      include_once($this->templates['edit']);
      $template=ob_get_contents();
      ob_end_clean();
    }
    else
    {
      $template=FALSE;
    }
  
  
   // vytvoreni formulare
   
   
   $form=new Form('', 'post', '', 'admin_form', $_POST, $this->dataRow, $this->templates['edit']);
  
    
   for ($i=0; $i<count($this->items); $i++)
   {
     $params=$this->items[$i]->getFormParams($this, $form);

    if (TRUE==$this->items[$i]->help)
    {
      $help='&nbsp;<span class="question" onmouseover="admin_help_show(\'help'.$this->items[$i]->id.$this->table.'\', event);" onmouseout="admin_help_hide(\'help'.$this->items[$i]->id.$this->table.'\');">?</span><div id="help'.$this->items[$i]->id.$this->table.'" class="admin-help">'.$this->items[$i]->help.'</div>';
    }
    else
    {
      $help='';
    }
     
     if (0<count($params))
     {
      for ($j=0; $j<count($params); $j++)
      {
        $form->addInput($params[$j]['type'], $params[$j]['name'], stripslashes($params[$j]['value']), $params[$j]['reg'], $params[$j]['css_id'], $params[$j]['css_class'], $params[$j]['spec'], $params[$j]['label'].$help, $params[$j]['labell_id'], $params[$j]['label_class'], $params[$j]['options'], $params[$j]['inactive']);
      }
     }
   }  
  $form->addInput('submit', '', $this->actions['edit_confirm']);    




  $result.='
          '.$this->innerHTML['edit']['top'].'

    <div class="admin-icons">
       <a href="?'.get_params($_GET, array('id'.$this->table, 'action'.$this->table)).'#'.$this->href.'" class="admin-icon-back" title="Zpět"><span class="no_css">Zpět</span></a>
       <div class="clear_both"><!-- --></div>
    </div>

  ';

  if ((0<count($_POST)) && (0==count($form->getErrors())) && (FALSE==isset($_POST['uploaddocuments'.$this->table])) )
  {

    // zdrane vyplneni
    $this->update($this->id);
    die();
  }
  else
  {
    $result.=$form->getHTML();
  }
      
      
   if (FALSE==$template)
   {
     $result.='
       <div class="admin-edit">
         '.$data_str.'
         '.$this->innerHTML['edit']['bottom'].'
        </div>
      ';
    }
      
  
   if (TRUE==$this->documents)
   {

  $result.='
    <div class="admin-icons">
       <a href="?'.get_params($_GET, array('id'.$this->table, 'action'.$this->table)).'#'.$this->href.'" class="admin-icon-back" title="Zpět"><span class="no_css">Zpět</span></a>
       <div class="clear_both"><!-- --></div>
    </div>
  ';
  
  if ($this->name<>'Fotogalerie')   require_once('Documents.php');
  if ($this->name=='Fotogalerie')   require_once('Documents2.php');
     $documents=new Documents($this);
     $result.=$documents->edit($this, $form);
   }


  
    return $result.'<div id="time_select"><!-- --></div>';
  }

// ****************************************************************************************************************************
// ****************************************************************************************************************************








    

 
 
 
 
 




// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                                U P D A T E                                                     ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function update($id)
{
  if (FALSE==$this->actions['edit'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }

        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
  if (FALSE==$this->actions['edit'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
  }

  if (TRUE==isset($this->log))
  {
    $row=array(
      'id_table'=>$GLOBALS['db']->tables[$this->table.'s'],
      'admin_id'=>$this->id,
      'operation'=>'update',
      'id_user'=>(int)$this->log['user'],
      'admin_title'=>(int)$this->dataRow['item_title'],
      'script'=>addslashes($this->log['script']),
    );
    $GLOBALS['db']->insert($this->log['table'], $row);
  }

  
  $this->action='update';

  $tables=array();  

  for ($i=0; $i<count($this->items); $i++)
  {
    if (FALSE==$this->items[$i]->virtual)
    {
      $params=$this->items[$i]->getInsertParams($this);

      for ($j=0; $j<count($params); $j++)
      {
        // seznam sloupcu
        $tables[$params[$j]['table']][]=array(
          'field'=>$params[$j]['field'],
          'value'=>$params[$j]['value'],
        );
      }
    }
  }  


  $row2=array();

  if (0<count($tables))
  {
    $keys=array_keys($tables);
    for ($i=0; $i<count($keys); $i++)
    {
      if (TRUE==$keys[$i])
      {
        $row=$row2=array();
        for ($j=0; $j<count($tables[$keys[$i]]); $j++)
        {
          $row[]=$tables[$keys[$i]][$j]['field'].'=\''.addslashes($tables[$keys[$i]][$j]['value']).'\'';
          $row2[$tables[$keys[$i]][$j]['field']]=addslashes($tables[$keys[$i]][$j]['value']);
        }
        
        $values=implode(', ', $row);
        if (TRUE==$values)
        {
          if ($keys[$i]==$this->table.'s')
          {
            $where=' AND id='.$this->id;
          }          
          else
          {
            $where='';
          }
            $GLOBALS['db']->queryN('UPDATE '.$keys[$i].' SET '.$values.' WHERE 1'.$where);
        }
      }
    }
  }


/*
  $sql='UPDATE '.$this->table.'s SET 
  ';
  
  $separator='';
  for ($i=0; $i<count($this->items); $i++)
  {
    $sql.=$separator.$this->items[$i]->field.'=\''.addslashes($_POST[$this->items[$i]->formName]).'\'';
    $separator=', ';
  }
  
  $sql.=' 
  WHERE id='.(int)$this->id.$this->where;
  
  $GLOBALS['db']->queryN($sql);   
  */
  if (TRUE==isset($this->actions['on_update']))
  {
    $this->actions['on_update']($this);
  }

  if (TRUE==isset($this->actions['after_update']))
  {
    $this->actions['after_update']($this);
  }


  header('location: ?action'.$this->table.'='.$this->actions['after_confirm'].str_replace('&amp;', '&', get_params($_GET, array('action'.$this->table))).'#docs');
  die();
}


    

 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************


















// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                          N O V Y    Z A Z N A M                                                ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function add()
{
  if (FALSE==$this->actions['add'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }

    $result='<h2>'.$this->dataRow['item_title'].'</h2>
    ';
  
    $result = '';
  
    // nacte se sablona Insertu (pokud existuje)
    if (TRUE==$this->templates['edit'])
    {
      ob_start();
      include_once($this->templates['edit']);
      $template=ob_get_contents();
      ob_end_clean();
    }
    else
    {
      $template=FALSE;
    }
  
   
   // vytvoreni formulare
   $error=FALSE;
   
   $form=new Form('', 'post', '', 'admin_form', $_POST, $this->dataRow, $this->templates['edit']);
    
   for ($i=0; $i<count($this->items); $i++)
   {
     $params=$this->items[$i]->getFormParams($this, $form);

    if (TRUE==$this->items[$i]->help)
    {
      $help='&nbsp;<span class="question" onmouseover="admin_help_show(\'help'.$this->items[$i]->id.$this->table.'\', event);" onmouseout="admin_help_hide(\'help'.$this->items[$i]->id.$this->table.'\');">?</span><div id="help'.$this->items[$i]->id.$this->table.'" class="admin-help">'.$this->items[$i]->help.'</div>';
    }
    else
    {
      $help='';
    }

     
     for ($j=0; $j<count($params); $j++)
     {
      $error=$error || $params['error'];
      $form->addInput($params[$j]['type'], $params[$j]['name'], $params[$j]['value'], $params[$j]['reg'], $params[$j]['css_id'], $params[$j]['input_class'], $params[$j]['spec'], $params[$j]['label'].$help, $params[$j]['label_id'], $params[$j]['label_class'], $params[$j]['options'], $params[$j]['inactive']);
     }
     
   }  

   
   
  $form->addInput('submit', '', $this->actions['add_now']);    


  $result.='
    <div class="admin-icons">
       <a href="?'.get_params($_GET, array('id'.$this->table, 'action'.$this->table)).'#'.$this->href.'" class="admin-icon-back" title="Zpět"><span class="no_css">Zpět</span></a>
       <div class="clear_both"><!-- --></div>
    </div>
  ';



  if ((0<count($_POST)) && (0==count($form->getErrors())) && (FALSE==$error) && (FALSE==isset($_POST['documents'.$this->table.'action'])))
  {
    // zdarne vyplneni
    $this->insert();
    die();
  }
  else
  {
  
    $result.=$form->getHTML();
  }
      
      
   if (FALSE==$template)
   {
     $result.='
       <div class="admin-edit">
         '.$data_str.'
        </div>
      ';
    }

    return $result.'<div id="time_select"><!-- --></div>';


  return $result;
}


    

 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************
















// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                                I N S E R T                                                     ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function insert()
{


  if (FALSE==$this->actions['edit'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }

  if (TRUE==isset($this->log))
  {
    $row=array(
      'id_table'=>$GLOBALS['db']->tables[$this->table.'s'],
      'admin_id'=>$this->id,
      'operation'=>'insert',
      'id_user'=>(int)$this->log['user'],
      'admin_title'=>(int)$this->dataRow['item_title'],
      'script'=>addslashes($this->log['script']),
    );
    
    $GLOBALS['db']->insert($this->log['table'], $row);
  }


  $tables[$this->table.'s']=array();  

  for ($i=0; $i<count($this->items); $i++)
  {
    if (FALSE==$this->items[$i]->virtual)
    {
      $params=$this->items[$i]->getInsertParams($this);
      for ($j=0; $j<count($params); $j++)
      {
        // seznam sloupcu
        $tables[$params[$j]['table']][]=array(
          'field'=>$params[$j]['field'],
          'value'=>$params[$j]['value'],
        );
      }
    }
  }  




  if (0<count($tables))
  {
    $keys=array_keys($tables);
    for ($i=0; $i<count($keys); $i++)
    {
      if (TRUE==$keys[$i])
      {
        $row=array();
        for ($j=0; $j<count($tables[$keys[$i]]); $j++)
        {
          $row[$tables[$keys[$i]][$j]['field']]=$tables[$keys[$i]][$j]['value'];
        }
            $GLOBALS['db']->insert($keys[$i], $row);
        
      }
    }
  }

          $tmp=$GLOBALS['db']->select('MAX(id) AS id', $this->table.'s', '', '1');
          if (TRUE==isset($this->actions['on_insert']))
          {
            $this->actions['on_insert']($this, $tmp['id']);
          }

  if ($this->actions['edit']==$this->actions['after_add'])
  {
    header('location: ?id'.$this->table.'='.(int)$tmp['id'].'&action'.$this->table.'=edit'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))).'#docs');
  }
  else if ('detail'==$this->actions['after_add'])
  {
    header('location: ?id'.$this->table.'='.(int)$tmp['id'].str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
  }
  else
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
  }
  die();
}


    

 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************



















// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                             D E A K T I V A C E                                                ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function deactive()
{
  if (FALSE==$this->actions['deactive'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }

        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
    }
    
  if (TRUE==isset($this->log))
  {
    $row=array(
      'id_table'=>$GLOBALS['db']->tables[$this->table.'s'],
      'admin_id'=>$this->id,
      'operation'=>'deactive',
      'id_user'=>(int)$this->log['user'],
      'admin_title'=>(int)$this->dataRow['item_title'],
      'script'=>addslashes($this->log['script']),
    );
    
    $GLOBALS['db']->insert($this->log['table'], $row);
  }

    
  $sql='UPDATE '.$this->table.'s SET active=\'N\' WHERE id='.(int)$this->id;
  $GLOBALS['db']->queryN($sql);   
  
  if (TRUE==isset($this->actions['on_deactive']))
  {
    $this->actions['on_deactive']($this);
  }
  
  
  header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
  die();
}


    

 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************













// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                             A K T I V A C E                                                    ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function active()
{
  if (FALSE==$this->actions['active'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }

  if (TRUE==isset($this->log))
  {
    $row=array(
      'id_table'=>$GLOBALS['db']->tables[$this->table.'s'],
      'admin_id'=>$this->id,
      'operation'=>'active',
      'id_user'=>(int)$this->log['user'],
      'admin_title'=>(int)$this->dataRow['item_title'],
      'script'=>addslashes($this->log['script']),
    );
    
    $GLOBALS['db']->insert($this->log['table'], $row);
  }


  $sql='UPDATE '.$this->table.'s SET active=\'Y\' WHERE id='.(int)$this->id;
  $GLOBALS['db']->queryN($sql);   

  if (TRUE==isset($this->actions['on_active']))
  {
    $this->actions['on_active']($this);
  }

  
  header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
  die();
}


    

 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************









// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                             S M A Z A N I                                                      ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************



function delete()
{
  if (FALSE==$this->actions['delete'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
  
  $result='';

  $result.='
    <p>Opravu chcete smazat záznam <b>'.$this->dataRow['item_title'].'</b>?</p>
    <p>
      <a href="?action'.$this->table.'=delete_confirm'.get_params($_GET, array('action'.$this->table)).'">'.$this->actions['delete_confirm'].'</a><br />
      <a href="'.$_SERVER['HTTP_REFERER'].'">Ne</a><br />
    </p>
    
  ';   
  
  return $result;
}


    

function deleteConfirm()
{
  if (FALSE==$this->actions['delete_confirm'])
  {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }
        if (TRUE==@in_array($this->id, $this->readOnlys))
        {
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
    die();
  }


  if (TRUE==isset($this->log))
  {
    $row=array(
      'id_table'=>$GLOBALS['db']->tables[$this->table.'s'],
      'admin_id'=>$this->id,
      'operation'=>'delete',
      'id_user'=>(int)$this->log['user'],
      'admin_title'=>(int)$this->dataRow['item_title'],
      'script'=>addslashes($this->log['script']),
    );
    
    $GLOBALS['db']->insert($this->log['table'], $row);
  }


  $sql='DELETE FROM '.$this->table.'s WHERE id='.(int)$this->id;
  $GLOBALS['db']->queryN($sql);   
  
  header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('id'.$this->table, 'action'.$this->table))));
  die();
  
  return $result;
}
 
 

// ****************************************************************************************************************************
// ****************************************************************************************************************************











 
 
 




// ****************************************************************************************************************************
// ******                                                                                                                ******   
// ******                                                D E T A I L                                                     ******   
// ******                                                                                                                ******   
// ****************************************************************************************************************************

  function getDetail()
  {
    $result='';
  
  
    // nacte se sablona detailu (pokud existuje)
    if (TRUE==$this->templates['detail'])
    {
      ob_start();
      include_once($this->templates['detail']);
      $template=ob_get_contents();
      ob_end_clean();
      $template=str_replace('{|item_title|}', $this->dataRow['item_title'], $template);
    }
    else
    {
      $template=FALSE;
      $result.=$this->innerHTML['detail']['top'];

    }

  
    for ($i=0; $i<count($this->items); $i++)
    {
      $data_str='';
      $params=$this->items[$i]->detail($this);


      if ((TRUE==$params['label']) && (FALSE==$params['value']))
      {
        $params['value']='-';
      }

      // label
      if (TRUE==$params['label'])
      {
      
        if (TRUE==$template)
        {
          $template=str_replace('{|'.$this->items[$i]->name.'.label|}', $params['label'], $template);
        }
        else
        {
          $data_str.='<div class="admin-detail-label">'.$params['label'].'</div>
          ';
        }
      }
      
      // hodnota
      if (TRUE==$params['value'])
      {
        if (TRUE==$template)
        {
          $template=str_replace('{|'.$this->items[$i]->name.'.value|}', $params['value'], $template);
        }
        else
        {
          $data_str.='<div class="admin-detail-value">'.$params['value'].'</div>
          '; 
        }
      }
      
      
      
      
      if (FALSE==$template)
      {
        
        if (TRUE==$params['in_detail'])
        {
        $result.='
          <div class="admin-detail-item">
              '.$data_str.'
            <div class="clear_both"><!-- --></div>
          </div>
        ';
        }
      }
      
    }    
  

    if (FALSE==$template)
    {
      $result.='
        <div class="admin-detail">
          <div class="admin-icons">
            <a href="?'.get_params($_GET, array('id'.$this->table, 'action'.$this->table)).'#'.$this->href.'" class="admin-icon-back" title="Zpět"><span class="no_css">Zpět</span></a>
          </div>
          '.$this->innerHTML['detail']['bottom'].'
        </div>
      ';
    }
    else
    {
      $template=str_replace('{|back|}', '<div class="admin-icons"><a href="?'.get_params($_GET, array('id'.$this->table, 'action'.$this->table)).'#'.$this->href.'" class="admin-icon-back" title="Zpět"><span class="no_css">Zpět</span></a></div>', $template);
      $result.=$template;
    }
    
            if (TRUE==$this->defaultLanguage)
        {
          $tmp_lang='&amp;'.$this->table.'languages='.$this->defaultLanguage.'&amp;';
        }


    if (TRUE==$this->actions['edit'])
    {
      if (TRUE==isset($this->list['edit']))
      {
        $icons=$this->list['edit']($this->id);
      }
      else
      {
      $icons.='<a href="?action'.$this->table.'=edit'.$tmp_lang.get_params($_GET, array('action'.$this->table)).'" class="admin-icon-edit" title="'.$this->actions['edit'].'"><span class="no_css">'.$this->actions['edit'].'</span></a>';        
      }
    }
    if (TRUE==$this->actions['delete'])
    {
      $icons.='<a href="?action'.$this->table.'=delete'.get_params($_GET, array('action'.$this->table)).'" class="admin-icon-delete" title="'.$this->actions['delete'].'"><span class="no_css">'.$this->actions['delete'].'</span></a>';        
    }
    if (
     (TRUE==$this->actions['deactive'])
       &&
     ('Y'==$this->data[$i]['active'])
    )
    {
      $icons.='<a href="?action'.$this->table.'=deactive'.get_params($_GET, array('action'.$this->table)).'" class="admin-icon-deactive" title="'.$this->actions['deactive'].'"><span class="no_css">'.$this->actions['deactive'].'</span></a>';        
    }
        
    $result='
      <div class="admin-icons">'.$icons.'<div class="clear_both"><!-- --></div></div>
    '.$result;


   if (TRUE==$this->documents)
   {
    if ($this->name<>'Fotogalerie')   require_once('Documents.php');
  if ($this->name=='Fotogalerie')   require_once('Documents2.php');
     $documents=new Documents($this);
     $result.=$documents->edit($this);
   }

  
    return $result;
  }

// ****************************************************************************************************************************
// ****************************************************************************************************************************





  function swap()  // prehodi dve polozky (atribut list)
  {
    $swap=explode('-', $_GET['swap'.$this->table]);
  
    $sql='
      UPDATE
        '.$this->table.'s
      SET
        list=9999999
      WHERE 
        list='.$swap[0].'
      ;
    ';
    mysql_query($sql);
    
    $sql='
      UPDATE
        '.$this->table.'s
      SET
        list='.$swap[0].'
      WHERE 
        list='.$swap[1].'
      ;
    ';
    mysql_query($sql);

    $sql='
      UPDATE
        '.$this->table.'s
      SET
        list='.$swap[1].'
      WHERE 
        list=9999999
      ;
    ';
    mysql_query($sql);
    
    header('location: ?'.str_replace('&amp;', '&', get_params($_GET, array('action'.$this->table, 'id'.$this->table, 'swap'.$this->table))));      
    die();
  }

















  
    // vrati html kod administrace
    function getHTML()
    {
      $result='';

      if (TRUE==isset($_GET['swap'.$this->table]))
      {
        $this->swap();
      }
      
      // pridani polozky
      if ('add'==$this->action)
      {
        $result.=$this->add();
      }

      // editace polozky
      else if ('edit'==$this->action)
      {
        $result.=$this->edit();
      }

      // deaktivace polozky
      else if ('deactive'==$this->action)
      {
        $result.=$this->deactive();
      }

      // aktivace polozky
      else if ('active'==$this->action)
      {
        $result.=$this->active();
      }

      // dotaz nasmazani polozky
      else if ('delete'==$this->action)
      {
        $result.=$this->delete();
      }

      // smazani polozky
      else if ('delete_confirm'==$this->action)
      {
        $result.=$this->deleteConfirm();
      }

      // detail polozky
      else if (TRUE==isset($_GET['id'.$this->table]))
      {
        $result.=$this->getDetail();
      }
      
      // vypis
      else $result.=$this->getList();
      
      return '<a name="'.$this->href.'"><!-- --></a><div class="admin" id="admin'.$this->table.$this->id.'">
          <h2 class="form-title" >'.$this->name.'</h2> <br />

        '.$result.'
        <script type="text/javascript">popInit(\'admin'.$this->table.$this->id.'\');</script>
        </div>&nbsp;';
    
    }

    

  }


    require_once('forms.php');




?>

ACC SHELL 2018