<?
function LISTS(){ if (!is_object($GLOBALS['lists'])) $GLOBALS['lists']=new c_lists();return($GLOBALS['lists']);}

class c_lists
{
    function get_rec_id_by_name($name,$clss,$parent,$table_name)
    {  $usl_select='clss='.$clss.' and parent='.$parent.' and enabled=1 and UPPER(obj_name) like "'.addslashes($name).'"' ;
       $key_field=_CLSS($clss)->get_key_field() ;
       $rec=execSQL_van('select '.$key_field.',obj_name from '.$table_name.' where '.$usl_select) ;
       if (!$rec[$key_field])
       { $rec=_CLSS($clss)->obj_create(array('tkey'=>_DOT($table_name)->pkey,'parent'=>$parent,'obj_name'=>$name)) ;
         echo 'Добавлен '._CLSS($clss)->name.' "'.$name.'"<br>' ;
           // заполняем уровни parent по новой системе
         $rec_parent_section=execSQL_van('select * from '.$table_name.' where pkey='.$parent) ;
         $data=array() ;
         if (isset($rec_parent_section['parent1']))
         { for ($i=1;$i<$rec_parent_section['level'];$i++)  $data['parent'.$i]=$rec_parent_section['parent'.$i] ;
           $data['parent'.$rec_parent_section['level']]=$parent ;
           $data['level']=$rec_parent_section['level']+1 ;
           update_rec_in_table($table_name,$data,'pkey='.$rec['pkey']) ;
         }
         reboot_engine() ;
       }
       return($rec[$key_field]) ;
    }
}

?>